diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-01-02 13:35:55 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-01-02 13:35:55 +0000 |
commit | bedb87c1e7cc9741c57c299d81d6e24c5e9c59c5 (patch) | |
tree | 7a3f0b05365b525bd9335b9a660aa80b6b6975b3 /os | |
parent | 15e6fecf11e470abebe963177434f83883e63acf (diff) | |
download | ChibiOS-bedb87c1e7cc9741c57c299d81d6e24c5e9c59c5.tar.gz ChibiOS-bedb87c1e7cc9741c57c299d81d6e24c5e9c59c5.tar.bz2 ChibiOS-bedb87c1e7cc9741c57c299d81d6e24c5e9c59c5.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1495 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r-- | os/hal/include/can.h | 20 | ||||
-rw-r--r-- | os/hal/platforms/STM32/can_lld.h | 4 | ||||
-rw-r--r-- | os/hal/platforms/STM32/pwm_lld.c | 2 | ||||
-rw-r--r-- | os/hal/platforms/Win32/serial_lld.c | 89 | ||||
-rw-r--r-- | os/hal/platforms/Win32/serial_lld.h | 71 | ||||
-rw-r--r-- | os/hal/templates/can_lld.h | 4 | ||||
-rw-r--r-- | os/hal/templates/serial_lld.c | 11 | ||||
-rw-r--r-- | os/hal/templates/serial_lld.h | 67 |
8 files changed, 139 insertions, 129 deletions
diff --git a/os/hal/include/can.h b/os/hal/include/can.h index 4dad345d8..72f089379 100644 --- a/os/hal/include/can.h +++ b/os/hal/include/can.h @@ -36,23 +36,23 @@ /**
* @brief Errors rate warning.
*/
-#define CAN_LIMIT_WARNING 1
+#define CAN_LIMIT_WARNING 1
/**
* @brief Errors rate error.
*/
-#define CAN_LIMIT_ERROR 2
+#define CAN_LIMIT_ERROR 2
/**
* @brief Bus off condition reached.
*/
-#define CAN_BUS_OFF_ERROR 4
+#define CAN_BUS_OFF_ERROR 4
/**
* @brief Framing error of some kind on the CAN bus.
*/
-#define CAN_FRAMING_ERROR 8
+#define CAN_FRAMING_ERROR 8
/**
* @brief Overflow in receive queue.
*/
-#define CAN_OVERFLOW_ERROR 16
+#define CAN_OVERFLOW_ERROR 16
/*===========================================================================*/
/* Driver pre-compile time settings. */
@@ -60,23 +60,15 @@ /**
* @brief Sleep mode related APIs inclusion switch.
- * @note This switch is enforced to @p FALSE if the driver implementation
- * does not support the sleep mode.
*/
-#if CAN_SUPPORTS_SLEEP || defined(__DOXYGEN__)
-#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)
#define CAN_USE_SLEEP_MODE TRUE
-#endif
-#else /* !CAN_SUPPORTS_SLEEP */
-#define CAN_USE_SLEEP_MODE FALSE
-#endif /* !CAN_SUPPORTS_SLEEP */
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
#if !CH_USE_SEMAPHORES || !CH_USE_EVENTS
-#error "the ADC driver requires CH_USE_SEMAPHORES and CH_USE_EVENTS"
+#error "CAN driver requires CH_USE_SEMAPHORES and CH_USE_EVENTS"
#endif
/*===========================================================================*/
diff --git a/os/hal/platforms/STM32/can_lld.h b/os/hal/platforms/STM32/can_lld.h index 754d4eadb..ced27f38d 100644 --- a/os/hal/platforms/STM32/can_lld.h +++ b/os/hal/platforms/STM32/can_lld.h @@ -93,6 +93,10 @@ /* Derived constants and error checks. */
/*===========================================================================*/
+#if CAN_USE_SLEEP_MODE && !CAN_SUPPORTS_SLEEP
+#error "CAN sleep mode not supported in this architecture"
+#endif
+
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
diff --git a/os/hal/platforms/STM32/pwm_lld.c b/os/hal/platforms/STM32/pwm_lld.c index 14b85ea8e..e5c20f12f 100644 --- a/os/hal/platforms/STM32/pwm_lld.c +++ b/os/hal/platforms/STM32/pwm_lld.c @@ -90,6 +90,7 @@ static void stop_channels(PWMDriver *pwmp) { pwmp->pd_tim->CCMR2 = 0; /* Channels 3 and 4 frozen. */
}
+#if USE_STM32_PWM2 || USE_STM32_PWM3 || USE_STM32_PWM4 || defined(__DOXYGEN__)
/**
* @brief Common TIM2...TIM4 IRQ handler. * @note It is assumed that the various sources are only activated if the
@@ -113,6 +114,7 @@ static void serve_interrupt(PWMDriver *pwmp) { if ((sr & TIM_SR_UIF) != 0)
pwmp->pd_config->pc_callback();
}
+#endif /* USE_STM32_PWM2 || USE_STM32_PWM3 || USE_STM32_PWM4 */
/*===========================================================================*/
/* Driver interrupt handlers. */
diff --git a/os/hal/platforms/Win32/serial_lld.c b/os/hal/platforms/Win32/serial_lld.c index 68decfc01..e29b994de 100644 --- a/os/hal/platforms/Win32/serial_lld.c +++ b/os/hal/platforms/Win32/serial_lld.c @@ -47,7 +47,7 @@ SerialDriver SD2; /*===========================================================================*/
/** @brief Driver default configuration.*/
-static const SerialDriverConfig default_config = {
+static const SerialConfig default_config = {
};
static u_long nb = 1;
@@ -61,18 +61,18 @@ static void init(SerialDriver *sdp, uint16_t port) { struct protoent *prtp;
if ((prtp = getprotobyname("tcp")) == NULL) {
- printf("%s: Error mapping protocol name to protocol number\n", sdp->d2.com_name);
+ printf("%s: Error mapping protocol name to protocol number\n", sdp->sd.com_name);
goto abort;
}
- sdp->d2.com_listen = socket(PF_INET, SOCK_STREAM, prtp->p_proto);
- if (sdp->d2.com_listen == INVALID_SOCKET) {
- printf("%s: Error creating simulator socket\n", sdp->d2.com_name);
+ sdp->sd.com_listen = socket(PF_INET, SOCK_STREAM, prtp->p_proto);
+ if (sdp->sd.com_listen == INVALID_SOCKET) {
+ printf("%s: Error creating simulator socket\n", sdp->sd.com_name);
goto abort;
}
- if (ioctlsocket(sdp->d2.com_listen, FIONBIO, &nb) != 0) {
- printf("%s: Unable to setup non blocking mode on socket\n", sdp->d2.com_name);
+ if (ioctlsocket(sdp->sd.com_listen, FIONBIO, &nb) != 0) {
+ printf("%s: Unable to setup non blocking mode on socket\n", sdp->sd.com_name);
goto abort;
}
@@ -80,36 +80,36 @@ static void init(SerialDriver *sdp, uint16_t port) { sad.sin_family = AF_INET;
sad.sin_addr.s_addr = INADDR_ANY;
sad.sin_port = htons(port);
- if (bind(sdp->d2.com_listen, (struct sockaddr *)&sad, sizeof(sad))) {
- printf("%s: Error binding socket\n", sdp->d2.com_name);
+ if (bind(sdp->sd.com_listen, (struct sockaddr *)&sad, sizeof(sad))) {
+ printf("%s: Error binding socket\n", sdp->sd.com_name);
goto abort;
}
- if (listen(sdp->d2.com_listen, 1) != 0) {
- printf("%s: Error listening socket\n", sdp->d2.com_name);
+ if (listen(sdp->sd.com_listen, 1) != 0) {
+ printf("%s: Error listening socket\n", sdp->sd.com_name);
goto abort;
}
- printf("Full Duplex Channel %s listening on port %d\n", sdp->d2.com_name, port);
+ printf("Full Duplex Channel %s listening on port %d\n", sdp->sd.com_name, port);
return;
abort:
- if (sdp->d2.com_listen != INVALID_SOCKET)
- closesocket(sdp->d2.com_listen);
+ if (sdp->sd.com_listen != INVALID_SOCKET)
+ closesocket(sdp->sd.com_listen);
WSACleanup();
exit(1);
}
static bool_t connint(SerialDriver *sdp) {
- if (sdp->d2.com_data == INVALID_SOCKET) {
+ if (sdp->sd.com_data == INVALID_SOCKET) {
struct sockaddr addr;
int addrlen = sizeof(addr);
- if ((sdp->d2.com_data = accept(sdp->d2.com_listen, &addr, &addrlen)) == INVALID_SOCKET)
+ if ((sdp->sd.com_data = accept(sdp->sd.com_listen, &addr, &addrlen)) == INVALID_SOCKET)
return FALSE;
- if (ioctlsocket(sdp->d2.com_data, FIONBIO, &nb) != 0) {
- printf("%s: Unable to setup non blocking mode on data socket\n", sdp->d2.com_name);
+ if (ioctlsocket(sdp->sd.com_data, FIONBIO, &nb) != 0) {
+ printf("%s: Unable to setup non blocking mode on data socket\n", sdp->sd.com_name);
goto abort;
}
sdAddFlagsI(sdp, SD_CONNECTED);
@@ -117,35 +117,35 @@ static bool_t connint(SerialDriver *sdp) { }
return FALSE;
abort:
- if (sdp->d2.com_listen != INVALID_SOCKET)
- closesocket(sdp->d2.com_listen);
- if (sdp->d2.com_data != INVALID_SOCKET)
- closesocket(sdp->d2.com_data);
+ if (sdp->sd.com_listen != INVALID_SOCKET)
+ closesocket(sdp->sd.com_listen);
+ if (sdp->sd.com_data != INVALID_SOCKET)
+ closesocket(sdp->sd.com_data);
WSACleanup();
exit(1);
}
static bool_t inint(SerialDriver *sdp) {
- if (sdp->d2.com_data != INVALID_SOCKET) {
+ if (sdp->sd.com_data != INVALID_SOCKET) {
int i;
uint8_t data[32];
/*
* Input.
*/
- int n = recv(sdp->d2.com_data, data, sizeof(data), 0);
+ int n = recv(sdp->sd.com_data, data, sizeof(data), 0);
switch (n) {
case 0:
- closesocket(sdp->d2.com_data);
- sdp->d2.com_data = INVALID_SOCKET;
+ closesocket(sdp->sd.com_data);
+ sdp->sd.com_data = INVALID_SOCKET;
sdAddFlagsI(sdp, SD_DISCONNECTED);
return FALSE;
case SOCKET_ERROR:
if (WSAGetLastError() == WSAEWOULDBLOCK)
return FALSE;
- closesocket(sdp->d2.com_data);
- sdp->d2.com_data = INVALID_SOCKET;
+ closesocket(sdp->sd.com_data);
+ sdp->sd.com_data = INVALID_SOCKET;
return FALSE;
}
for (i = 0; i < n; i++)
@@ -157,7 +157,7 @@ static bool_t inint(SerialDriver *sdp) { static bool_t outint(SerialDriver *sdp) {
- if (sdp->d2.com_data != INVALID_SOCKET) {
+ if (sdp->sd.com_data != INVALID_SOCKET) {
int n;
uint8_t data[1];
@@ -168,18 +168,18 @@ static bool_t outint(SerialDriver *sdp) { if (n < 0)
return FALSE;
data[0] = (uint8_t)n;
- n = send(sdp->d2.com_data, data, sizeof(data), 0);
+ n = send(sdp->sd.com_data, data, sizeof(data), 0);
switch (n) {
case 0:
- closesocket(sdp->d2.com_data);
- sdp->d2.com_data = INVALID_SOCKET;
+ closesocket(sdp->sd.com_data);
+ sdp->sd.com_data = INVALID_SOCKET;
sdAddFlagsI(sdp, SD_DISCONNECTED);
return FALSE;
case SOCKET_ERROR:
if (WSAGetLastError() == WSAEWOULDBLOCK)
return FALSE;
- closesocket(sdp->d2.com_data);
- sdp->d2.com_data = INVALID_SOCKET;
+ closesocket(sdp->sd.com_data);
+ sdp->sd.com_data = INVALID_SOCKET;
return FALSE;
}
return TRUE;
@@ -202,16 +202,16 @@ void sd_lld_init(void) { #if USE_WIN32_SERIAL1
sdObjectInit(&SD1, NULL, NULL);
- SD1.d2.com_listen = INVALID_SOCKET;
- SD1.d2.com_data = INVALID_SOCKET;
- SD1.d2.com_name = "SD1";
+ SD1.sd.com_listen = INVALID_SOCKET;
+ SD1.sd.com_data = INVALID_SOCKET;
+ SD1.sd.com_name = "SD1";
#endif
#if USE_WIN32_SERIAL1
sdObjectInit(&SD2, NULL, NULL);
- SD2.d2.com_listen = INVALID_SOCKET;
- SD2.d2.com_data = INVALID_SOCKET;
- SD2.d2.com_name = "SD2";
+ SD2.sd.com_listen = INVALID_SOCKET;
+ SD2.sd.com_data = INVALID_SOCKET;
+ SD2.sd.com_name = "SD2";
#endif
}
@@ -219,14 +219,11 @@ 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.
- * If this parameter is set to @p NULL then a default
- * configuration is used.
*/
-void sd_lld_start(SerialDriver *sdp, const SerialDriverConfig *config) {
+void sd_lld_start(SerialDriver *sdp) {
- if (config == NULL)
- config = &default_config;
+ if (sdp->sd.config == NULL)
+ sdp->sd.config = &default_config;
#if USE_WIN32_SERIAL1
if (sdp == &SD1)
diff --git a/os/hal/platforms/Win32/serial_lld.h b/os/hal/platforms/Win32/serial_lld.h index 4690fcb60..ed70a880a 100644 --- a/os/hal/platforms/Win32/serial_lld.h +++ b/os/hal/platforms/Win32/serial_lld.h @@ -88,62 +88,71 @@ typedef uint32_t sdflags_t;
/**
+ * @brief Generic Serial Driver configuration structure.
+ * @details An instance of this structure must be passed to @p sdStart()
+ * in order to configure and start a serial driver operations.
+ *
+ * @note This structure content is architecture dependent, each driver
+ * implementation defines its own version and the custom static
+ * initializers.
+ */
+typedef struct {
+} SerialConfig;
+
+/**
* @brief @p SerialDriver specific data.
*/
struct _serial_driver_data {
/**
- * Input queue, incoming data can be read from this input queue by
- * using the queues APIs.
+ * @brief Driver state.
+ */
+ sdstate_t state;
+ /**
+ * @brief Current configuration data.
*/
- InputQueue iqueue;
+ const SerialConfig *config;
/**
- * Output queue, outgoing data can be written to this output queue by
- * using the queues APIs.
+ * @brief Input queue, incoming data can be read from this input queue by
+ * using the queues APIs.
*/
- OutputQueue oqueue;
+ InputQueue iqueue;
/**
- * Status Change @p EventSource. This event is generated when one or more
- * condition flags change.
+ * @brief Output queue, outgoing data can be written to this output queue by
+ * using the queues APIs.
*/
- EventSource sevent;
+ OutputQueue oqueue;
/**
- * I/O driver status flags.
+ * @brief Status Change @p EventSource. This event is generated when one or
+ * more condition flags change.
*/
- sdflags_t flags;
+ EventSource sevent;
/**
- * Input circular buffer. + * @brief I/O driver status flags.
*/
- uint8_t ib[SERIAL_BUFFERS_SIZE];
+ sdflags_t flags;
/**
- * Output circular buffer. + * @brief Input circular buffer.
*/
- uint8_t ob[SERIAL_BUFFERS_SIZE];
+ uint8_t ib[SERIAL_BUFFERS_SIZE];
+ /**
+ * @brief Output circular buffer.
+ */
+ uint8_t ob[SERIAL_BUFFERS_SIZE];
+ /* End of the mandatory fields.*/
/**
* Listen socket for simulated serial port. */
- SOCKET com_listen;
+ SOCKET com_listen;
/**
* Data socket for simulated serial port.
*/
- SOCKET com_data;
+ SOCKET com_data;
/**
* Port readable name. */
- const char *com_name;
+ const char *com_name;
};
-/**
- * @brief Generic Serial Driver configuration structure.
- * @details An instance of this structure must be passed to @p sdStart()
- * in order to configure and start a serial driver operations.
- *
- * @note This structure content is architecture dependent, each driver
- * implementation defines its own version and the custom static
- * initializers.
- */
-typedef struct {
-} SerialDriverConfig;
-
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
@@ -160,7 +169,7 @@ extern SerialDriver SD2; extern "C" {
#endif
void sd_lld_init(void);
- void sd_lld_start(SerialDriver *sdp, const SerialDriverConfig *config);
+ void sd_lld_start(SerialDriver *sdp);
void sd_lld_stop(SerialDriver *sdp);
bool_t sd_lld_interrupt_pending(void);
#ifdef __cplusplus
diff --git a/os/hal/templates/can_lld.h b/os/hal/templates/can_lld.h index c6f0de0cb..6e55eb2c6 100644 --- a/os/hal/templates/can_lld.h +++ b/os/hal/templates/can_lld.h @@ -60,8 +60,8 @@ /* Derived constants and error checks. */
/*===========================================================================*/
-#if !CH_USE_SEMAPHORES || !CH_USE_EVENTS
-#error "the ADC driver requires CH_USE_SEMAPHORES and CH_USE_EVENTS"
+#if CAN_USE_SLEEP_MODE && !CAN_SUPPORTS_SLEEP
+#error "CAN sleep mode not supported in this architecture"
#endif
/*===========================================================================*/
diff --git a/os/hal/templates/serial_lld.c b/os/hal/templates/serial_lld.c index 63d1b09cf..cd155f210 100644 --- a/os/hal/templates/serial_lld.c +++ b/os/hal/templates/serial_lld.c @@ -38,7 +38,7 @@ /*===========================================================================*/
/** @brief Driver default configuration.*/
-static const SerialDriverConfig default_config = {
+static const SerialConfig default_config = {
};
/*===========================================================================*/
@@ -64,14 +64,11 @@ 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.
- * If this parameter is set to @p NULL then a default
- * configuration is used.
*/
-void sd_lld_start(SerialDriver *sdp, const SerialDriverConfig *config) {
+void sd_lld_start(SerialDriver *sdp) {
- if (config == NULL)
- config = &default_config;
+ if (sdp->sd.config == NULL)
+ sdp->sd.config = &default_config;
}
diff --git a/os/hal/templates/serial_lld.h b/os/hal/templates/serial_lld.h index 68d99c3e7..2a54fd56d 100644 --- a/os/hal/templates/serial_lld.h +++ b/os/hal/templates/serial_lld.h @@ -51,51 +51,60 @@ typedef uint8_t sdflags_t;
/**
+ * @brief Generic Serial Driver configuration structure.
+ * @details An instance of this structure must be passed to @p sdStart()
+ * in order to configure and start a serial driver operations.
+ *
+ * @note This structure content is architecture dependent, each driver
+ * implementation defines its own version and the custom static
+ * initializers.
+ */
+typedef struct {
+
+} SerialConfig;
+
+/**
* @brief @p SerialDriver specific data.
*/
struct _serial_driver_data {
/**
- * Input queue, incoming data can be read from this input queue by
- * using the queues APIs.
+ * @brief Driver state.
+ */
+ sdstate_t state;
+ /**
+ * @brief Current configuration data.
*/
- InputQueue iqueue;
+ const SerialConfig *config;
/**
- * Output queue, outgoing data can be written to this output queue by
- * using the queues APIs.
+ * @brief Input queue, incoming data can be read from this input queue by
+ * using the queues APIs.
*/
- OutputQueue oqueue;
+ InputQueue iqueue;
/**
- * Status Change @p EventSource. This event is generated when one or more
- * condition flags change.
+ * @brief Output queue, outgoing data can be written to this output queue by
+ * using the queues APIs.
*/
- EventSource sevent;
+ OutputQueue oqueue;
/**
- * I/O driver status flags.
+ * @brief Status Change @p EventSource. This event is generated when one or
+ * more condition flags change.
*/
- sdflags_t flags;
+ EventSource sevent;
/**
- * Input circular buffer. + * @brief I/O driver status flags.
*/
- uint8_t ib[SERIAL_BUFFERS_SIZE];
+ sdflags_t flags;
/**
- * Output circular buffer. + * @brief Input circular buffer.
*/
- uint8_t ob[SERIAL_BUFFERS_SIZE];
+ uint8_t ib[SERIAL_BUFFERS_SIZE];
+ /**
+ * @brief Output circular buffer.
+ */
+ uint8_t ob[SERIAL_BUFFERS_SIZE];
+ /* End of the mandatory fields.*/
};
-/**
- * @brief Generic Serial Driver configuration structure.
- * @details An instance of this structure must be passed to @p sdStart()
- * in order to configure and start a serial driver operations.
- *
- * @note This structure content is architecture dependent, each driver
- * implementation defines its own version and the custom static
- * initializers.
- */
-typedef struct {
-
-} SerialDriverConfig;
-
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
@@ -108,7 +117,7 @@ typedef struct { extern "C" {
#endif
void sd_lld_init(void);
- void sd_lld_start(SerialDriver *sdp, const SerialDriverConfig *config);
+ void sd_lld_start(SerialDriver *sdp);
void sd_lld_stop(SerialDriver *sdp);
#ifdef __cplusplus
}
|