ADuCM302x Device Drivers API Reference Manual  Release 3.1.2.0
adi_sport_def.h
1 
45 #ifndef ADI_SPORT_DEF_H
46 #define ADI_SPORT_DEF_H
47 
48 #include <drivers/general/adi_data_transfer.h>
49 
50 #if defined(ADI_CFG_SPORT0A_SERIAL_WLEN)
51 #if (ADI_CFG_SPORT0A_SERIAL_WLEN <= 3u) || (ADI_CFG_SPORT0A_SERIAL_WLEN > 32u)
52 #error "Invalid word length : it must be between 4 and 32"
53 #endif
54 #else
55 #error "ADI_CFG_SPORT0A_SERIAL_WLEN undefined!!! "
56 #endif
57 
58 #if defined(ADI_CFG_SPORT0B_SERIAL_WLEN)
59 #if (ADI_CFG_SPORT0B_SERIAL_WLEN <= 3u) || (ADI_CFG_SPORT0B_SERIAL_WLEN > 32u)
60 #error "Invalid word length : it must be between 4 and 32"
61 #endif
62 #else
63 #error "ADI_CFG_SPORT0B_SERIAL_WLEN undefined!!! "
64 #endif
65 
66 #define ADI_SPORT_NUM_INSTANCES (1u)
67 #define ADI_SPORT_NUM_CHANNELS (2u)
69 #define BITM_SPORT_DATA_CONFIG ( BITM_SPORT_CTL_A_LSBF \
70  | BITM_SPORT_CTL_A_PACK)
71 
72 #define BITM_SPORT_CLOCK_CONFIG ( BITM_SPORT_CTL_A_ICLK \
73  | BITM_SPORT_CTL_A_CKRE \
74  | BITM_SPORT_CTL_A_GCLKEN)
75 
76 #define BITM_SPORT_FS_CONFIG ( BITM_SPORT_CTL_A_FSR \
77  | BITM_SPORT_CTL_A_IFS \
78  | BITM_SPORT_CTL_A_DIFS \
79  | BITM_SPORT_CTL_A_LFS \
80  | BITM_SPORT_CTL_A_LAFS \
81  | BITM_SPORT_CTL_A_FSERRMODE)
82 
83 #define SPORT_BYTE_TRANSFER_LENGTH (8u)
84 #define SPORT_HALFWORD_TRANSFER_LENGTH (16u)
85 #define SPORT_WORD_TRANSFER_LENGTH (32u)
86 
87 #define SPORT_GET_WLEN(ctlVal) ((((ctlVal) & (uint32_t) BITM_SPORT_CTL_A_SLEN) >> ((uint32_t) BITP_SPORT_CTL_A_SLEN)) + 1u)
88 #define SPORT_GET_PACKEN(ctlVal) ((ctlVal) & (uint32_t) BITM_SPORT_CTL_A_PACK) >> ((uint32_t) BITP_SPORT_CTL_A_PACK)
89 
90 #define SPORT_CHECK_CFG_CTL(CFG) assert(0u == ((CFG) & (((uint32_t)BITM_SPORT_CTL_A_SPEN) | ((uint32_t)BITM_SPORT_CTL_A_DMAEN))))
91 
92 
93 #define SPORT_BIT_PACK_NONE (((uint32_t) ADI_SPORT_NO_PACKING) >> ((uint32_t) BITP_SPORT_CTL_A_PACK))
94 #define SPORT_BIT_PACK_8 (((uint32_t) ADI_SPORT_8BIT_PACKING) >> ((uint32_t) BITP_SPORT_CTL_A_PACK))
95 #define SPORT_BIT_PACK_16 (((uint32_t) ADI_SPORT_16BIT_PACKING) >> ((uint32_t) BITP_SPORT_CTL_A_PACK))
96 
102 typedef enum
103 {
104  ADI_SPORT_STATE_UNINITIALIZED = 0,
105  ADI_SPORT_STATE_INITIALIZED,
106  ADI_SPORT_STATE_DATA_FLOW_ENABLED,
107  ADI_SPORT_STATE_DATA_FLOW_DISABLED,
108  ADI_SPORT_STATE_PAUSED
109 } ADI_SPORT_STATE;
110 
117 typedef struct _ADI_SPORT_CONFIG
118 {
119  uint32_t CTL;
120  uint32_t DIV;
121  uint32_t TIM_CONVT;
122  uint32_t DMA_WIDTH;
123  uint32_t DMA_INC;
124 } ADI_SPORT_CONFIG;
125 
131 typedef struct _ADI_SPORT_DEVICE_INFO
132 {
133  volatile ADI_SPORT_TypeDef* pSportRegs;
134  ADI_SPORT_CONFIG sportCfg;
135  ADI_SPORT_STATE eState;
136  const DMA_CHANn_TypeDef eDMAChnlID;
137  const IRQn_Type eDMAn;
138  const IRQn_Type eIRQn;
139  ADI_SPORT_HANDLE hDevice;
140 } ADI_SPORT_DEVICE_INFO;
141 
142 /******************************************************************************
143  * SPORT Device internal API function prototypes
144  *****************************************************************************/
145 
146 #define NUM_SPORT_BUFFER (2u)
147 
149 typedef struct _ADI_SPORT_DEVICE
150 {
151  ADI_SPORT_DEVICE_INFO * pSportInfo;
152  ADI_SPORT_DIRECTION eDirection;
153  ADI_CALLBACK pfCallback;
154  void * pCBParam;
155  ADI_DT_CHANNEL sportChannel;
156  volatile uint32_t nHwError;
157 } ADI_SPORT_DEVICE;
158 
160 static inline void sport_Init (ADI_SPORT_DEVICE * pDevice);
161 
163 static inline void sport_Configure (ADI_SPORT_DEVICE *pDevice, ADI_SPORT_CONFIG const * sportCfg);
164 
166 static ADI_SPORT_RESULT sport_SubmitBufferDmaMode(ADI_SPORT_DEVICE * pDevice, ADI_DT_BUFF_INFO * pBuff);
167 
169 static ADI_SPORT_RESULT sport_SubmitBufferIntMode(ADI_SPORT_DEVICE * pDevice, ADI_DT_BUFF_INFO * pBuff);
170 
172 static void sport_Terminate(ADI_SPORT_DEVICE * pDevice);
173 
177 static void sport_InterruptHandler(ADI_SPORT_DEVICE * pDevice);
178 
179 static inline void sport_DmaErrorCallback(void *pCBParam, uint32_t Event, void *pArg);
180 
181 static inline uint32_t GetBytesPerSportData(const uint32_t ctlVal);
182 
183 /*
184  * Handle Validation function
185 */
186 #ifdef ADI_DEBUG
187 static ADI_SPORT_RESULT ValidateHandle(ADI_SPORT_HANDLE const hDevice);
188 #endif /* ADI_DEBUG */
189 
190 #endif /* end of ifndef ADI_SPORT_DEF_H */
191 
ADI_SPORT_DIRECTION
Definition: adi_sport.h:87
void * ADI_SPORT_HANDLE
Definition: adi_sport.h:73
ADI_SPORT_RESULT
Definition: adi_sport.h:125