altos/kernel: Allow ao_cmd to be built without tasking
authorKeith Packard <keithp@keithp.com>
Tue, 12 Dec 2017 23:30:45 +0000 (15:30 -0800)
committerKeith Packard <keithp@keithp.com>
Tue, 12 Dec 2017 23:30:45 +0000 (15:30 -0800)
Useful for single-threaded applications, like lambdakey

Signed-off-by: Keith Packard <keithp@keithp.com>
src/kernel/ao.h
src/kernel/ao_cmd.c
src/kernel/ao_notask.c
src/lambdakey-v1.0/ao_pins.h

index 139050cf78c64136792fbcaf870b170d177f578f..2bd0e3673d47701eb12565566260aeeb48eb5780 100644 (file)
@@ -218,6 +218,9 @@ ao_cmd_register(const __code struct ao_cmds *cmds);
 void
 ao_cmd_init(void);
 
+void
+ao_cmd(void);
+
 #if HAS_CMD_FILTER
 /*
  * Provided by an external module to filter raw command lines
index c1e9cef2cc901694a854b3d8a9f4d0c6e33eacda..405fd126dc36a3ce05308096b4f698263174c877 100644 (file)
@@ -423,11 +423,13 @@ ao_loader(void)
 }
 #endif
 
+#if HAS_TASK
 __xdata struct ao_task ao_cmd_task;
+#endif
 
 __code struct ao_cmds  ao_base_cmds[] = {
        { help,         "?\0Help" },
-#if HAS_TASK_INFO
+#if HAS_TASK_INFO && HAS_TASK
        { ao_task_info, "T\0Tasks" },
 #endif
        { echo,         "E <0 off, 1 on>\0Echo" },
@@ -445,5 +447,7 @@ void
 ao_cmd_init(void)
 {
        ao_cmd_register(&ao_base_cmds[0]);
+#if HAS_TASK
        ao_add_task(&ao_cmd_task, ao_cmd, "cmd");
+#endif
 }
index 00fe1ed61fc78d150dcf4e22102415e999d9d948..7207353af5444891b7982207c24d72fe5c3ddabc 100644 (file)
@@ -39,6 +39,21 @@ ao_sleep(__xdata void *wchan)
        return 0;
 }
 
+#if HAS_AO_DELAY
+void
+ao_delay(uint16_t ticks)
+{
+       AO_TICK_TYPE    target;
+
+       if (!ticks)
+               ticks = 1;
+       target = ao_tick_count + ticks;
+       do {
+               ao_sleep(&ao_time);
+       } while ((int16_t) (target - ao_tick_count) > 0);
+}
+#endif
+
 void
 ao_wakeup(__xdata void *wchan)
 {
index cb1c4aa736ba98914eae02cb7974c17aea1fc028..48b9db16e022aa45236edd69742e0e2089798e18 100644 (file)
@@ -20,6 +20,7 @@
 #define _AO_PINS_H_
 
 #define HAS_TASK       0
+#define HAS_AO_DELAY   1
 
 #define LED_PORT_ENABLE        STM_RCC_AHBENR_IOPBEN
 #define LED_PORT       (&stm_gpiob)