• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @file    wm_dma.h
18  *
19  * @brief   DMA Driver Module
20  *
21  * @author  dave
22  *
23  * Copyright (c) 2014 Winner Microelectronics Co., Ltd.
24  */
25 #ifndef __WM_DMA_H_
26 #define __WM_DMA_H_
27 
28 #define TLS_DMA_SEL_UART_RX       0
29 #define TLS_DMA_SEL_UART_TX       1
30 #define TLS_DMA_SEL_PWM_CAP0       2
31 #define TLS_DMA_SEL_PWM_CAP1       3
32 #define TLS_DMA_SEL_LSSPI_RX       4
33 #define TLS_DMA_SEL_LSSPI_TX       5
34 #define TLS_DMA_SEL_SDADC_CH0      6
35 #define TLS_DMA_SEL_SDADC_CH1      7
36 #define TLS_DMA_SEL_SDADC_CH2      8
37 #define TLS_DMA_SEL_SDADC_CH3      9
38 #define TLS_DMA_SEL_I2S_RX         10
39 #define TLS_DMA_SEL_I2S_TX         11
40 #define TLS_DMA_SEL_SDIO_HOST      12
41 
42 #define TLS_DMA_FLAGS_HARD_MODE                 (1   << 0)
43 #define TLS_DMA_FLAGS_CHAIN_MODE                (1   << 1)
44 #define TLS_DMA_FLAGS_CHANNEL_SEL(n)            ((n) << 2)
45 #define TLS_DMA_FLAGS_CHAIN_LINK_EN             (1   << 6)
46 #define TLS_DMA_FLAGS_CHANNEL_VALID             (1   << 7)
47 
48 #define TLS_DMA_DESC_VALID                      (1U  << 31)
49 #define TLS_DMA_DESC_CTRL_SRC_ADD_INC           (1   << 0)
50 #define TLS_DMA_DESC_CTRL_DEST_ADD_INC          (1   << 2)
51 #define TLS_DMA_DESC_CTRL_DATA_SIZE_BYTE        (0   << 4)
52 #define TLS_DMA_DESC_CTRL_DATA_SIZE_SHORT       (1   << 4)
53 #define TLS_DMA_DESC_CTRL_DATA_SIZE_WORD        (2   << 4)
54 #define TLS_DMA_DESC_CTRL_BURST_SIZE1           (0   << 6)
55 #define TLS_DMA_DESC_CTRL_BURST_SIZE4           (1   << 6)
56 #define TLS_DMA_DESC_CTRL_TOTAL_BYTES(n)        ((n) << 7)
57 
58 /* dma interrupt flags */
59 #define TLS_DMA_IRQ_BURST_DONE                  (1 << 0)
60 #define TLS_DMA_IRQ_TRANSFER_DONE               (1 << 1)
61 #define TLS_DMA_IRQ_BOTH_DONE                   (TLS_DMA_IRQ_BURST_DONE | TLS_DMA_IRQ_TRANSFER_DONE)
62 
63 struct tls_dma_descriptor {
64     unsigned int valid;
65     unsigned int dma_ctrl;
66     unsigned int src_addr;
67     unsigned int dest_addr;
68     struct tls_dma_descriptor *next;    /**< next dms descriptor */
69 };
70 
71 /**
72  * @defgroup Driver_APIs Driver APIs
73  * @brief Driver APIs
74  */
75 
76 /**
77  * @addtogroup Driver_APIs
78  * @{
79  */
80 
81 /**
82  * @defgroup DMA_Driver_APIs DMA Driver APIs
83  * @brief DMA driver APIs
84  */
85 
86 /**
87  * @addtogroup DMA_Driver_APIs
88  * @{
89  */
90 
91 /**
92  * @brief          	This function is used to clear dma interrupt flag.
93  *
94  * @param[in]     	ch		Channel no.[0~7]
95  * @param[in]     	flags		Flags setted to TLS_DMA_IRQ_BURST_DONE, TLS_DMA_IRQ_TRANSFER_DONE, TLS_DMA_IRQ_BOTH_DONE.
96  *
97  * @return         	None
98  *
99  * @note           	None
100  */
101 void tls_dma_irq_clr(unsigned char ch, unsigned char flags);
102 
103 /**
104  * @brief          	This function is used to register dma interrupt callback function.
105  *
106  * @param[in]     	ch		Channel no.[0~7]
107  * @param[in]     	callback	is the dma interrupt call back function.
108  * @param[in]     	arg	the param of the callback function.
109  * @param[in]     	flags		Flags setted to TLS_DMA_IRQ_BURST_DONE, TLS_DMA_IRQ_TRANSFER_DONE, TLS_DMA_IRQ_BOTH_DONE.
110  *
111  * @return         	None
112  *
113  * @note           	None
114  */
115 void tls_dma_irq_register(unsigned char ch, void (*callback)(void *p), void *arg, unsigned char flags);
116 
117 /**
118  * @brief          This function is used to register dma interrupt
119  *
120  * @param[in]     	ch		DMA channel no.[0~7]
121  *
122  * @return         None
123  *
124  * @note           	None
125  */
126 int tls_dma_wait_complt(unsigned char ch);
127 
128 /**
129  * @brief          This function is used to Start the DMA controller by Wrap
130  *
131  * @param[in]     	 autoReload 	Does restart when current transfer complete?
132  * @param[in]     	 ch            	Channel no.[0~7]
133  * @param[in]     	 pDmaDesc    	Pointer to DMA channel descriptor structure.
134  *
135  * @retval         	Always STATUS_SUCCESS.
136  *
137  * @note
138  * DMA Descriptor:  +--------------------------------------------------------------+
139  *            		|Vld[31] |                    RSV                              |
140  *            	 	+--------------------------------------------------------------+
141  *            	 	|                  RSV           |         Dma_Ctrl[16:0]      |
142  *            	 	+--------------------------------------------------------------+
143  *            	 	|                         Src_Addr[31:0]                       |
144  *            	 	+--------------------------------------------------------------+
145  *            	 	|                         Dest_Addr[31:0]                      |
146  *            	 	+--------------------------------------------------------------+
147  *            	 	|                       Next_Desc_Add[31:0]                    |
148  *            	 	+--------------------------------------------------------------+
149  */
150 unsigned char tls_dma_start_by_wrap(unsigned char ch, struct tls_dma_descriptor *dma_desc,
151                                     unsigned char auto_reload, unsigned short src_zize,
152                                     unsigned short dest_zize);
153 
154 /**
155  * @brief          This function is used to Wait until DMA operation completes
156  *
157  * @param[in]     	 autoReload 	Does restart when current transfer complete?
158  * @param[in]     	 ch            	Channel no.[0~7]
159  * @param[in]     	 pDmaDesc    	Pointer to DMA channel descriptor structure.
160  *
161  * @retval         	 Always STATUS_SUCCESS.
162  *
163  * @note
164  * DMA Descriptor:  +--------------------------------------------------------------+
165  *            		|Vld[31] |                    RSV                              |
166  *            	 	+--------------------------------------------------------------+
167  *            	 	|                  RSV           |         Dma_Ctrl[16:0]      |
168  *            	 	+--------------------------------------------------------------+
169  *            	 	|                         Src_Addr[31:0]                       |
170  *            	 	+--------------------------------------------------------------+
171  *            	 	|                         Dest_Addr[31:0]                      |
172  *            	 	+--------------------------------------------------------------+
173  *            	 	|                       Next_Desc_Add[31:0]                    |
174  *            	 	+--------------------------------------------------------------+
175  */
176 unsigned char tls_dma_start(unsigned char ch, struct tls_dma_descriptor *dma_desc,
177                             unsigned char auto_reload);
178 
179 /**
180  * @brief          This function is used to To stop current DMA channel transfer
181  *
182  * @param[in]      ch    channel no. to be stopped
183  *
184  * @retval         	Always STATUS_SUCCESS
185  *
186  * @note           	If channel stop, DMA_CHNL_CTRL_CHNL_ON bit in DMA_CHNLCTRL_REG is cleared.
187  */
188 unsigned char tls_dma_stop(unsigned char ch);
189 
190  /**
191  * @brief        This function is used to Request a free dma channel
192  *				If ch is out of range [0,7] or valid but used, the function will select another free channel.
193  *		         else return the selected channel no.
194  * @param[in]    ch       specified channel when ch is valid and not used.
195  * @param[in]    flags    flags setted to selected channel
196  *
197  * @return       Real DMA Channel No: if there is free dma channel.
198  *               0xFF: when DMA channels are all used.
199  *
200  * @note         If ch is invalid or valid but used, the function will select another free channel.
201  *               else return the selected channel no.
202  */
203 unsigned char tls_dma_request(unsigned char ch, unsigned char flags);
204 
205 /**
206  * @brief          This function is used to Free the DMA channel when not use
207  *
208  * @param[in]      ch    channel no. that is ready to free
209  *
210  * @return         None
211  *
212  * @note           None
213  */
214 void tls_dma_free(unsigned char ch);
215 
216 /**
217  * @brief          This function is used to Initialize DMA Control
218  *
219  * @param[in]      None
220  *
221  * @return         None
222  *
223  * @note           None
224  */
225 void tls_dma_init(void);
226 
227 /**
228  * @}
229  */
230 
231 /**
232  * @}
233  */
234 
235 #endif /* __TLS_DMA_H_151606__ */
236 
237