39 #include "rtimer-arch.h"
40 #include "aducrf101-contiki.h"
48 _timer2_enable(
int enable)
50 T2CON_ENABLE_BBA = enable;
52 while(T2STA_CON_BBA) {
65 now = pADI_WUT->T2VAL0;
66 now |= pADI_WUT->T2VAL1 << 16;
70 _timer2_measure_freq(
void)
72 const int test_usec = 10000;
73 uint32_t now = _timer2_val();
75 return (_timer2_val() - now) * (1000000 / test_usec);
81 const char *
timer =
"LFXTAL";
84 pADI_WUT->T2CON = T2CON_PRE_DIV1 | T2CON_MOD_FREERUN | T2CON_FREEZE_EN |
88 pADI_WUT->T2CON |= T2CON_CLK_LFXTAL;
90 freq = _timer2_measure_freq();
92 if(freq < 20000 || freq > 40000) {
95 pADI_WUT->T2CON &= ~T2CON_CLK_MSK;
96 pADI_WUT->T2CON |= T2CON_CLK_LFOSC;
98 freq = _timer2_measure_freq();
102 printf(
"Using %s for rtimer (%ld Hz)\n", timer, freq);
112 return _timer2_val();
117 uint32_t now = _timer2_val();
120 if((int32_t)(t - now) < 5) {
126 pADI_WUT->T2WUFB0 = (t & 0xffff);
127 pADI_WUT->T2WUFB1 = (t >> 16);
131 WakeUp_Int_Handler(
void)
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
Enable External Interrupt.
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.
void rtimer_arch_init(void)
We don't need to explicitly initialise anything but this routine is required by the API...
#define rtimer_arch_now()
CCIF clock_time_t clock_time(void)
Get the current clock time.
void rtimer_arch_schedule(rtimer_clock_t t)
Schedules an rtimer task to be triggered at time t.
void rtimer_run_next(void)
Execute the next real-time task and schedule the next task, if any.
#define CLOCK_SECOND
A second, measured in system clock time.