ADuCM4x50 Device Drivers API Reference Manual  Release 4.0.0.0
adi_sport_def.h
1 
14 #ifndef ADI_SPORT_DEF_H
15 #define ADI_SPORT_DEF_H
16 
17 #include <drivers/general/adi_data_transfer.h>
18 
19 #if defined(ADI_CFG_SPORT0A_SERIAL_WLEN)
20 #if (ADI_CFG_SPORT0A_SERIAL_WLEN <= 3u) || (ADI_CFG_SPORT0A_SERIAL_WLEN > 32u)
21 #error "Invalid word length : it must be between 4 and 32"
22 #endif
23 #else
24 #error "ADI_CFG_SPORT0A_SERIAL_WLEN undefined!!! "
25 #endif
26 
27 #if defined(ADI_CFG_SPORT0B_SERIAL_WLEN)
28 #if (ADI_CFG_SPORT0B_SERIAL_WLEN <= 3u) || (ADI_CFG_SPORT0B_SERIAL_WLEN > 32u)
29 #error "Invalid word length : it must be between 4 and 32"
30 #endif
31 #else
32 #error "ADI_CFG_SPORT0B_SERIAL_WLEN undefined!!! "
33 #endif
34 
35 #define ADI_SPORT_NUM_INSTANCES (1u)
36 #define ADI_SPORT_NUM_CHANNELS (2u)
38 #define BITM_SPORT_DATA_CONFIG ( BITM_SPORT_CTL_A_LSBF \
39  | BITM_SPORT_CTL_A_PACK)
40 
41 #define BITM_SPORT_CLOCK_CONFIG ( BITM_SPORT_CTL_A_ICLK \
42  | BITM_SPORT_CTL_A_CKRE \
43  | BITM_SPORT_CTL_A_GCLKEN)
44 
45 #define BITM_SPORT_FS_CONFIG ( BITM_SPORT_CTL_A_FSR \
46  | BITM_SPORT_CTL_A_IFS \
47  | BITM_SPORT_CTL_A_DIFS \
48  | BITM_SPORT_CTL_A_LFS \
49  | BITM_SPORT_CTL_A_LAFS \
50  | BITM_SPORT_CTL_A_FSERRMODE)
51 
52 #define SPORT_BYTE_TRANSFER_LENGTH (8u)
53 #define SPORT_HALFWORD_TRANSFER_LENGTH (16u)
54 #define SPORT_WORD_TRANSFER_LENGTH (32u)
55 
56 #define SPORT_GET_WLEN(ctlVal) ((((ctlVal) & (uint32_t) BITM_SPORT_CTL_A_SLEN) >> ((uint32_t) BITP_SPORT_CTL_A_SLEN)) + 1u)
57 #define SPORT_GET_PACKEN(ctlVal) ((ctlVal) & (uint32_t) BITM_SPORT_CTL_A_PACK) >> ((uint32_t) BITP_SPORT_CTL_A_PACK)
58 
59 #define SPORT_CHECK_CFG_CTL(CFG) assert(0u == ((CFG) & (((uint32_t)BITM_SPORT_CTL_A_SPEN) | ((uint32_t)BITM_SPORT_CTL_A_DMAEN))))
60 
61 
62 #define SPORT_BIT_PACK_NONE (((uint32_t) ADI_SPORT_NO_PACKING) >> ((uint32_t) BITP_SPORT_CTL_A_PACK))
63 #define SPORT_BIT_PACK_8 (((uint32_t) ADI_SPORT_8BIT_PACKING) >> ((uint32_t) BITP_SPORT_CTL_A_PACK))
64 #define SPORT_BIT_PACK_16 (((uint32_t) ADI_SPORT_16BIT_PACKING) >> ((uint32_t) BITP_SPORT_CTL_A_PACK))
65 
71 typedef enum
72 {
73  ADI_SPORT_STATE_UNINITIALIZED = 0,
74  ADI_SPORT_STATE_INITIALIZED,
75  ADI_SPORT_STATE_DATA_FLOW_ENABLED,
76  ADI_SPORT_STATE_DATA_FLOW_DISABLED,
77  ADI_SPORT_STATE_PAUSED
78 } ADI_SPORT_STATE;
79 
86 typedef struct _ADI_SPORT_CONFIG
87 {
88  uint32_t CTL;
89  uint32_t DIV;
90  uint32_t TIM_CONVT;
91  uint32_t DMA_WIDTH;
92  uint32_t DMA_INC;
93 } ADI_SPORT_CONFIG;
94 
100 typedef struct _ADI_SPORT_DEVICE_INFO
101 {
102  volatile ADI_SPORT_TypeDef* pSportRegs;
103  ADI_SPORT_CONFIG sportCfg;
104  ADI_SPORT_STATE eState;
105  const DMA_CHANn_TypeDef eDMAChnlID;
106  const IRQn_Type eDMAn;
107  const IRQn_Type eIRQn;
108  ADI_SPORT_HANDLE hDevice;
109 } ADI_SPORT_DEVICE_INFO;
110 
111 /******************************************************************************
112  * SPORT Device internal API function prototypes
113  *****************************************************************************/
114 
115 #define NUM_SPORT_BUFFER (2u)
116 
118 typedef struct _ADI_SPORT_DEVICE
119 {
120  ADI_SPORT_DEVICE_INFO * pSportInfo;
121  ADI_SPORT_DIRECTION eDirection;
122  ADI_CALLBACK pfCallback;
123  void * pCBParam;
124  ADI_DT_CHANNEL sportChannel;
125  volatile uint32_t nHwError;
126 } ADI_SPORT_DEVICE;
127 
129 static inline void sport_Init (ADI_SPORT_DEVICE * pDevice);
130 
132 static inline void sport_Configure (ADI_SPORT_DEVICE *pDevice, ADI_SPORT_CONFIG const * sportCfg);
133 
135 static ADI_SPORT_RESULT sport_SubmitBufferDmaMode(ADI_SPORT_DEVICE * pDevice, ADI_DT_BUFF_INFO * pBuff);
136 
138 static ADI_SPORT_RESULT sport_SubmitBufferIntMode(ADI_SPORT_DEVICE * pDevice, ADI_DT_BUFF_INFO * pBuff);
139 
141 static void sport_Terminate(ADI_SPORT_DEVICE * pDevice);
142 
146 static void sport_InterruptHandler(ADI_SPORT_DEVICE * pDevice);
147 
148 static inline void sport_DmaErrorCallback(void *pCBParam, uint32_t Event, void *pArg);
149 
150 static inline uint32_t GetBytesPerSportData(const uint32_t ctlVal);
151 
152 /*
153  * Handle Validation function
154 */
155 #ifdef ADI_DEBUG
156 static ADI_SPORT_RESULT ValidateHandle(ADI_SPORT_HANDLE const hDevice);
157 #endif /* ADI_DEBUG */
158 
159 #endif /* end of ifndef ADI_SPORT_DEF_H */
160 
ADI_SPORT_DIRECTION
Definition: adi_sport.h:56
void * ADI_SPORT_HANDLE
Definition: adi_sport.h:42
ADI_SPORT_RESULT
Definition: adi_sport.h:94