17 #if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
19 #if defined( USB_HOST )
25 #if ( USB_VBUSOVRCUR_PORT != USB_VBUSOVRCUR_PORT_NONE )
31 #define HANDLE_INT( x ) if ( status & x ) { Handle_##x(); status &= ~x; }
33 #define FIFO_TXSTS_HCNUM_MASK 0x78000000
34 #define FIFO_TXSTS_HCNUM_SHIFT 27
36 static void Handle_HcInInt( uint8_t hcnum );
37 static void Handle_HcOutInt( uint8_t hcnum );
38 static void Handle_USB_GINTSTS_DISCONNINT (
void );
39 static void Handle_USB_GINTSTS_HCHINT (
void );
40 static void Handle_USB_GINTSTS_PRTINT (
void );
45 void USB_IRQHandler(
void )
52 status = USBHAL_GetCoreInts();
56 DEBUG_USB_INT_LO_PUTS(
"\nSinT" );
68 DEBUG_USB_INT_LO_PUTS(
"\nUinT" );
75 static void Handle_HcInInt( uint8_t hcnum )
79 uint32_t status, hcchar, eptype;
80 #ifdef DEBUG_USB_INT_HI
85 status = USBHHAL_GetHcInts( hcnum );
86 hcchar =
USB->HC[ hcnum ].CHAR;
89 DEBUG_USB_INT_HI_PUTCHAR(
'i' );
93 USB->HC[ hcnum ].INT = 0xFFFFFFFF;
95 #ifdef DEBUG_USB_INT_HI
105 DEBUG_USB_INT_HI_PUTCHAR(
'c' );
107 hc->xferred = hc->hwXferSize -
111 hc->remaining -= hc->xferred;
121 DEBUG_USB_INT_LO_PUTS(
"StaL" );
127 DEBUG_USB_INT_LO_PUTS(
"BabL" );
130 else if ( ( ( status &
133 ( !( hc->status & HCS_TIMEOUT ) ) )
137 DEBUG_USB_INT_LO_PUTS(
"TglE" );
140 if ( hc->errorCnt < 3 )
142 USBHHAL_HCStart( hcnum );
147 else if ( ( ( status &
151 ( !( hc->status & HCS_TIMEOUT ) ) )
155 DEBUG_USB_INT_LO_PUTS(
"XacT" );
158 if ( hc->errorCnt < 3 )
160 USBHHAL_HCStart( hcnum );
165 else if ( hc->status & HCS_TIMEOUT )
167 DEBUG_USB_INT_HI_PUTCHAR(
't' );
173 #ifdef DEBUG_USB_INT_HI
174 if ( !( ( eptype == HCCHAR_EPTYPE_INTR ) &&
183 if ( eptype == HCCHAR_EPTYPE_CTRL )
184 USBHEP_CtrlEpHandler( hc->ep, result );
186 USBHEP_EpHandler( hc->ep, result );
193 static void Handle_HcOutInt( uint8_t hcnum )
197 uint32_t status, hcchar, eptype;
198 #ifdef DEBUG_USB_INT_HI
203 status = USBHHAL_GetHcInts( hcnum );
204 hcchar =
USB->HC[ hcnum ].CHAR;
207 DEBUG_USB_INT_HI_PUTCHAR(
'o' );
209 if ( status & USB_HC_INT_CHHLTD )
211 USB->HC[ hcnum ].INT = 0xFFFFFFFF;
213 #ifdef DEBUG_USB_INT_HI
222 DEBUG_USB_INT_HI_PUTCHAR(
'c' );
224 hc->xferred = hc->remaining;
232 else if ( status & USB_HC_INT_STALL )
235 DEBUG_USB_INT_LO_PUTS(
"StaL" );
240 DEBUG_USB_INT_LO_PUTS(
"XacT" );
244 USBHHAL_HCStart( hcnum );
250 if ( hc->errorCnt < 3 )
252 USBHHAL_HCStart( hcnum );
259 else if ( hc->status & HCS_TIMEOUT )
261 DEBUG_USB_INT_HI_PUTCHAR(
't' );
267 #ifdef DEBUG_USB_INT_HI
268 if ( !( ( eptype == HCCHAR_EPTYPE_INTR ) &&
277 if ( eptype == HCCHAR_EPTYPE_CTRL )
278 USBHEP_CtrlEpHandler( hc->ep, result );
280 USBHEP_EpHandler( hc->ep, result );
287 static void Handle_USB_GINTSTS_DISCONNINT(
void )
295 USBH_portStatus = H_PORT_DISCONNECTED;
297 USBHHAL_PortReset(
false );
299 for ( i=0; i< NUM_HC_USED + 2; i++ )
301 hcchar =
USB->HC[ i ].CHAR;
302 USBHHAL_HCHalt( i, hcchar );
303 USB->HC[ i ].INT = 0xFFFFFFFF;
305 if ( !hcs[ i ].idle )
311 DEBUG_USB_INT_LO_PUTS(
"\nDisC" );
317 static void Handle_USB_GINTSTS_HCHINT(
void )
320 uint32_t hcints, hcmask;
322 hcints = USBHHAL_GetHostChannelInts();
324 for ( hcnum = 0, hcmask = 1;
325 hcnum < NUM_HC_USED + 2;
326 hcnum++, hcmask <<= 1 )
328 if ( hcints & hcmask )
332 Handle_HcInInt( hcnum );
336 Handle_HcOutInt( hcnum );
346 static void PortResetComplete(
void )
350 DEBUG_USB_INT_LO_PUTCHAR(
'5' );
354 USBH_portStatus = H_PORT_DISCONNECTED;
356 USBHHAL_PortReset(
false );
363 static void PortDebounceComplete(
void )
373 DEBUG_USB_INT_LO_PUTCHAR(
'3' );
379 else if ( ( hprt & _USB_HPRT_PRTSPD_MASK ) == HPRT_F_SPEED )
381 DEBUG_USB_INT_LO_PUTCHAR(
'4' );
388 USBH_portStatus = H_PORT_CONNECTED_RESETTING;
390 USBH_attachTiming[ USBH_attachRetryCount ].resetTime,
392 USBHHAL_PortReset(
true );
396 USBH_portStatus = H_PORT_DISCONNECTED;
403 static void Handle_USB_GINTSTS_PRTINT(
void )
409 DEBUG_USB_INT_LO_PUTCHAR(
'^' );
411 switch ( USBH_portStatus )
413 case H_PORT_DISCONNECTED:
416 ( hprt & USB_HPRT_PRTCONNSTS ) )
418 DEBUG_USB_INT_LO_PUTCHAR(
'2' );
419 USBH_portStatus = H_PORT_CONNECTED_DEBOUNCING;
421 USBH_attachTiming[ USBH_attachRetryCount ].debounceTime,
422 PortDebounceComplete );
426 case H_PORT_CONNECTED_DEBOUNCING:
428 DEBUG_USB_INT_LO_PUTCHAR(
'Y' );
431 case H_PORT_CONNECTED_RESETTING:
435 ( hprt & USB_HPRT_PRTCONNSTS ) )
437 DEBUG_USB_INT_LO_PUTCHAR(
'6' );
438 USBH_portStatus = H_PORT_CONNECTED;
442 case H_PORT_CONNECTED:
444 if ( ( hprt & USB_HPRT_PRTENCHNG ) &&
445 ( !( hprt & USB_HPRT_PRTENA ) ) )
447 DEBUG_USB_INT_LO_PUTCHAR(
'X' );
448 #if ( USB_VBUSOVRCUR_PORT != USB_VBUSOVRCUR_PORT_NONE )
449 if (
GPIO_PinInGet( USB_VBUSOVRCUR_PORT, USB_VBUSOVRCUR_PIN ) ==
450 USB_VBUSOVRCUR_POLARITY )
452 DEBUG_USB_INT_LO_PUTCHAR(
'~' );
453 USBHHAL_PortReset(
false );
454 USBHHAL_VbusOn(
false );
456 USBH_portStatus = H_PORT_OVERCURRENT;
462 case H_PORT_OVERCURRENT:
469 DEBUG_USB_INT_LO_PUTCHAR(
'9' );
472 hprt &= ~HPRT_WC_MASK;
#define USB_HPRT_PRTCONNSTS
#define CORE_DECLARE_IRQ_STATE
#define _USB_HC_CHAR_EPTYPE_MASK
void USBTIMER_Stop(uint32_t id)
Stop a timer.
USB protocol stack library API for EFM32/EZR32.
#define USB_HPRT_PRTENCHNG
int USB_PRINTF(const char *format,...)
Transmit "printf" formated data on the debug serial port.
#define _USB_HC_TSIZ_PID_MASK
#define USB_GINTSTS_DISCONNINT
#define USB_HC_INT_BBLERR
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
#define USB_GINTSTS_PRTINT
#define USB_HC_INT_CHHLTD
USB_Status_TypeDef
USB transfer status enumerator.
#define USB_HC_INT_XACTERR
#define CORE_ENTER_ATOMIC()
#define _USB_HPRT_PRTSPD_MASK
General Purpose IO (GPIO) peripheral API.
#define USB_HC_TSIZ_PID_DATA0
USB protocol stack library API for EFM32/EZR32.
Core interrupt handling API.
#define USB_HC_CHAR_EPDIR
#define _USB_HC_TSIZ_XFERSIZE_MASK
#define CORE_EXIT_ATOMIC()
#define USB_GINTSTS_HCHINT
#define _USB_HCFG_FSLSPCLKSEL_SHIFT
#define USB_HC_INT_DATATGLERR
USB protocol stack library, low level USB peripheral access.
#define USB_HC_INT_XFERCOMPL
USB protocol stack library, internal type definitions.
#define USB_HPRT_PRTOVRCURRCHNG
void USBTIMER_Start(uint32_t id, uint32_t timeout, USBTIMER_Callback_TypeDef callback)
Start a timer.
__STATIC_INLINE unsigned int GPIO_PinInGet(GPIO_Port_TypeDef port, unsigned int pin)
Read the pad value for a single pin in a GPIO port.
#define USB_HPRT_PRTCONNDET
#define _USB_HCFG_FSLSPCLKSEL_MASK
#define _USB_HC_TSIZ_XFERSIZE_SHIFT