added initial uart1 DMA rx support and required LPM requirements api

This commit is contained in:
joxe 2011-01-05 12:02:01 +00:00
parent 65048c519c
commit 565fda47aa
3 changed files with 93 additions and 6 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)$Id: uart1.c,v 1.19 2010/06/15 13:30:42 nifi Exp $
* @(#)$Id: uart1.c,v 1.20 2011/01/05 12:02:02 joxe Exp $
*/
/*
@ -37,13 +37,16 @@
#include <io.h>
#include <signal.h>
#include <stdio.h>
#include "sys/energest.h"
#include "dev/uart1.h"
#include "dev/watchdog.h"
#include "sys/ctimer.h"
#include "lib/ringbuf.h"
static int (*uart1_input_handler)(unsigned char c);
/* should be static */
int (*uart1_input_handler)(unsigned char c);
static uint8_t rx_in_progress;
static volatile uint8_t transmitting;
@ -54,6 +57,12 @@ static volatile uint8_t transmitting;
#define TX_WITH_INTERRUPT 1
#endif /* UART1_CONF_TX_WITH_INTERRUPT */
#ifdef UART1_CONF_RX_WITH_DMA
#define TX_WITH_INTERRUPT UART1_CONF_RX_WITH_DMA
#else /* UART1_CONF_RX_WITH_DMA */
#define RX_WITH_DMA 0
#endif /* UART1_CONF_RX_WITH_DMA */
#if TX_WITH_INTERRUPT
#define TXBUFSIZE 64
@ -61,6 +70,29 @@ static struct ringbuf txbuf;
static uint8_t txbuf_data[TXBUFSIZE];
#endif /* TX_WITH_INTERRUPT */
#if RX_WITH_DMA
#define RXBUFSIZE 64
static uint8_t rxbuf[RXBUFSIZE];
static uint8_t last_size;
static struct ctimer rxdma_timer;
static void
handle_rxdma_timer(void *ptr)
{
uint8_t size;
size = DMA0SZ; /* Note: loop requires that size is less or eq to RXBUFSIZE */
for (;last_size != size; last_size--) {
if(last_size == 0) last_size = RXBUFSIZE;
/* printf("read: %c\n", (unsigned char)rxbuf[RXBUFSIZE - last_size]); */
uart1_input_handler((unsigned char)rxbuf[RXBUFSIZE - last_size]);
}
ctimer_reset(&rxdma_timer);
}
#endif /* RX_WITH_DMA */
/*---------------------------------------------------------------------------*/
uint8_t
uart1_active(void)
@ -71,6 +103,9 @@ uart1_active(void)
void
uart1_set_input(int (*input)(unsigned char c))
{
#if RX_WITH_DMA /* This needs to be called after ctimer process is started */
ctimer_set(&rxdma_timer, CLOCK_SECOND/32, handle_rxdma_timer, NULL);
#endif
uart1_input_handler = input;
}
/*---------------------------------------------------------------------------*/
@ -188,7 +223,25 @@ uart1_init(unsigned long ubr)
ringbuf_init(&txbuf, txbuf_data, sizeof(txbuf_data));
IE2 |= UTXIE1; /* Enable USART1 TX interrupt */
#endif /* TX_WITH_INTERRUPT */
#if RX_WITH_DMA
IE2 &= ~URXIE1; /* disable USART1 RX interrupt */
/* UART1_RX trigger */
DMACTL0 = DMA0TSEL_9;
/* source address = RXBUF1 */
DMA0SA = (unsigned int) &RXBUF1;
DMA0DA = (unsigned int) &rxbuf;
DMA0SZ = RXBUFSIZE;
last_size = RXBUFSIZE;
DMA0CTL = DMADT_4 + DMASBDB + DMADSTINCR_3 + DMAEN + DMAREQ;// DMAIE;
msp430_add_lpm_req(MSP430_REQUIRE_LPM1);
#endif /* RX_WITH_DMA */
}
/*---------------------------------------------------------------------------*/
interrupt(UART1RX_VECTOR)
uart1_rx_interrupt(void)

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: msp430.c,v 1.13 2010/03/21 10:40:15 nifi Exp $
* @(#)$Id: msp430.c,v 1.14 2011/01/05 12:02:01 joxe Exp $
*/
#include <io.h>
#include <signal.h>
@ -38,6 +38,10 @@
#include "dev/watchdog.h"
#include "net/uip.h"
/* dco_required set to 1 will cause the CPU not to go into
sleep modes where the DCO clock stopped */
int msp430_dco_required;
/*---------------------------------------------------------------------------*/
#if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND
void *
@ -126,7 +130,6 @@ static void
init_ports(void)
{
/* Turn everything off, device drivers enable what is needed. */
/* All configured for digital I/O */
#ifdef P1SEL
P1SEL = 0;
@ -183,6 +186,28 @@ init_ports(void)
extern int _end; /* Not in sys/unistd.h */
static char *cur_break = (char *)&_end;
/*---------------------------------------------------------------------------*/
/* add/remove_lpm_req - for requiring a specific LPM mode. currently Contiki */
/* jumps to LPM3 to save power, but DMA will not work if DCO is not clocked */
/* so some modules might need to enter their LPM requirements */
/* NOTE: currently only works with LPM1 (e.g. DCO) requirements. */
/*---------------------------------------------------------------------------*/
void
msp430_add_lpm_req(int req)
{
if (req <= MSP430_REQUIRE_LPM1) {
msp430_dco_required++;
}
}
void
msp430_remove_lpm_req(int req)
{
if (req <= MSP430_REQUIRE_LPM1) {
msp430_dco_required--;
}
}
void
msp430_cpu_init(void)
{
@ -194,6 +219,7 @@ msp430_cpu_init(void)
if((uintptr_t)cur_break & 1) { /* Workaround for msp430-ld bug! */
cur_break++;
}
msp430_dco_required = 0;
}
/*---------------------------------------------------------------------------*/
#define asmv(arg) __asm__ __volatile__(arg)

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: msp430.h,v 1.2 2008/02/03 20:58:11 adamdunkels Exp $
* $Id: msp430.h,v 1.3 2011/01/05 12:02:01 joxe Exp $
*/
/**
@ -49,4 +49,12 @@
#define MSP430_CPU_SPEED 2457600UL
#endif
#define MSP430_REQUIRE_CPUON 0
#define MSP430_REQUIRE_LPM1 1
#define MSP430_REQUIRE_LPM2 2
#define MSP430_REQUIRE_LPM3 3
void msp430_add_lpm_req();
void msp430_remove_lpm_req();
#endif /* __MSP430_H__ */