1 /**************************************************************************//**
2  * @file     lppdma.h
3  * @version  V1.00
4  * @brief    M2L31 series LPPDMA driver header file
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  * @copyright (C) 2023 Nuvoton Technology Corp. All rights reserved.
8  *****************************************************************************/
9 #ifndef __LPPDMA_H__
10 #define __LPPDMA_H__
11 
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16 
17 
18 /** @addtogroup Standard_Driver Standard Driver
19   @{
20 */
21 
22 /** @addtogroup LPPDMA_Driver LPPDMA Driver
23   @{
24 */
25 
26 /** @addtogroup LPPDMA_EXPORTED_CONSTANTS LPPDMA Exported Constants
27   @{
28 */
29 #define LPPDMA_CH_MAX    4UL   /*!< Specify Maximum Channels of LPPDMA  \hideinitializer */
30 
31 /*---------------------------------------------------------------------------------------------------------*/
32 /*  Operation Mode Constant Definitions                                                                    */
33 /*---------------------------------------------------------------------------------------------------------*/
34 #define LPPDMA_OP_STOP        0x00000000UL            /*!<DMA Stop Mode  \hideinitializer */
35 #define LPPDMA_OP_BASIC       0x00000001UL            /*!<DMA Basic Mode  \hideinitializer */
36 #define LPPDMA_OP_SCATTER     0x00000002UL            /*!<DMA Scatter-gather Mode  \hideinitializer */
37 
38 /*---------------------------------------------------------------------------------------------------------*/
39 /*  Data Width Constant Definitions                                                                        */
40 /*---------------------------------------------------------------------------------------------------------*/
41 #define LPPDMA_WIDTH_8        0x00000000UL            /*!<DMA Transfer Width 8-bit  \hideinitializer */
42 #define LPPDMA_WIDTH_16       0x00001000UL            /*!<DMA Transfer Width 16-bit  \hideinitializer */
43 #define LPPDMA_WIDTH_32       0x00002000UL            /*!<DMA Transfer Width 32-bit  \hideinitializer */
44 
45 /*---------------------------------------------------------------------------------------------------------*/
46 /*  Address Attribute Constant Definitions                                                                 */
47 /*---------------------------------------------------------------------------------------------------------*/
48 #define LPPDMA_SAR_INC        0x00000000UL            /*!<DMA SAR increment  \hideinitializer */
49 #define LPPDMA_SAR_FIX        0x00000300UL            /*!<DMA SAR fix address  \hideinitializer */
50 #define LPPDMA_DAR_INC        0x00000000UL            /*!<DMA DAR increment  \hideinitializer */
51 #define LPPDMA_DAR_FIX        0x00000C00UL            /*!<DMA DAR fix address  \hideinitializer */
52 
53 /*---------------------------------------------------------------------------------------------------------*/
54 /*  Burst Mode Constant Definitions                                                                        */
55 /*---------------------------------------------------------------------------------------------------------*/
56 #define LPPDMA_REQ_SINGLE     0x00000004UL            /*!<DMA Single Request  \hideinitializer */
57 #define LPPDMA_REQ_BURST      0x00000000UL            /*!<DMA Burst Request  \hideinitializer */
58 
59 #define LPPDMA_BURST_128      0x00000000UL            /*!<DMA Burst 128 Transfers  \hideinitializer */
60 #define LPPDMA_BURST_64       0x00000010UL            /*!<DMA Burst 64 Transfers  \hideinitializer */
61 #define LPPDMA_BURST_32       0x00000020UL            /*!<DMA Burst 32 Transfers  \hideinitializer */
62 #define LPPDMA_BURST_16       0x00000030UL            /*!<DMA Burst 16 Transfers  \hideinitializer */
63 #define LPPDMA_BURST_8        0x00000040UL            /*!<DMA Burst 8 Transfers  \hideinitializer */
64 #define LPPDMA_BURST_4        0x00000050UL            /*!<DMA Burst 4 Transfers  \hideinitializer */
65 #define LPPDMA_BURST_2        0x00000060UL            /*!<DMA Burst 2 Transfers  \hideinitializer */
66 #define LPPDMA_BURST_1        0x00000070UL            /*!<DMA Burst 1 Transfers  \hideinitializer */
67 
68 /*---------------------------------------------------------------------------------------------------------*/
69 /*  Table Interrupt Disable Constant Definitions                                                           */
70 /*---------------------------------------------------------------------------------------------------------*/
71 #define LPPDMA_TBINTDIS_ENABLE  (0x0UL<<LPPDMA_DSCT_CTL_TBINTDIS_Pos)  /*!<DMA Table Interrupt Enabled   \hideinitializer */
72 #define LPPDMA_TBINTDIS_DISABLE (0x1UL<<LPPDMA_DSCT_CTL_TBINTDIS_Pos)  /*!<DMA Table Interrupt Disabled  \hideinitializer */
73 
74 /*---------------------------------------------------------------------------------------------------------*/
75 /*  Peripheral Transfer Mode Constant Definitions                                                          */
76 /*---------------------------------------------------------------------------------------------------------*/
77 #define LPPDMA_MEM            0UL   /*!<DMA Connect to Memory \hideinitializer */
78 #define LPPDMA_LPUART0_TX     1UL   /*!<DMA Connect to LPUART0_TX \hideinitializer */
79 #define LPPDMA_LPUART0_RX     2UL   /*!<DMA Connect to LPUART0_RX \hideinitializer */
80 #define LPPDMA_LPSPI0_TX      3UL   /*!<DMA Connect to LPSPI0_TX \hideinitializer */
81 #define LPPDMA_LPSPI0_RX      4UL   /*!<DMA Connect to LPSPI0_RX \hideinitializer */
82 #define LPPDMA_LPI2C0_TX      5UL   /*!<DMA Connect to LPI2C0_TX \hideinitializer */
83 #define LPPDMA_LPI2C0_RX      6UL   /*!<DMA Connect to LPI2C0_RX \hideinitializer */
84 #define LPPDMA_LPTMR0         7UL   /*!<DMA Connect to LPTMR0 \hideinitializer */
85 #define LPPDMA_LPTMR1         8UL   /*!<DMA Connect to LPTMR1 \hideinitializer */
86 #define LPPDMA_TTMR0          9UL   /*!<DMA Connect to TTMR0 \hideinitializer */
87 #define LPPDMA_TTMR1          10UL  /*!<DMA Connect to TTMR1 \hideinitializer */
88 #define LPPDMA_LPADC0_RX      11UL  /*!<DMA Connect to LPADC0_RX \hideinitializer */
89 #define LPPDMA_ACMP0          14UL  /*!<DMA Connect to ACMP0 \hideinitializer */
90 #define LPPDMA_ACMP1          15UL  /*!<DMA Connect to ACMP1 \hideinitializer */
91 #define LPPDMA_ACMP2          16UL  /*!<DMA Connect to ACMP2 \hideinitializer */
92 
93 /*---------------------------------------------------------------------------------------------------------*/
94 /*  Interrupt Type Constant Definitions                                                                    */
95 /*---------------------------------------------------------------------------------------------------------*/
96 #define LPPDMA_INT_TRANS_DONE 0x00000000UL            /*!<Transfer Done Interrupt  \hideinitializer */
97 #define LPPDMA_INT_TEMPTY     0x00000001UL            /*!<Table Empty Interrupt  \hideinitializer */
98 
99 
100 /*@}*/ /* end of group LPPDMA_EXPORTED_CONSTANTS */
101 
102 /** @addtogroup LPPDMA_EXPORTED_FUNCTIONS LPPDMA Exported Functions
103   @{
104 */
105 
106 /**
107  * @brief       Get LPPDMA Interrupt Status
108  *
109  * @param[in]   lppdma      The pointer of the specified LPPDMA module
110  *
111  * @return      None
112  *
113  * @details     This macro gets the interrupt status.
114  * \hideinitializer
115  */
116 #define LPPDMA_GET_INT_STATUS(lppdma) ((uint32_t)(lppdma->INTSTS))
117 
118 /**
119  * @brief       Get Transfer Done Interrupt Status
120  *
121  * @param[in]   lppdma      The pointer of the specified LPPDMA module
122  *
123  * @return      None
124  *
125  * @details     Get the transfer done Interrupt status.
126  * \hideinitializer
127  */
128 #define LPPDMA_GET_TD_STS(lppdma) ((uint32_t)(lppdma->TDSTS))
129 
130 /**
131  * @brief       Clear Transfer Done Interrupt Status
132  *
133  * @param[in]   lppdma      The pointer of the specified LPPDMA module
134  *
135  * @param[in]   u32Mask     The channel mask
136  *
137  * @return      None
138  *
139  * @details     Clear the transfer done Interrupt status.
140  * \hideinitializer
141  */
142 #define LPPDMA_CLR_TD_FLAG(lppdma,u32Mask) ((uint32_t)(lppdma->TDSTS = (u32Mask)))
143 
144 /**
145  * @brief       Get Target Abort Interrupt Status
146  *
147  * @param[in]   lppdma      The pointer of the specified LPPDMA module
148  *
149  * @return      None
150  *
151  * @details     Get the target abort Interrupt status.
152  * \hideinitializer
153  */
154 #define LPPDMA_GET_ABORT_STS(lppdma) ((uint32_t)(lppdma->ABTSTS))
155 
156 /**
157  * @brief       Clear Target Abort Interrupt Status
158  *
159  * @param[in]   lppdma      The pointer of the specified LPPDMA module
160  *
161  * @param[in]   u32Mask     The channel mask
162  *
163  * @return      None
164  *
165  * @details     Clear the target abort Interrupt status.
166  * \hideinitializer
167  */
168 #define LPPDMA_CLR_ABORT_FLAG(lppdma,u32Mask) ((uint32_t)(lppdma->ABTSTS = (u32Mask)))
169 
170 /**
171  * @brief       Get Alignment Interrupt Status
172  *
173  * @param[in]   lppdma      The pointer of the specified LPPDMA module
174  *
175  * @return      None
176  *
177  * @details     Get Alignment Interrupt status.
178  * \hideinitializer
179  */
180 #define LPPDMA_GET_ALIGN_STS(lppdma) ((uint32_t)(lppdma->ALIGN))
181 
182 /**
183  * @brief       Clear Alignment Interrupt Status
184   *
185  * @param[in]   lppdma        The pointer of the specified LPPDMA module
186  * @param[in]   u32Mask     The channel mask
187  *
188  * @return      None
189  *
190  * @details     Clear the Alignment Interrupt status.
191  * \hideinitializer
192  */
193 #define LPPDMA_CLR_ALIGN_FLAG(lppdma,u32Mask) ((uint32_t)(lppdma->ALIGN = (u32Mask)))
194 
195 /**
196  * @brief       Check Channel Status
197   *
198  * @param[in]   lppdma      The pointer of the specified LPPDMA module
199  * @param[in]   u32Ch     The selected channel
200  *
201  * @retval      0 Idle state
202  * @retval      1 Busy state
203  *
204  * @details     Check the selected channel is busy or not.
205  * \hideinitializer
206  */
207 #define LPPDMA_IS_CH_BUSY(lppdma,u32Ch) ((uint32_t)(lppdma->TRGSTS & (1UL << (u32Ch)))? 1 : 0)
208 
209 /**
210  * @brief       Set Source Address
211   *
212  * @param[in]   lppdma      The pointer of the specified LPPDMA module
213  * @param[in]   u32Ch     The selected channel
214  * @param[in]   u32Addr   The selected address
215  *
216  * @return      None
217  *
218  * @details     This macro set the selected channel source address.
219  * \hideinitializer
220  */
221 #define LPPDMA_SET_SRC_ADDR(lppdma,u32Ch, u32Addr) ((uint32_t)(lppdma->LPDSCT[(u32Ch)].SA = (u32Addr)))
222 
223 /**
224  * @brief       Set Destination Address
225  *
226  * @param[in]   lppdma      The pointer of the specified LPPDMA module
227  * @param[in]   u32Ch     The selected channel
228  * @param[in]   u32Addr   The selected address
229  *
230  * @return      None
231  *
232  * @details     This macro set the selected channel destination address.
233  * \hideinitializer
234  */
235 #define LPPDMA_SET_DST_ADDR(lppdma,u32Ch, u32Addr) ((uint32_t)(lppdma->LPDSCT[(u32Ch)].DA = (u32Addr)))
236 
237 /**
238  * @brief       Set Transfer Count
239   *
240  * @param[in]   lppdma           The pointer of the specified LPPDMA module
241  * @param[in]   u32Ch          The selected channel
242  * @param[in]   u32TransCount  Transfer Count
243  *
244  * @return      None
245  *
246  * @details     This macro set the selected channel transfer count.
247  * \hideinitializer
248  */
249 #define LPPDMA_SET_TRANS_CNT(lppdma,u32Ch, u32TransCount) ((uint32_t)(lppdma->LPDSCT[(u32Ch)].CTL=(lppdma->LPDSCT[(u32Ch)].CTL&~LPPDMA_DSCT_CTL_TXCNT_Msk)|(((u32TransCount)-1UL) << LPPDMA_DSCT_CTL_TXCNT_Pos)))
250 
251 /**
252  * @brief       Set Scatter-gather descriptor Address
253  *
254  * @param[in]   lppdma      The pointer of the specified LPPDMA module
255  * @param[in]   u32Ch     The selected channel
256  * @param[in]   u32Addr   The descriptor address
257  *
258  * @return      None
259  *
260  * @details     This macro set the selected channel scatter-gather descriptor address.
261  * \hideinitializer
262  */
263 #define LPPDMA_SET_SCATTER_DESC(lppdma,u32Ch, u32Addr) ((uint32_t)(lppdma->LPDSCT[(u32Ch)].NEXT = (u32Addr) - (lppdma->SCATBA)))
264 
265 /**
266  * @brief       Stop the channel
267  *
268  * @param[in]   lppdma      The pointer of the specified LPPDMA module
269  *
270  * @param[in]   u32Ch     The selected channel
271  *
272  * @return      None
273  *
274  * @details     This macro stop the selected channel.
275  * \hideinitializer
276  */
277 #define LPPDMA_STOP(lppdma,u32Ch) ((uint32_t)(lppdma->PAUSE = (1UL << (u32Ch))))
278 
279 /**
280  * @brief       Pause the channel
281  *
282  * @param[in]   lppdma      The pointer of the specified LPPDMA module
283  *
284  * @param[in]   u32Ch     The selected channel
285  *
286  * @return      None
287  *
288  * @details     This macro pause the selected channel.
289  * \hideinitializer
290  */
291 #define LPPDMA_PAUSE(lppdma,u32Ch) ((uint32_t)(lppdma->PAUSE = (1UL << (u32Ch))))
292 
293 /*---------------------------------------------------------------------------------------------------------*/
294 /* Define PDMA functions prototype                                                                          */
295 /*---------------------------------------------------------------------------------------------------------*/
296 void LPPDMA_Open(LPPDMA_T * lppdma,uint32_t u32Mask);
297 void LPPDMA_Close(LPPDMA_T * lppdma);
298 void LPPDMA_SetTransferCnt(LPPDMA_T * lppdma,uint32_t u32Ch, uint32_t u32Width, uint32_t u32TransCount);
299 void LPPDMA_SetTransferAddr(LPPDMA_T * lppdma,uint32_t u32Ch, uint32_t u32SrcAddr, uint32_t u32SrcCtrl, uint32_t u32DstAddr, uint32_t u32DstCtrl);
300 void LPPDMA_SetTransferMode(LPPDMA_T * lppdma,uint32_t u32Ch, uint32_t u32Peripheral, uint32_t u32ScatterEn, uint32_t u32DescAddr);
301 void LPPDMA_SetBurstType(LPPDMA_T * lppdma,uint32_t u32Ch, uint32_t u32BurstType, uint32_t u32BurstSize);
302 void LPPDMA_Trigger(LPPDMA_T * lppdma,uint32_t u32Ch);
303 void LPPDMA_EnableInt(LPPDMA_T * lppdma,uint32_t u32Ch, uint32_t u32Mask);
304 void LPPDMA_DisableInt(LPPDMA_T * lppdma,uint32_t u32Ch, uint32_t u32Mask);
305 
306 
307 /*@}*/ /* end of group LPPDMA_EXPORTED_FUNCTIONS */
308 
309 /*@}*/ /* end of group LPPDMA_Driver */
310 
311 /*@}*/ /* end of group Standard_Driver */
312 
313 #ifdef __cplusplus
314 }
315 #endif
316 
317 #endif /* __LPPDMA_H__ */
318 
319 /*** (C) COPYRIGHT 2023 Nuvoton Technology Corp. ***/
320