Skip to content

Commit a9d4856

Browse files
committed
altos: Add 'microtest' -- micropeak load for testing µPusb
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 <[email protected]>
1 parent 898ef1a commit a9d4856

File tree

3 files changed

+295
-0
lines changed

3 files changed

+295
-0
lines changed

src/microtest/Makefile

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#
2+
# Tiny AltOS build
3+
#
4+
#
5+
TOPDIR=..
6+
include $(TOPDIR)/attiny/Makefile.defs
7+
8+
PROGNAME=microtest-v1.0
9+
PROG=$(PROGNAME)-$(VERSION).elf
10+
HEX=$(PROGNAME)-$(VERSION).ihx
11+
12+
ALTOS_SRC = \
13+
ao_microtest.c \
14+
ao_spi_attiny.c \
15+
ao_led_tiny.c \
16+
ao_clock.c \
17+
ao_ms5607.c \
18+
ao_exti.c \
19+
ao_notask.c \
20+
ao_eeprom_tiny.c \
21+
ao_panic.c \
22+
ao_log_micro.c \
23+
ao_async.c \
24+
ao_microflight.c \
25+
ao_microkalman.c
26+
27+
INC=\
28+
ao.h \
29+
ao_pins.h \
30+
ao_arch.h \
31+
ao_arch_funcs.h \
32+
ao_exti.h \
33+
ao_ms5607.h \
34+
ao_log_micro.h \
35+
ao_micropeak.h \
36+
ao_product.h \
37+
altitude-pa.h
38+
39+
IDPRODUCT=0
40+
PRODUCT=MicroTest-v1.0
41+
PRODUCT_DEF=-DMICROPEAK
42+
CFLAGS = $(PRODUCT_DEF) $(ATTINY_CFLAGS)
43+
44+
SRC=$(ALTOS_SRC)
45+
OBJ=$(SRC:.c=.o)
46+
47+
all: $(PROG) $(HEX)
48+
49+
CHECK=sh ../util/check-avr-mem
50+
51+
$(PROG): Makefile $(OBJ)
52+
$(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ)
53+
$(call quiet,CHECK) $(PROG) || ($(RM) -f $(PROG); exit 1)
54+
55+
$(HEX): $(PROG)
56+
avr-size $(PROG)
57+
$(OBJCOPY) -R .eeprom -O ihex $(PROG) $@
58+
59+
load: $(HEX)
60+
$(LOADCMD) $(LOADARG)$(HEX)
61+
62+
load-slow: $(HEX)
63+
$(LOADCMD) $(LOADSLOW) $(LOADARG)$(HEX)
64+
65+
distclean: clean
66+
67+
clean:
68+
rm -f *.o *.elf *.ihx *.map
69+
rm -f ao_product.h
70+
71+
load-product:
72+
./$(SCRIPT) fast
73+
74+
load-product-slow:
75+
./$(SCRIPT) slow
76+
77+
install:
78+
79+
uninstall:
80+
81+
$(OBJ): $(INC)

src/microtest/ao_microtest.c

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
* Copyright © 2012 Keith Packard <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program; if not, write to the Free Software Foundation, Inc.,
16+
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17+
*/
18+
19+
#include <ao.h>
20+
#include <ao_micropeak.h>
21+
#include <ao_ms5607.h>
22+
#include <ao_async.h>
23+
#include <ao_log_micro.h>
24+
25+
static struct ao_ms5607_value value;
26+
27+
alt_t ground_alt, max_alt;
28+
alt_t ao_max_height;
29+
30+
void
31+
ao_pa_get(void)
32+
{
33+
ao_ms5607_sample(&ao_ms5607_current);
34+
ao_ms5607_convert(&ao_ms5607_current, &value);
35+
pa = value.pres;
36+
}
37+
static void
38+
ao_pips(void)
39+
{
40+
uint8_t i;
41+
for (i = 0; i < 10; i++) {
42+
ao_led_toggle(AO_LED_REPORT);
43+
ao_delay(AO_MS_TO_TICKS(80));
44+
}
45+
ao_delay(AO_MS_TO_TICKS(200));
46+
}
47+
48+
#define POLY 0x8408
49+
50+
static uint16_t
51+
ao_log_micro_crc(uint16_t crc, uint8_t byte)
52+
{
53+
uint8_t i;
54+
55+
for (i = 0; i < 8; i++) {
56+
if ((crc & 0x0001) ^ (byte & 0x0001))
57+
crc = (crc >> 1) ^ POLY;
58+
else
59+
crc = crc >> 1;
60+
byte >>= 1;
61+
}
62+
return crc;
63+
}
64+
65+
struct header {
66+
uint32_t pa_ground_offset;
67+
uint32_t pa_min_offset;
68+
N_SAMPLES_TYPE nsamples;
69+
};
70+
71+
static const struct header head = {
72+
.pa_ground_offset = 0xfffefdfc,
73+
.pa_min_offset = 0xfbfaf9f8,
74+
.nsamples = 64
75+
};
76+
77+
static void
78+
ao_test_micro_dump(void)
79+
{
80+
N_SAMPLES_TYPE n_samples;
81+
uint16_t nbytes;
82+
uint8_t byte;
83+
uint16_t b;
84+
uint16_t crc = 0xffff;
85+
86+
n_samples = head.nsamples;
87+
nbytes = STARTING_LOG_OFFSET + sizeof (uint16_t) * n_samples;
88+
89+
/*
90+
* Rewrite n_samples so that it includes the log ID value with
91+
* 32-bit n_samples split into two chunks
92+
*/
93+
if (sizeof (n_samples) > 2) {
94+
N_SAMPLES_TYPE n_samples_low;
95+
N_SAMPLES_TYPE n_samples_high;
96+
n_samples_low = n_samples & ((1 << AO_LOG_ID_SHIFT) - 1);
97+
n_samples_high = (n_samples - n_samples_low) << AO_LOG_ID_WIDTH;
98+
n_samples = n_samples_low | n_samples_high;
99+
}
100+
#if AO_LOG_ID
101+
n_samples |= AO_LOG_ID << AO_LOG_ID_SHIFT;
102+
#endif
103+
ao_async_start();
104+
ao_async_byte('M');
105+
ao_async_byte('P');
106+
for (b = 0; b < nbytes; b++) {
107+
if ((b & 0xf) == 0)
108+
ao_log_newline();
109+
if (b < sizeof (head))
110+
byte = ((uint8_t *) &head)[b];
111+
else
112+
byte = b;
113+
#if AO_LOG_ID
114+
if (N_SAMPLES_OFFSET <= b && b < (N_SAMPLES_OFFSET + sizeof(n_samples))) {
115+
byte = n_samples >> ((b - N_SAMPLES_OFFSET) << 3);
116+
}
117+
#endif
118+
ao_log_hex(byte);
119+
crc = ao_log_micro_crc(crc, byte);
120+
}
121+
ao_log_newline();
122+
crc = ~crc;
123+
ao_log_hex(crc >> 8);
124+
ao_log_hex(crc);
125+
ao_log_newline();
126+
ao_async_stop();
127+
}
128+
129+
int
130+
main(void)
131+
{
132+
ao_led_init();
133+
ao_timer_init();
134+
135+
/* Init external hardware */
136+
ao_spi_init();
137+
ao_ms5607_init();
138+
ao_ms5607_setup();
139+
140+
for (;;)
141+
{
142+
ao_delay(AO_MS_TO_TICKS(1000));
143+
144+
ao_pips();
145+
ao_test_micro_dump();
146+
}
147+
}

src/microtest/ao_pins.h

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright © 2011 Keith Packard <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program; if not, write to the Free Software Foundation, Inc.,
16+
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17+
*/
18+
19+
#ifndef _AO_PINS_H_
20+
#define _AO_PINS_H_
21+
#include <avr/pgmspace.h>
22+
23+
#define AO_LED_ORANGE (1<<4)
24+
#define AO_LED_SERIAL 4
25+
#define AO_LED_PANIC AO_LED_ORANGE
26+
#define AO_LED_REPORT AO_LED_ORANGE
27+
#define LEDS_AVAILABLE (AO_LED_ORANGE)
28+
#define USE_SERIAL_1_STDIN 0
29+
#define HAS_USB 0
30+
#define PACKET_HAS_SLAVE 0
31+
#define HAS_SERIAL_1 0
32+
#define HAS_TASK 0
33+
#define HAS_MS5607 1
34+
#define HAS_MS5611 0
35+
#define HAS_SENSOR_ERRORS 0
36+
#define HAS_EEPROM 0
37+
#define HAS_BEEP 0
38+
#define AVR_CLOCK 250000UL
39+
40+
/* SPI */
41+
#define SPI_PORT PORTB
42+
#define SPI_PIN PINB
43+
#define SPI_DIR DDRB
44+
#define AO_MS5607_CS_PORT PORTB
45+
#define AO_MS5607_CS_PIN 3
46+
47+
/* MS5607 */
48+
#define AO_MS5607_SPI_INDEX 0
49+
#define AO_MS5607_MISO_PORT PORTB
50+
#define AO_MS5607_MISO_PIN 0
51+
#define AO_MS5607_BARO_OVERSAMPLE 4096
52+
#define AO_MS5607_TEMP_OVERSAMPLE 1024
53+
54+
/* I2C */
55+
#define I2C_PORT PORTB
56+
#define I2C_PIN PINB
57+
#define I2C_DIR DDRB
58+
#define I2C_PIN_SCL PINB2
59+
#define I2C_PIN_SDA PINB0
60+
61+
#define AO_CONST_ATTRIB PROGMEM
62+
typedef int32_t alt_t;
63+
#define FETCH_ALT(o) ((alt_t) pgm_read_dword(&altitude_table[o]))
64+
65+
#define AO_ALT_VALUE(x) ((x) * (alt_t) 10)
66+
67+
#endif /* _AO_PINS_H_ */

0 commit comments

Comments
 (0)