51 #define PRINTF(...) printf(__VA_ARGS__)
56 static uint16_t saved_TIM1CFG;
57 static uint32_t time_msb = 0;
61 static rtimer_clock_t next_rtimer_time = 0;
67 if(INT_TIM1FLAG & INT_TIMUIF) {
68 rtimer_clock_t now, clock_to_wait;
73 now = ((rtimer_clock_t) time_msb << 16) | TIM1_CNT;
74 clock_to_wait = next_rtimer_time - now;
76 if(clock_to_wait <= 0x10000 && clock_to_wait > 0) {
78 TIM1_CCR1 = (uint16_t) clock_to_wait;
79 INT_TIM1FLAG = INT_TIMCC1IF;
80 INT_TIM1CFG |= INT_TIMCC1IF;
82 INT_TIM1FLAG = INT_TIMUIF;
84 if(INT_TIM1FLAG & INT_TIMCC1IF) {
86 INT_TIM1CFG &= ~INT_TIMCC1IF;
87 PRINTF(
"\nCompare event %4x\r\n", TIM1_CNT);
88 PRINTF(
"INT_TIM1FLAG %2x\r\n", INT_TIM1FLAG);
89 ENERGEST_ON(ENERGEST_TYPE_IRQ);
91 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
92 INT_TIM1FLAG = INT_TIMCC1IF;
101 TIM1_PSC = RTIMER_ARCH_PRESCALER;
109 INT_TIM1FLAG = 0xffff;
112 INT_TIM1CFG = INT_TIMUIF;
118 INT_CFGSET = INT_TIM1;
123 rtimer_arch_disable_irq(
void)
125 ATOMIC(saved_TIM1CFG = INT_TIM1CFG; INT_TIM1CFG = 0;)
129 rtimer_arch_enable_irq(
void)
131 INT_TIM1CFG = saved_TIM1CFG;
139 ATOMIC(t = ((rtimer_clock_t) time_msb << 16) | TIM1_CNT;)
147 rtimer_clock_t now, clock_to_wait;
148 PRINTF(
"rtimer_arch_schedule time %4x\r\n",
150 next_rtimer_time = t;
152 clock_to_wait = t - now;
154 PRINTF(
"now %2x\r\n", TIM1_CNT);
155 PRINTF(
"clock_to_wait %4x\r\n", clock_to_wait);
157 if(clock_to_wait <= 0x10000) {
159 TIM1_CCR1 = (uint16_t)now + (uint16_t)clock_to_wait;
160 INT_TIM1FLAG = INT_TIMCC1IF;
161 INT_TIM1CFG |= INT_TIMCC1IF;
162 PRINTF(
"2-INT_TIM1FLAG %2x\r\n", INT_TIM1FLAG);
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()
Header file for the energy estimation mechanism
Header file for the real-time timer module.
#define ATOMIC(blah)
A block of code may be made atomic by wrapping it with this macro.
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.