diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ao.h | 9 | ||||
-rw-r--r-- | src/core/ao_cmd.c | 46 | ||||
-rw-r--r-- | src/core/ao_monitor.c | 2 | ||||
-rw-r--r-- | src/core/ao_notask.c | 45 | ||||
-rw-r--r-- | src/core/ao_notask.h | 27 | ||||
-rw-r--r-- | src/core/ao_packet.h | 2 | ||||
-rw-r--r-- | src/core/ao_radio_cmac.c | 10 | ||||
-rw-r--r-- | src/core/ao_stdio.c | 17 | ||||
-rw-r--r-- | src/core/ao_task.c | 5 | ||||
-rw-r--r-- | src/core/ao_task.h | 4 | ||||
-rw-r--r-- | src/core/ao_telemetry.c | 1 |
11 files changed, 152 insertions, 16 deletions
diff --git a/src/core/ao.h b/src/core/ao.h index 977e10b8..0ad3e4aa 100644 --- a/src/core/ao.h +++ b/src/core/ao.h @@ -45,6 +45,8 @@ #if HAS_TASK #include <ao_task.h> +#else +#include <ao_notask.h> #endif /* @@ -145,6 +147,9 @@ extern __pdata char ao_cmd_lex_c; extern __pdata enum ao_cmd_status ao_cmd_status; void +ao_put_string(__code char *s); + +void ao_cmd_lex(void); void @@ -508,6 +513,8 @@ ao_telemetry_tiny_init(void); extern __xdata uint8_t ao_radio_dma; +extern __xdata int8_t ao_radio_rssi; + #ifdef PKT_APPEND_STATUS_1_CRC_OK #define AO_RADIO_STATUS_CRC_OK PKT_APPEND_STATUS_1_CRC_OK #else @@ -532,7 +539,7 @@ ao_radio_send(const __xdata void *d, uint8_t size) __reentrant; #if HAS_RADIO_RECV uint8_t -ao_radio_recv(__xdata void *d, uint8_t size) __reentrant; +ao_radio_recv(__xdata void *d, uint8_t size, uint8_t timeout) __reentrant; void ao_radio_recv_abort(void); diff --git a/src/core/ao_cmd.c b/src/core/ao_cmd.c index 3d086a57..16cde919 100644 --- a/src/core/ao_cmd.c +++ b/src/core/ao_cmd.c @@ -16,6 +16,7 @@ */ #include "ao.h" +#include "ao_task.h" __pdata uint16_t ao_cmd_lex_i; __pdata uint32_t ao_cmd_lex_u32; @@ -28,8 +29,8 @@ static __xdata char cmd_line[CMD_LEN]; static __pdata uint8_t cmd_len; static __pdata uint8_t cmd_i; -static void -put_string(__code char *s) +void +ao_put_string(__code char *s) { char c; while ((c = *s++)) @@ -39,7 +40,7 @@ put_string(__code char *s) static void backspace(void) { - put_string ("\010 \010"); + ao_put_string ("\010 \010"); } static void @@ -47,7 +48,7 @@ readline(void) { char c; if (ao_echo()) - put_string("> "); + ao_put_string("> "); cmd_len = 0; for (;;) { flush(); @@ -262,6 +263,11 @@ ao_reboot(void) ao_panic(AO_PANIC_REBOOT); } +#ifndef HAS_VERSION +#define HAS_VERSION 1 +#endif + +#if HAS_VERSION static void version(void) { @@ -289,6 +295,7 @@ version(void) #endif printf("software-version %s\n", ao_version); } +#endif #ifndef NUM_CMDS #define NUM_CMDS 11 @@ -303,13 +310,21 @@ help(void) __pdata uint8_t cmds; __pdata uint8_t cmd; __code struct ao_cmds * __pdata cs; - const char *h; + __code char *h; + uint8_t e; for (cmds = 0; cmds < ao_ncmds; cmds++) { cs = ao_cmds[cmds]; for (cmd = 0; cs[cmd].func; cmd++) { h = cs[cmd].help; - printf("%-45s %s\n", h, h + 1 + strlen(h)); + ao_put_string(h); + e = strlen(h); + h += e + 1; + e = 45 - e; + while (e--) + putchar(' '); + ao_put_string(h); + putchar('\n'); } } } @@ -370,14 +385,33 @@ ao_cmd(void) } } +#if HAS_BOOT_LOADER + +#include <ao_boot.h> + +static void +ao_loader(void) +{ + flush(); + ao_boot_loader(); +} +#endif + __xdata struct ao_task ao_cmd_task; __code struct ao_cmds ao_base_cmds[] = { { help, "?\0Help" }, +#if HAS_TASK_INFO { ao_task_info, "T\0Tasks" }, +#endif { echo, "E <0 off, 1 on>\0Echo" }, { ao_reboot, "r eboot\0Reboot" }, +#if HAS_VERSION { version, "v\0Version" }, +#endif +#if HAS_BOOT_LOADER + { ao_loader, "X\0Switch to boot loader" }, +#endif { 0, NULL }, }; diff --git a/src/core/ao_monitor.c b/src/core/ao_monitor.c index 5876bef7..18f170b4 100644 --- a/src/core/ao_monitor.c +++ b/src/core/ao_monitor.c @@ -81,7 +81,7 @@ ao_monitor_get(void) size = ao_monitoring; break; } - if (!ao_radio_recv(&ao_monitor_ring[ao_monitor_head], size + 2)) + if (!ao_radio_recv(&ao_monitor_ring[ao_monitor_head], size + 2, 0)) continue; ao_monitor_head = ao_monitor_ring_next(ao_monitor_head); ao_wakeup(DATA_TO_XDATA(&ao_monitor_head)); diff --git a/src/core/ao_notask.c b/src/core/ao_notask.c new file mode 100644 index 00000000..a41712d2 --- /dev/null +++ b/src/core/ao_notask.c @@ -0,0 +1,45 @@ +/* + * Copyright © 2012 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include <ao.h> + +static volatile void *ao_wchan; + +uint8_t +ao_sleep(__xdata void *wchan) +{ +#if 1 + ao_wchan = wchan; + ao_arch_wait_interrupt(); +#else + uint8_t sreg; + + ao_wchan = wchan; + asm("in %0,__SREG__" : "=&r" (sreg)); + sei(); + while (ao_wchan) + ao_arch_cpu_idle(); + asm("out __SREG__,%0" : : "r" (sreg)); +#endif + return 0; +} + +void +ao_wakeup(__xdata void *wchan) +{ + ao_wchan = 0; +} diff --git a/src/core/ao_notask.h b/src/core/ao_notask.h new file mode 100644 index 00000000..6b6b5bb8 --- /dev/null +++ b/src/core/ao_notask.h @@ -0,0 +1,27 @@ +/* + * Copyright © 2012 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#ifndef _AO_NOTASK_H_ +#define _AO_NOTASK_H_ + +uint8_t +ao_sleep(__xdata void *wchan); + +void +ao_wakeup(__xdata void *wchan); + +#endif /* _AO_NOTASK_H_ */ diff --git a/src/core/ao_packet.h b/src/core/ao_packet.h index 6d121bb9..b8426cf9 100644 --- a/src/core/ao_packet.h +++ b/src/core/ao_packet.h @@ -68,7 +68,7 @@ _ao_packet_pollchar(void); #if PACKET_HAS_MASTER /* ao_packet_master.c */ -extern __xdata uint8_t ao_packet_last_rssi; +extern __xdata int8_t ao_packet_last_rssi; void ao_packet_master_init(void); diff --git a/src/core/ao_radio_cmac.c b/src/core/ao_radio_cmac.c index fc0ca8b1..3ca3c313 100644 --- a/src/core/ao_radio_cmac.c +++ b/src/core/ao_radio_cmac.c @@ -85,18 +85,14 @@ radio_cmac_recv(uint8_t len, uint16_t timeout) __reentrant #if HAS_MONITOR ao_monitor_set(0); #endif - if (timeout) - ao_alarm(timeout); - - i = ao_radio_recv(cmac_data, len + AO_CMAC_KEY_LEN + 2); - ao_clear_alarm(); + i = ao_radio_recv(cmac_data, len + AO_CMAC_KEY_LEN + 2, timeout); if (!i) { ao_radio_cmac_rssi = 0; return AO_RADIO_CMAC_TIMEOUT; } - ao_radio_cmac_rssi = (int8_t) (((int8_t) cmac_data[len + AO_CMAC_KEY_LEN]) >> 1) - 74; + ao_radio_cmac_rssi = ao_radio_rssi; if (!(cmac_data[len + AO_CMAC_KEY_LEN +1] & AO_RADIO_STATUS_CRC_OK)) return AO_RADIO_CMAC_CRC_ERROR; @@ -150,7 +146,7 @@ ao_radio_cmac_send(__xdata void *packet, uint8_t len) __reentrant int8_t ao_radio_cmac_recv(__xdata void *packet, uint8_t len, uint16_t timeout) __reentrant { - uint8_t i; + int8_t i; if (len > AO_CMAC_MAX_LEN) return AO_RADIO_CMAC_LEN_ERROR; ao_mutex_get(&ao_radio_cmac_mutex); diff --git a/src/core/ao_stdio.c b/src/core/ao_stdio.c index 977d74b1..cd144d6b 100644 --- a/src/core/ao_stdio.c +++ b/src/core/ao_stdio.c @@ -66,8 +66,15 @@ #define AO_NUM_STDIOS (HAS_USB + PACKET_HAS_SLAVE + USE_SERIAL_STDIN) __xdata struct ao_stdio ao_stdios[AO_NUM_STDIOS]; + +#if AO_NUM_STDIOS > 1 __pdata int8_t ao_cur_stdio; __pdata int8_t ao_num_stdios; +#else +__pdata int8_t ao_cur_stdio; +#define ao_cur_stdio 0 +#define ao_num_stdios 0 +#endif void putchar(char c) @@ -107,12 +114,16 @@ getchar(void) __reentrant c = ao_stdios[stdio]._pollchar(); if (c != AO_READ_AGAIN) break; +#if AO_NUM_STDIOS > 1 if (++stdio == ao_num_stdios) stdio = 0; if (stdio == ao_cur_stdio) +#endif ao_sleep(&ao_stdin_ready); } +#if AO_NUM_STDIOS > 1 ao_cur_stdio = stdio; +#endif ao_arch_release_interrupts(); return c; } @@ -128,11 +139,17 @@ ao_add_stdio(int (*_pollchar)(void), void (*putchar)(char), void (*flush)(void)) __reentrant { +#if AO_NUM_STDIOS > 1 if (ao_num_stdios == AO_NUM_STDIOS) ao_panic(AO_PANIC_STDIO); +#endif ao_stdios[ao_num_stdios]._pollchar = _pollchar; ao_stdios[ao_num_stdios].putchar = putchar; ao_stdios[ao_num_stdios].flush = flush; ao_stdios[ao_num_stdios].echo = 1; +#if AO_NUM_STDIOS > 1 return ao_num_stdios++; +#else + return 0; +#endif } diff --git a/src/core/ao_task.c b/src/core/ao_task.c index 9cb074b5..0aad6508 100644 --- a/src/core/ao_task.c +++ b/src/core/ao_task.c @@ -512,6 +512,7 @@ ao_exit(void) /* we'll never get back here */ } +#if HAS_TASK_INFO void ao_task_info(void) { @@ -528,6 +529,7 @@ ao_task_info(void) ao_task_validate(); #endif } +#endif void ao_start_scheduler(void) @@ -536,5 +538,8 @@ ao_start_scheduler(void) ao_cur_task_index = AO_NO_TASK_INDEX; #endif ao_cur_task = NULL; +#if HAS_ARCH_START_SCHEDULER + ao_arch_start_scheduler(); +#endif ao_yield(); } diff --git a/src/core/ao_task.h b/src/core/ao_task.h index 50bfb220..1a4b5b6b 100644 --- a/src/core/ao_task.h +++ b/src/core/ao_task.h @@ -21,6 +21,10 @@ #include <ao_list.h> #endif +#ifndef HAS_TASK_INFO +#define HAS_TASK_INFO 1 +#endif + /* An AltOS task */ struct ao_task { __xdata void *wchan; /* current wait channel (NULL if running) */ diff --git a/src/core/ao_telemetry.c b/src/core/ao_telemetry.c index 03aa48d8..c3bbfec5 100644 --- a/src/core/ao_telemetry.c +++ b/src/core/ao_telemetry.c @@ -230,6 +230,7 @@ ao_send_location(void) ao_xmemcpy(&telemetry.location.flags, &ao_gps_data.flags, 26); + telemetry.location.tick = ao_gps_tick; ao_mutex_put(&ao_gps_mutex); ao_radio_send(&telemetry, sizeof (telemetry)); ao_telemetry_loc_cur = ao_telemetry_config_max; |