I would like to present for review a high-resolution timer implementation; based on a modified gpt driver (though with this driver, the gpt driver is somewhat superfluous). The driver is fairly naive in that it simply keeps a list of timers that are running and configures the hardware to interrupt at the next shortest time. The timer interval currently has micro-second resolution (though about 5us of overhead has been measured). The code has been tested and seems to be in a state that I feel appropriate to release this as a beta. Please discuss.
Example of configuration/use:
// Toggle the led every 500 ms
Code: Select all
void
testTimerCallback (volatile hrtimer_t *pTimer,
volatile void *data)
{
static int cnt = 0;
if (cnt & 0x01) {
palSetPad(GPIOF, GPIOF_LED1);
}
else {
palClearPad(GPIOF, GPIOF_LED1);
}
cnt += 1;
}
main() {
...
volatile hrtimer_t testTimer;
hrTimerInit(&testTimer, HRT_TYPE_PERIODIC, 500000, testTimerCallback, NULL);
hrTimerStart(&testTimer);
...
}
This will sleep a thread and blink the led every second
Code: Select all
thread() {
int cnt = 0;
while(1) {
hrTimerSleep(1000000);
if (cnt & 0x01) {
palSetPad(GPIOF, GPIOF_LED2);
}
else {
palClearPad(GPIOF, GPIOF_LED2);
}
cnt += 1;
}
}
A bunch of files were modified and the current target is the STM32. Most files are added where you would expect them, and the list.h file I added to /os/various. I believe I have all the required files attached, please let me know if I don't, or it doesn't build correctly.
https://www.dropbox.com/s/wvhscpahiqqrlrb/hrt.zip