]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/USBDevice/USBDevice/TARGET_RENESAS/TARGET_RZ_A1H/usb1/src/function/usb1_function_sig.c
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / USBDevice / USBDevice / TARGET_RENESAS / TARGET_RZ_A1H / usb1 / src / function / usb1_function_sig.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_function_sig.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_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 static void usb1_function_EnableINTModule(void);
62
63
64 /*******************************************************************************
65 Private global variables and functions
66 *******************************************************************************/
67
68
69 /*******************************************************************************
70 * Function Name: usb1_function_InitModule
71 * Description : Initializes the USB module in the USB function mode.
72 * Arguments : uint16_t mode ; USB_FUNCTION_HIGH_SPEED ; Hi-Speed Mode
73 * : ; other ; Full-speed Mode
74 * Return Value : none
75 *******************************************************************************/
76 void usb1_function_InitModule (uint16_t mode)
77 {
78 RZA_IO_RegWrite_16(&USB201.SYSCFG0,
79 0,
80 USB_SYSCFG_DCFM_SHIFT,
81 USB_SYSCFG_DCFM); /* USB function */
82
83 /* USB module operation enabled */
84 RZA_IO_RegWrite_16(&USB201.SYSCFG0,
85 1,
86 USB_SYSCFG_USBE_SHIFT,
87 USB_SYSCFG_USBE);
88
89 if (mode == USB_FUNCTION_HIGH_SPEED)
90 {
91 RZA_IO_RegWrite_16(&USB201.SYSCFG0,
92 1,
93 USB_SYSCFG_HSE_SHIFT,
94 USB_SYSCFG_HSE); /* Hi-Speed Mode */
95 }
96 else
97 {
98 RZA_IO_RegWrite_16(&USB201.SYSCFG0,
99 0,
100 USB_SYSCFG_HSE_SHIFT,
101 USB_SYSCFG_HSE);
102 }
103
104 /* for power-on */
105 if (usb1_function_CheckVBUStaus() == DEVDRV_USBF_ON)
106 {
107 usb1_function_EnableINTModule(); /* Interrupt Enable */
108 usb1_function_USB_FUNCTION_Attach(); /* pull-up D+ and open D- */
109 }
110 else
111 {
112 usb1_function_USB_FUNCTION_Detach(); /* USB Detach */
113 /* with Interrupt Enable */
114 }
115 }
116
117 /*******************************************************************************
118 * Function Name: usb1_function_CheckVBUStaus
119 * Description : Checks the USB-VBUS state to returns the connection state to
120 * : the USB host.
121 * Arguments : none
122 * Return Value : DEVDRV_USBF_ON : VBUS ON
123 * : DEVDRV_USBF_OFF : VBUS OFF
124 *******************************************************************************/
125 uint16_t usb1_function_CheckVBUStaus (void)
126 {
127 uint16_t buf1;
128 uint16_t buf2;
129 uint16_t buf3;
130
131 /* monitor VBUS pins */
132 do
133 {
134 buf1 = RZA_IO_RegRead_16(&USB201.INTSTS0,
135 USB_INTSTS0_VBSTS_SHIFT,
136 USB_INTSTS0_VBSTS);
137 Userdef_USB_usb1_function_delay_10us(1);
138 buf2 = RZA_IO_RegRead_16(&USB201.INTSTS0,
139 USB_INTSTS0_VBSTS_SHIFT,
140 USB_INTSTS0_VBSTS);
141 Userdef_USB_usb1_function_delay_10us(1);
142 buf3 = RZA_IO_RegRead_16(&USB201.INTSTS0,
143 USB_INTSTS0_VBSTS_SHIFT,
144 USB_INTSTS0_VBSTS);
145 } while ((buf1 != buf2) || (buf2 != buf3));
146
147 if (buf1 == DEVDRV_USBF_OFF)
148 {
149 return DEVDRV_USBF_OFF; /* detach */
150 }
151
152 return DEVDRV_USBF_ON; /* attach */
153 }
154
155 /*******************************************************************************
156 * Function Name: usb1_function_USB_FUNCTION_Attach
157 * Description : Connects to the USB host controller.
158 * : This function pulls up D+.
159 * Arguments : none
160 * Return Value : none
161 *******************************************************************************/
162 void usb1_function_USB_FUNCTION_Attach (void)
163 {
164 Userdef_USB_usb1_function_attach();
165
166 Userdef_USB_usb1_function_delay_xms(10);
167
168 RZA_IO_RegWrite_16(&USB201.SYSCFG0,
169 1,
170 USB_SYSCFG_DPRPU_SHIFT,
171 USB_SYSCFG_DPRPU); /* Pull-up D+ and open D- */
172 }
173
174 /*******************************************************************************
175 * Function Name: usb1_function_USB_FUNCTION_Detach
176 * Description : Disconnects from the USB host controller.
177 * : This function opens D+/D-.
178 * Arguments : none
179 * Return Value : none
180 *******************************************************************************/
181 void usb1_function_USB_FUNCTION_Detach (void)
182 {
183 uint16_t pipe;
184
185 Userdef_USB_usb1_function_detach();
186
187 for (pipe = 0; pipe < (USB_FUNCTION_MAX_PIPE_NO + 1); ++pipe)
188 {
189 if (g_usb1_function_pipe_status[pipe] != DEVDRV_USBF_PIPE_IDLE)
190 {
191 usb1_function_stop_transfer(pipe);
192 }
193 }
194
195 RZA_IO_RegWrite_16(&USB201.SYSCFG0,
196 0,
197 USB_SYSCFG_DPRPU_SHIFT,
198 USB_SYSCFG_DPRPU); /* open D+ and D- */
199
200 /* Detach Recovery */
201 Userdef_USB_usb1_function_delay_500ns(); /* need 1us=500ns * 2 wait */
202 Userdef_USB_usb1_function_delay_500ns();
203
204 RZA_IO_RegWrite_16(&USB201.SYSCFG0,
205 1,
206 USB_SYSCFG_DCFM_SHIFT,
207 USB_SYSCFG_DCFM);
208 Userdef_USB_usb1_function_delay_500ns(); /* need 100ns wait but 500ns S/W wait */
209
210 RZA_IO_RegWrite_16(&USB201.SYSCFG0,
211 0,
212 USB_SYSCFG_DCFM_SHIFT,
213 USB_SYSCFG_DCFM);
214
215 RZA_IO_RegWrite_16(&USB201.SYSCFG0,
216 0,
217 USB_SYSCFG_USBE_SHIFT,
218 USB_SYSCFG_USBE); /* soft reset module */
219 Userdef_USB_usb1_function_delay_500ns();
220
221 RZA_IO_RegWrite_16(&USB201.SYSCFG0,
222 1,
223 USB_SYSCFG_USBE_SHIFT,
224 USB_SYSCFG_USBE);
225
226 usb1_function_EnableINTModule(); /* Interrupt Enable */
227 }
228
229 /*******************************************************************************
230 * Function Name: usb1_function_USB_FUNCTION_BusReset
231 * Description : This function is executed when the USB device is transitioned
232 * : to POWERD_STATE. Sets the device descriptor according to the
233 * : connection speed determined by the USB reset hand shake.
234 * Arguments : none
235 * Return Value : none
236 *******************************************************************************/
237 #if 0 /*The USBHAL in mbed does not need this function*/
238 void usb1_function_USB_FUNCTION_BusReset (void)
239 {
240 usb1_function_init_status(); /* memory clear */
241
242 if (usb1_function_is_hispeed() == USB_FUNCTION_HIGH_SPEED)
243 {
244 usb1_function_ResetDescriptor(USB_FUNCTION_HIGH_SPEED); /* Device Descriptor reset */
245 }
246 else
247 {
248 usb1_function_ResetDescriptor(USB_FUNCTION_FULL_SPEED); /* Device Descriptor reset */
249 }
250
251 usb1_function_ResetDCP(); /* Default Control PIPE reset */
252 }
253 #endif
254
255 /*******************************************************************************
256 * Function Name: usb1_function_USB_FUNCTION_Resume
257 * Description : This function is executed when the USB device detects a resume
258 * : signal.
259 * : The USB sample driver does not operate for this function.
260 * Arguments : none
261 * Return Value : none
262 *******************************************************************************/
263 #if 0 /*The USBHAL in mbed does not need this function*/
264 void usb1_function_USB_FUNCTION_Resume (void)
265 {
266 /* NOP */
267 }
268 #endif
269
270 /*******************************************************************************
271 * Function Name: usb1_function_USB_FUNCTION_Suspend
272 * Description : This function is executed when the USB device detects a suspend
273 * : signal.
274 * : The USB sample driver does not operate for this function.
275 * Arguments : none
276 * Return Value : none
277 *******************************************************************************/
278 #if 0 /*The USBHAL in mbed does not need this function*/
279 void usb1_function_USB_FUNCTION_Suspend (void)
280 {
281 /* NOP */
282 }
283 #endif
284
285 /*******************************************************************************
286 * Function Name: usb1_function_USB_FUNCTION_TestMode
287 * Description : This function is executed when the USB device is transitioned U
288 * : to TEST_MODE by the USB standard request.
289 * Arguments : none
290 * Return Value : none
291 *******************************************************************************/
292 void usb1_function_USB_FUNCTION_TestMode (void)
293 {
294 switch (g_usb1_function_TestModeSelectors & USB_FUNCTION_FUNCTION_TEST_SELECT)
295 {
296 case USB_FUNCTION_FUNCTION_TEST_J:
297 case USB_FUNCTION_FUNCTION_TEST_K:
298 case USB_FUNCTION_FUNCTION_TEST_SE0_NAK:
299 case USB_FUNCTION_FUNCTION_TEST_PACKET:
300 RZA_IO_RegWrite_16(&USB201.TESTMODE,
301 (g_usb1_function_TestModeSelectors >> 8),
302 USB_TESTMODE_UTST_SHIFT,
303 USB_TESTMODE_UTST);
304 break;
305
306 case USB_FUNCTION_FUNCTION_TEST_FORCE_ENABLE:
307 default:
308 break;
309 }
310 }
311
312 /*******************************************************************************
313 * Function Name: usb1_function_EnableINTModule
314 * Description : Enables USB interrupt.
315 * Arguments : none
316 * Return Value : none
317 *******************************************************************************/
318 static void usb1_function_EnableINTModule (void)
319 {
320 uint16_t buf;
321
322 buf = USB201.INTENB0;
323 buf |= (USB_FUNCTION_BITVBSE | USB_FUNCTION_BITDVSE | USB_FUNCTION_BITCTRE |
324 USB_FUNCTION_BITBEMPE | USB_FUNCTION_BITNRDYE | USB_FUNCTION_BITBRDYE);
325 USB201.INTENB0 = buf;
326
327 usb1_function_enable_bemp_int(USB_FUNCTION_PIPE0);
328 }
329
330 /* End of File */
Imprint / Impressum