From 7d7af240fb9c9f22fc5f2359752385faba4f94c1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 2 Jan 2010 10:00:15 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1487 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/MSP430/serial_lld.c | 61 ++++++++++++----------- os/hal/platforms/MSP430/serial_lld.h | 93 ++++++++++++++++++------------------ 2 files changed, 76 insertions(+), 78 deletions(-) (limited to 'os/hal/platforms/MSP430') diff --git a/os/hal/platforms/MSP430/serial_lld.c b/os/hal/platforms/MSP430/serial_lld.c index caa0e99d0..fd9dc19bf 100644 --- a/os/hal/platforms/MSP430/serial_lld.c +++ b/os/hal/platforms/MSP430/serial_lld.c @@ -49,8 +49,8 @@ SerialDriver SD2; /*===========================================================================*/ /** @brief Driver default configuration.*/ -static const SerialDriverConfig default_config = { - UBR(DEFAULT_USART_BITRATE), +static const SerialConfig default_config = { + UBR(SERIAL_DEFAULT_BITRATE), 0, CHAR }; @@ -59,7 +59,7 @@ static const SerialDriverConfig default_config = { /* Driver local functions. */ /*===========================================================================*/ -static void set_error(uint8_t urctl, SerialDriver *sdp) { +static void set_error(SerialDriver *sdp, uint8_t urctl) { sdflags_t sts = 0; if (urctl & OE) @@ -88,23 +88,24 @@ 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) { - U0CTL = SWRST; /* Resets the USART, it should already be.*/ + U0CTL = SWRST; /* Resets the USART. */ /* USART init */ - U0TCTL = SSEL0 | SSEL1; /* SMCLK as clock source.*/ - U0MCTL = config->mod; /* Modulator.*/ - U0BR1 = (uint8_t)(config->div >> 8); /* Divider high.*/ - U0BR0 = (uint8_t)(config->div >> 0); /* Divider low.*/ + U0TCTL = SSEL0 | SSEL1; /* SMCLK as clock source. */ + U0MCTL = config->sc_mod; /* Modulator. */ + U0BR1 = (uint8_t)(config->sc_div >> 8); /* Divider high. */ + U0BR0 = (uint8_t)(config->sc_div >> 0); /* Divider low. */ /* Clear USART status.*/ (void)U0RXBUF; U0RCTL = 0; /* USART enable.*/ - U0ME |= UTXE0 + URXE0; /* Enables the USART.*/ - U0CTL = config->ctl & ~SWRST; /* Various settings, clears reset state.*/ - U0IE |= URXIE0; /* Enables RX interrupt.*/ + U0ME |= UTXE0 + URXE0; /* Enables the USART. */ + U0CTL = config->sc_ctl & ~SWRST; /* Various settings. */ + U0IE |= URXIE0; /* Enables RX interrupt. */ } /** @@ -128,23 +129,24 @@ 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) { - U1CTL = SWRST; /* Resets the USART, it should already be.*/ + U1CTL = SWRST; /* Resets the USART. */ /* USART init.*/ - U1TCTL = SSEL0 | SSEL1; /* SMCLK as clock source.*/ - U1MCTL = config->mod; /* Modulator.*/ - U1BR1 = (uint8_t)(config->div >> 8); /* Divider high.*/ - U1BR0 = (uint8_t)(config->div >> 0); /* Divider low.*/ + U1TCTL = SSEL0 | SSEL1; /* SMCLK as clock source. */ + U1MCTL = config->sc_mod; /* Modulator. */ + U1BR1 = (uint8_t)(config->sc_div >> 8); /* Divider high. */ + U1BR0 = (uint8_t)(config->sc_div >> 0); /* Divider low. */ /* Clear USART status.*/ (void)U0RXBUF; U1RCTL = 0; /* USART enable.*/ - U1ME |= UTXE0 + URXE0; /* Enables the USART.*/ - U1CTL = config->ctl & ~SWRST; /* Various settings, clears reset state.*/ - U1IE |= URXIE0; /* Enables RX interrupt.*/ + U1ME |= UTXE0 + URXE0; /* Enables the USART. */ + U1CTL = config->sc_ctl & ~SWRST; /* Various settings. */ + U1IE |= URXIE0; /* Enables RX interrupt. */ } /** @@ -184,7 +186,7 @@ CH_IRQ_HANDLER(USART0RX_VECTOR) { CH_IRQ_PROLOGUE(); if ((urctl = U0RCTL) & RXERR) - set_error(urctl, &SD1); + set_error(&SD1, urctl); chSysLockFromIsr(); sdIncomingDataI(&SD1, U0RXBUF); chSysUnlockFromIsr(); @@ -216,7 +218,7 @@ CH_IRQ_HANDLER(USART1RX_VECTOR) { CH_IRQ_PROLOGUE(); if ((urctl = U1RCTL) & RXERR) - set_error(urctl, &SD2); + set_error(&SD2, urctl); chSysLockFromIsr(); sdIncomingDataI(&SD2, U1RXBUF); chSysUnlockFromIsr(); @@ -251,24 +253,21 @@ 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_MSP430_USART0 if (&SD1 == sdp) { - usart0_init(config); + usart0_init(sdp->sd.config); return; } #endif #if USE_MSP430_USART1 if (&SD2 == sdp) { - usart1_init(config); + usart1_init(sdp->sd.config); return; } #endif diff --git a/os/hal/platforms/MSP430/serial_lld.h b/os/hal/platforms/MSP430/serial_lld.h index fa56d32d8..8b8f80d30 100644 --- a/os/hal/platforms/MSP430/serial_lld.h +++ b/os/hal/platforms/MSP430/serial_lld.h @@ -37,25 +37,6 @@ /* Driver pre-compile time settings. */ /*===========================================================================*/ -/** - * @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. - */ -#if !defined(DEFAULT_USART_BITRATE) || defined(__DOXYGEN__) -#define DEFAULT_USART_BITRATE 38400 -#endif - /** * @brief USART0 driver enable switch. * @details If set to @p TRUE the support for USART0 is included. @@ -71,7 +52,7 @@ * @note The default is @p FALSE. */ #if !defined(USE_MSP430_USART1) || defined(__DOXYGEN__) -#define USE_MSP430_USART1 FALSE +#define USE_MSP430_USART1 TRUE #endif /*===========================================================================*/ @@ -87,50 +68,68 @@ */ typedef uint8_t sdflags_t; +/** + * @brief MSP430 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 UBRx registers. + */ + uint16_t sc_div; + /** + * @brief Initialization value for the MOD register. + */ + uint8_t sc_mod; + /** + * @brief Initialization value for the CTL register. + */ + uint8_t sc_ctl; +} 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. + */ + const SerialConfig *config; + /** + * @brief Input queue, incoming data can be read from this input queue by + * using the queues APIs. */ - InputQueue iqueue; + InputQueue iqueue; /** - * Output queue, outgoing data can be written to this output queue by - * using the queues APIs. + * @brief Output queue, outgoing data can be written to this output queue by + * using the queues APIs. */ - OutputQueue oqueue; + OutputQueue oqueue; /** - * Status Change @p EventSource. This event is generated when one or more - * condition flags change. + * @brief Status Change @p EventSource. This event is generated when one or + * more condition flags change. */ - EventSource sevent; + EventSource sevent; /** - * I/O driver status flags. + * @brief I/O driver status flags. */ - sdflags_t flags; + sdflags_t flags; /** - * Input circular buffer. + * @brief Input circular buffer. */ - uint8_t ib[SERIAL_BUFFERS_SIZE]; + uint8_t ib[SERIAL_BUFFERS_SIZE]; /** - * Output circular buffer. + * @brief Output circular buffer. */ - uint8_t ob[SERIAL_BUFFERS_SIZE]; + uint8_t ob[SERIAL_BUFFERS_SIZE]; + /* End of the mandatory fields.*/ }; -/** - * @brief MSP430 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 div; - uint8_t mod; - uint8_t ctl; -} SerialDriverConfig; - /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ @@ -157,7 +156,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 } -- cgit v1.2.3