Fix up fancy dbg stuff. Add teleterra initial bits.
authorKeith Packard <keithp@keithp.com>
Tue, 21 Apr 2009 08:17:03 +0000 (01:17 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 21 Apr 2009 08:17:03 +0000 (01:17 -0700)
The dbg stuff needed a bit of help to actually walk the tables; it appears
that complex expressions confuse sdcc.

This also adds primitive teleterra bits, but no UI, etc.

Signed-off-by: Keith Packard <keithp@keithp.com>
15 files changed:
Makefile
ao.h
ao_adc.c
ao_cmd.c
ao_dbg.c
ao_ee.c
ao_gps.c
ao_log.c
ao_monitor.c
ao_serial.c
ao_telemetrum.c
ao_telemetry.c
ao_teleterra.c [new file with mode: 0644]
ao_tidongle.c
check-stack

index 550e737..09f9368 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -97,6 +97,20 @@ TI_SRC = \
        $(TELE_COMMON_SRC) \
        $(TI_TASK_SRC)
        
+TT_TASK_SRC = \
+       ao_teleterra.c
+#
+# All sources for TeleTerra
+#
+TT_SRC = \
+       $(ALTOS_SRC) \
+       $(ALTOS_DRIVER_SRC) \
+       $(TELE_RECEIVER_SRC) \
+       $(TELE_DRIVER_SRC) \
+       $(TELE_COMMON_SRC) \
+       $(TT_TASK_SRC)
+       
+       
 SRC = \
        $(ALTOS_SRC) \
        $(ALTOS_DRIVER_SRC) \
@@ -109,6 +123,7 @@ SRC = \
 
 TM_REL=$(TM_SRC:.c=.rel)
 TI_REL=$(TI_SRC:.c=.rel)
+TT_REL=$(TT_SRC:.c=.rel)
 
 ADB=$(SRC:.c=.adb)
 ASM=$(SRC:.c=.asm)
@@ -118,7 +133,7 @@ REL=$(SRC:.c=.rel)
 RST=$(SRC:.c=.rst)
 SYM=$(SRC:.c=.sym)
 
-PROGS=telemetrum.ihx tidongle.ihx
+PROGS=telemetrum.ihx tidongle.ihx teleterra.ihx
 PCDB=$(PROGS:.ihx=.cdb)
 PLNK=$(PROGS:.ihx=.lnk)
 PMAP=$(PROGS:.ihx=.map)
@@ -140,6 +155,12 @@ tidongle.ihx: $(TI_REL) Makefile
 
 tidongle.ihx: telemetrum.ihx
 
+teleterra.ihx: $(TT_REL) Makefile
+       $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(TT_REL)
+       sh check-stack ao.h teleterra.mem
+
+teleterra.ihx: tidongle.ihx
+
 altitude.h: make-altitude
        nickle make-altitude > altitude.h
 
diff --git a/ao.h b/ao.h
index acce918..c2e8327 100644 (file)
--- a/ao.h
+++ b/ao.h
@@ -622,6 +622,9 @@ ao_dbg_debug_mode(void);
 void
 ao_dbg_reset(void);
 
+void
+ao_dbg_init(void);
+
 /*
  * ao_serial.c
  */
@@ -685,17 +688,11 @@ ao_gps_init(void);
  * ao_telemetry.c
  */
 
-#define AO_TELEMETRY_SENSOR    1
-#define AO_TELEMETRY_GPS       2
-
 struct ao_telemetry {
-       uint8_t         addr;
-       uint8_t         type;
-       uint8_t         flight_state;
-       union {
-               struct ao_adc           adc;
-               struct ao_gps_data      gps;
-       } u;
+       uint8_t                 addr;
+       uint8_t                 flight_state;
+       struct ao_adc           adc;
+       struct ao_gps_data      gps;
 };
 
 void
index 39875bb..82e1b01 100644 (file)
--- a/ao_adc.c
+++ b/ao_adc.c
@@ -76,7 +76,7 @@ ao_adc_dump(void)
 }
 
 __code struct ao_cmds ao_adc_cmds[] = {
-       { 'a',  ao_adc_dump,    "a                                  Display current ADC values\n" },
+       { 'a',  ao_adc_dump,    "a                                  Display current ADC values" },
        { 0,    ao_adc_dump, NULL },
 };
 
index 13def7c..7722c59 100644 (file)
--- a/ao_cmd.c
+++ b/ao_cmd.c
@@ -226,10 +226,13 @@ help(void)
 {
        __xdata uint8_t cmds;
        __xdata uint8_t cmd;
+       __code struct ao_cmds * __xdata cs;
        puts(help_txt);
-       for (cmds = 0; cmds < ao_ncmds; cmds++)
-               for (cmd = 0; ao_cmds[cmds][cmd].cmd; cmd++)
-                       puts(ao_cmds[cmds][cmd].help);
+       for (cmds = 0; cmds < ao_ncmds; cmds++) {
+               cs = ao_cmds[cmds];
+               for (cmd = 0; cs[cmd].cmd != '\0'; cmd++)
+                       puts(cs[cmd].help);
+       }
 }
 
 static void
@@ -257,6 +260,8 @@ ao_cmd(void *parameters)
 {
        __xdata uint8_t c;
        __xdata uint8_t cmd, cmds;
+       __code struct ao_cmds * __xdata cs;
+       void (*__xdata func)(void);
        (void) parameters;
 
        lex_echo = 1;
@@ -268,16 +273,19 @@ ao_cmd(void *parameters)
                ao_cmd_lex();
                if (c == '\r' || c == '\n')
                        continue;
-               cmd = 0;
+               func = (void (*)(void)) NULL;
                for (cmds = 0; cmds < ao_ncmds; cmds++) {
-                       for (cmd = 0; ao_cmds[cmds][cmd].cmd != '\0'; cmd++)
-                               if (ao_cmds[cmds][cmd].cmd == c)
+                       cs = ao_cmds[cmds];
+                       for (cmd = 0; cs[cmd].cmd != '\0'; cmd++)
+                               if (cs[cmd].cmd == c) {
+                                       func = cs[cmd].func;
                                        break;
-                       if (ao_cmds[cmds][cmd].cmd)
+                               }
+                       if (func)
                                break;
                }
-               if (ao_cmds[cmds][cmd].cmd)
-                       (*ao_cmds[cmds][cmd].func);
+               if (func)
+                       (*func)();
                else
                        ao_cmd_status = ao_cmd_syntax_error;
                report();
@@ -288,9 +296,9 @@ __xdata struct ao_task ao_cmd_task;
 
 __code struct ao_cmds  ao_base_cmds[] = {
        { '?', help,            "?                                  Print this message" },
-       { 'T', ao_task_info,    "T                                  Show task states\n" },
-       { 'E', echo,            "E <0 off, 1 on>                    Set command echo mode\n" },
-       { 'd', dump,            "d <start> <end>                    Dump memory\n" },
+       { 'T', ao_task_info,    "T                                  Show task states" },
+       { 'E', echo,            "E <0 off, 1 on>                    Set command echo mode" },
+       { 'd', dump,            "d <start> <end>                    Dump memory" },
        { 0,    help,   NULL },
 };
 
index 11d8d50..76d4bd9 100644 (file)
--- a/ao_dbg.c
+++ b/ao_dbg.c
@@ -330,12 +330,12 @@ debug_output(void)
 }
 
 __code struct ao_cmds ao_dbg_cmds[7] = {
-       { 'D',  debug_enable,   "D                                  Enable debug mode\n" },
-       { 'G',  debug_get,      "G <count>                          Get data from debug port\n" },
-       { 'I',  debug_input,    "I <count> <addr>                   Input <count> bytes to target at <addr>\n" },
-       { 'O',  debug_output,   "O <count> <addr>                   Output <count> bytes to target at <addr>\n" },
-       { 'P',  debug_put,      "P <byte> ...                       Put data to debug port\n" },
-       { 'R',  debug_reset,    "R                                  Reset target\n" },
+       { 'D',  debug_enable,   "D                                  Enable debug mode" },
+       { 'G',  debug_get,      "G <count>                          Get data from debug port" },
+       { 'I',  debug_input,    "I <count> <addr>                   Input <count> bytes to target at <addr>" },
+       { 'O',  debug_output,   "O <count> <addr>                   Output <count> bytes to target at <addr>" },
+       { 'P',  debug_put,      "P <byte> ...                       Put data to debug port" },
+       { 'R',  debug_reset,    "R                                  Reset target" },
        { 0, debug_reset,       0 },
 };
 
diff --git a/ao_ee.c b/ao_ee.c
index 642de19..bce293c 100644 (file)
--- a/ao_ee.c
+++ b/ao_ee.c
@@ -403,8 +403,8 @@ ee_store(void)
 }
 
 __code struct ao_cmds ao_ee_cmds[] = {
-       { 'e', ee_dump,         "e <block>                          Dump a block of EEPROM data\n" },
-       { 'w', ee_store,        "w <block> <start> <len> <data> ... Write data to EEPROM\n" },
+       { 'e', ee_dump,         "e <block>                          Dump a block of EEPROM data" },
+       { 'w', ee_store,        "w <block> <start> <len> <data> ... Write data to EEPROM" },
        { 0,   ee_store, NULL },
 };
 
index 80b96aa..651a59e 100644 (file)
--- a/ao_gps.c
+++ b/ao_gps.c
@@ -257,7 +257,6 @@ void
 ao_gps_report(void)
 {
        static __xdata struct ao_log_record     gps_log;
-       static __xdata struct ao_telemetry      gps_telemetry;
        static __xdata struct ao_gps_data       gps_data;
 
        for (;;) {
@@ -287,9 +286,6 @@ ao_gps_report(void)
                gps_log.u.gps_altitude.altitude = gps_data.altitude;
                gps_log.u.gps_altitude.unused = 0xffff;
                ao_log_data(&gps_log);
-               gps_telemetry.type = AO_TELEMETRY_GPS;
-               memcpy(&gps_telemetry.u.gps, &gps_data, sizeof (struct ao_gps_data));
-               ao_telemetry_send(&gps_telemetry);
        }
                
 }
@@ -306,7 +302,7 @@ gps_dump(void) __reentrant
 }
 
 __code struct ao_cmds ao_gps_cmds[] = {
-       { 'g', gps_dump,        "g                                  Display current GPS values\n" },
+       { 'g', gps_dump,        "g                                  Display current GPS values" },
        { 0, gps_dump, NULL },
 };
 
index d7ff5c8..1b473c1 100644 (file)
--- a/ao_log.c
+++ b/ao_log.c
@@ -141,7 +141,7 @@ ao_log(void)
                        log.u.sensor.accel = ao_adc_ring[ao_log_adc_pos].accel;
                        log.u.sensor.pres = ao_adc_ring[ao_log_adc_pos].pres;
                        ao_log_data(&log);
-                       if (ao_log_adc_pos == 0) {
+                       if ((ao_log_adc_pos & 0x1f) == 0) {
                                log.type = AO_LOG_TEMP_VOLT;
                                log.tick = ao_adc_ring[ao_log_adc_pos].tick;
                                log.u.temp_volt.temp = ao_adc_ring[ao_log_adc_pos].temp;
@@ -193,7 +193,7 @@ dump_log(void)
 }
 
 __code struct ao_cmds ao_log_cmds[] = {
-       { 'l',  dump_log,               "l                                  Dump last flight log\n" },
+       { 'l',  dump_log,               "l                                  Dump last flight log" },
        { 0, dump_log, NULL },
 };
 
index 1c2d127..f3c1fe7 100644 (file)
@@ -45,21 +45,15 @@ ao_monitor(void)
                        ao_state_names[state]);
                if (!(recv.status & PKT_APPEND_STATUS_1_CRC_OK))
                        printf("CRC INVALID ");
-               switch (recv.telemetry.type) {
-               case AO_TELEMETRY_SENSOR:
-                       printf("%5u a: %d p: %d t: %d v: %d d: %d m: %d\n",
-                              recv.telemetry.u.adc.tick,
-                              recv.telemetry.u.adc.accel,
-                              recv.telemetry.u.adc.pres,
-                              recv.telemetry.u.adc.temp,
-                              recv.telemetry.u.adc.v_batt,
-                              recv.telemetry.u.adc.sense_d,
-                              recv.telemetry.u.adc.sense_m);
-                       break;
-               case AO_TELEMETRY_GPS:
-                       ao_gps_print(&recv.telemetry.u.gps);
-                       break;
-               }
+               printf("%5u a: %d p: %d t: %d v: %d d: %d m: %d\n",
+                      recv.telemetry.adc.tick,
+                      recv.telemetry.adc.accel,
+                      recv.telemetry.adc.pres,
+                      recv.telemetry.adc.temp,
+                      recv.telemetry.adc.v_batt,
+                      recv.telemetry.adc.sense_d,
+                      recv.telemetry.adc.sense_m);
+               ao_gps_print(&recv.telemetry.gps);
                ao_usb_flush();
        }
 }
index a229298..2ed0791 100644 (file)
@@ -101,7 +101,7 @@ send_serial(void)
 }
 
 __code struct ao_cmds ao_serial_cmds[] = {
-       { 'S', send_serial,             "S<data>                            Send data to serial line\n" },
+       { 'S', send_serial,             "S<data>                            Send data to serial line" },
        { 0, send_serial, NULL },
 };
 
index 1f7a829..d2e05eb 100644 (file)
@@ -41,5 +41,6 @@ main(void)
        ao_gps_init();
        ao_telemetry_init();
        ao_radio_init();
+       ao_dbg_init();
        ao_start_scheduler();
 }
index 092918d..b46f03c 100644 (file)
@@ -34,16 +34,18 @@ ao_telemetry_send(__xdata struct ao_telemetry *telemetry) __reentrant
 void
 ao_telemetry(void)
 {
-       static __xdata struct ao_radio_recv recv;
+       static __xdata struct ao_telemetry telemetry;
        static uint8_t state;
 
        while (ao_flight_state == ao_flight_startup || ao_flight_state == ao_flight_idle)
                ao_sleep(DATA_TO_XDATA(&ao_flight_state));
 
-       recv.telemetry.type = AO_TELEMETRY_SENSOR;
        for (;;) {
-               ao_adc_get(&recv.telemetry.u.adc);
-               ao_telemetry_send(&recv.telemetry);
+               ao_adc_get(&telemetry.adc);
+               ao_mutex_get(&ao_gps_mutex);
+               memcpy(&telemetry.gps, &ao_gps_data, sizeof (struct ao_gps_data));
+               ao_mutex_put(&ao_gps_mutex);
+               ao_telemetry_send(&telemetry);
                ao_delay(AO_MS_TO_TICKS(1000));
        }
 }
diff --git a/ao_teleterra.c b/ao_teleterra.c
new file mode 100644 (file)
index 0000000..6a2b004
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2009 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.
+ */
+
+#define AO_NO_ADC_ISR 1
+#include "ao.h"
+
+void
+main(void)
+{
+       CLKCON = 0;
+       while (!(SLEEP & SLEEP_XOSC_STB))
+               ;
+
+       /* Turn on the red LED until the system is stable */
+       ao_led_init();
+       ao_led_on(AO_LED_RED);
+       ao_timer_init();
+       ao_beep_init();
+       ao_cmd_init();
+       ao_usb_init();
+       ao_serial_init();
+       ao_gps_init();
+       ao_monitor_init();
+       ao_radio_init();
+       ao_dbg_init();
+       ao_start_scheduler();
+}
+
+/* Stub for systems which have no ADC */
+void
+ao_adc_poll(void)
+{
+}
+
+/* Stub to not log GPS data */
+void
+ao_log_data(struct ao_log_record *log)
+{
+       (void) log;
+}
+
index 385e0cf..ea21e12 100644 (file)
@@ -34,6 +34,9 @@ main(void)
        ao_usb_init();
        ao_monitor_init();
        ao_radio_init();
+       ao_dbg_init();
+       /* Bring up the USB link */
+       ao_led_on(AO_LED_GREEN);
        ao_start_scheduler();
 }
 
index 6d3106a..82680b8 100755 (executable)
@@ -6,7 +6,8 @@ HEADER_STACK=`awk '/#define AO_STACK_START/ {print $3}' $HEADER | nickle`
 MEM_STACK=`awk '/Stack starts at/ {print $4}' $MEM | nickle`
 
 if [ "$HEADER_STACK" -lt "$MEM_STACK" ]; then
-       echo "Set AO_STACK_START to at least $MEM_STACK"
+       MIN=0x`nickle -e "$MEM_STACK # 16"`
+       echo "Set AO_STACK_START to at least $MIN"
        exit 1
 else
        exit 0