28 #define USTIMER_TIMER0 0
29 #define USTIMER_TIMER1 1
30 #define USTIMER_TIMER2 2
31 #define USTIMER_TIMER3 3
34 #define USTIMER_TIMER USTIMER_TIMER0
37 #if ( USTIMER_TIMER == USTIMER_TIMER0 ) && ( TIMER_COUNT >= 1 )
39 #define TIMER_CLK cmuClock_TIMER0
40 #define TIMER_IRQ TIMER0_IRQn
41 #define TIMER_IRQHandler TIMER0_IRQHandler
43 #elif ( USTIMER_TIMER == USTIMER_TIMER1 ) && ( TIMER_COUNT >= 2 )
45 #define TIMER_CLK cmuClock_TIMER1
46 #define TIMER_IRQ TIMER1_IRQn
47 #define TIMER_IRQHandler TIMER1_IRQHandler
49 #elif ( USTIMER_TIMER == USTIMER_TIMER2 ) && ( TIMER_COUNT >= 3 )
51 #define TIMER_CLK cmuClock_TIMER2
52 #define TIMER_IRQ TIMER2_IRQn
53 #define TIMER_IRQHandler TIMER2_IRQHandler
55 #elif ( USTIMER_TIMER == USTIMER_TIMER3 ) && ( TIMER_COUNT == 4 )
57 #define TIMER_CLK cmuClock_TIMER3
58 #define TIMER_IRQ TIMER3_IRQn
59 #define TIMER_IRQHandler TIMER3_IRQHandler
62 #error "Illegal USTIMER TIMER selection"
66 static uint32_t minTicks;
67 static volatile bool timeElapsed =
false;
69 static void DelayTicksEM1( uint16_t ticks );
70 static void DelayTicksPolled( uint16_t ticks );
90 uint32_t coreClockScale;
108 && ( freq > 2000000 ) );
116 minTicks = ( ( (uint64_t)freq * coreClockScale ) + 500000 ) / 1000000;
120 NVIC_ClearPendingIRQ( TIMER_IRQ );
121 NVIC_EnableIRQ( TIMER_IRQ );
139 NVIC_DisableIRQ( TIMER_IRQ );
143 NVIC_ClearPendingIRQ( TIMER_IRQ );
172 totalTicks = ( ( (uint64_t)freq * usec ) + 500000 ) / 1000000;
176 while ( totalTicks > 65000 )
178 DelayTicksEM1( 65000 );
181 DelayTicksEM1( (uint16_t)totalTicks );
207 totalTicks = ( ( (uint64_t)freq * usec ) + 500000 ) / 1000000;
211 while ( totalTicks > 65000 )
213 DelayTicksPolled( 65000 );
216 DelayTicksPolled( (uint16_t)totalTicks );
224 void TIMER_IRQHandler(
void )
237 static void DelayTicksPolled( uint16_t ticks )
240 volatile uint16_t now;
248 }
while ( (uint16_t)( now - startTime ) < ticks );
252 static void DelayTicksEM1( uint16_t ticks )
268 while ( ! timeElapsed )
Clock management unit (CMU) API.
__STATIC_INLINE void TIMER_IntDisable(TIMER_TypeDef *timer, uint32_t flags)
Disable one or more TIMER interrupts.
__STATIC_INLINE void TIMER_TopSet(TIMER_TypeDef *timer, uint32_t val)
Set top value for timer.
__STATIC_INLINE void TIMER_Enable(TIMER_TypeDef *timer, bool enable)
Start/stop 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
#define _TIMER_CTRL_PRESC_DIV1024
__STATIC_INLINE void TIMER_IntEnable(TIMER_TypeDef *timer, uint32_t flags)
Enable one or more TIMER interrupts.
Emlib general purpose utilities.
Ecode_t USTIMER_Init(void)
Activate and initialize the hardware timer used to pace the 1 microsecond delay functions.
Interrupt enable/disable unit API.
__STATIC_INLINE void EMU_EnterEM1(void)
Enter energy mode 1 (EM1).
__STATIC_INLINE uint32_t TIMER_IntGet(TIMER_TypeDef *timer)
Get pending TIMER interrupt flags.
#define TIMER_INIT_DEFAULT
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
Ecode_t USTIMER_DeInit(void)
Deinitialize USTIMER driver.
__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.
TIMER_Prescale_TypeDef prescale
void TIMER_Init(TIMER_TypeDef *timer, const TIMER_Init_TypeDef *init)
Initialize TIMER.
Energy management unit (EMU) peripheral API.
Ecode_t USTIMER_DelayIntSafe(uint32_t usec)
Delay a given number of microseconds.
#define ECODE_EMDRV_USTIMER_OK
Success return value.
#define _TIMER_CTRL_PRESC_DIV1
uint32_t Ecode_t
Typedef for API function errorcode return values.
__STATIC_INLINE uint32_t INT_Disable(void)
Disable interrupts.
Microsecond delay function API definition.
Ecode_t USTIMER_Delay(uint32_t usec)
Delay a given number of microseconds.
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.