diff options
Diffstat (limited to 'os/hal/platforms/AVR')
-rw-r--r-- | os/hal/platforms/AVR/serial_lld.c | 39 | ||||
-rw-r--r-- | os/hal/platforms/AVR/serial_lld.h | 79 |
2 files changed, 62 insertions, 56 deletions
diff --git a/os/hal/platforms/AVR/serial_lld.c b/os/hal/platforms/AVR/serial_lld.c index 166663c44..0244471a6 100644 --- a/os/hal/platforms/AVR/serial_lld.c +++ b/os/hal/platforms/AVR/serial_lld.c @@ -58,7 +58,7 @@ SerialDriver SD2; /**
* @brief Driver default configuration.
*/
-static const SerialDriverConfig default_config = {
+static const SerialConfig default_config = {
UBRR(DEFAULT_USART_BITRATE),
(1 << UCSZ1) | (1 << UCSZ0)
};
@@ -91,13 +91,13 @@ static void notify1(void) { * @brief USART0 initialization.
* @param[in] config the architecture-dependent serial driver configuration
*/
-static void usart0_init(const SerialDriverConfig *config) {
+static void usart0_init(const SerialConfig *config) {
- UBRR0L = config->brr;
- UBRR0H = config->brr >> 8;
+ UBRR0L = config->sc_brr;
+ UBRR0H = config->sc_brr >> 8;
UCSR0A = 0;
UCSR0B = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE);
- UCSR0C = config->csrc;
+ UCSR0C = config->sc_csrc;
}
/**
@@ -121,13 +121,13 @@ static void notify2(void) { * @brief USART1 initialization.
* @param[in] config the architecture-dependent serial driver configuration
*/
-static void usart1_init(const SerialDriverConfig *config) {
+static void usart1_init(const SerialConfig *config) {
- UBRR1L = config->brr;
- UBRR1H = config->brr >> 8;
+ UBRR1L = config->sc_brr;
+ UBRR1H = config->sc_brr >> 8;
UCSR1A = 0;
UCSR1B = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE);
- UCSR1C = config->csrc;
+ UCSR1C = config->sc_csrc;
}
/**
@@ -232,20 +232,19 @@ 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_AVR_USART0
- usart0_init(config);
+ if (&SD1 == sdp)
+ usart0_init(sdp->sd.config);
#endif
#if USE_AVR_USART1
- usart1_init(config);
+ if (&SD2 == sdp)
+ usart1_init(sdp->sd.config);
#endif
}
@@ -259,10 +258,12 @@ void sd_lld_start(SerialDriver *sdp, const SerialDriverConfig *config) { void sd_lld_stop(SerialDriver *sdp) {
#if USE_AVR_USART0
- usart0_deinit();
+ if (&SD1 == sdp)
+ usart0_deinit();
#endif
#if USE_AVR_USART1
- usart1_deinit();
+ if (&SD2 == sdp)
+ usart1_deinit();
#endif
}
diff --git a/os/hal/platforms/AVR/serial_lld.h b/os/hal/platforms/AVR/serial_lld.h index ad0ffdd3a..79d070635 100644 --- a/os/hal/platforms/AVR/serial_lld.h +++ b/os/hal/platforms/AVR/serial_lld.h @@ -38,16 +38,6 @@ /*===========================================================================*/
/**
- * @brief Serial buffers size.
- * @details Configuration parameter, you can change the depth of the queue
- * buffers depending on the requirements of your application.
- * @note The default is 32 bytes for both the transmission and receive buffers.
- */
-#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
-#define SERIAL_BUFFERS_SIZE 32
-#endif
-
-/**
* @brief Default bit rate.
* @details Configuration parameter, at startup the UARTs are configured at
* this speed.
@@ -86,53 +76,68 @@ /*===========================================================================*/
/**
- * Serial Driver condition flags type.
+ * @brief Serial Driver condition flags type.
*/
typedef uint8_t sdflags_t;
/**
+ * @brief AVR 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.
+ */
+typedef struct {
+ /**
+ * @brief Initialization value for the BRR register.
+ */
+ uint16_t sc_brr;
+ /**
+ * @brief Initialization value for the CSRC register.
+ */
+ uint8_t sc_csrc;
+} 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 AVR 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.
- */
-typedef struct {
- uint16_t brr;
- uint8_t csrc;
-} SerialDriverConfig;
-
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
@@ -159,7 +164,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);
#ifdef __cplusplus
}
|