Contiki 2.5
dma.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007, Swedish Institute of Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * DMA interrupt handling.
36  * \author
37  * Nicolas Tsiftes <nvt@sics.se>
38  */
39 #include "contiki.h"
40 
41 #include "contiki-msb430.h"
42 #include "dev/cc1020.h"
43 #include "dev/dma.h"
44 
45 static void (*callbacks[DMA_LINES])(void);
46 
47 interrupt(DACDMA_VECTOR) irq_dacdma(void)
48 {
49  if(DMA0CTL & DMAIFG) {
50  DMA0CTL &= ~(DMAIFG | DMAIE);
51  if(callbacks[0] != NULL) {
52  callbacks[0]();
53  }
54  _BIC_SR_IRQ(LPM3_bits);
55  }
56 
57  if(DMA1CTL & DMAIFG) {
58  DMA1CTL &= ~(DMAIFG | DMAIE);
59  if(callbacks[1] != NULL) {
60  callbacks[1]();
61  }
62  _BIC_SR_IRQ(LPM3_bits);
63  }
64 
65  if(DMA2CTL & DMAIFG) {
66  DMA2CTL &= ~(DMAIFG | DMAIE);
67  if(callbacks[2] != NULL) {
68  callbacks[2]();
69  }
70  _BIC_SR_IRQ(LPM3_bits);
71  }
72 
73  if(DAC12_0CTL & DAC12IFG) {
74  DAC12_0CTL &= ~(DAC12IFG | DAC12IE);
75  }
76 
77  if(DAC12_1CTL & DAC12IFG) {
78  DAC12_1CTL &= ~(DAC12IFG | DAC12IE);
79  }
80 }
81 
82 int
83 dma_subscribe(int line, void (*callback)(void))
84 {
85  if(line >= DMA_LINES) {
86  return -1;
87  }
88 
89  callbacks[line] = callback;
90  return 0;
91 }
92 
93 void
94 dma_transfer(unsigned char *dst, unsigned char *src, unsigned len)
95 {
96  /* Configure DMA Channel 0 for UART0 TXIFG. */
97  DMACTL0 = DMA0TSEL_4;
98 
99  /* No DMAONFETCH, ROUNDROBIN, ENNMI. */
100  DMACTL1 = 0x0000;
101 
102  /*
103  * Set single transfer mode with byte-per-byte transfers.
104  *
105  * The source address is incremented for each byte, while the
106  * destination address remains constant.
107  *
108  * In order to avoid missing the first rising edge of the trigger
109  * signal, it is important to use the level-sensitive trigger when
110  * using USART transfer interrupts.
111  */
112  DMA0CTL = DMADT_0 | DMADSTINCR_0 | DMASRCINCR_3 | DMASBDB | DMALEVEL;
113 
114  DMA0SA = (unsigned) src;
115  DMA0DA = (unsigned) dst;
116  DMA0SZ = len;
117 
118  DMA0CTL |= DMAEN | DMAIE; /* enable DMA and interrupts */
119  U0CTL &= ~SWRST; /* enable the UART state machine */
120 }