git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1883 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2010-04-21 17:42:35 +00:00
parent 75792b3d6a
commit f843a37153
3 changed files with 62 additions and 57 deletions

View File

@ -20,6 +20,7 @@
/** /**
* @file LPC214x/serial_lld.c * @file LPC214x/serial_lld.c
* @brief LPC214x low level serial driver code. * @brief LPC214x low level serial driver code.
*
* @addtogroup LPC214x_SERIAL * @addtogroup LPC214x_SERIAL
* @{ * @{
*/ */
@ -62,16 +63,17 @@ 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; UART *u = sdp->uart;
uint32_t div = PCLK / (sdp->config->sc_speed << 4); uint32_t div = PCLK / (config->sc_speed << 4);
u->UART_LCR = sdp->config->sc_lcr | LCR_DLAB; u->UART_LCR = config->sc_lcr | LCR_DLAB;
u->UART_DLL = div; u->UART_DLL = div;
u->UART_DLM = div >> 8; u->UART_DLM = div >> 8;
u->UART_LCR = sdp->config->sc_lcr; u->UART_LCR = config->sc_lcr;
u->UART_FCR = FCR_ENABLE | FCR_RXRESET | FCR_TXRESET | sdp->config->sc_fcr; u->UART_FCR = FCR_ENABLE | FCR_RXRESET | FCR_TXRESET | config->sc_fcr;
u->UART_ACR = 0; u->UART_ACR = 0;
u->UART_FDR = 0x10; u->UART_FDR = 0x10;
u->UART_TER = TER_ENABLE; u->UART_TER = TER_ENABLE;
@ -123,10 +125,11 @@ __attribute__((noinline))
#endif #endif
/** /**
* @brief Common IRQ handler. * @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] u pointer to an UART I/O block
* @param[in] sdp communication channel associated to the UART * @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.
*/ */
static void serve_interrupt(SerialDriver *sdp) { static void serve_interrupt(SerialDriver *sdp) {
UART *u = sdp->uart; UART *u = sdp->uart;
@ -257,7 +260,7 @@ CH_IRQ_HANDLER(UART1IrqHandler) {
/*===========================================================================*/ /*===========================================================================*/
/** /**
* Low level serial driver initialization. * @brief Low level serial driver initialization.
*/ */
void sd_lld_init(void) { void sd_lld_init(void) {
@ -277,11 +280,14 @@ 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) if (config == NULL)
sdp->config = &default_config; config = &default_config;
if (sdp->state == SD_STOP) { if (sdp->state == SD_STOP) {
#if USE_LPC214x_UART0 #if USE_LPC214x_UART0
@ -297,7 +303,7 @@ void sd_lld_start(SerialDriver *sdp) {
} }
#endif #endif
} }
uart_init(sdp); uart_init(sdp, config);
} }
/** /**

View File

@ -20,6 +20,7 @@
/** /**
* @file LPC214x/serial_lld.h * @file LPC214x/serial_lld.h
* @brief LPC214x low level serial driver header. * @brief LPC214x low level serial driver header.
*
* @addtogroup LPC214x_SERIAL * @addtogroup LPC214x_SERIAL
* @{ * @{
*/ */
@ -58,8 +59,8 @@
/** /**
* @brief FIFO preload parameter. * @brief FIFO preload parameter.
* @details Configuration parameter, this values defines how many bytes are * @details Configuration parameter, this values defines how many bytes are
* preloaded in the HW transmit FIFO for each interrupt, the maximum value is * preloaded in the HW transmit FIFO for each interrupt, the maximum
* 16 the minimum is 1. * value is 16 the minimum is 1.
* @note An high value reduces the number of interrupts generated but can * @note An high value reduces the number of interrupts generated but can
* also increase the worst case interrupt response time because the * also increase the worst case interrupt response time because the
* preload loops. * preload loops.
@ -126,8 +127,6 @@ typedef struct {
_base_asynchronous_channel_data \ _base_asynchronous_channel_data \
/* Driver state.*/ \ /* Driver state.*/ \
sdstate_t state; \ sdstate_t state; \
/* Current configuration data.*/ \
const SerialConfig *config; \
/* Input queue.*/ \ /* Input queue.*/ \
InputQueue iqueue; \ InputQueue iqueue; \
/* Output queue.*/ \ /* Output queue.*/ \
@ -163,7 +162,7 @@ extern SerialDriver SD2;
extern "C" { extern "C" {
#endif #endif
void sd_lld_init(void); 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); void sd_lld_stop(SerialDriver *sdp);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -264,18 +264,18 @@ void sd_lld_init(void) {
*/ */
void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) { void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {
if (sdp->config == NULL) if (config == NULL)
sdp->config = &default_config; config = &default_config;
#if USE_MSP430_USART0 #if USE_MSP430_USART0
if (&SD1 == sdp) { if (&SD1 == sdp) {
usart0_init(sdp->config); usart0_init(config);
return; return;
} }
#endif #endif
#if USE_MSP430_USART1 #if USE_MSP430_USART1
if (&SD2 == sdp) { if (&SD2 == sdp) {
usart1_init(sdp->config); usart1_init(config);
return; return;
} }
#endif #endif