added fix to enable start of ctimers before etimer process has started

This commit is contained in:
nifi 2007-11-13 15:13:03 +00:00
parent d8717c264a
commit 44480fc7b7

View file

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: ctimer.c,v 1.4 2007/03/31 18:31:27 adamdunkels Exp $
* $Id: ctimer.c,v 1.5 2007/11/13 15:13:03 nifi Exp $
*/
/**
@ -50,6 +50,8 @@
LIST(ctimer_list);
static char initialized;
#define DEBUG 0
#if DEBUG
#include <stdio.h>
@ -65,8 +67,11 @@ PROCESS_THREAD(ctimer_process, ev, data)
struct ctimer *c;
PROCESS_BEGIN();
list_init(ctimer_list);
for(c = list_head(ctimer_list); c != NULL; c = c->next) {
etimer_set(&c->etimer, c->etimer.timer.interval);
}
initialized = 1;
while(1) {
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_TIMER);
for(c = list_head(ctimer_list); c != NULL; c = c->next) {
@ -87,6 +92,8 @@ PROCESS_THREAD(ctimer_process, ev, data)
void
ctimer_init(void)
{
initialized = 0;
list_init(ctimer_list);
process_start(&ctimer_process, NULL);
}
/*---------------------------------------------------------------------------*/
@ -98,10 +105,13 @@ ctimer_set(struct ctimer *c, clock_time_t t,
c->p = PROCESS_CURRENT();
c->f = f;
c->ptr = ptr;
PROCESS_CONTEXT_BEGIN(&ctimer_process);
etimer_set(&c->etimer, t);
PROCESS_CONTEXT_END(&ctimer_process);
if(initialized) {
PROCESS_CONTEXT_BEGIN(&ctimer_process);
etimer_set(&c->etimer, t);
PROCESS_CONTEXT_END(&ctimer_process);
} else {
c->etimer.timer.interval = t;
}
list_remove(ctimer_list, c);
list_add(ctimer_list, c);
@ -110,9 +120,11 @@ ctimer_set(struct ctimer *c, clock_time_t t,
void
ctimer_reset(struct ctimer *c)
{
PROCESS_CONTEXT_BEGIN(&ctimer_process);
etimer_reset(&c->etimer);
PROCESS_CONTEXT_END(&ctimer_process);
if(initialized) {
PROCESS_CONTEXT_BEGIN(&ctimer_process);
etimer_reset(&c->etimer);
PROCESS_CONTEXT_END(&ctimer_process);
}
list_remove(ctimer_list, c);
list_add(ctimer_list, c);
@ -121,7 +133,12 @@ ctimer_reset(struct ctimer *c)
void
ctimer_stop(struct ctimer *c)
{
etimer_stop(&c->etimer);
if(initialized) {
etimer_stop(&c->etimer);
} else {
c->etimer.next = NULL;
c->etimer.p = PROCESS_NONE;
}
list_remove(ctimer_list, c);
}
/*---------------------------------------------------------------------------*/