git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1883 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
75792b3d6a
commit
f843a37153
|
@ -18,8 +18,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
@ -47,7 +48,7 @@ SerialDriver SD2;
|
||||||
/* Driver local variables. */
|
/* Driver local variables. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
/** @brief Driver default configuration.*/
|
/** @brief Driver default configuration.*/
|
||||||
static const SerialConfig default_config = {
|
static const SerialConfig default_config = {
|
||||||
SERIAL_DEFAULT_BITRATE,
|
SERIAL_DEFAULT_BITRATE,
|
||||||
LCR_WL8 | LCR_STOP1 | LCR_NOPARITY,
|
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;
|
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;
|
||||||
|
@ -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) {
|
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] sdp communication channel associated to the UART
|
||||||
* @param[in] err UART LSR register value
|
* @param[in] err UART LSR register value
|
||||||
*/
|
*/
|
||||||
static void set_error(SerialDriver *sdp, IOREG32 err) {
|
static void set_error(SerialDriver *sdp, IOREG32 err) {
|
||||||
sdflags_t sts = 0;
|
sdflags_t sts = 0;
|
||||||
|
@ -122,11 +124,12 @@ static void set_error(SerialDriver *sdp, IOREG32 err) {
|
||||||
__attribute__((noinline))
|
__attribute__((noinline))
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* @brief Common IRQ handler.
|
* @brief Common IRQ handler.
|
||||||
* @param[in] u pointer to an UART I/O block
|
* @note Tries hard to clear all the pending interrupt sources, we dont want
|
||||||
* @param[in] sdp communication channel associated to the UART
|
* to go through the whole ISR and have another interrupt soon after.
|
||||||
* @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) {
|
static void serve_interrupt(SerialDriver *sdp) {
|
||||||
UART *u = sdp->uart;
|
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) {
|
static void preload(SerialDriver *sdp) {
|
||||||
UART *u = sdp->uart;
|
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__)
|
#if USE_LPC214x_UART0 || defined(__DOXYGEN__)
|
||||||
static void notify1(void) {
|
static void notify1(void) {
|
||||||
|
@ -209,7 +212,7 @@ static void notify1(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Driver SD2 output notification.
|
* @brief Driver SD2 output notification.
|
||||||
*/
|
*/
|
||||||
#if USE_LPC214x_UART1 || defined(__DOXYGEN__)
|
#if USE_LPC214x_UART1 || defined(__DOXYGEN__)
|
||||||
static void notify2(void) {
|
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__)
|
#if USE_LPC214x_UART0 || defined(__DOXYGEN__)
|
||||||
CH_IRQ_HANDLER(UART0IrqHandler) {
|
CH_IRQ_HANDLER(UART0IrqHandler) {
|
||||||
|
@ -238,7 +241,7 @@ CH_IRQ_HANDLER(UART0IrqHandler) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief UART1 IRQ handler.
|
* @brief UART1 IRQ handler.
|
||||||
*/
|
*/
|
||||||
#if USE_LPC214x_UART1 || defined(__DOXYGEN__)
|
#if USE_LPC214x_UART1 || defined(__DOXYGEN__)
|
||||||
CH_IRQ_HANDLER(UART1IrqHandler) {
|
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) {
|
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)
|
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,15 +303,15 @@ void sd_lld_start(SerialDriver *sdp) {
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
* @details De-initializes the UART, stops the associated clock, resets the
|
||||||
* interrupt vector.
|
* 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) {
|
void sd_lld_stop(SerialDriver *sdp) {
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
@ -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.
|
* @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__)
|
#if !defined(USE_LPC214x_UART0) || defined(__DOXYGEN__)
|
||||||
#define USE_LPC214x_UART0 TRUE
|
#define USE_LPC214x_UART0 TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief UART1 driver enable switch.
|
* @brief UART1 driver enable switch.
|
||||||
* @details If set to @p TRUE the support for UART1 is included.
|
* @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__)
|
#if !defined(USE_LPC214x_UART1) || defined(__DOXYGEN__)
|
||||||
#define USE_LPC214x_UART1 TRUE
|
#define USE_LPC214x_UART1 TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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.
|
||||||
*/
|
*/
|
||||||
#if !defined(LPC214x_UART_FIFO_PRELOAD) || defined(__DOXYGEN__)
|
#if !defined(LPC214x_UART_FIFO_PRELOAD) || defined(__DOXYGEN__)
|
||||||
#define LPC214x_UART_FIFO_PRELOAD 16
|
#define LPC214x_UART_FIFO_PRELOAD 16
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief UART0 interrupt priority level setting.
|
* @brief UART0 interrupt priority level setting.
|
||||||
*/
|
*/
|
||||||
#if !defined(LPC214x_UART0_PRIORITY) || defined(__DOXYGEN__)
|
#if !defined(LPC214x_UART0_PRIORITY) || defined(__DOXYGEN__)
|
||||||
#define LPC214x_UART0_PRIORITY 1
|
#define LPC214x_UART0_PRIORITY 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief UART1 interrupt priority level setting.
|
* @brief UART1 interrupt priority level setting.
|
||||||
*/
|
*/
|
||||||
#if !defined(LPC214x_UART1_PRIORITY) || defined(__DOXYGEN__)
|
#if !defined(LPC214x_UART1_PRIORITY) || defined(__DOXYGEN__)
|
||||||
#define LPC214x_UART1_PRIORITY 2
|
#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;
|
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()
|
* @details An instance of this structure must be passed to @p sdStart()
|
||||||
* in order to configure and start a serial driver operations.
|
* in order to configure and start a serial driver operations.
|
||||||
*/
|
*/
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue