2020-2021 Sunseeker Telemetry and Lighting System
dma.c
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // dma.c - Driver for the dma Module.
4 //
5 //*****************************************************************************
6 
7 //*****************************************************************************
8 //
11 //
12 //*****************************************************************************
13 
14 #include "inc/hw_memmap.h"
15 
16 #if defined(__MSP430_HAS_DMAX_3__) || defined(__MSP430_HAS_DMAX_6__)
17 #include "dma.h"
18 
19 #include <assert.h>
20 
21 void DMA_init( DMA_initParam *param){
22  uint8_t triggerOffset = (param->channelSelect >> 4);
23 
24  //Reset and Set DMA Control 0 Register
25  HWREG16(DMA_BASE + param->channelSelect + OFS_DMA0CTL) =
26  param->transferModeSelect //Set Transfer Mode
27  + param->transferUnitSelect //Set Transfer Unit Size
28  + param->triggerTypeSelect; //Set Trigger Type
29 
30  //Set Transfer Size Amount
31  HWREG16(DMA_BASE + param->channelSelect + OFS_DMA0SZ) = param->transferSize;
32 
33  if (triggerOffset & 0x01){ //Odd Channel
34  HWREG16(DMA_BASE + (triggerOffset & 0x0E)) &= 0x00FF; //Reset Trigger Select
35  HWREG16(DMA_BASE +
36  (triggerOffset & 0x0E)) |= (param->triggerSourceSelect << 8);
37  } else { //Even Channel
38  HWREG16(DMA_BASE + (triggerOffset & 0x0E)) &= 0xFF00; //Reset Trigger Select
39  HWREG16(DMA_BASE + (triggerOffset & 0x0E)) |= param->triggerSourceSelect;
40  }
41 }
42 void DMA_setTransferSize (uint8_t channelSelect,
43  uint16_t transferSize)
44 {
45  //Set Transfer Size Amount
46  HWREG16(DMA_BASE + channelSelect + OFS_DMA0SZ) = transferSize;
47 }
48 
49 uint16_t DMA_getTransferSize (uint8_t channelSelect)
50 {
51  //Get Transfer Size Amount
52  return HWREG16(DMA_BASE + channelSelect + OFS_DMA0SZ);
53 }
54 
55 void DMA_setSrcAddress (uint8_t channelSelect,
56  uint32_t srcAddress,
57  uint16_t directionSelect)
58 {
59  //Set the Source Address
60  __data16_write_addr((unsigned short)(DMA_BASE + channelSelect + OFS_DMA0SA),
61  srcAddress);
62 
63  //Reset bits before setting them
64  HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) &= ~(DMASRCINCR_3);
65  HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) |= directionSelect;
66 }
67 
68 void DMA_setDstAddress (uint8_t channelSelect,
69  uint32_t dstAddress,
70  uint16_t directionSelect)
71 {
72  //Set the Destination Address
73  __data16_write_addr((unsigned short)(DMA_BASE + channelSelect + OFS_DMA0DA),
74  dstAddress);
75 
76  //Reset bits before setting them
77  HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) &= ~(DMADSTINCR_3);
78  HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) |= (directionSelect << 2);
79 }
80 
81 void DMA_enableTransfers (uint8_t channelSelect)
82 {
83  HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) |= DMAEN;
84 }
85 
86 void DMA_disableTransfers (uint8_t channelSelect)
87 {
88  HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) &= ~(DMAEN);
89 }
90 
91 void DMA_startTransfer (uint8_t channelSelect)
92 {
93  HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) |= DMAREQ;
94 }
95 
96 void DMA_enableInterrupt (uint8_t channelSelect)
97 {
98  HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) |= DMAIE;
99 }
100 
101 void DMA_disableInterrupt (uint8_t channelSelect)
102 {
103  HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) &= ~(DMAIE);
104 }
105 
106 uint16_t DMA_getInterruptStatus (uint8_t channelSelect)
107 {
108  return (HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) & DMAIFG);
109 }
110 
111 void DMA_clearInterrupt (uint8_t channelSelect)
112 {
113  HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) &= ~(DMAIFG);
114 }
115 
116 uint16_t DMA_getNMIAbortStatus (uint8_t channelSelect)
117 {
118  return (HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) & DMAABORT);
119 }
120 
121 void DMA_clearNMIAbort (uint8_t channelSelect)
122 {
123  HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) &= ~(DMAABORT);
124 }
125 
126 void DMA_disableTransferDuringReadModifyWrite (void)
127 {
128  HWREG16(DMA_BASE + OFS_DMACTL4) |= DMARMWDIS;
129 }
130 
131 void DMA_enableTransferDuringReadModifyWrite (void)
132 {
133  HWREG16(DMA_BASE + OFS_DMACTL4) &= ~(DMARMWDIS);
134 }
135 
136 void DMA_enableRoundRobinPriority (void)
137 {
138  HWREG16(DMA_BASE + OFS_DMACTL4) |= ROUNDROBIN;
139 }
140 
141 void DMA_disableRoundRobinPriority (void)
142 {
143  HWREG16(DMA_BASE + OFS_DMACTL4) &= ~(ROUNDROBIN);
144 }
145 
146 void DMA_enableNMIAbort (void)
147 {
148  HWREG16(DMA_BASE + OFS_DMACTL4) |= ENNMI;
149 }
150 
151 void DMA_disableNMIAbort (void)
152 {
153  HWREG16(DMA_BASE + OFS_DMACTL4) &= ~(ENNMI);
154 }
155 
156 
157 #endif
158 //*****************************************************************************
159 //
162 //
163 //*****************************************************************************
MPU_initThreeSegmentsParam param
#define HWREG16(x)
Definition: hw_memmap.h:39