Make it possible to subscribe to DMA events.

This commit is contained in:
nvt-se 2007-08-16 13:51:57 +00:00
parent 2780aef873
commit 0723f1fbc7
2 changed files with 42 additions and 17 deletions

View file

@ -42,22 +42,26 @@
#include "contiki-msb430.h" #include "contiki-msb430.h"
#include "dev/cc1020.h" #include "dev/cc1020.h"
#include "dev/dma.h"
static struct process *subscribers[DMA_LINES];
process_event_t dma_event;
interrupt(DACDMA_VECTOR) irq_dacdma(void) interrupt(DACDMA_VECTOR) irq_dacdma(void)
{ {
static unsigned char line;
if (DMA0CTL & DMAIFG) { if (DMA0CTL & DMAIFG) {
DMA0CTL &= ~(DMAIFG | DMAIE); DMA0CTL &= ~(DMAIFG | DMAIE);
line = 0; if (subscribers[0] != NULL) {
process_post(&cc1020_sender_process, cc1020_event, &line); process_post(subscribers[0], dma_event, NULL);
}
LPM_AWAKE(); LPM_AWAKE();
} }
if (DMA1CTL & DMAIFG) { if (DMA1CTL & DMAIFG) {
DMA1CTL &= ~(DMAIFG | DMAIE); DMA1CTL &= ~(DMAIFG | DMAIE);
line = 1; if (subscribers[1] != NULL) {
process_post(&cc1020_sender_process, cc1020_event, &line); process_post(subscribers[1], dma_event, NULL);
}
LPM_AWAKE(); LPM_AWAKE();
} }
@ -70,14 +74,29 @@ interrupt(DACDMA_VECTOR) irq_dacdma(void)
} }
} }
void
dma_init(void)
{
dma_event = process_alloc_event();
}
int
dma_subscribe(int line, struct process *p)
{
if (line >= DMA_LINES)
return -1;
subscribers[line] = p;
}
void void
dma_transfer(unsigned char *buf, unsigned len) dma_transfer(unsigned char *buf, unsigned len)
{ {
// Configure DMA Channel 0 for UART0 TXIFG. // Configure DMA Channel 0 for UART0 TXIFG.
DMACTL0 = DMA0TSEL_4; DMACTL0 = DMA0TSEL_4;
// No DMAONFETCH, ROUNDROBIN, ENNMI. // No DMAONFETCH, ROUNDROBIN, ENNMI.
DMACTL1 = 0x0000; DMACTL1 = 0x0000;
/* /*
* Set single transfer mode with byte-per-byte transfers. * Set single transfer mode with byte-per-byte transfers.
@ -89,12 +108,12 @@ dma_transfer(unsigned char *buf, unsigned len)
* interrupts so first edge * interrupts so first edge
* doesn't get lost (hangs every 50. - 100. time)! * doesn't get lost (hangs every 50. - 100. time)!
*/ */
DMA0CTL = DMADT_0 | DMADSTINCR_0 | DMASRCINCR_3 | DMASBDB | DMALEVEL | DMAIE; DMA0CTL = DMADT_0 | DMADSTINCR_0 | DMASRCINCR_3 | DMASBDB | DMALEVEL | DMAIE;
DMA0SA = (unsigned) buf; DMA0SA = (unsigned) buf;
DMA0DA = (unsigned) &TXBUF0; DMA0DA = (unsigned) &TXBUF0;
DMA0SZ = len; DMA0SZ = len;
DMA0CTL |= DMAEN; // enable DMA DMA0CTL |= DMAEN; // enable DMA
U0CTL &= ~SWRST; // enable UART state machine, starts transfer U0CTL &= ~SWRST; // enable UART state machine, starts transfer
} }

View file

@ -28,12 +28,18 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: dma.h,v 1.3 2007/07/05 08:35:13 nvt-se Exp $ * $Id: dma.h,v 1.4 2007/08/16 13:51:57 nvt-se Exp $
*/ */
#ifndef DMA_H #ifndef DMA_H
#define DMA_H #define DMA_H
#define DMA_LINES 2
void dma_init(void);
int dma_subscribe(int, struct process *);
void dma_transfer(unsigned char *, unsigned); void dma_transfer(unsigned char *, unsigned);
extern process_event_t dma_event;
#endif #endif