gossamer 0.0.1
a very lightweight app framework for SAMD and SAML chips
Loading...
Searching...
No Matches
dma_util.h
1#pragma once
2
3#include "sam.h"
4
5typedef enum {
6 DMA_CONFIG_LOOP = 1 << 0,
7 DMA_CONFIG_RUNSTDBY = 1 << 1,
8} dma_configuration_flags_t;
9
10typedef enum {
11 DMA_INCREMENT_NONE = 0,
12 DMA_INCREMENT_SOURCE = (1 << 0),
13 DMA_INCREMENT_DESTINATION = (1 << 1),
14 DMA_INCREMENT_BOTH = (1 << 1) | (1 << 0),
15} dma_address_increment_t;
16
17
18#if defined(_SAMD51_)
19typedef enum {
20 DMA_TRIGGER_ACTION_BLOCK = DMAC_CHCTRLA_TRIGACT_BLOCK_Val,
21 // The D51 renames BEAT to BURST; with the burst length left at the
22 // single-beat default this is the same one-beat-per-trigger behavior.
23 DMA_TRIGGER_ACTION_BEAT = DMAC_CHCTRLA_TRIGACT_BURST_Val,
24 DMA_TRIGGER_ACTION_TRANSACTION = DMAC_CHCTRLA_TRIGACT_TRANSACTION_Val,
25} dma_trigger_action_t;
26#else
27typedef enum {
28 DMA_TRIGGER_ACTION_BLOCK = DMAC_CHCTRLB_TRIGACT_BLOCK_Val,
29 DMA_TRIGGER_ACTION_BEAT = DMAC_CHCTRLB_TRIGACT_BEAT_Val,
30 DMA_TRIGGER_ACTION_TRANSACTION = DMAC_CHCTRLB_TRIGACT_TRANSACTION_Val,
31} dma_trigger_action_t;
32#endif
33
34typedef enum {
35 // First item here is for any transfer errors. A transfer error is
36 // flagged if a bus error is detected during an AHB access or when
37 // the DMAC fetches an invalid descriptor
38 DMA_CALLBACK_TRANSFER_ERROR,
39 DMA_CALLBACK_TRANSFER_DONE,
40 DMA_CALLBACK_CHANNEL_SUSPEND,
41 DMA_CALLBACK_N, // Number of available callbacks
42} dma_callback_type_t;
43
44typedef enum {
45 DMA_BEAT_SIZE_BYTE = 0, // 8-bit
46 DMA_BEAT_SIZE_HWORD, // 16-bit
47 DMA_BEAT_SIZE_WORD, // 32-bit
48} dma_beat_size_t;
49
50typedef enum {
51 DMA_EVENT_OUTPUT_DISABLE = 0, // Disable event generation
52 DMA_EVENT_OUTPUT_BLOCK, // Event strobe when block xfer complete
53 DMA_EVENT_OUTPUT_RESERVED,
54 DMA_EVENT_OUTPUT_BEAT, // Event strobe when beat xfer complete
55} dma_event_output_selection_t;
56
57typedef enum {
58 DMA_EVENT_INPUT_NOACT = 0,
59 DMA_EVENT_INPUT_TRIG = 1,
60 DMA_EVENT_INPUT_CTRIG = 2,
61 DMA_EVENT_INPUT_CBLOCK = 3,
62 DMA_EVENT_INPUT_SUSPEND = 4,
63 DMA_EVENT_INPUT_RESUME = 5,
64 DMA_EVENT_INPUT_SSKIP = 6,
65} dma_event_input_action_t;
66
67typedef enum {
68 DMA_BLOCK_ACTION_NONE = 0,
69 // Channel in normal operation and sets transfer complete interrupt
70 // flag after block transfer
71 DMA_BLOCK_ACTION_INTERRUPT,
72 // Trigger channel suspend after block transfer and sets channel
73 // suspend interrupt flag once the channel is suspended
74 DMA_BLOCK_ACTION_SUSPEND,
75 // Sets transfer complete interrupt flag after a block transfer and
76 // trigger channel suspend. The channel suspend interrupt flag will
77 // be set once the channel is suspended.
78 DMA_BLOCK_ACTION_INTERRUPT_AND_SUSPEND,
79} dma_block_action_t;
80
81// DMA step selection. This bit determines whether the step size setting
82// is applied to source or destination address.
83typedef enum {
84 DMA_STEPSEL_DESTINATION = 0,
85 DMA_STEPSEL_SOURCE,
86} dma_stepsel_t;
87
88// Address increment step size. These bits select the address increment step
89// size. The setting apply to source or destination address, depending on
90// STEPSEL setting.
91typedef enum {
92 DMA_STEPSIZE_1 = 0, // beat size * 1
93 DMA_STEPSIZE_2, // beat size * 2
94 DMA_STEPSIZE_4, // beat size * 4
95 DMA_STEPSIZE_8, // etc...
96 DMA_STEPSIZE_16,
97 DMA_STEPSIZE_32,
98 DMA_STEPSIZE_64,
99 DMA_STEPSIZE_128,
100} dma_stepsize_t;
101
102// higher numbers are higher priority
103typedef enum {
104 DMA_PRIORITY_0, // lowest (default)
105 DMA_PRIORITY_1,
106 DMA_PRIORITY_2,
107 DMA_PRIORITY_3, // highest
108} dma_priority_t;
109
110
111typedef enum {
112 DMA_STATUS_OK = 0,
113 DMA_STATUS_ERR_NOT_FOUND,
114 DMA_STATUS_ERR_NOT_INITIALIZED,
115 DMA_STATUS_ERR_INVALID_ARG,
116 DMA_STATUS_ERR_IO,
117 DMA_STATUS_ERR_TIMEOUT,
118 DMA_STATUS_BUSY,
119 DMA_STATUS_SUSPEND,
120 DMA_STATUS_ABORTED,
121 DMA_STATUS_JOBSTATUS = -1 // For printStatus() function
122} dma_status_t;