altos: Add 'microtest' -- micropeak load for testing µPusb
authorKeith Packard <keithp@keithp.com>
Fri, 6 Nov 2020 05:58:04 +0000 (21:58 -0800)
committerKeith Packard <keithp@keithp.com>
Wed, 18 Nov 2020 05:40:21 +0000 (21:40 -0800)
This is custom MicroPeak firmware that just repeatedly generates
constant flight log data which can be used to validate µPusb boards.

Signed-off-by: Keith Packard <keithp@keithp.com>
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]

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_ */