]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/USBDevice/USBDevice/TARGET_RENESAS/TARGET_RZ_A1H/usb0/src/common/usb0_function_intrn.c
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / USBDevice / USBDevice / TARGET_RENESAS / TARGET_RZ_A1H / usb0 / src / common / usb0_function_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 : usb0_function_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 "usb0_function.h"
41
42
43 /*******************************************************************************
44 Typedef definitions
45 *******************************************************************************/
46
47
48 /*******************************************************************************
49 Macro definitions
50 *******************************************************************************/
51
52
53 /*******************************************************************************
54 Imported global variables and functions (from other files)
55 *******************************************************************************/
56
57
58 /*******************************************************************************
59 Exported global variables and functions (to be accessed by other files)
60 *******************************************************************************/
61
62
63 /*******************************************************************************
64 Private global variables and functions
65 *******************************************************************************/
66
67
68 /*******************************************************************************
69 * Function Name: usb0_function_brdy_int
70 * Description : Executes BRDY interrupt(USB_FUNCTION_PIPE1-9).
71 * : According to the pipe that interrupt is generated in,
72 * : reads/writes buffer allocated in the pipe.
73 * : This function is executed in the BRDY interrupt handler.
74 * : This function clears BRDY interrupt status and BEMP interrupt
75 * : status.
76 * Arguments : uint16_t Status ; BRDYSTS Register Value
77 * : uint16_t Int_enbl ; BRDYENB Register Value
78 * Return Value : none
79 *******************************************************************************/
80 #if 0
81 void usb0_function_brdy_int (uint16_t status, uint16_t int_enb)
82 {
83 uint32_t int_sense = 0;
84 uint16_t pipe;
85 uint16_t pipebit;
86
87 for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++)
88 {
89 pipebit = g_usb0_function_bit_set[pipe];
90
91 if ((status & pipebit) && (int_enb & pipebit))
92 {
93 USB200.BRDYSTS = (uint16_t)~pipebit;
94 USB200.BEMPSTS = (uint16_t)~pipebit;
95 if ((g_usb0_function_PipeTbl[pipe] & USB_FUNCTION_FIFO_USE) == USB_FUNCTION_D0FIFO_DMA)
96 {
97 if (g_usb0_function_DmaStatus[USB_FUNCTION_D0FIFO] != USB_FUNCTION_DMA_READY)
98 {
99 usb0_function_dma_interrupt_d0fifo(int_sense);
100 }
101
102 if (RZA_IO_RegRead_16(&g_usb0_function_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
103 {
104 usb0_function_read_dma(pipe);
105 usb0_function_disable_brdy_int(pipe);
106 }
107 else
108 {
109 USB200.D0FIFOCTR = USB_FUNCTION_BITBCLR;
110 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
111 }
112 }
113 else if ((g_usb0_function_PipeTbl[pipe] & USB_FUNCTION_FIFO_USE) == USB_FUNCTION_D1FIFO_DMA)
114 {
115 if (g_usb0_function_DmaStatus[USB_FUNCTION_D1FIFO] != USB_FUNCTION_DMA_READY)
116 {
117 usb0_function_dma_interrupt_d1fifo(int_sense);
118 }
119
120 if (RZA_IO_RegRead_16(&g_usb0_function_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
121 {
122 usb0_function_read_dma(pipe);
123 usb0_function_disable_brdy_int(pipe);
124 }
125 else
126 {
127 USB200.D1FIFOCTR = USB_FUNCTION_BITBCLR;
128 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
129 }
130 }
131 else
132 {
133 if (RZA_IO_RegRead_16(&g_usb0_function_pipecfg[pipe], USB_PIPECFG_DIR_SHIFT, USB_PIPECFG_DIR) == 0)
134 {
135 usb0_function_read_buffer(pipe);
136 }
137 else
138 {
139 usb0_function_write_buffer(pipe);
140 }
141 }
142 }
143 }
144 }
145 #endif
146
147 /*******************************************************************************
148 * Function Name: usb0_function_nrdy_int
149 * Description : Executes NRDY interrupt(USB_FUNCTION_PIPE1-9).
150 * : Checks NRDY interrupt cause by PID. When the cause if STALL,
151 * : regards the pipe state as STALL and ends the processing.
152 * : Then the cause is not STALL, increments the error count to
153 * : communicate again. When the error count is 3, determines
154 * : the pipe state as DEVDRV_USBF_PIPE_NORES and ends the processing.
155 * : This function is executed in the NRDY interrupt handler.
156 * : This function clears NRDY interrupt status.
157 * Arguments : uint16_t status ; NRDYSTS Register Value
158 * : uint16_t int_enb ; NRDYENB Register Value
159 * Return Value : none
160 *******************************************************************************/
161 void usb0_function_nrdy_int (uint16_t status, uint16_t int_enb)
162 {
163 uint16_t pid;
164 uint16_t pipe;
165 uint16_t bitcheck;
166
167 bitcheck = (uint16_t)(status & int_enb);
168
169 USB200.NRDYSTS = (uint16_t)~status;
170
171 for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++)
172 {
173 if ((bitcheck&g_usb0_function_bit_set[pipe]) == g_usb0_function_bit_set[pipe])
174 {
175 if (RZA_IO_RegRead_16(&USB200.SYSCFG0, USB_SYSCFG_DCFM_SHIFT, USB_SYSCFG_DCFM) == 1)
176 {
177 if (g_usb0_function_pipe_status[pipe] == DEVDRV_USBF_PIPE_WAIT)
178 {
179 pid = usb0_function_get_pid(pipe);
180 if ((pid == DEVDRV_USBF_PID_STALL) || (pid == DEVDRV_USBF_PID_STALL2))
181 {
182 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_STALL;
183 }
184 else
185 {
186 g_usb0_function_PipeIgnore[pipe]++;
187 if (g_usb0_function_PipeIgnore[pipe] == 3)
188 {
189 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_NORES;
190 }
191 else
192 {
193 usb0_function_set_pid_buf(pipe);
194 }
195 }
196 }
197 }
198 else
199 {
200 /* USB Function */
201 }
202 }
203 }
204 }
205
206 /*******************************************************************************
207 * Function Name: usb0_function_bemp_int
208 * Description : Executes BEMP interrupt(USB_FUNCTION_PIPE1-9).
209 * Arguments : uint16_t status ; BEMPSTS Register Value
210 * : uint16_t int_enb ; BEMPENB Register Value
211 * Return Value : none
212 *******************************************************************************/
213 void usb0_function_bemp_int (uint16_t status, uint16_t int_enb)
214 {
215 uint16_t pid;
216 uint16_t pipe;
217 uint16_t bitcheck;
218 uint16_t inbuf;
219
220 bitcheck = (uint16_t)(status & int_enb);
221
222 USB200.BEMPSTS = (uint16_t)~status;
223
224 for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++)
225 {
226 if ((bitcheck&g_usb0_function_bit_set[pipe]) == g_usb0_function_bit_set[pipe])
227 {
228 pid = usb0_function_get_pid(pipe);
229
230 if ((pid == DEVDRV_USBF_PID_STALL) || (pid == DEVDRV_USBF_PID_STALL2))
231 {
232 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_STALL;
233 }
234 else
235 {
236 inbuf = usb0_function_get_inbuf(pipe);
237
238 if (inbuf == 0)
239 {
240 usb0_function_disable_bemp_int(pipe);
241 usb0_function_set_pid_nak(pipe);
242 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
243 }
244 }
245 }
246 }
247 }
248
249 /* End of File */
Imprint / Impressum