2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 #define HAS_TASK_INFO 1
29 /* arm stacks must be 32-bit aligned */
31 #define AO_STACK_ALIGNMENT __attribute__ ((aligned(4)))
34 #define AO_STACK_ALIGNMENT
37 #define AO_STACK_ALIGNMENT
42 __xdata void *wchan; /* current wait channel (NULL if running) */
43 uint16_t alarm; /* abort ao_sleep time */
44 ao_arch_task_members /* any architecture-specific fields */
45 uint8_t task_id; /* unique id */
46 __code char *name; /* task name */
48 int __errno; /* storage for errno in newlib libc */
52 struct ao_list alarm_queue;
54 uint8_t stack[AO_STACK_SIZE] AO_STACK_ALIGNMENT; /* saved stack */
55 #if HAS_SAMPLE_PROFILE
64 #define AO_NUM_TASKS 16 /* maximum number of tasks */
67 #define AO_NO_TASK 0 /* no task id */
69 extern __xdata struct ao_task * __xdata ao_tasks[AO_NUM_TASKS];
70 extern __data uint8_t ao_num_tasks;
71 extern __xdata struct ao_task *__data ao_cur_task;
72 extern __data uint8_t ao_task_minimize_latency; /* Reduce IRQ latency */
74 #ifndef HAS_ARCH_VALIDATE_CUR_STACK
75 #define ao_validate_cur_stack()
82 /* Suspend the current task until wchan is awoken.
88 ao_sleep(__xdata void *wchan);
90 /* Suspend the current task until wchan is awoken or the timeout
96 ao_sleep_for(__xdata void *wchan, uint16_t timeout);
98 /* Wake all tasks sleeping on wchan */
100 ao_wakeup(__xdata void *wchan) __reentrant;
103 /* set an alarm to go off in 'delay' ticks */
105 ao_alarm(uint16_t delay);
107 /* Clear any pending alarm */
109 ao_clear_alarm(void);
112 /* Yield the processor to another task */
114 ao_yield(void) ao_arch_naked_declare;
116 /* Add a task to the run queue */
118 ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *name) __reentrant;
121 /* Called on timer interrupt to check alarms */
122 extern uint16_t ao_task_alarm_tick;
124 ao_task_check_alarm(uint16_t tick);
127 /* Terminate the current task */
131 /* Dump task info to console */
135 /* Start the scheduler. This will not return */
137 ao_start_scheduler(void);
143 #define ao_task_init()