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

This commit is contained in:
gdisirio 2010-01-02 10:00:15 +00:00
parent 307e9891e4
commit 7d7af240fb
5 changed files with 109 additions and 92 deletions

View File

@ -54,6 +54,15 @@
/* Driver pre-compile time settings. */
/*===========================================================================*/
/**
* @brief Default bit rate.
* @details Configuration parameter, this is the baud rate selected for the
* default configuration.
*/
#if !defined(DEFAULT_USART_BITRATE) || defined(__DOXYGEN__)
#define SERIAL_DEFAULT_BITRATE 38400
#endif
/**
* @brief Serial buffers size.
* @details Configuration parameter, you can change the depth of the queue
@ -61,7 +70,7 @@
* @note The default is 64 bytes for both the transmission and receive buffers.
*/
#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
#define SERIAL_BUFFERS_SIZE 128
#define SERIAL_BUFFERS_SIZE 64
#endif
/*===========================================================================*/

View File

@ -239,12 +239,16 @@ void sd_lld_start(SerialDriver *sdp) {
sdp->sd.config = &default_config;
#if USE_AVR_USART0
if (&SD1 == sdp)
if (&SD1 == sdp) {
usart0_init(sdp->sd.config);
return;
}
#endif
#if USE_AVR_USART1
if (&SD2 == sdp)
if (&SD2 == sdp) {
usart1_init(sdp->sd.config);
return;
}
#endif
}

View File

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

View File

@ -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,49 +68,67 @@
*/
typedef uint8_t sdflags_t;
/**
* @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.
*/
InputQueue iqueue;
/**
* Output queue, outgoing data can be written to this output queue by
* using the queues APIs.
*/
OutputQueue oqueue;
/**
* Status Change @p EventSource. This event is generated when one or more
* condition flags change.
*/
EventSource sevent;
/**
* I/O driver status flags.
*/
sdflags_t flags;
/**
* Input circular buffer.
*/
uint8_t ib[SERIAL_BUFFERS_SIZE];
/**
* Output circular buffer.
*/
uint8_t ob[SERIAL_BUFFERS_SIZE];
};
/**
* @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;
/**
* @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 {
/**
* @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;
/**
* @brief Output queue, outgoing data can be written to this output queue by
* using the queues APIs.
*/
OutputQueue oqueue;
/**
* @brief Status Change @p EventSource. This event is generated when one or
* more condition flags change.
*/
EventSource sevent;
/**
* @brief I/O driver status flags.
*/
sdflags_t flags;
/**
* @brief Input circular buffer.
*/
uint8_t ib[SERIAL_BUFFERS_SIZE];
/**
* @brief Output circular buffer.
*/
uint8_t ob[SERIAL_BUFFERS_SIZE];
/* End of the mandatory fields.*/
};
/*===========================================================================*/
/* 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
}

View File

@ -106,6 +106,12 @@
#define CH_HAL_USE_SERIAL TRUE
#endif
/*
* Default SERIAL settings overrides (uncomment to override).
*/
/*#define SERIAL_DEFAULT_BITRATE 38400*/
/*#define SERIAL_BUFFERS_SIZE 64*/
/*===========================================================================*/
/* SPI driver related settings. */
/*===========================================================================*/