51 #define PRINTF(...) printf(__VA_ARGS__)
58 static u32_t time_msb = 0;
61 static rtimer_clock_t next_rtimer_time = 0;
63 static u16_t saved_TIM1CFG;
67 void halTimer1Isr(
void){
70 if(INT_TIM1FLAG & INT_TIMUIF){
76 rtimer_clock_t now = ((rtimer_clock_t)time_msb << 16)|TIM1_CNT;
78 rtimer_clock_t clock_to_wait = next_rtimer_time - now;
80 if(clock_to_wait <= 0x10000 && clock_to_wait > 0){
82 TIM1_CCR1 = (int16u)clock_to_wait;
83 INT_TIM1FLAG = INT_TIMCC1IF;
84 INT_TIM1CFG |= INT_TIMCC1IF;
87 INT_TIM1FLAG = INT_TIMUIF;
91 else if(INT_TIM1FLAG & INT_TIMCC1IF){
93 INT_TIM1CFG &= ~INT_TIMCC1IF;
95 PRINTF(
"\nCompare event %4x\r\n", TIM1_CNT);
96 PRINTF(
"INT_TIM1FLAG %2x\r\n", INT_TIM1FLAG);
97 ENERGEST_ON(ENERGEST_TYPE_IRQ);
99 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
100 INT_TIM1FLAG = INT_TIMCC1IF;
107 rtimer_arch_init(
void)
111 TIM1_PSC = RT_PRESCALER;
119 INT_TIM1FLAG = 0xffff;
121 INT_TIM1CFG = INT_TIMUIF;
125 INT_CFGSET = INT_TIM1;
129 void rtimer_arch_disable_irq(
void)
132 saved_TIM1CFG = INT_TIM1CFG;
137 void rtimer_arch_enable_irq(
void)
139 INT_TIM1CFG = saved_TIM1CFG;
142 rtimer_clock_t rtimer_arch_now(
void)
144 return ((rtimer_clock_t)time_msb << 16)|TIM1_CNT;
150 rtimer_arch_schedule(rtimer_clock_t t)
153 PRINTF(
"rtimer_arch_schedule time %4x\r\n", (u32_t)t);
155 next_rtimer_time = t;
157 rtimer_clock_t now = rtimer_arch_now();
159 rtimer_clock_t clock_to_wait = t - now;
161 PRINTF(
"now %2x\r\n", TIM1_CNT);
162 PRINTF(
"clock_to_wait %4x\r\n", clock_to_wait);
164 if(clock_to_wait <= 0x10000){
166 TIM1_CCR1 = (int16u)now + (int16u)clock_to_wait;
167 INT_TIM1FLAG = INT_TIMCC1IF;
168 INT_TIM1CFG |= INT_TIMCC1IF;
170 PRINTF(
"2-INT_TIM1FLAG %2x\r\n", INT_TIM1FLAG);