Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
authorBdale Garbee <bdale@gag.com>
Sat, 21 Nov 2020 18:00:43 +0000 (11:00 -0700)
committerBdale Garbee <bdale@gag.com>
Sat, 21 Nov 2020 18:00:43 +0000 (11:00 -0700)
altoslib/AltosAccelCal.java
altoslib/AltosConfigData.java
ao-bringup/test-easymini
ao-tools/ao-dump-up/ao-dump-up.c
configure.ac
src/kernel/ao_ignite.c
src/microtest/Makefile [new file with mode: 0644]
src/microtest/ao_microtest.c [new file with mode: 0644]
src/microtest/ao_pins.h [new file with mode: 0644]

index e8859b27aec7c7ddbff9b73a6d16be44f99d961d..8d0e992710f39cb265dfdbbb421b306f86e99e35 100644 (file)
@@ -182,6 +182,10 @@ public class AltosAccelCal implements Runnable {
                                if (config_data.pad_orientation != AltosLib.MISSING)
                                        link.printf("c o %d\n", config_data.pad_orientation);
                                if (plus != AltosLib.MISSING && minus != AltosLib.MISSING && plus != 0) {
+                                       if (plus < 0)
+                                               plus = 65536 + plus;
+                                       if (minus < 0)
+                                               minus = 65536 + minus;
                                        if (config_data.accel_zero_along != AltosLib.MISSING)
                                                link.printf("c a %d %d %d %d %d\n",
                                                            plus, minus,
index 5634ff410229f9fa77386c805e4f3b88c41446e2..ea7b63fa5813e963eabc60786258135c785ae8e0 100644 (file)
@@ -202,8 +202,8 @@ public class AltosConfigData {
                case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
                case AltosLib.AO_LOG_FORMAT_TELEMEGA:
                case AltosLib.AO_LOG_FORMAT_TELEMEGA_3:
-               case AltosLib.AO_LOG_FORMAT_TELEMEGA_4:
                        return 4095 - value;
+               case AltosLib.AO_LOG_FORMAT_TELEMEGA_4:
                case AltosLib.AO_LOG_FORMAT_EASYMEGA_2:
                case AltosLib.AO_LOG_FORMAT_EASYMOTOR:
                        return -value;
@@ -321,6 +321,9 @@ public class AltosConfigData {
        /* Return + accel calibration relative to a specific pad orientation */
        public int accel_cal_plus(int pad_orientation) {
                adjust_accel_cal();
+               if (!accel_cal_adjusted)
+                       return AltosLib.MISSING;
+
                switch (pad_orientation) {
                case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
                case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
@@ -338,6 +341,9 @@ public class AltosConfigData {
        /* Return - accel calibration relative to a specific pad orientation */
        public int accel_cal_minus(int pad_orientation) {
                adjust_accel_cal();
+               if (!accel_cal_adjusted)
+                       return AltosLib.MISSING;
+
                switch (pad_orientation) {
                case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
                case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
@@ -357,6 +363,7 @@ public class AltosConfigData {
         */
        private void adjust_accel_cal() {
                if (!accel_cal_adjusted &&
+                   product != null &&
                    pad_orientation != AltosLib.MISSING &&
                    accel_cal_plus != AltosLib.MISSING &&
                    accel_cal_minus != AltosLib.MISSING)
@@ -538,9 +545,6 @@ public class AltosConfigData {
                                }
                        }
                } catch (Exception e) {}
-
-               /* Fix accel cal as soon as all of the necessary values appear */
-               adjust_accel_cal();
        }
 
        public AltosConfigData() {
@@ -839,6 +843,10 @@ public class AltosConfigData {
                int plus = accel_cal_plus(pad_orientation);
                int minus = accel_cal_minus(pad_orientation);
                if (plus != AltosLib.MISSING && minus != AltosLib.MISSING) {
+                       if (plus < 0)
+                               plus = 65536 + plus;
+                       if (minus < 0)
+                               minus = 65536 + minus;
                        if (accel_zero_along != AltosLib.MISSING &&
                            accel_zero_across != AltosLib.MISSING &&
                            accel_zero_through != AltosLib.MISSING)
@@ -910,5 +918,6 @@ public class AltosConfigData {
                        read_link(link, "done");
                        break;
                }
+               adjust_accel_cal();
        }
 }
index ddcfcd5457d18b6ea703937687c0c59fbc9d18b8..c4479680120e4d722353bc1834a06535c3f657d7 100755 (executable)
@@ -21,6 +21,8 @@ while [ $found -eq 0 ]; do
                echo -e '\e[34m'Testing $product $serial $dev'\e[39m'
                echo ""
                
+               sleep 0.25
+
                ./test-igniters-nowait "$dev" drogue main
                echo ""
 
@@ -42,7 +44,6 @@ while [ $found -eq 0 ]; do
                    echo -e '\e[31m'"$PRODUCT-$VERSION serial $serial failed"'\e[39m'
                    exit 1
                fi
-
                echo ""
 
                echo -e '\e[32m'"$PRODUCT-v$VERSION" serial "$serial" is ready to ship'\e[39m'
@@ -57,6 +58,5 @@ while [ $found -eq 0 ]; do
     if [ $result -ne 2 ]; then
        exit $result
     fi
-    echo 'No device, sleeping...'
-    sleep 1
+    sleep 0.25
 done
index 6866ef592997e7fe24bf9954d5c6fa81c3b56faa..31bae4719127332713d5ab3dd932bd6278507d7d 100644 (file)
@@ -21,6 +21,7 @@
 #include <unistd.h>
 #include <getopt.h>
 #include <string.h>
+#include <stdbool.h>
 #include <ctype.h>
 #include "cc-usb.h"
 #include "cc.h"
@@ -52,6 +53,29 @@ static int get_nonwhite(struct cc_usb *cc, int timeout)
        }
 }
 
+static const uint8_t test_data[] = {
+       0xfc, 0xfd, 0xfe, 0xff, 0xf8, 0xf9, 0xfa, 0xfb, 0x40, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+       0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+       0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+       0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+       0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+       0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+       0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+       0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+       0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
+       0x17, 0x08,
+};
+
+static bool test_failed;
+static int test_pos;
+
+static void
+check_test(uint8_t b)
+{
+       if (test_pos >= sizeof (test_data) || test_data[test_pos++] != b)
+               test_failed = true;
+}
+
 static uint8_t
 get_hexc(struct cc_usb *cc)
 {
@@ -94,6 +118,7 @@ get_hex(struct cc_usb *cc)
        int     h = (a << 4) + b;
 
        file_crc = log_crc(file_crc, h);
+       check_test(h);
        return h;
 }
 
@@ -191,8 +216,12 @@ main (int argc, char **argv)
        current_crc = swap16(~file_crc & 0xffff);
        crc = get_16(cc);       /* crc */
        putchar ('\n');
-       if (crc == current_crc)
-               printf("CRC valid\n");
+       if (crc == current_crc) {
+               if (!test_failed)
+                       printf("\033[32mValid MicroTest Data\033[39m\n");
+               else
+                       printf("CRC valid\n");
+       }
        else
                printf("CRC invalid\n");
        cc_usb_close(cc);
index 936983e14e32a743be18807bfa242590aceee428..df5cbfdc662b445f9f510aef1ceba57e09d4b968 100644 (file)
@@ -18,13 +18,13 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.57)
-AC_INIT([altos], 1.9.6)
+AC_INIT([altos], 1.9.6.1)
 ANDROID_VERSION=27
 AC_CONFIG_SRCDIR([src/kernel/ao.h])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
 
-RELEASE_DATE=2020-10-21
+RELEASE_DATE=2020-10-29
 AC_SUBST(RELEASE_DATE)
 
 DOC_DATE=`LC_ALL=C date -d $RELEASE_DATE +'%d %b %Y'`
index e4e4843e1cb8383ba1597699988fc0c67a57bf6f..d197239a991e60db1ce9d90b38b8611335e4b184 100644 (file)
@@ -75,7 +75,7 @@ ao_igniter_status(enum ao_igniter igniter)
 #endif
 
 static void
-ao_igniter_fire(enum ao_igniter igniter)
+ao_igniter_fire(enum ao_igniter igniter, bool wait)
 {
        if (!ao_ignition[igniter].fired) {
                ao_ignition[igniter].firing = 1;
@@ -93,7 +93,8 @@ ao_igniter_fire(enum ao_igniter igniter)
                        break;
                }
                ao_ignition[igniter].firing = 0;
-               ao_delay(AO_IGNITER_CHARGE_TIME);
+               if (wait)
+                       ao_delay(AO_IGNITER_CHARGE_TIME);
        }
 }
 
@@ -111,27 +112,27 @@ ao_igniter(void)
                switch(ao_config.ignite_mode) {
                case AO_IGNITE_MODE_DUAL:
                        if (ao_flight_drogue <= ao_flight_state && ao_flight_state < ao_flight_landed)
-                               ao_igniter_fire(ao_igniter_drogue);
+                               ao_igniter_fire(ao_igniter_drogue, true);
                        if (ao_flight_main <= ao_flight_state && ao_flight_state < ao_flight_landed)
-                               ao_igniter_fire(ao_igniter_main);
+                               ao_igniter_fire(ao_igniter_main, true);
                        break;
                case AO_IGNITE_MODE_APOGEE:
                        if (ao_flight_drogue <= ao_flight_state && ao_flight_state < ao_flight_landed) {
-                               ao_igniter_fire(ao_igniter_drogue);
-                               ao_igniter_fire(ao_igniter_main);
+                               ao_igniter_fire(ao_igniter_drogue, true);
+                               ao_igniter_fire(ao_igniter_main, true);
                        }
                        break;
                case AO_IGNITE_MODE_MAIN:
                        if (ao_flight_main <= ao_flight_state && ao_flight_state < ao_flight_landed) {
-                               ao_igniter_fire(ao_igniter_drogue);
-                               ao_igniter_fire(ao_igniter_main);
+                               ao_igniter_fire(ao_igniter_drogue, true);
+                               ao_igniter_fire(ao_igniter_main, true);
                        }
                        break;
                case AO_IGNITE_MODE_BOOSTER:
                        if (ao_flight_fast <= ao_flight_state && ao_flight_state < ao_flight_landed)
-                               ao_igniter_fire(ao_igniter_main);
+                               ao_igniter_fire(ao_igniter_main, true);
                        if (ao_flight_drogue <= ao_flight_state && ao_flight_state < ao_flight_landed)
-                               ao_igniter_fire(ao_igniter_drogue);
+                               ao_igniter_fire(ao_igniter_drogue, true);
                        break;
                }
        }
@@ -149,12 +150,12 @@ ao_ignite_manual(void)
 #if HAS_IGNITE
        if (ao_cmd_lex_c == 'm' && ao_match_word("main")) {
                ao_ignition[ao_igniter_main].fired = 0;
-               ao_igniter_fire(ao_igniter_main);
+               ao_igniter_fire(ao_igniter_main, false);
                return;
        }
        if (ao_cmd_lex_c == 'd' && ao_match_word("drogue")) {
                ao_ignition[ao_igniter_drogue].fired = 0;
-               ao_igniter_fire(ao_igniter_drogue);
+               ao_igniter_fire(ao_igniter_drogue, false);
                return;
        }
 #endif
diff --git a/src/microtest/Makefile b/src/microtest/Makefile
new file mode 100644 (file)
index 0000000..04c31b0
--- /dev/null
@@ -0,0 +1,81 @@
+#
+# Tiny AltOS build
+#
+#
+TOPDIR=..
+include $(TOPDIR)/attiny/Makefile.defs
+
+PROGNAME=microtest-v1.0
+PROG=$(PROGNAME)-$(VERSION).elf
+HEX=$(PROGNAME)-$(VERSION).ihx
+
+ALTOS_SRC = \
+       ao_microtest.c \
+       ao_spi_attiny.c \
+       ao_led_tiny.c \
+       ao_clock.c \
+       ao_ms5607.c \
+       ao_exti.c \
+       ao_notask.c \
+       ao_eeprom_tiny.c \
+       ao_panic.c \
+       ao_log_micro.c \
+       ao_async.c \
+       ao_microflight.c \
+       ao_microkalman.c
+
+INC=\
+       ao.h \
+       ao_pins.h \
+       ao_arch.h \
+       ao_arch_funcs.h \
+       ao_exti.h \
+       ao_ms5607.h \
+       ao_log_micro.h \
+       ao_micropeak.h \
+       ao_product.h \
+       altitude-pa.h
+
+IDPRODUCT=0
+PRODUCT=MicroTest-v1.0
+PRODUCT_DEF=-DMICROPEAK
+CFLAGS = $(PRODUCT_DEF) $(ATTINY_CFLAGS)
+
+SRC=$(ALTOS_SRC)
+OBJ=$(SRC:.c=.o)
+
+all: $(PROG) $(HEX)
+
+CHECK=sh ../util/check-avr-mem
+
+$(PROG): Makefile $(OBJ)
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ)
+       $(call quiet,CHECK) $(PROG) || ($(RM) -f $(PROG); exit 1)
+
+$(HEX): $(PROG)
+       avr-size $(PROG)
+       $(OBJCOPY) -R .eeprom -O ihex $(PROG) $@
+
+load: $(HEX)
+       $(LOADCMD) $(LOADARG)$(HEX)
+
+load-slow: $(HEX)
+       $(LOADCMD) $(LOADSLOW) $(LOADARG)$(HEX)
+
+distclean:     clean
+
+clean:
+       rm -f *.o *.elf *.ihx *.map
+       rm -f ao_product.h
+
+load-product:
+       ./$(SCRIPT) fast
+
+load-product-slow:
+       ./$(SCRIPT) slow
+
+install:
+
+uninstall:
+
+$(OBJ): $(INC)
diff --git a/src/microtest/ao_microtest.c b/src/microtest/ao_microtest.c
new file mode 100644 (file)
index 0000000..168220c
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+ * 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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>
+#include <ao_micropeak.h>
+#include <ao_ms5607.h>
+#include <ao_async.h>
+#include <ao_log_micro.h>
+
+static struct ao_ms5607_value  value;
+
+alt_t          ground_alt, max_alt;
+alt_t          ao_max_height;
+
+void
+ao_pa_get(void)
+{
+       ao_ms5607_sample(&ao_ms5607_current);
+       ao_ms5607_convert(&ao_ms5607_current, &value);
+       pa = value.pres;
+}
+static void
+ao_pips(void)
+{
+       uint8_t i;
+       for (i = 0; i < 10; i++) {
+               ao_led_toggle(AO_LED_REPORT);
+               ao_delay(AO_MS_TO_TICKS(80));
+       }
+       ao_delay(AO_MS_TO_TICKS(200));
+}
+
+#define POLY 0x8408
+
+static uint16_t
+ao_log_micro_crc(uint16_t crc, uint8_t byte)
+{
+       uint8_t i;
+
+       for (i = 0; i < 8; i++) {
+               if ((crc & 0x0001) ^ (byte & 0x0001))
+                       crc = (crc >> 1) ^ POLY;
+               else
+                       crc = crc >> 1;
+               byte >>= 1;
+       }
+       return crc;
+}
+
+struct header {
+       uint32_t        pa_ground_offset;
+       uint32_t        pa_min_offset;
+       N_SAMPLES_TYPE  nsamples;
+};
+
+static const struct header head = {
+       .pa_ground_offset = 0xfffefdfc,
+       .pa_min_offset = 0xfbfaf9f8,
+       .nsamples = 64
+};
+
+static void
+ao_test_micro_dump(void)
+{
+       N_SAMPLES_TYPE  n_samples;
+       uint16_t        nbytes;
+       uint8_t         byte;
+       uint16_t        b;
+       uint16_t        crc = 0xffff;
+
+       n_samples = head.nsamples;
+       nbytes = STARTING_LOG_OFFSET + sizeof (uint16_t) * n_samples;
+
+       /*
+        * Rewrite n_samples so that it includes the log ID value with
+        * 32-bit n_samples split into two chunks
+        */
+       if (sizeof (n_samples) > 2) {
+               N_SAMPLES_TYPE  n_samples_low;
+               N_SAMPLES_TYPE  n_samples_high;
+               n_samples_low = n_samples & ((1 << AO_LOG_ID_SHIFT) - 1);
+               n_samples_high = (n_samples - n_samples_low) << AO_LOG_ID_WIDTH;
+               n_samples = n_samples_low | n_samples_high;
+       }
+#if AO_LOG_ID
+       n_samples |= AO_LOG_ID << AO_LOG_ID_SHIFT;
+#endif
+       ao_async_start();
+       ao_async_byte('M');
+       ao_async_byte('P');
+       for (b = 0; b < nbytes; b++) {
+               if ((b & 0xf) == 0)
+                       ao_log_newline();
+               if (b < sizeof (head))
+                       byte = ((uint8_t *) &head)[b];
+               else
+                       byte = b;
+#if AO_LOG_ID
+               if (N_SAMPLES_OFFSET <= b && b < (N_SAMPLES_OFFSET + sizeof(n_samples))) {
+                       byte = n_samples >> ((b - N_SAMPLES_OFFSET) << 3);
+               }
+#endif
+               ao_log_hex(byte);
+               crc = ao_log_micro_crc(crc, byte);
+       }
+       ao_log_newline();
+       crc = ~crc;
+       ao_log_hex(crc >> 8);
+       ao_log_hex(crc);
+       ao_log_newline();
+       ao_async_stop();
+}
+
+int
+main(void)
+{
+       ao_led_init();
+       ao_timer_init();
+
+       /* Init external hardware */
+       ao_spi_init();
+       ao_ms5607_init();
+       ao_ms5607_setup();
+
+       for (;;)
+       {
+               ao_delay(AO_MS_TO_TICKS(1000));
+
+               ao_pips();
+               ao_test_micro_dump();
+       }
+}
diff --git a/src/microtest/ao_pins.h b/src/microtest/ao_pins.h
new file mode 100644 (file)
index 0000000..2c02f3a
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright © 2011 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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_PINS_H_
+#define _AO_PINS_H_
+#include <avr/pgmspace.h>
+
+#define AO_LED_ORANGE          (1<<4)
+#define AO_LED_SERIAL          4
+#define AO_LED_PANIC           AO_LED_ORANGE
+#define AO_LED_REPORT          AO_LED_ORANGE
+#define LEDS_AVAILABLE         (AO_LED_ORANGE)
+#define USE_SERIAL_1_STDIN     0
+#define HAS_USB                        0
+#define PACKET_HAS_SLAVE       0
+#define HAS_SERIAL_1           0
+#define HAS_TASK               0
+#define HAS_MS5607             1
+#define HAS_MS5611             0
+#define HAS_SENSOR_ERRORS      0
+#define HAS_EEPROM             0
+#define HAS_BEEP               0
+#define AVR_CLOCK              250000UL
+
+/* SPI */
+#define SPI_PORT               PORTB
+#define SPI_PIN                        PINB
+#define SPI_DIR                        DDRB
+#define AO_MS5607_CS_PORT      PORTB
+#define AO_MS5607_CS_PIN       3
+
+/* MS5607 */
+#define AO_MS5607_SPI_INDEX    0
+#define AO_MS5607_MISO_PORT    PORTB
+#define AO_MS5607_MISO_PIN     0
+#define AO_MS5607_BARO_OVERSAMPLE      4096
+#define AO_MS5607_TEMP_OVERSAMPLE      1024
+
+/* I2C */
+#define I2C_PORT               PORTB
+#define I2C_PIN                        PINB
+#define I2C_DIR                        DDRB
+#define I2C_PIN_SCL            PINB2
+#define I2C_PIN_SDA            PINB0
+
+#define AO_CONST_ATTRIB                PROGMEM
+typedef int32_t alt_t;
+#define FETCH_ALT(o)           ((alt_t) pgm_read_dword(&altitude_table[o]))
+
+#define AO_ALT_VALUE(x)                ((x) * (alt_t) 10)
+
+#endif /* _AO_PINS_H_ */