Code: Select all
void timerafter(unsigned val);
#define timerafter(val) __builtin_timer_after(val)
Code: Select all
timer t;
uint32_t time;
const uint32_t period = 100000; // 100000 timer ticks = 1ms
// get the initial timer value t :> time;
while(1) {
select {
case t when timerafter(time) :> void:
// perform periodic task ...
time += period;
break;
}
}
A hypothesis of why XC uses unsigned here is that it's associated with arithmetic to get into the future (+) or to find elapsed time by some unsigned number of micro, milli or seconds, so it's so much easier just to use unsigned? Meet me in 120 seconds is unsigned by nature. At 23:59 then meet me in two minutes is at 00:01, "the hour" rather signed.
I noticed this just now, being occamised 25 years ago I have basically done it like this:
Code: Select all
timer tmr;
int timeout;
int current_time;
unsigned int milliseconds;
tmr :> current_time;
timeout = current_time + (int)(milliseconds * XS1_TIMER_KHZ);
tmr when timerafter(timeout) :> void;
PS.I have blogged about this theme here: http://www.teigfam.net/oyvind/home/tech ... multi-core (no money, no ads, no gifts received, just hobby)