X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fao_task.c;h=72c9d7d61f67216a71436ce9ffd7c4d0989c5bef;hp=4664163d6a1a7ccdd6801575f2b182d58e8d3f6a;hb=9e10e43eff9de3f034da49c4f88728fb933f5035;hpb=b92333ff5e75bf96804359e9fbf464d3b518bd95 diff --git a/src/ao_task.c b/src/ao_task.c index 4664163d..72c9d7d6 100644 --- a/src/ao_task.c +++ b/src/ao_task.c @@ -28,10 +28,19 @@ void ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *name) __reentrant { uint8_t __xdata *stack; + uint8_t task_id; + uint8_t t; if (ao_num_tasks == AO_NUM_TASKS) ao_panic(AO_PANIC_NO_TASK); + for (task_id = 1; task_id != 0; task_id++) { + for (t = 0; t < ao_num_tasks; t++) + if (ao_tasks[t]->task_id == task_id) + break; + if (t == ao_num_tasks) + break; + } ao_tasks[ao_num_tasks++] = task; - task->task_id = ao_num_tasks; + task->task_id = task_id; task->name = name; /* * Construct a stack frame so that it will 'return' @@ -217,7 +226,10 @@ ao_wakeup(__xdata void *wchan) void ao_alarm(uint16_t delay) { - if (!(ao_cur_task->alarm = ao_time() + delay)) + /* Make sure we sleep *at least* delay ticks, which means adding + * one to account for the fact that we may be close to the next tick + */ + if (!(ao_cur_task->alarm = ao_time() + delay + 1)) ao_cur_task->alarm = 1; }