1 /******************************************************************************
2 * @file  rsi_rom_udma.h
3 *******************************************************************************
4 * # License
5 * <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
6 *******************************************************************************
7 *
8 * SPDX-License-Identifier: Zlib
9 *
10 * The licensor of this software is Silicon Laboratories Inc.
11 *
12 * This software is provided 'as-is', without any express or implied
13 * warranty. In no event will the authors be held liable for any damages
14 * arising from the use of this software.
15 *
16 * Permission is granted to anyone to use this software for any purpose,
17 * including commercial applications, and to alter it and redistribute it
18 * freely, subject to the following restrictions:
19 *
20 * 1. The origin of this software must not be misrepresented; you must not
21 *    claim that you wrote the original software. If you use this software
22 *    in a product, an acknowledgment in the product documentation would be
23 *    appreciated but is not required.
24 * 2. Altered source versions must be plainly marked as such, and must not be
25 *    misrepresented as being the original software.
26 * 3. This notice may not be removed or altered from any source distribution.
27 *
28 ******************************************************************************/
29 
30 #ifndef __RSI_ROM_UDMA_H__
31 #define __RSI_ROM_UDMA_H__
32 
33 /**
34  * \ingroup   RSI_SPECIFIC_DRIVERS
35  * \defgroup RSI_UDMA_DRIVER
36  *  @{
37  *
38  */
39 #include "rsi_ccp_user_config.h"
40 #include "rsi_packing.h"
41 #if defined(A11_ROM)
42 #include "rsi_rom_table_si91x.h"
43 #else
44 #include "rsi_rom_table_RS1xxxx.h"
45 #endif
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /**
52  * @fn         STATIC INLINE rsi_error_t RSI_UDMA_SetupChannelTransfer( RSI_UDMA_HANDLE_T pHandle, RSI_UDMA_CHA_CFG_T *pCfg,
53 																			                RSI_UDMA_CHA_CONFIG_DATA_T vsUdmaChaConfigData,
54                                                       void *pSrcAddr, void *pDstAddr )
55  * @brief		   This API is used to control parameters for a UDMA channel control structure.
56  * @param[in]	 pHandle	            : Pointer to driver context handle
57  * @param[in]	 pCfg	                : Pointer to channel configuration structure \ref RSI_UDMA_CHA_CFG_T
58  * @param[in]  vsUdmaChaConfigData  :structure variable of type RSI_UDMA_CHA_CONFIG_DATA ,structure has below members
59 	                                 to configure and possible values
60                                    -  transferType : The operating mode of the DMA cycle
61 	                                                          - \ref UDMA_MODE_STOP
62 	                                                          - \ref UDMA_MODE_BASIC
63 	                                                          - \ref UDMA_MODE_AUTO
64 	                                                          - \ref UDMA_MODE_PINGPONG
65 	                                                          - \ref UDMA_MODE_MEM_SCATTER_GATHER
66 	                                                          - \ref UDMA_MODE_PER_SCATTER_GATHER
67                                    -  nextBurst : Controls if the chnl_useburst_set[0] bit is set to a 1
68 	                                                    when the controller is performing a peripheral scatter-gather
69 	                                                    and is completing a DMA cycle that uses the alternate data
70 																											structure
71 	                                                          -  0 : the controller does not change the value of the
72 	                                                                   chnl_useburst_set[0]bit
73 	                                                          -  1 : the controller sets the chnl_useburst_set [0] bit
74 	                                                                   to a 1
75                                    -  totalNumOfDMATrans : Represent the total number of DMA transfers that
76 	                                                             the DMA cycle contains
77 	                                                             \n possible values are 0x00 to 0x1FF for
78 	                                                                1 to 1024 transfers
79                                    -  rPower : The arbitration size determines how many items are
80 	                                                 transferred before the uDMA controller re-arbitrates for
81 	                                                 the bus.  Choose the arbitration size from one of
82 	                                                          - \ref ARBSIZE_1
83 	                                                          - \ref ARBSIZE_2
84 	                                                          - \ref ARBSIZE_4
85 	                                                          - \ref ARBSIZE_16
86 	                                                          - \ref ARBSIZE_64
87 	                                                          - \ref ARBSIZE_128
88 	                                                          - \ref ARBSIZE_256
89 	                                                          - \ref ARBSIZE_512
90 	                                                          - \ref ARBSIZE_1024
91 	                                                          \n to select the arbitration size from 1 to 1024 items,
92 	                                                          in powers of 2
93                                    -  srcProtCtrl : Set the bits to control the state of HPROT[3:1]
94 	                                                      when the controller reads the source data.
95                                    -  dstProtCtrl : Set the bits to control the state of HPROT[3:1] when
96 	                                                      the controller writes the destination data.
97                                    -  srcSize : Choose the source data size from one of
98               	                                            - \ref SRC_SIZE_8
99 	                                                          - \ref SRC_SIZE_16
100 	                                                          - \ref SRC_SIZE_32
101 	                                                          \n to select a data size of 8, 16, or 32 bits
102                                    -  dstSize : Choose the destination data size from one of
103               	                                            - \ref DST_SIZE_8
104 	                                                          - \ref DST_SIZE_16
105 	                                                          - \ref DST_SIZE_32
106 	                                                          \n to select a data size of 8, 16, or 32 bits
107                                    -  srcInc : Choose the source address increment from one of
108               	                                            - \ref SRC_INC_8
109 	                                                          - \ref SRC_INC_16
110 	                                                          - \ref SRC_INC_32
111 	                                                          - \ref SRC_INC_NONE
112 	                                                          \n to select a data size of 8, 16, or 32 bits
113  	                                                          half-words, 32-bit words, or to select non-incrementing.
114                                    -  dstInc : Choose the destination address increment from one of
115               	                                            - \ref DST_INC_8
116 	                                                          - \ref DST_INC_8
117 	                                                          - \ref DST_INC_8
118 	                                                          - \ref DST_INC_NONE
119 	                                                          \n to select a data size of 8, 16, or 32 bits
120  	                                                          half-words, 32-bit words, or to select non-incrementing.
121  * @param[in]  pSrcAddr : Pointer to source address
122  * @param[in]  pDstAddr : Pointer to destination address
123  * @return 		  \ref RSI_OK if no errors occurred, or an error code
124  */
RSI_UDMA_SetupChannelTransfer(RSI_UDMA_HANDLE_T pHandle,const RSI_UDMA_CHA_CFG_T * pCfg,RSI_UDMA_CHA_CONFIG_DATA_T vsUdmaChaConfigData,void * pSrcAddr,void * pDstAddr)125 STATIC INLINE rsi_error_t RSI_UDMA_SetupChannelTransfer(RSI_UDMA_HANDLE_T pHandle,
126                                                         const RSI_UDMA_CHA_CFG_T *pCfg,
127                                                         RSI_UDMA_CHA_CONFIG_DATA_T vsUdmaChaConfigData,
128                                                         void *pSrcAddr,
129                                                         void *pDstAddr)
130 {
131 #if defined(UDMA_ROMDRIVER_PRESENT)
132   return ROMAPI_UDMA_API->udma_setup_channel_transfer(pHandle, pCfg, vsUdmaChaConfigData, pSrcAddr, pDstAddr);
133 #else
134   return udma_setup_channel_transfer(pHandle, pCfg, vsUdmaChaConfigData, pSrcAddr, pDstAddr);
135 #endif
136 }
137 
138 /**
139  * @fn          STATIC INLINE rsi_error_t RSI_UDMA_SetChannelScatterGatherTransfer(RSI_UDMA_HANDLE_T pHandle, uint8_t dmaCh,
140                                                                  uint8_t taskCount,
141                                                                  void *pTaskList, uint32_t transferType)
142  * @brief		    This API is used to configures a UDMA channel for scatter-gather mode
143  * @param[in]	  pHandle	     :  Pointer to driver context handle
144  * @param[in]	  dmaCh	       :  Channel number(0 to 31)
145  * @param[in]	  taskCount    :  Number of scatter-gather tasks to execute
146  * @param[in]	  pTaskList    :  pointer to the beginning of the scatter-gather task list
147  * @param[in]	  transferType :  Transfer type
148  * @return 		  return \ref ERROR_UDMA_INVALID_ARG if channel is  greater than 31, and on success return \ref RSI_OK
149  */
RSI_UDMA_SetChannelScatterGatherTransfer(RSI_UDMA_HANDLE_T pHandle,uint8_t dmaCh,uint8_t taskCount,void * pTaskList,uint32_t transferType)150 STATIC INLINE rsi_error_t RSI_UDMA_SetChannelScatterGatherTransfer(RSI_UDMA_HANDLE_T pHandle,
151                                                                    uint8_t dmaCh,
152                                                                    uint8_t taskCount,
153                                                                    void *pTaskList,
154                                                                    uint32_t transferType)
155 
156 {
157 #if defined(UDMA_ROMDRIVER_PRESENT)
158   return ROMAPI_UDMA_API->udma_set_channel_scatter_gather_transfer(pHandle, dmaCh, taskCount, pTaskList, transferType);
159 
160 #else
161   return udma_set_channel_scatter_gather_transfer(pHandle, dmaCh, taskCount, pTaskList, transferType);
162 #endif
163 }
164 
165 /**
166  * @fn          STATIC INLINE uint32_t  RSI_UDMA_GetChannelTransferLength(RSI_UDMA_HANDLE_T pHandle, RSI_UDMA_CHA_CFG_T *pCfg,
167 																					                 RSI_UDMA_CHA_CONFIG_DATA_T vsUDMAChaConfigData)
168 
169  * @brief		    Gets the current transfer size for a UDMA channel control structure
170  * @param[in]	  pHandle	:  Pointer to driver context handle
171  * @param[in]	  pCfg	  :  Pointer to channel configuration structure \ref RSI_UDMA_CHA_CFG_T
172  * @param[in]   vsUDMAChaConfigData  :   structure variable of type \ref RSI_UDMA_CHA_CONFIG_DATA
173  * @return 		  Number of items remaining to transfer and all transmission is complete then return RSI_OK(0)
174  * @note        This function is used to get the UDMA transfer size for a channel.
175 								The transfer size is the number of items to transfer, where the size of an item
176 								might be 8, 16, or 32 bits.  If a partial transfer has already occurred,
177 								then the number of remaining items is returned.  If the transfer is
178 								complete, then 0 is returned.
179  */
RSI_UDMA_GetChannelTransferLength(RSI_UDMA_HANDLE_T pHandle,const RSI_UDMA_CHA_CFG_T * pCfg,RSI_UDMA_CHA_CONFIG_DATA_T vsUDMAChaConfigData)180 STATIC INLINE uint32_t RSI_UDMA_GetChannelTransferLength(RSI_UDMA_HANDLE_T pHandle,
181                                                          const RSI_UDMA_CHA_CFG_T *pCfg,
182                                                          RSI_UDMA_CHA_CONFIG_DATA_T vsUDMAChaConfigData)
183 {
184 #if defined(UDMA_ROMDRIVER_PRESENT)
185   return ROMAPI_UDMA_API->udma_get_channel_transfer_length(pHandle, pCfg, vsUDMAChaConfigData);
186 #else
187   return udma_get_channel_transfer_length(pHandle, pCfg, vsUDMAChaConfigData);
188 #endif
189 }
190 /**
191 
192  * @fn          STATIC INLINE uint32_t  RSI_UDMA_GetChannelTransferMode(RSI_UDMA_HANDLE_T pHandle, const RSI_UDMA_CHA_CFG_T *pCfg)
193  * @brief		    Gets the transfer mode for a UDMA channel control structure.
194  * @param[in]	   pHandle	:  Pointer to driver context handle
195  * @param[in]   pCfg	  : Pointer to DMA channel configuration structure \RSI_UDMA_CHA_CFG_T required parameter below
196                           - \ref channelPrioHigh : channel priority level.
197                           - \ref altStruct       : alternate structure if 1 then enable alternate structure
198                                                    if 0 then primary structure
199                           - \ref burstReq        : Burst request
200                           - \ref reqMask         : mask the specific channel.
201                           - \ref periphReq       : peripheral request like i2c ,i2s etc
202                           - \ref periAck         : peripheral ack like i2c ,i2s etc
203                           - \ref dmaCh           :dma channel number(0-31)
204  * @return 		  Returns the transfer mode of the specified channel and control structure,possible value is below
205                           - \ref UDMA_MODE_STOP
206                           - \ref UDMA_MODE_BASIC
207                           - \ref UDMA_MODE_AUTO
208                           - \ref UDMA_MODE_PINGPONG
209                           - \ref UDMA_MODE_MEM_SCATTER_GATHER
210                           - \ref UDMA_MODE_PER_SCATTER_GATHER
211  */
212 
RSI_UDMA_GetChannelTransferMode(RSI_UDMA_HANDLE_T pHandle,const RSI_UDMA_CHA_CFG_T * pCfg)213 STATIC INLINE uint32_t RSI_UDMA_GetChannelTransferMode(RSI_UDMA_HANDLE_T pHandle, const RSI_UDMA_CHA_CFG_T *pCfg)
214 {
215 #if defined(UDMA_ROMDRIVER_PRESENT)
216   return ROMAPI_UDMA_API->udma_get_channel_transfer_mode(pHandle, pCfg);
217 #else
218   return udma_get_channel_transfer_mode(pHandle, pCfg);
219 #endif
220 }
221 /**
222  * @fn          RSI_UDMA_HANDLE_T RSI_UDMA_Init(void *mem, const RSI_UDMA_INIT_T *pInit)
223 
224  * @brief		    This API is used to initialize driver context parameters
225  * @param[in]   pInit	  : Pointer to DMA controller init data
226  * @param[in]   mem		  : Pointer to memory area used to driver context
227  * @return 		  NULL on error, or a pointer to the device context handle
228  */
RSI_UDMA_Init(void * mem,const RSI_UDMA_INIT_T * pInit)229 STATIC INLINE RSI_UDMA_HANDLE_T RSI_UDMA_Init(void *mem, const RSI_UDMA_INIT_T *pInit)
230 {
231 #if defined(UDMA_ROMDRIVER_PRESENT)
232   return ROMAPI_UDMA_API->udma_init(mem, pInit);
233 #else
234   return udma_init(mem, pInit);
235 #endif
236 }
237 
238 /**
239  * @fn          STATIC INLINE rsi_error_t RSI_UDMA_SetupChannel(RSI_UDMA_HANDLE_T pHandle, RSI_UDMA_CHA_CFG_T *pCfg)
240 
241  * @brief		    This API is used to configures required parameters for a channel
242  * @param[in]   pHandle	: Pointer to driver context handle
243  * @param[in]   pCfg	  : Pointer to DMA channel configuration structure \RSI_UDMA_CHA_CFG_T required parameter below
244                           - \ref channelPrioHigh : channel priority level.
245                           - \ref altStruct       : alternate structure if 1 then enable alternate structure
246                                                    if 0 then primary structure
247                           - \ref burstReq        : Burst request
248                           - \ref reqMask         : mask the specific channel.
249                           - \ref periphReq       : peripheral request like i2c ,i2s etc
250                           - \ref periAck         : peripheral ack like i2c ,i2s etc
251                           - \ref dmaCh           :dma channel number(0-31)
252  * @return 		  - \ref  RSI_OK if no errors occurred, or an error code
253  */
RSI_UDMA_SetupChannel(RSI_UDMA_HANDLE_T pHandle,const RSI_UDMA_CHA_CFG_T * pCfg)254 STATIC INLINE rsi_error_t RSI_UDMA_SetupChannel(RSI_UDMA_HANDLE_T pHandle, const RSI_UDMA_CHA_CFG_T *pCfg)
255 {
256 #if defined(UDMA_ROMDRIVER_PRESENT)
257   return ROMAPI_UDMA_API->udma_setup_channel(pHandle, pCfg);
258 #else
259   return udma_setup_channel(pHandle, pCfg);
260 #endif
261 }
262 /**
263  * @fn          STATIC INLINE void  RSI_UDMA_DeInit(RSI_UDMA_HANDLE_T pHandle, const RSI_UDMA_CHA_CFG_T *pCfg)
264  * @brief		    This API is used to Uninitialized driver context parameters
265  * @param[in]   pHandle	: Pointer to driver context handle
266  * @param[in]   pCfg	  : Pointer to DMA channel configuration structure
267  * @return 		  none
268  */
RSI_UDMA_DeInit(RSI_UDMA_HANDLE_T pHandle,const RSI_UDMA_CHA_CFG_T * pCfg)269 STATIC INLINE void RSI_UDMA_DeInit(RSI_UDMA_HANDLE_T pHandle, const RSI_UDMA_CHA_CFG_T *pCfg)
270 {
271 #if defined(UDMA_ROMDRIVER_PRESENT)
272   ROMAPI_UDMA_API->udma_deInit(pHandle, pCfg);
273 #else
274   udma_deInit(pHandle, pCfg);
275 #endif
276 }
277 /**
278  * @fn          STATIC INLINE void  RSI_UDMA_Interrupthandler(RSI_UDMA_HANDLE_T pHandle)
279  * @brief		    This API is used to handle all interrupt and error flags in interrupt context
280  * @param[in]   pHandle	:  Pointer to driver context handle
281  * @return 		  none
282  * @note(s)     This function should be called from the DMA interrupt handler
283  */
284 
RSI_UDMA_Interrupthandler(RSI_UDMA_HANDLE_T pHandle)285 STATIC INLINE void RSI_UDMA_Interrupthandler(RSI_UDMA_HANDLE_T pHandle)
286 {
287 #if defined(UDMA_ROMDRIVER_PRESENT)
288   ROMAPI_UDMA_API->udma_interrupt_handler(pHandle);
289 #else
290   udma_interrupt_handler(pHandle);
291 #endif
292 }
293 
294 /**
295  * @fn          STATIC INLINE rsi_error_t RSI_UDMA_InterruptEnable(RSI_UDMA_HANDLE_T pHandle, uint8_t dmaCh)
296  * @brief		    This API is used to enable the done interrupt to processor
297  * @param[in]	  pHandle	 : Pointer to driver context handle
298  * @param[in]	  dmaCh    :  Channel number(0 to 31)
299  * @return 		  return \ref ERROR_UDMA_INVALID_ARG if channel is  greater than 31, and on success return \ref RSI_OK
300  */
RSI_UDMA_InterruptEnable(RSI_UDMA_HANDLE_T pHandle,uint8_t dmaCh)301 STATIC INLINE rsi_error_t RSI_UDMA_InterruptEnable(RSI_UDMA_HANDLE_T pHandle, uint8_t dmaCh)
302 {
303 #if defined(UDMA_ROMDRIVER_PRESENT)
304   return ROMAPI_UDMA_API->udma_interrupt_enable(pHandle, dmaCh);
305 #else
306   return udma_interrupt_enable(pHandle, dmaCh);
307 #endif
308 }
309 /* @} end of  RSI_UDMA_DRIVERS */
310 /**************************************************************************************
311 								              UDMA ROM FUNCTION PROTOTYPES
312 		 **************************************************************************************/
313 rsi_error_t RSI_UDMA_SetupChannelTransfer(RSI_UDMA_HANDLE_T pHandle,
314                                           const RSI_UDMA_CHA_CFG_T *pCfg,
315                                           RSI_UDMA_CHA_CONFIG_DATA_T vsUdmaChaConfigData,
316                                           void *pSrcAddr,
317                                           void *pDstAddr);
318 
319 rsi_error_t RSI_UDMA_SetChannelScatterGatherTransfer(RSI_UDMA_HANDLE_T pHandle,
320                                                      uint8_t dmaCh,
321                                                      uint8_t taskCount,
322                                                      void *pTaskList,
323                                                      uint32_t transferType);
324 
325 uint32_t RSI_UDMA_GetChannelTransferLength(RSI_UDMA_HANDLE_T pHandle,
326                                            const RSI_UDMA_CHA_CFG_T *pCfg,
327                                            RSI_UDMA_CHA_CONFIG_DATA_T vsUDMAChaConfigData);
328 
329 uint32_t RSI_UDMA_GetChannelTransferMode(RSI_UDMA_HANDLE_T pHandle, const RSI_UDMA_CHA_CFG_T *pCfg);
330 
331 RSI_UDMA_HANDLE_T RSI_UDMA_Init(void *mem, const RSI_UDMA_INIT_T *pInit);
332 
333 rsi_error_t RSI_UDMA_SetupChannel(RSI_UDMA_HANDLE_T pHandle, const RSI_UDMA_CHA_CFG_T *pCfg);
334 
335 static void RSI_UDMA_DeInit(RSI_UDMA_HANDLE_T pHandle, const RSI_UDMA_CHA_CFG_T *pCfg);
336 
337 void RSI_UDMA_Interrupthandler(RSI_UDMA_HANDLE_T pHandle);
338 
339 rsi_error_t RSI_UDMA_InterruptEnable(RSI_UDMA_HANDLE_T pHandle, uint8_t dmaCh);
340 
341 #ifdef __cplusplus
342 }
343 #endif
344 
345 #endif /* __RSI_ROM_UDMA_H__*/
346