projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
altos: Shrink ao_config_callsign_set
[fw/altos]
/
src
/
ao_task.c
diff --git
a/src/ao_task.c
b/src/ao_task.c
index 136444b0899ef0b6112544f507f7ca9e8b7d80fa..35f34b491eef2a92d507756504cb47e8222c6ecc 100644
(file)
--- 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;
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);
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;
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'
task->name = name;
/*
* Construct a stack frame so that it will 'return'
@@
-129,6
+138,13
@@
ao_yield(void) _naked
break;
}
break;
}
+ /* Check if the alarm is set for a time which has passed */
+ if (ao_cur_task->alarm &&
+ (int16_t) (ao_time() - ao_cur_task->alarm) >= 0) {
+ 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;
/* Enter lower power mode when there isn't anything to do */
if (ao_next_task_index == ao_cur_task_index)
PCON = PCON_IDLE;
@@
-181,13
+197,19
@@
ao_yield(void) _naked
_endasm;
}
_endasm;
}
-void
+uint8_t
ao_sleep(__xdata void *wchan)
{
__critical {
ao_cur_task->wchan = wchan;
}
ao_yield();
ao_sleep(__xdata void *wchan)
{
__critical {
ao_cur_task->wchan = wchan;
}
ao_yield();
+ ao_cur_task->alarm = 0;
+ if (ao_cur_task->wchan) {
+ ao_cur_task->wchan = NULL;
+ return 1;
+ }
+ return 0;
}
void
}
void
@@
-201,13
+223,17
@@
ao_wakeup(__xdata void *wchan)
}
void
}
void
-ao_
wake_task(__xdata struct ao_task *task
)
+ao_
alarm(uint16_t delay
)
{
{
- task->wchan = NULL;
+ /* 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;
}
void
}
void
-ao_exit(void)
+ao_exit(void)
__critical
{
uint8_t i;
ao_num_tasks--;
{
uint8_t i;
ao_num_tasks--;