1 /*******************************************************************************
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
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
26 * $Date:: 2014-07-09 16:29:19 +0900#$
31 * Description : RZ/A1H R7S72100 USB Sample Program
34 *******************************************************************************/
37 /*******************************************************************************
38 Includes <System Includes> , "Project Includes"
39 *******************************************************************************/
40 #include "usb1_function.h"
43 /*******************************************************************************
45 *******************************************************************************/
48 /*******************************************************************************
50 *******************************************************************************/
53 /*******************************************************************************
54 Imported global variables and functions (from other files)
55 *******************************************************************************/
58 /*******************************************************************************
59 Exported global variables and functions (to be accessed by other files)
60 *******************************************************************************/
61 static void usb1_function_EnableINTModule(void);
64 /*******************************************************************************
65 Private global variables and functions
66 *******************************************************************************/
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
75 *******************************************************************************/
76 void usb1_function_InitModule (uint16_t mode
)
78 RZA_IO_RegWrite_16(&USB201
.SYSCFG0
,
80 USB_SYSCFG_DCFM_SHIFT
,
81 USB_SYSCFG_DCFM
); /* USB function */
83 /* USB module operation enabled */
84 RZA_IO_RegWrite_16(&USB201
.SYSCFG0
,
86 USB_SYSCFG_USBE_SHIFT
,
89 if (mode
== USB_FUNCTION_HIGH_SPEED
)
91 RZA_IO_RegWrite_16(&USB201
.SYSCFG0
,
94 USB_SYSCFG_HSE
); /* Hi-Speed Mode */
98 RZA_IO_RegWrite_16(&USB201
.SYSCFG0
,
100 USB_SYSCFG_HSE_SHIFT
,
105 if (usb1_function_CheckVBUStaus() == DEVDRV_USBF_ON
)
107 usb1_function_EnableINTModule(); /* Interrupt Enable */
108 usb1_function_USB_FUNCTION_Attach(); /* pull-up D+ and open D- */
112 usb1_function_USB_FUNCTION_Detach(); /* USB Detach */
113 /* with Interrupt Enable */
117 /*******************************************************************************
118 * Function Name: usb1_function_CheckVBUStaus
119 * Description : Checks the USB-VBUS state to returns the connection state to
122 * Return Value : DEVDRV_USBF_ON : VBUS ON
123 * : DEVDRV_USBF_OFF : VBUS OFF
124 *******************************************************************************/
125 uint16_t usb1_function_CheckVBUStaus (void)
131 /* monitor VBUS pins */
134 buf1
= RZA_IO_RegRead_16(&USB201
.INTSTS0
,
135 USB_INTSTS0_VBSTS_SHIFT
,
137 Userdef_USB_usb1_function_delay_10us(1);
138 buf2
= RZA_IO_RegRead_16(&USB201
.INTSTS0
,
139 USB_INTSTS0_VBSTS_SHIFT
,
141 Userdef_USB_usb1_function_delay_10us(1);
142 buf3
= RZA_IO_RegRead_16(&USB201
.INTSTS0
,
143 USB_INTSTS0_VBSTS_SHIFT
,
145 } while ((buf1
!= buf2
) || (buf2
!= buf3
));
147 if (buf1
== DEVDRV_USBF_OFF
)
149 return DEVDRV_USBF_OFF
; /* detach */
152 return DEVDRV_USBF_ON
; /* attach */
155 /*******************************************************************************
156 * Function Name: usb1_function_USB_FUNCTION_Attach
157 * Description : Connects to the USB host controller.
158 * : This function pulls up D+.
160 * Return Value : none
161 *******************************************************************************/
162 void usb1_function_USB_FUNCTION_Attach (void)
164 Userdef_USB_usb1_function_attach();
166 Userdef_USB_usb1_function_delay_xms(10);
168 RZA_IO_RegWrite_16(&USB201
.SYSCFG0
,
170 USB_SYSCFG_DPRPU_SHIFT
,
171 USB_SYSCFG_DPRPU
); /* Pull-up D+ and open D- */
174 /*******************************************************************************
175 * Function Name: usb1_function_USB_FUNCTION_Detach
176 * Description : Disconnects from the USB host controller.
177 * : This function opens D+/D-.
179 * Return Value : none
180 *******************************************************************************/
181 void usb1_function_USB_FUNCTION_Detach (void)
185 Userdef_USB_usb1_function_detach();
187 for (pipe
= 0; pipe
< (USB_FUNCTION_MAX_PIPE_NO
+ 1); ++pipe
)
189 if (g_usb1_function_pipe_status
[pipe
] != DEVDRV_USBF_PIPE_IDLE
)
191 usb1_function_stop_transfer(pipe
);
195 RZA_IO_RegWrite_16(&USB201
.SYSCFG0
,
197 USB_SYSCFG_DPRPU_SHIFT
,
198 USB_SYSCFG_DPRPU
); /* open D+ and D- */
200 /* Detach Recovery */
201 Userdef_USB_usb1_function_delay_500ns(); /* need 1us=500ns * 2 wait */
202 Userdef_USB_usb1_function_delay_500ns();
204 RZA_IO_RegWrite_16(&USB201
.SYSCFG0
,
206 USB_SYSCFG_DCFM_SHIFT
,
208 Userdef_USB_usb1_function_delay_500ns(); /* need 100ns wait but 500ns S/W wait */
210 RZA_IO_RegWrite_16(&USB201
.SYSCFG0
,
212 USB_SYSCFG_DCFM_SHIFT
,
215 RZA_IO_RegWrite_16(&USB201
.SYSCFG0
,
217 USB_SYSCFG_USBE_SHIFT
,
218 USB_SYSCFG_USBE
); /* soft reset module */
219 Userdef_USB_usb1_function_delay_500ns();
221 RZA_IO_RegWrite_16(&USB201
.SYSCFG0
,
223 USB_SYSCFG_USBE_SHIFT
,
226 usb1_function_EnableINTModule(); /* Interrupt Enable */
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.
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)
240 usb1_function_init_status(); /* memory clear */
242 if (usb1_function_is_hispeed() == USB_FUNCTION_HIGH_SPEED
)
244 usb1_function_ResetDescriptor(USB_FUNCTION_HIGH_SPEED
); /* Device Descriptor reset */
248 usb1_function_ResetDescriptor(USB_FUNCTION_FULL_SPEED
); /* Device Descriptor reset */
251 usb1_function_ResetDCP(); /* Default Control PIPE reset */
255 /*******************************************************************************
256 * Function Name: usb1_function_USB_FUNCTION_Resume
257 * Description : This function is executed when the USB device detects a resume
259 * : The USB sample driver does not operate for this function.
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)
270 /*******************************************************************************
271 * Function Name: usb1_function_USB_FUNCTION_Suspend
272 * Description : This function is executed when the USB device detects a suspend
274 * : The USB sample driver does not operate for this function.
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)
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.
290 * Return Value : none
291 *******************************************************************************/
292 void usb1_function_USB_FUNCTION_TestMode (void)
294 switch (g_usb1_function_TestModeSelectors
& USB_FUNCTION_FUNCTION_TEST_SELECT
)
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
,
306 case USB_FUNCTION_FUNCTION_TEST_FORCE_ENABLE
:
312 /*******************************************************************************
313 * Function Name: usb1_function_EnableINTModule
314 * Description : Enables USB interrupt.
316 * Return Value : none
317 *******************************************************************************/
318 static void usb1_function_EnableINTModule (void)
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
;
327 usb1_function_enable_bemp_int(USB_FUNCTION_PIPE0
);