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:
Fri Apr 29 01:16:38 2016 +0100
Revision:
35:f72ccc6892ee
Synchronized with git revision fe9720f24b1adc71ab6962506ec51290f6afd270

Full URL: https://github.com/mbedmicro/mbed/commit/fe9720f24b1adc71ab6962506ec51290f6afd270/

[Renesas RZ/A1H] Enable asynchronous communications

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 35:f72ccc6892ee 1 /*******************************************************************************
mbed_official 35:f72ccc6892ee 2 * DISCLAIMER
mbed_official 35:f72ccc6892ee 3 * This software is supplied by Renesas Electronics Corporation and is only
mbed_official 35:f72ccc6892ee 4 * intended for use with Renesas products. No other uses are authorized. This
mbed_official 35:f72ccc6892ee 5 * software is owned by Renesas Electronics Corporation and is protected under
mbed_official 35:f72ccc6892ee 6 * all applicable laws, including copyright laws.
mbed_official 35:f72ccc6892ee 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
mbed_official 35:f72ccc6892ee 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
mbed_official 35:f72ccc6892ee 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
mbed_official 35:f72ccc6892ee 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
mbed_official 35:f72ccc6892ee 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
mbed_official 35:f72ccc6892ee 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
mbed_official 35:f72ccc6892ee 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
mbed_official 35:f72ccc6892ee 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
mbed_official 35:f72ccc6892ee 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
mbed_official 35:f72ccc6892ee 16 * Renesas reserves the right, without notice, to make changes to this software
mbed_official 35:f72ccc6892ee 17 * and to discontinue the availability of this software. By using this software,
mbed_official 35:f72ccc6892ee 18 * you agree to the additional terms and conditions found by accessing the
mbed_official 35:f72ccc6892ee 19 * following link:
mbed_official 35:f72ccc6892ee 20 * http://www.renesas.com/disclaimer
mbed_official 35:f72ccc6892ee 21 * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
mbed_official 35:f72ccc6892ee 22 *******************************************************************************/
mbed_official 35:f72ccc6892ee 23 /*******************************************************************************
mbed_official 35:f72ccc6892ee 24 * File Name : usb1_host_controlrw.c
mbed_official 35:f72ccc6892ee 25 * $Rev: 1116 $
mbed_official 35:f72ccc6892ee 26 * $Date:: 2014-07-09 16:29:19 +0900#$
mbed_official 35:f72ccc6892ee 27 * Device(s) : RZ/A1H
mbed_official 35:f72ccc6892ee 28 * Tool-Chain :
mbed_official 35:f72ccc6892ee 29 * OS : None
mbed_official 35:f72ccc6892ee 30 * H/W Platform :
mbed_official 35:f72ccc6892ee 31 * Description : RZ/A1H R7S72100 USB Sample Program
mbed_official 35:f72ccc6892ee 32 * Operation :
mbed_official 35:f72ccc6892ee 33 * Limitations :
mbed_official 35:f72ccc6892ee 34 *******************************************************************************/
mbed_official 35:f72ccc6892ee 35
mbed_official 35:f72ccc6892ee 36
mbed_official 35:f72ccc6892ee 37 /*******************************************************************************
mbed_official 35:f72ccc6892ee 38 Includes <System Includes> , "Project Includes"
mbed_official 35:f72ccc6892ee 39 *******************************************************************************/
mbed_official 35:f72ccc6892ee 40 #include "usb1_host.h"
mbed_official 35:f72ccc6892ee 41 #include "dev_drv.h"
mbed_official 35:f72ccc6892ee 42
mbed_official 35:f72ccc6892ee 43
mbed_official 35:f72ccc6892ee 44 /*******************************************************************************
mbed_official 35:f72ccc6892ee 45 Typedef definitions
mbed_official 35:f72ccc6892ee 46 *******************************************************************************/
mbed_official 35:f72ccc6892ee 47
mbed_official 35:f72ccc6892ee 48
mbed_official 35:f72ccc6892ee 49 /*******************************************************************************
mbed_official 35:f72ccc6892ee 50 Macro definitions
mbed_official 35:f72ccc6892ee 51 *******************************************************************************/
mbed_official 35:f72ccc6892ee 52
mbed_official 35:f72ccc6892ee 53
mbed_official 35:f72ccc6892ee 54 /*******************************************************************************
mbed_official 35:f72ccc6892ee 55 Imported global variables and functions (from other files)
mbed_official 35:f72ccc6892ee 56 *******************************************************************************/
mbed_official 35:f72ccc6892ee 57
mbed_official 35:f72ccc6892ee 58
mbed_official 35:f72ccc6892ee 59 /*******************************************************************************
mbed_official 35:f72ccc6892ee 60 Exported global variables and functions (to be accessed by other files)
mbed_official 35:f72ccc6892ee 61 *******************************************************************************/
mbed_official 35:f72ccc6892ee 62
mbed_official 35:f72ccc6892ee 63
mbed_official 35:f72ccc6892ee 64 /*******************************************************************************
mbed_official 35:f72ccc6892ee 65 Private global variables and functions
mbed_official 35:f72ccc6892ee 66 *******************************************************************************/
mbed_official 35:f72ccc6892ee 67
mbed_official 35:f72ccc6892ee 68
mbed_official 35:f72ccc6892ee 69 /*******************************************************************************
mbed_official 35:f72ccc6892ee 70 * Function Name: usb1_host_CtrlTransStart
mbed_official 35:f72ccc6892ee 71 * Description : Executes USB control transfer.
mbed_official 35:f72ccc6892ee 72 * Arguments : uint16_t devadr ; device address
mbed_official 35:f72ccc6892ee 73 * : uint16_t Req ; bmRequestType & bRequest
mbed_official 35:f72ccc6892ee 74 * : uint16_t Val ; wValue
mbed_official 35:f72ccc6892ee 75 * : uint16_t Indx ; wIndex
mbed_official 35:f72ccc6892ee 76 * : uint16_t Len ; wLength
mbed_official 35:f72ccc6892ee 77 * : uint8_t *Buf ; Data buffer
mbed_official 35:f72ccc6892ee 78 * Return Value : DEVDRV_SUCCESS ; SUCCESS
mbed_official 35:f72ccc6892ee 79 * : DEVDRV_ERROR ; ERROR
mbed_official 35:f72ccc6892ee 80 *******************************************************************************/
mbed_official 35:f72ccc6892ee 81 int32_t usb1_host_CtrlTransStart (uint16_t devadr, uint16_t Req, uint16_t Val,
mbed_official 35:f72ccc6892ee 82 uint16_t Indx, uint16_t Len, uint8_t * Buf)
mbed_official 35:f72ccc6892ee 83 {
mbed_official 35:f72ccc6892ee 84 if (g_usb1_host_UsbDeviceSpeed == USB_HOST_LOW_SPEED)
mbed_official 35:f72ccc6892ee 85 {
mbed_official 35:f72ccc6892ee 86 RZA_IO_RegWrite_16(&USB201.SOFCFG,
mbed_official 35:f72ccc6892ee 87 1,
mbed_official 35:f72ccc6892ee 88 USB_SOFCFG_TRNENSEL_SHIFT,
mbed_official 35:f72ccc6892ee 89 USB_SOFCFG_TRNENSEL);
mbed_official 35:f72ccc6892ee 90 }
mbed_official 35:f72ccc6892ee 91 else
mbed_official 35:f72ccc6892ee 92 {
mbed_official 35:f72ccc6892ee 93 RZA_IO_RegWrite_16(&USB201.SOFCFG,
mbed_official 35:f72ccc6892ee 94 0,
mbed_official 35:f72ccc6892ee 95 USB_SOFCFG_TRNENSEL_SHIFT,
mbed_official 35:f72ccc6892ee 96 USB_SOFCFG_TRNENSEL);
mbed_official 35:f72ccc6892ee 97 }
mbed_official 35:f72ccc6892ee 98
mbed_official 35:f72ccc6892ee 99 USB201.DCPMAXP = (uint16_t)((uint16_t)(devadr << 12) + g_usb1_host_default_max_packet[devadr]);
mbed_official 35:f72ccc6892ee 100
mbed_official 35:f72ccc6892ee 101 if (g_usb1_host_pipe_status[USB_HOST_PIPE0] == USB_HOST_PIPE_IDLE)
mbed_official 35:f72ccc6892ee 102 {
mbed_official 35:f72ccc6892ee 103 g_usb1_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_WAIT;
mbed_official 35:f72ccc6892ee 104 g_usb1_host_PipeIgnore[USB_HOST_PIPE0] = 0; /* Ignore count clear */
mbed_official 35:f72ccc6892ee 105 g_usb1_host_CmdStage = (USB_HOST_STAGE_SETUP | USB_HOST_CMD_IDLE);
mbed_official 35:f72ccc6892ee 106
mbed_official 35:f72ccc6892ee 107 if (Len == 0)
mbed_official 35:f72ccc6892ee 108 {
mbed_official 35:f72ccc6892ee 109 g_usb1_host_CmdStage |= USB_HOST_MODE_NO_DATA; /* No-data Control */
mbed_official 35:f72ccc6892ee 110 }
mbed_official 35:f72ccc6892ee 111 else
mbed_official 35:f72ccc6892ee 112 {
mbed_official 35:f72ccc6892ee 113 if ((Req & 0x0080) != 0)
mbed_official 35:f72ccc6892ee 114 {
mbed_official 35:f72ccc6892ee 115 g_usb1_host_CmdStage |= USB_HOST_MODE_READ; /* Control Read */
mbed_official 35:f72ccc6892ee 116 }
mbed_official 35:f72ccc6892ee 117 else
mbed_official 35:f72ccc6892ee 118 {
mbed_official 35:f72ccc6892ee 119 g_usb1_host_CmdStage |= USB_HOST_MODE_WRITE; /* Control Write */
mbed_official 35:f72ccc6892ee 120 }
mbed_official 35:f72ccc6892ee 121 }
mbed_official 35:f72ccc6892ee 122
mbed_official 35:f72ccc6892ee 123 g_usb1_host_SavReq = Req; /* save request */
mbed_official 35:f72ccc6892ee 124 g_usb1_host_SavVal = Val;
mbed_official 35:f72ccc6892ee 125 g_usb1_host_SavIndx = Indx;
mbed_official 35:f72ccc6892ee 126 g_usb1_host_SavLen = Len;
mbed_official 35:f72ccc6892ee 127 }
mbed_official 35:f72ccc6892ee 128 else
mbed_official 35:f72ccc6892ee 129 {
mbed_official 35:f72ccc6892ee 130 if ((g_usb1_host_SavReq != Req) || (g_usb1_host_SavVal != Val)
mbed_official 35:f72ccc6892ee 131 || (g_usb1_host_SavIndx != Indx) || (g_usb1_host_SavLen != Len))
mbed_official 35:f72ccc6892ee 132 {
mbed_official 35:f72ccc6892ee 133 return DEVDRV_ERROR;
mbed_official 35:f72ccc6892ee 134 }
mbed_official 35:f72ccc6892ee 135 }
mbed_official 35:f72ccc6892ee 136
mbed_official 35:f72ccc6892ee 137 switch ((g_usb1_host_CmdStage & (USB_HOST_STAGE_FIELD | USB_HOST_CMD_FIELD)))
mbed_official 35:f72ccc6892ee 138 {
mbed_official 35:f72ccc6892ee 139 /* --------------- SETUP STAGE --------------- */
mbed_official 35:f72ccc6892ee 140 case (USB_HOST_STAGE_SETUP | USB_HOST_CMD_IDLE):
mbed_official 35:f72ccc6892ee 141 usb1_host_SetupStage(Req, Val, Indx, Len);
mbed_official 35:f72ccc6892ee 142 break;
mbed_official 35:f72ccc6892ee 143
mbed_official 35:f72ccc6892ee 144 case (USB_HOST_STAGE_SETUP | USB_HOST_CMD_DOING):
mbed_official 35:f72ccc6892ee 145 /* do nothing */
mbed_official 35:f72ccc6892ee 146 break;
mbed_official 35:f72ccc6892ee 147
mbed_official 35:f72ccc6892ee 148 case (USB_HOST_STAGE_SETUP | USB_HOST_CMD_DONE): /* goto next stage */
mbed_official 35:f72ccc6892ee 149 g_usb1_host_PipeIgnore[USB_HOST_PIPE0] = 0; /* Ignore count clear */
mbed_official 35:f72ccc6892ee 150 switch ((g_usb1_host_CmdStage & (USB_HOST_MODE_FIELD)))
mbed_official 35:f72ccc6892ee 151 {
mbed_official 35:f72ccc6892ee 152 case USB_HOST_MODE_WRITE:
mbed_official 35:f72ccc6892ee 153 g_usb1_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
mbed_official 35:f72ccc6892ee 154 g_usb1_host_CmdStage |= USB_HOST_STAGE_DATA;
mbed_official 35:f72ccc6892ee 155 break;
mbed_official 35:f72ccc6892ee 156
mbed_official 35:f72ccc6892ee 157 case USB_HOST_MODE_READ:
mbed_official 35:f72ccc6892ee 158 g_usb1_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
mbed_official 35:f72ccc6892ee 159 g_usb1_host_CmdStage |= USB_HOST_STAGE_DATA;
mbed_official 35:f72ccc6892ee 160 break;
mbed_official 35:f72ccc6892ee 161
mbed_official 35:f72ccc6892ee 162 case USB_HOST_MODE_NO_DATA:
mbed_official 35:f72ccc6892ee 163 g_usb1_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
mbed_official 35:f72ccc6892ee 164 g_usb1_host_CmdStage |= USB_HOST_STAGE_STATUS;
mbed_official 35:f72ccc6892ee 165 break;
mbed_official 35:f72ccc6892ee 166
mbed_official 35:f72ccc6892ee 167 default:
mbed_official 35:f72ccc6892ee 168 break;
mbed_official 35:f72ccc6892ee 169 }
mbed_official 35:f72ccc6892ee 170 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 35:f72ccc6892ee 171 g_usb1_host_CmdStage |= USB_HOST_CMD_IDLE;
mbed_official 35:f72ccc6892ee 172 break;
mbed_official 35:f72ccc6892ee 173
mbed_official 35:f72ccc6892ee 174 case (USB_HOST_STAGE_SETUP | USB_HOST_CMD_NORES):
mbed_official 35:f72ccc6892ee 175 if (g_usb1_host_PipeIgnore[USB_HOST_PIPE0] == 3)
mbed_official 35:f72ccc6892ee 176 {
mbed_official 35:f72ccc6892ee 177 g_usb1_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_NORES; /* exit NORES */
mbed_official 35:f72ccc6892ee 178 }
mbed_official 35:f72ccc6892ee 179 else
mbed_official 35:f72ccc6892ee 180 {
mbed_official 35:f72ccc6892ee 181 g_usb1_host_PipeIgnore[USB_HOST_PIPE0]++; /* Ignore count */
mbed_official 35:f72ccc6892ee 182 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 35:f72ccc6892ee 183 g_usb1_host_CmdStage |= USB_HOST_CMD_IDLE;
mbed_official 35:f72ccc6892ee 184 }
mbed_official 35:f72ccc6892ee 185 break;
mbed_official 35:f72ccc6892ee 186
mbed_official 35:f72ccc6892ee 187 /* --------------- DATA STAGE --------------- */
mbed_official 35:f72ccc6892ee 188 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_IDLE):
mbed_official 35:f72ccc6892ee 189 switch ((g_usb1_host_CmdStage & (USB_HOST_MODE_FIELD)))
mbed_official 35:f72ccc6892ee 190 {
mbed_official 35:f72ccc6892ee 191 case USB_HOST_MODE_WRITE:
mbed_official 35:f72ccc6892ee 192 usb1_host_CtrlWriteStart((uint32_t)Len, Buf);
mbed_official 35:f72ccc6892ee 193 break;
mbed_official 35:f72ccc6892ee 194
mbed_official 35:f72ccc6892ee 195 case USB_HOST_MODE_READ:
mbed_official 35:f72ccc6892ee 196 usb1_host_CtrlReadStart((uint32_t)Len, Buf);
mbed_official 35:f72ccc6892ee 197 break;
mbed_official 35:f72ccc6892ee 198
mbed_official 35:f72ccc6892ee 199 default:
mbed_official 35:f72ccc6892ee 200 break;
mbed_official 35:f72ccc6892ee 201 }
mbed_official 35:f72ccc6892ee 202 break;
mbed_official 35:f72ccc6892ee 203
mbed_official 35:f72ccc6892ee 204 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_DOING):
mbed_official 35:f72ccc6892ee 205 /* do nothing */
mbed_official 35:f72ccc6892ee 206 break;
mbed_official 35:f72ccc6892ee 207
mbed_official 35:f72ccc6892ee 208 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_DONE): /* goto next stage */
mbed_official 35:f72ccc6892ee 209 g_usb1_host_PipeIgnore[USB_HOST_PIPE0] = 0; /* Ignore count clear */
mbed_official 35:f72ccc6892ee 210 g_usb1_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
mbed_official 35:f72ccc6892ee 211 g_usb1_host_CmdStage |= USB_HOST_STAGE_STATUS;
mbed_official 35:f72ccc6892ee 212 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 35:f72ccc6892ee 213 g_usb1_host_CmdStage |= USB_HOST_CMD_IDLE;
mbed_official 35:f72ccc6892ee 214 break;
mbed_official 35:f72ccc6892ee 215
mbed_official 35:f72ccc6892ee 216 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_NORES):
mbed_official 35:f72ccc6892ee 217 if (g_usb1_host_PipeIgnore[USB_HOST_PIPE0] == 3)
mbed_official 35:f72ccc6892ee 218 {
mbed_official 35:f72ccc6892ee 219 g_usb1_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_NORES; /* exit NORES */
mbed_official 35:f72ccc6892ee 220 }
mbed_official 35:f72ccc6892ee 221 else
mbed_official 35:f72ccc6892ee 222 {
mbed_official 35:f72ccc6892ee 223 g_usb1_host_PipeIgnore[USB_HOST_PIPE0]++; /* Ignore count */
mbed_official 35:f72ccc6892ee 224 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 35:f72ccc6892ee 225 g_usb1_host_CmdStage |= USB_HOST_CMD_DOING;
mbed_official 35:f72ccc6892ee 226 usb1_host_clear_pid_stall(USB_HOST_PIPE0);
mbed_official 35:f72ccc6892ee 227 usb1_host_set_pid_buf(USB_HOST_PIPE0);
mbed_official 35:f72ccc6892ee 228 }
mbed_official 35:f72ccc6892ee 229 break;
mbed_official 35:f72ccc6892ee 230
mbed_official 35:f72ccc6892ee 231 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_STALL):
mbed_official 35:f72ccc6892ee 232 g_usb1_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_STALL; /* exit STALL */
mbed_official 35:f72ccc6892ee 233 break;
mbed_official 35:f72ccc6892ee 234
mbed_official 35:f72ccc6892ee 235 /* --------------- STATUS STAGE --------------- */
mbed_official 35:f72ccc6892ee 236 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_IDLE):
mbed_official 35:f72ccc6892ee 237 usb1_host_StatusStage();
mbed_official 35:f72ccc6892ee 238 break;
mbed_official 35:f72ccc6892ee 239
mbed_official 35:f72ccc6892ee 240 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_DOING):
mbed_official 35:f72ccc6892ee 241 /* do nothing */
mbed_official 35:f72ccc6892ee 242 break;
mbed_official 35:f72ccc6892ee 243
mbed_official 35:f72ccc6892ee 244 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_DONE): /* end of Control transfer */
mbed_official 35:f72ccc6892ee 245 usb1_host_set_pid_nak(USB_HOST_PIPE0);
mbed_official 35:f72ccc6892ee 246 g_usb1_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_DONE; /* exit DONE */
mbed_official 35:f72ccc6892ee 247 break;
mbed_official 35:f72ccc6892ee 248
mbed_official 35:f72ccc6892ee 249 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_NORES):
mbed_official 35:f72ccc6892ee 250 if (g_usb1_host_PipeIgnore[USB_HOST_PIPE0] == 3)
mbed_official 35:f72ccc6892ee 251 {
mbed_official 35:f72ccc6892ee 252 g_usb1_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_NORES; /* exit NORES */
mbed_official 35:f72ccc6892ee 253 }
mbed_official 35:f72ccc6892ee 254 else
mbed_official 35:f72ccc6892ee 255 {
mbed_official 35:f72ccc6892ee 256 g_usb1_host_PipeIgnore[USB_HOST_PIPE0]++; /* Ignore count */
mbed_official 35:f72ccc6892ee 257 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 35:f72ccc6892ee 258 g_usb1_host_CmdStage |= USB_HOST_CMD_DOING;
mbed_official 35:f72ccc6892ee 259 usb1_host_clear_pid_stall(USB_HOST_PIPE0);
mbed_official 35:f72ccc6892ee 260 usb1_host_set_pid_buf(USB_HOST_PIPE0);
mbed_official 35:f72ccc6892ee 261 }
mbed_official 35:f72ccc6892ee 262 break;
mbed_official 35:f72ccc6892ee 263
mbed_official 35:f72ccc6892ee 264 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_STALL):
mbed_official 35:f72ccc6892ee 265 g_usb1_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_STALL; /* exit STALL */
mbed_official 35:f72ccc6892ee 266 break;
mbed_official 35:f72ccc6892ee 267
mbed_official 35:f72ccc6892ee 268 default:
mbed_official 35:f72ccc6892ee 269 break;
mbed_official 35:f72ccc6892ee 270 }
mbed_official 35:f72ccc6892ee 271
mbed_official 35:f72ccc6892ee 272 if (g_usb1_host_pipe_status[USB_HOST_PIPE0] != USB_HOST_PIPE_WAIT)
mbed_official 35:f72ccc6892ee 273 {
mbed_official 35:f72ccc6892ee 274 RZA_IO_RegWrite_16(&USB201.SOFCFG,
mbed_official 35:f72ccc6892ee 275 0,
mbed_official 35:f72ccc6892ee 276 USB_SOFCFG_TRNENSEL_SHIFT,
mbed_official 35:f72ccc6892ee 277 USB_SOFCFG_TRNENSEL);
mbed_official 35:f72ccc6892ee 278 }
mbed_official 35:f72ccc6892ee 279
mbed_official 35:f72ccc6892ee 280 return DEVDRV_SUCCESS;
mbed_official 35:f72ccc6892ee 281 }
mbed_official 35:f72ccc6892ee 282
mbed_official 35:f72ccc6892ee 283 /*******************************************************************************
mbed_official 35:f72ccc6892ee 284 * Function Name: usb1_host_SetupStage
mbed_official 35:f72ccc6892ee 285 * Description : Executes USB control transfer/set up stage.
mbed_official 35:f72ccc6892ee 286 * Arguments : uint16_t Req ; bmRequestType & bRequest
mbed_official 35:f72ccc6892ee 287 * : uint16_t Val ; wValue
mbed_official 35:f72ccc6892ee 288 * : uint16_t Indx ; wIndex
mbed_official 35:f72ccc6892ee 289 * : uint16_t Len ; wLength
mbed_official 35:f72ccc6892ee 290 * Return Value : none
mbed_official 35:f72ccc6892ee 291 *******************************************************************************/
mbed_official 35:f72ccc6892ee 292 void usb1_host_SetupStage (uint16_t Req, uint16_t Val, uint16_t Indx, uint16_t Len)
mbed_official 35:f72ccc6892ee 293 {
mbed_official 35:f72ccc6892ee 294 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 35:f72ccc6892ee 295 g_usb1_host_CmdStage |= USB_HOST_CMD_DOING;
mbed_official 35:f72ccc6892ee 296
mbed_official 35:f72ccc6892ee 297 USB201.INTSTS1 = (uint16_t)~(USB_HOST_BITSACK | USB_HOST_BITSIGN); /* Status Clear */
mbed_official 35:f72ccc6892ee 298 USB201.USBREQ = Req;
mbed_official 35:f72ccc6892ee 299 USB201.USBVAL = Val;
mbed_official 35:f72ccc6892ee 300 USB201.USBINDX = Indx;
mbed_official 35:f72ccc6892ee 301 USB201.USBLENG = Len;
mbed_official 35:f72ccc6892ee 302 USB201.DCPCTR = USB_HOST_BITSUREQ; /* PID=NAK & Send Setup */
mbed_official 35:f72ccc6892ee 303 }
mbed_official 35:f72ccc6892ee 304
mbed_official 35:f72ccc6892ee 305 /*******************************************************************************
mbed_official 35:f72ccc6892ee 306 * Function Name: usb1_host_StatusStage
mbed_official 35:f72ccc6892ee 307 * Description : Executes USB control transfer/status stage.
mbed_official 35:f72ccc6892ee 308 * Arguments : none
mbed_official 35:f72ccc6892ee 309 * Return Value : none
mbed_official 35:f72ccc6892ee 310 *******************************************************************************/
mbed_official 35:f72ccc6892ee 311 void usb1_host_StatusStage (void)
mbed_official 35:f72ccc6892ee 312 {
mbed_official 35:f72ccc6892ee 313 uint8_t Buf1[16];
mbed_official 35:f72ccc6892ee 314
mbed_official 35:f72ccc6892ee 315 switch ((g_usb1_host_CmdStage & (USB_HOST_MODE_FIELD)))
mbed_official 35:f72ccc6892ee 316 {
mbed_official 35:f72ccc6892ee 317 case USB_HOST_MODE_READ:
mbed_official 35:f72ccc6892ee 318 usb1_host_CtrlWriteStart((uint32_t)0, (uint8_t*)&Buf1);
mbed_official 35:f72ccc6892ee 319 break;
mbed_official 35:f72ccc6892ee 320
mbed_official 35:f72ccc6892ee 321 case USB_HOST_MODE_WRITE:
mbed_official 35:f72ccc6892ee 322 usb1_host_CtrlReadStart((uint32_t)0, (uint8_t*)&Buf1);
mbed_official 35:f72ccc6892ee 323 break;
mbed_official 35:f72ccc6892ee 324
mbed_official 35:f72ccc6892ee 325 case USB_HOST_MODE_NO_DATA:
mbed_official 35:f72ccc6892ee 326 usb1_host_CtrlReadStart((uint32_t)0, (uint8_t*)&Buf1);
mbed_official 35:f72ccc6892ee 327 break;
mbed_official 35:f72ccc6892ee 328
mbed_official 35:f72ccc6892ee 329 default:
mbed_official 35:f72ccc6892ee 330 break;
mbed_official 35:f72ccc6892ee 331 }
mbed_official 35:f72ccc6892ee 332 }
mbed_official 35:f72ccc6892ee 333
mbed_official 35:f72ccc6892ee 334 /*******************************************************************************
mbed_official 35:f72ccc6892ee 335 * Function Name: usb1_host_CtrlWriteStart
mbed_official 35:f72ccc6892ee 336 * Description : Executes USB control transfer/data stage(write).
mbed_official 35:f72ccc6892ee 337 * Arguments : uint32_t Bsize ; Data Size
mbed_official 35:f72ccc6892ee 338 * : uint8_t *Table ; Data Table Address
mbed_official 35:f72ccc6892ee 339 * Return Value : USB_HOST_WRITESHRT ; End of data write
mbed_official 35:f72ccc6892ee 340 * : USB_HOST_WRITEEND ; End of data write (not null)
mbed_official 35:f72ccc6892ee 341 * : USB_HOST_WRITING ; Continue of data write
mbed_official 35:f72ccc6892ee 342 * : USB_HOST_FIFOERROR ; FIFO access error
mbed_official 35:f72ccc6892ee 343 *******************************************************************************/
mbed_official 35:f72ccc6892ee 344 uint16_t usb1_host_CtrlWriteStart (uint32_t Bsize, uint8_t * Table)
mbed_official 35:f72ccc6892ee 345 {
mbed_official 35:f72ccc6892ee 346 uint16_t EndFlag_K;
mbed_official 35:f72ccc6892ee 347 uint16_t mbw;
mbed_official 35:f72ccc6892ee 348
mbed_official 35:f72ccc6892ee 349 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 35:f72ccc6892ee 350 g_usb1_host_CmdStage |= USB_HOST_CMD_DOING;
mbed_official 35:f72ccc6892ee 351
mbed_official 35:f72ccc6892ee 352 usb1_host_set_pid_nak(USB_HOST_PIPE0); /* Set NAK */
mbed_official 35:f72ccc6892ee 353 g_usb1_host_data_count[USB_HOST_PIPE0] = Bsize; /* Transfer size set */
mbed_official 35:f72ccc6892ee 354 g_usb1_host_data_pointer[USB_HOST_PIPE0] = Table; /* Transfer address set */
mbed_official 35:f72ccc6892ee 355
mbed_official 35:f72ccc6892ee 356 USB201.DCPCTR = USB_HOST_BITSQSET; /* SQSET=1, PID=NAK */
mbed_official 35:f72ccc6892ee 357 #if(1) /* ohci_wrapp */
mbed_official 35:f72ccc6892ee 358 Userdef_USB_usb1_host_delay_10us(3);
mbed_official 35:f72ccc6892ee 359 #endif
mbed_official 35:f72ccc6892ee 360 RZA_IO_RegWrite_16(&USB201.DCPCFG,
mbed_official 35:f72ccc6892ee 361 1,
mbed_official 35:f72ccc6892ee 362 USB_DCPCFG_DIR_SHIFT,
mbed_official 35:f72ccc6892ee 363 USB_DCPCFG_DIR);
mbed_official 35:f72ccc6892ee 364
mbed_official 35:f72ccc6892ee 365 mbw = usb1_host_get_mbw(g_usb1_host_data_count[USB_HOST_PIPE0], (uint32_t)g_usb1_host_data_pointer[USB_HOST_PIPE0]);
mbed_official 35:f72ccc6892ee 366 usb1_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_CUSE, USB_HOST_BITISEL, mbw);
mbed_official 35:f72ccc6892ee 367 USB201.CFIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
mbed_official 35:f72ccc6892ee 368
mbed_official 35:f72ccc6892ee 369 usb1_host_clear_pid_stall(USB_HOST_PIPE0);
mbed_official 35:f72ccc6892ee 370 EndFlag_K = usb1_host_write_buffer_c(USB_HOST_PIPE0);
mbed_official 35:f72ccc6892ee 371 /* Host Control sequence */
mbed_official 35:f72ccc6892ee 372 switch (EndFlag_K)
mbed_official 35:f72ccc6892ee 373 {
mbed_official 35:f72ccc6892ee 374 case USB_HOST_WRITESHRT: /* End of data write */
mbed_official 35:f72ccc6892ee 375 g_usb1_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
mbed_official 35:f72ccc6892ee 376 g_usb1_host_CmdStage |= USB_HOST_STAGE_STATUS;
mbed_official 35:f72ccc6892ee 377 usb1_host_enable_nrdy_int(USB_HOST_PIPE0); /* Error (NORES or STALL) */
mbed_official 35:f72ccc6892ee 378 usb1_host_enable_bemp_int(USB_HOST_PIPE0); /* Enable Empty Interrupt */
mbed_official 35:f72ccc6892ee 379 break;
mbed_official 35:f72ccc6892ee 380
mbed_official 35:f72ccc6892ee 381 case USB_HOST_WRITEEND: /* End of data write (not null) */
mbed_official 35:f72ccc6892ee 382 case USB_HOST_WRITING: /* Continue of data write */
mbed_official 35:f72ccc6892ee 383 usb1_host_enable_nrdy_int(USB_HOST_PIPE0); /* Error (NORES or STALL) */
mbed_official 35:f72ccc6892ee 384 usb1_host_enable_bemp_int(USB_HOST_PIPE0); /* Enable Empty Interrupt */
mbed_official 35:f72ccc6892ee 385 break;
mbed_official 35:f72ccc6892ee 386
mbed_official 35:f72ccc6892ee 387 case USB_HOST_FIFOERROR: /* FIFO access error */
mbed_official 35:f72ccc6892ee 388 break;
mbed_official 35:f72ccc6892ee 389
mbed_official 35:f72ccc6892ee 390 default:
mbed_official 35:f72ccc6892ee 391 break;
mbed_official 35:f72ccc6892ee 392 }
mbed_official 35:f72ccc6892ee 393 usb1_host_set_pid_buf(USB_HOST_PIPE0); /* Set BUF */
mbed_official 35:f72ccc6892ee 394 return (EndFlag_K); /* End or Err or Continue */
mbed_official 35:f72ccc6892ee 395 }
mbed_official 35:f72ccc6892ee 396
mbed_official 35:f72ccc6892ee 397 /*******************************************************************************
mbed_official 35:f72ccc6892ee 398 * Function Name: usb1_host_CtrlReadStart
mbed_official 35:f72ccc6892ee 399 * Description : Executes USB control transfer/data stage(read).
mbed_official 35:f72ccc6892ee 400 * Arguments : uint32_t Bsize ; Data Size
mbed_official 35:f72ccc6892ee 401 * : uint8_t *Table ; Data Table Address
mbed_official 35:f72ccc6892ee 402 * Return Value : none
mbed_official 35:f72ccc6892ee 403 *******************************************************************************/
mbed_official 35:f72ccc6892ee 404 void usb1_host_CtrlReadStart (uint32_t Bsize, uint8_t * Table)
mbed_official 35:f72ccc6892ee 405 {
mbed_official 35:f72ccc6892ee 406 uint16_t mbw;
mbed_official 35:f72ccc6892ee 407
mbed_official 35:f72ccc6892ee 408 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 35:f72ccc6892ee 409 g_usb1_host_CmdStage |= USB_HOST_CMD_DOING;
mbed_official 35:f72ccc6892ee 410
mbed_official 35:f72ccc6892ee 411 usb1_host_set_pid_nak(USB_HOST_PIPE0); /* Set NAK */
mbed_official 35:f72ccc6892ee 412 g_usb1_host_data_count[USB_HOST_PIPE0] = Bsize; /* Transfer size set */
mbed_official 35:f72ccc6892ee 413 g_usb1_host_data_pointer[USB_HOST_PIPE0] = Table; /* Transfer address set */
mbed_official 35:f72ccc6892ee 414
mbed_official 35:f72ccc6892ee 415 USB201.DCPCTR = USB_HOST_BITSQSET; /* SQSET=1, PID=NAK */
mbed_official 35:f72ccc6892ee 416 #if(1) /* ohci_wrapp */
mbed_official 35:f72ccc6892ee 417 Userdef_USB_usb1_host_delay_10us(3);
mbed_official 35:f72ccc6892ee 418 #endif
mbed_official 35:f72ccc6892ee 419 RZA_IO_RegWrite_16(&USB201.DCPCFG,
mbed_official 35:f72ccc6892ee 420 0,
mbed_official 35:f72ccc6892ee 421 USB_DCPCFG_DIR_SHIFT,
mbed_official 35:f72ccc6892ee 422 USB_DCPCFG_DIR);
mbed_official 35:f72ccc6892ee 423
mbed_official 35:f72ccc6892ee 424 mbw = usb1_host_get_mbw(g_usb1_host_data_count[USB_HOST_PIPE0], (uint32_t)g_usb1_host_data_pointer[USB_HOST_PIPE0]);
mbed_official 35:f72ccc6892ee 425 usb1_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_CUSE, USB_HOST_NO, mbw);
mbed_official 35:f72ccc6892ee 426 USB201.CFIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
mbed_official 35:f72ccc6892ee 427
mbed_official 35:f72ccc6892ee 428 usb1_host_enable_nrdy_int(USB_HOST_PIPE0); /* Error (NORES or STALL) */
mbed_official 35:f72ccc6892ee 429 usb1_host_enable_brdy_int(USB_HOST_PIPE0); /* Ok */
mbed_official 35:f72ccc6892ee 430 usb1_host_clear_pid_stall(USB_HOST_PIPE0);
mbed_official 35:f72ccc6892ee 431 usb1_host_set_pid_buf(USB_HOST_PIPE0); /* Set BUF */
mbed_official 35:f72ccc6892ee 432 }
mbed_official 35:f72ccc6892ee 433
mbed_official 35:f72ccc6892ee 434 /* End of File */