X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fao_task.c;h=72c9d7d61f67216a71436ce9ffd7c4d0989c5bef;hp=14aa84c841d698d3a285de7370c80de369c7b56f;hb=9e10e43eff9de3f034da49c4f88728fb933f5035;hpb=73db30b2f9128c37dc7fa075793a8862814ce044 diff --git a/src/ao_task.c b/src/ao_task.c index 14aa84c8..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; } @@ -228,7 +240,7 @@ ao_wake_task(__xdata struct ao_task *task) } void -ao_exit(void) +ao_exit(void) __critical { uint8_t i; ao_num_tasks--;