| Digital Power Starter Kit 3 Firmware dsPIC33C Boost Converter Voltage Mode Control Example |

p33c_dma.c
1 /* Microchip Technology Inc. and its subsidiaries. You may use this software
2 * and any derivatives exclusively with Microchip products.
3 *
4 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
5 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
6 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
7 * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
8 * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
9 *
10 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
11 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
12 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
13 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
14 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS
15 * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF
16 * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
17 *
18 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
19 * TERMS.
20 */
21
22 // Include standard header files
23 #include <xc.h> // include processor files - each processor file is guarded.
24 #include <stdint.h> // include standard integer data types
25 #include <stdbool.h> // include standard boolean data types
26 #include <stddef.h> // include standard definition data types
27
28 #include "p33c_dma.h"
29
30 #if defined (DMACH7)
31 volatile uint16_t* p33c_DmaChannel_Handles[8]={
32 &DMACH0, &DMACH1, &DMACH2, &DMACH3,
33 &DMACH4, &DMACH5, &DMACH6, &DMACH7
34 };
35 #elif defined (DMACH6)
36 volatile uint16_t* p33c_DmaChannel_Handles[7]={
37 &DMACH0, &DMACH1, &DMACH2, &DMACH3
38 &DMACH4, &DMACH5, &DMACH6
39 };
40 #elif defined (DMACH5)
41 volatile uint16_t* p33c_DmaChannel_Handles[6]={
42 &DMACH0, &DMACH1, &DMACH2, &DMACH3
43 &DMACH4, &DMACH5
44 };
45 #elif defined (DMACH4)
46 volatile uint16_t* p33c_DmaChannel_Handles[5]={
47 &DMACH0, &DMACH1, &DMACH2, &DMACH3
48 &DMACH4
49 };
50 #elif defined (DMACH3)
51 volatile uint16_t* p33c_DmaChannel_Handles[4]={
52 &DMACH0, &DMACH1, &DMACH2, &DMACH3
53 };
54 #elif defined (DMACH2)
55 volatile uint16_t* p33c_DmaChannel_Handles[3]={
56 &DMACH0, &DMACH1, &DMACH2
57 };
58 #elif defined (DMACH1)
59 volatile uint16_t* p33c_DmaChannel_Handles[2]={
60 &DMACH0, &DMACH1
61 };
62 #elif defined (DMACH0)
63 volatile uint16_t* p33c_DmaChannel_Handles[1]={
64 &DMACH0
65 };
66 #else
67 #pragma message "selected device has no supported DMA channels"
68 #endif
69
70 /*********************************************************************************
71 * @fn volatile uint16_t p33c_DmaModule_Dispose(void)
72 * @ingroup lib-layer-pral-functions-public-dma
73 * @brief Resets all DMA Module registers to their RESET default values
74 * @param void
75 * @return 0 = failure, disposing DMA module was not successful
76 * @return 1 = success, disposing DMA module was successful
77 *
78 * @details
79 * This function clears all DMA module registers to their
80 * default values set when the device comes out of RESET.
81 *
82 * Default configuration:
83 * - addressable memory range is reset to default (maximum range)
84 * - stop operation in IDLE mode
85 * - channel priority scheme is set to Fixed Priority Scheme
86 *
87 *********************************************************************************/
88
89 volatile uint16_t p33c_DmaModule_Dispose(void)
90 {
91 volatile uint16_t retval=1;
92
93 retval = p33c_DmaModule_ConfigWrite(dmaModuleConfigClear);
94
95 return(retval);
96 }
97
98 /*********************************************************************************
99 * @fn volatile struct P33C_DMA_MODULE_s p33c_DmaModule_ConfigRead(void)
100 * @ingroup lib-layer-pral-functions-public-dma
101 * @brief Read the current configuration from the DMA module base registers
102 * @param void
103 * @return 0 = failure, reading DMA module was not successful (returns NULL)
104 * @return n = success, reading DMA module was successful (returns result of type P33C_DMA_MODULE_s)
105 *
106 * @details
107 * This function reads all registers with their current configuration into
108 * a data structure of type P33C_DMA_MODULE_s. Users can read and
109 * verify or modify the configuration to write it back to the DMA module
110 * registers.
111 *
112 *********************************************************************************/
113
114 volatile struct P33C_DMA_MODULE_s p33c_DmaModule_ConfigRead(void)
115 {
116 volatile struct P33C_DMA_MODULE_s* dmac;
117
118 // Set pointer to memory address of DMA base register set
119 dmac = p33c_DmaModule_GetHandle();
120
121 return(*dmac);
122
123 }
124
125 /*********************************************************************************
126 * @fn volatile uint16_t p33c_DmaModule_ConfigWrite(volatile struct P33C_DMA_MODULE_s dmaModuleConfig)
127 * @ingroup lib-layer-pral-functions-public-dma
128 * @brief Writes a user-defined configuration to the DMA module base registers
129 * @param dmaModuleConfig DIrect Memory Access module configuration of type struct P33C_DMA_MODULE_s
130 * @return 0 = failure, writing DMA module was not successful
131 * @return 1 = success, writing DMA module was successful
132 *
133 * @details
134 * This function writes a user-defined DMA module configuration of
135 * type P33C_DMA_MODULE_s to the DMA module base registers. The
136 * individual register configurations have to be set in user-code
137 * before calling this function. To simplify the configuration process
138 * of standard functions, this driver provides templates, which can be
139 * loaded and written directly.
140 *
141 *********************************************************************************/
142
143 volatile uint16_t p33c_DmaModule_ConfigWrite(
144 volatile struct P33C_DMA_MODULE_s dmaModuleConfig
145 )
146 {
147 volatile uint16_t retval=1;
148 volatile struct P33C_DMA_MODULE_s* dmac;
149
150 // Set pointer to memory address of the DMA module base registers
151 dmac = p33c_DmaModule_GetHandle();
152 *dmac = dmaModuleConfig;
153
154 return(retval);
155
156 }
157
158
159 /* ============================================================================== */
160 /* ============================================================================== */
161 /* ============================================================================== */
162
163
164 /*********************************************************************************
165 * @fn volatile uint16_t p33c_DmaInstance_Dispose(volatile uint16_t dmaInstance)
166 * @ingroup lib-layer-pral-functions-public-dma
167 * @brief Resets all DMA Instance registers to their RESET default values
168 * @param dmaInstance Index of the selected DMA Instance (1=DMA1, 2=DMA2, etc.)
169 * @return 0 = failure, disposing DMA instance was not successful
170 * @return 1 = success, disposing DMA instance was successful
171 *
172 * @details
173 * This function clears all DMA instance registers to their
174 * default values set when the device comes out of RESET.
175 *
176 * Default configuration:
177 * - all outputs are set to logic functions
178 * - all analog functions are disabled
179 * - all pull-up and pull-down resistors are disabled
180 * - all DMAs are operating in push-pull mode (open drain disabled)
181 * - all DMAs are configured as input with their signal level HIGH
182 *
183 *********************************************************************************/
184
185 volatile uint16_t p33c_DmaInstance_Dispose(volatile uint16_t dmaInstance)
186 {
187 volatile uint16_t retval=1;
188
189 retval = p33c_DmaInstance_ConfigWrite(dmaInstance, dmaInstanceConfigClear);
190
191 return(retval);
192 }
193
194 /*********************************************************************************
195 * @fn volatile struct P33C_DMA_INSTANCE_s p33c_DmaInstance_ConfigRead(volatile uint16_t dmaInstance)
196 * @ingroup lib-layer-pral-functions-public-dma
197 * @brief Read the current configuration from the DMA instance registers
198 * @param dmaInstance Index of the selected DMA Instance (1=DMA1, 2=DMA2, etc.)
199 * @return DMA instance object of type struct P33C_DMA_INSTANCE_s of the selected DMA instance
200 *
201 * @details
202 * This function reads all registers with their current configuration into
203 * a data structure of type P33C_DMA_INSTANCE_s. Users can read and
204 * verify or modify the configuration to write it back to the DMA instance
205 * registers or copy configurations to other instances of the same type.
206 *
207 *********************************************************************************/
208
209 volatile struct P33C_DMA_INSTANCE_s p33c_DmaInstance_ConfigRead(volatile uint16_t dmaInstance)
210 {
211 volatile struct P33C_DMA_INSTANCE_s* dma;
212
213 // Set pointer to memory address of desired DMA instance
214 dma = p33c_DmaInstance_GetHandle(dmaInstance);
215
216 return(*dma);
217
218 }
219
220 /*********************************************************************************
221 * @fn volatile uint16_t p33c_DmaInstance_ConfigWrite(volatile uint16_t dmaInstance, volatile struct P33C_DMA_INSTANCE_s dmaConfig)
222 * @ingroup lib-layer-pral-functions-public-dma
223 * @brief Writes a user-defined configuration to the DMA instance registers
224 * @param dmaInstance Index of the selected DMA Instance (1=DMA1, 2=DMA2, etc.)
225 * @param dmaConfig DMA instance object of type struct P33C_DMA_INSTANCE_s of the selected DMA instance
226 * @return 0 = failure, writing DMA instance was not successful
227 * @return 1 = success, writing DMA instance was successful
228 *
229 * @details
230 * This function writes a user-defined DMA instance configuration of type
231 * P33C_DMA_INSTANCE_s to the DMA instance registers. The
232 * individual register configurations have to be set in user-code
233 * before calling this function. To simplify the configuration process
234 * of standard functions, this driver provides templates, which can be
235 * loaded and written directly.
236 *
237 *********************************************************************************/
238
239 volatile uint16_t p33c_DmaInstance_ConfigWrite(
240 volatile uint16_t dmaInstance,
241 volatile struct P33C_DMA_INSTANCE_s dmaConfig)
242 {
243 volatile uint16_t retval=1;
244 volatile struct P33C_DMA_INSTANCE_s* dma;
245
246 // Set pointer to memory address of desired DMA instance
247 dma = p33c_DmaInstance_GetHandle(dmaInstance);
248 *dma = dmaConfig;
249
250 return(retval);
251
252 }
253
254
255 /* ============================================================================== */
256 /* ============================================================================== */
257 /* ============================================================================== */
258
259 /*********************************************************************************
260 * @var dmaModuleConfigClear
261 * @ingroup lib-layer-pral-properties-private-dma
262 * @brief Default RESET configuration of DMA module
263 *
264 * @details
265 * Default configuration of the DMA module SFRs with all its registers
266 * being reset to their default state when the device comes out of RESET.
267 * The minimum and maximum addresses specifying the memory range addressable
268 * by the DMA module affects/limits all DMA channels.
269 * (Please read the device data sheet for details)
270 *
271 * Programmers can use this template to reset a previously used
272 * DMA module when it's not used anymore or to ensure a known startup
273 * condition before writing individual configurations to its SFRs.
274 *
275 ********************************************************************************/
276
277 volatile struct P33C_DMA_MODULE_s dmaModuleConfigClear = {
278
279 .DmaCon.value = 0x0000,
280 .DmaBuf.value = 0x0000,
281 .DmaL.value = P33C_DACL_DEFAULT,
282 .DmaH.value = P33C_DACH_DEFAULT,
283 };
284
285 /*********************************************************************************
286 * @var dmaInstanceConfigClear
287 * @ingroup lib-layer-pral-properties-private-dma
288 * @brief Default RESET configuration of one DMA instance SFRs
289 * @param dmaConfigClear DMA instance Special Function Register (SFR) set
290 *
291 * @details
292 * Default configuration of the DMA instance SFRs with all its registers
293 * being reset to their default state when the device comes out of RESET.
294 * Programmers can use this template to reset (dispose) a previously used
295 * DMA instance when it's not used anymore or to secure a known startup
296 * condition before writing individual configurations to its SFRs.
297 *
298 * *******************************************************************************/
299
300 volatile struct P33C_DMA_INSTANCE_s dmaInstanceConfigClear = {
301
302 .DMACHx.value = 0x0000, // Clear DMA Channel n Control Register
303 .DMAINTx.value = 0x0000, // Clear DMA Channel n Interrupt Control Register
304 .DMASRCx.value = 0x0000, // Clear DMA Channel n Source Address Register
305 .DMADSTx.value = 0x0000, // DMA Channel n Destination Address Register
306 .DMACNTx.value = 0x0000 // DMA Channel n Count Register
307 };
308
309
310 // end of file
P33C_DMA_INSTANCE_s::DMACHx
union P33C_DMA_INSTANCE_s::@106 DMACHx
P33C_DMA_INSTANCE_s
Definition: p33c_dma.h:118
P33C_DMA_MODULE_s::value
volatile uint16_t value
Definition: p33c_dma.h:63
P33C_DMA_MODULE_s::DmaCon
union P33C_DMA_MODULE_s::@92 DmaCon
P33C_DMA_MODULE_s
Definition: p33c_dma.h:60
P33C_DMA_INSTANCE_s::value
volatile uint16_t value
Definition: p33c_dma.h:121