USBDevice for STM support

Dependents:   Nucleo_Usb_JoyMouse Nucleo_usbmouse ELEC350_1-referral-2018-usb-hid USBJoystick_HelloWorld2_wip ... more

This library contains all mbed usb device library (mbed-os\features\unsupported\USBDevice).

Committer:
frq08711@LMECWL0871.LME.ST.COM
Date:
Tue Mar 28 11:00:57 2017 +0200
Branch:
master
Revision:
4:50ec00aa4515
Parent:
1:2a3ae13b45ef
update for 5.4.2

Who changed what in which revision?

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