Merge branch 'master' into mm-ms5611
[fw/altos] / src / core / ao_task.h
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #ifndef _AO_TASK_H_
19 #define _AO_TASK_H_
20
21 /* An AltOS task */
22 struct ao_task {
23         __xdata void *wchan;            /* current wait channel (NULL if running) */
24         uint16_t alarm;                 /* abort ao_sleep time */
25         ao_arch_task_members            /* any architecture-specific fields */
26         uint8_t task_id;                /* unique id */
27         __code char *name;              /* task name */
28         uint8_t stack[AO_STACK_SIZE];   /* saved stack */
29 };
30
31 extern __xdata struct ao_task *__data ao_cur_task;
32
33 #define AO_NUM_TASKS            16      /* maximum number of tasks */
34 #define AO_NO_TASK              0       /* no task id */
35
36 /*
37  ao_task.c
38  */
39
40 /* Suspend the current task until wchan is awoken.
41  * returns:
42  *  0 on normal wake
43  *  1 on alarm
44  */
45 uint8_t
46 ao_sleep(__xdata void *wchan);
47
48 /* Wake all tasks sleeping on wchan */
49 void
50 ao_wakeup(__xdata void *wchan);
51
52 /* set an alarm to go off in 'delay' ticks */
53 void
54 ao_alarm(uint16_t delay);
55
56 /* Clear any pending alarm */
57 void
58 ao_clear_alarm(void);
59
60 /* Yield the processor to another task */
61 void
62 ao_yield(void) ao_arch_naked_declare;
63
64 /* Add a task to the run queue */
65 void
66 ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *name) __reentrant;
67
68 /* Terminate the current task */
69 void
70 ao_exit(void);
71
72 /* Dump task info to console */
73 void
74 ao_task_info(void);
75
76 /* Start the scheduler. This will not return */
77 void
78 ao_start_scheduler(void);
79
80 #endif