USB device stack

Dependents:   mbed-mX-USB-TEST1 USBMSD_SD_HID_HelloWorld HidTest MIDI_usb_bridge ... more

Legacy Warning

This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.

Pull requests against this repository are no longer supported. Please raise against mbed OS 5 as documented above.

Committer:
Kojto
Date:
Thu Jul 27 12:14:04 2017 +0100
Revision:
71:53949e6131f6
Update libraries

Fixes the previous commmit, as some devices were not copied. USBDevice contains
now targets directory with all targets implementations

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 71:53949e6131f6 1 /*******************************************************************************
Kojto 71:53949e6131f6 2 * DISCLAIMER
Kojto 71:53949e6131f6 3 * This software is supplied by Renesas Electronics Corporation and is only
Kojto 71:53949e6131f6 4 * intended for use with Renesas products. No other uses are authorized. This
Kojto 71:53949e6131f6 5 * software is owned by Renesas Electronics Corporation and is protected under
Kojto 71:53949e6131f6 6 * all applicable laws, including copyright laws.
Kojto 71:53949e6131f6 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
Kojto 71:53949e6131f6 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
Kojto 71:53949e6131f6 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
Kojto 71:53949e6131f6 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
Kojto 71:53949e6131f6 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
Kojto 71:53949e6131f6 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
Kojto 71:53949e6131f6 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
Kojto 71:53949e6131f6 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
Kojto 71:53949e6131f6 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Kojto 71:53949e6131f6 16 * Renesas reserves the right, without notice, to make changes to this software
Kojto 71:53949e6131f6 17 * and to discontinue the availability of this software. By using this software,
Kojto 71:53949e6131f6 18 * you agree to the additional terms and conditions found by accessing the
Kojto 71:53949e6131f6 19 * following link:
Kojto 71:53949e6131f6 20 * http://www.renesas.com/disclaimer
Kojto 71:53949e6131f6 21 * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
Kojto 71:53949e6131f6 22 *******************************************************************************/
Kojto 71:53949e6131f6 23 /*******************************************************************************
Kojto 71:53949e6131f6 24 * File Name : usb0_function_intrn.c
Kojto 71:53949e6131f6 25 * $Rev: 1116 $
Kojto 71:53949e6131f6 26 * $Date:: 2014-07-09 16:29:19 +0900#$
Kojto 71:53949e6131f6 27 * Device(s) : RZ/A1H
Kojto 71:53949e6131f6 28 * Tool-Chain :
Kojto 71:53949e6131f6 29 * OS : None
Kojto 71:53949e6131f6 30 * H/W Platform :
Kojto 71:53949e6131f6 31 * Description : RZ/A1H R7S72100 USB Sample Program
Kojto 71:53949e6131f6 32 * Operation :
Kojto 71:53949e6131f6 33 * Limitations :
Kojto 71:53949e6131f6 34 *******************************************************************************/
Kojto 71:53949e6131f6 35
Kojto 71:53949e6131f6 36
Kojto 71:53949e6131f6 37 /*******************************************************************************
Kojto 71:53949e6131f6 38 Includes <System Includes> , "Project Includes"
Kojto 71:53949e6131f6 39 *******************************************************************************/
Kojto 71:53949e6131f6 40 #include "usb0_function.h"
Kojto 71:53949e6131f6 41
Kojto 71:53949e6131f6 42
Kojto 71:53949e6131f6 43 /*******************************************************************************
Kojto 71:53949e6131f6 44 Typedef definitions
Kojto 71:53949e6131f6 45 *******************************************************************************/
Kojto 71:53949e6131f6 46
Kojto 71:53949e6131f6 47
Kojto 71:53949e6131f6 48 /*******************************************************************************
Kojto 71:53949e6131f6 49 Macro definitions
Kojto 71:53949e6131f6 50 *******************************************************************************/
Kojto 71:53949e6131f6 51
Kojto 71:53949e6131f6 52
Kojto 71:53949e6131f6 53 /*******************************************************************************
Kojto 71:53949e6131f6 54 Imported global variables and functions (from other files)
Kojto 71:53949e6131f6 55 *******************************************************************************/
Kojto 71:53949e6131f6 56
Kojto 71:53949e6131f6 57
Kojto 71:53949e6131f6 58 /*******************************************************************************
Kojto 71:53949e6131f6 59 Exported global variables and functions (to be accessed by other files)
Kojto 71:53949e6131f6 60 *******************************************************************************/
Kojto 71:53949e6131f6 61
Kojto 71:53949e6131f6 62
Kojto 71:53949e6131f6 63 /*******************************************************************************
Kojto 71:53949e6131f6 64 Private global variables and functions
Kojto 71:53949e6131f6 65 *******************************************************************************/
Kojto 71:53949e6131f6 66
Kojto 71:53949e6131f6 67
Kojto 71:53949e6131f6 68 /*******************************************************************************
Kojto 71:53949e6131f6 69 * Function Name: usb0_function_brdy_int
Kojto 71:53949e6131f6 70 * Description : Executes BRDY interrupt(USB_FUNCTION_PIPE1-9).
Kojto 71:53949e6131f6 71 * : According to the pipe that interrupt is generated in,
Kojto 71:53949e6131f6 72 * : reads/writes buffer allocated in the pipe.
Kojto 71:53949e6131f6 73 * : This function is executed in the BRDY interrupt handler.
Kojto 71:53949e6131f6 74 * : This function clears BRDY interrupt status and BEMP interrupt
Kojto 71:53949e6131f6 75 * : status.
Kojto 71:53949e6131f6 76 * Arguments : uint16_t Status ; BRDYSTS Register Value
Kojto 71:53949e6131f6 77 * : uint16_t Int_enbl ; BRDYENB Register Value
Kojto 71:53949e6131f6 78 * Return Value : none
Kojto 71:53949e6131f6 79 *******************************************************************************/
Kojto 71:53949e6131f6 80 #if 0
Kojto 71:53949e6131f6 81 void usb0_function_brdy_int (uint16_t status, uint16_t int_enb)
Kojto 71:53949e6131f6 82 {
Kojto 71:53949e6131f6 83 uint32_t int_sense = 0;
Kojto 71:53949e6131f6 84 uint16_t pipe;
Kojto 71:53949e6131f6 85 uint16_t pipebit;
Kojto 71:53949e6131f6 86
Kojto 71:53949e6131f6 87 for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++)
Kojto 71:53949e6131f6 88 {
Kojto 71:53949e6131f6 89 pipebit = g_usb0_function_bit_set[pipe];
Kojto 71:53949e6131f6 90
Kojto 71:53949e6131f6 91 if ((status & pipebit) && (int_enb & pipebit))
Kojto 71:53949e6131f6 92 {
Kojto 71:53949e6131f6 93 USB200.BRDYSTS = (uint16_t)~pipebit;
Kojto 71:53949e6131f6 94 USB200.BEMPSTS = (uint16_t)~pipebit;
Kojto 71:53949e6131f6 95 if ((g_usb0_function_PipeTbl[pipe] & USB_FUNCTION_FIFO_USE) == USB_FUNCTION_D0FIFO_DMA)
Kojto 71:53949e6131f6 96 {
Kojto 71:53949e6131f6 97 if (g_usb0_function_DmaStatus[USB_FUNCTION_D0FIFO] != USB_FUNCTION_DMA_READY)
Kojto 71:53949e6131f6 98 {
Kojto 71:53949e6131f6 99 usb0_function_dma_interrupt_d0fifo(int_sense);
Kojto 71:53949e6131f6 100 }
Kojto 71:53949e6131f6 101
Kojto 71:53949e6131f6 102 if (RZA_IO_RegRead_16(&g_usb0_function_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
Kojto 71:53949e6131f6 103 {
Kojto 71:53949e6131f6 104 usb0_function_read_dma(pipe);
Kojto 71:53949e6131f6 105 usb0_function_disable_brdy_int(pipe);
Kojto 71:53949e6131f6 106 }
Kojto 71:53949e6131f6 107 else
Kojto 71:53949e6131f6 108 {
Kojto 71:53949e6131f6 109 USB200.D0FIFOCTR = USB_FUNCTION_BITBCLR;
Kojto 71:53949e6131f6 110 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
Kojto 71:53949e6131f6 111 }
Kojto 71:53949e6131f6 112 }
Kojto 71:53949e6131f6 113 else if ((g_usb0_function_PipeTbl[pipe] & USB_FUNCTION_FIFO_USE) == USB_FUNCTION_D1FIFO_DMA)
Kojto 71:53949e6131f6 114 {
Kojto 71:53949e6131f6 115 if (g_usb0_function_DmaStatus[USB_FUNCTION_D1FIFO] != USB_FUNCTION_DMA_READY)
Kojto 71:53949e6131f6 116 {
Kojto 71:53949e6131f6 117 usb0_function_dma_interrupt_d1fifo(int_sense);
Kojto 71:53949e6131f6 118 }
Kojto 71:53949e6131f6 119
Kojto 71:53949e6131f6 120 if (RZA_IO_RegRead_16(&g_usb0_function_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
Kojto 71:53949e6131f6 121 {
Kojto 71:53949e6131f6 122 usb0_function_read_dma(pipe);
Kojto 71:53949e6131f6 123 usb0_function_disable_brdy_int(pipe);
Kojto 71:53949e6131f6 124 }
Kojto 71:53949e6131f6 125 else
Kojto 71:53949e6131f6 126 {
Kojto 71:53949e6131f6 127 USB200.D1FIFOCTR = USB_FUNCTION_BITBCLR;
Kojto 71:53949e6131f6 128 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
Kojto 71:53949e6131f6 129 }
Kojto 71:53949e6131f6 130 }
Kojto 71:53949e6131f6 131 else
Kojto 71:53949e6131f6 132 {
Kojto 71:53949e6131f6 133 if (RZA_IO_RegRead_16(&g_usb0_function_pipecfg[pipe], USB_PIPECFG_DIR_SHIFT, USB_PIPECFG_DIR) == 0)
Kojto 71:53949e6131f6 134 {
Kojto 71:53949e6131f6 135 usb0_function_read_buffer(pipe);
Kojto 71:53949e6131f6 136 }
Kojto 71:53949e6131f6 137 else
Kojto 71:53949e6131f6 138 {
Kojto 71:53949e6131f6 139 usb0_function_write_buffer(pipe);
Kojto 71:53949e6131f6 140 }
Kojto 71:53949e6131f6 141 }
Kojto 71:53949e6131f6 142 }
Kojto 71:53949e6131f6 143 }
Kojto 71:53949e6131f6 144 }
Kojto 71:53949e6131f6 145 #endif
Kojto 71:53949e6131f6 146
Kojto 71:53949e6131f6 147 /*******************************************************************************
Kojto 71:53949e6131f6 148 * Function Name: usb0_function_nrdy_int
Kojto 71:53949e6131f6 149 * Description : Executes NRDY interrupt(USB_FUNCTION_PIPE1-9).
Kojto 71:53949e6131f6 150 * : Checks NRDY interrupt cause by PID. When the cause if STALL,
Kojto 71:53949e6131f6 151 * : regards the pipe state as STALL and ends the processing.
Kojto 71:53949e6131f6 152 * : Then the cause is not STALL, increments the error count to
Kojto 71:53949e6131f6 153 * : communicate again. When the error count is 3, determines
Kojto 71:53949e6131f6 154 * : the pipe state as DEVDRV_USBF_PIPE_NORES and ends the processing.
Kojto 71:53949e6131f6 155 * : This function is executed in the NRDY interrupt handler.
Kojto 71:53949e6131f6 156 * : This function clears NRDY interrupt status.
Kojto 71:53949e6131f6 157 * Arguments : uint16_t status ; NRDYSTS Register Value
Kojto 71:53949e6131f6 158 * : uint16_t int_enb ; NRDYENB Register Value
Kojto 71:53949e6131f6 159 * Return Value : none
Kojto 71:53949e6131f6 160 *******************************************************************************/
Kojto 71:53949e6131f6 161 void usb0_function_nrdy_int (uint16_t status, uint16_t int_enb)
Kojto 71:53949e6131f6 162 {
Kojto 71:53949e6131f6 163 uint16_t pid;
Kojto 71:53949e6131f6 164 uint16_t pipe;
Kojto 71:53949e6131f6 165 uint16_t bitcheck;
Kojto 71:53949e6131f6 166
Kojto 71:53949e6131f6 167 bitcheck = (uint16_t)(status & int_enb);
Kojto 71:53949e6131f6 168
Kojto 71:53949e6131f6 169 USB200.NRDYSTS = (uint16_t)~status;
Kojto 71:53949e6131f6 170
Kojto 71:53949e6131f6 171 for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++)
Kojto 71:53949e6131f6 172 {
Kojto 71:53949e6131f6 173 if ((bitcheck&g_usb0_function_bit_set[pipe]) == g_usb0_function_bit_set[pipe])
Kojto 71:53949e6131f6 174 {
Kojto 71:53949e6131f6 175 if (RZA_IO_RegRead_16(&USB200.SYSCFG0, USB_SYSCFG_DCFM_SHIFT, USB_SYSCFG_DCFM) == 1)
Kojto 71:53949e6131f6 176 {
Kojto 71:53949e6131f6 177 if (g_usb0_function_pipe_status[pipe] == DEVDRV_USBF_PIPE_WAIT)
Kojto 71:53949e6131f6 178 {
Kojto 71:53949e6131f6 179 pid = usb0_function_get_pid(pipe);
Kojto 71:53949e6131f6 180 if ((pid == DEVDRV_USBF_PID_STALL) || (pid == DEVDRV_USBF_PID_STALL2))
Kojto 71:53949e6131f6 181 {
Kojto 71:53949e6131f6 182 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_STALL;
Kojto 71:53949e6131f6 183 }
Kojto 71:53949e6131f6 184 else
Kojto 71:53949e6131f6 185 {
Kojto 71:53949e6131f6 186 g_usb0_function_PipeIgnore[pipe]++;
Kojto 71:53949e6131f6 187 if (g_usb0_function_PipeIgnore[pipe] == 3)
Kojto 71:53949e6131f6 188 {
Kojto 71:53949e6131f6 189 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_NORES;
Kojto 71:53949e6131f6 190 }
Kojto 71:53949e6131f6 191 else
Kojto 71:53949e6131f6 192 {
Kojto 71:53949e6131f6 193 usb0_function_set_pid_buf(pipe);
Kojto 71:53949e6131f6 194 }
Kojto 71:53949e6131f6 195 }
Kojto 71:53949e6131f6 196 }
Kojto 71:53949e6131f6 197 }
Kojto 71:53949e6131f6 198 else
Kojto 71:53949e6131f6 199 {
Kojto 71:53949e6131f6 200 /* USB Function */
Kojto 71:53949e6131f6 201 }
Kojto 71:53949e6131f6 202 }
Kojto 71:53949e6131f6 203 }
Kojto 71:53949e6131f6 204 }
Kojto 71:53949e6131f6 205
Kojto 71:53949e6131f6 206 /*******************************************************************************
Kojto 71:53949e6131f6 207 * Function Name: usb0_function_bemp_int
Kojto 71:53949e6131f6 208 * Description : Executes BEMP interrupt(USB_FUNCTION_PIPE1-9).
Kojto 71:53949e6131f6 209 * Arguments : uint16_t status ; BEMPSTS Register Value
Kojto 71:53949e6131f6 210 * : uint16_t int_enb ; BEMPENB Register Value
Kojto 71:53949e6131f6 211 * Return Value : none
Kojto 71:53949e6131f6 212 *******************************************************************************/
Kojto 71:53949e6131f6 213 void usb0_function_bemp_int (uint16_t status, uint16_t int_enb)
Kojto 71:53949e6131f6 214 {
Kojto 71:53949e6131f6 215 uint16_t pid;
Kojto 71:53949e6131f6 216 uint16_t pipe;
Kojto 71:53949e6131f6 217 uint16_t bitcheck;
Kojto 71:53949e6131f6 218 uint16_t inbuf;
Kojto 71:53949e6131f6 219
Kojto 71:53949e6131f6 220 bitcheck = (uint16_t)(status & int_enb);
Kojto 71:53949e6131f6 221
Kojto 71:53949e6131f6 222 USB200.BEMPSTS = (uint16_t)~status;
Kojto 71:53949e6131f6 223
Kojto 71:53949e6131f6 224 for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++)
Kojto 71:53949e6131f6 225 {
Kojto 71:53949e6131f6 226 if ((bitcheck&g_usb0_function_bit_set[pipe]) == g_usb0_function_bit_set[pipe])
Kojto 71:53949e6131f6 227 {
Kojto 71:53949e6131f6 228 pid = usb0_function_get_pid(pipe);
Kojto 71:53949e6131f6 229
Kojto 71:53949e6131f6 230 if ((pid == DEVDRV_USBF_PID_STALL) || (pid == DEVDRV_USBF_PID_STALL2))
Kojto 71:53949e6131f6 231 {
Kojto 71:53949e6131f6 232 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_STALL;
Kojto 71:53949e6131f6 233 }
Kojto 71:53949e6131f6 234 else
Kojto 71:53949e6131f6 235 {
Kojto 71:53949e6131f6 236 inbuf = usb0_function_get_inbuf(pipe);
Kojto 71:53949e6131f6 237
Kojto 71:53949e6131f6 238 if (inbuf == 0)
Kojto 71:53949e6131f6 239 {
Kojto 71:53949e6131f6 240 usb0_function_disable_bemp_int(pipe);
Kojto 71:53949e6131f6 241 usb0_function_set_pid_nak(pipe);
Kojto 71:53949e6131f6 242 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
Kojto 71:53949e6131f6 243 }
Kojto 71:53949e6131f6 244 }
Kojto 71:53949e6131f6 245 }
Kojto 71:53949e6131f6 246 }
Kojto 71:53949e6131f6 247 }
Kojto 71:53949e6131f6 248
Kojto 71:53949e6131f6 249 /* End of File */