]> 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_intrn.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_intrn.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_intrn.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 #if(1) /* ohci_wrapp */
42 #include "ohci_wrapp_RZ_A1_local.h"
43 #endif
44
45
46 /*******************************************************************************
47 Typedef definitions
48 *******************************************************************************/
49
50
51 /*******************************************************************************
52 Macro definitions
53 *******************************************************************************/
54
55
56 /*******************************************************************************
57 Imported global variables and functions (from other files)
58 *******************************************************************************/
59
60
61 /*******************************************************************************
62 Exported global variables and functions (to be accessed by other files)
63 *******************************************************************************/
64
65
66 /*******************************************************************************
67 Private global variables and functions
68 *******************************************************************************/
69
70
71 /*******************************************************************************
72 * Function Name: usb1_host_brdy_int
73 * Description : Executes BRDY interrupt(USB_HOST_PIPE1-9).
74 * : According to the pipe that interrupt is generated in,
75 * : reads/writes buffer allocated in the pipe.
76 * : This function is executed in the BRDY interrupt handler.
77 * : This function clears BRDY interrupt status and BEMP interrupt
78 * : status.
79 * Arguments : uint16_t status ; BRDYSTS Register Value
80 * : uint16_t int_enb ; BRDYENB Register Value
81 * Return Value : none
82 *******************************************************************************/
83 void usb1_host_brdy_int (uint16_t status, uint16_t int_enb)
84 {
85 uint32_t int_sense = 0;
86 uint16_t pipe;
87 uint16_t pipebit;
88
89 for (pipe = USB_HOST_PIPE1; pipe <= USB_HOST_MAX_PIPE_NO; pipe++)
90 {
91 pipebit = g_usb1_host_bit_set[pipe];
92
93 if ((status & pipebit) && (int_enb & pipebit))
94 {
95 USB201.BRDYSTS = (uint16_t)~pipebit;
96 USB201.BEMPSTS = (uint16_t)~pipebit;
97
98 if ((g_usb1_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D0FIFO_DMA)
99 {
100 if (g_usb1_host_DmaStatus[USB_HOST_D0FIFO] != USB_HOST_DMA_READY)
101 {
102 usb1_host_dma_interrupt_d0fifo(int_sense);
103 }
104
105 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
106 {
107 usb1_host_read_dma(pipe);
108 usb1_host_disable_brdy_int(pipe);
109 }
110 else
111 {
112 USB201.D0FIFOCTR = USB_HOST_BITBCLR;
113 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
114 }
115 }
116 else if ((g_usb1_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D1FIFO_DMA)
117 {
118 if (g_usb1_host_DmaStatus[USB_HOST_D1FIFO] != USB_HOST_DMA_READY)
119 {
120 usb1_host_dma_interrupt_d1fifo(int_sense);
121 }
122
123 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
124 {
125 usb1_host_read_dma(pipe);
126 usb1_host_disable_brdy_int(pipe);
127 }
128 else
129 {
130 USB201.D1FIFOCTR = USB_HOST_BITBCLR;
131 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
132 }
133 }
134 else
135 {
136 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_DIR_SHIFT, USB_PIPECFG_DIR) == 0)
137 {
138 usb1_host_read_buffer(pipe);
139 }
140 else
141 {
142 usb1_host_write_buffer(pipe);
143 }
144 }
145 #if(1) /* ohci_wrapp */
146 switch (g_usb1_host_pipe_status[pipe])
147 {
148 case USB_HOST_PIPE_DONE:
149 ohciwrapp_loc_TransEnd(pipe, TD_CC_NOERROR);
150 break;
151 case USB_HOST_PIPE_NORES:
152 case USB_HOST_PIPE_STALL:
153 case USB_HOST_PIPE_ERROR:
154 ohciwrapp_loc_TransEnd(pipe, TD_CC_STALL);
155 break;
156 default:
157 /* Do Nothing */
158 break;
159 }
160 #endif
161 }
162 }
163 }
164
165 /*******************************************************************************
166 * Function Name: usb1_host_nrdy_int
167 * Description : Executes NRDY interrupt(USB_HOST_PIPE1-9).
168 * : Checks NRDY interrupt cause by PID. When the cause if STALL,
169 * : regards the pipe state as STALL and ends the processing.
170 * : Then the cause is not STALL, increments the error count to
171 * : communicate again. When the error count is 3, determines
172 * : the pipe state as USB_HOST_PIPE_NORES and ends the processing.
173 * : This function is executed in the NRDY interrupt handler.
174 * : This function clears NRDY interrupt status.
175 * Arguments : uint16_t status ; NRDYSTS Register Value
176 * : uint16_t int_enb ; NRDYENB Register Value
177 * Return Value : none
178 *******************************************************************************/
179 void usb1_host_nrdy_int (uint16_t status, uint16_t int_enb)
180 {
181 uint16_t pid;
182 uint16_t pipe;
183 uint16_t bitcheck;
184
185 bitcheck = (uint16_t)(status & int_enb);
186
187 USB201.NRDYSTS = (uint16_t)~status;
188
189 for (pipe = USB_HOST_PIPE1; pipe <= USB_HOST_MAX_PIPE_NO; pipe++)
190 {
191 if ((bitcheck&g_usb1_host_bit_set[pipe]) == g_usb1_host_bit_set[pipe])
192 {
193 if (RZA_IO_RegRead_16(&USB201.SYSCFG0,
194 USB_SYSCFG_DCFM_SHIFT,
195 USB_SYSCFG_DCFM) == 1)
196 {
197 if (g_usb1_host_pipe_status[pipe] == USB_HOST_PIPE_WAIT)
198 {
199 pid = usb1_host_get_pid(pipe);
200
201 if ((pid == USB_HOST_PID_STALL) || (pid == USB_HOST_PID_STALL2))
202 {
203 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_STALL;
204 #if(1) /* ohci_wrapp */
205 ohciwrapp_loc_TransEnd(pipe, TD_CC_STALL);
206 #endif
207 }
208 else
209 {
210 #if(1) /* ohci_wrapp */
211 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_NORES;
212 ohciwrapp_loc_TransEnd(pipe, TD_CC_DEVICENOTRESPONDING);
213 #else
214 g_usb1_host_PipeIgnore[pipe]++;
215
216 if (g_usb1_host_PipeIgnore[pipe] == 3)
217 {
218 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_NORES;
219 }
220 else
221 {
222 usb1_host_set_pid_buf(pipe);
223 }
224 #endif
225 }
226 }
227 }
228 else
229 {
230 /* USB Function */
231 }
232 }
233 }
234 }
235
236 /*******************************************************************************
237 * Function Name: usb1_host_bemp_int
238 * Description : Executes BEMP interrupt(USB_HOST_PIPE1-9).
239 * Arguments : uint16_t status ; BEMPSTS Register Value
240 * : uint16_t int_enb ; BEMPENB Register Value
241 * Return Value : none
242 *******************************************************************************/
243 void usb1_host_bemp_int (uint16_t status, uint16_t int_enb)
244 {
245 uint16_t pid;
246 uint16_t pipe;
247 uint16_t bitcheck;
248 uint16_t inbuf;
249
250 bitcheck = (uint16_t)(status & int_enb);
251
252 USB201.BEMPSTS = (uint16_t)~status;
253
254 for (pipe = USB_HOST_PIPE1; pipe <= USB_HOST_MAX_PIPE_NO; pipe++)
255 {
256 if ((bitcheck&g_usb1_host_bit_set[pipe]) == g_usb1_host_bit_set[pipe])
257 {
258 pid = usb1_host_get_pid(pipe);
259
260 if ((pid == USB_HOST_PID_STALL) || (pid == USB_HOST_PID_STALL2))
261 {
262 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_STALL;
263 #if(1) /* ohci_wrapp */
264 ohciwrapp_loc_TransEnd(pipe, TD_CC_STALL);
265 #endif
266 }
267 else
268 {
269 inbuf = usb1_host_get_inbuf(pipe);
270
271 if (inbuf == 0)
272 {
273 usb1_host_disable_bemp_int(pipe);
274 usb1_host_set_pid_nak(pipe);
275 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
276 #if(1) /* ohci_wrapp */
277 ohciwrapp_loc_TransEnd(pipe, TD_CC_NOERROR);
278 #endif
279 }
280 }
281 }
282 }
283 }
284
285 /* End of File */
Imprint / Impressum