X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=ao_task.c;h=06c279e9faa7eb9119cbb53eda77195842f8b680;hp=878724c5a0ba484be8715f51fd636664493127ee;hb=7cb9fb675f56bf30ab6bf0bcdc5cb679709ffe3e;hpb=43c8f7012102cdb591ace899420c10e4a78385ad diff --git a/ao_task.c b/ao_task.c index 878724c5..06c279e9 100644 --- a/ao_task.c +++ b/ao_task.c @@ -25,7 +25,7 @@ __data uint8_t ao_cur_task_index; __xdata struct ao_task *__data ao_cur_task; void -ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *name) +ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *name) __reentrant { uint8_t __xdata *stack; if (ao_num_tasks == AO_NUM_TASKS) @@ -114,13 +114,23 @@ ao_yield(void) _naked /* Find a task to run. If there isn't any runnable task, * this loop will run forever, which is just fine */ - for (;;) { - ++ao_cur_task_index; - if (ao_cur_task_index == ao_num_tasks) - ao_cur_task_index = 0; - ao_cur_task = ao_tasks[ao_cur_task_index]; - if (ao_cur_task->wchan == NULL) - break; + { + __pdata uint8_t ao_next_task_index = ao_cur_task_index; + for (;;) { + ++ao_next_task_index; + if (ao_next_task_index == ao_num_tasks) + ao_next_task_index = 0; + + ao_cur_task = ao_tasks[ao_next_task_index]; + if (ao_cur_task->wchan == NULL) { + ao_cur_task_index = ao_next_task_index; + break; + } + + /* Enter lower power mode when there isn't anything to do */ + if (ao_next_task_index == ao_cur_task_index) + PCON = PCON_IDLE; + } } { @@ -193,13 +203,15 @@ ao_task_info(void) { uint8_t i; uint8_t pc_loc; + __xdata struct ao_task *task; for (i = 0; i < ao_num_tasks; i++) { - pc_loc = ao_tasks[i]->stack_count - 17; - printf("%-8s: wchan %04x pc %04x\n", - ao_tasks[i]->name, - (int16_t) ao_tasks[i]->wchan, - (ao_tasks[i]->stack[pc_loc]) | (ao_tasks[i]->stack[pc_loc+1] << 8)); + task = ao_tasks[i]; + pc_loc = task->stack_count - 17; + printf("%12s: wchan %04x pc %04x\n", + task->name, + (int16_t) task->wchan, + (task->stack[pc_loc]) | (task->stack[pc_loc+1] << 8)); } }