Contributions from Michael Baar:

CC1020

o   Turns off only after transmission has ended and not in between

o   Using events for DMA takes too long. It should use a callback when
    DMA finishes to turn off the transmit mode as early as possible.

Core/UART

o   Added profiling and energest initialization

o   Changed low-power mode from LPM1 to LPM3
This commit is contained in:
nvt-se 2007-12-13 12:51:38 +00:00
parent b1d87bf0d3
commit 665c58fd2a
4 changed files with 267 additions and 163 deletions

View file

@ -32,11 +32,19 @@ whether in contract, strict liability, or tort (including negligence
or otherwise) arising in any way out of the use of this software, even
if advised of the possibility of such damage.
This implementation was developed by the CST group at the FUB.
For documentation and questions please use the web site
http://scatterweb.mi.fu-berlin.de and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2007
*/
/**
* \file UART interface
* \author Michael Baar <baar@inf.fu-berlin.de>
* @file ScatterWeb.Uart.c
* @addtogroup interfaces
* @brief UART interface
* @author Michael Baar <baar@inf.fu-berlin.de>
*
* UART switch for RS232 and SPI protocols on UART1 written for
* ScatterWeb MSB boards. Compatible to ScatterWeb EOS,
@ -54,36 +62,38 @@ if advised of the possibility of such damage.
#define U1ME ME2
#endif
static void uart_configure(unsigned char mode);
static void uart_set_mode(unsigned char mode);
void _uart_configure(unsigned char mode);
void _uart_set_mode(unsigned char mode);
static volatile unsigned char uart_mode = UART_MODE_RESET;
static volatile unsigned char uart_lockcnt;
volatile unsigned char uart_mode = UART_MODE_RESET;
volatile unsigned char uart_lockcnt = 0;
volatile uint8_t uart_edge = 0;
static unsigned char uart_speed_br0[UART_NUM_MODES];
static unsigned char uart_speed_br1[UART_NUM_MODES];
static unsigned char uart_speed_bmn[UART_NUM_MODES];
static fp_uart_handler uart_handler[UART_NUM_MODES];
static unsigned char _uart_speed_br0[UART_NUM_MODES];
static unsigned char _uart_speed_br1[UART_NUM_MODES];
static unsigned char _uart_speed_bmn[UART_NUM_MODES];
static fp_uart_handler _uart_handler[UART_NUM_MODES] = {NULL, NULL};
/*---------------------------------------------------------------------------*/
void
uart_set_speed(unsigned char mode, unsigned char ubr0,
unsigned char ubr1, unsigned char umctl)
{
// store setting
uart_speed_br0[mode] = ubr0; // baudrate
uart_speed_br1[mode] = ubr1; // baudrate
uart_speed_bmn[mode] = umctl; // modulation
_uart_speed_br0[mode] = ubr0; // baudrate
_uart_speed_br1[mode] = ubr1; // baudrate
_uart_speed_bmn[mode] = umctl; // modulation
// reconfigure, if mode active
if (uart_mode == mode)
uart_configure(mode);
_uart_configure(mode);
}
/*---------------------------------------------------------------------------*/
void
uart_set_handler(unsigned char mode, fp_uart_handler fpHandler)
{
// store setting
uart_handler[mode] = fpHandler;
_uart_handler[mode] = fpHandler;
if (mode == uart_mode) {
if (fpHandler == NULL)
IE2 &= ~URXIE1; // Disable USART1 RX interrupt
@ -91,28 +101,30 @@ uart_set_handler(unsigned char mode, fp_uart_handler fpHandler)
IE2 |= URXIE1; // Enable USART1 RX interrupt
}
}
/*---------------------------------------------------------------------------*/
int
uart_lock(unsigned char mode)
{
// already locked?
if ((mode != uart_mode) && (uart_lockcnt)) {
return FALSE;
return 0;
} else {
// increase lock count
uart_lockcnt++;
// switch mode (if neccessary)
_uart_set_mode(mode);
return 1;
}
// increase lock count
uart_lockcnt++;
// switch mode (if neccessary)
uart_set_mode(mode);
return TRUE;
}
/*---------------------------------------------------------------------------*/
int
uart_unlock(unsigned char mode)
{
/* Strict checking. */
if (mode != uart_mode)
return FALSE;
/*
Do we wan't strict checking?
if( (uart_lockcnt == 0) || (mode != uart_mode) )
return false;
*/
// decrement lock
if (uart_lockcnt > 0) {
@ -120,28 +132,28 @@ uart_unlock(unsigned char mode)
// if no more locks, switch back to default mode
if (uart_lockcnt == 0) {
uart_set_mode(UART_MODE_DEFAULT);
_uart_set_mode(UART_MODE_DEFAULT);
}
return TRUE;
return 1;
}
return FALSE;
return 0;
}
static void
uart_configure(unsigned char mode)
/*---------------------------------------------------------------------------*/
void
_uart_configure(unsigned char mode)
{
int s;
s = splhigh();
_DINT(); // disable interrupts
UART_WAIT_TXDONE();
// wait till all buffered data has been transmitted
// configure
if (mode == UART_MODE_RS232) {
P5OUT |= 0x01;
// unselect SPI
P3SEL |= 0xC0;
// select rs232 to RS232 mode
// select rs232
// to RS232 mode
UCTL1 = SWRST | CHAR; // 8-bit character
UTCTL1 |= SSEL1; // UCLK = MCLK
// activate
@ -159,48 +171,56 @@ uart_configure(unsigned char mode)
}
// restore speed settings
UBR01 = uart_speed_br0[mode]; // set baudrate
UBR11 = uart_speed_br1[mode];
UMCTL1 = uart_speed_bmn[mode]; // set modulation
UBR01 = _uart_speed_br0[mode]; // set baudrate
UBR11 = _uart_speed_br1[mode];
UMCTL1 = _uart_speed_bmn[mode]; // set modulation
UCTL1 &= ~SWRST; // clear reset flag
splx(s);
_EINT(); // enable interrupts
}
static void
uart_set_mode(unsigned char mode)
/*---------------------------------------------------------------------------*/
void
_uart_set_mode(unsigned char mode)
{
// do nothing if mode already set
if (mode == uart_mode )
if (mode == uart_mode)
return;
IE2 &= ~(URXIE1 | UTXIE1); // disable irq
uart_configure(mode); // configure uart parameters
_uart_configure(mode); // configure uart parameters
uart_mode = mode;
if (uart_handler[mode] != NULL)
if (_uart_handler[mode] != NULL)
IE2 |= URXIE1; // Enable USART1 RX interrupt
}
interrupt(UART1RX_VECTOR) uart_rx(void)
{
fp_uart_handler handler = uart_handler[uart_mode];
/* Check status register for receive errors. - before reading RXBUF since
it clears the error and interrupt flags */
if (!(URCTL1 & RXERR) && handler != NULL) {
if(handler(UART_RX)) {
LPM_AWAKE();
}
} else {
// read out the char to clear the I-flags, etc.
UART_RX;
}
}
/*---------------------------------------------------------------------------*/
int
uart_get_mode(void)
{
return uart_mode;
}
/*---------------------------------------------------------------------------*/
interrupt(UART1RX_VECTOR)_uart_rx(void)
{
fp_uart_handler handler = _uart_handler[uart_mode];
int c;
if (!(IFG2 & URXIFG1)) {
// If start edge detected, toggle & return
uart_edge = 1;
U1TCTL &= ~URXSE;
U1TCTL |= URXSE;
_BIC_SR_IRQ(LPM3_bits);
return;
}
uart_edge = 0;
if (!(URCTL1 & RXERR)) {
c = UART_RX;
if (handler(c)) {
_BIC_SR_IRQ(LPM3_bits);
}
} else {
// read out the char to clear the I-flags, etc.
c = UART_RX;
}
}