]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/USBDevice/USBDevice/TARGET_RENESAS/TARGET_RZ_A1H/usb0/src/function/usb0_function_controlrw.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / USBDevice / USBDevice / TARGET_RENESAS / TARGET_RZ_A1H / usb0 / src / function / usb0_function_controlrw.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_controlrw.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_api_function_CtrlReadStart
70 * Description  : Executes the USB control read transfer.
71 *              : USB host controller <- USB device
72 * Arguments    : uint16_t size     ; Data Size
73 *              : uint8_t  *data    ; Data Address
74 * Return Value : DEVDRV_USBF_WRITEEND          ; End of data write
75 *              : DEVDRV_USBF_WRITESHRT         ; End of short data write
76 *              : DEVDRV_USBF_WRITING           ; Continue of data write
77 *              : DEVDRV_USBF_FIFOERROR         ; FIFO access error
78 *******************************************************************************/
79 uint16_t usb0_api_function_CtrlReadStart (uint32_t size, uint8_t * data)
80 {
81     uint16_t status;
82     uint16_t mbw;
83
84     usb0_function_set_pid_nak(USB_FUNCTION_PIPE0);
85
86     g_usb0_function_data_count[USB_FUNCTION_PIPE0]   = size;
87     g_usb0_function_data_pointer[USB_FUNCTION_PIPE0] = data;
88
89     mbw = usb0_function_get_mbw(g_usb0_function_data_count[USB_FUNCTION_PIPE0],
90                                  (uint32_t)g_usb0_function_data_pointer[USB_FUNCTION_PIPE0]);
91     usb0_function_set_curpipe(USB_FUNCTION_PIPE0, USB_FUNCTION_CUSE, USB_FUNCTION_CFIFO_WRITE, mbw);
92     USB200.CFIFOCTR = USB_FUNCTION_BITBCLR;
93
94     status = usb0_function_write_buffer_c(USB_FUNCTION_PIPE0);
95
96     /* Peripheral Control sequence */
97     switch (status)
98     {
99         case DEVDRV_USBF_WRITESHRT:                                     /* End of data write */
100         case DEVDRV_USBF_WRITEEND:                                      /* End of data write (not null) */
101         case DEVDRV_USBF_WRITING:                                       /* Continue of data write */
102             usb0_function_enable_bemp_int(USB_FUNCTION_PIPE0);          /* Enable Empty Interrupt */
103             usb0_function_set_pid_buf(USB_FUNCTION_PIPE0);              /* Set BUF */
104         break;
105
106         case DEVDRV_USBF_FIFOERROR:                                     /* FIFO access error */
107         break;
108
109         default:
110         break;
111     }
112
113     return status;                                                      /* End or Err or Continue */
114 }
115
116 /*******************************************************************************
117 * Function Name: usb0_api_function_CtrlWriteStart
118 * Description  : Executes the USB control write transfer.
119 *              : USB host controller -> USB device
120 * Arguments    : uint16_t  size         ; Data Size
121 *              : uint8_t  *data         ; Data Address
122 * Return Value : none
123 *******************************************************************************/
124 void usb0_api_function_CtrlWriteStart (uint32_t size, uint8_t * data)
125 {
126     uint16_t mbw;
127
128     usb0_function_set_pid_nak(USB_FUNCTION_PIPE0);
129
130     g_usb0_function_data_count[USB_FUNCTION_PIPE0]   = size;
131     g_usb0_function_data_pointer[USB_FUNCTION_PIPE0] = data;
132
133     mbw = usb0_function_get_mbw(g_usb0_function_data_count[USB_FUNCTION_PIPE0],
134                                 (uint32_t)g_usb0_function_data_pointer[USB_FUNCTION_PIPE0]);
135     usb0_function_set_curpipe(USB_FUNCTION_PIPE0, USB_FUNCTION_CUSE, USB_FUNCTION_CFIFO_WRITE, mbw);
136     USB200.CFIFOCTR = USB_FUNCTION_BITBCLR;
137
138     usb0_function_enable_brdy_int(USB_FUNCTION_PIPE0);
139     usb0_function_set_pid_buf(USB_FUNCTION_PIPE0);
140 }
141
142 /* End of File */