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_usbint.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 static void usb1_host_interrupt1(void);
Kojto 39:d96aa62afc5b 65 static void usb1_host_BRDYInterrupt(uint16_t Status, uint16_t Int_enbl);
Kojto 39:d96aa62afc5b 66 static void usb1_host_NRDYInterrupt(uint16_t Status, uint16_t Int_enbl);
Kojto 39:d96aa62afc5b 67 static void usb1_host_BEMPInterrupt(uint16_t Status, uint16_t Int_enbl);
Kojto 39:d96aa62afc5b 68
Kojto 39:d96aa62afc5b 69
Kojto 39:d96aa62afc5b 70 /*******************************************************************************
Kojto 39:d96aa62afc5b 71 Private global variables and functions
Kojto 39:d96aa62afc5b 72 *******************************************************************************/
Kojto 39:d96aa62afc5b 73
Kojto 39:d96aa62afc5b 74
Kojto 39:d96aa62afc5b 75 /*******************************************************************************
Kojto 39:d96aa62afc5b 76 * Function Name: usb1_host_interrupt
Kojto 39:d96aa62afc5b 77 * Description : Executes USB interrupt.
Kojto 39:d96aa62afc5b 78 * : Register this function in the USB interrupt handler.
Kojto 39:d96aa62afc5b 79 * : Set CFIF0 in the pipe set before the interrupt after executing
Kojto 39:d96aa62afc5b 80 * : this function.
Kojto 39:d96aa62afc5b 81 * Arguments : uint32_t int_sense ; Interrupts detection mode
Kojto 39:d96aa62afc5b 82 * : ; INTC_LEVEL_SENSITIVE : Level sense
Kojto 39:d96aa62afc5b 83 * : ; INTC_EDGE_TRIGGER : Edge trigger
Kojto 39:d96aa62afc5b 84 * Return Value : none
Kojto 39:d96aa62afc5b 85 *******************************************************************************/
Kojto 39:d96aa62afc5b 86 void usb1_host_interrupt (uint32_t int_sense)
Kojto 39:d96aa62afc5b 87 {
Kojto 39:d96aa62afc5b 88 uint16_t savepipe1;
Kojto 39:d96aa62afc5b 89 uint16_t savepipe2;
Kojto 39:d96aa62afc5b 90 uint16_t buffer;
Kojto 39:d96aa62afc5b 91
Kojto 39:d96aa62afc5b 92 savepipe1 = USB201.CFIFOSEL;
Kojto 39:d96aa62afc5b 93 savepipe2 = USB201.PIPESEL;
Kojto 39:d96aa62afc5b 94 usb1_host_interrupt1();
Kojto 39:d96aa62afc5b 95
Kojto 39:d96aa62afc5b 96 /* Control transmission changes ISEL within interruption processing. */
Kojto 39:d96aa62afc5b 97 /* For this reason, write return of ISEL cannot be performed. */
Kojto 39:d96aa62afc5b 98 buffer = USB201.CFIFOSEL;
Kojto 39:d96aa62afc5b 99 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE);
Kojto 39:d96aa62afc5b 100 buffer |= (uint16_t)(savepipe1 & USB_HOST_BITCURPIPE);
Kojto 39:d96aa62afc5b 101 USB201.CFIFOSEL = buffer;
Kojto 39:d96aa62afc5b 102 USB201.PIPESEL = savepipe2;
Kojto 39:d96aa62afc5b 103 }
Kojto 39:d96aa62afc5b 104
Kojto 39:d96aa62afc5b 105 /*******************************************************************************
Kojto 39:d96aa62afc5b 106 * Function Name: usb1_host_interrupt1
Kojto 39:d96aa62afc5b 107 * Description : Execue the USB interrupt.
Kojto 39:d96aa62afc5b 108 * Arguments : none
Kojto 39:d96aa62afc5b 109 * Return Value : none
Kojto 39:d96aa62afc5b 110 *******************************************************************************/
Kojto 39:d96aa62afc5b 111 void usb1_host_interrupt1 (void)
Kojto 39:d96aa62afc5b 112 {
Kojto 39:d96aa62afc5b 113 uint16_t intsts0;
Kojto 39:d96aa62afc5b 114 uint16_t intsts1;
Kojto 39:d96aa62afc5b 115 uint16_t intenb0;
Kojto 39:d96aa62afc5b 116 uint16_t intenb1;
Kojto 39:d96aa62afc5b 117 uint16_t brdysts;
Kojto 39:d96aa62afc5b 118 uint16_t nrdysts;
Kojto 39:d96aa62afc5b 119 uint16_t bempsts;
Kojto 39:d96aa62afc5b 120 uint16_t brdyenb;
Kojto 39:d96aa62afc5b 121 uint16_t nrdyenb;
Kojto 39:d96aa62afc5b 122 uint16_t bempenb;
Kojto 39:d96aa62afc5b 123 volatile uint16_t dumy_sts;
Kojto 39:d96aa62afc5b 124
Kojto 39:d96aa62afc5b 125 intsts0 = USB201.INTSTS0;
Kojto 39:d96aa62afc5b 126 intsts1 = USB201.INTSTS1;
Kojto 39:d96aa62afc5b 127 intenb0 = USB201.INTENB0;
Kojto 39:d96aa62afc5b 128 intenb1 = USB201.INTENB1;
Kojto 39:d96aa62afc5b 129
Kojto 39:d96aa62afc5b 130 if ((intsts1 & USB_HOST_BITBCHG) && (intenb1 & USB_HOST_BITBCHGE))
Kojto 39:d96aa62afc5b 131 {
Kojto 39:d96aa62afc5b 132 USB201.INTSTS1 = (uint16_t)~USB_HOST_BITBCHG;
Kojto 39:d96aa62afc5b 133 RZA_IO_RegWrite_16(&USB201.INTENB1,
Kojto 39:d96aa62afc5b 134 0,
Kojto 39:d96aa62afc5b 135 USB_INTENB1_BCHGE_SHIFT,
Kojto 39:d96aa62afc5b 136 USB_INTENB1_BCHGE);
Kojto 39:d96aa62afc5b 137 g_usb1_host_bchg_flag = USB_HOST_YES;
Kojto 39:d96aa62afc5b 138 }
Kojto 39:d96aa62afc5b 139 else if ((intsts1 & USB_HOST_BITSACK) && (intenb1 & USB_HOST_BITSACKE))
Kojto 39:d96aa62afc5b 140 {
Kojto 39:d96aa62afc5b 141 USB201.INTSTS1 = (uint16_t)~USB_HOST_BITSACK;
Kojto 39:d96aa62afc5b 142 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 143 ohciwrapp_loc_TransEnd(USB_HOST_PIPE0, TD_CC_NOERROR);
Kojto 39:d96aa62afc5b 144 #else
Kojto 39:d96aa62afc5b 145 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 146 g_usb1_host_CmdStage |= USB_HOST_CMD_DONE;
Kojto 39:d96aa62afc5b 147 #endif
Kojto 39:d96aa62afc5b 148 }
Kojto 39:d96aa62afc5b 149 else if ((intsts1 & USB_HOST_BITSIGN) && (intenb1 & USB_HOST_BITSIGNE))
Kojto 39:d96aa62afc5b 150 {
Kojto 39:d96aa62afc5b 151 USB201.INTSTS1 = (uint16_t)~USB_HOST_BITSIGN;
Kojto 39:d96aa62afc5b 152 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 153 g_usb1_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_NORES; /* exit NORES */
Kojto 39:d96aa62afc5b 154 ohciwrapp_loc_TransEnd(USB_HOST_PIPE0, TD_CC_STALL);
Kojto 39:d96aa62afc5b 155 #else
Kojto 39:d96aa62afc5b 156 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 157 g_usb1_host_CmdStage |= USB_HOST_CMD_NORES;
Kojto 39:d96aa62afc5b 158 #endif
Kojto 39:d96aa62afc5b 159 }
Kojto 39:d96aa62afc5b 160 else if (((intsts1 & USB_HOST_BITDTCH) == USB_HOST_BITDTCH)
Kojto 39:d96aa62afc5b 161 && ((intenb1 & USB_HOST_BITDTCHE) == USB_HOST_BITDTCHE))
Kojto 39:d96aa62afc5b 162 {
Kojto 39:d96aa62afc5b 163 USB201.INTSTS1 = (uint16_t)~USB_HOST_BITDTCH;
Kojto 39:d96aa62afc5b 164 RZA_IO_RegWrite_16(&USB201.INTENB1,
Kojto 39:d96aa62afc5b 165 0,
Kojto 39:d96aa62afc5b 166 USB_INTENB1_DTCHE_SHIFT,
Kojto 39:d96aa62afc5b 167 USB_INTENB1_DTCHE);
Kojto 39:d96aa62afc5b 168 g_usb1_host_detach_flag = USB_HOST_YES;
Kojto 39:d96aa62afc5b 169
Kojto 39:d96aa62afc5b 170 Userdef_USB_usb1_host_detach();
Kojto 39:d96aa62afc5b 171
Kojto 39:d96aa62afc5b 172 usb1_host_UsbDetach2();
Kojto 39:d96aa62afc5b 173 }
Kojto 39:d96aa62afc5b 174 else if (((intsts1 & USB_HOST_BITATTCH) == USB_HOST_BITATTCH)
Kojto 39:d96aa62afc5b 175 && ((intenb1 & USB_HOST_BITATTCHE) == USB_HOST_BITATTCHE))
Kojto 39:d96aa62afc5b 176 {
Kojto 39:d96aa62afc5b 177 USB201.INTSTS1 = (uint16_t)~USB_HOST_BITATTCH;
Kojto 39:d96aa62afc5b 178 RZA_IO_RegWrite_16(&USB201.INTENB1,
Kojto 39:d96aa62afc5b 179 0,
Kojto 39:d96aa62afc5b 180 USB_INTENB1_ATTCHE_SHIFT,
Kojto 39:d96aa62afc5b 181 USB_INTENB1_ATTCHE);
Kojto 39:d96aa62afc5b 182 g_usb1_host_attach_flag = USB_HOST_YES;
Kojto 39:d96aa62afc5b 183
Kojto 39:d96aa62afc5b 184 Userdef_USB_usb1_host_attach();
Kojto 39:d96aa62afc5b 185
Kojto 39:d96aa62afc5b 186 usb1_host_UsbAttach();
Kojto 39:d96aa62afc5b 187 }
Kojto 39:d96aa62afc5b 188 else if ((intsts0 & intenb0 & (USB_HOST_BITBEMP | USB_HOST_BITNRDY | USB_HOST_BITBRDY)))
Kojto 39:d96aa62afc5b 189 {
Kojto 39:d96aa62afc5b 190 brdysts = USB201.BRDYSTS;
Kojto 39:d96aa62afc5b 191 nrdysts = USB201.NRDYSTS;
Kojto 39:d96aa62afc5b 192 bempsts = USB201.BEMPSTS;
Kojto 39:d96aa62afc5b 193 brdyenb = USB201.BRDYENB;
Kojto 39:d96aa62afc5b 194 nrdyenb = USB201.NRDYENB;
Kojto 39:d96aa62afc5b 195 bempenb = USB201.BEMPENB;
Kojto 39:d96aa62afc5b 196
Kojto 39:d96aa62afc5b 197 if ((intsts0 & USB_HOST_BITBRDY) && (intenb0 & USB_HOST_BITBRDYE) && (brdysts & brdyenb))
Kojto 39:d96aa62afc5b 198 {
Kojto 39:d96aa62afc5b 199 usb1_host_BRDYInterrupt(brdysts, brdyenb);
Kojto 39:d96aa62afc5b 200 }
Kojto 39:d96aa62afc5b 201 else if ((intsts0 & USB_HOST_BITBEMP) && (intenb0 & USB_HOST_BITBEMPE) && (bempsts & bempenb))
Kojto 39:d96aa62afc5b 202 {
Kojto 39:d96aa62afc5b 203 usb1_host_BEMPInterrupt(bempsts, bempenb);
Kojto 39:d96aa62afc5b 204 }
Kojto 39:d96aa62afc5b 205 else if ((intsts0 & USB_HOST_BITNRDY) && (intenb0 & USB_HOST_BITNRDYE) && (nrdysts & nrdyenb))
Kojto 39:d96aa62afc5b 206 {
Kojto 39:d96aa62afc5b 207 usb1_host_NRDYInterrupt(nrdysts, nrdyenb);
Kojto 39:d96aa62afc5b 208 }
Kojto 39:d96aa62afc5b 209 else
Kojto 39:d96aa62afc5b 210 {
Kojto 39:d96aa62afc5b 211 /* Do Nothing */
Kojto 39:d96aa62afc5b 212 }
Kojto 39:d96aa62afc5b 213 }
Kojto 39:d96aa62afc5b 214 else
Kojto 39:d96aa62afc5b 215 {
Kojto 39:d96aa62afc5b 216 /* Do Nothing */
Kojto 39:d96aa62afc5b 217 }
Kojto 39:d96aa62afc5b 218
Kojto 39:d96aa62afc5b 219 /* Three dummy read for clearing interrupt requests */
Kojto 39:d96aa62afc5b 220 dumy_sts = USB201.INTSTS0;
Kojto 39:d96aa62afc5b 221 dumy_sts = USB201.INTSTS1;
Kojto 39:d96aa62afc5b 222
Kojto 39:d96aa62afc5b 223 }
Kojto 39:d96aa62afc5b 224
Kojto 39:d96aa62afc5b 225 /*******************************************************************************
Kojto 39:d96aa62afc5b 226 * Function Name: usb1_host_BRDYInterrupt
Kojto 39:d96aa62afc5b 227 * Description : Executes USB BRDY interrupt.
Kojto 39:d96aa62afc5b 228 * Arguments : uint16_t Status ; BRDYSTS Register Value
Kojto 39:d96aa62afc5b 229 * : uint16_t Int_enbl ; BRDYENB Register Value
Kojto 39:d96aa62afc5b 230 * Return Value : none
Kojto 39:d96aa62afc5b 231 *******************************************************************************/
Kojto 39:d96aa62afc5b 232 void usb1_host_BRDYInterrupt (uint16_t Status, uint16_t Int_enbl)
Kojto 39:d96aa62afc5b 233 {
Kojto 39:d96aa62afc5b 234 uint16_t buffer;
Kojto 39:d96aa62afc5b 235 volatile uint16_t dumy_sts;
Kojto 39:d96aa62afc5b 236
Kojto 39:d96aa62afc5b 237 if ((Status & g_usb1_host_bit_set[USB_HOST_PIPE0]) && (Int_enbl & g_usb1_host_bit_set[USB_HOST_PIPE0]))
Kojto 39:d96aa62afc5b 238 {
Kojto 39:d96aa62afc5b 239 USB201.BRDYSTS = (uint16_t)~g_usb1_host_bit_set[USB_HOST_PIPE0];
Kojto 39:d96aa62afc5b 240
Kojto 39:d96aa62afc5b 241 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 242 switch ((g_usb1_host_CmdStage & (USB_HOST_STAGE_FIELD | USB_HOST_CMD_FIELD)))
Kojto 39:d96aa62afc5b 243 {
Kojto 39:d96aa62afc5b 244 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_DOING):
Kojto 39:d96aa62afc5b 245 buffer = usb1_host_read_buffer_c(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 246 usb1_host_disable_brdy_int(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 247 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 248 g_usb1_host_CmdStage |= USB_HOST_CMD_DONE;
Kojto 39:d96aa62afc5b 249 ohciwrapp_loc_TransEnd(USB_HOST_PIPE0, TD_CC_NOERROR);
Kojto 39:d96aa62afc5b 250 break;
Kojto 39:d96aa62afc5b 251
Kojto 39:d96aa62afc5b 252 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_DOING):
Kojto 39:d96aa62afc5b 253 buffer = usb1_host_read_buffer_c(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 254 switch (buffer)
Kojto 39:d96aa62afc5b 255 {
Kojto 39:d96aa62afc5b 256 case USB_HOST_READING: /* Continue of data read */
Kojto 39:d96aa62afc5b 257 break;
Kojto 39:d96aa62afc5b 258
Kojto 39:d96aa62afc5b 259 case USB_HOST_READEND: /* End of data read */
Kojto 39:d96aa62afc5b 260 case USB_HOST_READSHRT: /* End of data read */
Kojto 39:d96aa62afc5b 261 usb1_host_disable_brdy_int(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 262 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 263 g_usb1_host_CmdStage |= USB_HOST_CMD_DONE;
Kojto 39:d96aa62afc5b 264 ohciwrapp_loc_TransEnd(USB_HOST_PIPE0, TD_CC_NOERROR);
Kojto 39:d96aa62afc5b 265 break;
Kojto 39:d96aa62afc5b 266
Kojto 39:d96aa62afc5b 267 case USB_HOST_READOVER: /* buffer over */
Kojto 39:d96aa62afc5b 268 USB201.CFIFOCTR = USB_HOST_BITBCLR;
Kojto 39:d96aa62afc5b 269 usb1_host_disable_brdy_int(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 270 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 271 g_usb1_host_CmdStage |= USB_HOST_CMD_DONE;
Kojto 39:d96aa62afc5b 272 ohciwrapp_loc_TransEnd(USB_HOST_PIPE0, TD_CC_NOERROR);
Kojto 39:d96aa62afc5b 273 break;
Kojto 39:d96aa62afc5b 274
Kojto 39:d96aa62afc5b 275 case USB_HOST_FIFOERROR: /* FIFO access error */
Kojto 39:d96aa62afc5b 276 default:
Kojto 39:d96aa62afc5b 277 break;
Kojto 39:d96aa62afc5b 278 }
Kojto 39:d96aa62afc5b 279 break;
Kojto 39:d96aa62afc5b 280
Kojto 39:d96aa62afc5b 281 default:
Kojto 39:d96aa62afc5b 282 break;
Kojto 39:d96aa62afc5b 283 }
Kojto 39:d96aa62afc5b 284 #else
Kojto 39:d96aa62afc5b 285 switch ((g_usb1_host_CmdStage & (USB_HOST_MODE_FIELD | USB_HOST_STAGE_FIELD | USB_HOST_CMD_FIELD)))
Kojto 39:d96aa62afc5b 286 {
Kojto 39:d96aa62afc5b 287 case (USB_HOST_MODE_WRITE | USB_HOST_STAGE_STATUS | USB_HOST_CMD_DOING):
Kojto 39:d96aa62afc5b 288 case (USB_HOST_MODE_NO_DATA | USB_HOST_STAGE_STATUS | USB_HOST_CMD_DOING):
Kojto 39:d96aa62afc5b 289 buffer = usb1_host_read_buffer_c(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 290 usb1_host_disable_brdy_int(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 291 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 292 g_usb1_host_CmdStage |= USB_HOST_CMD_DONE;
Kojto 39:d96aa62afc5b 293 break;
Kojto 39:d96aa62afc5b 294
Kojto 39:d96aa62afc5b 295 case (USB_HOST_MODE_READ | USB_HOST_STAGE_DATA | USB_HOST_CMD_DOING):
Kojto 39:d96aa62afc5b 296 buffer = usb1_host_read_buffer_c(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 297
Kojto 39:d96aa62afc5b 298 switch (buffer)
Kojto 39:d96aa62afc5b 299 {
Kojto 39:d96aa62afc5b 300 case USB_HOST_READING: /* Continue of data read */
Kojto 39:d96aa62afc5b 301 break;
Kojto 39:d96aa62afc5b 302
Kojto 39:d96aa62afc5b 303 case USB_HOST_READEND: /* End of data read */
Kojto 39:d96aa62afc5b 304 case USB_HOST_READSHRT: /* End of data read */
Kojto 39:d96aa62afc5b 305 usb1_host_disable_brdy_int(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 306 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 307 g_usb1_host_CmdStage |= USB_HOST_CMD_DONE;
Kojto 39:d96aa62afc5b 308 break;
Kojto 39:d96aa62afc5b 309
Kojto 39:d96aa62afc5b 310 case USB_HOST_READOVER: /* buffer over */
Kojto 39:d96aa62afc5b 311 USB201.CFIFOCTR = USB_HOST_BITBCLR;
Kojto 39:d96aa62afc5b 312 usb1_host_disable_brdy_int(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 313 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 314 g_usb1_host_CmdStage |= USB_HOST_CMD_DONE;
Kojto 39:d96aa62afc5b 315 break;
Kojto 39:d96aa62afc5b 316
Kojto 39:d96aa62afc5b 317 case USB_HOST_FIFOERROR: /* FIFO access error */
Kojto 39:d96aa62afc5b 318 default:
Kojto 39:d96aa62afc5b 319 break;
Kojto 39:d96aa62afc5b 320 }
Kojto 39:d96aa62afc5b 321 break;
Kojto 39:d96aa62afc5b 322
Kojto 39:d96aa62afc5b 323 default:
Kojto 39:d96aa62afc5b 324 break;
Kojto 39:d96aa62afc5b 325 }
Kojto 39:d96aa62afc5b 326 #endif
Kojto 39:d96aa62afc5b 327 }
Kojto 39:d96aa62afc5b 328 else
Kojto 39:d96aa62afc5b 329 {
Kojto 39:d96aa62afc5b 330 usb1_host_brdy_int(Status, Int_enbl);
Kojto 39:d96aa62afc5b 331 }
Kojto 39:d96aa62afc5b 332
Kojto 39:d96aa62afc5b 333 /* Three dummy reads for clearing interrupt requests */
Kojto 39:d96aa62afc5b 334 dumy_sts = USB201.BRDYSTS;
Kojto 39:d96aa62afc5b 335 }
Kojto 39:d96aa62afc5b 336
Kojto 39:d96aa62afc5b 337 /*******************************************************************************
Kojto 39:d96aa62afc5b 338 * Function Name: usb1_host_NRDYInterrupt
Kojto 39:d96aa62afc5b 339 * Description : Executes USB NRDY interrupt.
Kojto 39:d96aa62afc5b 340 * Arguments : uint16_t Status ; NRDYSTS Register Value
Kojto 39:d96aa62afc5b 341 * : uint16_t Int_enbl ; NRDYENB Register Value
Kojto 39:d96aa62afc5b 342 * Return Value : none
Kojto 39:d96aa62afc5b 343 *******************************************************************************/
Kojto 39:d96aa62afc5b 344 void usb1_host_NRDYInterrupt (uint16_t Status, uint16_t Int_enbl)
Kojto 39:d96aa62afc5b 345 {
Kojto 39:d96aa62afc5b 346 uint16_t pid;
Kojto 39:d96aa62afc5b 347 volatile uint16_t dumy_sts;
Kojto 39:d96aa62afc5b 348
Kojto 39:d96aa62afc5b 349 if ((Status & g_usb1_host_bit_set[USB_HOST_PIPE0]) && (Int_enbl & g_usb1_host_bit_set[USB_HOST_PIPE0]))
Kojto 39:d96aa62afc5b 350 {
Kojto 39:d96aa62afc5b 351 USB201.NRDYSTS = (uint16_t)~g_usb1_host_bit_set[USB_HOST_PIPE0];
Kojto 39:d96aa62afc5b 352 pid = usb1_host_get_pid(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 353
Kojto 39:d96aa62afc5b 354 if ((pid == USB_HOST_PID_STALL) || (pid == USB_HOST_PID_STALL2))
Kojto 39:d96aa62afc5b 355 {
Kojto 39:d96aa62afc5b 356 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 357 g_usb1_host_CmdStage |= USB_HOST_CMD_STALL;
Kojto 39:d96aa62afc5b 358 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 359 g_usb1_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_STALL;
Kojto 39:d96aa62afc5b 360 ohciwrapp_loc_TransEnd(USB_HOST_PIPE0, TD_CC_STALL);
Kojto 39:d96aa62afc5b 361 #endif
Kojto 39:d96aa62afc5b 362
Kojto 39:d96aa62afc5b 363 }
Kojto 39:d96aa62afc5b 364 else if (pid == USB_HOST_PID_NAK)
Kojto 39:d96aa62afc5b 365 {
Kojto 39:d96aa62afc5b 366 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 367 g_usb1_host_CmdStage |= USB_HOST_CMD_NORES;
Kojto 39:d96aa62afc5b 368 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 369 g_usb1_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_NORES;
Kojto 39:d96aa62afc5b 370 ohciwrapp_loc_TransEnd(USB_HOST_PIPE0, TD_CC_STALL);
Kojto 39:d96aa62afc5b 371 #endif
Kojto 39:d96aa62afc5b 372 }
Kojto 39:d96aa62afc5b 373 else
Kojto 39:d96aa62afc5b 374 {
Kojto 39:d96aa62afc5b 375 /* Do Nothing */
Kojto 39:d96aa62afc5b 376 }
Kojto 39:d96aa62afc5b 377 }
Kojto 39:d96aa62afc5b 378 else
Kojto 39:d96aa62afc5b 379 {
Kojto 39:d96aa62afc5b 380 usb1_host_nrdy_int(Status, Int_enbl);
Kojto 39:d96aa62afc5b 381 }
Kojto 39:d96aa62afc5b 382
Kojto 39:d96aa62afc5b 383 /* Three dummy reads for clearing interrupt requests */
Kojto 39:d96aa62afc5b 384 dumy_sts = USB201.NRDYSTS;
Kojto 39:d96aa62afc5b 385 }
Kojto 39:d96aa62afc5b 386
Kojto 39:d96aa62afc5b 387 /*******************************************************************************
Kojto 39:d96aa62afc5b 388 * Function Name: usb1_host_BEMPInterrupt
Kojto 39:d96aa62afc5b 389 * Description : Executes USB BEMP interrupt.
Kojto 39:d96aa62afc5b 390 * Arguments : uint16_t Status ; BEMPSTS Register Value
Kojto 39:d96aa62afc5b 391 * : uint16_t Int_enbl ; BEMPENB Register Value
Kojto 39:d96aa62afc5b 392 * Return Value : none
Kojto 39:d96aa62afc5b 393 *******************************************************************************/
Kojto 39:d96aa62afc5b 394 void usb1_host_BEMPInterrupt (uint16_t Status, uint16_t Int_enbl)
Kojto 39:d96aa62afc5b 395 {
Kojto 39:d96aa62afc5b 396 uint16_t buffer;
Kojto 39:d96aa62afc5b 397 uint16_t pid;
Kojto 39:d96aa62afc5b 398 volatile uint16_t dumy_sts;
Kojto 39:d96aa62afc5b 399
Kojto 39:d96aa62afc5b 400 if ((Status & g_usb1_host_bit_set[USB_HOST_PIPE0]) && (Int_enbl & g_usb1_host_bit_set[USB_HOST_PIPE0]))
Kojto 39:d96aa62afc5b 401 {
Kojto 39:d96aa62afc5b 402 USB201.BEMPSTS = (uint16_t)~g_usb1_host_bit_set[USB_HOST_PIPE0];
Kojto 39:d96aa62afc5b 403 pid = usb1_host_get_pid(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 404
Kojto 39:d96aa62afc5b 405 if ((pid == USB_HOST_PID_STALL) || (pid == USB_HOST_PID_STALL2))
Kojto 39:d96aa62afc5b 406 {
Kojto 39:d96aa62afc5b 407 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 408 g_usb1_host_CmdStage |= USB_HOST_CMD_STALL;
Kojto 39:d96aa62afc5b 409 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 410 g_usb1_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_STALL; /* exit STALL */
Kojto 39:d96aa62afc5b 411 ohciwrapp_loc_TransEnd(USB_HOST_PIPE0, TD_CC_STALL);
Kojto 39:d96aa62afc5b 412 #endif
Kojto 39:d96aa62afc5b 413 }
Kojto 39:d96aa62afc5b 414 else
Kojto 39:d96aa62afc5b 415 {
Kojto 39:d96aa62afc5b 416 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 417 switch ((g_usb1_host_CmdStage & (USB_HOST_STAGE_FIELD | USB_HOST_CMD_FIELD)))
Kojto 39:d96aa62afc5b 418 {
Kojto 39:d96aa62afc5b 419 case (USB_HOST_STAGE_STATUS | USB_HOST_CMD_DOING):
Kojto 39:d96aa62afc5b 420 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 421 g_usb1_host_CmdStage |= USB_HOST_CMD_DONE;
Kojto 39:d96aa62afc5b 422 ohciwrapp_loc_TransEnd(USB_HOST_PIPE0, TD_CC_NOERROR);
Kojto 39:d96aa62afc5b 423 break;
Kojto 39:d96aa62afc5b 424
Kojto 39:d96aa62afc5b 425 case (USB_HOST_STAGE_DATA | USB_HOST_CMD_DOING):
Kojto 39:d96aa62afc5b 426 buffer = usb1_host_write_buffer(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 427 switch (buffer)
Kojto 39:d96aa62afc5b 428 {
Kojto 39:d96aa62afc5b 429 case USB_HOST_WRITING: /* Continue of data write */
Kojto 39:d96aa62afc5b 430 case USB_HOST_WRITEEND: /* End of data write (zero-length) */
Kojto 39:d96aa62afc5b 431 break;
Kojto 39:d96aa62afc5b 432
Kojto 39:d96aa62afc5b 433 case USB_HOST_WRITESHRT: /* End of data write */
Kojto 39:d96aa62afc5b 434 g_usb1_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
Kojto 39:d96aa62afc5b 435 g_usb1_host_CmdStage |= USB_HOST_STAGE_STATUS;
Kojto 39:d96aa62afc5b 436 ohciwrapp_loc_TransEnd(USB_HOST_PIPE0, TD_CC_NOERROR);
Kojto 39:d96aa62afc5b 437 break;
Kojto 39:d96aa62afc5b 438
Kojto 39:d96aa62afc5b 439 case USB_HOST_FIFOERROR: /* FIFO access error */
Kojto 39:d96aa62afc5b 440 default:
Kojto 39:d96aa62afc5b 441 break;
Kojto 39:d96aa62afc5b 442 }
Kojto 39:d96aa62afc5b 443 break;
Kojto 39:d96aa62afc5b 444
Kojto 39:d96aa62afc5b 445 default:
Kojto 39:d96aa62afc5b 446 /* do nothing */
Kojto 39:d96aa62afc5b 447 break;
Kojto 39:d96aa62afc5b 448 }
Kojto 39:d96aa62afc5b 449 #else
Kojto 39:d96aa62afc5b 450 switch ((g_usb1_host_CmdStage & (USB_HOST_MODE_FIELD | USB_HOST_STAGE_FIELD | USB_HOST_CMD_FIELD)))
Kojto 39:d96aa62afc5b 451 {
Kojto 39:d96aa62afc5b 452 case (USB_HOST_MODE_READ | USB_HOST_STAGE_STATUS | USB_HOST_CMD_DOING):
Kojto 39:d96aa62afc5b 453 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 454 g_usb1_host_CmdStage |= USB_HOST_CMD_DONE;
Kojto 39:d96aa62afc5b 455 break;
Kojto 39:d96aa62afc5b 456
Kojto 39:d96aa62afc5b 457 case (USB_HOST_MODE_WRITE | USB_HOST_STAGE_DATA | USB_HOST_CMD_DOING):
Kojto 39:d96aa62afc5b 458 buffer = usb1_host_write_buffer(USB_HOST_PIPE0);
Kojto 39:d96aa62afc5b 459 switch (buffer)
Kojto 39:d96aa62afc5b 460 {
Kojto 39:d96aa62afc5b 461 case USB_HOST_WRITING: /* Continue of data write */
Kojto 39:d96aa62afc5b 462 case USB_HOST_WRITEEND: /* End of data write (zero-length) */
Kojto 39:d96aa62afc5b 463 break;
Kojto 39:d96aa62afc5b 464
Kojto 39:d96aa62afc5b 465 case USB_HOST_WRITESHRT: /* End of data write */
Kojto 39:d96aa62afc5b 466 g_usb1_host_CmdStage &= (~USB_HOST_STAGE_FIELD);
Kojto 39:d96aa62afc5b 467 g_usb1_host_CmdStage |= USB_HOST_STAGE_STATUS;
Kojto 39:d96aa62afc5b 468 break;
Kojto 39:d96aa62afc5b 469
Kojto 39:d96aa62afc5b 470 case USB_HOST_FIFOERROR: /* FIFO access error */
Kojto 39:d96aa62afc5b 471 default:
Kojto 39:d96aa62afc5b 472 break;
Kojto 39:d96aa62afc5b 473 }
Kojto 39:d96aa62afc5b 474 break;
Kojto 39:d96aa62afc5b 475
Kojto 39:d96aa62afc5b 476 case (USB_HOST_MODE_WRITE | USB_HOST_STAGE_STATUS | USB_HOST_CMD_DOING):
Kojto 39:d96aa62afc5b 477 g_usb1_host_CmdStage &= (~USB_HOST_CMD_FIELD);
Kojto 39:d96aa62afc5b 478 g_usb1_host_CmdStage |= USB_HOST_CMD_IDLE;
Kojto 39:d96aa62afc5b 479 break;
Kojto 39:d96aa62afc5b 480
Kojto 39:d96aa62afc5b 481 default:
Kojto 39:d96aa62afc5b 482 /* do nothing */
Kojto 39:d96aa62afc5b 483 break;
Kojto 39:d96aa62afc5b 484 }
Kojto 39:d96aa62afc5b 485 #endif
Kojto 39:d96aa62afc5b 486 }
Kojto 39:d96aa62afc5b 487 }
Kojto 39:d96aa62afc5b 488 else
Kojto 39:d96aa62afc5b 489 {
Kojto 39:d96aa62afc5b 490 usb1_host_bemp_int(Status, Int_enbl);
Kojto 39:d96aa62afc5b 491 }
Kojto 39:d96aa62afc5b 492
Kojto 39:d96aa62afc5b 493 /* Three dummy reads for clearing interrupt requests */
Kojto 39:d96aa62afc5b 494 dumy_sts = USB201.BEMPSTS;
Kojto 39:d96aa62afc5b 495 }
Kojto 39:d96aa62afc5b 496
Kojto 39:d96aa62afc5b 497 /* End of File */