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 &
191 ~(GUSBCFG_WO_BITMASK | USB_GUSBCFG_FORCEHSTMODE ) ) |
192 USB_GUSBCFG_FORCEDEVMODE;
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 &
589 ~(GUSBCFG_WO_BITMASK | USB_GUSBCFG_FORCEDEVMODE ) ) |
590 USB_GUSBCFG_FORCEHSTMODE;
597 USB->HCFG = (
USB->HCFG & ~_USB_HCFG_FSLSPCLKSEL_MASK ) |
598 ( 1 << _USB_HCFG_FSLSPCLKSEL_SHIFT ) |
599 ( USB_HCFG_FSLSSUPP );
609 USB->GNPTXFSIZ = ( ( nptxFifoSize <<
614 _USB_GNPTXFSIZ_NPTXFSTADDR_MASK );
616 USB->HPTXFSIZ = ( ( ptxFifoSize << _USB_HPTXFSIZ_PTXFSIZE_SHIFT ) &
617 _USB_HPTXFSIZ_PTXFSIZE_MASK ) |
618 ( ( ( rxFifoSize + nptxFifoSize )
619 << _USB_HPTXFSIZ_PTXFSTADDR_SHIFT ) &
620 _USB_HPTXFSIZ_PTXFSTADDR_MASK );
623 USBHAL_FlushTxFifo( 0x10 );
624 USBHAL_FlushRxFifo();
626 for ( i = 0; i < MAX_NUM_HOSTCHANNELS; i++ )
628 USB->HC[ i ].CHAR = USB_HC_CHAR_CHDIS;
629 USB->HC[ i ].INT = 0xFFFFFFFF;
633 for ( i = 0; i < MAX_NUM_HOSTCHANNELS; i++ )
635 USB->HC[ i ].CHAR |= USB_HC_CHAR_CHDIS | USB_HC_CHAR_CHENA;
638 __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
640 while (
USB->HC[ i ].CHAR & USB_HC_CHAR_CHENA );
644 for ( i = 0; i < MAX_NUM_HOSTCHANNELS; i++ )
646 USB->HC[ i ].INTMSK = 0;
654 void USBHHAL_HCHalt(
int hcnum, uint32_t hcchar )
656 hcchar |= USB_HC_CHAR_CHENA | USB_HC_CHAR_CHDIS;
657 USB->HC[ hcnum ].CHAR = hcchar;
660 void USBHHAL_HCInit(
int hcnum )
664 ep = hcs[ hcnum ].ep;
665 USB->HC[ hcnum ].INT = 0xFFFFFFFF;
672 USB->HC[ hcnum ].INTMSK = USB_HC_INT_CHHLTD;
676 hcs[ hcnum ].errorCnt = 0;
678 USB->HAINTMSK |= 1 << hcnum;
680 USB->HC[ hcnum ].CHAR =
681 ( ep->parentDevice->addr << _USB_HC_CHAR_DEVADDR_SHIFT ) |
683 ( ep->type << _USB_HC_CHAR_EPTYPE_SHIFT ) |
684 ( ep->packetSize << _USB_HC_CHAR_MPS_SHIFT ) |
685 ( ep->in ? USB_HC_CHAR_EPDIR : 0 ) |
686 ( ep->parentDevice->speed ==
687 HPRT_L_SPEED >> _USB_HPRT_PRTSPD_SHIFT
688 ? USB_HC_CHAR_LSPDDEV : 0 );
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 =
721 ( ( len << _USB_HC_TSIZ_XFERSIZE_SHIFT ) &
722 _USB_HC_TSIZ_XFERSIZE_MASK ) |
723 ( ( packets << _USB_HC_TSIZ_PKTCNT_SHIFT ) &
724 _USB_HC_TSIZ_PKTCNT_MASK ) |
725 ( ( hc->ep->toggle << _USB_HC_TSIZ_PID_SHIFT ) &
726 _USB_HC_TSIZ_PID_MASK );
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_GNPTXFSIZ_NPTXFSTADDR_MASK
#define USB_GRSTCTL_CSFTRST
#define USB_STATUS_VREGOS
USB protocol stack library API for EFM32/EZR32.
#define CORE_ATOMIC_IRQ_ENABLE()
#define _USB_DCFG_PERFRINT_MASK
int USB_PRINTF(const char *format,...)
Transmit "printf" formated data on the debug serial port.
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_DIEP_INT_EPDISBLD
#define USB_DCTL_CGOUTNAK
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
#define USB_DCFG_NZSTSOUTHSHK
#define USB_SETUP_DIR_MASK
#define USB_DIEPMSK_INEPNAKEFFMSK
void USBD_Connect(void)
Start USB device operation.
#define USB_DIEP_INT_INEPNAKEFF
char * USB_GetErrorMsgString(int error)
Return an error message string for a given error code.
#define _USB_GAHBCFG_HBSTLEN_MASK
#define CORE_ATOMIC_IRQ_DISABLE()
#define USB_DOEPMSK_EPDISBLDMSK
void USBTIMER_DelayMs(uint32_t msec)
Active wait millisecond delay function. Can also be used inside interrupt handlers.
#define USB_GINTMSK_GOUTNAKEFFMSK
#define USB_GAHBCFG_HBSTLEN_INCR
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_PCGCCTL_PWRCLMP
#define _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_MASK
#define _USB_DIEPTXF1_INEPNTXFDEP_SHIFT
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
Set the mode for a GPIO pin.
#define USB_DCTL_SFTDISCON
General Purpose IO (GPIO) peripheral API.
#define USB_DIEP_CTL_SNAK
#define _USB_GRXFSIZ_RXFDEP_SHIFT
#define _USB_GRXFSIZ_RXFDEP_MASK
USB protocol stack library API for EFM32/EZR32.
Core interrupt handling API.
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
#define USB_GINTSTS_GOUTNAKEFF
#define USB_GAHBCFG_DMAEN
#define _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_SHIFT
#define USB_PCGCCTL_STOPPCLK
USB protocol stack library, low level USB peripheral access.
#define SL_MAX(a, b)
Macro for getting maximum value. No sideeffects, a and b are evaluated once only. ...
#define USB_GRSTCTL_AHBIDLE
void assertEFM(const char *file, int line)
EFM internal assert handling.
USB protocol stack library, internal type definitions.
#define USB_CTRL_VREGOSEN
#define _USB_GNPTXFSIZ_NPTXFSTADDR_SHIFT
#define USB_DOEP_INT_EPDISBLD
#define _USB_DCFG_DEVSPD_MASK
int USB_PUTCHAR(char c)
Transmit a single char on the debug serial port.
#define _USB_DIEPTXF1_INEPNTXFSTADDR_MASK
void USBTIMER_DelayUs(uint32_t usec)
Active wait microsecond delay function. Can also be used inside interrupt handlers.
#define USB_DCTL_IGNRFRMNUM
#define USB_PCGCCTL_RSTPDWNMODULE
#define USB_DCTL_SGOUTNAK