mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #411 from mehlis/fix-native-hwtimer-backend
fix: native hwtimer backend emulation
This commit is contained in:
commit
74b2d28e5e
@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#define HWTIMERMINOFFSET 100000
|
#define HWTIMERMINOFFSET (10 * 1000UL) // 10 ms
|
||||||
|
|
||||||
static unsigned long native_hwtimer_now;
|
static unsigned long native_hwtimer_now;
|
||||||
static unsigned long time_null;
|
static unsigned long time_null;
|
||||||
@ -89,45 +89,39 @@ unsigned long ts2ticks(struct timespec *tp)
|
|||||||
*/
|
*/
|
||||||
void schedule_timer(void)
|
void schedule_timer(void)
|
||||||
{
|
{
|
||||||
int l = next_timer;
|
next_timer = -1;
|
||||||
|
|
||||||
for (
|
/* try to find *an active* timer */
|
||||||
int i = ((next_timer + 1) % ARCH_MAXTIMERS);
|
for (int i = 0; i < ARCH_MAXTIMERS; i++) {
|
||||||
i != next_timer;
|
if (native_hwtimer_isset[i] == 1) {
|
||||||
i = ((i + 1) % ARCH_MAXTIMERS)
|
next_timer = i;
|
||||||
) {
|
break;
|
||||||
|
|
||||||
if (native_hwtimer_isset[l] != 1) {
|
|
||||||
/* make sure we dont compare to garbage in the following
|
|
||||||
* if condition */
|
|
||||||
l = i;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next_timer == -1) {
|
||||||
|
DEBUG("schedule_timer(): no valid timer found - nothing to schedule");
|
||||||
|
// TODO: unset timer.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* find the next pending timer (next_timer now points to *a* valid pending timer) */
|
||||||
|
for (int i = 0; i < ARCH_MAXTIMERS; i++) {
|
||||||
if (
|
if (
|
||||||
(native_hwtimer_isset[i] == 1) &&
|
(native_hwtimer_isset[i] == 1) &&
|
||||||
(tv2ticks(&(native_hwtimer[i].it_value)) < tv2ticks(&(native_hwtimer[l].it_value)))
|
(tv2ticks(&(native_hwtimer[i].it_value)) < tv2ticks(&(native_hwtimer[next_timer].it_value)))
|
||||||
) {
|
) {
|
||||||
/* set l to the lowest active time */
|
/* timer in slot i is active and the timeout is more recent than next_timer */
|
||||||
l = i;
|
next_timer = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
next_timer = l;
|
/* next pending timer is in slot next_timer */
|
||||||
|
if (setitimer(ITIMER_REAL, &native_hwtimer[next_timer], NULL) == -1) {
|
||||||
/* l could still point to some unused (garbage) timer if no timers
|
err(EXIT_FAILURE, "schedule_timer");
|
||||||
* are set at all */
|
|
||||||
if (native_hwtimer_isset[next_timer] == 1) {
|
|
||||||
if (setitimer(ITIMER_REAL, &native_hwtimer[next_timer], NULL) == -1) {
|
|
||||||
err(EXIT_FAILURE, "schedule_timer");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
DEBUG("schedule_timer(): set next timer.\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DEBUG("schedule_timer(): no next timer!? This looks suspicous.\n");
|
DEBUG("schedule_timer(): set next timer.\n");
|
||||||
// TODO: unset timer.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,21 +132,22 @@ void schedule_timer(void)
|
|||||||
*/
|
*/
|
||||||
void hwtimer_isr_timer()
|
void hwtimer_isr_timer()
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
DEBUG("hwtimer_isr_timer()\n");
|
DEBUG("hwtimer_isr_timer()\n");
|
||||||
|
|
||||||
i = next_timer;
|
if (next_timer == -1) {
|
||||||
native_hwtimer_isset[next_timer] = 0;
|
DEBUG("hwtimer_isr_timer(): next_timer in invalid\n");
|
||||||
schedule_timer();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (native_hwtimer_irq[i] == 1) {
|
if (native_hwtimer_irq[next_timer] == 1) {
|
||||||
DEBUG("hwtimer_isr_timer(): calling hwtimer.int_handler(%i)\n", i);
|
DEBUG("hwtimer_isr_timer(): calling hwtimer.int_handler(%i)\n", next_timer);
|
||||||
int_handler(i);
|
int_handler(next_timer);
|
||||||
|
native_hwtimer_isset[next_timer] = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DEBUG("hwtimer_isr_timer(): this should not have happened");
|
DEBUG("hwtimer_isr_timer(): this should not have happened");
|
||||||
}
|
}
|
||||||
|
schedule_timer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwtimer_arch_enable_interrupt(void)
|
void hwtimer_arch_enable_interrupt(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user