Merge pull request #1336 from sumanpanchal/z1-uart0-dma

Zolertia Z1: Direct memory access using UART.
This commit is contained in:
Antonio Lignan 2015-11-02 08:47:08 +01:00
commit 6037e269a8
3 changed files with 95 additions and 24 deletions

View file

@ -32,6 +32,10 @@
#include "contiki.h" #include "contiki.h"
#include "dev/watchdog.h" #include "dev/watchdog.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__) #if defined(__MSP430__) && defined(__GNUC__)
#define asmv(arg) __asm__ __volatile__ (arg) #define asmv(arg) __asm__ __volatile__ (arg)
#endif #endif
@ -156,6 +160,26 @@ extern int _end; /* Not in sys/unistd.h */
static char *cur_break = (char *)&_end; static char *cur_break = (char *)&_end;
#endif #endif
/*---------------------------------------------------------------------------*/
/* 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 void
msp430_cpu_init(void) msp430_cpu_init(void)
{ {
@ -172,6 +196,7 @@ msp430_cpu_init(void)
cur_break++; cur_break++;
} }
#endif #endif
msp430_dco_required = 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -209,7 +234,8 @@ splhigh_(void)
/* } */ /* } */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__ #ifdef __IAR_SYSTEMS_ICC__
int __low_level_init(void) int
__low_level_init(void)
{ {
/* turn off watchdog so that C-init will run */ /* turn off watchdog so that C-init will run */
WDTCTL = WDTPW + WDTHOLD; WDTCTL = WDTPW + WDTHOLD;
@ -224,7 +250,8 @@ int __low_level_init(void)
#endif #endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
msp430_sync_dco(void) { msp430_sync_dco(void)
{
uint16_t oldcapture; uint16_t oldcapture;
int16_t diff; int16_t diff;
/* DELTA_2 assumes an ACLK of 32768 Hz */ /* DELTA_2 assumes an ACLK of 32768 Hz */

View file

@ -51,6 +51,11 @@ static volatile uint8_t transmitting;
#define TX_WITH_INTERRUPT 1 #define TX_WITH_INTERRUPT 1
#endif /* UART0_CONF_TX_WITH_INTERRUPT */ #endif /* UART0_CONF_TX_WITH_INTERRUPT */
#ifdef UART0_CONF_RX_WITH_DMA
#define RX_WITH_DMA UART0_CONF_RX_WITH_DMA
#else /* UART0_CONF_RX_WITH_DMA */
#define RX_WITH_DMA 1
#endif /* UART0_CONF_RX_WITH_DMA */
#if TX_WITH_INTERRUPT #if TX_WITH_INTERRUPT
#define TXBUFSIZE 64 #define TXBUFSIZE 64
@ -59,6 +64,30 @@ static struct ringbuf txbuf;
static uint8_t txbuf_data[TXBUFSIZE]; static uint8_t txbuf_data[TXBUFSIZE];
#endif /* TX_WITH_INTERRUPT */ #endif /* TX_WITH_INTERRUPT */
#if RX_WITH_DMA
#define RXBUFSIZE 128
static uint8_t rxbuf[RXBUFSIZE];
static uint16_t last_size;
static struct ctimer rxdma_timer;
static void
handle_rxdma_timer(void *ptr)
{
uint16_t size;
size = DMA0SZ; /* Note: loop requires that size is less or eq to RXBUFSIZE */
while(last_size != size) {
uart0_input_handler((unsigned char)rxbuf[RXBUFSIZE - last_size]);
last_size--;
if(last_size == 0) {
last_size = RXBUFSIZE;
}
}
ctimer_reset(&rxdma_timer);
}
#endif /* RX_WITH_DMA */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
uint8_t uint8_t
uart0_active(void) uart0_active(void)
@ -69,6 +98,9 @@ uart0_active(void)
void void
uart0_set_input(int (*input)(unsigned char c)) uart0_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 / 64, handle_rxdma_timer, NULL);
#endif
uart0_input_handler = input; uart0_input_handler = input;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -135,8 +167,24 @@ uart0_init(unsigned long ubr)
ringbuf_init(&txbuf, txbuf_data, sizeof(txbuf_data)); ringbuf_init(&txbuf, txbuf_data, sizeof(txbuf_data));
IE2 |= UCA0TXIE; /* Enable UCA0 TX interrupt */ IE2 |= UCA0TXIE; /* Enable UCA0 TX interrupt */
#endif /* TX_WITH_INTERRUPT */ #endif /* TX_WITH_INTERRUPT */
#if RX_WITH_DMA
IE2 &= ~UCA0RXIE; /* disable USART0 RX interrupt */
/* UART0_RX trigger */
DMACTL0 = DMA0TSEL_3;
/* source address = UCA0RXBUF */
DMA0SA = (unsigned int)&UCA0RXBUF;
DMA0DA = (unsigned int)&rxbuf;
DMA0SZ = RXBUFSIZE;
last_size = RXBUFSIZE;
DMA0CTL = DMADT_4 + DMASBDB + DMADSTINCR_3 + DMAEN + DMAREQ;
msp430_add_lpm_req(MSP430_REQUIRE_LPM1);
#endif /* RX_WITH_DMA */
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if !RX_WITH_DMA
ISR(USCIAB0RX, uart0_rx_interrupt) ISR(USCIAB0RX, uart0_rx_interrupt)
{ {
uint8_t c; uint8_t c;
@ -154,6 +202,7 @@ ISR(USCIAB0RX, uart0_rx_interrupt)
} }
ENERGEST_OFF(ENERGEST_TYPE_IRQ); ENERGEST_OFF(ENERGEST_TYPE_IRQ);
} }
#endif /* !RX_WITH_DMA */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if TX_WITH_INTERRUPT #if TX_WITH_INTERRUPT
ISR(USCIAB0TX, uart0_tx_interrupt) ISR(USCIAB0TX, uart0_tx_interrupt)

View file

@ -31,7 +31,6 @@
#ifndef CONTIKI_CONF_H #ifndef CONTIKI_CONF_H
#define CONTIKI_CONF_H #define CONTIKI_CONF_H
#include "platform-conf.h" #include "platform-conf.h"
#define XMAC_CONF_COMPOWER 1 #define XMAC_CONF_COMPOWER 1
@ -60,7 +59,6 @@
#define QUEUEBUF_CONF_NUM 4 #define QUEUEBUF_CONF_NUM 4
#else /* NETSTACK_CONF_WITH_IPV6 */ #else /* NETSTACK_CONF_WITH_IPV6 */
/* Network setup for non-IPv6 (rime). */ /* Network setup for non-IPv6 (rime). */
@ -108,7 +106,6 @@
#define SHELL_VARS_CONF_RAM_BEGIN 0x1100 #define SHELL_VARS_CONF_RAM_BEGIN 0x1100
#define SHELL_VARS_CONF_RAM_END 0x2000 #define SHELL_VARS_CONF_RAM_END 0x2000
#define CFS_CONF_OFFSET_TYPE long #define CFS_CONF_OFFSET_TYPE long
#define PROFILE_CONF_ON 0 #define PROFILE_CONF_ON 0
@ -127,8 +124,9 @@
#define PROCESS_CONF_STATS 1 #define PROCESS_CONF_STATS 1
/*#define PROCESS_CONF_FASTPOLL 4*/ /*#define PROCESS_CONF_FASTPOLL 4*/
#define UART0_CONF_TX_WITH_INTERRUPT 0 /* So far, printfs without interrupt. */
#define UART0_CONF_TX_WITH_INTERRUPT 0 // So far, printfs without interrupt. #define UART0_CONF_RX_WITH_DMA 0
#ifdef NETSTACK_CONF_WITH_IPV6 #ifdef NETSTACK_CONF_WITH_IPV6
@ -186,11 +184,8 @@
#define UIP_CONF_TCP_SPLIT 0 #define UIP_CONF_TCP_SPLIT 0
#ifdef PROJECT_CONF_H #ifdef PROJECT_CONF_H
#include PROJECT_CONF_H #include PROJECT_CONF_H
#endif /* PROJECT_CONF_H */ #endif /* PROJECT_CONF_H */
#endif /* CONTIKI_CONF_H */ #endif /* CONTIKI_CONF_H */