USB device stack for NUCLEO-F042K6, NUCLEO-L152RE and NUCLEO-F103RB.

Dependents:   LPE-SEM01

Fork of L152RE_USBDevice by Norimasa Okamoto

I tried USB device using HAL_PCD.

/media/uploads/va009039/f042k6_usbdevice_vin.jpg

Nucleo-F042K6USB
PA11 (CN3-13)DM  (2 WHITE)
PA12 (CN3-5)DP  (3 GREEN)
GND (CN3-4)GND (5 BLACK)
VIN (CN4-1)VBUS(1 RED)

Examples

Import programF042K6_USBDevice_example

NUCLEO-F042K6 USBDevice example code

Import programL152RE_USBDevice_example

L152RE_USBDevice example code

Import programF042K6_Simple-CMSIS-DAP

cmsis-dap debug adapter

Import programL152RE_Simple-CMSIS-DAP

cmsis-dap debug adapter

Committer:
va009039
Date:
Mon Jan 18 10:47:16 2016 +0000
Revision:
65:0ba7c5e2b3dc
Parent:
46:378357d7e90d
add NUCLEO-F042K6

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 35:a8484e16c2f3 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
mbed_official 35:a8484e16c2f3 2 *
mbed_official 40:3b1c43ac045c 3 * Permission is hereby granted, free of charge, to any person
mbed_official 40:3b1c43ac045c 4 * obtaining a copy of this software and associated documentation
mbed_official 40:3b1c43ac045c 5 * files (the "Software"), to deal in the Software without
mbed_official 40:3b1c43ac045c 6 * restriction, including without limitation the rights to use,
mbed_official 40:3b1c43ac045c 7 * copy, modify, merge, publish, distribute, sublicense, and/or
mbed_official 40:3b1c43ac045c 8 * sell copies of the Software, and to permit persons to whom the
mbed_official 40:3b1c43ac045c 9 * Software is furnished to do so, subject to the following
mbed_official 40:3b1c43ac045c 10 * conditions:
mbed_official 35:a8484e16c2f3 11 *
mbed_official 40:3b1c43ac045c 12 * The above copyright notice and this permission notice shall be
mbed_official 40:3b1c43ac045c 13 * included in all copies or substantial portions of the
mbed_official 40:3b1c43ac045c 14 * Software.
mbed_official 35:a8484e16c2f3 15 *
mbed_official 40:3b1c43ac045c 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
mbed_official 40:3b1c43ac045c 17 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
mbed_official 40:3b1c43ac045c 18 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
mbed_official 40:3b1c43ac045c 19 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
mbed_official 40:3b1c43ac045c 20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mbed_official 40:3b1c43ac045c 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
mbed_official 40:3b1c43ac045c 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
mbed_official 40:3b1c43ac045c 23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
mbed_official 35:a8484e16c2f3 24 */
mbed_official 35:a8484e16c2f3 25
mbed_official 35:a8484e16c2f3 26 #if defined(TARGET_RZ_A1H)
mbed_official 35:a8484e16c2f3 27
mbed_official 35:a8484e16c2f3 28 /*
mbed_official 35:a8484e16c2f3 29 This class can use the pipe1, pipe3 and pipe6 only. You should
mbed_official 35:a8484e16c2f3 30 re-program this class if you wanted to use other pipe.
mbed_official 35:a8484e16c2f3 31 */
mbed_official 35:a8484e16c2f3 32
mbed_official 35:a8484e16c2f3 33 /*************************************************************************/
mbed_official 35:a8484e16c2f3 34 extern "C"
mbed_official 35:a8484e16c2f3 35 {
mbed_official 35:a8484e16c2f3 36 #include "r_typedefs.h"
mbed_official 35:a8484e16c2f3 37 #include "iodefine.h"
mbed_official 35:a8484e16c2f3 38 }
mbed_official 35:a8484e16c2f3 39 #include "USBHAL.h"
mbed_official 35:a8484e16c2f3 40 #include "devdrv_usb_function_api.h"
mbed_official 36:4d3e7f3d5211 41 #include "usb_iobitmask.h"
mbed_official 35:a8484e16c2f3 42 #include "rza_io_regrw.h"
mbed_official 35:a8484e16c2f3 43 #include "USBDevice_Types.h"
mbed_official 46:378357d7e90d 44 #include "usb_function_setting.h"
mbed_official 35:a8484e16c2f3 45
mbed_official 35:a8484e16c2f3 46
mbed_official 35:a8484e16c2f3 47 /*************************************************************************/
mbed_official 35:a8484e16c2f3 48 /* constants */
mbed_official 35:a8484e16c2f3 49 const struct PIPECFGREC {
mbed_official 35:a8484e16c2f3 50 uint16_t endpoint;
mbed_official 35:a8484e16c2f3 51 uint16_t pipesel;
mbed_official 35:a8484e16c2f3 52 uint16_t pipecfg;
mbed_official 35:a8484e16c2f3 53 uint16_t pipebuf;
mbed_official 35:a8484e16c2f3 54 uint16_t pipemaxp;
mbed_official 35:a8484e16c2f3 55 uint16_t pipeperi;
mbed_official 35:a8484e16c2f3 56 } def_pipecfg[] = {
mbed_official 35:a8484e16c2f3 57 /*EP0OUT and EP0IN are configured by USB IP*/
mbed_official 35:a8484e16c2f3 58 {
mbed_official 35:a8484e16c2f3 59 EP1OUT, /*EP1: Host -> Func, INT*/
mbed_official 35:a8484e16c2f3 60 6 | USB_FUNCTION_D0FIFO_USE,
mbed_official 35:a8484e16c2f3 61 USB_FUNCTION_INTERRUPT |
mbed_official 35:a8484e16c2f3 62 USB_FUNCTION_BFREOFF |
mbed_official 35:a8484e16c2f3 63 USB_FUNCTION_DBLBOFF |
mbed_official 35:a8484e16c2f3 64 USB_FUNCTION_CNTMDON |
mbed_official 35:a8484e16c2f3 65 USB_FUNCTION_SHTNAKOFF |
mbed_official 35:a8484e16c2f3 66 USB_FUNCTION_DIR_P_OUT |
mbed_official 35:a8484e16c2f3 67 USB_FUNCTION_EP1,
mbed_official 35:a8484e16c2f3 68 ( ( ( 64) / 64 - 1 ) << 10 ) | 0x04u,
mbed_official 40:3b1c43ac045c 69 MAX_PACKET_SIZE_EP1,
mbed_official 40:3b1c43ac045c 70 DEVDRV_USBF_OFF |
mbed_official 40:3b1c43ac045c 71 ( 3 << USB_PIPEPERI_IITV_SHIFT ),
mbed_official 35:a8484e16c2f3 72 },
mbed_official 35:a8484e16c2f3 73 {
mbed_official 35:a8484e16c2f3 74 EP1IN, /*EP1: Host <- Func, INT*/
mbed_official 35:a8484e16c2f3 75 7 | USB_FUNCTION_D1FIFO_USE,
mbed_official 35:a8484e16c2f3 76 USB_FUNCTION_INTERRUPT |
mbed_official 35:a8484e16c2f3 77 USB_FUNCTION_BFREOFF |
mbed_official 35:a8484e16c2f3 78 USB_FUNCTION_DBLBOFF |
mbed_official 35:a8484e16c2f3 79 USB_FUNCTION_CNTMDOFF |
mbed_official 35:a8484e16c2f3 80 USB_FUNCTION_SHTNAKOFF |
mbed_official 35:a8484e16c2f3 81 USB_FUNCTION_DIR_P_IN |
mbed_official 35:a8484e16c2f3 82 USB_FUNCTION_EP1,
mbed_official 35:a8484e16c2f3 83 ( ( ( 64) / 64 - 1 ) << 10 ) | 0x05u,
mbed_official 40:3b1c43ac045c 84 MAX_PACKET_SIZE_EP1,
mbed_official 40:3b1c43ac045c 85 DEVDRV_USBF_OFF |
mbed_official 40:3b1c43ac045c 86 ( 3 << USB_PIPEPERI_IITV_SHIFT ),
mbed_official 35:a8484e16c2f3 87 },
mbed_official 35:a8484e16c2f3 88 {
mbed_official 35:a8484e16c2f3 89 EP2OUT, /*EP2: Host -> Func, BULK*/
mbed_official 35:a8484e16c2f3 90 3 | USB_FUNCTION_D0FIFO_USE,
mbed_official 35:a8484e16c2f3 91 USB_FUNCTION_BULK |
mbed_official 35:a8484e16c2f3 92 USB_FUNCTION_BFREOFF |
mbed_official 35:a8484e16c2f3 93 USB_FUNCTION_DBLBON |
mbed_official 35:a8484e16c2f3 94 USB_FUNCTION_CNTMDON |
mbed_official 35:a8484e16c2f3 95 USB_FUNCTION_SHTNAKON |
mbed_official 35:a8484e16c2f3 96 USB_FUNCTION_DIR_P_OUT |
mbed_official 35:a8484e16c2f3 97 USB_FUNCTION_EP2,
mbed_official 35:a8484e16c2f3 98 ( ( (2048) / 64 - 1 ) << 10 ) | 0x30u,
mbed_official 40:3b1c43ac045c 99 MAX_PACKET_SIZE_EP2,
mbed_official 40:3b1c43ac045c 100 DEVDRV_USBF_OFF |
mbed_official 40:3b1c43ac045c 101 ( 0 << USB_PIPEPERI_IITV_SHIFT ),
mbed_official 35:a8484e16c2f3 102 },
mbed_official 35:a8484e16c2f3 103 {
mbed_official 35:a8484e16c2f3 104 EP2IN, /*EP2: Host <- Func, BULK*/
mbed_official 35:a8484e16c2f3 105 4 | USB_FUNCTION_D1FIFO_USE,
mbed_official 35:a8484e16c2f3 106 USB_FUNCTION_BULK |
mbed_official 35:a8484e16c2f3 107 USB_FUNCTION_BFREOFF |
mbed_official 35:a8484e16c2f3 108 USB_FUNCTION_DBLBOFF |
mbed_official 35:a8484e16c2f3 109 USB_FUNCTION_CNTMDON |
mbed_official 35:a8484e16c2f3 110 USB_FUNCTION_SHTNAKOFF |
mbed_official 35:a8484e16c2f3 111 USB_FUNCTION_DIR_P_IN |
mbed_official 35:a8484e16c2f3 112 USB_FUNCTION_EP2,
mbed_official 35:a8484e16c2f3 113 ( ( (2048) / 64 - 1 ) << 10 ) | 0x50u,
mbed_official 40:3b1c43ac045c 114 MAX_PACKET_SIZE_EP2,
mbed_official 40:3b1c43ac045c 115 DEVDRV_USBF_OFF |
mbed_official 40:3b1c43ac045c 116 ( 0 << USB_PIPEPERI_IITV_SHIFT ),
mbed_official 35:a8484e16c2f3 117 },
mbed_official 35:a8484e16c2f3 118 {
mbed_official 35:a8484e16c2f3 119 EP3OUT, /*EP3: Host -> Func, ISO*/
mbed_official 35:a8484e16c2f3 120 1 | USB_FUNCTION_D0FIFO_USE,
mbed_official 35:a8484e16c2f3 121 USB_FUNCTION_ISO |
mbed_official 35:a8484e16c2f3 122 USB_FUNCTION_BFREOFF |
mbed_official 35:a8484e16c2f3 123 USB_FUNCTION_DBLBON |
mbed_official 40:3b1c43ac045c 124 USB_FUNCTION_CNTMDOFF |
mbed_official 35:a8484e16c2f3 125 USB_FUNCTION_SHTNAKON |
mbed_official 35:a8484e16c2f3 126 USB_FUNCTION_DIR_P_OUT |
mbed_official 35:a8484e16c2f3 127 USB_FUNCTION_EP3,
mbed_official 40:3b1c43ac045c 128 ( ( ( 512) / 64 - 1 ) << 10 ) | 0x10u,
mbed_official 40:3b1c43ac045c 129 MAX_PACKET_SIZE_EP3,
mbed_official 40:3b1c43ac045c 130 DEVDRV_USBF_OFF |
mbed_official 40:3b1c43ac045c 131 ( 0 << USB_PIPEPERI_IITV_SHIFT ),
mbed_official 35:a8484e16c2f3 132 },
mbed_official 35:a8484e16c2f3 133 {
mbed_official 35:a8484e16c2f3 134 EP3IN, /*EP3: Host <- Func, ISO*/
mbed_official 35:a8484e16c2f3 135 2 | USB_FUNCTION_D1FIFO_USE,
mbed_official 35:a8484e16c2f3 136 USB_FUNCTION_ISO |
mbed_official 35:a8484e16c2f3 137 USB_FUNCTION_BFREOFF |
mbed_official 35:a8484e16c2f3 138 USB_FUNCTION_DBLBON |
mbed_official 40:3b1c43ac045c 139 USB_FUNCTION_CNTMDOFF |
mbed_official 35:a8484e16c2f3 140 USB_FUNCTION_SHTNAKOFF |
mbed_official 35:a8484e16c2f3 141 USB_FUNCTION_DIR_P_IN |
mbed_official 35:a8484e16c2f3 142 USB_FUNCTION_EP3,
mbed_official 40:3b1c43ac045c 143 ( ( ( 512) / 64 - 1 ) << 10 ) | 0x20u,
mbed_official 40:3b1c43ac045c 144 MAX_PACKET_SIZE_EP3,
mbed_official 40:3b1c43ac045c 145 DEVDRV_USBF_OFF |
mbed_official 40:3b1c43ac045c 146 ( 0 << USB_PIPEPERI_IITV_SHIFT ),
mbed_official 35:a8484e16c2f3 147 },
mbed_official 35:a8484e16c2f3 148 { /*terminator*/
mbed_official 35:a8484e16c2f3 149 0, 0, 0, 0, 0,
mbed_official 35:a8484e16c2f3 150 },
mbed_official 35:a8484e16c2f3 151 };
mbed_official 35:a8484e16c2f3 152
mbed_official 35:a8484e16c2f3 153
mbed_official 35:a8484e16c2f3 154 /*************************************************************************/
mbed_official 35:a8484e16c2f3 155 /* workareas */
mbed_official 35:a8484e16c2f3 156 USBHAL * USBHAL::instance;
mbed_official 35:a8484e16c2f3 157
mbed_official 35:a8484e16c2f3 158 static IRQn_Type int_id; /* interrupt ID */
mbed_official 35:a8484e16c2f3 159 static uint16_t int_level; /* initerrupt level */
mbed_official 35:a8484e16c2f3 160 static uint16_t clock_mode; /* input clock selector */
mbed_official 35:a8484e16c2f3 161 static uint16_t mode; /* USB speed (HIGH/FULL) */
mbed_official 35:a8484e16c2f3 162
mbed_official 46:378357d7e90d 163 //static DigitalOut *usbx_en;
mbed_official 35:a8484e16c2f3 164
mbed_official 35:a8484e16c2f3 165 static uint16_t EP0_read_status;
mbed_official 35:a8484e16c2f3 166 static uint16_t EPx_read_status;
mbed_official 35:a8484e16c2f3 167
mbed_official 35:a8484e16c2f3 168 static uint16_t setup_buffer[MAX_PACKET_SIZE_EP0 / 2];
mbed_official 35:a8484e16c2f3 169
mbed_official 35:a8484e16c2f3 170 /* 0: not used / other: a pipe number to use recv_buffer*/
mbed_official 35:a8484e16c2f3 171 static uint8_t recv_buffer[MAX_PACKET_SIZE_EPBULK];
mbed_official 35:a8484e16c2f3 172 volatile static uint16_t recv_error;
mbed_official 35:a8484e16c2f3 173
mbed_official 35:a8484e16c2f3 174
mbed_official 35:a8484e16c2f3 175 /*************************************************************************/
mbed_official 35:a8484e16c2f3 176 /* prototypes for C */
mbed_official 40:3b1c43ac045c 177 extern "C" {
mbed_official 46:378357d7e90d 178 void usbx_function_BRDYInterruptPIPE0 (uint16_t status, uint16_t intenb,
mbed_official 40:3b1c43ac045c 179 USBHAL *object, void (USBHAL::*EP0func)(void));
mbed_official 35:a8484e16c2f3 180
mbed_official 46:378357d7e90d 181 void usbx_function_BRDYInterrupt (uint16_t status, uint16_t intenb,
mbed_official 40:3b1c43ac045c 182 USBHAL *object, bool (USBHAL::*epCallback[])(void));
mbed_official 40:3b1c43ac045c 183
mbed_official 46:378357d7e90d 184 void usbx_function_NRDYInterruptPIPE0(uint16_t status, uint16_t intenb,
mbed_official 40:3b1c43ac045c 185 USBHAL *object, void (USBHAL::*EP0func)(void));
mbed_official 40:3b1c43ac045c 186
mbed_official 46:378357d7e90d 187 void usbx_function_NRDYInterrupt (uint16_t status, uint16_t intenb,
mbed_official 40:3b1c43ac045c 188 USBHAL *object, bool (USBHAL::*epCallback[])(void));
mbed_official 40:3b1c43ac045c 189
mbed_official 46:378357d7e90d 190 void usbx_function_BEMPInterruptPIPE0(uint16_t status, uint16_t intenb,
mbed_official 40:3b1c43ac045c 191 USBHAL *object, void (USBHAL::*EP0func)(void));
mbed_official 40:3b1c43ac045c 192
mbed_official 46:378357d7e90d 193 void usbx_function_BEMPInterrupt (uint16_t status, uint16_t intenb,
mbed_official 40:3b1c43ac045c 194 USBHAL *object, bool (USBHAL::*epCallback[])(void));
mbed_official 40:3b1c43ac045c 195 }
mbed_official 40:3b1c43ac045c 196
mbed_official 35:a8484e16c2f3 197
mbed_official 35:a8484e16c2f3 198 /*************************************************************************/
mbed_official 35:a8484e16c2f3 199 /* macros */
mbed_official 35:a8484e16c2f3 200
mbed_official 35:a8484e16c2f3 201 /******************************************************************************
mbed_official 46:378357d7e90d 202 * Function Name: usbx_function_BRDYInterruptPIPE0
mbed_official 35:a8484e16c2f3 203 * Description : Executes BRDY interrupt for pipe0.
mbed_official 35:a8484e16c2f3 204 * Arguments : uint16_t status ; BRDYSTS Register Value
mbed_official 35:a8484e16c2f3 205 * : uint16_t intenb ; BRDYENB Register Value
mbed_official 35:a8484e16c2f3 206 * Return Value : none
mbed_official 35:a8484e16c2f3 207 *****************************************************************************/
mbed_official 40:3b1c43ac045c 208 extern "C" {
mbed_official 46:378357d7e90d 209 void usbx_function_BRDYInterruptPIPE0 (
mbed_official 40:3b1c43ac045c 210 uint16_t status,
mbed_official 40:3b1c43ac045c 211 uint16_t intenb,
mbed_official 40:3b1c43ac045c 212 USBHAL *object,
mbed_official 40:3b1c43ac045c 213 void (USBHAL::*EP0func)(void)
mbed_official 40:3b1c43ac045c 214 )
mbed_official 40:3b1c43ac045c 215 {
mbed_official 40:3b1c43ac045c 216 volatile uint16_t dumy_sts;
mbed_official 40:3b1c43ac045c 217 uint16_t read_status;
mbed_official 40:3b1c43ac045c 218
mbed_official 46:378357d7e90d 219 USB20X.BRDYSTS =
mbed_official 46:378357d7e90d 220 (uint16_t)~g_usbx_function_bit_set[USB_FUNCTION_PIPE0];
mbed_official 40:3b1c43ac045c 221 RZA_IO_RegWrite_16(
mbed_official 46:378357d7e90d 222 &USB20X.CFIFOSEL, USB_FUNCTION_PIPE0,
mbed_official 40:3b1c43ac045c 223 USB_CFIFOSEL_CURPIPE_SHIFT, USB_CFIFOSEL_CURPIPE);
mbed_official 40:3b1c43ac045c 224
mbed_official 46:378357d7e90d 225 g_usbx_function_PipeDataSize[USB_FUNCTION_PIPE0] =
mbed_official 46:378357d7e90d 226 g_usbx_function_data_count[USB_FUNCTION_PIPE0];
mbed_official 40:3b1c43ac045c 227
mbed_official 46:378357d7e90d 228 read_status = usbx_function_read_buffer_c(USB_FUNCTION_PIPE0);
mbed_official 40:3b1c43ac045c 229
mbed_official 46:378357d7e90d 230 g_usbx_function_PipeDataSize[USB_FUNCTION_PIPE0] -=
mbed_official 46:378357d7e90d 231 g_usbx_function_data_count[USB_FUNCTION_PIPE0];
mbed_official 40:3b1c43ac045c 232
mbed_official 40:3b1c43ac045c 233 switch (read_status) {
mbed_official 40:3b1c43ac045c 234 case USB_FUNCTION_READING: /* Continue of data read */
mbed_official 40:3b1c43ac045c 235 case USB_FUNCTION_READEND: /* End of data read */
mbed_official 40:3b1c43ac045c 236 /* PID = BUF */
mbed_official 46:378357d7e90d 237 usbx_function_set_pid_buf(USB_FUNCTION_PIPE0);
mbed_official 40:3b1c43ac045c 238
mbed_official 40:3b1c43ac045c 239 /*callback*/
mbed_official 40:3b1c43ac045c 240 (object->*EP0func)();
mbed_official 40:3b1c43ac045c 241 break;
mbed_official 40:3b1c43ac045c 242
mbed_official 40:3b1c43ac045c 243 case USB_FUNCTION_READSHRT: /* End of data read */
mbed_official 46:378357d7e90d 244 usbx_function_disable_brdy_int(USB_FUNCTION_PIPE0);
mbed_official 40:3b1c43ac045c 245 /* PID = BUF */
mbed_official 46:378357d7e90d 246 usbx_function_set_pid_buf(USB_FUNCTION_PIPE0);
mbed_official 40:3b1c43ac045c 247
mbed_official 40:3b1c43ac045c 248 /*callback*/
mbed_official 40:3b1c43ac045c 249 (object->*EP0func)();
mbed_official 40:3b1c43ac045c 250 break;
mbed_official 40:3b1c43ac045c 251
mbed_official 40:3b1c43ac045c 252 case USB_FUNCTION_READOVER: /* FIFO access error */
mbed_official 40:3b1c43ac045c 253 /* Buffer Clear */
mbed_official 46:378357d7e90d 254 USB20X.CFIFOCTR = USB_FUNCTION_BITBCLR;
mbed_official 46:378357d7e90d 255 usbx_function_disable_brdy_int(USB_FUNCTION_PIPE0);
mbed_official 40:3b1c43ac045c 256 /* Req Error */
mbed_official 46:378357d7e90d 257 usbx_function_set_pid_stall(USB_FUNCTION_PIPE0);
mbed_official 40:3b1c43ac045c 258
mbed_official 40:3b1c43ac045c 259 /*callback*/
mbed_official 40:3b1c43ac045c 260 (object->*EP0func)();
mbed_official 40:3b1c43ac045c 261 break;
mbed_official 40:3b1c43ac045c 262
mbed_official 40:3b1c43ac045c 263 case DEVDRV_USBF_FIFOERROR: /* FIFO access error */
mbed_official 40:3b1c43ac045c 264 default:
mbed_official 46:378357d7e90d 265 usbx_function_disable_brdy_int(USB_FUNCTION_PIPE0);
mbed_official 40:3b1c43ac045c 266 /* Req Error */
mbed_official 46:378357d7e90d 267 usbx_function_set_pid_stall(USB_FUNCTION_PIPE0);
mbed_official 40:3b1c43ac045c 268 break;
mbed_official 40:3b1c43ac045c 269 }
mbed_official 40:3b1c43ac045c 270 /* Three dummy reads for clearing interrupt requests */
mbed_official 46:378357d7e90d 271 dumy_sts = USB20X.BRDYSTS;
mbed_official 35:a8484e16c2f3 272 }
mbed_official 40:3b1c43ac045c 273 }
mbed_official 35:a8484e16c2f3 274
mbed_official 35:a8484e16c2f3 275
mbed_official 35:a8484e16c2f3 276 /******************************************************************************
mbed_official 46:378357d7e90d 277 * Function Name: usbx_function_BRDYInterrupt
mbed_official 35:a8484e16c2f3 278 * Description : Executes BRDY interrupt uxclude pipe0.
mbed_official 35:a8484e16c2f3 279 * Arguments : uint16_t status ; BRDYSTS Register Value
mbed_official 35:a8484e16c2f3 280 * : uint16_t intenb ; BRDYENB Register Value
mbed_official 35:a8484e16c2f3 281 * Return Value : none
mbed_official 35:a8484e16c2f3 282 *****************************************************************************/
mbed_official 40:3b1c43ac045c 283 extern "C" {
mbed_official 46:378357d7e90d 284 void usbx_function_BRDYInterrupt(
mbed_official 40:3b1c43ac045c 285 uint16_t status,
mbed_official 40:3b1c43ac045c 286 uint16_t intenb,
mbed_official 40:3b1c43ac045c 287 USBHAL *object,
mbed_official 40:3b1c43ac045c 288 bool (USBHAL::*epCallback[])(void)
mbed_official 40:3b1c43ac045c 289 )
mbed_official 40:3b1c43ac045c 290 {
mbed_official 40:3b1c43ac045c 291 volatile uint16_t dumy_sts;
mbed_official 40:3b1c43ac045c 292
mbed_official 40:3b1c43ac045c 293 /**************************************************************
mbed_official 46:378357d7e90d 294 * Function Name: usbx_function_brdy_int
mbed_official 40:3b1c43ac045c 295 * Description : Executes BRDY interrupt(USB_FUNCTION_PIPE1-9).
mbed_official 40:3b1c43ac045c 296 * : According to the pipe that interrupt is generated in,
mbed_official 40:3b1c43ac045c 297 * : reads/writes buffer allocated in the pipe.
mbed_official 40:3b1c43ac045c 298 * : This function is executed in the BRDY
mbed_official 40:3b1c43ac045c 299 * : interrupt handler. This function
mbed_official 40:3b1c43ac045c 300 * : clears BRDY interrupt status and BEMP
mbed_official 40:3b1c43ac045c 301 * : interrupt status.
mbed_official 40:3b1c43ac045c 302 * Arguments : uint16_t Status ; BRDYSTS Register Value
mbed_official 40:3b1c43ac045c 303 * : uint16_t Int_enbl ; BRDYENB Register Value
mbed_official 40:3b1c43ac045c 304 * Return Value : none
mbed_official 40:3b1c43ac045c 305 *************************************************************/
mbed_official 46:378357d7e90d 306 /* copied from usbx_function_intrn.c */
mbed_official 40:3b1c43ac045c 307 uint32_t int_sense = 0;
mbed_official 40:3b1c43ac045c 308 uint16_t pipe;
mbed_official 40:3b1c43ac045c 309 uint16_t pipebit;
mbed_official 40:3b1c43ac045c 310 uint16_t ep;
mbed_official 40:3b1c43ac045c 311
mbed_official 40:3b1c43ac045c 312 for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++) {
mbed_official 46:378357d7e90d 313 pipebit = g_usbx_function_bit_set[pipe];
mbed_official 40:3b1c43ac045c 314
mbed_official 40:3b1c43ac045c 315 if ((status & pipebit) && (intenb & pipebit)) {
mbed_official 46:378357d7e90d 316 USB20X.BRDYSTS = (uint16_t)~pipebit;
mbed_official 46:378357d7e90d 317 USB20X.BEMPSTS = (uint16_t)~pipebit;
mbed_official 40:3b1c43ac045c 318
mbed_official 46:378357d7e90d 319 switch (g_usbx_function_PipeTbl[pipe] & USB_FUNCTION_FIFO_USE) {
mbed_official 40:3b1c43ac045c 320 case USB_FUNCTION_D0FIFO_DMA:
mbed_official 46:378357d7e90d 321 if (g_usbx_function_DmaStatus[USB_FUNCTION_D0FIFO] != USB_FUNCTION_DMA_READY) {
mbed_official 40:3b1c43ac045c 322 /*now, DMA is not supported*/
mbed_official 46:378357d7e90d 323 usbx_function_dma_interrupt_d0fifo(int_sense);
mbed_official 40:3b1c43ac045c 324 }
mbed_official 40:3b1c43ac045c 325
mbed_official 40:3b1c43ac045c 326 if (RZA_IO_RegRead_16(
mbed_official 46:378357d7e90d 327 &g_usbx_function_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0) {
mbed_official 40:3b1c43ac045c 328 /*now, DMA is not supported*/
mbed_official 46:378357d7e90d 329 usbx_function_read_dma(pipe);
mbed_official 46:378357d7e90d 330 usbx_function_disable_brdy_int(pipe);
mbed_official 40:3b1c43ac045c 331 } else {
mbed_official 46:378357d7e90d 332 USB20X.D0FIFOCTR = USB_FUNCTION_BITBCLR;
mbed_official 46:378357d7e90d 333 g_usbx_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
mbed_official 40:3b1c43ac045c 334 }
mbed_official 40:3b1c43ac045c 335 break;
mbed_official 40:3b1c43ac045c 336
mbed_official 40:3b1c43ac045c 337 case USB_FUNCTION_D1FIFO_DMA:
mbed_official 46:378357d7e90d 338 if (g_usbx_function_DmaStatus[USB_FUNCTION_D1FIFO] != USB_FUNCTION_DMA_READY) {
mbed_official 40:3b1c43ac045c 339 /*now, DMA is not supported*/
mbed_official 46:378357d7e90d 340 usbx_function_dma_interrupt_d1fifo(int_sense);
mbed_official 40:3b1c43ac045c 341 }
mbed_official 40:3b1c43ac045c 342
mbed_official 40:3b1c43ac045c 343 if (RZA_IO_RegRead_16(
mbed_official 46:378357d7e90d 344 &g_usbx_function_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0) {
mbed_official 40:3b1c43ac045c 345 /*now, DMA is not supported*/
mbed_official 46:378357d7e90d 346 usbx_function_read_dma(pipe);
mbed_official 46:378357d7e90d 347 usbx_function_disable_brdy_int(pipe);
mbed_official 40:3b1c43ac045c 348 } else {
mbed_official 46:378357d7e90d 349 USB20X.D1FIFOCTR = USB_FUNCTION_BITBCLR;
mbed_official 46:378357d7e90d 350 g_usbx_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
mbed_official 40:3b1c43ac045c 351 }
mbed_official 40:3b1c43ac045c 352 break;
mbed_official 40:3b1c43ac045c 353
mbed_official 40:3b1c43ac045c 354 default:
mbed_official 46:378357d7e90d 355 ep = (g_usbx_function_pipecfg[pipe] & USB_PIPECFG_EPNUM) >> USB_PIPECFG_EPNUM_SHIFT;
mbed_official 40:3b1c43ac045c 356 ep <<= 1;
mbed_official 40:3b1c43ac045c 357 if (RZA_IO_RegRead_16(
mbed_official 46:378357d7e90d 358 &g_usbx_function_pipecfg[pipe], USB_PIPECFG_DIR_SHIFT, USB_PIPECFG_DIR) == 0) {
mbed_official 40:3b1c43ac045c 359 /* read */
mbed_official 40:3b1c43ac045c 360 EPx_read_status = DEVDRV_USBF_PIPE_WAIT;
mbed_official 40:3b1c43ac045c 361 (object->*(epCallback[ep - 2])) ();
mbed_official 40:3b1c43ac045c 362 EPx_read_status = DEVDRV_USBF_PIPE_DONE;
mbed_official 40:3b1c43ac045c 363 } else {
mbed_official 40:3b1c43ac045c 364 /* write */
mbed_official 40:3b1c43ac045c 365 EPx_read_status = DEVDRV_USBF_PIPE_WAIT;
mbed_official 40:3b1c43ac045c 366 (object->*(epCallback[ep - 2 + 1])) ();
mbed_official 40:3b1c43ac045c 367 EPx_read_status = DEVDRV_USBF_PIPE_DONE;
mbed_official 46:378357d7e90d 368 usbx_function_write_buffer(pipe);
mbed_official 40:3b1c43ac045c 369 }
mbed_official 40:3b1c43ac045c 370 }
mbed_official 40:3b1c43ac045c 371 }
mbed_official 40:3b1c43ac045c 372 }
mbed_official 40:3b1c43ac045c 373 /* Three dummy reads for clearing interrupt requests */
mbed_official 46:378357d7e90d 374 dumy_sts = USB20X.BRDYSTS;
mbed_official 35:a8484e16c2f3 375 }
mbed_official 40:3b1c43ac045c 376 }
mbed_official 35:a8484e16c2f3 377
mbed_official 35:a8484e16c2f3 378
mbed_official 35:a8484e16c2f3 379 /******************************************************************************
mbed_official 46:378357d7e90d 380 * Function Name: usbx_function_NRDYInterruptPIPE0
mbed_official 35:a8484e16c2f3 381 * Description : Executes NRDY interrupt for pipe0.
mbed_official 35:a8484e16c2f3 382 * Arguments : uint16_t status ; NRDYSTS Register Value
mbed_official 35:a8484e16c2f3 383 * : uint16_t intenb ; NRDYENB Register Value
mbed_official 35:a8484e16c2f3 384 * Return Value : none
mbed_official 35:a8484e16c2f3 385 *****************************************************************************/
mbed_official 40:3b1c43ac045c 386 extern "C" {
mbed_official 46:378357d7e90d 387 void usbx_function_NRDYInterruptPIPE0(
mbed_official 40:3b1c43ac045c 388 uint16_t status,
mbed_official 40:3b1c43ac045c 389 uint16_t intenb,
mbed_official 40:3b1c43ac045c 390 USBHAL *object,
mbed_official 40:3b1c43ac045c 391 void (USBHAL::*EP0func)(void)
mbed_official 40:3b1c43ac045c 392 )
mbed_official 40:3b1c43ac045c 393 {
mbed_official 40:3b1c43ac045c 394 volatile uint16_t dumy_sts;
mbed_official 40:3b1c43ac045c 395
mbed_official 46:378357d7e90d 396 USB20X.NRDYSTS =
mbed_official 46:378357d7e90d 397 (uint16_t)~g_usbx_function_bit_set[USB_FUNCTION_PIPE0];
mbed_official 40:3b1c43ac045c 398
mbed_official 40:3b1c43ac045c 399 /* Three dummy reads for clearing interrupt requests */
mbed_official 46:378357d7e90d 400 dumy_sts = USB20X.NRDYSTS;
mbed_official 35:a8484e16c2f3 401 }
mbed_official 40:3b1c43ac045c 402 }
mbed_official 40:3b1c43ac045c 403
mbed_official 35:a8484e16c2f3 404
mbed_official 35:a8484e16c2f3 405 /******************************************************************************
mbed_official 46:378357d7e90d 406 * Function Name: usbx_function_NRDYInterrupt
mbed_official 35:a8484e16c2f3 407 * Description : Executes NRDY interrupt exclude pipe0.
mbed_official 35:a8484e16c2f3 408 * Arguments : uint16_t status ; NRDYSTS Register Value
mbed_official 35:a8484e16c2f3 409 * : uint16_t intenb ; NRDYENB Register Value
mbed_official 35:a8484e16c2f3 410 * Return Value : none
mbed_official 35:a8484e16c2f3 411 *****************************************************************************/
mbed_official 40:3b1c43ac045c 412 extern "C" {
mbed_official 46:378357d7e90d 413 void usbx_function_NRDYInterrupt(
mbed_official 40:3b1c43ac045c 414 uint16_t status,
mbed_official 40:3b1c43ac045c 415 uint16_t intenb,
mbed_official 40:3b1c43ac045c 416 USBHAL *object,
mbed_official 40:3b1c43ac045c 417 bool (USBHAL::*epCallback[])(void)
mbed_official 40:3b1c43ac045c 418 )
mbed_official 40:3b1c43ac045c 419 {
mbed_official 40:3b1c43ac045c 420 volatile uint16_t dumy_sts;
mbed_official 40:3b1c43ac045c 421
mbed_official 40:3b1c43ac045c 422 /**************************************************************
mbed_official 46:378357d7e90d 423 * Function Name: usbx_function_nrdy_int
mbed_official 40:3b1c43ac045c 424 * Description : Executes NRDY interrupt(USB_FUNCTION_PIPE1-9).
mbed_official 40:3b1c43ac045c 425 * : Checks NRDY interrupt cause by PID. When the cause if STALL,
mbed_official 40:3b1c43ac045c 426 * : regards the pipe state as STALL and ends the processing.
mbed_official 40:3b1c43ac045c 427 * : Then the cause is not STALL, increments the error count to
mbed_official 40:3b1c43ac045c 428 * : communicate again. When the error count is 3, determines
mbed_official 40:3b1c43ac045c 429 * : the pipe state as DEVDRV_USBF_PIPE_NORES and ends the processing.
mbed_official 40:3b1c43ac045c 430 * : This function is executed in the NRDY interrupt handler.
mbed_official 40:3b1c43ac045c 431 * : This function clears NRDY interrupt status.
mbed_official 40:3b1c43ac045c 432 * Arguments : uint16_t status ; NRDYSTS Register Value
mbed_official 40:3b1c43ac045c 433 * : uint16_t int_enb ; NRDYENB Register Value
mbed_official 40:3b1c43ac045c 434 * Return Value : none
mbed_official 40:3b1c43ac045c 435 *************************************************************/
mbed_official 46:378357d7e90d 436 /* copied from usbx_function_intrn.c */
mbed_official 40:3b1c43ac045c 437 #if 0
mbed_official 40:3b1c43ac045c 438 uint16_t usefifo;
mbed_official 40:3b1c43ac045c 439 #endif
mbed_official 40:3b1c43ac045c 440 uint16_t pid;
mbed_official 40:3b1c43ac045c 441 uint16_t pipe;
mbed_official 40:3b1c43ac045c 442 uint16_t bitcheck;
mbed_official 40:3b1c43ac045c 443 #if 0
mbed_official 40:3b1c43ac045c 444 uint16_t mbw;
mbed_official 40:3b1c43ac045c 445 uint32_t size;
mbed_official 40:3b1c43ac045c 446 #endif
mbed_official 40:3b1c43ac045c 447 uint16_t ep;
mbed_official 40:3b1c43ac045c 448
mbed_official 40:3b1c43ac045c 449 bitcheck = (uint16_t)(status & intenb);
mbed_official 40:3b1c43ac045c 450
mbed_official 46:378357d7e90d 451 USB20X.NRDYSTS = (uint16_t)~status;
mbed_official 40:3b1c43ac045c 452
mbed_official 40:3b1c43ac045c 453
mbed_official 46:378357d7e90d 454 if (RZA_IO_RegRead_16(&USB20X.SYSCFG0, USB_SYSCFG_DCFM_SHIFT, USB_SYSCFG_DCFM) == 1) {
mbed_official 40:3b1c43ac045c 455 /* USB HOST */
mbed_official 40:3b1c43ac045c 456 /* not support */
mbed_official 40:3b1c43ac045c 457
mbed_official 40:3b1c43ac045c 458 } else {
mbed_official 40:3b1c43ac045c 459 /* USB Function */
mbed_official 40:3b1c43ac045c 460 for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++) {
mbed_official 46:378357d7e90d 461 if ((bitcheck&g_usbx_function_bit_set[pipe]) != g_usbx_function_bit_set[pipe]) {
mbed_official 40:3b1c43ac045c 462 continue;
mbed_official 40:3b1c43ac045c 463 }
mbed_official 40:3b1c43ac045c 464
mbed_official 46:378357d7e90d 465 if (g_usbx_function_pipe_status[pipe] != DEVDRV_USBF_PIPE_WAIT) {
mbed_official 40:3b1c43ac045c 466 continue;
mbed_official 40:3b1c43ac045c 467 }
mbed_official 40:3b1c43ac045c 468
mbed_official 40:3b1c43ac045c 469 #if 0
mbed_official 46:378357d7e90d 470 usbx_function_set_pid_nak(pipe);
mbed_official 40:3b1c43ac045c 471
mbed_official 46:378357d7e90d 472 size = (uint32_t)g_usbx_function_data_count[pipe];
mbed_official 46:378357d7e90d 473 mbw = usbx_function_get_mbw(
mbed_official 46:378357d7e90d 474 size, (uint32_t)g_usbx_function_data_pointer[pipe]);
mbed_official 40:3b1c43ac045c 475
mbed_official 46:378357d7e90d 476 usefifo = (uint16_t)(g_usbx_function_PipeTbl[pipe] & USB_FUNCTION_FIFO_USE);
mbed_official 40:3b1c43ac045c 477 switch (usefifo) {
mbed_official 40:3b1c43ac045c 478
mbed_official 40:3b1c43ac045c 479 case USB_FUNCTION_D0FIFO_USE:
mbed_official 46:378357d7e90d 480 usbx_function_set_curpipe(
mbed_official 40:3b1c43ac045c 481 pipe, USB_FUNCTION_D0USE, DEVDRV_USBF_NO, mbw);
mbed_official 46:378357d7e90d 482 USB20X.D0FIFOCTR = USB_FUNCTION_BITBCLR;
mbed_official 40:3b1c43ac045c 483 break;
mbed_official 40:3b1c43ac045c 484
mbed_official 40:3b1c43ac045c 485 case USB_FUNCTION_D1FIFO_USE:
mbed_official 46:378357d7e90d 486 usbx_function_set_curpipe(
mbed_official 40:3b1c43ac045c 487 pipe, USB_FUNCTION_D1USE, DEVDRV_USBF_NO, mbw);
mbed_official 46:378357d7e90d 488 USB20X.D1FIFOCTR = USB_FUNCTION_BITBCLR;
mbed_official 40:3b1c43ac045c 489 break;
mbed_official 40:3b1c43ac045c 490
mbed_official 40:3b1c43ac045c 491 default:
mbed_official 46:378357d7e90d 492 usbx_function_set_curpipe(
mbed_official 40:3b1c43ac045c 493 pipe, USB_FUNCTION_CUSE, USB_FUNCTION_CFIFO_READ, mbw);
mbed_official 46:378357d7e90d 494 USB20X.CFIFOCTR = USB_FUNCTION_BITBCLR;
mbed_official 40:3b1c43ac045c 495 break;
mbed_official 40:3b1c43ac045c 496 }
mbed_official 40:3b1c43ac045c 497
mbed_official 46:378357d7e90d 498 usbx_function_aclrm(pipe);
mbed_official 40:3b1c43ac045c 499
mbed_official 46:378357d7e90d 500 usbx_function_enable_nrdy_int(pipe);
mbed_official 46:378357d7e90d 501 usbx_function_enable_brdy_int(pipe);
mbed_official 40:3b1c43ac045c 502
mbed_official 46:378357d7e90d 503 usbx_function_set_pid_buf(pipe);
mbed_official 40:3b1c43ac045c 504 #endif
mbed_official 40:3b1c43ac045c 505
mbed_official 46:378357d7e90d 506 pid = usbx_function_get_pid(pipe);
mbed_official 40:3b1c43ac045c 507 if ((pid == DEVDRV_USBF_PID_STALL) || (pid == DEVDRV_USBF_PID_STALL2)) {
mbed_official 46:378357d7e90d 508 g_usbx_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_STALL;
mbed_official 40:3b1c43ac045c 509 } else {
mbed_official 46:378357d7e90d 510 usbx_function_set_pid_buf(pipe);
mbed_official 40:3b1c43ac045c 511 }
mbed_official 40:3b1c43ac045c 512
mbed_official 46:378357d7e90d 513 ep = (g_usbx_function_pipecfg[pipe] & USB_PIPECFG_EPNUM) >> USB_PIPECFG_EPNUM_SHIFT;
mbed_official 40:3b1c43ac045c 514 ep <<= 1;
mbed_official 40:3b1c43ac045c 515 if (RZA_IO_RegRead_16(
mbed_official 46:378357d7e90d 516 &g_usbx_function_pipecfg[pipe], USB_PIPECFG_DIR_SHIFT, USB_PIPECFG_DIR) == 0) {
mbed_official 40:3b1c43ac045c 517 /* read */
mbed_official 42:4f589e246b9e 518 __NOP();
mbed_official 40:3b1c43ac045c 519 } else {
mbed_official 40:3b1c43ac045c 520 /* write */
mbed_official 42:4f589e246b9e 521 __NOP();
mbed_official 40:3b1c43ac045c 522 }
mbed_official 40:3b1c43ac045c 523 }
mbed_official 40:3b1c43ac045c 524 }
mbed_official 40:3b1c43ac045c 525
mbed_official 40:3b1c43ac045c 526 /* Three dummy reads for clearing interrupt requests */
mbed_official 46:378357d7e90d 527 dumy_sts = USB20X.NRDYSTS;
mbed_official 35:a8484e16c2f3 528 }
mbed_official 40:3b1c43ac045c 529 }
mbed_official 35:a8484e16c2f3 530
mbed_official 35:a8484e16c2f3 531 /******************************************************************************
mbed_official 46:378357d7e90d 532 * Function Name: usbx_function_BEMPInterruptPIPE0
mbed_official 35:a8484e16c2f3 533 * Description : Executes BEMP interrupt for pipe0.
mbed_official 35:a8484e16c2f3 534 * Arguments : uint16_t status ; BEMPSTS Register Value
mbed_official 35:a8484e16c2f3 535 * : uint16_t intenb ; BEMPENB Register Value
mbed_official 35:a8484e16c2f3 536 * Return Value : none
mbed_official 35:a8484e16c2f3 537 *****************************************************************************/
mbed_official 40:3b1c43ac045c 538 extern "C" {
mbed_official 46:378357d7e90d 539 void usbx_function_BEMPInterruptPIPE0(
mbed_official 40:3b1c43ac045c 540 uint16_t status,
mbed_official 40:3b1c43ac045c 541 uint16_t intenb,
mbed_official 40:3b1c43ac045c 542 USBHAL *object,
mbed_official 40:3b1c43ac045c 543 void (USBHAL::*EP0func)(void)
mbed_official 40:3b1c43ac045c 544 )
mbed_official 40:3b1c43ac045c 545 {
mbed_official 40:3b1c43ac045c 546 volatile uint16_t dumy_sts;
mbed_official 40:3b1c43ac045c 547
mbed_official 46:378357d7e90d 548 USB20X.BEMPSTS =
mbed_official 46:378357d7e90d 549 (uint16_t)~g_usbx_function_bit_set[USB_FUNCTION_PIPE0];
mbed_official 40:3b1c43ac045c 550 RZA_IO_RegWrite_16(
mbed_official 46:378357d7e90d 551 &USB20X.CFIFOSEL, USB_FUNCTION_PIPE0,
mbed_official 40:3b1c43ac045c 552 USB_CFIFOSEL_CURPIPE_SHIFT, USB_CFIFOSEL_CURPIPE);
mbed_official 40:3b1c43ac045c 553
mbed_official 46:378357d7e90d 554 /*usbx_function_write_buffer_c(USB_FUNCTION_PIPE0);*/
mbed_official 40:3b1c43ac045c 555 (object->*EP0func)();
mbed_official 40:3b1c43ac045c 556
mbed_official 40:3b1c43ac045c 557 /* Three dummy reads for clearing interrupt requests */
mbed_official 46:378357d7e90d 558 dumy_sts = USB20X.BEMPSTS;
mbed_official 35:a8484e16c2f3 559 }
mbed_official 40:3b1c43ac045c 560 }
mbed_official 35:a8484e16c2f3 561
mbed_official 35:a8484e16c2f3 562
mbed_official 35:a8484e16c2f3 563 /******************************************************************************
mbed_official 46:378357d7e90d 564 * Function Name: usbx_function_BEMPInterrupt
mbed_official 35:a8484e16c2f3 565 * Description : Executes BEMP interrupt exclude pipe0.
mbed_official 35:a8484e16c2f3 566 * Arguments : uint16_t status ; BEMPSTS Register Value
mbed_official 35:a8484e16c2f3 567 * : uint16_t intenb ; BEMPENB Register Value
mbed_official 35:a8484e16c2f3 568 * Return Value : none
mbed_official 35:a8484e16c2f3 569 *****************************************************************************/
mbed_official 40:3b1c43ac045c 570 extern "C" {
mbed_official 46:378357d7e90d 571 void usbx_function_BEMPInterrupt(
mbed_official 40:3b1c43ac045c 572 uint16_t status,
mbed_official 40:3b1c43ac045c 573 uint16_t intenb,
mbed_official 40:3b1c43ac045c 574 USBHAL *object,
mbed_official 40:3b1c43ac045c 575 bool (USBHAL::*epCallback[])(void)
mbed_official 40:3b1c43ac045c 576 )
mbed_official 40:3b1c43ac045c 577 {
mbed_official 40:3b1c43ac045c 578 volatile uint16_t dumy_sts;
mbed_official 40:3b1c43ac045c 579
mbed_official 40:3b1c43ac045c 580 /**************************************************************
mbed_official 46:378357d7e90d 581 * Function Name: usbx_function_bemp_int
mbed_official 40:3b1c43ac045c 582 * Description : Executes BEMP interrupt(USB_FUNCTION_PIPE1-9).
mbed_official 40:3b1c43ac045c 583 * Arguments : uint16_t status ; BEMPSTS Register Value
mbed_official 40:3b1c43ac045c 584 * : uint16_t intenb ; BEMPENB Register Value
mbed_official 40:3b1c43ac045c 585 * Return Value : none
mbed_official 40:3b1c43ac045c 586 *************************************************************/
mbed_official 46:378357d7e90d 587 /* copied from usbx_function_intrn.c */
mbed_official 40:3b1c43ac045c 588 uint16_t pid;
mbed_official 40:3b1c43ac045c 589 uint16_t pipe;
mbed_official 40:3b1c43ac045c 590 uint16_t bitcheck;
mbed_official 40:3b1c43ac045c 591 uint16_t inbuf;
mbed_official 40:3b1c43ac045c 592 uint16_t ep;
mbed_official 40:3b1c43ac045c 593
mbed_official 40:3b1c43ac045c 594 bitcheck = (uint16_t)(status & intenb);
mbed_official 40:3b1c43ac045c 595
mbed_official 46:378357d7e90d 596 USB20X.BEMPSTS = (uint16_t)~status;
mbed_official 40:3b1c43ac045c 597
mbed_official 40:3b1c43ac045c 598 for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++) {
mbed_official 46:378357d7e90d 599 if ((bitcheck&g_usbx_function_bit_set[pipe]) != g_usbx_function_bit_set[pipe]) {
mbed_official 40:3b1c43ac045c 600 continue;
mbed_official 40:3b1c43ac045c 601 }
mbed_official 40:3b1c43ac045c 602
mbed_official 46:378357d7e90d 603 pid = usbx_function_get_pid(pipe);
mbed_official 40:3b1c43ac045c 604
mbed_official 40:3b1c43ac045c 605 if ((pid == DEVDRV_USBF_PID_STALL) ||
mbed_official 40:3b1c43ac045c 606 (pid == DEVDRV_USBF_PID_STALL2)) {
mbed_official 46:378357d7e90d 607 g_usbx_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_STALL;
mbed_official 40:3b1c43ac045c 608
mbed_official 40:3b1c43ac045c 609 } else {
mbed_official 46:378357d7e90d 610 inbuf = usbx_function_get_inbuf(pipe);
mbed_official 40:3b1c43ac045c 611
mbed_official 40:3b1c43ac045c 612 if (inbuf == 0) {
mbed_official 46:378357d7e90d 613 usbx_function_disable_bemp_int(pipe);
mbed_official 46:378357d7e90d 614 usbx_function_set_pid_nak(pipe);
mbed_official 46:378357d7e90d 615 g_usbx_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
mbed_official 40:3b1c43ac045c 616
mbed_official 46:378357d7e90d 617 switch (g_usbx_function_PipeTbl[pipe] & USB_FUNCTION_FIFO_USE) {
mbed_official 40:3b1c43ac045c 618 case USB_FUNCTION_D0FIFO_DMA:
mbed_official 40:3b1c43ac045c 619 /*now, DMA is not supported*/
mbed_official 40:3b1c43ac045c 620 break;
mbed_official 40:3b1c43ac045c 621
mbed_official 40:3b1c43ac045c 622 case USB_FUNCTION_D1FIFO_DMA:
mbed_official 40:3b1c43ac045c 623 /*now, DMA is not supported*/
mbed_official 40:3b1c43ac045c 624 break;
mbed_official 40:3b1c43ac045c 625
mbed_official 40:3b1c43ac045c 626 default:
mbed_official 46:378357d7e90d 627 ep = (g_usbx_function_pipecfg[pipe] & USB_PIPECFG_EPNUM) >> USB_PIPECFG_EPNUM_SHIFT;
mbed_official 40:3b1c43ac045c 628 ep <<= 1;
mbed_official 40:3b1c43ac045c 629 if (RZA_IO_RegRead_16(
mbed_official 46:378357d7e90d 630 &g_usbx_function_pipecfg[pipe], USB_PIPECFG_DIR_SHIFT, USB_PIPECFG_DIR) == 0) {
mbed_official 40:3b1c43ac045c 631 /* read */
mbed_official 42:4f589e246b9e 632 __NOP();
mbed_official 40:3b1c43ac045c 633 } else {
mbed_official 40:3b1c43ac045c 634 /* write */
mbed_official 40:3b1c43ac045c 635 EPx_read_status = DEVDRV_USBF_PIPE_WAIT;
mbed_official 40:3b1c43ac045c 636 (object->*(epCallback[ep - 2 + 1])) ();
mbed_official 40:3b1c43ac045c 637 EPx_read_status = DEVDRV_USBF_PIPE_DONE;
mbed_official 40:3b1c43ac045c 638 }
mbed_official 40:3b1c43ac045c 639 }
mbed_official 40:3b1c43ac045c 640 }
mbed_official 40:3b1c43ac045c 641 }
mbed_official 40:3b1c43ac045c 642 }
mbed_official 40:3b1c43ac045c 643
mbed_official 40:3b1c43ac045c 644 /* Three dummy reads for clearing interrupt requests */
mbed_official 46:378357d7e90d 645 dumy_sts = USB20X.BEMPSTS;
mbed_official 40:3b1c43ac045c 646 }
mbed_official 35:a8484e16c2f3 647 }
mbed_official 35:a8484e16c2f3 648
mbed_official 35:a8484e16c2f3 649 /******************************************************************************
mbed_official 35:a8484e16c2f3 650 * Function Name: EP2PIPE
mbed_official 35:a8484e16c2f3 651 * Description : Converts from endpoint to pipe
mbed_official 35:a8484e16c2f3 652 * Arguments : number of endpoint
mbed_official 35:a8484e16c2f3 653 * Return Value : number of pipe
mbed_official 35:a8484e16c2f3 654 *****************************************************************************/
mbed_official 35:a8484e16c2f3 655 /*EP2PIPE converter is for pipe1, pipe3 and pipe6 only.*/
mbed_official 46:378357d7e90d 656 #define EP2PIPE(endpoint) ((uint32_t)usbx_function_EpToPipe(endpoint))
mbed_official 35:a8484e16c2f3 657
mbed_official 35:a8484e16c2f3 658
mbed_official 35:a8484e16c2f3 659 /******************************************************************************
mbed_official 46:378357d7e90d 660 * Function Name: usbx_function_save_request
mbed_official 35:a8484e16c2f3 661 * Description : Retains the USB request information in variables.
mbed_official 35:a8484e16c2f3 662 * Arguments : none
mbed_official 35:a8484e16c2f3 663 * Return Value : none
mbed_official 35:a8484e16c2f3 664 *****************************************************************************/
mbed_official 46:378357d7e90d 665 #define usbx_function_save_request() \
mbed_official 35:a8484e16c2f3 666 { \
mbed_official 35:a8484e16c2f3 667 uint16_t *bufO = &setup_buffer[0]; \
mbed_official 35:a8484e16c2f3 668 \
mbed_official 46:378357d7e90d 669 USB20X.INTSTS0 = (uint16_t)~USB_FUNCTION_BITVALID; \
mbed_official 35:a8484e16c2f3 670 /*data[0] <= bmRequest, data[1] <= bmRequestType */ \
mbed_official 46:378357d7e90d 671 *bufO++ = USB20X.USBREQ; \
mbed_official 35:a8484e16c2f3 672 /*data[2] data[3] <= wValue*/ \
mbed_official 46:378357d7e90d 673 *bufO++ = USB20X.USBVAL; \
mbed_official 35:a8484e16c2f3 674 /*data[4] data[5] <= wIndex*/ \
mbed_official 46:378357d7e90d 675 *bufO++ = USB20X.USBINDX; \
mbed_official 35:a8484e16c2f3 676 /*data[6] data[6] <= wIndex*/ \
mbed_official 46:378357d7e90d 677 *bufO++ = USB20X.USBLENG; \
mbed_official 40:3b1c43ac045c 678 }
mbed_official 35:a8484e16c2f3 679
mbed_official 35:a8484e16c2f3 680
mbed_official 35:a8484e16c2f3 681 /*************************************************************************/
mbed_official 35:a8484e16c2f3 682 /*************************************************************************/
mbed_official 35:a8484e16c2f3 683 /*************************************************************************/
mbed_official 35:a8484e16c2f3 684
mbed_official 35:a8484e16c2f3 685 /*************************************************************************/
mbed_official 35:a8484e16c2f3 686 /* constructor */
mbed_official 35:a8484e16c2f3 687 USBHAL::USBHAL(void)
mbed_official 35:a8484e16c2f3 688 {
mbed_official 35:a8484e16c2f3 689 /* ---- P4_1 : P4_1 (USB0_EN for GR-PEACH) ---- */
mbed_official 46:378357d7e90d 690 //usbx_en = new DigitalOut(P4_1, 1);
mbed_official 35:a8484e16c2f3 691
mbed_official 35:a8484e16c2f3 692 /* some constants */
mbed_official 46:378357d7e90d 693 int_id = USBIX_IRQn;
mbed_official 35:a8484e16c2f3 694 int_level = ( 2 << 3 );
mbed_official 35:a8484e16c2f3 695 clock_mode = USBFCLOCK_X1_48MHZ;
mbed_official 46:378357d7e90d 696 #if (USB_FUNCTION_HISPEED == 0)
mbed_official 46:378357d7e90d 697 mode = USB_FUNCTION_FULL_SPEED;
mbed_official 46:378357d7e90d 698 #else
mbed_official 35:a8484e16c2f3 699 mode = USB_FUNCTION_HIGH_SPEED;
mbed_official 40:3b1c43ac045c 700 #endif
mbed_official 35:a8484e16c2f3 701 EP0_read_status = DEVDRV_USBF_WRITEEND;
mbed_official 35:a8484e16c2f3 702 EPx_read_status = DEVDRV_USBF_PIPE_DONE;
mbed_official 35:a8484e16c2f3 703
mbed_official 35:a8484e16c2f3 704 /* Disables interrupt for usb */
mbed_official 35:a8484e16c2f3 705 GIC_DisableIRQ(int_id);
mbed_official 35:a8484e16c2f3 706
mbed_official 35:a8484e16c2f3 707 /* Setup the end point */
mbed_official 35:a8484e16c2f3 708 epCallback[ 0] = &USBHAL::EP1_OUT_callback;
mbed_official 35:a8484e16c2f3 709 epCallback[ 1] = &USBHAL::EP1_IN_callback;
mbed_official 35:a8484e16c2f3 710 epCallback[ 2] = &USBHAL::EP2_OUT_callback;
mbed_official 35:a8484e16c2f3 711 epCallback[ 3] = &USBHAL::EP2_IN_callback;
mbed_official 35:a8484e16c2f3 712 epCallback[ 4] = &USBHAL::EP3_OUT_callback;
mbed_official 35:a8484e16c2f3 713 epCallback[ 5] = &USBHAL::EP3_IN_callback;
mbed_official 35:a8484e16c2f3 714 epCallback[ 6] = &USBHAL::EP4_OUT_callback;
mbed_official 35:a8484e16c2f3 715 epCallback[ 7] = &USBHAL::EP4_IN_callback;
mbed_official 35:a8484e16c2f3 716 epCallback[ 8] = &USBHAL::EP5_OUT_callback;
mbed_official 35:a8484e16c2f3 717 epCallback[ 9] = &USBHAL::EP5_IN_callback;
mbed_official 35:a8484e16c2f3 718 epCallback[10] = &USBHAL::EP6_OUT_callback;
mbed_official 35:a8484e16c2f3 719 epCallback[11] = &USBHAL::EP6_IN_callback;
mbed_official 35:a8484e16c2f3 720 epCallback[12] = &USBHAL::EP7_OUT_callback;
mbed_official 35:a8484e16c2f3 721 epCallback[13] = &USBHAL::EP7_IN_callback;
mbed_official 35:a8484e16c2f3 722 epCallback[14] = &USBHAL::EP8_OUT_callback;
mbed_official 35:a8484e16c2f3 723 epCallback[15] = &USBHAL::EP8_IN_callback;
mbed_official 35:a8484e16c2f3 724 epCallback[16] = &USBHAL::EP9_OUT_callback;
mbed_official 35:a8484e16c2f3 725 epCallback[17] = &USBHAL::EP9_IN_callback;
mbed_official 35:a8484e16c2f3 726 epCallback[18] = &USBHAL::EP10_OUT_callback;
mbed_official 35:a8484e16c2f3 727 epCallback[19] = &USBHAL::EP10_IN_callback;
mbed_official 35:a8484e16c2f3 728 epCallback[20] = &USBHAL::EP11_OUT_callback;
mbed_official 35:a8484e16c2f3 729 epCallback[21] = &USBHAL::EP11_IN_callback;
mbed_official 35:a8484e16c2f3 730 epCallback[22] = &USBHAL::EP12_OUT_callback;
mbed_official 35:a8484e16c2f3 731 epCallback[23] = &USBHAL::EP12_IN_callback;
mbed_official 35:a8484e16c2f3 732 epCallback[24] = &USBHAL::EP13_OUT_callback;
mbed_official 35:a8484e16c2f3 733 epCallback[25] = &USBHAL::EP13_IN_callback;
mbed_official 35:a8484e16c2f3 734 epCallback[26] = &USBHAL::EP14_OUT_callback;
mbed_official 35:a8484e16c2f3 735 epCallback[27] = &USBHAL::EP14_IN_callback;
mbed_official 35:a8484e16c2f3 736 epCallback[28] = &USBHAL::EP15_OUT_callback;
mbed_official 35:a8484e16c2f3 737 epCallback[29] = &USBHAL::EP15_IN_callback;
mbed_official 35:a8484e16c2f3 738
mbed_official 35:a8484e16c2f3 739 /* registers me */
mbed_official 35:a8484e16c2f3 740 instance = this;
mbed_official 35:a8484e16c2f3 741
mbed_official 35:a8484e16c2f3 742 /* Clear pipe table */
mbed_official 46:378357d7e90d 743 usbx_function_clear_pipe_tbl();
mbed_official 35:a8484e16c2f3 744
mbed_official 35:a8484e16c2f3 745 /******************************************************************************
mbed_official 46:378357d7e90d 746 * Function Name: usbx_api_function_init
mbed_official 35:a8484e16c2f3 747 * Description : Initializes the USB module in the USB function mode.
mbed_official 35:a8484e16c2f3 748 *****************************************************************************/
mbed_official 35:a8484e16c2f3 749 /* The clock of USB0 modules is permitted */
mbed_official 46:378357d7e90d 750 #if (USB_FUNCTION_CH == 0)
mbed_official 35:a8484e16c2f3 751 CPG.STBCR7 &= ~(CPG_STBCR7_MSTP71);
mbed_official 46:378357d7e90d 752 #else
mbed_official 46:378357d7e90d 753 CPG.STBCR7 &= ~(CPG_STBCR7_MSTP71 | CPG_STBCR7_MSTP70);
mbed_official 46:378357d7e90d 754 #endif
mbed_official 35:a8484e16c2f3 755 volatile uint8_t dummy8;
mbed_official 35:a8484e16c2f3 756 dummy8 = CPG.STBCR7;
mbed_official 35:a8484e16c2f3 757
mbed_official 35:a8484e16c2f3 758 {
mbed_official 35:a8484e16c2f3 759 /******************************************************************************
mbed_official 46:378357d7e90d 760 * Function Name: usbx_function_setting_interrupt
mbed_official 35:a8484e16c2f3 761 * Description : Sets the USB module interrupt level.
mbed_official 35:a8484e16c2f3 762 *****************************************************************************/
mbed_official 35:a8484e16c2f3 763 #if 0 /*DMA is not supported*/
mbed_official 35:a8484e16c2f3 764 IRQn_Type d0fifo_dmaintid;
mbed_official 35:a8484e16c2f3 765 IRQn_Type d1fifo_dmaintid;
mbed_official 35:a8484e16c2f3 766 #endif
mbed_official 35:a8484e16c2f3 767
mbed_official 35:a8484e16c2f3 768 InterruptHandlerRegister(int_id, &_usbisr);
mbed_official 35:a8484e16c2f3 769 GIC_SetPriority(int_id, int_level);
mbed_official 35:a8484e16c2f3 770 GIC_EnableIRQ(int_id);
mbed_official 35:a8484e16c2f3 771
mbed_official 35:a8484e16c2f3 772 #if 0 /*DMA is not supported*/
mbed_official 46:378357d7e90d 773 d0fifo_dmaintid = Userdef_USB_usbx_function_d0fifo_dmaintid();
mbed_official 35:a8484e16c2f3 774 if (d0fifo_dmaintid != 0xFFFF) {
mbed_official 46:378357d7e90d 775 InterruptHandlerRegister(d0fifo_dmaintid, usbx_function_dma_interrupt_d0fifo);
mbed_official 35:a8484e16c2f3 776 GIC_SetPriority(d0fifo_dmaintid, int_level);
mbed_official 35:a8484e16c2f3 777 GIC_EnableIRQ(d0fifo_dmaintid);
mbed_official 35:a8484e16c2f3 778 }
mbed_official 35:a8484e16c2f3 779 #endif
mbed_official 35:a8484e16c2f3 780
mbed_official 35:a8484e16c2f3 781 #if 0 /*DMA is not supported*/
mbed_official 46:378357d7e90d 782 d1fifo_dmaintid = Userdef_USB_usbx_function_d1fifo_dmaintid();
mbed_official 35:a8484e16c2f3 783 if (d1fifo_dmaintid != 0xFFFF) {
mbed_official 46:378357d7e90d 784 InterruptHandlerRegister(d1fifo_dmaintid, usbx_function_dma_interrupt_d1fifo);
mbed_official 35:a8484e16c2f3 785 GIC_SetPriority(d1fifo_dmaintid, int_level);
mbed_official 35:a8484e16c2f3 786 GIC_EnableIRQ(d1fifo_dmaintid);
mbed_official 35:a8484e16c2f3 787 }
mbed_official 35:a8484e16c2f3 788 #endif
mbed_official 35:a8484e16c2f3 789 /*****************************************************************************/
mbed_official 35:a8484e16c2f3 790 }
mbed_official 35:a8484e16c2f3 791
mbed_official 35:a8484e16c2f3 792 /* reset USB module with setting tranciever and HSE=1 */
mbed_official 46:378357d7e90d 793 usbx_function_reset_module(clock_mode);
mbed_official 35:a8484e16c2f3 794
mbed_official 35:a8484e16c2f3 795 /* clear variables */
mbed_official 46:378357d7e90d 796 usbx_function_init_status();
mbed_official 35:a8484e16c2f3 797
mbed_official 35:a8484e16c2f3 798 /* select USB Function and Interrupt Enable */
mbed_official 35:a8484e16c2f3 799 /* Detect USB Device to attach or detach */
mbed_official 46:378357d7e90d 800 usbx_function_InitModule(mode);
mbed_official 35:a8484e16c2f3 801
mbed_official 35:a8484e16c2f3 802 {
mbed_official 35:a8484e16c2f3 803 uint16_t buf;
mbed_official 46:378357d7e90d 804 buf = USB20X.INTENB0;
mbed_official 35:a8484e16c2f3 805 buf |= USB_INTENB0_SOFE;
mbed_official 46:378357d7e90d 806 USB20X.INTENB0 = buf;
mbed_official 35:a8484e16c2f3 807 }
mbed_official 35:a8484e16c2f3 808 }
mbed_official 35:a8484e16c2f3 809
mbed_official 35:a8484e16c2f3 810 /*************************************************************************/
mbed_official 35:a8484e16c2f3 811 USBHAL::~USBHAL(void)
mbed_official 35:a8484e16c2f3 812 {
mbed_official 35:a8484e16c2f3 813 /* Disables interrupt for usb */
mbed_official 35:a8484e16c2f3 814 GIC_DisableIRQ( int_id );
mbed_official 35:a8484e16c2f3 815 /* Unregisters interrupt function and priority */
mbed_official 35:a8484e16c2f3 816 InterruptHandlerRegister( int_id, (uint32_t)NULL );
mbed_official 35:a8484e16c2f3 817
mbed_official 46:378357d7e90d 818 //usbx_en = NULL;
mbed_official 35:a8484e16c2f3 819 instance = NULL;
mbed_official 35:a8484e16c2f3 820 }
mbed_official 35:a8484e16c2f3 821
mbed_official 35:a8484e16c2f3 822 /*************************************************************************/
mbed_official 35:a8484e16c2f3 823 void USBHAL::connect(void)
mbed_official 35:a8484e16c2f3 824 {
mbed_official 35:a8484e16c2f3 825 /* Activates USB0_EN */
mbed_official 46:378357d7e90d 826 //(*usbx_en) = 0;
mbed_official 35:a8484e16c2f3 827 }
mbed_official 35:a8484e16c2f3 828
mbed_official 35:a8484e16c2f3 829
mbed_official 35:a8484e16c2f3 830 /*************************************************************************/
mbed_official 35:a8484e16c2f3 831 void USBHAL::disconnect(void)
mbed_official 35:a8484e16c2f3 832 {
mbed_official 35:a8484e16c2f3 833 /* Deactivates USB0_EN */
mbed_official 46:378357d7e90d 834 //(*usbx_en) = 1;
mbed_official 35:a8484e16c2f3 835 }
mbed_official 35:a8484e16c2f3 836
mbed_official 35:a8484e16c2f3 837
mbed_official 35:a8484e16c2f3 838 /*************************************************************************/
mbed_official 35:a8484e16c2f3 839 void USBHAL::configureDevice(void)
mbed_official 35:a8484e16c2f3 840 {
mbed_official 35:a8484e16c2f3 841 /*The pipes set up in USBHAL::realiseEndpoint*/
mbed_official 46:378357d7e90d 842 /*usbx_function_clear_alt();*/ /* Alternate setting clear */
mbed_official 46:378357d7e90d 843 /*usbx_function_set_pid_buf(USB_FUNCTION_PIPE0);*/
mbed_official 35:a8484e16c2f3 844 }
mbed_official 35:a8484e16c2f3 845
mbed_official 35:a8484e16c2f3 846
mbed_official 35:a8484e16c2f3 847 /*************************************************************************/
mbed_official 35:a8484e16c2f3 848 void USBHAL::unconfigureDevice(void)
mbed_official 35:a8484e16c2f3 849 {
mbed_official 35:a8484e16c2f3 850 /* The Interface would be managed by USBDevice */
mbed_official 46:378357d7e90d 851 /*usbx_function_clear_alt();*/ /* Alternate setting clear */
mbed_official 46:378357d7e90d 852 /*usbx_function_set_pid_buf(USB_FUNCTION_PIPE0);*/
mbed_official 35:a8484e16c2f3 853 }
mbed_official 35:a8484e16c2f3 854
mbed_official 35:a8484e16c2f3 855
mbed_official 35:a8484e16c2f3 856 /*************************************************************************/
mbed_official 35:a8484e16c2f3 857 void USBHAL::setAddress(uint8_t address)
mbed_official 35:a8484e16c2f3 858 {
mbed_official 35:a8484e16c2f3 859 if (address <= 127) {
mbed_official 46:378357d7e90d 860 usbx_function_set_pid_buf(USB_FUNCTION_PIPE0); /* OK */
mbed_official 35:a8484e16c2f3 861 } else {
mbed_official 46:378357d7e90d 862 usbx_function_set_pid_stall(USB_FUNCTION_PIPE0); /* Not Spec */
mbed_official 35:a8484e16c2f3 863 }
mbed_official 35:a8484e16c2f3 864 }
mbed_official 35:a8484e16c2f3 865
mbed_official 35:a8484e16c2f3 866
mbed_official 35:a8484e16c2f3 867 /*************************************************************************/
mbed_official 35:a8484e16c2f3 868 bool USBHAL::realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t flags)
mbed_official 35:a8484e16c2f3 869 {
mbed_official 35:a8484e16c2f3 870 const struct PIPECFGREC *cfg;
mbed_official 35:a8484e16c2f3 871 uint16_t pipe;
mbed_official 35:a8484e16c2f3 872 uint16_t buf;
mbed_official 35:a8484e16c2f3 873
mbed_official 35:a8484e16c2f3 874 if ( (EP0OUT == endpoint) || (EP0IN == endpoint) ) {
mbed_official 35:a8484e16c2f3 875 return true;
mbed_official 35:a8484e16c2f3 876 }
mbed_official 35:a8484e16c2f3 877
mbed_official 35:a8484e16c2f3 878 for (cfg = &def_pipecfg[0]; cfg->pipesel != 0; cfg++) {
mbed_official 35:a8484e16c2f3 879 if (cfg->endpoint == endpoint) {
mbed_official 35:a8484e16c2f3 880 break;
mbed_official 35:a8484e16c2f3 881 }
mbed_official 35:a8484e16c2f3 882 }
mbed_official 35:a8484e16c2f3 883 if (cfg->pipesel == 0) {
mbed_official 35:a8484e16c2f3 884 return false;
mbed_official 35:a8484e16c2f3 885 }
mbed_official 35:a8484e16c2f3 886
mbed_official 35:a8484e16c2f3 887 pipe = ((cfg->pipesel & USB_PIPESEL_PIPESEL) >> USB_PIPESEL_PIPESEL_SHIFT);
mbed_official 35:a8484e16c2f3 888
mbed_official 46:378357d7e90d 889 g_usbx_function_PipeTbl[ pipe ] = (uint16_t)(endpoint | ((cfg->pipesel & USB_FUNCTION_FIFO_USE) << 0));
mbed_official 35:a8484e16c2f3 890
mbed_official 35:a8484e16c2f3 891 /* There are maintenance routine of SHTNAK and BFRE bits
mbed_official 35:a8484e16c2f3 892 * in original sample program. This sample is not
mbed_official 35:a8484e16c2f3 893 * programmed. Do maintenance the "def_pipecfg" array if
mbed_official 35:a8484e16c2f3 894 * you want it. */
mbed_official 35:a8484e16c2f3 895
mbed_official 35:a8484e16c2f3 896 /* Interrupt Disable */
mbed_official 46:378357d7e90d 897 buf = USB20X.BRDYENB;
mbed_official 46:378357d7e90d 898 buf &= (uint16_t)~g_usbx_function_bit_set[pipe];
mbed_official 46:378357d7e90d 899 USB20X.BRDYENB = buf;
mbed_official 46:378357d7e90d 900 buf = USB20X.NRDYENB;
mbed_official 46:378357d7e90d 901 buf &= (uint16_t)~g_usbx_function_bit_set[pipe];
mbed_official 46:378357d7e90d 902 USB20X.NRDYENB = buf;
mbed_official 46:378357d7e90d 903 buf = USB20X.BEMPENB;
mbed_official 46:378357d7e90d 904 buf &= (uint16_t)~g_usbx_function_bit_set[pipe];
mbed_official 46:378357d7e90d 905 USB20X.BEMPENB = buf;
mbed_official 35:a8484e16c2f3 906
mbed_official 46:378357d7e90d 907 usbx_function_set_pid_nak(pipe);
mbed_official 35:a8484e16c2f3 908
mbed_official 35:a8484e16c2f3 909 /* CurrentPIPE Clear */
mbed_official 46:378357d7e90d 910 if (RZA_IO_RegRead_16(&USB20X.CFIFOSEL, USB_CFIFOSEL_CURPIPE_SHIFT, USB_CFIFOSEL_CURPIPE) == pipe) {
mbed_official 46:378357d7e90d 911 RZA_IO_RegWrite_16(&USB20X.CFIFOSEL, 0, USB_CFIFOSEL_CURPIPE_SHIFT, USB_CFIFOSEL_CURPIPE);
mbed_official 35:a8484e16c2f3 912 }
mbed_official 35:a8484e16c2f3 913
mbed_official 46:378357d7e90d 914 if (RZA_IO_RegRead_16(&USB20X.D0FIFOSEL, USB_DnFIFOSEL_CURPIPE_SHIFT, USB_DnFIFOSEL_CURPIPE) == pipe) {
mbed_official 46:378357d7e90d 915 RZA_IO_RegWrite_16(&USB20X.D0FIFOSEL, 0, USB_DnFIFOSEL_CURPIPE_SHIFT, USB_DnFIFOSEL_CURPIPE);
mbed_official 35:a8484e16c2f3 916 }
mbed_official 35:a8484e16c2f3 917
mbed_official 46:378357d7e90d 918 if (RZA_IO_RegRead_16(&USB20X.D1FIFOSEL, USB_DnFIFOSEL_CURPIPE_SHIFT, USB_DnFIFOSEL_CURPIPE) == pipe) {
mbed_official 46:378357d7e90d 919 RZA_IO_RegWrite_16(&USB20X.D1FIFOSEL, 0, USB_DnFIFOSEL_CURPIPE_SHIFT, USB_DnFIFOSEL_CURPIPE);
mbed_official 35:a8484e16c2f3 920 }
mbed_official 35:a8484e16c2f3 921
mbed_official 35:a8484e16c2f3 922 /* PIPE Configuration */
mbed_official 46:378357d7e90d 923 USB20X.PIPESEL = pipe;
mbed_official 46:378357d7e90d 924 USB20X.PIPECFG = cfg->pipecfg;
mbed_official 46:378357d7e90d 925 USB20X.PIPEBUF = cfg->pipebuf;
mbed_official 46:378357d7e90d 926 USB20X.PIPEMAXP = cfg->pipemaxp;
mbed_official 46:378357d7e90d 927 USB20X.PIPEPERI = cfg->pipeperi;
mbed_official 35:a8484e16c2f3 928
mbed_official 46:378357d7e90d 929 g_usbx_function_pipecfg[pipe] = cfg->pipecfg;
mbed_official 46:378357d7e90d 930 g_usbx_function_pipebuf[pipe] = cfg->pipebuf;
mbed_official 46:378357d7e90d 931 g_usbx_function_pipemaxp[pipe] = cfg->pipemaxp;
mbed_official 46:378357d7e90d 932 g_usbx_function_pipeperi[pipe] = cfg->pipeperi;
mbed_official 35:a8484e16c2f3 933
mbed_official 35:a8484e16c2f3 934 /* Buffer Clear */
mbed_official 46:378357d7e90d 935 usbx_function_set_sqclr(pipe);
mbed_official 46:378357d7e90d 936 usbx_function_aclrm(pipe);
mbed_official 35:a8484e16c2f3 937
mbed_official 35:a8484e16c2f3 938 /* init Global */
mbed_official 46:378357d7e90d 939 g_usbx_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_IDLE;
mbed_official 46:378357d7e90d 940 g_usbx_function_PipeDataSize[pipe] = 0;
mbed_official 35:a8484e16c2f3 941
mbed_official 35:a8484e16c2f3 942 return true;
mbed_official 35:a8484e16c2f3 943 }
mbed_official 35:a8484e16c2f3 944
mbed_official 35:a8484e16c2f3 945
mbed_official 35:a8484e16c2f3 946 /*************************************************************************/
mbed_official 35:a8484e16c2f3 947 // read setup packet
mbed_official 35:a8484e16c2f3 948 void USBHAL::EP0setup(uint8_t *buffer)
mbed_official 35:a8484e16c2f3 949 {
mbed_official 35:a8484e16c2f3 950 memcpy(buffer, setup_buffer, MAX_PACKET_SIZE_EP0);
mbed_official 35:a8484e16c2f3 951 }
mbed_official 35:a8484e16c2f3 952
mbed_official 35:a8484e16c2f3 953
mbed_official 35:a8484e16c2f3 954 /*************************************************************************/
mbed_official 35:a8484e16c2f3 955 void USBHAL::EP0readStage(void)
mbed_official 35:a8484e16c2f3 956 {
mbed_official 35:a8484e16c2f3 957 // No implements
mbed_official 35:a8484e16c2f3 958 }
mbed_official 35:a8484e16c2f3 959
mbed_official 35:a8484e16c2f3 960
mbed_official 35:a8484e16c2f3 961 /*************************************************************************/
mbed_official 35:a8484e16c2f3 962 void USBHAL::EP0read(void)
mbed_official 35:a8484e16c2f3 963 {
mbed_official 35:a8484e16c2f3 964 uint8_t *buffer;
mbed_official 35:a8484e16c2f3 965 uint32_t size;
mbed_official 35:a8484e16c2f3 966
mbed_official 35:a8484e16c2f3 967 /* remain of last writing */
mbed_official 35:a8484e16c2f3 968 while (EP0_read_status != DEVDRV_USBF_WRITEEND) {
mbed_official 35:a8484e16c2f3 969 static uint8_t bbb[2] = { 255, 255 };
mbed_official 35:a8484e16c2f3 970 EP0write(&bbb[0], 0);
mbed_official 35:a8484e16c2f3 971 }
mbed_official 35:a8484e16c2f3 972
mbed_official 35:a8484e16c2f3 973 buffer = (uint8_t*)(&setup_buffer[4]);
mbed_official 35:a8484e16c2f3 974 size = (MAX_PACKET_SIZE_EP0 / 2) - 8;
mbed_official 46:378357d7e90d 975 usbx_api_function_CtrlWriteStart(size, buffer);
mbed_official 35:a8484e16c2f3 976 }
mbed_official 35:a8484e16c2f3 977
mbed_official 35:a8484e16c2f3 978
mbed_official 35:a8484e16c2f3 979 /*************************************************************************/
mbed_official 35:a8484e16c2f3 980 uint32_t USBHAL::EP0getReadResult(uint8_t *buffer)
mbed_official 35:a8484e16c2f3 981 {
mbed_official 46:378357d7e90d 982 memcpy(buffer, (uint8_t*)(&setup_buffer[4]), g_usbx_function_PipeDataSize[USB_FUNCTION_PIPE0]);
mbed_official 35:a8484e16c2f3 983
mbed_official 46:378357d7e90d 984 return g_usbx_function_PipeDataSize[USB_FUNCTION_PIPE0];
mbed_official 35:a8484e16c2f3 985 }
mbed_official 35:a8484e16c2f3 986
mbed_official 35:a8484e16c2f3 987
mbed_official 35:a8484e16c2f3 988 /*************************************************************************/
mbed_official 35:a8484e16c2f3 989 void USBHAL::EP0write(uint8_t *buffer, uint32_t size)
mbed_official 35:a8484e16c2f3 990 {
mbed_official 35:a8484e16c2f3 991 /* zero byte writing */
mbed_official 35:a8484e16c2f3 992 if ( (size == 0) && (EP0_read_status == DEVDRV_USBF_WRITEEND) ) {
mbed_official 35:a8484e16c2f3 993 return;
mbed_official 35:a8484e16c2f3 994 }
mbed_official 35:a8484e16c2f3 995
mbed_official 35:a8484e16c2f3 996 if (EP0_read_status == DEVDRV_USBF_WRITEEND) {
mbed_official 35:a8484e16c2f3 997 /*1st block*/
mbed_official 46:378357d7e90d 998 EP0_read_status = usbx_api_function_CtrlReadStart(size, buffer);
mbed_official 35:a8484e16c2f3 999 } else {
mbed_official 35:a8484e16c2f3 1000 /* waits the last transmission */
mbed_official 35:a8484e16c2f3 1001 /*other blocks*/
mbed_official 46:378357d7e90d 1002 g_usbx_function_data_count[ USB_FUNCTION_PIPE0 ] = size;
mbed_official 46:378357d7e90d 1003 g_usbx_function_data_pointer [ USB_FUNCTION_PIPE0 ] = buffer;
mbed_official 46:378357d7e90d 1004 EP0_read_status = usbx_function_write_buffer_c(USB_FUNCTION_PIPE0);
mbed_official 35:a8484e16c2f3 1005 }
mbed_official 35:a8484e16c2f3 1006 /*max size may be deblocking outside*/
mbed_official 35:a8484e16c2f3 1007 if (size == MAX_PACKET_SIZE_EP0) {
mbed_official 35:a8484e16c2f3 1008 EP0_read_status = DEVDRV_USBF_WRITING;
mbed_official 35:a8484e16c2f3 1009 }
mbed_official 35:a8484e16c2f3 1010 }
mbed_official 35:a8484e16c2f3 1011
mbed_official 35:a8484e16c2f3 1012
mbed_official 35:a8484e16c2f3 1013 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1014 #if 0 // No implements
mbed_official 35:a8484e16c2f3 1015 void USBHAL::EP0getWriteResult(void)
mbed_official 35:a8484e16c2f3 1016 {
mbed_official 35:a8484e16c2f3 1017 }
mbed_official 35:a8484e16c2f3 1018 #endif
mbed_official 35:a8484e16c2f3 1019
mbed_official 35:a8484e16c2f3 1020 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1021 void USBHAL::EP0stall(void)
mbed_official 35:a8484e16c2f3 1022 {
mbed_official 35:a8484e16c2f3 1023 stallEndpoint( 0 );
mbed_official 35:a8484e16c2f3 1024 }
mbed_official 35:a8484e16c2f3 1025
mbed_official 35:a8484e16c2f3 1026
mbed_official 35:a8484e16c2f3 1027 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1028 EP_STATUS USBHAL::endpointRead(uint8_t endpoint, uint32_t max_size)
mbed_official 35:a8484e16c2f3 1029 {
mbed_official 35:a8484e16c2f3 1030 uint32_t pipe = EP2PIPE(endpoint);
mbed_official 35:a8484e16c2f3 1031 uint32_t pipe_size;
mbed_official 35:a8484e16c2f3 1032 uint16_t pipe_status;
mbed_official 35:a8484e16c2f3 1033 EP_STATUS status = EP_COMPLETED;
mbed_official 35:a8484e16c2f3 1034
mbed_official 46:378357d7e90d 1035 pipe_status = usbx_api_function_check_pipe_status(pipe, &pipe_size);
mbed_official 40:3b1c43ac045c 1036
mbed_official 40:3b1c43ac045c 1037 switch (pipe_status) {
mbed_official 40:3b1c43ac045c 1038 case DEVDRV_USBF_PIPE_IDLE:
mbed_official 40:3b1c43ac045c 1039 case DEVDRV_USBF_PIPE_WAIT:
mbed_official 46:378357d7e90d 1040 usbx_api_function_set_pid_nak(pipe);
mbed_official 46:378357d7e90d 1041 usbx_api_function_clear_pipe_status(pipe);
mbed_official 35:a8484e16c2f3 1042
mbed_official 46:378357d7e90d 1043 usbx_api_function_start_receive_transfer(pipe, max_size, recv_buffer);
mbed_official 40:3b1c43ac045c 1044 break;
mbed_official 35:a8484e16c2f3 1045
mbed_official 40:3b1c43ac045c 1046 default:
mbed_official 40:3b1c43ac045c 1047 status = EP_PENDING;
mbed_official 40:3b1c43ac045c 1048 break;
mbed_official 35:a8484e16c2f3 1049 }
mbed_official 35:a8484e16c2f3 1050
mbed_official 35:a8484e16c2f3 1051 return status;
mbed_official 35:a8484e16c2f3 1052 }
mbed_official 35:a8484e16c2f3 1053
mbed_official 35:a8484e16c2f3 1054
mbed_official 35:a8484e16c2f3 1055 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1056 EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t *buffer, uint32_t *bytes_read )
mbed_official 35:a8484e16c2f3 1057 {
mbed_official 35:a8484e16c2f3 1058 uint32_t pipe = EP2PIPE(endpoint);
mbed_official 35:a8484e16c2f3 1059 uint16_t pipe_status;
mbed_official 35:a8484e16c2f3 1060 uint16_t err;
mbed_official 35:a8484e16c2f3 1061 EP_STATUS status = EP_PENDING;
mbed_official 35:a8484e16c2f3 1062
mbed_official 35:a8484e16c2f3 1063
mbed_official 35:a8484e16c2f3 1064 if (EPx_read_status != DEVDRV_USBF_PIPE_WAIT) {
mbed_official 35:a8484e16c2f3 1065 return status;
mbed_official 35:a8484e16c2f3 1066 }
mbed_official 35:a8484e16c2f3 1067
mbed_official 46:378357d7e90d 1068 pipe_status = usbx_api_function_check_pipe_status(pipe, bytes_read);
mbed_official 40:3b1c43ac045c 1069 switch (pipe_status) {
mbed_official 40:3b1c43ac045c 1070 case DEVDRV_USBF_PIPE_IDLE:
mbed_official 40:3b1c43ac045c 1071 return EP_COMPLETED;
mbed_official 40:3b1c43ac045c 1072
mbed_official 40:3b1c43ac045c 1073 case DEVDRV_USBF_PIPE_DONE:
mbed_official 40:3b1c43ac045c 1074 return EP_COMPLETED;
mbed_official 40:3b1c43ac045c 1075
mbed_official 40:3b1c43ac045c 1076 case DEVDRV_USBF_PIPE_WAIT:
mbed_official 40:3b1c43ac045c 1077 break;
mbed_official 40:3b1c43ac045c 1078
mbed_official 40:3b1c43ac045c 1079 default:
mbed_official 40:3b1c43ac045c 1080 return status;
mbed_official 35:a8484e16c2f3 1081 }
mbed_official 35:a8484e16c2f3 1082
mbed_official 35:a8484e16c2f3 1083 /* sets the output buffer and size */
mbed_official 46:378357d7e90d 1084 g_usbx_function_data_pointer[pipe] = buffer;
mbed_official 35:a8484e16c2f3 1085
mbed_official 35:a8484e16c2f3 1086 /* receives data from pipe */
mbed_official 46:378357d7e90d 1087 err = usbx_function_read_buffer(pipe);
mbed_official 35:a8484e16c2f3 1088 recv_error = err;
mbed_official 40:3b1c43ac045c 1089 switch (err) {
mbed_official 40:3b1c43ac045c 1090 case USB_FUNCTION_READEND:
mbed_official 40:3b1c43ac045c 1091 case USB_FUNCTION_READSHRT:
mbed_official 40:3b1c43ac045c 1092 case USB_FUNCTION_READOVER:
mbed_official 46:378357d7e90d 1093 *bytes_read = g_usbx_function_PipeDataSize[pipe];
mbed_official 40:3b1c43ac045c 1094 break;
mbed_official 40:3b1c43ac045c 1095
mbed_official 40:3b1c43ac045c 1096 case USB_FUNCTION_READING:
mbed_official 40:3b1c43ac045c 1097 case DEVDRV_USBF_FIFOERROR:
mbed_official 40:3b1c43ac045c 1098 break;
mbed_official 40:3b1c43ac045c 1099 }
mbed_official 35:a8484e16c2f3 1100
mbed_official 46:378357d7e90d 1101 pipe_status = usbx_api_function_check_pipe_status(pipe, bytes_read);
mbed_official 40:3b1c43ac045c 1102 switch (pipe_status) {
mbed_official 40:3b1c43ac045c 1103 case DEVDRV_USBF_PIPE_DONE:
mbed_official 40:3b1c43ac045c 1104 status = EP_COMPLETED;
mbed_official 40:3b1c43ac045c 1105 break;
mbed_official 40:3b1c43ac045c 1106
mbed_official 40:3b1c43ac045c 1107 case DEVDRV_USBF_PIPE_IDLE:
mbed_official 40:3b1c43ac045c 1108 case DEVDRV_USBF_PIPE_NORES:
mbed_official 40:3b1c43ac045c 1109 case DEVDRV_USBF_PIPE_STALL:
mbed_official 40:3b1c43ac045c 1110 case DEVDRV_USBF_FIFOERROR:
mbed_official 40:3b1c43ac045c 1111 default:
mbed_official 40:3b1c43ac045c 1112 break;
mbed_official 35:a8484e16c2f3 1113 }
mbed_official 35:a8484e16c2f3 1114
mbed_official 35:a8484e16c2f3 1115 return status;
mbed_official 35:a8484e16c2f3 1116 }
mbed_official 35:a8484e16c2f3 1117
mbed_official 35:a8484e16c2f3 1118
mbed_official 35:a8484e16c2f3 1119 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1120 EP_STATUS USBHAL::endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size)
mbed_official 35:a8484e16c2f3 1121 {
mbed_official 35:a8484e16c2f3 1122 uint32_t pipe = EP2PIPE(endpoint);
mbed_official 35:a8484e16c2f3 1123 uint32_t pipe_size;
mbed_official 35:a8484e16c2f3 1124 uint16_t pipe_status;
mbed_official 35:a8484e16c2f3 1125 uint16_t err;
mbed_official 35:a8484e16c2f3 1126 uint16_t count;
mbed_official 35:a8484e16c2f3 1127 EP_STATUS status = EP_PENDING;
mbed_official 35:a8484e16c2f3 1128
mbed_official 46:378357d7e90d 1129 pipe_status = usbx_api_function_check_pipe_status(pipe, &pipe_size);
mbed_official 35:a8484e16c2f3 1130
mbed_official 35:a8484e16c2f3 1131 /* waits the last transmission */
mbed_official 35:a8484e16c2f3 1132 count = 30000;
mbed_official 35:a8484e16c2f3 1133 while ((pipe_status == DEVDRV_USBF_PIPE_WAIT) || (pipe_status == DEVDRV_USBF_PIPE_DONE)) {
mbed_official 46:378357d7e90d 1134 pipe_status = usbx_api_function_check_pipe_status(pipe, &pipe_size);
mbed_official 35:a8484e16c2f3 1135 if( --count == 0 ) {
mbed_official 35:a8484e16c2f3 1136 pipe_status = DEVDRV_USBF_PIPE_STALL;
mbed_official 35:a8484e16c2f3 1137 break;
mbed_official 35:a8484e16c2f3 1138 }
mbed_official 35:a8484e16c2f3 1139 }
mbed_official 35:a8484e16c2f3 1140
mbed_official 35:a8484e16c2f3 1141 switch (pipe_status) {
mbed_official 35:a8484e16c2f3 1142 case DEVDRV_USBF_PIPE_IDLE:
mbed_official 46:378357d7e90d 1143 err = usbx_api_function_start_send_transfer(pipe, size, data);
mbed_official 35:a8484e16c2f3 1144
mbed_official 35:a8484e16c2f3 1145 switch (err) {
mbed_official 35:a8484e16c2f3 1146 /* finish to write */
mbed_official 35:a8484e16c2f3 1147 case DEVDRV_USBF_WRITEEND:
mbed_official 35:a8484e16c2f3 1148 /* finish to write, but data is short */
mbed_official 35:a8484e16c2f3 1149 case DEVDRV_USBF_WRITESHRT:
mbed_official 35:a8484e16c2f3 1150 /* continue to write */
mbed_official 35:a8484e16c2f3 1151 case DEVDRV_USBF_WRITING:
mbed_official 35:a8484e16c2f3 1152 /* use DMA */
mbed_official 35:a8484e16c2f3 1153 case DEVDRV_USBF_WRITEDMA:
mbed_official 35:a8484e16c2f3 1154 /* error */
mbed_official 35:a8484e16c2f3 1155 case DEVDRV_USBF_FIFOERROR:
mbed_official 35:a8484e16c2f3 1156 status = EP_PENDING;
mbed_official 35:a8484e16c2f3 1157 break;
mbed_official 35:a8484e16c2f3 1158 }
mbed_official 35:a8484e16c2f3 1159 break;
mbed_official 35:a8484e16c2f3 1160
mbed_official 35:a8484e16c2f3 1161 case DEVDRV_USBF_PIPE_WAIT:
mbed_official 35:a8484e16c2f3 1162 case DEVDRV_USBF_PIPE_DONE:
mbed_official 35:a8484e16c2f3 1163 status = EP_PENDING;
mbed_official 35:a8484e16c2f3 1164 break;
mbed_official 35:a8484e16c2f3 1165
mbed_official 35:a8484e16c2f3 1166 case DEVDRV_USBF_PIPE_NORES:
mbed_official 35:a8484e16c2f3 1167 case DEVDRV_USBF_PIPE_STALL:
mbed_official 35:a8484e16c2f3 1168 default:
mbed_official 35:a8484e16c2f3 1169 status = EP_STALLED;
mbed_official 35:a8484e16c2f3 1170 break;
mbed_official 35:a8484e16c2f3 1171 }
mbed_official 35:a8484e16c2f3 1172
mbed_official 35:a8484e16c2f3 1173 return status;
mbed_official 35:a8484e16c2f3 1174 }
mbed_official 35:a8484e16c2f3 1175
mbed_official 35:a8484e16c2f3 1176
mbed_official 35:a8484e16c2f3 1177 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1178 EP_STATUS USBHAL::endpointWriteResult(uint8_t endpoint)
mbed_official 35:a8484e16c2f3 1179 {
mbed_official 35:a8484e16c2f3 1180 uint32_t pipe = EP2PIPE(endpoint);
mbed_official 35:a8484e16c2f3 1181 uint32_t pipe_size;
mbed_official 35:a8484e16c2f3 1182 uint16_t pipe_status;
mbed_official 35:a8484e16c2f3 1183 EP_STATUS status = EP_PENDING;
mbed_official 35:a8484e16c2f3 1184
mbed_official 46:378357d7e90d 1185 pipe_status = usbx_api_function_check_pipe_status(pipe, &pipe_size);
mbed_official 35:a8484e16c2f3 1186
mbed_official 35:a8484e16c2f3 1187 switch (pipe_status) {
mbed_official 35:a8484e16c2f3 1188 case DEVDRV_USBF_PIPE_IDLE:
mbed_official 35:a8484e16c2f3 1189 status = EP_COMPLETED;
mbed_official 35:a8484e16c2f3 1190 break;
mbed_official 35:a8484e16c2f3 1191
mbed_official 35:a8484e16c2f3 1192 case DEVDRV_USBF_PIPE_WAIT:
mbed_official 35:a8484e16c2f3 1193 status = EP_PENDING;
mbed_official 35:a8484e16c2f3 1194 break;
mbed_official 35:a8484e16c2f3 1195
mbed_official 35:a8484e16c2f3 1196 case DEVDRV_USBF_PIPE_DONE:
mbed_official 46:378357d7e90d 1197 usbx_function_stop_transfer(pipe);
mbed_official 35:a8484e16c2f3 1198 status = EP_COMPLETED;
mbed_official 35:a8484e16c2f3 1199 break;
mbed_official 35:a8484e16c2f3 1200
mbed_official 35:a8484e16c2f3 1201 case DEVDRV_USBF_PIPE_NORES:
mbed_official 35:a8484e16c2f3 1202 status = EP_STALLED;
mbed_official 35:a8484e16c2f3 1203 break;
mbed_official 35:a8484e16c2f3 1204
mbed_official 35:a8484e16c2f3 1205 case DEVDRV_USBF_PIPE_STALL:
mbed_official 35:a8484e16c2f3 1206 status = EP_STALLED;
mbed_official 35:a8484e16c2f3 1207 break;
mbed_official 35:a8484e16c2f3 1208
mbed_official 35:a8484e16c2f3 1209 default:
mbed_official 35:a8484e16c2f3 1210 status = EP_PENDING;
mbed_official 35:a8484e16c2f3 1211 }
mbed_official 35:a8484e16c2f3 1212
mbed_official 35:a8484e16c2f3 1213 return status;
mbed_official 35:a8484e16c2f3 1214 }
mbed_official 35:a8484e16c2f3 1215
mbed_official 35:a8484e16c2f3 1216
mbed_official 35:a8484e16c2f3 1217 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1218 void USBHAL::stallEndpoint(uint8_t endpoint)
mbed_official 35:a8484e16c2f3 1219 {
mbed_official 35:a8484e16c2f3 1220 uint32_t pipe = EP2PIPE(endpoint);
mbed_official 35:a8484e16c2f3 1221
mbed_official 46:378357d7e90d 1222 usbx_function_clear_pid_stall(pipe);
mbed_official 35:a8484e16c2f3 1223 }
mbed_official 35:a8484e16c2f3 1224
mbed_official 35:a8484e16c2f3 1225
mbed_official 35:a8484e16c2f3 1226 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1227 void USBHAL::unstallEndpoint(uint8_t endpoint)
mbed_official 35:a8484e16c2f3 1228 {
mbed_official 35:a8484e16c2f3 1229 uint32_t pipe = EP2PIPE(endpoint);
mbed_official 35:a8484e16c2f3 1230
mbed_official 46:378357d7e90d 1231 usbx_function_set_pid_stall( pipe );
mbed_official 35:a8484e16c2f3 1232 }
mbed_official 35:a8484e16c2f3 1233
mbed_official 35:a8484e16c2f3 1234
mbed_official 35:a8484e16c2f3 1235 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1236 bool USBHAL::getEndpointStallState(uint8_t endpoint)
mbed_official 35:a8484e16c2f3 1237 {
mbed_official 35:a8484e16c2f3 1238 // No implemens
mbed_official 35:a8484e16c2f3 1239 return false;
mbed_official 35:a8484e16c2f3 1240 }
mbed_official 35:a8484e16c2f3 1241
mbed_official 35:a8484e16c2f3 1242
mbed_official 35:a8484e16c2f3 1243 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1244 #if 0 // No implements
mbed_official 35:a8484e16c2f3 1245 void USBHAL::remoteWakeup(void)
mbed_official 35:a8484e16c2f3 1246 {
mbed_official 35:a8484e16c2f3 1247 }
mbed_official 35:a8484e16c2f3 1248 #endif
mbed_official 35:a8484e16c2f3 1249
mbed_official 35:a8484e16c2f3 1250 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1251 void USBHAL::_usbisr(void)
mbed_official 35:a8484e16c2f3 1252 {
mbed_official 35:a8484e16c2f3 1253 instance->usbisr();
mbed_official 35:a8484e16c2f3 1254 }
mbed_official 35:a8484e16c2f3 1255
mbed_official 35:a8484e16c2f3 1256
mbed_official 35:a8484e16c2f3 1257 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1258 void USBHAL::usbisr(void)
mbed_official 35:a8484e16c2f3 1259 {
mbed_official 35:a8484e16c2f3 1260 uint16_t int_sts0;
mbed_official 35:a8484e16c2f3 1261 uint16_t int_sts1;
mbed_official 35:a8484e16c2f3 1262 uint16_t int_sts2;
mbed_official 35:a8484e16c2f3 1263 uint16_t int_sts3;
mbed_official 35:a8484e16c2f3 1264 uint16_t int_enb0;
mbed_official 35:a8484e16c2f3 1265 uint16_t int_enb2;
mbed_official 35:a8484e16c2f3 1266 uint16_t int_enb3;
mbed_official 35:a8484e16c2f3 1267 uint16_t int_enb4;
mbed_official 35:a8484e16c2f3 1268 volatile uint16_t dumy_sts;
mbed_official 35:a8484e16c2f3 1269
mbed_official 35:a8484e16c2f3 1270
mbed_official 46:378357d7e90d 1271 int_sts0 = USB20X.INTSTS0;
mbed_official 35:a8484e16c2f3 1272
mbed_official 35:a8484e16c2f3 1273 if (!(int_sts0 & (
mbed_official 35:a8484e16c2f3 1274 USB_FUNCTION_BITVBINT |
mbed_official 35:a8484e16c2f3 1275 USB_FUNCTION_BITRESM |
mbed_official 35:a8484e16c2f3 1276 USB_FUNCTION_BITSOFR |
mbed_official 35:a8484e16c2f3 1277 USB_FUNCTION_BITDVST |
mbed_official 35:a8484e16c2f3 1278 USB_FUNCTION_BITCTRT |
mbed_official 35:a8484e16c2f3 1279 USB_FUNCTION_BITBEMP |
mbed_official 35:a8484e16c2f3 1280 USB_FUNCTION_BITNRDY |
mbed_official 35:a8484e16c2f3 1281 USB_FUNCTION_BITBRDY ))) {
mbed_official 35:a8484e16c2f3 1282 return;
mbed_official 35:a8484e16c2f3 1283 }
mbed_official 35:a8484e16c2f3 1284
mbed_official 46:378357d7e90d 1285 int_sts1 = USB20X.BRDYSTS;
mbed_official 46:378357d7e90d 1286 int_sts2 = USB20X.NRDYSTS;
mbed_official 46:378357d7e90d 1287 int_sts3 = USB20X.BEMPSTS;
mbed_official 46:378357d7e90d 1288 int_enb0 = USB20X.INTENB0;
mbed_official 46:378357d7e90d 1289 int_enb2 = USB20X.BRDYENB;
mbed_official 46:378357d7e90d 1290 int_enb3 = USB20X.NRDYENB;
mbed_official 46:378357d7e90d 1291 int_enb4 = USB20X.BEMPENB;
mbed_official 35:a8484e16c2f3 1292
mbed_official 35:a8484e16c2f3 1293 if ((int_sts0 & USB_FUNCTION_BITRESM) &&
mbed_official 35:a8484e16c2f3 1294 (int_enb0 & USB_FUNCTION_BITRSME)) {
mbed_official 46:378357d7e90d 1295 USB20X.INTSTS0 = (uint16_t)~USB_FUNCTION_BITRESM;
mbed_official 46:378357d7e90d 1296 RZA_IO_RegWrite_16(&USB20X.INTENB0, 0, USB_INTENB0_RSME_SHIFT, USB_INTENB0_RSME);
mbed_official 46:378357d7e90d 1297 /*usbx_function_USB_FUNCTION_Resume();*/
mbed_official 35:a8484e16c2f3 1298 suspendStateChanged(1);
mbed_official 35:a8484e16c2f3 1299 } else if (
mbed_official 35:a8484e16c2f3 1300 (int_sts0 & USB_FUNCTION_BITVBINT) &&
mbed_official 35:a8484e16c2f3 1301 (int_enb0 & USB_FUNCTION_BITVBSE)) {
mbed_official 46:378357d7e90d 1302 USB20X.INTSTS0 = (uint16_t)~USB_FUNCTION_BITVBINT;
mbed_official 35:a8484e16c2f3 1303
mbed_official 46:378357d7e90d 1304 if (usbx_function_CheckVBUStaus() == DEVDRV_USBF_ON) {
mbed_official 46:378357d7e90d 1305 usbx_function_USB_FUNCTION_Attach();
mbed_official 35:a8484e16c2f3 1306 } else {
mbed_official 46:378357d7e90d 1307 usbx_function_USB_FUNCTION_Detach();
mbed_official 35:a8484e16c2f3 1308 }
mbed_official 35:a8484e16c2f3 1309 } else if (
mbed_official 35:a8484e16c2f3 1310 (int_sts0 & USB_FUNCTION_BITSOFR) &&
mbed_official 35:a8484e16c2f3 1311 (int_enb0 & USB_FUNCTION_BITSOFE)) {
mbed_official 46:378357d7e90d 1312 USB20X.INTSTS0 = (uint16_t)~USB_FUNCTION_BITSOFR;
mbed_official 46:378357d7e90d 1313 SOF((USB20X.FRMNUM & USB_FRMNUM_FRNM) >> USB_FRMNUM_FRNM_SHIFT);
mbed_official 35:a8484e16c2f3 1314 } else if (
mbed_official 35:a8484e16c2f3 1315 (int_sts0 & USB_FUNCTION_BITDVST) &&
mbed_official 35:a8484e16c2f3 1316 (int_enb0 & USB_FUNCTION_BITDVSE)) {
mbed_official 46:378357d7e90d 1317 USB20X.INTSTS0 = (uint16_t)~USB_FUNCTION_BITDVST;
mbed_official 35:a8484e16c2f3 1318 switch (int_sts0 & USB_FUNCTION_BITDVSQ) {
mbed_official 35:a8484e16c2f3 1319 case USB_FUNCTION_DS_POWR:
mbed_official 35:a8484e16c2f3 1320 break;
mbed_official 35:a8484e16c2f3 1321
mbed_official 35:a8484e16c2f3 1322 case USB_FUNCTION_DS_DFLT:
mbed_official 35:a8484e16c2f3 1323 /*****************************************************************************
mbed_official 46:378357d7e90d 1324 * Function Name: usbx_function_USB_FUNCTION_BusReset
mbed_official 35:a8484e16c2f3 1325 * Description : This function is executed when the USB device is transitioned
mbed_official 35:a8484e16c2f3 1326 * : to POWERD_STATE. Sets the device descriptor according to the
mbed_official 35:a8484e16c2f3 1327 * : connection speed determined by the USB reset hand shake.
mbed_official 35:a8484e16c2f3 1328 * Arguments : none
mbed_official 35:a8484e16c2f3 1329 * Return Value : none
mbed_official 35:a8484e16c2f3 1330 *****************************************************************************/
mbed_official 46:378357d7e90d 1331 usbx_function_init_status(); /* memory clear */
mbed_official 35:a8484e16c2f3 1332
mbed_official 35:a8484e16c2f3 1333 #if 0
mbed_official 35:a8484e16c2f3 1334 /* You would program those steps in USBCallback_busReset
mbed_official 35:a8484e16c2f3 1335 * if the system need the comment out steps.
mbed_official 35:a8484e16c2f3 1336 */
mbed_official 35:a8484e16c2f3 1337
mbed_official 46:378357d7e90d 1338 if (usbx_function_is_hispeed() == USB_FUNCTION_HIGH_SPEED) {
mbed_official 35:a8484e16c2f3 1339 /* Device Descriptor reset */
mbed_official 46:378357d7e90d 1340 usbx_function_ResetDescriptor(USB_FUNCTION_HIGH_SPEED);
mbed_official 35:a8484e16c2f3 1341 } else {
mbed_official 35:a8484e16c2f3 1342 /* Device Descriptor reset */
mbed_official 46:378357d7e90d 1343 usbx_function_ResetDescriptor(USB_FUNCTION_FULL_SPEED);
mbed_official 35:a8484e16c2f3 1344 }
mbed_official 35:a8484e16c2f3 1345 #endif
mbed_official 35:a8484e16c2f3 1346 /* Default Control PIPE reset */
mbed_official 35:a8484e16c2f3 1347 /*****************************************************************************
mbed_official 46:378357d7e90d 1348 * Function Name: usbx_function_ResetDCP
mbed_official 35:a8484e16c2f3 1349 * Description : Initializes the default control pipe(DCP).
mbed_official 35:a8484e16c2f3 1350 * Outline : Reset default control pipe
mbed_official 35:a8484e16c2f3 1351 * Arguments : none
mbed_official 35:a8484e16c2f3 1352 * Return Value : none
mbed_official 35:a8484e16c2f3 1353 *****************************************************************************/
mbed_official 46:378357d7e90d 1354 USB20X.DCPCFG = 0;
mbed_official 46:378357d7e90d 1355 USB20X.DCPMAXP = 64; /*TODO: This value is copied from sample*/
mbed_official 35:a8484e16c2f3 1356
mbed_official 46:378357d7e90d 1357 USB20X.CFIFOSEL = (uint16_t)(USB_FUNCTION_BITMBW_8 | USB_FUNCTION_BITBYTE_LITTLE);
mbed_official 46:378357d7e90d 1358 USB20X.D0FIFOSEL = (uint16_t)(USB_FUNCTION_BITMBW_8 | USB_FUNCTION_BITBYTE_LITTLE);
mbed_official 46:378357d7e90d 1359 USB20X.D1FIFOSEL = (uint16_t)(USB_FUNCTION_BITMBW_8 | USB_FUNCTION_BITBYTE_LITTLE);
mbed_official 35:a8484e16c2f3 1360
mbed_official 35:a8484e16c2f3 1361 busReset();
mbed_official 35:a8484e16c2f3 1362 break;
mbed_official 35:a8484e16c2f3 1363
mbed_official 35:a8484e16c2f3 1364 case USB_FUNCTION_DS_ADDS:
mbed_official 35:a8484e16c2f3 1365 break;
mbed_official 35:a8484e16c2f3 1366
mbed_official 35:a8484e16c2f3 1367 case USB_FUNCTION_DS_CNFG:
mbed_official 35:a8484e16c2f3 1368 break;
mbed_official 35:a8484e16c2f3 1369
mbed_official 35:a8484e16c2f3 1370 case USB_FUNCTION_DS_SPD_POWR:
mbed_official 35:a8484e16c2f3 1371 case USB_FUNCTION_DS_SPD_DFLT:
mbed_official 35:a8484e16c2f3 1372 case USB_FUNCTION_DS_SPD_ADDR:
mbed_official 35:a8484e16c2f3 1373 case USB_FUNCTION_DS_SPD_CNFG:
mbed_official 35:a8484e16c2f3 1374 suspendStateChanged(0);
mbed_official 46:378357d7e90d 1375 /*usbx_function_USB_FUNCTION_Suspend();*/
mbed_official 35:a8484e16c2f3 1376 break;
mbed_official 35:a8484e16c2f3 1377
mbed_official 35:a8484e16c2f3 1378 default:
mbed_official 35:a8484e16c2f3 1379 break;
mbed_official 35:a8484e16c2f3 1380 }
mbed_official 35:a8484e16c2f3 1381 } else if (
mbed_official 35:a8484e16c2f3 1382 (int_sts0 & USB_FUNCTION_BITBEMP) &&
mbed_official 35:a8484e16c2f3 1383 (int_enb0 & USB_FUNCTION_BITBEMP) &&
mbed_official 46:378357d7e90d 1384 ((int_sts3 & int_enb4) & g_usbx_function_bit_set[USB_FUNCTION_PIPE0])) {
mbed_official 35:a8484e16c2f3 1385 /* ==== BEMP PIPE0 ==== */
mbed_official 46:378357d7e90d 1386 usbx_function_BEMPInterruptPIPE0(int_sts3, int_enb4, this, &USBHAL::EP0in);
mbed_official 35:a8484e16c2f3 1387 } else if (
mbed_official 35:a8484e16c2f3 1388 (int_sts0 & USB_FUNCTION_BITBRDY) &&
mbed_official 35:a8484e16c2f3 1389 (int_enb0 & USB_FUNCTION_BITBRDY) &&
mbed_official 46:378357d7e90d 1390 ((int_sts1 & int_enb2) & g_usbx_function_bit_set[USB_FUNCTION_PIPE0])) {
mbed_official 35:a8484e16c2f3 1391 /* ==== BRDY PIPE0 ==== */
mbed_official 46:378357d7e90d 1392 usbx_function_BRDYInterruptPIPE0(int_sts1, int_enb2, this, &USBHAL::EP0out);
mbed_official 35:a8484e16c2f3 1393 } else if (
mbed_official 35:a8484e16c2f3 1394 (int_sts0 & USB_FUNCTION_BITNRDY) &&
mbed_official 35:a8484e16c2f3 1395 (int_enb0 & USB_FUNCTION_BITNRDY) &&
mbed_official 46:378357d7e90d 1396 ((int_sts2 & int_enb3) & g_usbx_function_bit_set[USB_FUNCTION_PIPE0])) {
mbed_official 35:a8484e16c2f3 1397 /* ==== NRDY PIPE0 ==== */
mbed_official 46:378357d7e90d 1398 usbx_function_NRDYInterruptPIPE0(int_sts2, int_enb3, this, NULL);
mbed_official 35:a8484e16c2f3 1399 } else if (
mbed_official 35:a8484e16c2f3 1400 (int_sts0 & USB_FUNCTION_BITCTRT) && (int_enb0 & USB_FUNCTION_BITCTRE)) {
mbed_official 46:378357d7e90d 1401 int_sts0 = USB20X.INTSTS0;
mbed_official 46:378357d7e90d 1402 USB20X.INTSTS0 = (uint16_t)~USB_FUNCTION_BITCTRT;
mbed_official 35:a8484e16c2f3 1403
mbed_official 35:a8484e16c2f3 1404 if (((int_sts0 & USB_FUNCTION_BITCTSQ) == USB_FUNCTION_CS_RDDS) ||
mbed_official 35:a8484e16c2f3 1405 ((int_sts0 & USB_FUNCTION_BITCTSQ) == USB_FUNCTION_CS_WRDS) ||
mbed_official 35:a8484e16c2f3 1406 ((int_sts0 & USB_FUNCTION_BITCTSQ) == USB_FUNCTION_CS_WRND)) {
mbed_official 35:a8484e16c2f3 1407
mbed_official 35:a8484e16c2f3 1408 /* remake EP0 into buffer */
mbed_official 46:378357d7e90d 1409 usbx_function_save_request();
mbed_official 46:378357d7e90d 1410 if ((USB20X.INTSTS0 & USB_FUNCTION_BITVALID) && (
mbed_official 35:a8484e16c2f3 1411 ((int_sts0 & USB_FUNCTION_BITCTSQ) == USB_FUNCTION_CS_RDDS) ||
mbed_official 35:a8484e16c2f3 1412 ((int_sts0 & USB_FUNCTION_BITCTSQ) == USB_FUNCTION_CS_WRDS) ||
mbed_official 35:a8484e16c2f3 1413 ((int_sts0 & USB_FUNCTION_BITCTSQ) == USB_FUNCTION_CS_WRND))) {
mbed_official 35:a8484e16c2f3 1414 /* New SETUP token received */
mbed_official 35:a8484e16c2f3 1415 /* Three dummy reads for cleearing interrupt requests */
mbed_official 46:378357d7e90d 1416 dumy_sts = USB20X.INTSTS0;
mbed_official 46:378357d7e90d 1417 dumy_sts = USB20X.INTSTS0;
mbed_official 46:378357d7e90d 1418 dumy_sts = USB20X.INTSTS0;
mbed_official 35:a8484e16c2f3 1419 return;
mbed_official 35:a8484e16c2f3 1420 }
mbed_official 35:a8484e16c2f3 1421 }
mbed_official 35:a8484e16c2f3 1422
mbed_official 35:a8484e16c2f3 1423 switch (int_sts0 & USB_FUNCTION_BITCTSQ) {
mbed_official 35:a8484e16c2f3 1424 case USB_FUNCTION_CS_IDST:
mbed_official 46:378357d7e90d 1425 if (g_usbx_function_TestModeFlag == DEVDRV_USBF_YES) {
mbed_official 35:a8484e16c2f3 1426 /* ==== Test Mode ==== */
mbed_official 46:378357d7e90d 1427 usbx_function_USB_FUNCTION_TestMode();
mbed_official 35:a8484e16c2f3 1428 }
mbed_official 35:a8484e16c2f3 1429 /* Needs not procedure in this state */
mbed_official 35:a8484e16c2f3 1430 break;
mbed_official 35:a8484e16c2f3 1431
mbed_official 35:a8484e16c2f3 1432 case USB_FUNCTION_CS_RDDS:
mbed_official 35:a8484e16c2f3 1433 /* Reads a setup packet */
mbed_official 35:a8484e16c2f3 1434 EP0setupCallback();
mbed_official 35:a8484e16c2f3 1435 break;
mbed_official 35:a8484e16c2f3 1436
mbed_official 35:a8484e16c2f3 1437 case USB_FUNCTION_CS_WRDS:
mbed_official 35:a8484e16c2f3 1438 /* Original code was the SetDescriptor was called */
mbed_official 35:a8484e16c2f3 1439 EP0setupCallback();
mbed_official 35:a8484e16c2f3 1440 break;
mbed_official 35:a8484e16c2f3 1441
mbed_official 35:a8484e16c2f3 1442 case USB_FUNCTION_CS_WRND:
mbed_official 35:a8484e16c2f3 1443 EP0setupCallback();
mbed_official 35:a8484e16c2f3 1444
mbed_official 35:a8484e16c2f3 1445 /*The EP0setupCallback should finish in successful */
mbed_official 46:378357d7e90d 1446 usbx_function_set_pid_buf(USB_FUNCTION_PIPE0);
mbed_official 35:a8484e16c2f3 1447
mbed_official 46:378357d7e90d 1448 RZA_IO_RegWrite_16(&USB20X.DCPCTR, 1, USB_DCPCTR_CCPL_SHIFT, USB_DCPCTR_CCPL);
mbed_official 35:a8484e16c2f3 1449 break;
mbed_official 35:a8484e16c2f3 1450
mbed_official 35:a8484e16c2f3 1451 case USB_FUNCTION_CS_RDSS:
mbed_official 46:378357d7e90d 1452 RZA_IO_RegWrite_16(&USB20X.DCPCTR, 1, USB_DCPCTR_CCPL_SHIFT, USB_DCPCTR_CCPL);
mbed_official 35:a8484e16c2f3 1453 break;
mbed_official 35:a8484e16c2f3 1454
mbed_official 35:a8484e16c2f3 1455 case USB_FUNCTION_CS_WRSS:
mbed_official 46:378357d7e90d 1456 RZA_IO_RegWrite_16(&USB20X.DCPCTR, 1, USB_DCPCTR_CCPL_SHIFT, USB_DCPCTR_CCPL);
mbed_official 35:a8484e16c2f3 1457 break;
mbed_official 35:a8484e16c2f3 1458
mbed_official 35:a8484e16c2f3 1459 case USB_FUNCTION_CS_SQER:
mbed_official 46:378357d7e90d 1460 usbx_function_set_pid_stall(USB_FUNCTION_PIPE0);
mbed_official 35:a8484e16c2f3 1461 break;
mbed_official 35:a8484e16c2f3 1462
mbed_official 35:a8484e16c2f3 1463 default:
mbed_official 46:378357d7e90d 1464 usbx_function_set_pid_stall(USB_FUNCTION_PIPE0);
mbed_official 35:a8484e16c2f3 1465 break;
mbed_official 35:a8484e16c2f3 1466 }
mbed_official 35:a8484e16c2f3 1467 } else if (
mbed_official 35:a8484e16c2f3 1468 (int_sts0 & USB_FUNCTION_BITBEMP) &&
mbed_official 35:a8484e16c2f3 1469 (int_enb0 & USB_FUNCTION_BITBEMP) &&
mbed_official 35:a8484e16c2f3 1470 (int_sts3 & int_enb4) ) {
mbed_official 35:a8484e16c2f3 1471 /* ==== BEMP PIPEx ==== */
mbed_official 46:378357d7e90d 1472 usbx_function_BEMPInterrupt(int_sts3, int_enb4, this, epCallback);
mbed_official 35:a8484e16c2f3 1473 } else if (
mbed_official 35:a8484e16c2f3 1474 (int_sts0 & USB_FUNCTION_BITBRDY) &&
mbed_official 35:a8484e16c2f3 1475 (int_enb0 & USB_FUNCTION_BITBRDY) &&
mbed_official 35:a8484e16c2f3 1476 (int_sts1 & int_enb2) ) {
mbed_official 35:a8484e16c2f3 1477 /* ==== BRDY PIPEx ==== */
mbed_official 46:378357d7e90d 1478 usbx_function_BRDYInterrupt(int_sts1, int_enb2, this, epCallback);
mbed_official 35:a8484e16c2f3 1479 } else if (
mbed_official 35:a8484e16c2f3 1480 (int_sts0 & USB_FUNCTION_BITNRDY) &&
mbed_official 35:a8484e16c2f3 1481 (int_enb0 & USB_FUNCTION_BITNRDY) &&
mbed_official 35:a8484e16c2f3 1482 (int_sts2 & int_enb3)) {
mbed_official 35:a8484e16c2f3 1483 /* ==== NRDY PIPEx ==== */
mbed_official 46:378357d7e90d 1484 usbx_function_NRDYInterrupt(int_sts2, int_enb3, this, epCallback);
mbed_official 35:a8484e16c2f3 1485 } else {
mbed_official 35:a8484e16c2f3 1486 /* Do Nothing */
mbed_official 35:a8484e16c2f3 1487 }
mbed_official 35:a8484e16c2f3 1488
mbed_official 35:a8484e16c2f3 1489 /* Three dummy reads for cleearing interrupt requests */
mbed_official 46:378357d7e90d 1490 dumy_sts = USB20X.INTSTS0;
mbed_official 46:378357d7e90d 1491 dumy_sts = USB20X.INTSTS1;
mbed_official 35:a8484e16c2f3 1492 }
mbed_official 35:a8484e16c2f3 1493
mbed_official 35:a8484e16c2f3 1494 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1495 #endif
mbed_official 35:a8484e16c2f3 1496 /*************************************************************************/
mbed_official 35:a8484e16c2f3 1497 /*EOF*/