aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-08-19 13:11:25 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-08-19 13:11:25 +0000
commit45a6b7dc5a1758cb2bc49b0d76effa381043d297 (patch)
tree2e9f38ca4e3eed5f7d1c3b0c1271564c4f5655f0 /os
parent0a59caa507fd9aed69345ba2c915dfa8f7c2395c (diff)
downloadChibiOS-45a6b7dc5a1758cb2bc49b0d76effa381043d297.tar.gz
ChibiOS-45a6b7dc5a1758cb2bc49b0d76effa381043d297.tar.bz2
ChibiOS-45a6b7dc5a1758cb2bc49b0d76effa381043d297.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1082 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/io/serial.c62
-rw-r--r--os/io/serial.h44
-rw-r--r--os/io/templates/serial_lld.c11
-rw-r--r--os/ports/GCC/ARMCM3/STM32F103/serial_lld.c16
-rw-r--r--os/ports/GCC/ARMCM3/nvic.c15
-rw-r--r--os/ports/GCC/ARMCM3/nvic.h1
6 files changed, 89 insertions, 60 deletions
diff --git a/os/io/serial.c b/os/io/serial.c
index abc099eea..05d258841 100644
--- a/os/io/serial.c
+++ b/os/io/serial.c
@@ -61,36 +61,10 @@ static size_t read(void *ip, uint8_t *buffer, size_t n) {
return chIQRead(&((SerialDriver *)ip)->d2.iqueue, buffer, n);
}
-static void start(void *ip, const SerialDriverConfig *config) {
- SerialDriver *sdp = (SerialDriver *)ip;
-
- chSysLock();
- sd_lld_start(sdp, config);
- chSysUnlock();
-}
-
-/**
- * @brief Stops the driver.
- * @Details Any thread waiting on the driver's queues will be awakened with
- * the message @p Q_RESET.
- *
- * @param sd The @p SerialDriver to be stopped.
- */
-static void stop(void *ip) {
- SerialDriver *sdp = (SerialDriver *)ip;
-
- chSysLock();
- sd_lld_stop(sdp);
- chOQResetI(&sdp->d2.oqueue);
- chIQResetI(&sdp->d2.iqueue);
- chSchRescheduleS();
- chSysUnlock();
-}
-
static const struct SerialDriverVMT vmt = {
{putwouldblock, getwouldblock, put, get},
{write, read},
- {start, stop}
+ {}
};
/**
@@ -112,8 +86,6 @@ static const struct SerialDriverVMT vmt = {
*/
void sdInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) {
- chDbgCheck(sdp != NULL, "sdInit");
-
sdp->vmt = &vmt;
chEvtInit(&sdp->d1.ievent);
chEvtInit(&sdp->d1.oevent);
@@ -124,6 +96,38 @@ void sdInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) {
}
/**
+ * @brief Configures and starts the driver.
+ *
+ * @param[in] ip pointer to a @p SerialDriver or derived class
+ * @param[in] config the architecture-dependent serial driver configuration.
+ * If this parameter is set to @p NULL then a default
+ * configuration is used.
+ */
+void sdStart(SerialDriver *sdp, const SerialDriverConfig *config) {
+
+ chSysLock();
+ sd_lld_start(sdp, config);
+ chSysUnlock();
+}
+
+/**
+ * @brief Stops the driver.
+ * @Details Any thread waiting on the driver's queues will be awakened with
+ * the message @p Q_RESET.
+ *
+ * @param[in] ip pointer to a @p SerialDriver or derived class
+ */
+void sdStop(SerialDriver *sdp) {
+
+ chSysLock();
+ sd_lld_stop(sdp);
+ chOQResetI(&sdp->d2.oqueue);
+ chIQResetI(&sdp->d2.iqueue);
+ chSchRescheduleS();
+ chSysUnlock();
+}
+
+/**
* @brief Handles incoming data.
* @details This function must be called from the input interrupt service
* routine in order to enqueue incoming data and generate the
diff --git a/os/io/serial.h b/os/io/serial.h
index aa18ebe7b..acfb2500f 100644
--- a/os/io/serial.h
+++ b/os/io/serial.h
@@ -50,22 +50,6 @@ typedef struct _SerialDriver SerialDriver;
* @brief @p SerialDriver specific methods.
*/
struct _serial_driver_methods {
- /**
- * @brief Configures and starts the driver.
- *
- * @param[in] ip pointer to a @p SerialDriver or derived class
- * @param[in] config The configuration record.
- */
- void (*start)(void *ip, const SerialDriverConfig *config);
-
- /**
- * @brief Stops the driver.
- * @Details Any thread waiting on the driver's queues will be awakened with
- * the message @p Q_RESET.
- *
- * @param[in] ip pointer to a @p SerialDriver or derived class
- */
- void (*stop)(void *ip);
};
/**
@@ -115,11 +99,13 @@ struct _SerialDriver {
#ifdef __cplusplus
extern "C" {
#endif
- void sdInit(SerialDriver *sd, qnotify_t inotify, qnotify_t onotify);
- void sdIncomingDataI(SerialDriver *sd, uint8_t b);
- msg_t sdRequestDataI(SerialDriver *sd);
- void sdAddFlagsI(SerialDriver *sd, sdflags_t mask);
- sdflags_t sdGetAndClearFlags(SerialDriver *sd);
+ void sdInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify);
+ void sdStart(SerialDriver *sdp, const SerialDriverConfig *config);
+ void sdStop(SerialDriver *sdp);
+ void sdIncomingDataI(SerialDriver *sdp, uint8_t b);
+ msg_t sdRequestDataI(SerialDriver *sdp);
+ void sdAddFlagsI(SerialDriver *sdp, sdflags_t mask);
+ sdflags_t sdGetAndClearFlags(SerialDriver *sdp);
#ifdef __cplusplus
}
#endif
@@ -131,7 +117,7 @@ extern "C" {
* be used to check different channels implementations.
* @see chIOPutWouldBlock()
*/
-#define sdPutWouldBlock(sd) chOQIsFull(&(sd)->d2.oqueue)
+#define sdPutWouldBlock(sdp) chOQIsFull(&(sdp)->d2.oqueue)
/**
* @brief Direct input check on a @p SerialDriver.
@@ -140,7 +126,7 @@ extern "C" {
* be used to check different channels implementations.
* @see chIOGetWouldBlock()
*/
-#define sdGetWouldBlock(sd) chIQIsEmpty(&(sd)->d2.iqueue)
+#define sdGetWouldBlock(sdp) chIQIsEmpty(&(sdp)->d2.iqueue)
/**
* @brief Direct blocking write to a @p SerialDriver.
@@ -149,7 +135,7 @@ extern "C" {
* be used to write to different channels implementations.
* @see chIOPut()
*/
-#define sdPut(sd, b) chOQPut(&(sd)->d2.oqueue, b)
+#define sdPut(sdp, b) chOQPut(&(sdp)->d2.oqueue, b)
/**
* @brief Direct blocking write on a @p SerialDriver with timeout
@@ -159,7 +145,7 @@ extern "C" {
* be used to write to different channels implementations.
* @see chIOPutTimeout()
*/
-#define sdPutTimeout(sd, b, t) chOQPutTimeout(&(sd)->d2.iqueue, b, t)
+#define sdPutTimeout(sdp, b, t) chOQPutTimeout(&(sdp)->d2.iqueue, b, t)
/**
* @brief Direct blocking read from a @p SerialDriver.
@@ -168,7 +154,7 @@ extern "C" {
* be used to read from different channels implementations.
* @see chIOGet()
*/
-#define sdGet(sd) chIQGet(&(sd)->d2.iqueue)
+#define sdGet(sdp) chIQGet(&(sdp)->d2.iqueue)
/**
* @brief Direct blocking read from a @p SerialDriver with timeout
@@ -178,7 +164,7 @@ extern "C" {
* be used to read from different channels implementations.
* @see chIOGetTimeout()
*/
-#define sdGetTimeout(sd, t) chIQGetTimeout(&(sd)->d2.iqueue, t)
+#define sdGetTimeout(sdp, t) chIQGetTimeout(&(sdp)->d2.iqueue, t)
/**
* @brief Direct non-blocking write to a @p SerialDriver.
@@ -187,7 +173,7 @@ extern "C" {
* be used to write from different channels implementations.
* @see chIOWrite()
*/
-#define sdWrite(sd, b, n) chOQWrite(&(sd)->d2.oqueue, b, n)
+#define sdWrite(sdp, b, n) chOQWrite(&(sdp)->d2.oqueue, b, n)
/**
* @brief Direct non-blocking read on a @p SerialDriver.
@@ -196,7 +182,7 @@ extern "C" {
* be used to read from different channels implementations.
* @see chIORead()
*/
-#define sdRead(sd, b, n) chIQRead(&(sd)->d2.iqueue, b, n)
+#define sdRead(sdp, b, n) chIQRead(&(sdp)->d2.iqueue, b, n)
#endif /* _SERIAL_H_ */
diff --git a/os/io/templates/serial_lld.c b/os/io/templates/serial_lld.c
index 0fbaa3900..d0aabfaa0 100644
--- a/os/io/templates/serial_lld.c
+++ b/os/io/templates/serial_lld.c
@@ -26,6 +26,10 @@
#include <ch.h>
+/** @brief Driver default configuration.*/
+static const SerialDriverConfig default_config = {
+};
+
/*===========================================================================*/
/* Low Level Driver local functions. */
/*===========================================================================*/
@@ -49,10 +53,15 @@ void sd_lld_init(void) {
* @brief Low level serial driver configuration and (re)start.
*
* @param[in] sdp pointer to a @p SerialDriver object
- * @param[in] config the architecture-dependent serial driver configuration
+ * @param[in] config the architecture-dependent serial driver configuration.
+ * If this parameter is set to @p NULL then a default
+ * configuration is used.
*/
void sd_lld_start(SerialDriver *sdp, const SerialDriverConfig *config) {
+ if (config == NULL)
+ config = &default_config;
+
}
/**
diff --git a/os/ports/GCC/ARMCM3/STM32F103/serial_lld.c b/os/ports/GCC/ARMCM3/STM32F103/serial_lld.c
index 5e4bcce99..bf06195be 100644
--- a/os/ports/GCC/ARMCM3/STM32F103/serial_lld.c
+++ b/os/ports/GCC/ARMCM3/STM32F103/serial_lld.c
@@ -45,6 +45,15 @@ SerialDriver COM2;
SerialDriver COM3;
#endif
+/** @brief Driver default configuration.*/
+static const SerialDriverConfig default_config =
+{
+ 38400,
+ 0,
+ USART_CR2_STOP1_BITS | USART_CR2_LINEN,
+ 0
+};
+
/*===========================================================================*/
/* Low Level Driver local functions. */
/*===========================================================================*/
@@ -222,10 +231,15 @@ void sd_lld_init(void) {
* @brief Low level serial driver configuration and (re)start.
*
* @param[in] sdp pointer to a @p SerialDriver object
- * @param[in] config the architecture-dependent serial driver configuration
+ * @param[in] config the architecture-dependent serial driver configuration.
+ * If this parameter is set to @p NULL then a default
+ * configuration is used.
*/
void sd_lld_start(SerialDriver *sdp, const SerialDriverConfig *config) {
+ if (config == NULL)
+ config = &default_config;
+
#if USE_STM32_USART1
if (&COM1 == sdp) {
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
diff --git a/os/ports/GCC/ARMCM3/nvic.c b/os/ports/GCC/ARMCM3/nvic.c
index 4a11cbb39..e992427fd 100644
--- a/os/ports/GCC/ARMCM3/nvic.c
+++ b/os/ports/GCC/ARMCM3/nvic.c
@@ -32,6 +32,7 @@
*
* @param n the interrupt number
* @param prio the interrupt priority
+ *
* @note The parameters are not tested for correctness.
*/
void NVICEnableVector(uint32_t n, uint32_t prio) {
@@ -42,6 +43,20 @@ void NVICEnableVector(uint32_t n, uint32_t prio) {
}
/**
+ * @brief Disables an interrupt handler.
+ *
+ * @param n the interrupt number
+ *
+ * @note The parameters are not tested for correctness.
+ */
+void NVICDisableVector(uint32_t n) {
+ unsigned sh = (n & 3) << 3;
+
+ NVIC_ICER(n >> 5) = 1 << (n & 0x1F);
+ NVIC_IPR(n >> 2) = NVIC_IPR(n >> 2) & ~(0xFF << sh);
+}
+
+/**
* @brief Changes the priority of a system handler.
*
* @param handler the system handler number
diff --git a/os/ports/GCC/ARMCM3/nvic.h b/os/ports/GCC/ARMCM3/nvic.h
index 9d2b79606..54437aa62 100644
--- a/os/ports/GCC/ARMCM3/nvic.h
+++ b/os/ports/GCC/ARMCM3/nvic.h
@@ -180,6 +180,7 @@ typedef struct {
extern "C" {
#endif
void NVICEnableVector(uint32_t n, uint32_t prio);
+ void NVICDisableVector(uint32_t n);
void NVICSetSystemHandlerPriority(uint32_t handler, uint32_t prio);
#ifdef __cplusplus
}