I changed one line of code in the file with path name: USBDeviceHT/targets/TARGET_Maxim

Fork of USBDeviceHT by Helmut Tschemernjak

Committer:
dev_alexander
Date:
Fri Jun 01 21:43:55 2018 +0000
Revision:
6:c1f162fd7777
Parent:
0:a3ea811f80f2
Fixed Error with code not compiling due to an issue with there not being a (uint32_t) cast of a (void) pointer. Maxim was the only mbed vendor to not have this one (uint32_t) cast in the spot it was added to. Look into public repos for similar cases.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Helmut64 0:a3ea811f80f2 1 /**************************************************************************//**
Helmut64 0:a3ea811f80f2 2 * @file em_usbdint.c
Helmut64 0:a3ea811f80f2 3 * @brief USB protocol stack library, USB device peripheral interrupt handlers.
Helmut64 0:a3ea811f80f2 4 * @version 3.20.14
Helmut64 0:a3ea811f80f2 5 ******************************************************************************
Helmut64 0:a3ea811f80f2 6 * @section License
Helmut64 0:a3ea811f80f2 7 * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
Helmut64 0:a3ea811f80f2 8 *******************************************************************************
Helmut64 0:a3ea811f80f2 9 *
Helmut64 0:a3ea811f80f2 10 * Licensed under the Apache License, Version 2.0 (the "License");
Helmut64 0:a3ea811f80f2 11 * you may not use this file except in compliance with the License.
Helmut64 0:a3ea811f80f2 12 * You may obtain a copy of the License at
Helmut64 0:a3ea811f80f2 13 *
Helmut64 0:a3ea811f80f2 14 * http://www.apache.org/licenses/LICENSE-2.0
Helmut64 0:a3ea811f80f2 15 *
Helmut64 0:a3ea811f80f2 16 * Unless required by applicable law or agreed to in writing, software
Helmut64 0:a3ea811f80f2 17 * distributed under the License is distributed on an "AS IS" BASIS,
Helmut64 0:a3ea811f80f2 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Helmut64 0:a3ea811f80f2 19 * See the License for the specific language governing permissions and
Helmut64 0:a3ea811f80f2 20 * limitations under the License.
Helmut64 0:a3ea811f80f2 21 *
Helmut64 0:a3ea811f80f2 22 ******************************************************************************/
Helmut64 0:a3ea811f80f2 23
Helmut64 0:a3ea811f80f2 24 #include "em_device.h"
Helmut64 0:a3ea811f80f2 25 #if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
Helmut64 0:a3ea811f80f2 26 #include "em_usb.h"
Helmut64 0:a3ea811f80f2 27 #if defined( USB_DEVICE )
Helmut64 0:a3ea811f80f2 28
Helmut64 0:a3ea811f80f2 29 #include "em_cmu.h"
Helmut64 0:a3ea811f80f2 30 #include "em_core.h"
Helmut64 0:a3ea811f80f2 31 #include "em_usbtypes.h"
Helmut64 0:a3ea811f80f2 32 #include "em_usbhal.h"
Helmut64 0:a3ea811f80f2 33 #include "em_usbd.h"
Helmut64 0:a3ea811f80f2 34
Helmut64 0:a3ea811f80f2 35 #ifdef __MBED__
Helmut64 0:a3ea811f80f2 36 extern void usbhal_allow_em2(bool em2_allow);
Helmut64 0:a3ea811f80f2 37 #endif
Helmut64 0:a3ea811f80f2 38
Helmut64 0:a3ea811f80f2 39 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
Helmut64 0:a3ea811f80f2 40
Helmut64 0:a3ea811f80f2 41 #define HANDLE_INT( x ) if ( status & x ) { Handle_##x(); status &= ~x; }
Helmut64 0:a3ea811f80f2 42
Helmut64 0:a3ea811f80f2 43 static void Handle_USB_GINTSTS_ENUMDONE ( void );
Helmut64 0:a3ea811f80f2 44 static void Handle_USB_GINTSTS_IEPINT ( void );
Helmut64 0:a3ea811f80f2 45 static void Handle_USB_GINTSTS_OEPINT ( void );
Helmut64 0:a3ea811f80f2 46 static void Handle_USB_GINTSTS_RESETDET ( void );
Helmut64 0:a3ea811f80f2 47 static void Handle_USB_GINTSTS_SOF ( void );
Helmut64 0:a3ea811f80f2 48 static void Handle_USB_GINTSTS_USBRST ( void );
Helmut64 0:a3ea811f80f2 49 static void Handle_USB_GINTSTS_USBSUSP ( void );
Helmut64 0:a3ea811f80f2 50 static void Handle_USB_GINTSTS_WKUPINT ( void );
Helmut64 0:a3ea811f80f2 51 #if defined( USB_DOEP0INT_STUPPKTRCVD )
Helmut64 0:a3ea811f80f2 52 static void HandleOutEpIntr( uint32_t status, USBD_Ep_TypeDef *ep );
Helmut64 0:a3ea811f80f2 53 #else
Helmut64 0:a3ea811f80f2 54 static void ProcessSetup ( void );
Helmut64 0:a3ea811f80f2 55 static void ProcessOepData ( USBD_Ep_TypeDef *ep );
Helmut64 0:a3ea811f80f2 56 #endif
Helmut64 0:a3ea811f80f2 57
Helmut64 0:a3ea811f80f2 58 #if ( USB_PWRSAVE_MODE )
Helmut64 0:a3ea811f80f2 59 /* Variables and prototypes for USB powerdown (suspend) functionality. */
Helmut64 0:a3ea811f80f2 60 static bool UsbPowerDown( void );
Helmut64 0:a3ea811f80f2 61 static bool UsbPowerUp( void );
Helmut64 0:a3ea811f80f2 62
Helmut64 0:a3ea811f80f2 63 volatile bool USBD_poweredDown = false;
Helmut64 0:a3ea811f80f2 64
Helmut64 0:a3ea811f80f2 65 /* Storage for backing up USB core registers. */
Helmut64 0:a3ea811f80f2 66 static uint32_t x_USB_GINTMSK;
Helmut64 0:a3ea811f80f2 67 #if defined(_USB_GOTGCTL_MASK)
Helmut64 0:a3ea811f80f2 68 static uint32_t x_USB_GOTGCTL;
Helmut64 0:a3ea811f80f2 69 #endif
Helmut64 0:a3ea811f80f2 70 static uint32_t x_USB_GAHBCFG;
Helmut64 0:a3ea811f80f2 71 static uint32_t x_USB_GUSBCFG;
Helmut64 0:a3ea811f80f2 72 static uint32_t x_USB_GRXFSIZ;
Helmut64 0:a3ea811f80f2 73 static uint32_t x_USB_GNPTXFSIZ;
Helmut64 0:a3ea811f80f2 74 static uint32_t x_USB_DCFG;
Helmut64 0:a3ea811f80f2 75 static uint32_t x_USB_DCTL;
Helmut64 0:a3ea811f80f2 76 static uint32_t x_USB_DAINTMSK;
Helmut64 0:a3ea811f80f2 77 static uint32_t x_USB_DIEPMSK;
Helmut64 0:a3ea811f80f2 78 static uint32_t x_USB_DOEPMSK;
Helmut64 0:a3ea811f80f2 79 static uint32_t x_USB_PCGCCTL;
Helmut64 0:a3ea811f80f2 80
Helmut64 0:a3ea811f80f2 81 #if ( NUM_EP_USED > 0 )
Helmut64 0:a3ea811f80f2 82 static uint32_t x_USB_EP_CTL[ NUM_EP_USED ];
Helmut64 0:a3ea811f80f2 83 static uint32_t x_USB_EP_TSIZ[ NUM_EP_USED ];
Helmut64 0:a3ea811f80f2 84 static uint32_t x_USB_EP_DMAADDR[ NUM_EP_USED ];
Helmut64 0:a3ea811f80f2 85 #endif
Helmut64 0:a3ea811f80f2 86
Helmut64 0:a3ea811f80f2 87 #if ( NUM_EP_USED > MAX_NUM_TX_FIFOS )
Helmut64 0:a3ea811f80f2 88 #define FIFO_CNT MAX_NUM_TX_FIFOS
Helmut64 0:a3ea811f80f2 89 #else
Helmut64 0:a3ea811f80f2 90 #define FIFO_CNT NUM_EP_USED
Helmut64 0:a3ea811f80f2 91 #endif
Helmut64 0:a3ea811f80f2 92
Helmut64 0:a3ea811f80f2 93 #if ( FIFO_CNT > 0 )
Helmut64 0:a3ea811f80f2 94 static uint32_t x_USB_DIEPTXFS[ FIFO_CNT ];
Helmut64 0:a3ea811f80f2 95 #endif
Helmut64 0:a3ea811f80f2 96
Helmut64 0:a3ea811f80f2 97 #if ( USB_PWRSAVE_MODE )
Helmut64 0:a3ea811f80f2 98 static uint32_t cmuStatus = 0;
Helmut64 0:a3ea811f80f2 99 #endif
Helmut64 0:a3ea811f80f2 100
Helmut64 0:a3ea811f80f2 101 #endif /* if ( USB_PWRSAVE_MODE ) */
Helmut64 0:a3ea811f80f2 102
Helmut64 0:a3ea811f80f2 103 /*
Helmut64 0:a3ea811f80f2 104 * USB_IRQHandler() is the first level handler for the USB peripheral interrupt.
Helmut64 0:a3ea811f80f2 105 */
Helmut64 0:a3ea811f80f2 106 void USB_IRQHandler( void )
Helmut64 0:a3ea811f80f2 107 {
Helmut64 0:a3ea811f80f2 108 uint32_t status;
Helmut64 0:a3ea811f80f2 109 bool servedVbusInterrupt = false;
Helmut64 0:a3ea811f80f2 110 CORE_DECLARE_IRQ_STATE;
Helmut64 0:a3ea811f80f2 111
Helmut64 0:a3ea811f80f2 112 CORE_ENTER_CRITICAL();
Helmut64 0:a3ea811f80f2 113
Helmut64 0:a3ea811f80f2 114 #if ( USB_PWRSAVE_MODE )
Helmut64 0:a3ea811f80f2 115 if ( USBD_poweredDown )
Helmut64 0:a3ea811f80f2 116 {
Helmut64 0:a3ea811f80f2 117 /* Switch USBC clock from 32kHz to a 48MHz clock to be able to */
Helmut64 0:a3ea811f80f2 118 /* read USB peripheral registers. */
Helmut64 0:a3ea811f80f2 119 /* If we woke up from EM2, HFCLK is now HFRCO. */
Helmut64 0:a3ea811f80f2 120
Helmut64 0:a3ea811f80f2 121 /* Restore clock oscillators.*/
Helmut64 0:a3ea811f80f2 122 #if defined( CMU_OSCENCMD_USHFRCOEN )
Helmut64 0:a3ea811f80f2 123 if ( ( CMU->STATUS & CMU_STATUS_USHFRCOENS ) == 0 )/*Wakeup from EM2 ?*/
Helmut64 0:a3ea811f80f2 124 {
Helmut64 0:a3ea811f80f2 125 CMU->OSCENCMD = ( cmuStatus
Helmut64 0:a3ea811f80f2 126 & ( CMU_STATUS_AUXHFRCOENS | CMU_STATUS_HFXOENS ) )
Helmut64 0:a3ea811f80f2 127 | CMU_OSCENCMD_USHFRCOEN;
Helmut64 0:a3ea811f80f2 128 }
Helmut64 0:a3ea811f80f2 129 #else
Helmut64 0:a3ea811f80f2 130 if ( ( CMU->STATUS & CMU_STATUS_HFXOENS ) == 0 ) /* Wakeup from EM2 ? */
Helmut64 0:a3ea811f80f2 131 {
Helmut64 0:a3ea811f80f2 132 CMU->OSCENCMD = cmuStatus
Helmut64 0:a3ea811f80f2 133 & ( CMU_STATUS_AUXHFRCOENS | CMU_STATUS_HFXOENS );
Helmut64 0:a3ea811f80f2 134 }
Helmut64 0:a3ea811f80f2 135 #endif
Helmut64 0:a3ea811f80f2 136
Helmut64 0:a3ea811f80f2 137 /* Select correct USBC clock.*/
Helmut64 0:a3ea811f80f2 138 #if defined( CMU_OSCENCMD_USHFRCOEN )
Helmut64 0:a3ea811f80f2 139 CMU->CMD = CMU_CMD_USBCCLKSEL_USHFRCO;
Helmut64 0:a3ea811f80f2 140 while ( ( CMU->STATUS & CMU_STATUS_USBCUSHFRCOSEL ) == 0 ){}
Helmut64 0:a3ea811f80f2 141 #else
Helmut64 0:a3ea811f80f2 142 CMU->CMD = CMU_CMD_USBCCLKSEL_HFCLKNODIV;
Helmut64 0:a3ea811f80f2 143 while ( ( CMU->STATUS & CMU_STATUS_USBCHFCLKSEL ) == 0 ){}
Helmut64 0:a3ea811f80f2 144 #endif
Helmut64 0:a3ea811f80f2 145 }
Helmut64 0:a3ea811f80f2 146 #endif /* if ( USB_PWRSAVE_MODE ) */
Helmut64 0:a3ea811f80f2 147
Helmut64 0:a3ea811f80f2 148 if ( USB->IF && ( USB->CTRL & USB_CTRL_VREGOSEN ) )
Helmut64 0:a3ea811f80f2 149 {
Helmut64 0:a3ea811f80f2 150 if ( USB->IF & USB_IF_VREGOSH )
Helmut64 0:a3ea811f80f2 151 {
Helmut64 0:a3ea811f80f2 152 USB->IFC = USB_IFC_VREGOSH;
Helmut64 0:a3ea811f80f2 153
Helmut64 0:a3ea811f80f2 154 if ( USB->STATUS & USB_STATUS_VREGOS )
Helmut64 0:a3ea811f80f2 155 {
Helmut64 0:a3ea811f80f2 156 servedVbusInterrupt = true;
Helmut64 0:a3ea811f80f2 157 DEBUG_USB_INT_LO_PUTS( "\nVboN" );
Helmut64 0:a3ea811f80f2 158
Helmut64 0:a3ea811f80f2 159 #if ( USB_PWRSAVE_MODE )
Helmut64 0:a3ea811f80f2 160 if ( UsbPowerUp() )
Helmut64 0:a3ea811f80f2 161 {
Helmut64 0:a3ea811f80f2 162 USBDHAL_EnableUsbResetAndSuspendInt();
Helmut64 0:a3ea811f80f2 163 }
Helmut64 0:a3ea811f80f2 164 USBD_SetUsbState( USBD_STATE_POWERED );
Helmut64 0:a3ea811f80f2 165 #endif
Helmut64 0:a3ea811f80f2 166 }
Helmut64 0:a3ea811f80f2 167 }
Helmut64 0:a3ea811f80f2 168
Helmut64 0:a3ea811f80f2 169 if ( USB->IF & USB_IF_VREGOSL )
Helmut64 0:a3ea811f80f2 170 {
Helmut64 0:a3ea811f80f2 171 USB->IFC = USB_IFC_VREGOSL;
Helmut64 0:a3ea811f80f2 172
Helmut64 0:a3ea811f80f2 173 if ( ( USB->STATUS & USB_STATUS_VREGOS ) == 0 )
Helmut64 0:a3ea811f80f2 174 {
Helmut64 0:a3ea811f80f2 175 servedVbusInterrupt = true;
Helmut64 0:a3ea811f80f2 176 DEBUG_USB_INT_LO_PUTS( "\nVboF" );
Helmut64 0:a3ea811f80f2 177
Helmut64 0:a3ea811f80f2 178 #if ( USB_PWRSAVE_MODE )
Helmut64 0:a3ea811f80f2 179 #if ( USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF )
Helmut64 0:a3ea811f80f2 180 if ( !USBD_poweredDown )
Helmut64 0:a3ea811f80f2 181 {
Helmut64 0:a3ea811f80f2 182 USB->GINTMSK = 0;
Helmut64 0:a3ea811f80f2 183 USB->GINTSTS = 0xFFFFFFFF;
Helmut64 0:a3ea811f80f2 184 }
Helmut64 0:a3ea811f80f2 185
Helmut64 0:a3ea811f80f2 186 UsbPowerDown();
Helmut64 0:a3ea811f80f2 187 #endif
Helmut64 0:a3ea811f80f2 188 USBD_SetUsbState( USBD_STATE_NONE );
Helmut64 0:a3ea811f80f2 189 #endif
Helmut64 0:a3ea811f80f2 190 }
Helmut64 0:a3ea811f80f2 191 }
Helmut64 0:a3ea811f80f2 192 }
Helmut64 0:a3ea811f80f2 193
Helmut64 0:a3ea811f80f2 194 status = USBHAL_GetCoreInts();
Helmut64 0:a3ea811f80f2 195 if ( status == 0 )
Helmut64 0:a3ea811f80f2 196 {
Helmut64 0:a3ea811f80f2 197 CORE_EXIT_CRITICAL();
Helmut64 0:a3ea811f80f2 198 if ( !servedVbusInterrupt )
Helmut64 0:a3ea811f80f2 199 {
Helmut64 0:a3ea811f80f2 200 DEBUG_USB_INT_LO_PUTS( "\nSinT" );
Helmut64 0:a3ea811f80f2 201 }
Helmut64 0:a3ea811f80f2 202 return;
Helmut64 0:a3ea811f80f2 203 }
Helmut64 0:a3ea811f80f2 204
Helmut64 0:a3ea811f80f2 205 HANDLE_INT( USB_GINTSTS_RESETDET )
Helmut64 0:a3ea811f80f2 206 HANDLE_INT( USB_GINTSTS_WKUPINT )
Helmut64 0:a3ea811f80f2 207 HANDLE_INT( USB_GINTSTS_USBSUSP )
Helmut64 0:a3ea811f80f2 208 HANDLE_INT( USB_GINTSTS_SOF )
Helmut64 0:a3ea811f80f2 209 HANDLE_INT( USB_GINTSTS_ENUMDONE )
Helmut64 0:a3ea811f80f2 210 HANDLE_INT( USB_GINTSTS_USBRST )
Helmut64 0:a3ea811f80f2 211 HANDLE_INT( USB_GINTSTS_IEPINT )
Helmut64 0:a3ea811f80f2 212 HANDLE_INT( USB_GINTSTS_OEPINT )
Helmut64 0:a3ea811f80f2 213
Helmut64 0:a3ea811f80f2 214 CORE_EXIT_CRITICAL();
Helmut64 0:a3ea811f80f2 215
Helmut64 0:a3ea811f80f2 216 if ( status != 0 )
Helmut64 0:a3ea811f80f2 217 {
Helmut64 0:a3ea811f80f2 218 DEBUG_USB_INT_LO_PUTS( "\nUinT" );
Helmut64 0:a3ea811f80f2 219 }
Helmut64 0:a3ea811f80f2 220 }
Helmut64 0:a3ea811f80f2 221
Helmut64 0:a3ea811f80f2 222 /*
Helmut64 0:a3ea811f80f2 223 * Handle port enumeration interrupt. This has nothing to do with normal
Helmut64 0:a3ea811f80f2 224 * device enumeration.
Helmut64 0:a3ea811f80f2 225 */
Helmut64 0:a3ea811f80f2 226 static void Handle_USB_GINTSTS_ENUMDONE( void )
Helmut64 0:a3ea811f80f2 227 {
Helmut64 0:a3ea811f80f2 228 #if ( USB_PWRSAVE_MODE )
Helmut64 0:a3ea811f80f2 229 UsbPowerUp();
Helmut64 0:a3ea811f80f2 230 #endif
Helmut64 0:a3ea811f80f2 231
Helmut64 0:a3ea811f80f2 232 USBDHAL_Ep0Activate( dev->ep0MpsCode );
Helmut64 0:a3ea811f80f2 233 dev->ep[ 0 ].state = D_EP_IDLE;
Helmut64 0:a3ea811f80f2 234 USBDHAL_EnableInts( dev );
Helmut64 0:a3ea811f80f2 235 DEBUG_USB_INT_LO_PUTS( "EnumD" );
Helmut64 0:a3ea811f80f2 236 }
Helmut64 0:a3ea811f80f2 237
Helmut64 0:a3ea811f80f2 238 /*
Helmut64 0:a3ea811f80f2 239 * Handle IN endpoint transfer interrupt.
Helmut64 0:a3ea811f80f2 240 */
Helmut64 0:a3ea811f80f2 241 static void Handle_USB_GINTSTS_IEPINT( void )
Helmut64 0:a3ea811f80f2 242 {
Helmut64 0:a3ea811f80f2 243 int epnum;
Helmut64 0:a3ea811f80f2 244 uint16_t epint;
Helmut64 0:a3ea811f80f2 245 uint16_t epmask;
Helmut64 0:a3ea811f80f2 246 uint32_t status;
Helmut64 0:a3ea811f80f2 247 USBD_Ep_TypeDef *ep;
Helmut64 0:a3ea811f80f2 248
Helmut64 0:a3ea811f80f2 249 DEBUG_USB_INT_HI_PUTCHAR( 'i' );
Helmut64 0:a3ea811f80f2 250
Helmut64 0:a3ea811f80f2 251 epint = USBDHAL_GetAllInEpInts();
Helmut64 0:a3ea811f80f2 252 for ( epnum = 0, epmask = 1;
Helmut64 0:a3ea811f80f2 253 epnum <= MAX_NUM_IN_EPS;
Helmut64 0:a3ea811f80f2 254 epnum++, epmask <<= 1 )
Helmut64 0:a3ea811f80f2 255 {
Helmut64 0:a3ea811f80f2 256 if ( epint & epmask )
Helmut64 0:a3ea811f80f2 257 {
Helmut64 0:a3ea811f80f2 258 ep = USBD_GetEpFromAddr( USB_SETUP_DIR_MASK | epnum );
Helmut64 0:a3ea811f80f2 259 status = USBDHAL_GetInEpInts( ep );
Helmut64 0:a3ea811f80f2 260
Helmut64 0:a3ea811f80f2 261 if ( status & USB_DIEP_INT_XFERCOMPL )
Helmut64 0:a3ea811f80f2 262 {
Helmut64 0:a3ea811f80f2 263 USB_DINEPS[ epnum ].INT = USB_DIEP_INT_XFERCOMPL;
Helmut64 0:a3ea811f80f2 264
Helmut64 0:a3ea811f80f2 265 DEBUG_USB_INT_HI_PUTCHAR( 'c' );
Helmut64 0:a3ea811f80f2 266
Helmut64 0:a3ea811f80f2 267 if ( epnum == 0 )
Helmut64 0:a3ea811f80f2 268 {
Helmut64 0:a3ea811f80f2 269 if ( ep->remaining > ep->packetSize )
Helmut64 0:a3ea811f80f2 270 {
Helmut64 0:a3ea811f80f2 271 ep->remaining -= ep->packetSize;
Helmut64 0:a3ea811f80f2 272 ep->xferred += ep->packetSize;
Helmut64 0:a3ea811f80f2 273 }
Helmut64 0:a3ea811f80f2 274 else
Helmut64 0:a3ea811f80f2 275 {
Helmut64 0:a3ea811f80f2 276 ep->xferred += ep->remaining;
Helmut64 0:a3ea811f80f2 277 ep->remaining = 0;
Helmut64 0:a3ea811f80f2 278 }
Helmut64 0:a3ea811f80f2 279 USBDEP_Ep0Handler( dev );
Helmut64 0:a3ea811f80f2 280 }
Helmut64 0:a3ea811f80f2 281 else
Helmut64 0:a3ea811f80f2 282 {
Helmut64 0:a3ea811f80f2 283 ep->xferred = ep->remaining -
Helmut64 0:a3ea811f80f2 284 ( ( USB_DINEPS[ epnum ].TSIZ &
Helmut64 0:a3ea811f80f2 285 _USB_DIEP_TSIZ_XFERSIZE_MASK ) >>
Helmut64 0:a3ea811f80f2 286 _USB_DIEP_TSIZ_XFERSIZE_SHIFT );
Helmut64 0:a3ea811f80f2 287 ep->remaining -= ep->xferred;
Helmut64 0:a3ea811f80f2 288
Helmut64 0:a3ea811f80f2 289 USBDEP_EpHandler( ep->addr );
Helmut64 0:a3ea811f80f2 290 #if defined( USB_DOEP0INT_STUPPKTRCVD )
Helmut64 0:a3ea811f80f2 291 if ( USB_DINEPS[ ep->num ].INT & USB_DIEP_INT_NAKINTRPT )
Helmut64 0:a3ea811f80f2 292 {
Helmut64 0:a3ea811f80f2 293 USB_DINEPS[ ep->num ].INT = USB_DIEP_INT_NAKINTRPT;
Helmut64 0:a3ea811f80f2 294 }
Helmut64 0:a3ea811f80f2 295 #endif
Helmut64 0:a3ea811f80f2 296 }
Helmut64 0:a3ea811f80f2 297 }
Helmut64 0:a3ea811f80f2 298 }
Helmut64 0:a3ea811f80f2 299 }
Helmut64 0:a3ea811f80f2 300 }
Helmut64 0:a3ea811f80f2 301
Helmut64 0:a3ea811f80f2 302 /*
Helmut64 0:a3ea811f80f2 303 * Handle OUT endpoint transfer interrupt.
Helmut64 0:a3ea811f80f2 304 */
Helmut64 0:a3ea811f80f2 305 static void Handle_USB_GINTSTS_OEPINT( void )
Helmut64 0:a3ea811f80f2 306 {
Helmut64 0:a3ea811f80f2 307 int epnum;
Helmut64 0:a3ea811f80f2 308 uint16_t epint;
Helmut64 0:a3ea811f80f2 309 uint16_t epmask;
Helmut64 0:a3ea811f80f2 310 uint32_t status;
Helmut64 0:a3ea811f80f2 311 USBD_Ep_TypeDef *ep;
Helmut64 0:a3ea811f80f2 312
Helmut64 0:a3ea811f80f2 313 DEBUG_USB_INT_HI_PUTCHAR( 'o' );
Helmut64 0:a3ea811f80f2 314
Helmut64 0:a3ea811f80f2 315 epint = USBDHAL_GetAllOutEpInts();
Helmut64 0:a3ea811f80f2 316 for ( epnum = 0, epmask = 1;
Helmut64 0:a3ea811f80f2 317 epnum <= MAX_NUM_OUT_EPS;
Helmut64 0:a3ea811f80f2 318 epnum++, epmask <<= 1 )
Helmut64 0:a3ea811f80f2 319 {
Helmut64 0:a3ea811f80f2 320 if ( epint & epmask )
Helmut64 0:a3ea811f80f2 321 {
Helmut64 0:a3ea811f80f2 322 ep = USBD_GetEpFromAddr( epnum );
Helmut64 0:a3ea811f80f2 323 status = USBDHAL_GetOutEpInts( ep );
Helmut64 0:a3ea811f80f2 324
Helmut64 0:a3ea811f80f2 325 #if defined( USB_DOEP0INT_STUPPKTRCVD )
Helmut64 0:a3ea811f80f2 326 HandleOutEpIntr( status, ep );
Helmut64 0:a3ea811f80f2 327 #else
Helmut64 0:a3ea811f80f2 328 if ( status & USB_DOEP_INT_XFERCOMPL )
Helmut64 0:a3ea811f80f2 329 {
Helmut64 0:a3ea811f80f2 330 USB_DOUTEPS[ epnum ].INT = USB_DOEP_INT_XFERCOMPL;
Helmut64 0:a3ea811f80f2 331 DEBUG_USB_INT_HI_PUTCHAR( 'c' );
Helmut64 0:a3ea811f80f2 332 ProcessOepData( ep );
Helmut64 0:a3ea811f80f2 333 }
Helmut64 0:a3ea811f80f2 334
Helmut64 0:a3ea811f80f2 335 /* Setup Phase Done */
Helmut64 0:a3ea811f80f2 336 if ( status & USB_DOEP0INT_SETUP )
Helmut64 0:a3ea811f80f2 337 {
Helmut64 0:a3ea811f80f2 338 ProcessSetup();
Helmut64 0:a3ea811f80f2 339 }
Helmut64 0:a3ea811f80f2 340 #endif
Helmut64 0:a3ea811f80f2 341 }
Helmut64 0:a3ea811f80f2 342 }
Helmut64 0:a3ea811f80f2 343 }
Helmut64 0:a3ea811f80f2 344
Helmut64 0:a3ea811f80f2 345 #if !defined( USB_DOEP0INT_STUPPKTRCVD )
Helmut64 0:a3ea811f80f2 346 static void ProcessOepData( USBD_Ep_TypeDef *ep )
Helmut64 0:a3ea811f80f2 347 {
Helmut64 0:a3ea811f80f2 348 if ( ep->num == 0 )
Helmut64 0:a3ea811f80f2 349 {
Helmut64 0:a3ea811f80f2 350
Helmut64 0:a3ea811f80f2 351 #ifdef __MBED__
Helmut64 0:a3ea811f80f2 352 int xfer_size = ep->packetSize - (( USB->DOEP0TSIZ & _USB_DOEP0TSIZ_XFERSIZE_MASK )
Helmut64 0:a3ea811f80f2 353 >> _USB_DOEP0TSIZ_XFERSIZE_SHIFT);
Helmut64 0:a3ea811f80f2 354 int setup_pkt_received = USBDHAL_GetOutEpInts( ep ) & USB_DOEP0INT_SETUP;
Helmut64 0:a3ea811f80f2 355
Helmut64 0:a3ea811f80f2 356 if ( (!setup_pkt_received && xfer_size == 0) ||
Helmut64 0:a3ea811f80f2 357 (setup_pkt_received && xfer_size == 8) )
Helmut64 0:a3ea811f80f2 358 {
Helmut64 0:a3ea811f80f2 359 /* Higher levels need to see the correct transfer amount for ZLPs */
Helmut64 0:a3ea811f80f2 360 ep->remaining = 0;
Helmut64 0:a3ea811f80f2 361 ep->xferred = 0;
Helmut64 0:a3ea811f80f2 362 }
Helmut64 0:a3ea811f80f2 363 else
Helmut64 0:a3ea811f80f2 364 {
Helmut64 0:a3ea811f80f2 365 /* FIXME - does not work if actual read size > 56 */
Helmut64 0:a3ea811f80f2 366 if ( setup_pkt_received ) xfer_size -= 8;
Helmut64 0:a3ea811f80f2 367
Helmut64 0:a3ea811f80f2 368 ep->xferred = xfer_size;
Helmut64 0:a3ea811f80f2 369 ep->remaining -= xfer_size;
Helmut64 0:a3ea811f80f2 370 }
Helmut64 0:a3ea811f80f2 371 #else
Helmut64 0:a3ea811f80f2 372 if ( ep->remaining > ep->packetSize )
Helmut64 0:a3ea811f80f2 373 {
Helmut64 0:a3ea811f80f2 374 ep->remaining -= ep->packetSize;
Helmut64 0:a3ea811f80f2 375 ep->xferred += ep->packetSize;
Helmut64 0:a3ea811f80f2 376 }
Helmut64 0:a3ea811f80f2 377 else
Helmut64 0:a3ea811f80f2 378 {
Helmut64 0:a3ea811f80f2 379 ep->xferred += ep->remaining;
Helmut64 0:a3ea811f80f2 380 ep->remaining = 0;
Helmut64 0:a3ea811f80f2 381 }
Helmut64 0:a3ea811f80f2 382 #endif
Helmut64 0:a3ea811f80f2 383
Helmut64 0:a3ea811f80f2 384 USBDEP_Ep0Handler( dev );
Helmut64 0:a3ea811f80f2 385 }
Helmut64 0:a3ea811f80f2 386 else
Helmut64 0:a3ea811f80f2 387 {
Helmut64 0:a3ea811f80f2 388 ep->xferred = ep->hwXferSize -
Helmut64 0:a3ea811f80f2 389 ( ( USB_DOUTEPS[ ep->num ].TSIZ & _USB_DOEP_TSIZ_XFERSIZE_MASK )>>
Helmut64 0:a3ea811f80f2 390 _USB_DOEP_TSIZ_XFERSIZE_SHIFT );
Helmut64 0:a3ea811f80f2 391 ep->remaining -= ep->xferred;
Helmut64 0:a3ea811f80f2 392 USBDEP_EpHandler( ep->addr );
Helmut64 0:a3ea811f80f2 393 }
Helmut64 0:a3ea811f80f2 394 }
Helmut64 0:a3ea811f80f2 395 #endif
Helmut64 0:a3ea811f80f2 396
Helmut64 0:a3ea811f80f2 397 #if !defined( USB_DOEP0INT_STUPPKTRCVD )
Helmut64 0:a3ea811f80f2 398 static void ProcessSetup( void )
Helmut64 0:a3ea811f80f2 399 {
Helmut64 0:a3ea811f80f2 400 DEBUG_USB_INT_LO_PUTS( "\nS" );
Helmut64 0:a3ea811f80f2 401
Helmut64 0:a3ea811f80f2 402 if ( USB->DOEP0INT & USB_DOEP0INT_BACK2BACKSETUP )
Helmut64 0:a3ea811f80f2 403 { /* Back to back setup packets received */
Helmut64 0:a3ea811f80f2 404 USB->DOEP0INT = USB_DOEP0INT_BACK2BACKSETUP;
Helmut64 0:a3ea811f80f2 405 DEBUG_USB_INT_LO_PUTS( "B2B" );
Helmut64 0:a3ea811f80f2 406
Helmut64 0:a3ea811f80f2 407 dev->setup = (USB_Setup_TypeDef*)( USB->DOEP0DMAADDR - USB_SETUP_PKT_SIZE );
Helmut64 0:a3ea811f80f2 408 }
Helmut64 0:a3ea811f80f2 409 else
Helmut64 0:a3ea811f80f2 410 {
Helmut64 0:a3ea811f80f2 411 /* Read SETUP packet counter from hw. */
Helmut64 0:a3ea811f80f2 412 int supCnt = ( USB->DOEP0TSIZ & _USB_DOEP0TSIZ_SUPCNT_MASK )
Helmut64 0:a3ea811f80f2 413 >> _USB_DOEP0TSIZ_SUPCNT_SHIFT;
Helmut64 0:a3ea811f80f2 414
Helmut64 0:a3ea811f80f2 415 if ( supCnt == 3 )
Helmut64 0:a3ea811f80f2 416 supCnt = 2;
Helmut64 0:a3ea811f80f2 417
Helmut64 0:a3ea811f80f2 418 dev->setup = &dev->setupPkt[ 2 - supCnt ];
Helmut64 0:a3ea811f80f2 419 }
Helmut64 0:a3ea811f80f2 420 USB->DOEP0TSIZ |= 3 << _USB_DOEP0TSIZ_SUPCNT_SHIFT;
Helmut64 0:a3ea811f80f2 421 USB->DOEP0DMAADDR = (uint32_t)dev->setupPkt;
Helmut64 0:a3ea811f80f2 422 USB->DOEP0INT = USB_DOEP0INT_SETUP;
Helmut64 0:a3ea811f80f2 423
Helmut64 0:a3ea811f80f2 424 USBDEP_Ep0Handler( dev ); /* Call the SETUP handler for EP0 */
Helmut64 0:a3ea811f80f2 425 }
Helmut64 0:a3ea811f80f2 426 #endif
Helmut64 0:a3ea811f80f2 427
Helmut64 0:a3ea811f80f2 428 /*
Helmut64 0:a3ea811f80f2 429 * Handle USB reset detected interrupt in suspend mode.
Helmut64 0:a3ea811f80f2 430 */
Helmut64 0:a3ea811f80f2 431 static void Handle_USB_GINTSTS_RESETDET ( void )
Helmut64 0:a3ea811f80f2 432 {
Helmut64 0:a3ea811f80f2 433 #if ( USB_PWRSAVE_MODE )
Helmut64 0:a3ea811f80f2 434 if ( ! USBD_poweredDown )
Helmut64 0:a3ea811f80f2 435 {
Helmut64 0:a3ea811f80f2 436 USB->GINTSTS = USB_GINTSTS_RESETDET;
Helmut64 0:a3ea811f80f2 437 }
Helmut64 0:a3ea811f80f2 438
Helmut64 0:a3ea811f80f2 439 if ( UsbPowerUp() )
Helmut64 0:a3ea811f80f2 440 {
Helmut64 0:a3ea811f80f2 441 USB->GINTSTS = USB_GINTSTS_RESETDET;
Helmut64 0:a3ea811f80f2 442 }
Helmut64 0:a3ea811f80f2 443
Helmut64 0:a3ea811f80f2 444 #if ( USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF )
Helmut64 0:a3ea811f80f2 445 /* Power down immediately if VBUS is off. */
Helmut64 0:a3ea811f80f2 446 if ( ! ( USB->STATUS & USB_STATUS_VREGOS ) )
Helmut64 0:a3ea811f80f2 447 {
Helmut64 0:a3ea811f80f2 448 UsbPowerDown();
Helmut64 0:a3ea811f80f2 449 }
Helmut64 0:a3ea811f80f2 450 #endif
Helmut64 0:a3ea811f80f2 451
Helmut64 0:a3ea811f80f2 452 #else
Helmut64 0:a3ea811f80f2 453 USB->GINTSTS = USB_GINTSTS_RESETDET;
Helmut64 0:a3ea811f80f2 454 #endif /* if ( USB_PWRSAVE_MODE ) */
Helmut64 0:a3ea811f80f2 455
Helmut64 0:a3ea811f80f2 456 if ( USB->STATUS & USB_STATUS_VREGOS )
Helmut64 0:a3ea811f80f2 457 {
Helmut64 0:a3ea811f80f2 458 USBD_SetUsbState( USBD_STATE_DEFAULT );
Helmut64 0:a3ea811f80f2 459 }
Helmut64 0:a3ea811f80f2 460 else
Helmut64 0:a3ea811f80f2 461 {
Helmut64 0:a3ea811f80f2 462 USBD_SetUsbState( USBD_STATE_NONE );
Helmut64 0:a3ea811f80f2 463 }
Helmut64 0:a3ea811f80f2 464 DEBUG_USB_INT_LO_PUTS( "RsuP\n" );
Helmut64 0:a3ea811f80f2 465 }
Helmut64 0:a3ea811f80f2 466
Helmut64 0:a3ea811f80f2 467 /*
Helmut64 0:a3ea811f80f2 468 * Handle Start Of Frame (SOF) interrupt.
Helmut64 0:a3ea811f80f2 469 */
Helmut64 0:a3ea811f80f2 470 static void Handle_USB_GINTSTS_SOF( void )
Helmut64 0:a3ea811f80f2 471 {
Helmut64 0:a3ea811f80f2 472 USB->GINTSTS = USB_GINTSTS_SOF;
Helmut64 0:a3ea811f80f2 473
Helmut64 0:a3ea811f80f2 474 if ( dev->callbacks->sofInt )
Helmut64 0:a3ea811f80f2 475 {
Helmut64 0:a3ea811f80f2 476 dev->callbacks->sofInt(
Helmut64 0:a3ea811f80f2 477 ( USB->DSTS & _USB_DSTS_SOFFN_MASK ) >> _USB_DSTS_SOFFN_SHIFT );
Helmut64 0:a3ea811f80f2 478 }
Helmut64 0:a3ea811f80f2 479 }
Helmut64 0:a3ea811f80f2 480
Helmut64 0:a3ea811f80f2 481 /*
Helmut64 0:a3ea811f80f2 482 * Handle USB port reset interrupt.
Helmut64 0:a3ea811f80f2 483 */
Helmut64 0:a3ea811f80f2 484 static void Handle_USB_GINTSTS_USBRST( void )
Helmut64 0:a3ea811f80f2 485 {
Helmut64 0:a3ea811f80f2 486 int i;
Helmut64 0:a3ea811f80f2 487
Helmut64 0:a3ea811f80f2 488 DEBUG_USB_INT_LO_PUTS( "ReseT" );
Helmut64 0:a3ea811f80f2 489
Helmut64 0:a3ea811f80f2 490 /* Clear Remote Wakeup Signalling */
Helmut64 0:a3ea811f80f2 491 USB->DCTL &= ~( DCTL_WO_BITMASK | USB_DCTL_RMTWKUPSIG );
Helmut64 0:a3ea811f80f2 492 USBHAL_FlushTxFifo( 0 );
Helmut64 0:a3ea811f80f2 493
Helmut64 0:a3ea811f80f2 494 /* Clear pending interrupts */
Helmut64 0:a3ea811f80f2 495 for ( i = 0; i <= MAX_NUM_IN_EPS; i++ )
Helmut64 0:a3ea811f80f2 496 {
Helmut64 0:a3ea811f80f2 497 USB_DINEPS[ i ].INT = 0xFFFFFFFF;
Helmut64 0:a3ea811f80f2 498 }
Helmut64 0:a3ea811f80f2 499
Helmut64 0:a3ea811f80f2 500 for ( i = 0; i <= MAX_NUM_OUT_EPS; i++ )
Helmut64 0:a3ea811f80f2 501 {
Helmut64 0:a3ea811f80f2 502 USB_DOUTEPS[ i ].INT = 0xFFFFFFFF;
Helmut64 0:a3ea811f80f2 503 }
Helmut64 0:a3ea811f80f2 504
Helmut64 0:a3ea811f80f2 505 USB->DAINTMSK = USB_DAINTMSK_INEPMSK0 | USB_DAINTMSK_OUTEPMSK0;
Helmut64 0:a3ea811f80f2 506 #if defined( USB_DOEPMSK_STSPHSERCVDMSK )
Helmut64 0:a3ea811f80f2 507 USB->DOEPMSK = USB_DOEPMSK_SETUPMSK | USB_DOEPMSK_XFERCOMPLMSK
Helmut64 0:a3ea811f80f2 508 | USB_DOEPMSK_STSPHSERCVDMSK;
Helmut64 0:a3ea811f80f2 509 #else
Helmut64 0:a3ea811f80f2 510 USB->DOEPMSK = USB_DOEPMSK_SETUPMSK | USB_DOEPMSK_XFERCOMPLMSK;
Helmut64 0:a3ea811f80f2 511 #endif
Helmut64 0:a3ea811f80f2 512 USB->DIEPMSK = USB_DIEPMSK_XFERCOMPLMSK;
Helmut64 0:a3ea811f80f2 513
Helmut64 0:a3ea811f80f2 514 /* Reset Device Address */
Helmut64 0:a3ea811f80f2 515 USB->DCFG &= ~_USB_DCFG_DEVADDR_MASK;
Helmut64 0:a3ea811f80f2 516
Helmut64 0:a3ea811f80f2 517 /* Setup EP0 to receive SETUP packets */
Helmut64 0:a3ea811f80f2 518 USBDHAL_StartEp0Setup( dev );
Helmut64 0:a3ea811f80f2 519 USBDHAL_EnableInts( dev );
Helmut64 0:a3ea811f80f2 520
Helmut64 0:a3ea811f80f2 521 if ( dev->callbacks->usbReset )
Helmut64 0:a3ea811f80f2 522 {
Helmut64 0:a3ea811f80f2 523 dev->callbacks->usbReset();
Helmut64 0:a3ea811f80f2 524 }
Helmut64 0:a3ea811f80f2 525
Helmut64 0:a3ea811f80f2 526 USBD_SetUsbState( USBD_STATE_DEFAULT );
Helmut64 0:a3ea811f80f2 527 USBDHAL_AbortAllTransfers( USB_STATUS_DEVICE_RESET );
Helmut64 0:a3ea811f80f2 528 }
Helmut64 0:a3ea811f80f2 529
Helmut64 0:a3ea811f80f2 530 /*
Helmut64 0:a3ea811f80f2 531 * Handle USB port suspend interrupt.
Helmut64 0:a3ea811f80f2 532 */
Helmut64 0:a3ea811f80f2 533 static void Handle_USB_GINTSTS_USBSUSP( void )
Helmut64 0:a3ea811f80f2 534 {
Helmut64 0:a3ea811f80f2 535 USBD_State_TypeDef state;
Helmut64 0:a3ea811f80f2 536
Helmut64 0:a3ea811f80f2 537 USB->GINTSTS = USB_GINTSTS_USBSUSP;
Helmut64 0:a3ea811f80f2 538 USBDHAL_AbortAllTransfers( USB_STATUS_DEVICE_SUSPENDED );
Helmut64 0:a3ea811f80f2 539 DEBUG_USB_INT_LO_PUTS( "\nSusP" );
Helmut64 0:a3ea811f80f2 540
Helmut64 0:a3ea811f80f2 541 if ( USBD_GetUsbState() == USBD_STATE_NONE )
Helmut64 0:a3ea811f80f2 542 {
Helmut64 0:a3ea811f80f2 543 USBD_SetUsbState( USBD_STATE_POWERED );
Helmut64 0:a3ea811f80f2 544 }
Helmut64 0:a3ea811f80f2 545
Helmut64 0:a3ea811f80f2 546 state = USBD_GetUsbState();
Helmut64 0:a3ea811f80f2 547 if ( ( state == USBD_STATE_POWERED ) ||
Helmut64 0:a3ea811f80f2 548 ( state == USBD_STATE_DEFAULT ) ||
Helmut64 0:a3ea811f80f2 549 ( state == USBD_STATE_ADDRESSED ) ||
Helmut64 0:a3ea811f80f2 550 ( state == USBD_STATE_CONFIGURED ) )
Helmut64 0:a3ea811f80f2 551 {
Helmut64 0:a3ea811f80f2 552 #if ( USB_PWRSAVE_MODE )
Helmut64 0:a3ea811f80f2 553 UsbPowerDown();
Helmut64 0:a3ea811f80f2 554 #endif
Helmut64 0:a3ea811f80f2 555 USBD_SetUsbState( USBD_STATE_SUSPENDED );
Helmut64 0:a3ea811f80f2 556 }
Helmut64 0:a3ea811f80f2 557 }
Helmut64 0:a3ea811f80f2 558
Helmut64 0:a3ea811f80f2 559 /*
Helmut64 0:a3ea811f80f2 560 * Handle USB port wakeup interrupt.
Helmut64 0:a3ea811f80f2 561 */
Helmut64 0:a3ea811f80f2 562 static void Handle_USB_GINTSTS_WKUPINT( void )
Helmut64 0:a3ea811f80f2 563 {
Helmut64 0:a3ea811f80f2 564 #if ( USB_PWRSAVE_MODE )
Helmut64 0:a3ea811f80f2 565 if ( ! USBD_poweredDown )
Helmut64 0:a3ea811f80f2 566 {
Helmut64 0:a3ea811f80f2 567 USB->GINTSTS = USB_GINTSTS_WKUPINT;
Helmut64 0:a3ea811f80f2 568 }
Helmut64 0:a3ea811f80f2 569
Helmut64 0:a3ea811f80f2 570 if ( UsbPowerUp() )
Helmut64 0:a3ea811f80f2 571 {
Helmut64 0:a3ea811f80f2 572 USB->GINTSTS = USB_GINTSTS_WKUPINT;
Helmut64 0:a3ea811f80f2 573 USBDHAL_StartEp0Setup( dev );
Helmut64 0:a3ea811f80f2 574 USBDHAL_Ep0Activate( dev->ep0MpsCode );
Helmut64 0:a3ea811f80f2 575 }
Helmut64 0:a3ea811f80f2 576 #else
Helmut64 0:a3ea811f80f2 577 USB->GINTSTS = USB_GINTSTS_WKUPINT;
Helmut64 0:a3ea811f80f2 578 #endif
Helmut64 0:a3ea811f80f2 579
Helmut64 0:a3ea811f80f2 580 USBD_SetUsbState( dev->savedState );
Helmut64 0:a3ea811f80f2 581 DEBUG_USB_INT_LO_PUTS( "WkuP\n" );
Helmut64 0:a3ea811f80f2 582 }
Helmut64 0:a3ea811f80f2 583
Helmut64 0:a3ea811f80f2 584 #if ( USB_PWRSAVE_MODE )
Helmut64 0:a3ea811f80f2 585 /*
Helmut64 0:a3ea811f80f2 586 * Backup essential USB core registers, and set the core in partial powerdown
Helmut64 0:a3ea811f80f2 587 * mode. Optionally prepare entry into EM2.
Helmut64 0:a3ea811f80f2 588 */
Helmut64 0:a3ea811f80f2 589 static bool UsbPowerDown( void )
Helmut64 0:a3ea811f80f2 590 {
Helmut64 0:a3ea811f80f2 591 #if ( NUM_EP_USED > 0 ) || ( FIFO_CNT > 0 )
Helmut64 0:a3ea811f80f2 592 int i;
Helmut64 0:a3ea811f80f2 593 #endif
Helmut64 0:a3ea811f80f2 594 #if ( NUM_EP_USED > 0 )
Helmut64 0:a3ea811f80f2 595 int epNum;
Helmut64 0:a3ea811f80f2 596 USBD_Ep_TypeDef *ep;
Helmut64 0:a3ea811f80f2 597 #endif
Helmut64 0:a3ea811f80f2 598
Helmut64 0:a3ea811f80f2 599 if ( !USBD_poweredDown )
Helmut64 0:a3ea811f80f2 600 {
Helmut64 0:a3ea811f80f2 601 USBD_poweredDown = true;
Helmut64 0:a3ea811f80f2 602 DEBUG_USB_INT_LO_PUTCHAR( '\\' );
Helmut64 0:a3ea811f80f2 603
Helmut64 0:a3ea811f80f2 604 /* Backup USB core registers. */
Helmut64 0:a3ea811f80f2 605 x_USB_GINTMSK = USB->GINTMSK;
Helmut64 0:a3ea811f80f2 606 #if defined(_USB_GOTGCTL_MASK)
Helmut64 0:a3ea811f80f2 607 x_USB_GOTGCTL = USB->GOTGCTL;
Helmut64 0:a3ea811f80f2 608 #endif
Helmut64 0:a3ea811f80f2 609 x_USB_GAHBCFG = USB->GAHBCFG;
Helmut64 0:a3ea811f80f2 610 x_USB_GUSBCFG = USB->GUSBCFG;
Helmut64 0:a3ea811f80f2 611 x_USB_GRXFSIZ = USB->GRXFSIZ;
Helmut64 0:a3ea811f80f2 612 x_USB_GNPTXFSIZ = USB->GNPTXFSIZ;
Helmut64 0:a3ea811f80f2 613 x_USB_DCFG = USB->DCFG;
Helmut64 0:a3ea811f80f2 614 x_USB_DCTL = USB->DCTL;
Helmut64 0:a3ea811f80f2 615 x_USB_DAINTMSK = USB->DAINTMSK;
Helmut64 0:a3ea811f80f2 616 x_USB_DIEPMSK = USB->DIEPMSK;
Helmut64 0:a3ea811f80f2 617 x_USB_DOEPMSK = USB->DOEPMSK;
Helmut64 0:a3ea811f80f2 618 x_USB_PCGCCTL = USB->PCGCCTL;
Helmut64 0:a3ea811f80f2 619
Helmut64 0:a3ea811f80f2 620 #if ( NUM_EP_USED > 0 )
Helmut64 0:a3ea811f80f2 621 for ( i = 0; i < NUM_EP_USED; i++ )
Helmut64 0:a3ea811f80f2 622 {
Helmut64 0:a3ea811f80f2 623 ep = &dev->ep[ i+1 ];
Helmut64 0:a3ea811f80f2 624 epNum = ep->num;
Helmut64 0:a3ea811f80f2 625 if ( ep->in )
Helmut64 0:a3ea811f80f2 626 {
Helmut64 0:a3ea811f80f2 627 x_USB_EP_CTL[ i ] = USB_DINEPS[ epNum ].CTL;
Helmut64 0:a3ea811f80f2 628 x_USB_EP_TSIZ[ i ] = USB_DINEPS[ epNum ].TSIZ;
Helmut64 0:a3ea811f80f2 629 x_USB_EP_DMAADDR[ i ] = USB_DINEPS[ epNum ].DMAADDR;
Helmut64 0:a3ea811f80f2 630 }
Helmut64 0:a3ea811f80f2 631 else
Helmut64 0:a3ea811f80f2 632 {
Helmut64 0:a3ea811f80f2 633 x_USB_EP_CTL[ i ] = USB_DOUTEPS[ epNum ].CTL;
Helmut64 0:a3ea811f80f2 634 x_USB_EP_TSIZ[ i ] = USB_DOUTEPS[ epNum ].TSIZ;
Helmut64 0:a3ea811f80f2 635 x_USB_EP_DMAADDR[ i ] = USB_DOUTEPS[ epNum ].DMAADDR;
Helmut64 0:a3ea811f80f2 636 }
Helmut64 0:a3ea811f80f2 637 }
Helmut64 0:a3ea811f80f2 638 #endif
Helmut64 0:a3ea811f80f2 639
Helmut64 0:a3ea811f80f2 640 #if ( FIFO_CNT > 0 )
Helmut64 0:a3ea811f80f2 641 for ( i = 0; i < FIFO_CNT; i++ )
Helmut64 0:a3ea811f80f2 642 {
Helmut64 0:a3ea811f80f2 643 x_USB_DIEPTXFS[ i ] = USB_DIEPTXFS[ i ];
Helmut64 0:a3ea811f80f2 644 }
Helmut64 0:a3ea811f80f2 645 #endif
Helmut64 0:a3ea811f80f2 646
Helmut64 0:a3ea811f80f2 647 /* Prepare for wakeup on resume and reset. */
Helmut64 0:a3ea811f80f2 648 USB->DCFG = (USB->DCFG & ~_USB_DCFG_RESVALID_MASK) |
Helmut64 0:a3ea811f80f2 649 (4 << _USB_DCFG_RESVALID_SHIFT);
Helmut64 0:a3ea811f80f2 650 USB->DCFG |= USB_DCFG_ENA32KHZSUSP;
Helmut64 0:a3ea811f80f2 651 USB->GINTMSK = USB_GINTMSK_RESETDETMSK | USB_GINTMSK_WKUPINTMSK;
Helmut64 0:a3ea811f80f2 652
Helmut64 0:a3ea811f80f2 653 /* Enter partial powerdown mode. */
Helmut64 0:a3ea811f80f2 654 USB->PCGCCTL |= USB_PCGCCTL_PWRCLMP;
Helmut64 0:a3ea811f80f2 655 USB->PCGCCTL |= USB_PCGCCTL_RSTPDWNMODULE;
Helmut64 0:a3ea811f80f2 656 USB->PCGCCTL |= USB_PCGCCTL_STOPPCLK;
Helmut64 0:a3ea811f80f2 657
Helmut64 0:a3ea811f80f2 658 /* Record current clock settings. */
Helmut64 0:a3ea811f80f2 659 cmuStatus = CMU->STATUS;
Helmut64 0:a3ea811f80f2 660
Helmut64 0:a3ea811f80f2 661 #if ( USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ENTEREM2 )
Helmut64 0:a3ea811f80f2 662 #ifndef __MBED__
Helmut64 0:a3ea811f80f2 663 /* Enter EM2 on interrupt exit. */
Helmut64 0:a3ea811f80f2 664 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk;
Helmut64 0:a3ea811f80f2 665 #else
Helmut64 0:a3ea811f80f2 666 usbhal_allow_em2(true);
Helmut64 0:a3ea811f80f2 667 #endif
Helmut64 0:a3ea811f80f2 668 #endif
Helmut64 0:a3ea811f80f2 669
Helmut64 0:a3ea811f80f2 670 /* Switch USBC clock to 32 kHz. */
Helmut64 0:a3ea811f80f2 671 #if ( USB_USBC_32kHz_CLK == USB_USBC_32kHz_CLK_LFXO )
Helmut64 0:a3ea811f80f2 672 CMU->CMD = CMU_CMD_USBCCLKSEL_LFXO;
Helmut64 0:a3ea811f80f2 673 while ( ( CMU->STATUS & CMU_STATUS_USBCLFXOSEL ) == 0 ){}
Helmut64 0:a3ea811f80f2 674 #else
Helmut64 0:a3ea811f80f2 675 CMU->CMD = CMU_CMD_USBCCLKSEL_LFRCO;
Helmut64 0:a3ea811f80f2 676 while ( ( CMU->STATUS & CMU_STATUS_USBCLFRCOSEL ) == 0 ){}
Helmut64 0:a3ea811f80f2 677 #endif
Helmut64 0:a3ea811f80f2 678
Helmut64 0:a3ea811f80f2 679 return true;
Helmut64 0:a3ea811f80f2 680 }
Helmut64 0:a3ea811f80f2 681 return false;
Helmut64 0:a3ea811f80f2 682 }
Helmut64 0:a3ea811f80f2 683 #endif /* if ( USB_PWRSAVE_MODE ) */
Helmut64 0:a3ea811f80f2 684
Helmut64 0:a3ea811f80f2 685 #if ( USB_PWRSAVE_MODE )
Helmut64 0:a3ea811f80f2 686 /*
Helmut64 0:a3ea811f80f2 687 * Exit USB core partial powerdown mode, restore essential USB core registers.
Helmut64 0:a3ea811f80f2 688 * Will prevent re-entry back to EM2.
Helmut64 0:a3ea811f80f2 689 * Returns true if a powerup sequence was performed.
Helmut64 0:a3ea811f80f2 690 */
Helmut64 0:a3ea811f80f2 691 static bool UsbPowerUp( void )
Helmut64 0:a3ea811f80f2 692 {
Helmut64 0:a3ea811f80f2 693 #if ( NUM_EP_USED > 0 ) || ( FIFO_CNT > 0 )
Helmut64 0:a3ea811f80f2 694 int i;
Helmut64 0:a3ea811f80f2 695 #endif
Helmut64 0:a3ea811f80f2 696 #if ( NUM_EP_USED > 0 )
Helmut64 0:a3ea811f80f2 697 int epNum;
Helmut64 0:a3ea811f80f2 698 uint32_t tmp;
Helmut64 0:a3ea811f80f2 699 USBD_Ep_TypeDef *ep;
Helmut64 0:a3ea811f80f2 700 #endif
Helmut64 0:a3ea811f80f2 701
Helmut64 0:a3ea811f80f2 702 if ( USBD_poweredDown )
Helmut64 0:a3ea811f80f2 703 {
Helmut64 0:a3ea811f80f2 704 USBD_poweredDown = false;
Helmut64 0:a3ea811f80f2 705 DEBUG_USB_INT_LO_PUTCHAR( '/' );
Helmut64 0:a3ea811f80f2 706
Helmut64 0:a3ea811f80f2 707 #if !defined( USB_CORECLK_HFRCO ) || !defined( CMU_OSCENCMD_USHFRCOEN )
Helmut64 0:a3ea811f80f2 708 /* Switch HFCLK from HFRCO to HFXO. */
Helmut64 0:a3ea811f80f2 709 CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO );
Helmut64 0:a3ea811f80f2 710 #endif
Helmut64 0:a3ea811f80f2 711
Helmut64 0:a3ea811f80f2 712 /* Turn off HFRCO when not needed. */
Helmut64 0:a3ea811f80f2 713 if ( ( cmuStatus & CMU_STATUS_HFRCOENS ) == 0 )
Helmut64 0:a3ea811f80f2 714 {
Helmut64 0:a3ea811f80f2 715 CMU->OSCENCMD = CMU_OSCENCMD_HFRCODIS;
Helmut64 0:a3ea811f80f2 716 }
Helmut64 0:a3ea811f80f2 717
Helmut64 0:a3ea811f80f2 718 /* Exit partial powerdown mode. */
Helmut64 0:a3ea811f80f2 719 USB->PCGCCTL &= ~USB_PCGCCTL_STOPPCLK;
Helmut64 0:a3ea811f80f2 720 USB->PCGCCTL &= ~(USB_PCGCCTL_PWRCLMP | USB_PCGCCTL_RSTPDWNMODULE);
Helmut64 0:a3ea811f80f2 721
Helmut64 0:a3ea811f80f2 722 if (( USB->GINTSTS & ( USB_GINTSTS_WKUPINT | USB_GINTSTS_RESETDET ) ) == 0)
Helmut64 0:a3ea811f80f2 723 {
Helmut64 0:a3ea811f80f2 724 USB->DCTL = x_USB_DCTL | USB_DCTL_RMTWKUPSIG;
Helmut64 0:a3ea811f80f2 725 USB->DCTL = x_USB_DCTL;
Helmut64 0:a3ea811f80f2 726 }
Helmut64 0:a3ea811f80f2 727
Helmut64 0:a3ea811f80f2 728 /* Restore USB core registers. */
Helmut64 0:a3ea811f80f2 729 USB->GUSBCFG = x_USB_GUSBCFG;
Helmut64 0:a3ea811f80f2 730 USB->DCFG = x_USB_DCFG;
Helmut64 0:a3ea811f80f2 731
Helmut64 0:a3ea811f80f2 732 #if ( FIFO_CNT > 0 )
Helmut64 0:a3ea811f80f2 733 for ( i = 0; i < FIFO_CNT; i++ )
Helmut64 0:a3ea811f80f2 734 {
Helmut64 0:a3ea811f80f2 735 USB_DIEPTXFS[ i ] = x_USB_DIEPTXFS[ i ];
Helmut64 0:a3ea811f80f2 736 }
Helmut64 0:a3ea811f80f2 737 #endif
Helmut64 0:a3ea811f80f2 738
Helmut64 0:a3ea811f80f2 739 #if ( NUM_EP_USED > 0 )
Helmut64 0:a3ea811f80f2 740 for ( i = 0; i < NUM_EP_USED; i++ )
Helmut64 0:a3ea811f80f2 741 {
Helmut64 0:a3ea811f80f2 742 ep = &dev->ep[ i+1 ];
Helmut64 0:a3ea811f80f2 743 epNum = ep->num;
Helmut64 0:a3ea811f80f2 744
Helmut64 0:a3ea811f80f2 745 tmp = x_USB_EP_CTL[ i ] &
Helmut64 0:a3ea811f80f2 746 ~( USB_DIEP_CTL_CNAK | USB_DIEP_CTL_SNAK |
Helmut64 0:a3ea811f80f2 747 USB_DIEP_CTL_SETD0PIDEF | USB_DIEP_CTL_SETD1PIDOF );
Helmut64 0:a3ea811f80f2 748
Helmut64 0:a3ea811f80f2 749 if ( x_USB_EP_CTL[ i ] & USB_DIEP_CTL_DPIDEOF )
Helmut64 0:a3ea811f80f2 750 tmp |= USB_DIEP_CTL_SETD1PIDOF;
Helmut64 0:a3ea811f80f2 751 else
Helmut64 0:a3ea811f80f2 752 tmp |= USB_DIEP_CTL_SETD0PIDEF;
Helmut64 0:a3ea811f80f2 753
Helmut64 0:a3ea811f80f2 754 if ( x_USB_EP_CTL[ i ] & USB_DIEP_CTL_NAKSTS )
Helmut64 0:a3ea811f80f2 755 tmp |= USB_DIEP_CTL_SNAK;
Helmut64 0:a3ea811f80f2 756 else
Helmut64 0:a3ea811f80f2 757 tmp |= USB_DIEP_CTL_CNAK;
Helmut64 0:a3ea811f80f2 758
Helmut64 0:a3ea811f80f2 759 if ( ep->in )
Helmut64 0:a3ea811f80f2 760 {
Helmut64 0:a3ea811f80f2 761 USB_DINEPS[ epNum ].CTL = tmp;
Helmut64 0:a3ea811f80f2 762 USB_DINEPS[ epNum ].TSIZ = x_USB_EP_TSIZ[ i ];
Helmut64 0:a3ea811f80f2 763 USB_DINEPS[ epNum ].DMAADDR = x_USB_EP_DMAADDR[ i ];
Helmut64 0:a3ea811f80f2 764 }
Helmut64 0:a3ea811f80f2 765 else
Helmut64 0:a3ea811f80f2 766 {
Helmut64 0:a3ea811f80f2 767 USB_DOUTEPS[ epNum ].CTL = tmp;
Helmut64 0:a3ea811f80f2 768 USB_DOUTEPS[ epNum ].TSIZ = x_USB_EP_TSIZ[ i ];
Helmut64 0:a3ea811f80f2 769 USB_DOUTEPS[ epNum ].DMAADDR = x_USB_EP_DMAADDR[ i ];
Helmut64 0:a3ea811f80f2 770 }
Helmut64 0:a3ea811f80f2 771 }
Helmut64 0:a3ea811f80f2 772 #endif
Helmut64 0:a3ea811f80f2 773
Helmut64 0:a3ea811f80f2 774 USB->PCGCCTL = x_USB_PCGCCTL;
Helmut64 0:a3ea811f80f2 775 USB->DOEPMSK = x_USB_DOEPMSK;
Helmut64 0:a3ea811f80f2 776 USB->DIEPMSK = x_USB_DIEPMSK;
Helmut64 0:a3ea811f80f2 777 USB->DAINTMSK = x_USB_DAINTMSK;
Helmut64 0:a3ea811f80f2 778 USB->DCTL = x_USB_DCTL;
Helmut64 0:a3ea811f80f2 779 USB->GNPTXFSIZ = x_USB_GNPTXFSIZ;
Helmut64 0:a3ea811f80f2 780 USB->GRXFSIZ = x_USB_GRXFSIZ;
Helmut64 0:a3ea811f80f2 781 USB->GAHBCFG = x_USB_GAHBCFG;
Helmut64 0:a3ea811f80f2 782 #if defined(_USB_GOTGCTL_MASK)
Helmut64 0:a3ea811f80f2 783 USB->GOTGCTL = x_USB_GOTGCTL;
Helmut64 0:a3ea811f80f2 784 #endif
Helmut64 0:a3ea811f80f2 785 USB->GINTMSK = x_USB_GINTMSK;
Helmut64 0:a3ea811f80f2 786
Helmut64 0:a3ea811f80f2 787 USB->DCTL |= USB_DCTL_PWRONPRGDONE;
Helmut64 0:a3ea811f80f2 788
Helmut64 0:a3ea811f80f2 789 #if ( USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ENTEREM2 )
Helmut64 0:a3ea811f80f2 790 #ifndef __MBED__
Helmut64 0:a3ea811f80f2 791 /* Do not reenter EM2 on interrupt exit. */
Helmut64 0:a3ea811f80f2 792 SCB->SCR &= ~(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk);
Helmut64 0:a3ea811f80f2 793 #else
Helmut64 0:a3ea811f80f2 794 usbhal_allow_em2(false);
Helmut64 0:a3ea811f80f2 795 #endif
Helmut64 0:a3ea811f80f2 796 #endif
Helmut64 0:a3ea811f80f2 797
Helmut64 0:a3ea811f80f2 798 return true;
Helmut64 0:a3ea811f80f2 799 }
Helmut64 0:a3ea811f80f2 800 return false;
Helmut64 0:a3ea811f80f2 801 }
Helmut64 0:a3ea811f80f2 802 #endif /* if ( USB_PWRSAVE_MODE ) */
Helmut64 0:a3ea811f80f2 803
Helmut64 0:a3ea811f80f2 804 #if defined( USB_DOEP0INT_STUPPKTRCVD )
Helmut64 0:a3ea811f80f2 805 static void HandleOutEpIntr( uint32_t status, USBD_Ep_TypeDef *ep )
Helmut64 0:a3ea811f80f2 806 {
Helmut64 0:a3ea811f80f2 807 uint32_t doeptsiz;
Helmut64 0:a3ea811f80f2 808
Helmut64 0:a3ea811f80f2 809 if ( ep->num == 0 )
Helmut64 0:a3ea811f80f2 810 {
Helmut64 0:a3ea811f80f2 811 if ( status & USB_DOEP0INT_XFERCOMPL )
Helmut64 0:a3ea811f80f2 812 {
Helmut64 0:a3ea811f80f2 813 USB->DOEP0INT = USB_DOEP0INT_XFERCOMPL;
Helmut64 0:a3ea811f80f2 814 doeptsiz = USB->DOEP0TSIZ;
Helmut64 0:a3ea811f80f2 815
Helmut64 0:a3ea811f80f2 816 if ( ep->state == D_EP_IDLE )
Helmut64 0:a3ea811f80f2 817 {
Helmut64 0:a3ea811f80f2 818 if ( status & USB_DOEP0INT_STUPPKTRCVD )
Helmut64 0:a3ea811f80f2 819 {
Helmut64 0:a3ea811f80f2 820 USB->DOEP0INT = USB_DOEP0INT_STUPPKTRCVD;
Helmut64 0:a3ea811f80f2 821 }
Helmut64 0:a3ea811f80f2 822 status = USBDHAL_GetOutEpInts( ep );
Helmut64 0:a3ea811f80f2 823 doeptsiz = USB->DOEP0TSIZ;
Helmut64 0:a3ea811f80f2 824
Helmut64 0:a3ea811f80f2 825 if ( status & USB_DOEP0INT_SETUP )
Helmut64 0:a3ea811f80f2 826 {
Helmut64 0:a3ea811f80f2 827 retry:
Helmut64 0:a3ea811f80f2 828 /* Already started data stage, clear setup */
Helmut64 0:a3ea811f80f2 829 USB->DOEP0INT = USB_DOEP0INT_SETUP;
Helmut64 0:a3ea811f80f2 830 status &= ~USB_DOEP0INT_SETUP;
Helmut64 0:a3ea811f80f2 831 {
Helmut64 0:a3ea811f80f2 832 int supCnt = ( doeptsiz & _USB_DOEP0TSIZ_SUPCNT_MASK )
Helmut64 0:a3ea811f80f2 833 >> _USB_DOEP0TSIZ_SUPCNT_SHIFT;
Helmut64 0:a3ea811f80f2 834
Helmut64 0:a3ea811f80f2 835 if ( supCnt == 3 )
Helmut64 0:a3ea811f80f2 836 supCnt = 2;
Helmut64 0:a3ea811f80f2 837
Helmut64 0:a3ea811f80f2 838 dev->setup = &dev->setupPkt[ 2 - supCnt ];
Helmut64 0:a3ea811f80f2 839 }
Helmut64 0:a3ea811f80f2 840 DEBUG_USB_INT_LO_PUTS( "\nS" );
Helmut64 0:a3ea811f80f2 841 USBDEP_Ep0Handler( dev );
Helmut64 0:a3ea811f80f2 842
Helmut64 0:a3ea811f80f2 843 /* Prepare for more setup packets */
Helmut64 0:a3ea811f80f2 844 if ( ep->state == D_EP0_IN_STATUS || ep->state == D_EP_TRANSMITTING )
Helmut64 0:a3ea811f80f2 845 {
Helmut64 0:a3ea811f80f2 846 USBDHAL_StartEp0Setup( dev );
Helmut64 0:a3ea811f80f2 847 }
Helmut64 0:a3ea811f80f2 848 }
Helmut64 0:a3ea811f80f2 849 else /* xfercompl && idle && !setup */
Helmut64 0:a3ea811f80f2 850 {
Helmut64 0:a3ea811f80f2 851 status = USBDHAL_GetOutEpInts( ep );
Helmut64 0:a3ea811f80f2 852 if ( status & USB_DOEP0INT_SETUP )
Helmut64 0:a3ea811f80f2 853 goto retry;
Helmut64 0:a3ea811f80f2 854 USBDHAL_StartEp0Setup( dev );
Helmut64 0:a3ea811f80f2 855 }
Helmut64 0:a3ea811f80f2 856 }
Helmut64 0:a3ea811f80f2 857 else /* ep0state != EP0_IDLE */
Helmut64 0:a3ea811f80f2 858 {
Helmut64 0:a3ea811f80f2 859 #ifdef __MBED__
Helmut64 0:a3ea811f80f2 860 if ( ep->state == D_EP_RECEIVING )
Helmut64 0:a3ea811f80f2 861 {
Helmut64 0:a3ea811f80f2 862 int xfer_size = ep->packetSize - (( USB->DOEP0TSIZ & _USB_DOEP0TSIZ_XFERSIZE_MASK )
Helmut64 0:a3ea811f80f2 863 >> _USB_DOEP0TSIZ_XFERSIZE_SHIFT);
Helmut64 0:a3ea811f80f2 864 int setup_pkt_received = status & USB_DOEP0INT_SETUP;
Helmut64 0:a3ea811f80f2 865
Helmut64 0:a3ea811f80f2 866 if ( (!setup_pkt_received && xfer_size == 0) ||
Helmut64 0:a3ea811f80f2 867 (setup_pkt_received && xfer_size == 8) )
Helmut64 0:a3ea811f80f2 868 {
Helmut64 0:a3ea811f80f2 869 /* Higher levels need to see the correct transfer amount for ZLPs */
Helmut64 0:a3ea811f80f2 870 ep->remaining = 0;
Helmut64 0:a3ea811f80f2 871 ep->xferred = 0;
Helmut64 0:a3ea811f80f2 872 }
Helmut64 0:a3ea811f80f2 873 else
Helmut64 0:a3ea811f80f2 874 {
Helmut64 0:a3ea811f80f2 875 /* FIXME - does not work if actual read size > 56 */
Helmut64 0:a3ea811f80f2 876 if ( setup_pkt_received ) xfer_size -= 8;
Helmut64 0:a3ea811f80f2 877
Helmut64 0:a3ea811f80f2 878 ep->xferred = xfer_size;
Helmut64 0:a3ea811f80f2 879 ep->remaining -= xfer_size;
Helmut64 0:a3ea811f80f2 880 }
Helmut64 0:a3ea811f80f2 881
Helmut64 0:a3ea811f80f2 882 USBDEP_Ep0Handler( dev );
Helmut64 0:a3ea811f80f2 883 }
Helmut64 0:a3ea811f80f2 884 #else
Helmut64 0:a3ea811f80f2 885 if ( ep->state == D_EP_RECEIVING )
Helmut64 0:a3ea811f80f2 886 {
Helmut64 0:a3ea811f80f2 887 if ( ep->remaining > ep->packetSize )
Helmut64 0:a3ea811f80f2 888 {
Helmut64 0:a3ea811f80f2 889 ep->remaining -= ep->packetSize;
Helmut64 0:a3ea811f80f2 890 ep->xferred += ep->packetSize;
Helmut64 0:a3ea811f80f2 891 }
Helmut64 0:a3ea811f80f2 892 else
Helmut64 0:a3ea811f80f2 893 {
Helmut64 0:a3ea811f80f2 894 ep->xferred += ep->remaining;
Helmut64 0:a3ea811f80f2 895 ep->remaining = 0;
Helmut64 0:a3ea811f80f2 896 }
Helmut64 0:a3ea811f80f2 897 USBDEP_Ep0Handler( dev );
Helmut64 0:a3ea811f80f2 898 }
Helmut64 0:a3ea811f80f2 899 else if ( ep->state == D_EP0_OUT_STATUS )
Helmut64 0:a3ea811f80f2 900 {
Helmut64 0:a3ea811f80f2 901 USBDEP_Ep0Handler( dev );
Helmut64 0:a3ea811f80f2 902 }
Helmut64 0:a3ea811f80f2 903 #endif
Helmut64 0:a3ea811f80f2 904 }
Helmut64 0:a3ea811f80f2 905 } /* if ( status & USB_DOEP0INT_XFERCOMPL ) */
Helmut64 0:a3ea811f80f2 906
Helmut64 0:a3ea811f80f2 907 if ( status & USB_DOEP0INT_STSPHSERCVD )
Helmut64 0:a3ea811f80f2 908 {
Helmut64 0:a3ea811f80f2 909 USB->DOEP0INT = USB_DOEP0INT_STSPHSERCVD;
Helmut64 0:a3ea811f80f2 910 }
Helmut64 0:a3ea811f80f2 911
Helmut64 0:a3ea811f80f2 912 if ( status & USB_DOEP0INT_SETUP )
Helmut64 0:a3ea811f80f2 913 {
Helmut64 0:a3ea811f80f2 914 USB->DOEP0INT = USB_DOEP0INT_SETUP;
Helmut64 0:a3ea811f80f2 915 {
Helmut64 0:a3ea811f80f2 916 int supCnt = ( USB->DOEP0TSIZ & _USB_DOEP0TSIZ_SUPCNT_MASK )
Helmut64 0:a3ea811f80f2 917 >> _USB_DOEP0TSIZ_SUPCNT_SHIFT;
Helmut64 0:a3ea811f80f2 918
Helmut64 0:a3ea811f80f2 919 if ( supCnt == 3 )
Helmut64 0:a3ea811f80f2 920 supCnt = 2;
Helmut64 0:a3ea811f80f2 921
Helmut64 0:a3ea811f80f2 922 dev->setup = &dev->setupPkt[ 2 - supCnt ];
Helmut64 0:a3ea811f80f2 923 }
Helmut64 0:a3ea811f80f2 924 DEBUG_USB_INT_LO_PUTS( "\nS" );
Helmut64 0:a3ea811f80f2 925 USBDEP_Ep0Handler( dev );
Helmut64 0:a3ea811f80f2 926 }
Helmut64 0:a3ea811f80f2 927 }
Helmut64 0:a3ea811f80f2 928 else /* epnum != 0 */
Helmut64 0:a3ea811f80f2 929 {
Helmut64 0:a3ea811f80f2 930 if ( status & USB_DOEP_INT_XFERCOMPL )
Helmut64 0:a3ea811f80f2 931 {
Helmut64 0:a3ea811f80f2 932 USB_DOUTEPS[ ep->num ].INT = USB_DOEP_INT_XFERCOMPL;
Helmut64 0:a3ea811f80f2 933
Helmut64 0:a3ea811f80f2 934 ep->xferred = ep->hwXferSize -
Helmut64 0:a3ea811f80f2 935 ( ( USB_DOUTEPS[ ep->num ].TSIZ & _USB_DOEP_TSIZ_XFERSIZE_MASK )>>
Helmut64 0:a3ea811f80f2 936 _USB_DOEP_TSIZ_XFERSIZE_SHIFT );
Helmut64 0:a3ea811f80f2 937 ep->remaining -= ep->xferred;
Helmut64 0:a3ea811f80f2 938
Helmut64 0:a3ea811f80f2 939 USBDEP_EpHandler( ep->addr );
Helmut64 0:a3ea811f80f2 940 }
Helmut64 0:a3ea811f80f2 941 }
Helmut64 0:a3ea811f80f2 942 }
Helmut64 0:a3ea811f80f2 943 #endif
Helmut64 0:a3ea811f80f2 944
Helmut64 0:a3ea811f80f2 945 /** @endcond */
Helmut64 0:a3ea811f80f2 946
Helmut64 0:a3ea811f80f2 947 #endif /* defined( USB_DEVICE ) */
Helmut64 0:a3ea811f80f2 948 #endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */