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.
25 #define HAS_TASK_INFO 1
28 /* arm stacks must be 64-bit aligned */
29 #ifndef AO_STACK_ALIGNMENT
31 #define AO_STACK_ALIGNMENT __attribute__ ((aligned(8)))
33 #define AO_STACK_ALIGNMENT
39 void *wchan; /* current wait channel (NULL if running) */
40 AO_TICK_TYPE alarm; /* abort ao_sleep time */
41 uint16_t task_id; /* unique id */
42 /* Saved stack pointer */
47 const char *name; /* task name */
49 struct ao_list alarm_queue;
50 /* Provide both 32-bit and 8-bit stacks */
52 uint32_t stack32[AO_STACK_SIZE>>2];
53 uint8_t stack8[AO_STACK_SIZE];
55 #if HAS_SAMPLE_PROFILE
64 #define AO_NUM_TASKS 16 /* maximum number of tasks */
67 extern struct ao_task * ao_tasks[AO_NUM_TASKS];
68 extern uint8_t ao_num_tasks;
69 extern struct ao_task *ao_cur_task;
70 extern uint8_t ao_task_minimize_latency; /* Reduce IRQ latency */
72 #ifndef HAS_ARCH_VALIDATE_CUR_STACK
73 #define ao_validate_cur_stack()
80 /* Suspend the current task until wchan is awoken.
86 ao_sleep(void *wchan);
88 /* Suspend the current task until wchan is awoken or the timeout
94 ao_sleep_for(void *wchan, AO_TICK_TYPE timeout);
96 /* Wake all tasks sleeping on wchan */
98 ao_wakeup(void *wchan);
101 /* set an alarm to go off in 'delay' ticks */
103 ao_alarm(AO_TICK_TYPE delay);
105 /* Clear any pending alarm */
107 ao_clear_alarm(void);
110 /* Yield the processor to another task */
112 ao_yield(void) ao_arch_naked_declare;
114 /* Add a task to the run queue */
116 ao_add_task(struct ao_task * task, void (*start)(void), const char *name);
118 /* Called on timer interrupt to check alarms */
119 extern AO_TICK_TYPE ao_task_alarm_tick;
120 extern volatile AO_TICK_TYPE ao_tick_count;
123 ao_task_alarm(AO_TICK_TYPE tick);
126 ao_task_check_alarm(void) {
128 if ((AO_TICK_SIGNED) (ao_tick_count - ao_task_alarm_tick) >= 0)
129 ao_task_alarm(ao_tick_count);
133 /* Terminate the current task */
135 ao_exit(void) __attribute__ ((noreturn));
137 /* Dump task info to console */
141 /* Start the scheduler. This will not return */
143 ao_start_scheduler(void) __attribute__((noreturn));