17 #if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
19 #if defined( USB_DEVICE ) || defined( USB_HOST )
43 #define USB_TIMER USB_TIMER0
46 #if ( USB_TIMER == USB_TIMER0 ) && ( TIMER_COUNT >= 1 )
48 #define TIMER_CLK cmuClock_TIMER0
49 #define TIMER_IRQ TIMER0_IRQn
50 #define TIMER_IRQHandler TIMER0_IRQHandler
52 #elif ( USB_TIMER == USB_TIMER1 ) && ( TIMER_COUNT >= 2 )
54 #define TIMER_CLK cmuClock_TIMER1
55 #define TIMER_IRQ TIMER1_IRQn
56 #define TIMER_IRQHandler TIMER1_IRQHandler
58 #elif ( USB_TIMER == USB_TIMER2 ) && ( TIMER_COUNT >= 3 )
60 #define TIMER_CLK cmuClock_TIMER2
61 #define TIMER_IRQ TIMER2_IRQn
62 #define TIMER_IRQHandler TIMER2_IRQHandler
64 #elif ( USB_TIMER == USB_TIMER3 ) && ( TIMER_COUNT == 4 )
66 #define TIMER_CLK cmuClock_TIMER3
67 #define TIMER_IRQ TIMER3_IRQn
68 #define TIMER_IRQHandler TIMER3_IRQHandler
71 #error "Illegal USB TIMER definition"
80 } USBTIMER_Timer_TypeDef;
82 #if ( NUM_QTIMERS > 0 )
83 static USBTIMER_Timer_TypeDef timers[ NUM_QTIMERS ];
84 static USBTIMER_Timer_TypeDef *head = NULL;
87 static uint32_t ticksPrMs, ticksPr1us, ticksPr10us, ticksPr100us;
89 #if ( NUM_QTIMERS > 0 )
91 static void TimerTick(
void );
93 void TIMER_IRQHandler(
void )
110 static void DelayTicks( uint16_t ticks )
113 volatile uint16_t now;
121 }
while ( (uint16_t)( now - startTime ) < ticks );
142 totalTicks = (uint64_t)ticksPrMs * msec;
143 while ( totalTicks > 20000 )
148 DelayTicks( (uint16_t)totalTicks );
163 totalTicks = (uint64_t)ticksPr1us * usec;
164 if ( totalTicks == 0 )
167 totalTicks = (uint64_t)ticksPr10us * usec;
169 if ( totalTicks == 0 )
172 totalTicks = (uint64_t)ticksPr100us * usec;
176 while ( totalTicks > 60000 )
181 DelayTicks( (uint16_t)totalTicks );
200 ticksPrMs = ( freq + 500 ) / 1000;
201 ticksPr1us = ( freq + 500000 ) / 1000000;
202 ticksPr10us = ( freq + 50000 ) / 100000;
203 ticksPr100us = ( freq + 5000 ) / 10000;
211 #if ( NUM_QTIMERS > 0 )
215 NVIC_ClearPendingIRQ( TIMER_IRQ );
216 NVIC_EnableIRQ( TIMER_IRQ );
220 #if ( NUM_QTIMERS > 0 ) || defined( DOXY_DOC_ONLY )
240 uint32_t accumulated;
241 USBTIMER_Timer_TypeDef *
this, **last;
246 if ( timers[
id ].running )
258 timers[ id ].running =
true;
259 timers[ id ].callback = callback;
260 timers[ id ].next = NULL;
264 timers[ id ].timeout = timeout;
265 head = &timers[ id ];
276 if ( timeout < accumulated + this->timeout )
278 timers[ id ].timeout = timeout - accumulated;
279 timers[ id ].next =
this;
280 *last = &timers[ id ];
281 this->timeout -= timers[ id ].timeout;
284 else if ( this->next == NULL )
286 timers[ id ].timeout = timeout - accumulated - this->timeout;
287 this->next = &timers[ id ];
290 accumulated += this->timeout;
308 USBTIMER_Timer_TypeDef *
this, **last;
317 timers[ id ].running =
false;
321 if (
this == &timers[
id ] )
325 this->next->timeout += timers[ id ].timeout;
341 #if ( NUM_QTIMERS > 0 )
344 static void TimerTick(
void )
357 if ( head->timeout == 0 )
360 head->running =
false;
Clock management unit (CMU) API.
__STATIC_INLINE void TIMER_TopSet(TIMER_TypeDef *timer, uint32_t val)
Set top value for timer.
#define CORE_DECLARE_IRQ_STATE
void USBTIMER_Stop(uint32_t id)
Stop a timer.
#define TIMER_INITCC_DEFAULT
Timer/counter (TIMER) peripheral API.
__STATIC_INLINE void TIMER_IntClear(TIMER_TypeDef *timer, uint32_t flags)
Clear one or more pending TIMER interrupts.
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
TIMER_CCMode_TypeDef mode
void(* USBTIMER_Callback_TypeDef)(void)
USBTIMER callback function.
__STATIC_INLINE void TIMER_IntEnable(TIMER_TypeDef *timer, uint32_t flags)
Enable one or more TIMER interrupts.
void USBTIMER_DelayMs(uint32_t msec)
Active wait millisecond delay function. Can also be used inside interrupt handlers.
#define CORE_ENTER_ATOMIC()
__STATIC_INLINE uint32_t TIMER_IntGet(TIMER_TypeDef *timer)
Get pending TIMER interrupt flags.
#define TIMER_INIT_DEFAULT
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.
__STATIC_INLINE void TIMER_CompareSet(TIMER_TypeDef *timer, unsigned int ch, uint32_t val)
Set compare value for compare/capture channel when operating in compare or PWM mode.
__STATIC_INLINE uint32_t TIMER_CounterGet(TIMER_TypeDef *timer)
Get TIMER counter value.
__STATIC_INLINE uint32_t TIMER_CaptureGet(TIMER_TypeDef *timer, unsigned int ch)
Get capture value for compare/capture channel when operating in capture mode.
#define CORE_EXIT_ATOMIC()
__STATIC_INLINE uint32_t TIMER_MaxCount(const TIMER_TypeDef *ref)
Get the Max count of the timer.
void TIMER_Init(TIMER_TypeDef *timer, const TIMER_Init_TypeDef *init)
Initialize TIMER.
USB protocol stack library, low level USB peripheral access.
void USBTIMER_Init(void)
Activate the hardware timer used to pace the 1 millisecond timer system.
USB protocol stack library, internal type definitions.
void TIMER_InitCC(TIMER_TypeDef *timer, unsigned int ch, const TIMER_InitCC_TypeDef *init)
Initialize TIMER compare/capture channel.
uint32_t CMU_ClockFreqGet(CMU_Clock_TypeDef clock)
Get clock frequency for a clock point.
void USBTIMER_Start(uint32_t id, uint32_t timeout, USBTIMER_Callback_TypeDef callback)
Start a timer.
void USBTIMER_DelayUs(uint32_t usec)
Active wait microsecond delay function. Can also be used inside interrupt handlers.