first cut at turnon scripts for EasyTimer v2
[fw/altos] / src / kernel / ao_task.h
index 7d81c1da547243e4c024fbf35ebcc5ae8633812a..27f47a5629de139565d203e34f3c63ccc21998e3 100644 (file)
@@ -18,9 +18,8 @@
 
 #ifndef _AO_TASK_H_
 #define _AO_TASK_H_
-#if HAS_TASK_QUEUE
+
 #include <ao_list.h>
-#endif
 
 #ifndef HAS_TASK_INFO
 #define HAS_TASK_INFO 1
 struct ao_task {
        void *wchan;                    /* current wait channel (NULL if running) */
        AO_TICK_TYPE alarm;             /* abort ao_sleep time */
-       uint16_t task_id;               /* unique id */
+       uint8_t task_id;                /* unique id */
        /* Saved stack pointer */
        union {
                uint32_t        *sp32;
                uint8_t         *sp8;
        };
        const char *name;               /* task name */
-#if HAS_TASK_QUEUE
        struct ao_list  queue;
        struct ao_list  alarm_queue;
-#endif
        /* Provide both 32-bit and 8-bit stacks */
+#ifdef AO_STACK_CANARY
+       uint32_t        bottom_canary;
+#endif
        union {
                uint32_t stack32[AO_STACK_SIZE>>2];
                uint8_t stack8[AO_STACK_SIZE];
        } AO_STACK_ALIGNMENT;
+#ifdef AO_STACK_CANARY
+       uint32_t top_canary;
+#endif
 #if HAS_SAMPLE_PROFILE
        uint32_t ticks;
        uint32_t yields;
@@ -67,8 +70,6 @@ struct ao_task {
 #define AO_NUM_TASKS           16      /* maximum number of tasks */
 #endif
 
-#define AO_NO_TASK             0       /* no task id */
-
 extern struct ao_task * ao_tasks[AO_NUM_TASKS];
 extern uint8_t ao_num_tasks;
 extern struct ao_task *ao_cur_task;
@@ -120,16 +121,24 @@ ao_yield(void) ao_arch_naked_declare;
 void
 ao_add_task(struct ao_task * task, void (*start)(void), const char *name);
 
-#if HAS_TASK_QUEUE
 /* Called on timer interrupt to check alarms */
-extern AO_TICK_TYPE    ao_task_alarm_tick;
+extern AO_TICK_TYPE            ao_task_alarm_tick;
+extern volatile AO_TICK_TYPE   ao_tick_count;
+
 void
-ao_task_check_alarm(AO_TICK_TYPE tick);
+ao_task_alarm(AO_TICK_TYPE tick);
+
+static inline void
+ao_task_check_alarm(void) {
+#if HAS_TASK
+       if ((AO_TICK_SIGNED) (ao_tick_count - ao_task_alarm_tick) >= 0)
+               ao_task_alarm(ao_tick_count);
 #endif
+}
 
 /* Terminate the current task */
 void
-ao_exit(void);
+ao_exit(void) __attribute__ ((noreturn));
 
 /* Dump task info to console */
 void
@@ -139,11 +148,7 @@ ao_task_info(void);
 void
 ao_start_scheduler(void) __attribute__((noreturn));
 
-#if HAS_TASK_QUEUE
 void
 ao_task_init(void);
-#else
-#define ao_task_init()
-#endif
 
 #endif