Bar Logo 3.8/7.6 kw Totem pole Demonstration Application (Part-No. (not specified))
 
Content
     
Loading...
Searching...
No Matches
dma.h
Go to the documentation of this file.
1
17/*
18© [2024] Microchip Technology Inc. and its subsidiaries.
19
20 Subject to your compliance with these terms, you may use Microchip
21 software and any derivatives exclusively with Microchip products.
22 You are responsible for complying with 3rd party license terms
23 applicable to your use of 3rd party software (including open source
24 software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
25 NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
26 SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
27 MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
28 WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
29 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
30 KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
31 MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
32 FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
33 TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
34 EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
35 THIS SOFTWARE.
36*/
37
38#ifndef DMA_H
39#define DMA_H
40
41// Section: Included Files
42
43#include <xc.h>
44#include <stdbool.h>
45#include <stdint.h>
46#include "dma_types.h"
47#include "dma_interface.h"
48
49// Section: Data Type Definitions
50
59extern const struct DMA_INTERFACE DMA_SPI;
60
65#define DMA_SPI_Initialize DMA_Initialize
70#define DMA_SPI_Deinitialize DMA_Deinitialize
75#define DMA_SPI_ChannelEnable DMA_ChannelEnable
80#define DMA_SPI_TransferCountSet DMA_TransferCountSet
85#define DMA_SPI_TransferCountGet DMA_TransferCountGet
90#define DMA_SPI_SoftwareTriggerEnable DMA_SoftwareTriggerEnable
95#define DMA_SPI_SourceAddressSet DMA_SourceAddressSet
100#define DMA_SPI_DestinationAddressSet DMA_DestinationAddressSet
105#define DMA_SPI_IsSoftwareRequestPending DMA_IsSoftwareRequestPending
110#define DMA_SPI_ChannelTasks DMA_ChannelTasks
115#define DMA_SPI_ChannelCallbackRegister DMA_ChannelCallbackRegister
116
117// Section: Driver Interface Functions
118
125void DMA_Initialize (void);
126
133void DMA_Deinitialize(void);
134
142inline static void DMA_ChannelEnable(enum DMA_CHANNEL channel)
143{
144 switch(channel)
145 {
146 case DMA_CHANNEL_0:
147 DMACH0bits.CHEN = 1;
148 break;
149 case DMA_CHANNEL_1:
150 DMACH1bits.CHEN = 1;
151 break;
152 case DMA_CHANNEL_2:
153 DMACH2bits.CHEN = 1;
154 break;
155 case DMA_CHANNEL_3:
156 DMACH3bits.CHEN = 1;
157 break;
158 case DMA_CHANNEL_4:
159 DMACH4bits.CHEN = 1;
160 break;
161 case DMA_CHANNEL_5:
162 DMACH5bits.CHEN = 1;
163 break;
164 default: break;
165 }
166}
167
175inline static void DMA_ChannelDisable(enum DMA_CHANNEL channel)
176{
177 switch(channel)
178 {
179 case DMA_CHANNEL_0:
180 DMACH0bits.CHEN = 0;
181 break;
182 case DMA_CHANNEL_1:
183 DMACH1bits.CHEN = 0;
184 break;
185 case DMA_CHANNEL_2:
186 DMACH2bits.CHEN = 0;
187 break;
188 case DMA_CHANNEL_3:
189 DMACH3bits.CHEN = 0;
190 break;
191 case DMA_CHANNEL_4:
192 DMACH4bits.CHEN = 0;
193 break;
194 case DMA_CHANNEL_5:
195 DMACH5bits.CHEN = 0;
196 break;
197 default: break;
198 }
199}
200
209inline static void DMA_TransferCountSet(enum DMA_CHANNEL channel, uint16_t transferCount)
210{
211 switch(channel)
212 {
213 case DMA_CHANNEL_0:
214 DMACNT0 = transferCount;
215
216 break;
217 case DMA_CHANNEL_1:
218 DMACNT1 = transferCount;
219
220 break;
221 case DMA_CHANNEL_2:
222 DMACNT2 = transferCount;
223
224 break;
225 case DMA_CHANNEL_3:
226 DMACNT3 = transferCount;
227
228 break;
229 case DMA_CHANNEL_4:
230 DMACNT4 = transferCount;
231
232 break;
233 case DMA_CHANNEL_5:
234 DMACNT5 = transferCount;
235
236 break;
237 default: break;
238 }
239}
240
248inline static uint16_t DMA_TransferCountGet(enum DMA_CHANNEL channel)
249{
250 uint16_t transferCount = 0U;
251 switch(channel)
252 {
253 case DMA_CHANNEL_0:
254 transferCount = DMACNT0;
255 break;
256 case DMA_CHANNEL_1:
257 transferCount = DMACNT1;
258 break;
259 case DMA_CHANNEL_2:
260 transferCount = DMACNT2;
261 break;
262 case DMA_CHANNEL_3:
263 transferCount = DMACNT3;
264 break;
265 case DMA_CHANNEL_4:
266 transferCount = DMACNT4;
267 break;
268 case DMA_CHANNEL_5:
269 transferCount = DMACNT5;
270 break;
271 default:
272 break;
273 }
274 return transferCount;
275}
276
284inline static void DMA_SoftwareTriggerEnable(enum DMA_CHANNEL channel)
285{
286 switch(channel)
287 {
288 case DMA_CHANNEL_0:
289 DMACH0bits.CHREQ = 1;
290 break;
291 case DMA_CHANNEL_1:
292 DMACH1bits.CHREQ = 1;
293 break;
294 case DMA_CHANNEL_2:
295 DMACH2bits.CHREQ = 1;
296 break;
297 case DMA_CHANNEL_3:
298 DMACH3bits.CHREQ = 1;
299 break;
300 case DMA_CHANNEL_4:
301 DMACH4bits.CHREQ = 1;
302 break;
303 case DMA_CHANNEL_5:
304 DMACH5bits.CHREQ = 1;
305 break;
306 default: break;
307 }
308}
309
318inline static void DMA_SourceAddressSet(enum DMA_CHANNEL channel, uint16_t address)
319{
320 switch(channel)
321 {
322 case DMA_CHANNEL_0:
323 DMASRC0 = address;
324 break;
325 case DMA_CHANNEL_1:
326 DMASRC1 = address;
327 break;
328 case DMA_CHANNEL_2:
329 DMASRC2 = address;
330 break;
331 case DMA_CHANNEL_3:
332 DMASRC3 = address;
333 break;
334 case DMA_CHANNEL_4:
335 DMASRC4 = address;
336 break;
337 case DMA_CHANNEL_5:
338 DMASRC5 = address;
339 break;
340 default: break;
341 }
342}
343
352inline static void DMA_DestinationAddressSet(enum DMA_CHANNEL channel, uint16_t address)
353{
354 switch(channel)
355 {
356 case DMA_CHANNEL_0:
357 DMADST0 = address;
358 break;
359 case DMA_CHANNEL_1:
360 DMADST1 = address;
361 break;
362 case DMA_CHANNEL_2:
363 DMADST2 = address;
364 break;
365 case DMA_CHANNEL_3:
366 DMADST3 = address;
367 break;
368 case DMA_CHANNEL_4:
369 DMADST4 = address;
370 break;
371 case DMA_CHANNEL_5:
372 DMADST5 = address;
373 break;
374 default: break;
375 }
376}
377
378
387inline static bool DMA_IsSoftwareRequestPending(enum DMA_CHANNEL channel)
388{
389 bool status = 0;
390 switch(channel)
391 {
392 case DMA_CHANNEL_0:
393 status = DMACH0bits.CHREQ;
394 break;
395 case DMA_CHANNEL_1:
396 status = DMACH1bits.CHREQ;
397 break;
398 case DMA_CHANNEL_2:
399 status = DMACH2bits.CHREQ;
400 break;
401 case DMA_CHANNEL_3:
402 status = DMACH3bits.CHREQ;
403 break;
404 case DMA_CHANNEL_4:
405 status = DMACH4bits.CHREQ;
406 break;
407 case DMA_CHANNEL_5:
408 status = DMACH5bits.CHREQ;
409 break;
410 default:
411 break;
412 }
413 return status;
414}
415
423void DMA_ChannelTasks(void);
424
425
433void DMA_ChannelCallbackRegister(void(*callback)(enum DMA_CHANNEL channel));
434
443void DMA_ChannelCallback(enum DMA_CHANNEL channel);
444
445#endif // DMA_H
446
447
This is the generated driver types header file for the DMA driver.
@ DMA_CHANNEL_5
Definition dma_types.h:57
@ DMA_CHANNEL_0
Definition dma_types.h:52
@ DMA_CHANNEL_4
Definition dma_types.h:56
@ DMA_CHANNEL_1
Definition dma_types.h:53
@ DMA_CHANNEL_3
Definition dma_types.h:55
@ DMA_CHANNEL_2
Definition dma_types.h:54
size_t status
Definition uart1.c:99
void DMA_Initialize(void)
Initializes the DMA module.
Definition dma.c:67
void DMA_ChannelTasks(void)
This function is used to implement the tasks for polled implementations of DMA Channel.
Definition dma.c:241
static void DMA_SourceAddressSet(enum DMA_CHANNEL channel, uint16_t address)
This inline function sets the source address to specified DMA channel.
Definition dma.h:318
DMA_CHANNEL
Defines the DMA channles that are selected from the MCC Melody User Interface for the DMA transfers....
Definition dma_types.h:51
static void DMA_TransferCountSet(enum DMA_CHANNEL channel, uint16_t transferCount)
This inline function sets the number of transfer counts to DMA channel.
Definition dma.h:209
void DMA_Deinitialize(void)
Deinitializes the DMA to POR values.
Definition dma.c:163
static bool DMA_IsSoftwareRequestPending(enum DMA_CHANNEL channel)
This inline function returns the status of the software request of the DMA channel.
Definition dma.h:387
static uint16_t DMA_TransferCountGet(enum DMA_CHANNEL channel)
This inline function returns the number of transfer counts from DMA channel.
Definition dma.h:248
void DMA_ChannelCallback(enum DMA_CHANNEL channel)
This is the default callback with weak attribute. The user can override and implement the default cal...
Definition dma.c:226
static void DMA_SoftwareTriggerEnable(enum DMA_CHANNEL channel)
This inline function sets the software trigger of the DMA channel.
Definition dma.h:284
const struct DMA_INTERFACE DMA_SPI
Structure object of type DMA_INTERFACE with the custom name given by the user in the Melody Driver Us...
Definition dma.c:51
static void DMA_ChannelDisable(enum DMA_CHANNEL channel)
This inline function disables the DMA channel.
Definition dma.h:175
void DMA_ChannelCallbackRegister(void(*callback)(enum DMA_CHANNEL channel))
This function can be used to override default callback and to define custom callback for DMA Channel ...
Definition dma.c:218
static void DMA_ChannelEnable(enum DMA_CHANNEL channel)
This inline function enables the DMA channel.
Definition dma.h:142
static void DMA_DestinationAddressSet(enum DMA_CHANNEL channel, uint16_t address)
This inline function sets the destination address to specified DMA channel.
Definition dma.h:352
Structure containing the function pointers of DMA driver.