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:
mbed_official
Date:
Mon Jan 19 14:30:37 2015 +0000
Revision:
27:4206883f4cb7
Synchronized with git revision 0ab8d2e6b3d884137dcb5c62d29a07abe132bac7

Full URL: https://github.com/mbedmicro/mbed/commit/0ab8d2e6b3d884137dcb5c62d29a07abe132bac7/

RZ_A1H - Implement some USB functions and fix some bugs about USBHost common codes.

Who changed what in which revision?

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