]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/USBHost/USBHost/TARGET_RENESAS/TARGET_RZ_A1H/usb1/src/common/usb1_host_dma.c
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / USBHost / USBHost / TARGET_RENESAS / TARGET_RZ_A1H / usb1 / src / common / usb1_host_dma.c
1 /*******************************************************************************
2 * DISCLAIMER
3 * This software is supplied by Renesas Electronics Corporation and is only
4 * intended for use with Renesas products. No other uses are authorized. This
5 * software is owned by Renesas Electronics Corporation and is protected under
6 * all applicable laws, including copyright laws.
7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
16 * Renesas reserves the right, without notice, to make changes to this software
17 * and to discontinue the availability of this software. By using this software,
18 * you agree to the additional terms and conditions found by accessing the
19 * following link:
20 * http://www.renesas.com/disclaimer
21 * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
22 *******************************************************************************/
23 /*******************************************************************************
24 * File Name : usb1_host_dma.c
25 * $Rev: 1116 $
26 * $Date:: 2014-07-09 16:29:19 +0900#$
27 * Device(s) : RZ/A1H
28 * Tool-Chain :
29 * OS : None
30 * H/W Platform :
31 * Description : RZ/A1H R7S72100 USB Sample Program
32 * Operation :
33 * Limitations :
34 *******************************************************************************/
35
36
37 /*******************************************************************************
38 Includes <System Includes> , "Project Includes"
39 *******************************************************************************/
40 #include "usb1_host.h"
41 /* #include "usb1_host_dmacdrv.h" */
42
43
44 /*******************************************************************************
45 Typedef definitions
46 *******************************************************************************/
47
48
49 /*******************************************************************************
50 Macro definitions
51 *******************************************************************************/
52
53
54 /*******************************************************************************
55 Imported global variables and functions (from other files)
56 *******************************************************************************/
57
58
59 /*******************************************************************************
60 Exported global variables and functions (to be accessed by other files)
61 *******************************************************************************/
62
63
64 /*******************************************************************************
65 Private global variables and functions
66 *******************************************************************************/
67 static void usb1_host_dmaint(uint16_t fifo);
68 static void usb1_host_dmaint_buf2fifo(uint16_t pipe);
69 static void usb1_host_dmaint_fifo2buf(uint16_t pipe);
70
71
72 /*******************************************************************************
73 * Function Name: usb1_host_dma_stop_d0
74 * Description : D0FIFO DMA stop
75 * Arguments : uint16_t pipe : pipe number
76 * : uint32_t remain : transfer byte
77 * Return Value : none
78 *******************************************************************************/
79 void usb1_host_dma_stop_d0 (uint16_t pipe, uint32_t remain)
80 {
81 uint16_t dtln;
82 uint16_t dfacc;
83 uint16_t buffer;
84 uint16_t sds_b = 1;
85
86 dfacc = RZA_IO_RegRead_16(&USB201.D0FBCFG,
87 USB_DnFBCFG_DFACC_SHIFT,
88 USB_DnFBCFG_DFACC);
89 if (dfacc == 2)
90 {
91 sds_b = 32;
92 }
93 else if (dfacc == 1)
94 {
95 sds_b = 16;
96 }
97 else
98 {
99 if (g_usb1_host_DmaInfo[USB_HOST_D0FIFO].size == 2)
100 {
101 sds_b = 4;
102 }
103 else if (g_usb1_host_DmaInfo[USB_HOST_D0FIFO].size == 1)
104 {
105 sds_b = 2;
106 }
107 else
108 {
109 sds_b = 1;
110 }
111 }
112
113 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
114 {
115 if (g_usb1_host_pipe_status[pipe] != USB_HOST_PIPE_DONE)
116 {
117 buffer = USB201.D0FIFOCTR;
118 dtln = (buffer & USB_HOST_BITDTLN);
119
120 if ((dtln % sds_b) != 0)
121 {
122 remain += (sds_b - (dtln % sds_b));
123 }
124 g_usb1_host_PipeDataSize[pipe] = (g_usb1_host_data_count[pipe] - remain);
125 g_usb1_host_data_count[pipe] = remain;
126 }
127 }
128
129 RZA_IO_RegWrite_16(&USB201.D0FIFOSEL,
130 0,
131 USB_DnFIFOSEL_DREQE_SHIFT,
132 USB_DnFIFOSEL_DREQE);
133 }
134
135 /*******************************************************************************
136 * Function Name: usb1_host_dma_stop_d1
137 * Description : D1FIFO DMA stop
138 * Arguments : uint16_t pipe : pipe number
139 * : uint32_t remain : transfer byte
140 * Return Value : none
141 *******************************************************************************/
142 void usb1_host_dma_stop_d1 (uint16_t pipe, uint32_t remain)
143 {
144 uint16_t dtln;
145 uint16_t dfacc;
146 uint16_t buffer;
147 uint16_t sds_b = 1;
148
149 dfacc = RZA_IO_RegRead_16(&USB201.D1FBCFG,
150 USB_DnFBCFG_DFACC_SHIFT,
151 USB_DnFBCFG_DFACC);
152 if (dfacc == 2)
153 {
154 sds_b = 32;
155 }
156 else if (dfacc == 1)
157 {
158 sds_b = 16;
159 }
160 else
161 {
162 if (g_usb1_host_DmaInfo[USB_HOST_D1FIFO].size == 2)
163 {
164 sds_b = 4;
165 }
166 else if (g_usb1_host_DmaInfo[USB_HOST_D1FIFO].size == 1)
167 {
168 sds_b = 2;
169 }
170 else
171 {
172 sds_b = 1;
173 }
174 }
175
176 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
177 {
178 if (g_usb1_host_pipe_status[pipe] != USB_HOST_PIPE_DONE)
179 {
180 buffer = USB201.D1FIFOCTR;
181 dtln = (buffer & USB_HOST_BITDTLN);
182
183 if ((dtln % sds_b) != 0)
184 {
185 remain += (sds_b - (dtln % sds_b));
186 }
187 g_usb1_host_PipeDataSize[pipe] = (g_usb1_host_data_count[pipe] - remain);
188 g_usb1_host_data_count[pipe] = remain;
189 }
190 }
191
192 RZA_IO_RegWrite_16(&USB201.D1FIFOSEL,
193 0,
194 USB_DnFIFOSEL_DREQE_SHIFT,
195 USB_DnFIFOSEL_DREQE);
196 }
197
198 /*******************************************************************************
199 * Function Name: usb1_host_dma_interrupt_d0fifo
200 * Description : This function is DMA interrupt handler entry.
201 * : Execute usb1_host_dmaint() after disabling DMA interrupt in this function.
202 * : Disable DMA interrupt to DMAC executed when USB_HOST_D0FIFO_DMA is
203 * : specified by dma->fifo.
204 * : Register this function as DMA complete interrupt.
205 * Arguments : uint32_t int_sense ; Interrupts detection mode
206 * : ; INTC_LEVEL_SENSITIVE : Level sense
207 * : ; INTC_EDGE_TRIGGER : Edge trigger
208 * Return Value : none
209 *******************************************************************************/
210 void usb1_host_dma_interrupt_d0fifo (uint32_t int_sense)
211 {
212 usb1_host_dmaint(USB_HOST_D0FIFO);
213 g_usb1_host_DmaStatus[USB_HOST_D0FIFO] = USB_HOST_DMA_READY;
214 }
215
216 /*******************************************************************************
217 * Function Name: usb1_host_dma_interrupt_d1fifo
218 * Description : This function is DMA interrupt handler entry.
219 * : Execute usb0_host_dmaint() after disabling DMA interrupt in this function.
220 * : Disable DMA interrupt to DMAC executed when USB_HOST_D1FIFO_DMA is
221 * : specified by dma->fifo.
222 * : Register this function as DMA complete interrupt.
223 * Arguments : uint32_t int_sense ; Interrupts detection mode
224 * : ; INTC_LEVEL_SENSITIVE : Level sense
225 * : ; INTC_EDGE_TRIGGER : Edge trigger
226 * Return Value : none
227 *******************************************************************************/
228 void usb1_host_dma_interrupt_d1fifo (uint32_t int_sense)
229 {
230 usb1_host_dmaint(USB_HOST_D1FIFO);
231 g_usb1_host_DmaStatus[USB_HOST_D1FIFO] = USB_HOST_DMA_READY;
232 }
233
234 /*******************************************************************************
235 * Function Name: usb1_host_dmaint
236 * Description : This function is DMA transfer end interrupt
237 * Arguments : uint16_t fifo ; fifo number
238 * : ; USB_HOST_D0FIFO
239 * : ; USB_HOST_D1FIFO
240 * Return Value : none
241 *******************************************************************************/
242 static void usb1_host_dmaint (uint16_t fifo)
243 {
244 uint16_t pipe;
245
246 pipe = g_usb1_host_DmaPipe[fifo];
247
248 if (g_usb1_host_DmaInfo[fifo].dir == USB_HOST_BUF2FIFO)
249 {
250 usb1_host_dmaint_buf2fifo(pipe);
251 }
252 else
253 {
254 usb1_host_dmaint_fifo2buf(pipe);
255 }
256 }
257
258 /*******************************************************************************
259 * Function Name: usb1_host_dmaint_fifo2buf
260 * Description : Executes read completion from FIFO by DMAC.
261 * Arguments : uint16_t pipe : pipe number
262 * Return Value : none
263 *******************************************************************************/
264 static void usb1_host_dmaint_fifo2buf (uint16_t pipe)
265 {
266 uint32_t remain;
267 uint16_t useport;
268
269 if (g_usb1_host_pipe_status[pipe] != USB_HOST_PIPE_DONE)
270 {
271 useport = (uint16_t)(g_usb1_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
272
273 if (useport == USB_HOST_D0FIFO_DMA)
274 {
275 remain = Userdef_USB_usb1_host_stop_dma0();
276 usb1_host_dma_stop_d0(pipe, remain);
277
278 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
279 {
280 if (g_usb1_host_DmaStatus[USB_HOST_D0FIFO] == USB_HOST_DMA_BUSYEND)
281 {
282 USB201.D0FIFOCTR = USB_HOST_BITBCLR;
283 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
284 }
285 else
286 {
287 usb1_host_enable_brdy_int(pipe);
288 }
289 }
290 }
291 else
292 {
293 remain = Userdef_USB_usb1_host_stop_dma1();
294 usb1_host_dma_stop_d1(pipe, remain);
295
296 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
297 {
298 if (g_usb1_host_DmaStatus[USB_HOST_D1FIFO] == USB_HOST_DMA_BUSYEND)
299 {
300 USB201.D1FIFOCTR = USB_HOST_BITBCLR;
301 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
302 }
303 else
304 {
305 usb1_host_enable_brdy_int(pipe);
306 }
307 }
308 }
309 }
310 }
311
312 /*******************************************************************************
313 * Function Name: usb1_host_dmaint_buf2fifo
314 * Description : Executes write completion in FIFO by DMAC.
315 * Arguments : uint16_t pipe : pipe number
316 * Return Value : none
317 *******************************************************************************/
318 static void usb1_host_dmaint_buf2fifo (uint16_t pipe)
319 {
320 uint16_t useport;
321 uint32_t remain;
322
323 useport = (uint16_t)(g_usb1_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
324
325 if (useport == USB_HOST_D0FIFO_DMA)
326 {
327 remain = Userdef_USB_usb1_host_stop_dma0();
328 usb1_host_dma_stop_d0(pipe, remain);
329
330 if (g_usb1_host_DmaBval[USB_HOST_D0FIFO] != 0)
331 {
332 RZA_IO_RegWrite_16(&USB201.D0FIFOCTR,
333 1,
334 USB_DnFIFOCTR_BVAL_SHIFT,
335 USB_DnFIFOCTR_BVAL);
336 }
337 }
338 else
339 {
340 remain = Userdef_USB_usb1_host_stop_dma1();
341 usb1_host_dma_stop_d1(pipe, remain);
342
343 if (g_usb1_host_DmaBval[USB_HOST_D1FIFO] != 0)
344 {
345 RZA_IO_RegWrite_16(&USB201.D1FIFOCTR,
346 1,
347 USB_DnFIFOCTR_BVAL_SHIFT,
348 USB_DnFIFOCTR_BVAL);
349 }
350 }
351
352 usb1_host_enable_bemp_int(pipe);
353 }
354
355 /* End of File */
Imprint / Impressum