diff --git a/os/hal/platforms/LPC214x/serial_lld.c b/os/hal/platforms/LPC214x/serial_lld.c index d79ba22d2..21c39f674 100644 --- a/os/hal/platforms/LPC214x/serial_lld.c +++ b/os/hal/platforms/LPC214x/serial_lld.c @@ -18,8 +18,9 @@ */ /** - * @file LPC214x/serial_lld.c - * @brief LPC214x low level serial driver code. + * @file LPC214x/serial_lld.c + * @brief LPC214x low level serial driver code. + * * @addtogroup LPC214x_SERIAL * @{ */ @@ -47,7 +48,7 @@ SerialDriver SD2; /* Driver local variables. */ /*===========================================================================*/ -/** @brief Driver default configuration.*/ +/** @brief Driver default configuration.*/ static const SerialConfig default_config = { SERIAL_DEFAULT_BITRATE, LCR_WL8 | LCR_STOP1 | LCR_NOPARITY, @@ -59,19 +60,20 @@ static const SerialConfig default_config = { /*===========================================================================*/ /** - * @brief UART initialization. + * @brief UART initialization. * - * @param[in] sdp communication channel associated to the UART + * @param[in] sdp communication channel associated to the UART + * @param[in] config the architecture-dependent serial driver configuration */ -static void uart_init(SerialDriver *sdp) { +static void uart_init(SerialDriver *sdp, const SerialConfig *config) { UART *u = sdp->uart; - uint32_t div = PCLK / (sdp->config->sc_speed << 4); - u->UART_LCR = sdp->config->sc_lcr | LCR_DLAB; + uint32_t div = PCLK / (config->sc_speed << 4); + u->UART_LCR = config->sc_lcr | LCR_DLAB; u->UART_DLL = div; u->UART_DLM = div >> 8; - u->UART_LCR = sdp->config->sc_lcr; - u->UART_FCR = FCR_ENABLE | FCR_RXRESET | FCR_TXRESET | sdp->config->sc_fcr; + u->UART_LCR = config->sc_lcr; + u->UART_FCR = FCR_ENABLE | FCR_RXRESET | FCR_TXRESET | config->sc_fcr; u->UART_ACR = 0; u->UART_FDR = 0x10; u->UART_TER = TER_ENABLE; @@ -79,9 +81,9 @@ static void uart_init(SerialDriver *sdp) { } /** - * @brief UART de-initialization. + * @brief UART de-initialization. * - * @param[in] u pointer to an UART I/O block + * @param[in] u pointer to an UART I/O block */ static void uart_deinit(UART *u) { @@ -97,10 +99,10 @@ static void uart_deinit(UART *u) { } /** - * @brief Error handling routine. + * @brief Error handling routine. * - * @param[in] sdp communication channel associated to the UART - * @param[in] err UART LSR register value + * @param[in] sdp communication channel associated to the UART + * @param[in] err UART LSR register value */ static void set_error(SerialDriver *sdp, IOREG32 err) { sdflags_t sts = 0; @@ -122,11 +124,12 @@ static void set_error(SerialDriver *sdp, IOREG32 err) { __attribute__((noinline)) #endif /** - * @brief Common IRQ handler. - * @param[in] u pointer to an UART I/O block - * @param[in] sdp communication channel associated to the UART - * @note Tries hard to clear all the pending interrupt sources, we dont want to - * go through the whole ISR and have another interrupt soon after. + * @brief Common IRQ handler. + * @note Tries hard to clear all the pending interrupt sources, we dont want + * to go through the whole ISR and have another interrupt soon after. + * + * @param[in] u pointer to an UART I/O block + * @param[in] sdp communication channel associated to the UART */ static void serve_interrupt(SerialDriver *sdp) { UART *u = sdp->uart; @@ -179,7 +182,7 @@ static void serve_interrupt(SerialDriver *sdp) { } /** - * @brief Attempts a TX FIFO preload. + * @brief Attempts a TX FIFO preload. */ static void preload(SerialDriver *sdp) { UART *u = sdp->uart; @@ -199,7 +202,7 @@ static void preload(SerialDriver *sdp) { } /** - * @brief Driver SD1 output notification. + * @brief Driver SD1 output notification. */ #if USE_LPC214x_UART0 || defined(__DOXYGEN__) static void notify1(void) { @@ -209,7 +212,7 @@ static void notify1(void) { #endif /** - * @brief Driver SD2 output notification. + * @brief Driver SD2 output notification. */ #if USE_LPC214x_UART1 || defined(__DOXYGEN__) static void notify2(void) { @@ -223,7 +226,7 @@ static void notify2(void) { /*===========================================================================*/ /** - * @brief UART0 IRQ handler. + * @brief UART0 IRQ handler. */ #if USE_LPC214x_UART0 || defined(__DOXYGEN__) CH_IRQ_HANDLER(UART0IrqHandler) { @@ -238,7 +241,7 @@ CH_IRQ_HANDLER(UART0IrqHandler) { #endif /** - * @brief UART1 IRQ handler. + * @brief UART1 IRQ handler. */ #if USE_LPC214x_UART1 || defined(__DOXYGEN__) CH_IRQ_HANDLER(UART1IrqHandler) { @@ -257,7 +260,7 @@ CH_IRQ_HANDLER(UART1IrqHandler) { /*===========================================================================*/ /** - * Low level serial driver initialization. + * @brief Low level serial driver initialization. */ void sd_lld_init(void) { @@ -274,14 +277,17 @@ void sd_lld_init(void) { } /** - * @brief Low level serial driver configuration and (re)start. + * @brief Low level serial driver configuration and (re)start. * - * @param[in] sdp pointer to a @p SerialDriver object + * @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) { +void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) { - if (sdp->config == NULL) - sdp->config = &default_config; + if (config == NULL) + config = &default_config; if (sdp->state == SD_STOP) { #if USE_LPC214x_UART0 @@ -297,15 +303,15 @@ void sd_lld_start(SerialDriver *sdp) { } #endif } - uart_init(sdp); + uart_init(sdp, config); } /** - * @brief Low level serial driver stop. + * @brief Low level serial driver stop. * @details De-initializes the UART, stops the associated clock, resets the * interrupt vector. * - * @param[in] sdp pointer to a @p SerialDriver object + * @param[in] sdp pointer to a @p SerialDriver object */ void sd_lld_stop(SerialDriver *sdp) { diff --git a/os/hal/platforms/LPC214x/serial_lld.h b/os/hal/platforms/LPC214x/serial_lld.h index 6d47f9d95..a5cea7538 100644 --- a/os/hal/platforms/LPC214x/serial_lld.h +++ b/os/hal/platforms/LPC214x/serial_lld.h @@ -18,8 +18,9 @@ */ /** - * @file LPC214x/serial_lld.h - * @brief LPC214x low level serial driver header. + * @file LPC214x/serial_lld.h + * @brief LPC214x low level serial driver header. + * * @addtogroup LPC214x_SERIAL * @{ */ @@ -38,45 +39,45 @@ /*===========================================================================*/ /** - * @brief UART0 driver enable switch. + * @brief UART0 driver enable switch. * @details If set to @p TRUE the support for UART0 is included. - * @note The default is @p TRUE . + * @note The default is @p TRUE . */ #if !defined(USE_LPC214x_UART0) || defined(__DOXYGEN__) #define USE_LPC214x_UART0 TRUE #endif /** - * @brief UART1 driver enable switch. + * @brief UART1 driver enable switch. * @details If set to @p TRUE the support for UART1 is included. - * @note The default is @p TRUE. + * @note The default is @p TRUE. */ #if !defined(USE_LPC214x_UART1) || defined(__DOXYGEN__) #define USE_LPC214x_UART1 TRUE #endif /** - * @brief FIFO preload parameter. + * @brief FIFO preload parameter. * @details Configuration parameter, this values defines how many bytes are - * preloaded in the HW transmit FIFO for each interrupt, the maximum value is - * 16 the minimum is 1. - * @note An high value reduces the number of interrupts generated but can - * also increase the worst case interrupt response time because the - * preload loops. + * preloaded in the HW transmit FIFO for each interrupt, the maximum + * value is 16 the minimum is 1. + * @note An high value reduces the number of interrupts generated but can + * also increase the worst case interrupt response time because the + * preload loops. */ #if !defined(LPC214x_UART_FIFO_PRELOAD) || defined(__DOXYGEN__) #define LPC214x_UART_FIFO_PRELOAD 16 #endif /** - * @brief UART0 interrupt priority level setting. + * @brief UART0 interrupt priority level setting. */ #if !defined(LPC214x_UART0_PRIORITY) || defined(__DOXYGEN__) #define LPC214x_UART0_PRIORITY 1 #endif /** - * @brief UART1 interrupt priority level setting. + * @brief UART1 interrupt priority level setting. */ #if !defined(LPC214x_UART1_PRIORITY) || defined(__DOXYGEN__) #define LPC214x_UART1_PRIORITY 2 @@ -95,12 +96,12 @@ /*===========================================================================*/ /** - * @brief Serial Driver condition flags type. + * @brief Serial Driver condition flags type. */ typedef uint32_t sdflags_t; /** - * @brief LPC214x Serial Driver configuration structure. + * @brief LPC214x 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. */ @@ -126,8 +127,6 @@ typedef struct { _base_asynchronous_channel_data \ /* Driver state.*/ \ sdstate_t state; \ - /* Current configuration data.*/ \ - const SerialConfig *config; \ /* Input queue.*/ \ InputQueue iqueue; \ /* Output queue.*/ \ @@ -163,7 +162,7 @@ extern SerialDriver SD2; extern "C" { #endif void sd_lld_init(void); - void sd_lld_start(SerialDriver *sdp); + void sd_lld_start(SerialDriver *sdp, const SerialConfig *config); void sd_lld_stop(SerialDriver *sdp); #ifdef __cplusplus } diff --git a/os/hal/platforms/MSP430/serial_lld.c b/os/hal/platforms/MSP430/serial_lld.c index 8186813fb..4ab12a872 100644 --- a/os/hal/platforms/MSP430/serial_lld.c +++ b/os/hal/platforms/MSP430/serial_lld.c @@ -264,18 +264,18 @@ void sd_lld_init(void) { */ void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) { - if (sdp->config == NULL) - sdp->config = &default_config; + if (config == NULL) + config = &default_config; #if USE_MSP430_USART0 if (&SD1 == sdp) { - usart0_init(sdp->config); + usart0_init(config); return; } #endif #if USE_MSP430_USART1 if (&SD2 == sdp) { - usart1_init(sdp->config); + usart1_init(config); return; } #endif