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 : usb0_host_controlrw.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 "usb0_host.h"
Kojto 39:d96aa62afc5b 41 #include "dev_drv.h"
Kojto 39:d96aa62afc5b 42
Kojto 39:d96aa62afc5b 43
Kojto 39:d96aa62afc5b 44 /*******************************************************************************
Kojto 39:d96aa62afc5b 45 Typedef definitions
Kojto 39:d96aa62afc5b 46 *******************************************************************************/
Kojto 39:d96aa62afc5b 47
Kojto 39:d96aa62afc5b 48
Kojto 39:d96aa62afc5b 49 /*******************************************************************************
Kojto 39:d96aa62afc5b 50 Macro definitions
Kojto 39:d96aa62afc5b 51 *******************************************************************************/
Kojto 39:d96aa62afc5b 52
Kojto 39:d96aa62afc5b 53
Kojto 39:d96aa62afc5b 54 /*******************************************************************************
Kojto 39:d96aa62afc5b 55 Imported global variables and functions (from other files)
Kojto 39:d96aa62afc5b 56 *******************************************************************************/
Kojto 39:d96aa62afc5b 57
Kojto 39:d96aa62afc5b 58
Kojto 39:d96aa62afc5b 59 /*******************************************************************************
Kojto 39:d96aa62afc5b 60 Exported global variables and functions (to be accessed by other files)
Kojto 39:d96aa62afc5b 61 *******************************************************************************/
Kojto 39:d96aa62afc5b 62
Kojto 39:d96aa62afc5b 63
Kojto 39:d96aa62afc5b 64 /*******************************************************************************
Kojto 39:d96aa62afc5b 65 Private global variables and functions
Kojto 39:d96aa62afc5b 66 *******************************************************************************/
Kojto 39:d96aa62afc5b 67
Kojto 39:d96aa62afc5b 68
Kojto 39:d96aa62afc5b 69 /*******************************************************************************
Kojto 39:d96aa62afc5b 70 * Function Name: usb0_host_CtrlTransStart
Kojto 39:d96aa62afc5b 71 * Description : Executes USB control transfer.
Kojto 39:d96aa62afc5b 72 * Arguments : uint16_t devadr ; device address
Kojto 39:d96aa62afc5b 73 * : uint16_t Req ; bmRequestType & bRequest
Kojto 39:d96aa62afc5b 74 * : uint16_t Val ; wValue
Kojto 39:d96aa62afc5b 75 * : uint16_t Indx ; wIndex
Kojto 39:d96aa62afc5b 76 * : uint16_t Len ; wLength
Kojto 39:d96aa62afc5b 77 * : uint8_t *Buf ; Data buffer
Kojto 39:d96aa62afc5b 78 * Return Value : DEVDRV_SUCCESS ; SUCCESS
Kojto 39:d96aa62afc5b 79 * : DEVDRV_ERROR ; ERROR
Kojto 39:d96aa62afc5b 80 *******************************************************************************/
Kojto 39:d96aa62afc5b 81 int32_t usb0_host_CtrlTransStart (uint16_t devadr, uint16_t Req, uint16_t Val,
Kojto 39:d96aa62afc5b 82 uint16_t Indx, uint16_t Len, uint8_t * Buf)
Kojto 39:d96aa62afc5b 83 {
Kojto 39:d96aa62afc5b 84 if (g_usb0_host_UsbDeviceSpeed == USB_HOST_LOW_SPEED)
Kojto 39:d96aa62afc5b 85 {
Kojto 39:d96aa62afc5b 86 RZA_IO_RegWrite_16(&USB200.SOFCFG,
Kojto 39:d96aa62afc5b 87 1,
Kojto 39:d96aa62afc5b 88 USB_SOFCFG_TRNENSEL_SHIFT,
Kojto 39:d96aa62afc5b 89 USB_SOFCFG_TRNENSEL);
Kojto 39:d96aa62afc5b 90 }
Kojto 39:d96aa62afc5b 91 else
Kojto 39:d96aa62afc5b 92 {
Kojto 39:d96aa62afc5b 93 RZA_IO_RegWrite_16(&USB200.SOFCFG,
Kojto 39:d96aa62afc5b 94 0,
Kojto 39:d96aa62afc5b 95 USB_SOFCFG_TRNENSEL_SHIFT,
Kojto 39:d96aa62afc5b 96 USB_SOFCFG_TRNENSEL);
Kojto 39:d96aa62afc5b 97 }
Kojto 39:d96aa62afc5b 98
Kojto 39:d96aa62afc5b 99 USB200.DCPMAXP = (uint16_t)((uint16_t)(devadr << 12) + g_usb0_host_default_max_packet[devadr]);
Kojto 39:d96aa62afc5b 100
Kojto 39:d96aa62afc5b 101 if (g_usb0_host_pipe_status[USB_HOST_PIPE0] == USB_HOST_PIPE_IDLE)
Kojto 39:d96aa62afc5b 102 {
Kojto 39:d96aa62afc5b 103 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_WAIT;
Kojto 39:d96aa62afc5b 104 g_usb0_host_PipeIgnore[USB_HOST_PIPE0] = 0; /* Ignore count clear */
Kojto 39:d96aa62afc5b 105 g_usb0_host_CmdStage = (USB_HOST_STAGE_SETUP | USB_HOST_CMD_IDLE);
Kojto 39:d96aa62afc5b 106
Kojto 39:d96aa62afc5b 107 if (Len == 0)
Kojto 39:d96aa62afc5b 108 {
Kojto 39:d96aa62afc5b 109 g_usb0_host_CmdStage |= USB_HOST_MODE_NO_DATA; /* No-data Control */
Kojto 39:d96aa62afc5b 110 }
Kojto 39:d96aa62afc5b 111 else
Kojto 39:d96aa62afc5b 112 {
Kojto 39:d96aa62afc5b 113 if ((Req & 0x0080) != 0)
Kojto 39:d96aa62afc5b 114 {
Kojto 39:d96aa62afc5b 115 g_usb0_host_CmdStage |= USB_HOST_MODE_READ; /* Control Read */
Kojto 39:d96aa62afc5b 116 }
Kojto 39:d96aa62afc5b 117 else
Kojto 39:d96aa62afc5b 118 {
Kojto 39:d96aa62afc5b 119 g_usb0_host_CmdStage |= USB_HOST_MODE_WRITE; /* Control Write */
Kojto 39:d96aa62afc5b 120 }
Kojto 39:d96aa62afc5b 121 }
Kojto 39:d96aa62afc5b 122
Kojto 39:d96aa62afc5b 123 g_usb0_host_SavReq = Req; /* save request */
Kojto 39:d96aa62afc5b 124 g_usb0_host_SavVal = Val;
Kojto 39:d96aa62afc5b 125 g_usb0_host_SavIndx = Indx;
Kojto 39:d96aa62afc5b 126 g_usb0_host_SavLen = Len;
Kojto 39:d96aa62afc5b 127 }
Kojto 39:d96aa62afc5b 128 else
Kojto 39:d96aa62afc5b 129 {
Kojto 39:d96aa62afc5b 130 if ((g_usb0_host_SavReq != Req) || (g_usb0_host_SavVal != Val)
Kojto 39:d96aa62afc5b 131 || (g_usb0_host_SavIndx != Indx) || (g_usb0_host_SavLen != Len))
Kojto 39:d96aa62afc5b 132 {
Kojto 39:d96aa62afc5b 133 return DEVDRV_ERROR;
Kojto 39:d96aa62afc5b 134 }
Kojto 39:d96aa62afc5b 135 }
Kojto 39:d96aa62afc5b 136
Kojto 39:d96aa62afc5b 137 switch ((g_usb0_host_CmdStage & (USB_HOST_STAGE_FIELD | USB_HOST_CMD_FIELD)))
Kojto 39:d96aa62afc5b 138 {
Kojto 39:d96aa62afc5b 139 /* --------------- SETUP STAGE --------------- */
Kojto 39:d96aa62afc5b 140 case (USB_HOST_STAGE_SETUP | USB_HOST_CMD_IDLE):
Kojto 39:d96aa62afc5b 141 usb0_host_SetupStage(Req, Val, Indx, Len);
Kojto 39:d96aa62afc5b 142 break;
Kojto 39:d96aa62afc5b 143
Kojto 39:d96aa62afc5b 144 case (USB_HOST_STAGE_SETUP | USB_HOST_CMD_DOING):
Kojto 39:d96aa62afc5b 145 /* do nothing */
Kojto 39:d96aa62afc5b 146 break;
Kojto 39:d96aa62afc5b 147
Kojto 39:d96aa62afc5b 148 case (USB_HOST_STAGE_SETUP | USB_HOST_CMD_DONE): /* goto next stage */
Kojto 39:d96aa62afc5b 149 g_usb0_host_PipeIgnore[USB_HOST_PIPE0] = 0; /* Ignore count clear */
Kojto 39:d96aa62afc5b 150 switch ((g_usb0_host_CmdStage & (USB_HOST_MODE_FIELD)))
Kojto 39:d96aa62afc5b 151 {
Kojto 39:d96aa62afc5b 152 case USB_HOST_MODE_WRITE:
Kojto 39:d96aa62afc5b 153 g_usb0_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
Kojto 39:d96aa62afc5b 154 g_usb0_host_CmdStage |= USB_HOST_STAGE_DATA;
Kojto 39:d96aa62afc5b 155 break;
Kojto 39:d96aa62afc5b 156
Kojto 39:d96aa62afc5b 157 case USB_HOST_MODE_READ:
Kojto 39:d96aa62afc5b 158 g_usb0_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
Kojto 39:d96aa62afc5b 159 g_usb0_host_CmdStage |= USB_HOST_STAGE_DATA;
Kojto 39:d96aa62afc5b 160 break;
Kojto 39:d96aa62afc5b 161
Kojto 39:d96aa62afc5b 162 case USB_HOST_MODE_NO_DATA:
Kojto 39:d96aa62afc5b 163 g_usb0_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
Kojto 39:d96aa62afc5b 164 g_usb0_host_CmdStage |= USB_HOST_STAGE_STATUS;
Kojto 39:d96aa62afc5b 165 break;
Kojto 39:d96aa62afc5b 166
Kojto 39:d96aa62afc5b 167 default:
Kojto 39:d96aa62afc5b 168 break;
Kojto 39:d96aa62afc5b 169 }
Kojto 39:d96aa62afc5b 170 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 171 g_usb0_host_CmdStage |= USB_HOST_CMD_IDLE;
Kojto 39:d96aa62afc5b 172 break;
Kojto 39:d96aa62afc5b 173
Kojto 39:d96aa62afc5b 174 case (USB_HOST_STAGE_SETUP | USB_HOST_CMD_NORES):
Kojto 39:d96aa62afc5b 175 if (g_usb0_host_PipeIgnore[USB_HOST_PIPE0] == 3)
Kojto 39:d96aa62afc5b 176 {
Kojto 39:d96aa62afc5b 177 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_NORES; /* exit NORES */
Kojto 39:d96aa62afc5b 178 }
Kojto 39:d96aa62afc5b 179 else
Kojto 39:d96aa62afc5b 180 {
Kojto 39:d96aa62afc5b 181 g_usb0_host_PipeIgnore[USB_HOST_PIPE0]++; /* Ignore count */
Kojto 39:d96aa62afc5b 182 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 183 g_usb0_host_CmdStage |= USB_HOST_CMD_IDLE;
Kojto 39:d96aa62afc5b 184 }
Kojto 39:d96aa62afc5b 185 break;
Kojto 39:d96aa62afc5b 186
Kojto 39:d96aa62afc5b 187 /* --------------- DATA STAGE --------------- */
Kojto 39:d96aa62afc5b 188 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_IDLE):
Kojto 39:d96aa62afc5b 189 switch ((g_usb0_host_CmdStage & (USB_HOST_MODE_FIELD)))
Kojto 39:d96aa62afc5b 190 {
Kojto 39:d96aa62afc5b 191 case USB_HOST_MODE_WRITE:
Kojto 39:d96aa62afc5b 192 usb0_host_CtrlWriteStart((uint32_t)Len, Buf);
Kojto 39:d96aa62afc5b 193 break;
Kojto 39:d96aa62afc5b 194
Kojto 39:d96aa62afc5b 195 case USB_HOST_MODE_READ:
Kojto 39:d96aa62afc5b 196 usb0_host_CtrlReadStart((uint32_t)Len, Buf);
Kojto 39:d96aa62afc5b 197 break;
Kojto 39:d96aa62afc5b 198
Kojto 39:d96aa62afc5b 199 default:
Kojto 39:d96aa62afc5b 200 break;
Kojto 39:d96aa62afc5b 201 }
Kojto 39:d96aa62afc5b 202 break;
Kojto 39:d96aa62afc5b 203
Kojto 39:d96aa62afc5b 204 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_DOING):
Kojto 39:d96aa62afc5b 205 /* do nothing */
Kojto 39:d96aa62afc5b 206 break;
Kojto 39:d96aa62afc5b 207
Kojto 39:d96aa62afc5b 208 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_DONE): /* goto next stage */
Kojto 39:d96aa62afc5b 209 g_usb0_host_PipeIgnore[USB_HOST_PIPE0] = 0; /* Ignore count clear */
Kojto 39:d96aa62afc5b 210 g_usb0_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
Kojto 39:d96aa62afc5b 211 g_usb0_host_CmdStage |= USB_HOST_STAGE_STATUS;
Kojto 39:d96aa62afc5b 212 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 213 g_usb0_host_CmdStage |= USB_HOST_CMD_IDLE;
Kojto 39:d96aa62afc5b 214 break;
Kojto 39:d96aa62afc5b 215
Kojto 39:d96aa62afc5b 216 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_NORES):
Kojto 39:d96aa62afc5b 217 if (g_usb0_host_PipeIgnore[USB_HOST_PIPE0] == 3)
Kojto 39:d96aa62afc5b 218 {
Kojto 39:d96aa62afc5b 219 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_NORES; /* exit NORES */
Kojto 39:d96aa62afc5b 220 }
Kojto 39:d96aa62afc5b 221 else
Kojto 39:d96aa62afc5b 222 {
Kojto 39:d96aa62afc5b 223 g_usb0_host_PipeIgnore[USB_HOST_PIPE0]++; /* Ignore count */
Kojto 39:d96aa62afc5b 224 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 225 g_usb0_host_CmdStage |= USB_HOST_CMD_DOING;
Kojto 39:d96aa62afc5b 226 usb0_host_clear_pid_stall(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 227 usb0_host_set_pid_buf(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 228 }
Kojto 39:d96aa62afc5b 229 break;
Kojto 39:d96aa62afc5b 230
Kojto 39:d96aa62afc5b 231 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_STALL):
Kojto 39:d96aa62afc5b 232 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_STALL; /* exit STALL */
Kojto 39:d96aa62afc5b 233 break;
Kojto 39:d96aa62afc5b 234
Kojto 39:d96aa62afc5b 235 /* --------------- STATUS STAGE --------------- */
Kojto 39:d96aa62afc5b 236 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_IDLE):
Kojto 39:d96aa62afc5b 237 usb0_host_StatusStage();
Kojto 39:d96aa62afc5b 238 break;
Kojto 39:d96aa62afc5b 239
Kojto 39:d96aa62afc5b 240 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_DOING):
Kojto 39:d96aa62afc5b 241 /* do nothing */
Kojto 39:d96aa62afc5b 242 break;
Kojto 39:d96aa62afc5b 243
Kojto 39:d96aa62afc5b 244 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_DONE): /* end of Control transfer */
Kojto 39:d96aa62afc5b 245 usb0_host_set_pid_nak(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 246 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_DONE; /* exit DONE */
Kojto 39:d96aa62afc5b 247 break;
Kojto 39:d96aa62afc5b 248
Kojto 39:d96aa62afc5b 249 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_NORES):
Kojto 39:d96aa62afc5b 250 if (g_usb0_host_PipeIgnore[USB_HOST_PIPE0] == 3)
Kojto 39:d96aa62afc5b 251 {
Kojto 39:d96aa62afc5b 252 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_NORES; /* exit NORES */
Kojto 39:d96aa62afc5b 253 }
Kojto 39:d96aa62afc5b 254 else
Kojto 39:d96aa62afc5b 255 {
Kojto 39:d96aa62afc5b 256 g_usb0_host_PipeIgnore[USB_HOST_PIPE0]++; /* Ignore count */
Kojto 39:d96aa62afc5b 257 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 258 g_usb0_host_CmdStage |= USB_HOST_CMD_DOING;
Kojto 39:d96aa62afc5b 259 usb0_host_clear_pid_stall(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 260 usb0_host_set_pid_buf(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 261 }
Kojto 39:d96aa62afc5b 262 break;
Kojto 39:d96aa62afc5b 263
Kojto 39:d96aa62afc5b 264 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_STALL):
Kojto 39:d96aa62afc5b 265 g_usb0_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_STALL; /* exit STALL */
Kojto 39:d96aa62afc5b 266 break;
Kojto 39:d96aa62afc5b 267
Kojto 39:d96aa62afc5b 268 default:
Kojto 39:d96aa62afc5b 269 break;
Kojto 39:d96aa62afc5b 270 }
Kojto 39:d96aa62afc5b 271
Kojto 39:d96aa62afc5b 272 if (g_usb0_host_pipe_status[USB_HOST_PIPE0] != USB_HOST_PIPE_WAIT)
Kojto 39:d96aa62afc5b 273 {
Kojto 39:d96aa62afc5b 274 RZA_IO_RegWrite_16(&USB200.SOFCFG,
Kojto 39:d96aa62afc5b 275 0,
Kojto 39:d96aa62afc5b 276 USB_SOFCFG_TRNENSEL_SHIFT,
Kojto 39:d96aa62afc5b 277 USB_SOFCFG_TRNENSEL);
Kojto 39:d96aa62afc5b 278 }
Kojto 39:d96aa62afc5b 279
Kojto 39:d96aa62afc5b 280 return DEVDRV_SUCCESS;
Kojto 39:d96aa62afc5b 281 }
Kojto 39:d96aa62afc5b 282
Kojto 39:d96aa62afc5b 283 /*******************************************************************************
Kojto 39:d96aa62afc5b 284 * Function Name: usb0_host_SetupStage
Kojto 39:d96aa62afc5b 285 * Description : Executes USB control transfer/set up stage.
Kojto 39:d96aa62afc5b 286 * Arguments : uint16_t Req ; bmRequestType & bRequest
Kojto 39:d96aa62afc5b 287 * : uint16_t Val ; wValue
Kojto 39:d96aa62afc5b 288 * : uint16_t Indx ; wIndex
Kojto 39:d96aa62afc5b 289 * : uint16_t Len ; wLength
Kojto 39:d96aa62afc5b 290 * Return Value : none
Kojto 39:d96aa62afc5b 291 *******************************************************************************/
Kojto 39:d96aa62afc5b 292 void usb0_host_SetupStage (uint16_t Req, uint16_t Val, uint16_t Indx, uint16_t Len)
Kojto 39:d96aa62afc5b 293 {
Kojto 39:d96aa62afc5b 294 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 295 g_usb0_host_CmdStage |= USB_HOST_CMD_DOING;
Kojto 39:d96aa62afc5b 296
Kojto 39:d96aa62afc5b 297 USB200.INTSTS1 = (uint16_t)~(USB_HOST_BITSACK | USB_HOST_BITSIGN); /* Status Clear */
Kojto 39:d96aa62afc5b 298 USB200.USBREQ = Req;
Kojto 39:d96aa62afc5b 299 USB200.USBVAL = Val;
Kojto 39:d96aa62afc5b 300 USB200.USBINDX = Indx;
Kojto 39:d96aa62afc5b 301 USB200.USBLENG = Len;
Kojto 39:d96aa62afc5b 302 USB200.DCPCTR = USB_HOST_BITSUREQ; /* PID=NAK & Send Setup */
Kojto 39:d96aa62afc5b 303 }
Kojto 39:d96aa62afc5b 304
Kojto 39:d96aa62afc5b 305 /*******************************************************************************
Kojto 39:d96aa62afc5b 306 * Function Name: usb0_host_StatusStage
Kojto 39:d96aa62afc5b 307 * Description : Executes USB control transfer/status stage.
Kojto 39:d96aa62afc5b 308 * Arguments : none
Kojto 39:d96aa62afc5b 309 * Return Value : none
Kojto 39:d96aa62afc5b 310 *******************************************************************************/
Kojto 39:d96aa62afc5b 311 void usb0_host_StatusStage (void)
Kojto 39:d96aa62afc5b 312 {
Kojto 39:d96aa62afc5b 313 uint8_t Buf1[16];
Kojto 39:d96aa62afc5b 314
Kojto 39:d96aa62afc5b 315 switch ((g_usb0_host_CmdStage & (USB_HOST_MODE_FIELD)))
Kojto 39:d96aa62afc5b 316 {
Kojto 39:d96aa62afc5b 317 case USB_HOST_MODE_READ:
Kojto 39:d96aa62afc5b 318 usb0_host_CtrlWriteStart((uint32_t)0, (uint8_t *)&Buf1);
Kojto 39:d96aa62afc5b 319 break;
Kojto 39:d96aa62afc5b 320
Kojto 39:d96aa62afc5b 321 case USB_HOST_MODE_WRITE:
Kojto 39:d96aa62afc5b 322 usb0_host_CtrlReadStart((uint32_t)0, (uint8_t *)&Buf1);
Kojto 39:d96aa62afc5b 323 break;
Kojto 39:d96aa62afc5b 324
Kojto 39:d96aa62afc5b 325 case USB_HOST_MODE_NO_DATA:
Kojto 39:d96aa62afc5b 326 usb0_host_CtrlReadStart((uint32_t)0, (uint8_t *)&Buf1);
Kojto 39:d96aa62afc5b 327 break;
Kojto 39:d96aa62afc5b 328
Kojto 39:d96aa62afc5b 329 default:
Kojto 39:d96aa62afc5b 330 break;
Kojto 39:d96aa62afc5b 331 }
Kojto 39:d96aa62afc5b 332 }
Kojto 39:d96aa62afc5b 333
Kojto 39:d96aa62afc5b 334 /*******************************************************************************
Kojto 39:d96aa62afc5b 335 * Function Name: usb0_host_CtrlWriteStart
Kojto 39:d96aa62afc5b 336 * Description : Executes USB control transfer/data stage(write).
Kojto 39:d96aa62afc5b 337 * Arguments : uint32_t Bsize ; Data Size
Kojto 39:d96aa62afc5b 338 * : uint8_t *Table ; Data Table Address
Kojto 39:d96aa62afc5b 339 * Return Value : USB_HOST_WRITESHRT ; End of data write
Kojto 39:d96aa62afc5b 340 * : USB_HOST_WRITEEND ; End of data write (not null)
Kojto 39:d96aa62afc5b 341 * : USB_HOST_WRITING ; Continue of data write
Kojto 39:d96aa62afc5b 342 * : USB_HOST_FIFOERROR ; FIFO access error
Kojto 39:d96aa62afc5b 343 *******************************************************************************/
Kojto 39:d96aa62afc5b 344 uint16_t usb0_host_CtrlWriteStart (uint32_t Bsize, uint8_t * Table)
Kojto 39:d96aa62afc5b 345 {
Kojto 39:d96aa62afc5b 346 uint16_t EndFlag_K;
Kojto 39:d96aa62afc5b 347 uint16_t mbw;
Kojto 39:d96aa62afc5b 348
Kojto 39:d96aa62afc5b 349 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 350 g_usb0_host_CmdStage |= USB_HOST_CMD_DOING;
Kojto 39:d96aa62afc5b 351
Kojto 39:d96aa62afc5b 352 usb0_host_set_pid_nak(USB_HOST_PIPE0); /* Set NAK */
Kojto 39:d96aa62afc5b 353 g_usb0_host_data_count[USB_HOST_PIPE0] = Bsize; /* Transfer size set */
Kojto 39:d96aa62afc5b 354 g_usb0_host_data_pointer[USB_HOST_PIPE0] = Table; /* Transfer address set */
Kojto 39:d96aa62afc5b 355
Kojto 39:d96aa62afc5b 356 USB200.DCPCTR = USB_HOST_BITSQSET; /* SQSET=1, PID=NAK */
Kojto 39:d96aa62afc5b 357 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 358 Userdef_USB_usb0_host_delay_10us(3);
Kojto 39:d96aa62afc5b 359 #endif
Kojto 39:d96aa62afc5b 360 RZA_IO_RegWrite_16(&USB200.DCPCFG,
Kojto 39:d96aa62afc5b 361 1,
Kojto 39:d96aa62afc5b 362 USB_DCPCFG_DIR_SHIFT,
Kojto 39:d96aa62afc5b 363 USB_DCPCFG_DIR);
Kojto 39:d96aa62afc5b 364
Kojto 39:d96aa62afc5b 365 mbw = usb0_host_get_mbw(g_usb0_host_data_count[USB_HOST_PIPE0], (uint32_t)g_usb0_host_data_pointer[USB_HOST_PIPE0]);
Kojto 39:d96aa62afc5b 366 usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_CUSE, USB_HOST_BITISEL, mbw);
Kojto 39:d96aa62afc5b 367 USB200.CFIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
Kojto 39:d96aa62afc5b 368
Kojto 39:d96aa62afc5b 369 usb0_host_clear_pid_stall(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 370 EndFlag_K = usb0_host_write_buffer_c(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 371 /* Host Control sequence */
Kojto 39:d96aa62afc5b 372 switch (EndFlag_K)
Kojto 39:d96aa62afc5b 373 {
Kojto 39:d96aa62afc5b 374 case USB_HOST_WRITESHRT: /* End of data write */
Kojto 39:d96aa62afc5b 375 g_usb0_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
Kojto 39:d96aa62afc5b 376 g_usb0_host_CmdStage |= USB_HOST_STAGE_STATUS;
Kojto 39:d96aa62afc5b 377 usb0_host_enable_nrdy_int(USB_HOST_PIPE0); /* Error (NORES or STALL) */
Kojto 39:d96aa62afc5b 378 usb0_host_enable_bemp_int(USB_HOST_PIPE0); /* Enable Empty Interrupt */
Kojto 39:d96aa62afc5b 379 break;
Kojto 39:d96aa62afc5b 380
Kojto 39:d96aa62afc5b 381 case USB_HOST_WRITEEND: /* End of data write (not null) */
Kojto 39:d96aa62afc5b 382 case USB_HOST_WRITING: /* Continue of data write */
Kojto 39:d96aa62afc5b 383 usb0_host_enable_nrdy_int(USB_HOST_PIPE0); /* Error (NORES or STALL) */
Kojto 39:d96aa62afc5b 384 usb0_host_enable_bemp_int(USB_HOST_PIPE0); /* Enable Empty Interrupt */
Kojto 39:d96aa62afc5b 385 break;
Kojto 39:d96aa62afc5b 386
Kojto 39:d96aa62afc5b 387 case USB_HOST_FIFOERROR: /* FIFO access error */
Kojto 39:d96aa62afc5b 388 break;
Kojto 39:d96aa62afc5b 389
Kojto 39:d96aa62afc5b 390 default:
Kojto 39:d96aa62afc5b 391 break;
Kojto 39:d96aa62afc5b 392 }
Kojto 39:d96aa62afc5b 393 usb0_host_set_pid_buf(USB_HOST_PIPE0); /* Set BUF */
Kojto 39:d96aa62afc5b 394 return (EndFlag_K); /* End or Err or Continue */
Kojto 39:d96aa62afc5b 395 }
Kojto 39:d96aa62afc5b 396
Kojto 39:d96aa62afc5b 397 /*******************************************************************************
Kojto 39:d96aa62afc5b 398 * Function Name: usb0_host_CtrlReadStart
Kojto 39:d96aa62afc5b 399 * Description : Executes USB control transfer/data stage(read).
Kojto 39:d96aa62afc5b 400 * Arguments : uint32_t Bsize ; Data Size
Kojto 39:d96aa62afc5b 401 * : uint8_t *Table ; Data Table Address
Kojto 39:d96aa62afc5b 402 * Return Value : none
Kojto 39:d96aa62afc5b 403 *******************************************************************************/
Kojto 39:d96aa62afc5b 404 void usb0_host_CtrlReadStart (uint32_t Bsize, uint8_t * Table)
Kojto 39:d96aa62afc5b 405 {
Kojto 39:d96aa62afc5b 406 uint16_t mbw;
Kojto 39:d96aa62afc5b 407
Kojto 39:d96aa62afc5b 408 g_usb0_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 409 g_usb0_host_CmdStage |= USB_HOST_CMD_DOING;
Kojto 39:d96aa62afc5b 410
Kojto 39:d96aa62afc5b 411 usb0_host_set_pid_nak(USB_HOST_PIPE0); /* Set NAK */
Kojto 39:d96aa62afc5b 412 g_usb0_host_data_count[USB_HOST_PIPE0] = Bsize; /* Transfer size set */
Kojto 39:d96aa62afc5b 413 g_usb0_host_data_pointer[USB_HOST_PIPE0] = Table; /* Transfer address set */
Kojto 39:d96aa62afc5b 414
Kojto 39:d96aa62afc5b 415 USB200.DCPCTR = USB_HOST_BITSQSET; /* SQSET=1, PID=NAK */
Kojto 39:d96aa62afc5b 416 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 417 Userdef_USB_usb0_host_delay_10us(3);
Kojto 39:d96aa62afc5b 418 #endif
Kojto 39:d96aa62afc5b 419 RZA_IO_RegWrite_16(&USB200.DCPCFG,
Kojto 39:d96aa62afc5b 420 0,
Kojto 39:d96aa62afc5b 421 USB_DCPCFG_DIR_SHIFT,
Kojto 39:d96aa62afc5b 422 USB_DCPCFG_DIR);
Kojto 39:d96aa62afc5b 423
Kojto 39:d96aa62afc5b 424 mbw = usb0_host_get_mbw(g_usb0_host_data_count[USB_HOST_PIPE0], (uint32_t)g_usb0_host_data_pointer[USB_HOST_PIPE0]);
Kojto 39:d96aa62afc5b 425 usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_CUSE, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 426 USB200.CFIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
Kojto 39:d96aa62afc5b 427
Kojto 39:d96aa62afc5b 428 usb0_host_enable_nrdy_int(USB_HOST_PIPE0); /* Error (NORES or STALL) */
Kojto 39:d96aa62afc5b 429 usb0_host_enable_brdy_int(USB_HOST_PIPE0); /* Ok */
Kojto 39:d96aa62afc5b 430 usb0_host_clear_pid_stall(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 431 usb0_host_set_pid_buf(USB_HOST_PIPE0); /* Set BUF */
Kojto 39:d96aa62afc5b 432 }
Kojto 39:d96aa62afc5b 433
Kojto 39:d96aa62afc5b 434 /* End of File */