17 #if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
19 #if defined( USB_DEVICE ) || defined( USB_HOST )
42 #define USB_TIMER USB_TIMER0
45 #if ( USB_TIMER == USB_TIMER0 ) && ( TIMER_COUNT >= 1 )
47 #define TIMER_CLK cmuClock_TIMER0
48 #define TIMER_IRQ TIMER0_IRQn
49 #define TIMER_IRQHandler TIMER0_IRQHandler
51 #elif ( USB_TIMER == USB_TIMER1 ) && ( TIMER_COUNT >= 2 )
53 #define TIMER_CLK cmuClock_TIMER1
54 #define TIMER_IRQ TIMER1_IRQn
55 #define TIMER_IRQHandler TIMER1_IRQHandler
57 #elif ( USB_TIMER == USB_TIMER2 ) && ( TIMER_COUNT >= 3 )
59 #define TIMER_CLK cmuClock_TIMER2
60 #define TIMER_IRQ TIMER2_IRQn
61 #define TIMER_IRQHandler TIMER2_IRQHandler
63 #elif ( USB_TIMER == USB_TIMER3 ) && ( TIMER_COUNT == 4 )
65 #define TIMER_CLK cmuClock_TIMER3
66 #define TIMER_IRQ TIMER3_IRQn
67 #define TIMER_IRQHandler TIMER3_IRQHandler
70 #error "Illegal USB TIMER definition"
79 } USBTIMER_Timer_TypeDef;
81 #if ( NUM_QTIMERS > 0 )
82 static USBTIMER_Timer_TypeDef timers[ NUM_QTIMERS ];
83 static USBTIMER_Timer_TypeDef *head = NULL;
86 static uint32_t ticksPrMs, ticksPr1us, ticksPr10us, ticksPr100us;
88 #if ( NUM_QTIMERS > 0 )
90 static void TimerTick(
void );
92 void TIMER_IRQHandler(
void )
107 static void DelayTicks( uint16_t ticks )
110 volatile uint16_t now;
118 }
while ( (uint16_t)( now - startTime ) < ticks );
139 totalTicks = (uint64_t)ticksPrMs * msec;
140 while ( totalTicks > 20000 )
145 DelayTicks( (uint16_t)totalTicks );
160 totalTicks = (uint64_t)ticksPr1us * usec;
161 if ( totalTicks == 0 )
164 totalTicks = (uint64_t)ticksPr10us * usec;
166 if ( totalTicks == 0 )
169 totalTicks = (uint64_t)ticksPr100us * usec;
173 while ( totalTicks > 60000 )
178 DelayTicks( (uint16_t)totalTicks );
197 ticksPrMs = ( freq + 500 ) / 1000;
198 ticksPr1us = ( freq + 500000 ) / 1000000;
199 ticksPr10us = ( freq + 50000 ) / 100000;
200 ticksPr100us = ( freq + 5000 ) / 10000;
208 #if ( NUM_QTIMERS > 0 )
212 NVIC_ClearPendingIRQ( TIMER_IRQ );
213 NVIC_EnableIRQ( TIMER_IRQ );
217 #if ( NUM_QTIMERS > 0 ) || defined( DOXY_DOC_ONLY )
237 uint32_t accumulated;
238 USBTIMER_Timer_TypeDef *
this, **last;
242 if ( timers[
id ].running )
254 timers[ id ].running =
true;
255 timers[ id ].callback = callback;
256 timers[ id ].next = NULL;
260 timers[ id ].timeout = timeout;
261 head = &timers[ id ];
272 if ( timeout < accumulated + this->timeout )
274 timers[ id ].timeout = timeout - accumulated;
275 timers[ id ].next =
this;
276 *last = &timers[ id ];
277 this->timeout -= timers[ id ].timeout;
280 else if ( this->next == NULL )
282 timers[ id ].timeout = timeout - accumulated - this->timeout;
283 this->next = &timers[ id ];
286 accumulated += this->timeout;
304 USBTIMER_Timer_TypeDef *
this, **last;
312 timers[ id ].running =
false;
316 if (
this == &timers[
id ] )
320 this->next->timeout += timers[ id ].timeout;
336 #if ( NUM_QTIMERS > 0 )
339 static void TimerTick(
void )
351 if ( head->timeout == 0 )
354 head->running =
false;
Clock management unit (CMU) API.
__STATIC_INLINE void TIMER_TopSet(TIMER_TypeDef *timer, uint32_t val)
Set top value for timer.
void USBTIMER_Stop(uint32_t id)
Stop a timer.
#define TIMER_INITCC_DEFAULT
__STATIC_INLINE uint32_t INT_Enable(void)
Enable interrupts.
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.
__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.
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.
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.
__STATIC_INLINE uint32_t INT_Disable(void)
Disable interrupts.
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.