mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
* many fixes. vtimer_hammer OK now.
This commit is contained in:
parent
5838ce604b
commit
9757bb7dda
37
sys/vtimer.c
37
sys/vtimer.c
@ -13,6 +13,7 @@
|
||||
#include <debug.h>
|
||||
|
||||
#define VTIMER_THRESHOLD 20U
|
||||
#define VTIMER_BACKOFF 10U
|
||||
|
||||
#define SECONDS_PER_TICK (4096U)
|
||||
#define NANOSECONDS_PER_TICK (4096U * 1000000)
|
||||
@ -41,7 +42,7 @@ static int set_longterm(vtimer_t *timer) {
|
||||
}
|
||||
|
||||
static int update_shortterm() {
|
||||
if (hwtimer_id) {
|
||||
if (hwtimer_id != -1) {
|
||||
if (hwtimer_next_absolute != shortterm_queue_root.next->priority) {
|
||||
hwtimer_remove(hwtimer_id);
|
||||
} else {
|
||||
@ -49,23 +50,24 @@ static int update_shortterm() {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t now = hwtimer_now();
|
||||
|
||||
hwtimer_next_absolute = shortterm_queue_root.next->priority;
|
||||
|
||||
while ((hwtimer_next_absolute + longterm_tick_start)-(hwtimer_now()+VTIMER_THRESHOLD) > NANOSECONDS_PER_TICK) {
|
||||
hwtimer_next_absolute += VTIMER_THRESHOLD;
|
||||
|
||||
unsigned int next = hwtimer_next_absolute + longterm_tick_start;
|
||||
unsigned int now = hwtimer_now();
|
||||
|
||||
if((next - VTIMER_THRESHOLD - now) > NANOSECONDS_PER_TICK ) {
|
||||
next = now + VTIMER_BACKOFF;
|
||||
}
|
||||
|
||||
hwtimer_id = hwtimer_set_absolute(hwtimer_next_absolute + longterm_tick_start, vtimer_callback, NULL);
|
||||
hwtimer_id = hwtimer_set_absolute(next, vtimer_callback, NULL);
|
||||
|
||||
DEBUG("update_shortterm: Set hwtimer to %lu (now=%lu)\n", hwtimer_next_absolute + longterm_tick_start, hwtimer_now());
|
||||
//printf("%lu (now=%lu)\n", hwtimer_next_absolute + longterm_tick_start, hwtimer_now());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vtimer_tick(void *ptr) {
|
||||
puts("vtimer_tick().");
|
||||
DEBUG("vtimer_tick().");
|
||||
seconds += SECONDS_PER_TICK;
|
||||
|
||||
longterm_tick_start = longterm_tick_timer.absolute.nanoseconds;
|
||||
@ -95,9 +97,12 @@ static int set_shortterm(vtimer_t *timer) {
|
||||
void vtimer_callback(void *ptr) {
|
||||
vtimer_t *timer;
|
||||
in_callback = true;
|
||||
hwtimer_id = -1;
|
||||
|
||||
timer = (vtimer_t *)queue_remove_head(&shortterm_queue_root);
|
||||
|
||||
DEBUG("vtimer_callback(): Shooting %lu.\n", timer->absolute.nanoseconds);
|
||||
|
||||
/* shoot timer */
|
||||
timer->action(timer->arg);
|
||||
|
||||
@ -126,10 +131,6 @@ void normalize_to_tick(timex_t *time) {
|
||||
int vtimer_set(vtimer_t *timer, timex_t *offset) {
|
||||
DEBUG("vtimer_set(): New timer. Offset: %lu %lu\n", offset->seconds, offset->nanoseconds);
|
||||
|
||||
|
||||
// timex_t vnow = vtimer_now();
|
||||
// DEBUG("Now = %lu %lu\n", vnow.seconds, vnow.nanoseconds);
|
||||
|
||||
timer->absolute = timex_add(vtimer_now(), *offset);
|
||||
normalize_to_tick(&(timer->absolute));
|
||||
|
||||
@ -137,6 +138,12 @@ int vtimer_set(vtimer_t *timer, timex_t *offset) {
|
||||
|
||||
int result = 0;
|
||||
|
||||
if (timer->absolute.seconds == 0) {
|
||||
if (timer->absolute.nanoseconds > 10) {
|
||||
timer->absolute.nanoseconds -= 10;
|
||||
}
|
||||
}
|
||||
|
||||
int state = disableIRQ();
|
||||
if (timer->absolute.seconds != seconds ) {
|
||||
/* we're long-term */
|
||||
@ -167,6 +174,7 @@ timex_t vtimer_now() {
|
||||
|
||||
int vtimer_init() {
|
||||
DEBUG("vtimer_init().\n");
|
||||
int state = disableIRQ();
|
||||
seconds = 0;
|
||||
|
||||
longterm_tick_timer.action = vtimer_tick;
|
||||
@ -180,13 +188,14 @@ int vtimer_init() {
|
||||
set_shortterm(&longterm_tick_timer);
|
||||
update_shortterm();
|
||||
|
||||
restoreIRQ(state);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vtimer_usleep(uint32_t usecs) {
|
||||
vtimer_t t;
|
||||
timex_t offset = timex_set(0, usecs);
|
||||
t.action = thread_wakeup;
|
||||
t.action = (void*) thread_wakeup;
|
||||
t.arg = (void*) thread_getpid();
|
||||
vtimer_set(&t, &offset);
|
||||
thread_sleep();
|
||||
|
Loading…
Reference in New Issue
Block a user