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
* @brief LPC214x low level serial driver code.
*
* @addtogroup LPC214x_SERIAL
* @{
*/
@ -62,16 +63,17 @@ static const SerialConfig default_config = {
* @brief UART initialization.
*
* @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;
@ -123,10 +125,11 @@ __attribute__((noinline))
#endif
/**
* @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
* @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) {
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) {
@ -277,11 +280,14 @@ 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) {
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,7 +303,7 @@ void sd_lld_start(SerialDriver *sdp) {
}
#endif
}
uart_init(sdp);
uart_init(sdp, config);
}
/**

View File

@ -20,6 +20,7 @@
/**
* @file LPC214x/serial_lld.h
* @brief LPC214x low level serial driver header.
*
* @addtogroup LPC214x_SERIAL
* @{
*/
@ -58,8 +59,8 @@
/**
* @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.
* 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.
@ -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
}

View File

@ -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