A copy of the mbed USBDevice with USBSerial library

Dependents:   STM32L0_LoRa Smartage STM32L0_LoRa Turtle_RadioShuttle

Committer:
Helmut Tschemernjak
Date:
Thu Jan 31 20:56:55 2019 +0100
Revision:
7:8a5cc0d9bfa2
Parent:
0:a3ea811f80f2
fixed compiler warnings

Who changed what in which revision?

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