PER Firmware
Loading...
Searching...
No Matches
dma.h
Go to the documentation of this file.
1
12#ifndef __PHAL_G4_DMA_H__
13#define __PHAL_G4_DMA_H__
14
15#include "common/phal_G4/phal_G4.h"
16
17typedef enum {
18 DMA_SIZE_8BIT = 0,
19 DMA_SIZE_16BIT = 1,
20 DMA_SIZE_32BIT = 2
21} dma_size_t;
22
23// Mux requests (TODO support all)
24#define DMA_REQUEST_ADC1 5U
25
26#define DMA_REQUEST_SPI1_RX 10U
27#define DMA_REQUEST_SPI1_TX 11U
28#define DMA_REQUEST_SPI2_RX 12U
29#define DMA_REQUEST_SPI2_TX 13U
30#define DMA_REQUEST_SPI3_RX 14U
31#define DMA_REQUEST_SPI3_TX 15U
32
33#define DMA_REQUEST_USART1_RX 24U
34#define DMA_REQUEST_USART1_TX 25U
35#define DMA_REQUEST_USART2_RX 26U
36#define DMA_REQUEST_USART2_TX 27U
37#define DMA_REQUEST_USART3_RX 28U
38#define DMA_REQUEST_USART3_TX 29U
39
40typedef struct {
41 uint32_t periph_addr;
42 uint32_t mem_addr;
43 uint16_t tx_size;
44 uint8_t mem_size;
45
46 bool increment;
47 bool circular;
48 uint8_t dir;
49 bool mem_inc;
50 bool periph_inc;
51 bool mem_to_mem;
52 uint8_t priority;
53 uint8_t periph_size;
54 bool tx_isr_en;
55 uint8_t dma_chan_request;
56 uint8_t channel_idx;
57 uint8_t mux_request;
58
59 DMA_TypeDef* periph;
60 DMA_Channel_TypeDef* channel; // Example DMA1_Stream0 or DMA2_Stream7
62
63/*
64 * @brief Initialize DMA peripheral to set m2m, p2p, or p2m with set size
65 * and length of txfer
66 *
67 * @param dma -> Address of initialization structure
68 * @return true -> Successful init (no clashing params)
69 * @return false -> Init not complete (parameters clash)
70 */
71bool PHAL_initDMA(dma_init_t* dma);
72
73/*
74 * @brief Start txfer after sucessful DMA peripheral initialization
75 *
76 * @param dma -> Address of initialization structure
77 */
78void PHAL_startTxfer(dma_init_t* dma);
79
80/*
81 * @brief Stop txfer
82 *
83 * @param dma -> Address of initialization structure
84 */
85void PHAL_stopTxfer(dma_init_t* dma);
86
87/*
88 * @brief Re-enable DMA txfer after error ISR fires
89 *
90 * @param dma -> Address of initialization structure
91 */
92void PHAL_reEnable(dma_init_t* dma);
93
94/*
95 * @brief Set memory address for DMA transfer. In Mem to Mem this acts as the source address
96 *
97 * @param dma -> Address of initialization structure
98 */
99void PHAL_DMA_setMemAddress(dma_init_t* dma, const uint32_t address);
100
101/*
102 * @brief Set transfer length for DMA transaction
103 *
104 * @param dma -> Address of initialization structure
105 */
106void PHAL_DMA_setTxferLength(dma_init_t* dma, const uint32_t length);
107
108#endif // __PHAL_G4_DMA_H__
Definition dma.h:17