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