CRpi
A library for rpi with intefaces to: gpio, pwm, dma
dma.h
Go to the documentation of this file.
1 #ifndef DMA_H
2 #define DMA_H
3 
4 #include <stdint.h>
5 #include <stdlib.h>
6 #include "../memoryManagement/cacheCoherentMemoryProvider.h"
7 
8 
9 
21 //::::::::::::::::::::::: Masks and offsets for the Transfer Info register ::::::::::::::::::::::::::::::::::::::::::::::::
22 
24  #define TI_NO_WIDE_BURSTS_OFF 26
26  #define TI_NO_WIDE_BURSTS_MASK (1<<TI_NO_WIDE_BURSTS_OFF)
27 
28 
29  #define TI_WAITS_OFF 21
31  #define TI_WAITS_MASK (31<<TI_WAITS_OFF)
32 
33 
34  #define TI_PERMAP_OFF 16
36  #define TI_PERMAP_MASK (31<<TI_PERMAP_OFF)
37 
38 
39  #define TI_BURST_LEN_OFF 12
41  #define TI_BURST_LEN_MASK (0xf<<TI_BURST_LEN_OFF)
42 
43 
44  #define TI_SRC_IGNORE_OFF 11
46  #define TI_SRC_IGNORE_MASK (1<<TI_SRC_IGNORE_OFF)
47 
48 
49  #define TI_SRC_DREQ_OFF 10
51  #define TI_SRC_DREQ_MASK (1<<TI_SRC_DREQ_OFF)
52 
53 
54  #define TI_SRC_WIDTH_OFF 9
56  #define TI_SRC_WIDTH_MASK (1<<TI_SRC_WIDTH_OFF)
57 
58 
59  #define TI_SRC_INC_OFF 8
61  #define TI_SRC_INC_MASK (1<<TI_SRC_INC_OFF)
62 
63 
64  #define TI_DEST_IGNORE_OFF 7
66  #define TI_DEST_IGNORE_MASK (1<<TI_DEST_IGNORE_OFF)
67 
68 
69  #define TI_DEST_DREQ_OFF 6
71  #define TI_DEST_DREQ_MASK (1<<TI_DEST_DREQ_OFF)
72 
73 
74  #define TI_DEST_WIDTH_OFF 5
76  #define TI_DEST_WIDTH_MASK (1<<TI_DEST_WIDTH_OFF)
77 
78 
79  #define TI_DEST_INC_OFF 4
81  #define TI_DEST_INC_MASK (1<<TI_DEST_INC_OFF)
82 
83 
84  #define TI_WAIT_RESP_OFF 3
86  #define TI_WAIT_RESP_MASK (1<<TI_WAIT_RESP_OFF)
87 
88 
89  #define TI_2DMODE_OFF 1
91  #define TI_2DMODE_MASK (1<<TI_2DMODE_OFF)
92 
93 
94  #define TI_INTEN_OFF (0)
96  #define TI_INTEN_MASK (1)
97 
98 
100  #define DREQ_ALWAYS_ON 0
102  #define DREQ_DSI 1
103  #define DREQ_PCM_TX 2
104  #define DREQ_PCM_RX 3
105  #define DREQ_SMI 4
106  #define DREQ_PWM 5
107  #define DREQ_SPI_TX 6
108  #define DREQ_SPI_RX 7
109 
110 
111 
112 //:::::::::::::::::::::::::::::: Masks and offsets for the Transfer Length register :::::::::::::::::::::::::::::::::::::::
113 
115  #define TL_Y_LEN_OFF 16
117  #define TL_Y_LEN_MASK (0x3fff<<TL_Y_LEN_OFF)
118 
119 
120  #define TL_X_LEN_OFF 0
122  #define TL_X_LEN_MASK (0xffff)
123 
124 
125  #define TL_LEN_OFF 0
127  #define TL_LEN_MASK (0x3fffffff)
128 
129 
130 
131 //::::::::::::::::::::::::::::::: Masks and offsets for the 2DStride Register :::::::::::::::::::::::::::::::::::::::::::::
132 
134  #define REG_2D_STRIDE_DST_STRIDE_OFF 16
136  #define REG_2D_STRIDE_DST_STRIDE_MASK (0xffff<<REG_2D_STRIDE_DST_STRIDE_OFF)
137 
138 
139  #define REG_2D_STRIDE_SRC_STRIDE_OFF 0
141  #define REG_2D_STRIDE_SRC_STRIDE_MASK (0xffff)
142 
143 
144 
145 
149 typedef volatile struct ControlBlock_struct
150 {
152  uint32_t transferInfo;
154  uint32_t srcAddrPhys;
156  uint32_t dstAddrPhys;
158  uint32_t transferLength;
160  uint32_t _2DStrideMode;
164  uint32_t zero1;
166  uint32_t zero2;
167 } ControlBlock;
168 
169 
170 
171 int dma_init();
172 
173 int dma_isInit();
174 
175 int dma_channelResetInitDefault(int channel);
176 
177 int dma_setControlBlockAddr(int channel, uint32_t controlBlockAddrPhys);
178 
179 int dma_writeControlBlock(ControlBlock* cb,uintptr_t srcAddrPhys,uintptr_t dstAddrPhys,size_t transferLength,uintptr_t nextControlBlockPhys,uint32_t transferInfo,uint32_t _2DStrideModeInfo,size_t _2DStrideTransferLenX,size_t _2DStrideTransferLenY);
180 
181 int dma_allocControlBlockPhys(uintptr_t srcAddrPhys,uintptr_t dstAddrPhys,size_t transferLength,uintptr_t nextControlBlockPhys,uint32_t transferInfo,uint32_t _2DStrideModeInfo,size_t _2DStrideTransferLenX,size_t _2DStrideTransferLenY,Ccmb_desc* area);
182 
183 int dma_dumpRegisters(int channel, char* s);
184 
185 int dma_printRegisters(int channel);
186 
188 
189 int dma_controlBlockToString(ControlBlock* cb, char* s);
190 
191 int dma_setChannelActive(int channel, int value);
192 
193 int dma_setChannelGlobalEnable(int channel, int value);
194 
195 uint32_t dma_getUsableChannels();
196 
197 int dma_isChannelActive(int channel);
198 
199 int dma_dumpRegistersDense(int channel, char* s);
200 
201 
202 //this tells doxygen to ignore the static assert
204 static_assert(sizeof(ControlBlock)==32, "ControlBlock has wrong size");
206 
207 
208 #endif
uint32_t zero1
This must be zero.
Definition: dma.h:164
int dma_allocControlBlockPhys(uintptr_t srcAddrPhys, uintptr_t dstAddrPhys, size_t transferLength, uintptr_t nextControlBlockPhys, uint32_t transferInfo, uint32_t _2DStrideModeInfo, size_t _2DStrideTransferLenX, size_t _2DStrideTransferLenY, Ccmb_desc *area)
Builds a control block with the specified characteristics.
Definition: dma.cpp:521
uint32_t zero2
This must be zero.
Definition: dma.h:166
int dma_init()
Initializes the interface, to be called before any other function in this file.
Definition: dma.cpp:209
uint32_t dma_getUsableChannels()
Returns a bit mask indicating the usable channels with 1.
Definition: dma.cpp:557
int dma_writeControlBlock(ControlBlock *cb, uintptr_t srcAddrPhys, uintptr_t dstAddrPhys, size_t transferLength, uintptr_t nextControlBlockPhys, uint32_t transferInfo, uint32_t _2DStrideModeInfo, size_t _2DStrideTransferLenX, size_t _2DStrideTransferLenY)
Definition: dma.cpp:486
int dma_isInit()
Says if dma_init has been called with success.
Definition: dma.cpp:227
uint32_t nextControlBlockAddrPhys
The physical address of the next control block, 0 if there isn&#39;t a next control block.
Definition: dma.h:162
int dma_dumpRegisters(int channel, char *s)
For debug purposes: writes the register&#39;s contents on the provided string.
Definition: dma.cpp:267
uint32_t transferInfo
The tranfer info register: fill using the TI_* macros.
Definition: dma.h:152
int dma_printControlBlock(ControlBlock *cb)
For debug purposes: prints the control block&#39;s contents on standard output.
Definition: dma.cpp:331
int dma_controlBlockToString(ControlBlock *cb, char *s)
For debug purposes: writes the control block&#39;s contents on a string.
Definition: dma.cpp:343
Describes a Cache Coherent Memory Block allocated by ccmp_malloc()
Definition: cacheCoherentMemoryProvider.h:23
int dma_dumpRegistersDense(int channel, char *s)
For debug purposes: writes the register&#39;s contents on the provided string, in a single line...
Definition: dma.cpp:304
int dma_setChannelGlobalEnable(int channel, int value)
Set the global enable status for the specified channel.
Definition: dma.cpp:388
int dma_setControlBlockAddr(int channel, uint32_t controlBlockAddrPhys)
Sets the address of the control block to be loaded in the dma engine, to start the transfer you then ...
Definition: dma.cpp:457
uint32_t srcAddrPhys
The physical source address.
Definition: dma.h:154
uint32_t _2DStrideMode
The 2DStride register, fill using the REG_2D_* macros.
Definition: dma.h:160
volatile struct ControlBlock_struct ControlBlock
Describes a control block, contorl blocks are needed to load the registers of the DMA engine and star...
int dma_channelResetInitDefault(int channel)
Resets the channel and sets it to default values.
Definition: dma.cpp:361
uint32_t dstAddrPhys
The physical destination address.
Definition: dma.h:156
uint32_t transferLength
The transfer length register, fill using the TL_* macros.
Definition: dma.h:158
int dma_setChannelActive(int channel, int value)
Sets the channel active bit, this is automatically cleared at the end of each control block chain...
Definition: dma.cpp:411
int dma_isChannelActive(int channel)
Gets the channel active bit, this is automatically cleared at the end of each control block chain...
Definition: dma.cpp:436
Describes a control block, contorl blocks are needed to load the registers of the DMA engine and star...
Definition: dma.h:149
int dma_printRegisters(int channel)
For debug purposes: prints the registers&#39; contents to standard output.
Definition: dma.cpp:239