USBHost library. NOTE: This library is only officially supported on the LPC1768 platform. For more information, please see the handbook page.

Dependencies:   FATFileSystem mbed-rtos

Dependents:   BTstack WallbotWii SD to Flash Data Transfer USBHost-MSD_HelloWorld ... 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:24:30 2017 +0100
Revision:
39:d96aa62afc5b
Update USBHost - add targets directory

This corresponds to mbed-os/master commit 9207365

Who changed what in which revision?

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