17 #if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
19 #if defined( USB_DEVICE ) || defined( USB_HOST )
23 #if defined( USB_DEVICE )
26 #if defined( USB_HOST )
35 #define EPABORT_BREAK_LOOP_COUNT 15000
39 static const char *
const errMsg[] =
75 return (
char*)errMsg[ 0 ];
77 return (
char*)errMsg[ -error ];
81 #if defined( USB_USE_PRINTF )
113 #if defined( DEBUG_EFM_USER )
114 static void PrintI(
int i )
116 #if !defined ( USER_PUTCHAR )
124 DEBUG_USB_API_PUTCHAR( ( i % 10 ) +
'0' );
128 void assertEFM(
const char *file,
int line )
130 #if !defined ( USER_PUTCHAR )
134 DEBUG_USB_API_PUTS(
"\nASSERT " );
135 DEBUG_USB_API_PUTS( file );
136 DEBUG_USB_API_PUTCHAR(
' ' );
142 #if defined ( USER_PUTCHAR )
143 void USB_Puts(
const char *p )
150 void USBHAL_CoreReset(
void )
166 void USBDHAL_Connect(
void )
172 uint32_t totalTxFifoSize )
175 uint16_t start, depth;
178 #if !defined( USB_VBUS_SWITCH_NOT_PRESENT )
188 #if defined( USB_GUSBCFG_FORCEHSTMODE )
190 USB->GUSBCFG = (
USB->GUSBCFG &
215 start =
SL_MAX( totalRxFifoSize, MIN_EP_FIFO_SIZE_INWORDS );
220 depth =
SL_MAX( dev->ep[ 0 ].fifoSize, MIN_EP_FIFO_SIZE_INWORDS );
228 for ( j = 1; j <= MAX_NUM_TX_FIFOS; j++ )
230 for ( i = 1; i <= MAX_NUM_IN_EPS; i++ )
235 if ( ep->txFifoNum == j )
238 depth =
SL_MAX( ep->fifoSize, MIN_EP_FIFO_SIZE_INWORDS );
239 USB_DIEPTXFS[ ep->txFifoNum - 1 ] =
247 if ( totalRxFifoSize + totalTxFifoSize > MAX_DEVICE_FIFO_SIZE_INWORDS )
250 if ( start > MAX_DEVICE_FIFO_SIZE_INWORDS )
254 USBHAL_FlushTxFifo( 0x10 );
255 USBHAL_FlushRxFifo();
264 for ( i = 0; i <= MAX_NUM_IN_EPS; i++ )
266 USB_DINEPS[ i ].CTL = 0;
267 USB_DINEPS[ i ].TSIZ = 0;
268 USB_DINEPS[ i ].INT = 0xFFFFFFFF;
271 for ( i = 0; i <= MAX_NUM_OUT_EPS; i++ )
273 USB_DOUTEPS[ i ].CTL = 0;
274 USB_DOUTEPS[ i ].TSIZ = 0;
275 USB_DOUTEPS[ i ].INT = 0xFFFFFFFF;
278 #if ( USB_DCTL_SFTDISCON_DEFAULT != 0 )
295 void USBDHAL_Disconnect(
void )
300 void USBDHAL_AbortEpIn( USBD_Ep_TypeDef *ep )
308 USB_DINEPS[ ep->num ].CTL = ( USB_DINEPS[ ep->num ].CTL &
309 ~DEPCTL_WO_BITMASK ) |
317 DEBUG_USB_INT_LO_PUTCHAR(
'.' );
319 USBDHAL_SetEPDISNAK( ep );
324 USBHAL_FlushTxFifo( ep->txFifoNum );
329 DEBUG_USB_INT_LO_PUTCHAR(
'.' );
332 void USBDHAL_AbortEpOut( USBD_Ep_TypeDef *ep )
347 cnt = EPABORT_BREAK_LOOP_COUNT;
356 DEBUG_USB_INT_LO_PUTCHAR(
',' );
358 USBDHAL_SetEPDISNAK( ep );
361 cnt = EPABORT_BREAK_LOOP_COUNT;
376 DEBUG_USB_INT_LO_PUTCHAR(
',' );
379 void USBDHAL_AbortAllEps(
void )
383 uint16_t im, om, inmask=0, outmask=0;
386 for ( i = 1; i <= NUM_EP_USED; i++ )
389 if ( ep->state != D_EP_IDLE )
412 for ( i = 1; i <= NUM_EP_USED; i++ )
417 USB_DINEPS[ ep->num ].CTL = ( USB_DINEPS[ ep->num ].CTL &
418 ~DEPCTL_WO_BITMASK ) |
435 cnt = EPABORT_BREAK_LOOP_COUNT;
448 cnt = EPABORT_BREAK_LOOP_COUNT;
451 for ( i = 1; i <= NUM_EP_USED; i++ )
464 }
while ( im && cnt );
468 DEBUG_USB_INT_LO_PUTCHAR(
'\'' );
471 for ( i = 1; i <= NUM_EP_USED; i++ )
474 if ( ep->state != D_EP_IDLE )
476 USBDHAL_SetEPDISNAK( ep );
483 cnt = EPABORT_BREAK_LOOP_COUNT;
486 for ( i = 1; i <= NUM_EP_USED; i++ )
489 if ( ep->in && ( im & ep->mask ) )
498 if ( !ep->in && ( om & ep->mask ) )
508 }
while ( ( im || om ) && cnt );
513 USBHAL_FlushTxFifo( 0x10 );
523 DEBUG_USB_INT_LO_PUTCHAR(
'\'' );
534 USBDHAL_AbortAllEps();
537 for ( i = 1; i <= NUM_EP_USED; i++ )
540 if ( ep->state != D_EP_IDLE )
542 ep->state = D_EP_IDLE;
543 if ( ep->xferCompleteCb )
545 callback = ep->xferCompleteCb;
546 ep->xferCompleteCb = NULL;
551 USBDHAL_DeactivateEp( ep );
554 DEBUG_TRACE_ABORT( reason );
555 callback( reason, ep->xferred, ep->remaining );
565 #if defined( USB_HOST )
567 uint32_t nptxFifoSize,
568 uint32_t ptxFifoSize )
579 #if ( USB_VBUSOVRCUR_PORT != USB_VBUSOVRCUR_PORT_NONE )
588 USB->GUSBCFG = (
USB->GUSBCFG &
609 USB->GNPTXFSIZ = ( ( nptxFifoSize <<
614 _USB_GNPTXFSIZ_NPTXFSTADDR_MASK );
618 ( ( ( rxFifoSize + nptxFifoSize )
623 USBHAL_FlushTxFifo( 0x10 );
624 USBHAL_FlushRxFifo();
626 for ( i = 0; i < MAX_NUM_HOSTCHANNELS; i++ )
629 USB->HC[ i ].INT = 0xFFFFFFFF;
633 for ( i = 0; i < MAX_NUM_HOSTCHANNELS; i++ )
638 __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
644 for ( i = 0; i < MAX_NUM_HOSTCHANNELS; i++ )
646 USB->HC[ i ].INTMSK = 0;
654 void USBHHAL_HCHalt(
int hcnum, uint32_t hcchar )
657 USB->HC[ hcnum ].CHAR = hcchar;
660 void USBHHAL_HCInit(
int hcnum )
664 ep = hcs[ hcnum ].ep;
665 USB->HC[ hcnum ].INT = 0xFFFFFFFF;
676 hcs[ hcnum ].errorCnt = 0;
678 USB->HAINTMSK |= 1 << hcnum;
680 USB->HC[ hcnum ].CHAR =
691 void USBHHAL_HCStart(
int hcnum )
694 uint16_t packets, len;
700 if ( hc->remaining > 0 )
702 packets = ( hc->remaining + hc->ep->packetSize - 1 ) / hc->ep->packetSize;
711 len = packets * hc->ep->packetSize;
719 hc->hwXferSize = len;
720 USB->HC[ hcnum ].TSIZ =
728 USB->HC[ hcnum ].DMAADDR = (uint32_t)hc->buf;
730 USBHHAL_HCActivate( hcnum,
731 USB->HC[ hcnum ].CHAR,
USB protocol stack library API for EFM32/EZR32.
Clock management unit (CMU) API.
#define USB_DIEPMSK_EPDISBLDMSK
#define USB_DOEP_INT_EPDISBLD
USB protocol stack library API for EFM32/EZR32.
#define _USB_GNPTXFSIZ_NPTXFSTADDR_SHIFT
#define CORE_ATOMIC_IRQ_ENABLE()
#define _USB_DCFG_PERFRINT_MASK
#define _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_SHIFT
#define USB_DIEP_INT_INEPNAKEFF
int USB_PRINTF(const char *format,...)
Transmit "printf" formated data on the debug serial port.
#define USB_DOEPMSK_EPDISBLDMSK
#define USB_DIEP_INT_EPDISBLD
#define _USB_HC_TSIZ_PID_MASK
void USB_PrintErrorMsgString(char *pre, int error)
Format and print a text string given an error code, prepends an optional user supplied leader string...
#define USB_PCGCCTL_RSTPDWNMODULE
#define USB_PCGCCTL_STOPPCLK
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
#define _USB_HC_CHAR_MPS_SHIFT
#define USB_SETUP_DIR_MASK
#define USB_HC_INT_CHHLTD
#define _USB_HC_CHAR_EPTYPE_SHIFT
void USBD_Connect(void)
Start USB device operation.
#define _USB_HC_TSIZ_PKTCNT_SHIFT
char * USB_GetErrorMsgString(int error)
Return an error message string for a given error code.
#define _USB_DCFG_DEVSPD_MASK
#define USB_DCTL_CGOUTNAK
#define _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_MASK
#define CORE_ATOMIC_IRQ_DISABLE()
#define USB_DIEPMSK_INEPNAKEFFMSK
void USBTIMER_DelayMs(uint32_t msec)
Active wait millisecond delay function. Can also be used inside interrupt handlers.
#define USB_DCTL_IGNRFRMNUM
int(* USB_XferCompleteCb_TypeDef)(USB_Status_TypeDef status, uint32_t xferred, uint32_t remaining)
USB transfer callback function.
USB_Status_TypeDef
USB transfer status enumerator.
#define _USB_GRXFSIZ_RXFDEP_SHIFT
#define _USB_GAHBCFG_HBSTLEN_MASK
#define USB_ROUTE_VBUSENPEN
#define _USB_GNPTXFSIZ_NPTXFSTADDR_MASK
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
Set the mode for a GPIO pin.
struct USBH_Device_TypeDef * parentDevice
General Purpose IO (GPIO) peripheral API.
#define USB_GINTMSK_GOUTNAKEFFMSK
#define _USB_HC_CHAR_EPNUM_SHIFT
#define USB_DIEP_CTL_SNAK
#define USB_HC_CHAR_CHENA
#define USB_GUSBCFG_FORCEDEVMODE
#define _USB_HC_CHAR_DEVADDR_SHIFT
USB protocol stack library API for EFM32/EZR32.
#define USB_GAHBCFG_HBSTLEN_INCR
Core interrupt handling API.
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
#define USB_HCFG_FSLSSUPP
#define USB_HC_CHAR_EPDIR
#define _USB_HPTXFSIZ_PTXFSIZE_SHIFT
#define USB_DCTL_SGOUTNAK
#define USB_STATUS_VREGOS
#define _USB_HC_TSIZ_XFERSIZE_MASK
#define USB_DCFG_NZSTSOUTHSHK
#define _USB_HPTXFSIZ_PTXFSIZE_MASK
#define USB_HC_CHAR_LSPDDEV
#define _USB_HC_TSIZ_PKTCNT_MASK
#define USB_CTRL_VREGOSEN
#define USB_GRSTCTL_AHBIDLE
#define _USB_DIEPTXF1_INEPNTXFSTADDR_MASK
#define USB_GINTSTS_GOUTNAKEFF
#define USB_GAHBCFG_DMAEN
#define USB_GRSTCTL_CSFTRST
#define _USB_HPTXFSIZ_PTXFSTADDR_SHIFT
#define _USB_HCFG_FSLSPCLKSEL_SHIFT
#define _USB_HPRT_PRTSPD_SHIFT
USB protocol stack library, low level USB peripheral access.
#define _USB_DIEPTXF1_INEPNTXFDEP_SHIFT
#define SL_MAX(a, b)
Macro for getting maximum value. No sideeffects, a and b are evaluated once only. ...
#define _USB_HPTXFSIZ_PTXFSTADDR_MASK
USB HOST endpoint status data.
void assertEFM(const char *file, int line)
EFM internal assert handling.
USB protocol stack library, internal type definitions.
#define USB_HC_CHAR_CHDIS
#define _USB_HC_TSIZ_PID_SHIFT
#define USB_DCTL_SFTDISCON
int USB_PUTCHAR(char c)
Transmit a single char on the debug serial port.
#define USB_GUSBCFG_FORCEHSTMODE
#define _USB_GRXFSIZ_RXFDEP_MASK
void USBTIMER_DelayUs(uint32_t usec)
Active wait microsecond delay function. Can also be used inside interrupt handlers.
#define USB_PCGCCTL_PWRCLMP
#define _USB_HCFG_FSLSPCLKSEL_MASK
#define _USB_HC_TSIZ_XFERSIZE_SHIFT