altoslib: Missed a couple of easy mini voltage API changes
[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 #if HAS_TASK_QUEUE
21 #include <ao_list.h>
22 #endif
23
24 #ifndef HAS_TASK_INFO
25 #define HAS_TASK_INFO 1
26 #endif
27
28 /* An AltOS task */
29 struct ao_task {
30         __xdata void *wchan;            /* current wait channel (NULL if running) */
31         uint16_t alarm;                 /* abort ao_sleep time */
32         ao_arch_task_members            /* any architecture-specific fields */
33         uint8_t task_id;                /* unique id */
34         __code char *name;              /* task name */
35 #if HAS_TASK_QUEUE
36         struct ao_list  queue;
37         struct ao_list  alarm_queue;
38 #endif
39         uint8_t stack[AO_STACK_SIZE];   /* saved stack */
40 #if HAS_SAMPLE_PROFILE
41         uint32_t ticks;
42         uint32_t yields;
43         uint16_t start;
44         uint16_t max_run;
45 #endif
46 };
47
48 #ifndef AO_NUM_TASKS
49 #define AO_NUM_TASKS            16      /* maximum number of tasks */
50 #endif
51
52 #define AO_NO_TASK              0       /* no task id */
53
54 extern __xdata struct ao_task * __xdata ao_tasks[AO_NUM_TASKS];
55 extern __data uint8_t ao_num_tasks;
56 extern __xdata struct ao_task *__data ao_cur_task;
57 extern __data uint8_t ao_task_minimize_latency; /* Reduce IRQ latency */
58
59 /*
60  ao_task.c
61  */
62
63 /* Suspend the current task until wchan is awoken.
64  * returns:
65  *  0 on normal wake
66  *  1 on alarm
67  */
68 uint8_t
69 ao_sleep(__xdata void *wchan);
70
71 /* Wake all tasks sleeping on wchan */
72 void
73 ao_wakeup(__xdata void *wchan) __reentrant;
74
75 /* set an alarm to go off in 'delay' ticks */
76 void
77 ao_alarm(uint16_t delay);
78
79 /* Clear any pending alarm */
80 void
81 ao_clear_alarm(void);
82
83 /* Yield the processor to another task */
84 void
85 ao_yield(void) ao_arch_naked_declare;
86
87 /* Add a task to the run queue */
88 void
89 ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *name) __reentrant;
90
91 #if HAS_TASK_QUEUE
92 /* Called on timer interrupt to check alarms */
93 extern uint16_t ao_task_alarm_tick;
94 void
95 ao_task_check_alarm(uint16_t tick);
96 #endif
97
98 /* Terminate the current task */
99 void
100 ao_exit(void);
101
102 /* Dump task info to console */
103 void
104 ao_task_info(void);
105
106 /* Start the scheduler. This will not return */
107 void
108 ao_start_scheduler(void);
109
110 #if HAS_TASK_QUEUE
111 void
112 ao_task_init(void);
113 #else
114 #define ao_task_init()
115 #endif
116
117 #endif