Contiki 3.x
dma.c
Go to the documentation of this file.
1 /**
2  * \file
3  * Driver for the cc2430 DMA controller. Can be assigned to any bank
4  *
5  * \author
6  * Original: Martti Huttunen <martti@sensinode.com>
7  * Port: Zach Shelby <zach@sensinode.com>
8  * Further Modifications:
9  * George Oikonomou <oikonomou@users.sourceforge.net>
10  *
11  */
12 
13 #include "contiki.h"
14 #include "dev/dma.h"
15 #include "cc2430_sfr.h"
16 
17 #if DMA_ON
18 struct dma_config dma_conf[DMA_CHANNEL_COUNT]; /* DMA Descriptors */
19 struct process *dma_callback[DMA_CHANNEL_COUNT];
20 /*---------------------------------------------------------------------------*/
21 void
22 dma_init(void)
23 {
24  uint16_t tmp_ptr;
25 
26  memset(dma_conf, 0, 4 * sizeof(dma_config_t));
27 
28  for(tmp_ptr = 0; tmp_ptr < DMA_CHANNEL_COUNT; tmp_ptr++) {
29  dma_callback[tmp_ptr] = 0;
30  }
31 
32  /* The address of the descriptor for Channel 0 is configured separately */
33  tmp_ptr = (uint16_t)&(dma_conf[0]);
34  DMA0CFGH = tmp_ptr >> 8;
35  DMA0CFGL = tmp_ptr;
36 
37  /*
38  * Descriptors for Channels 1-4 must be consecutive in RAM.
39  * We write the address of the 1st one to the register and the rest are
40  * derived by the SoC
41  */
42 #if (DMA_CHANNEL_COUNT > 1)
43  tmp_ptr = (uint16_t)&(dma_conf[1]);
44  DMA1CFGH = tmp_ptr >> 8;
45  DMA1CFGL = tmp_ptr;
46 #endif
47 
48  IEN1_DMAIE = 1; /* Enable DMA interrupts */
49 }
50 /*---------------------------------------------------------------------------*/
51 /*
52  * Associate process p with DMA channel c. When a transfer on that channel
53  * completes, the ISR will poll this process.
54  */
55 void
56 dma_associate_process(struct process *p, uint8_t c)
57 {
58  if((!c) || (c >= DMA_CHANNEL_COUNT)) {
59  return;
60  }
61 
62  if(p) {
63  dma_conf[c].inc_prio |= 8; /* Enable interrupt generation */
64  IEN1_DMAIE = 1; /* Make sure DMA interrupts are acknowledged */
65  }
66  dma_callback[c] = p;
67 }
68 /*---------------------------------------------------------------------------*/
69 #endif
CC2430 registers header file for CC2430.
DMA configuration structure.
Definition: dma.h:103