From 84c93bb2fc4558a5e4654794ba90e730a84eaf67 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Feb 2010 20:22:16 -0800 Subject: [PATCH] Change altos build process to support per-product compile-time changes This creates per-product subdirectories and recompiles everything for each product, allowing per-product compile-time changes for things like peripheral pin assignments and attached serial devices. Signed-off-by: Keith Packard --- src/Makefile | 306 +------------------------ src/Makefile.proto | 217 ++++++++++++++++++ src/ao.h | 38 +-- src/ao_adc.c | 7 +- src/ao_config.c | 18 +- src/ao_dbg.c | 32 +-- src/ao_host.h | 24 -- src/ao_packet.c | 8 + src/ao_packet_slave.c | 2 +- src/ao_pins.h | 144 ++++++++++++ src/ao_reboot.c | 28 +++ src/ao_stdio.c | 3 +- src/ao_teledongle.c | 5 +- src/ao_telemetrum.c | 6 +- src/ao_timer.c | 6 + src/teledongle-v0.1/Makefile | 1 + src/teledongle-v0.1/Makefile.defs | 9 + src/teledongle-v0.2/Makefile | 1 + src/teledongle-v0.2/Makefile.defs | 9 + src/telemetrum-v0.1-sirf/Makefile | 1 + src/telemetrum-v0.1-sirf/Makefile.defs | 11 + src/telemetrum-v0.1-sky/Makefile | 1 + src/telemetrum-v0.1-sky/Makefile.defs | 11 + src/telemetrum-v0.2/Makefile | 1 + src/telemetrum-v0.2/Makefile.defs | 11 + src/test/Makefile | 24 ++ src/tidongle/Makefile | 1 + src/tidongle/Makefile.defs | 8 + 28 files changed, 572 insertions(+), 361 deletions(-) create mode 100644 src/Makefile.proto create mode 100644 src/ao_pins.h create mode 100644 src/ao_reboot.c create mode 100644 src/teledongle-v0.1/Makefile create mode 100644 src/teledongle-v0.1/Makefile.defs create mode 100644 src/teledongle-v0.2/Makefile create mode 100644 src/teledongle-v0.2/Makefile.defs create mode 100644 src/telemetrum-v0.1-sirf/Makefile create mode 100644 src/telemetrum-v0.1-sirf/Makefile.defs create mode 100644 src/telemetrum-v0.1-sky/Makefile create mode 100644 src/telemetrum-v0.1-sky/Makefile.defs create mode 100644 src/telemetrum-v0.2/Makefile create mode 100644 src/telemetrum-v0.2/Makefile.defs create mode 100644 src/test/Makefile create mode 100644 src/tidongle/Makefile create mode 100644 src/tidongle/Makefile.defs diff --git a/src/Makefile b/src/Makefile index dcd41718..e2699ee6 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,307 +4,23 @@ # CC=sdcc -ifndef VERSION -VERSION=$(shell git describe) -endif +SUBDIRS=telemetrum-v0.2 teledongle-v0.2 telemetrum-v0.1-sky telemetrum-v0.1-sirf teledongle-v0.1 tidongle test -CFLAGS=--model-small --debug --opt-code-speed +all: all-recursive -LDFLAGS=--out-fmt-ihx --code-loc 0x0000 --code-size 0x8000 \ - --xram-loc 0xf000 --xram-size 0xda2 --iram-size 0xff +RECURSIVE_TARGETS = all-recursive clean-recursive install-recursive -INC = \ - ao.h \ - cc1111.h \ - altitude.h \ - 25lc1024.h - -# -# Common AltOS sources -# -ALTOS_SRC = \ - ao_cmd.c \ - ao_dma.c \ - ao_mutex.c \ - ao_panic.c \ - ao_task.c \ - ao_timer.c \ - _bp.c - -# -# Shared AltOS drivers -# -ALTOS_DRIVER_SRC = \ - ao_beep.c \ - ao_config.c \ - ao_led.c \ - ao_radio.c \ - ao_stdio.c \ - ao_usb.c - -TELE_COMMON_SRC = \ - ao_packet.c \ - ao_packet_slave.c \ - ao_state.c - -# -# Receiver code -# -TELE_RECEIVER_SRC =\ - ao_monitor.c \ - ao_gps_print.c \ - ao_packet_master.c \ - ao_rssi.c - -# -# Shared Tele drivers (on TeleMetrum, TeleTerra, TeleDongle) -# - -TELE_DRIVER_SRC = \ - ao_convert.c \ - ao_serial.c - -# -# Drivers for partially-flled boards (TT, TD and TI) -# -TELE_FAKE_SRC = \ - ao_adc_fake.c \ - ao_ee_fake.c - -# -# Debug dongle driver (only on TI) -# -DBG_DONGLE_SRC = \ - ao_dbg.c - -# -# Drivers only on TeleMetrum -# -TM_DRIVER_SRC = \ - ao_adc.c \ - ao_flash.c \ - ao_gps_report.c \ - ao_ignite.c - -# -# Drivers only on TeleMetrum -# -TM_SIRF_DRIVER_SRC = \ - ao_gps_sirf.c -# -# Drivers only on TeleMetrum -# -TM_SKY_DRIVER_SRC = \ - ao_gps_skytraq.c - -# -# Tasks run on TeleMetrum -# -TM_TASK_SRC = \ - ao_flight.c \ - ao_log.c \ - ao_report.c \ - ao_telemetry.c - -TM_MAIN_SRC = \ - ao_telemetrum.c - -# -# All sources for TeleMetrum -# -TM_SRC = \ - $(ALTOS_SRC) \ - $(ALTOS_DRIVER_SRC) \ - $(TELE_DRIVER_SRC) \ - $(TELE_COMMON_SRC) \ - $(TM_DRIVER_SRC) \ - $(TM_TASK_SRC) \ - $(TM_MAIN_SRC) - -TM_SIRF_SRC = \ - $(TM_SRC) \ - $(TM_SIRF_DRIVER_SRC) - -TM_SKY_SRC = \ - $(TM_SRC) \ - $(TM_SKY_DRIVER_SRC) - -TI_MAIN_SRC = \ - ao_tidongle.c - -# -# All sources for the TI debug dongle -# -TI_SRC = \ - $(ALTOS_SRC) \ - $(ALTOS_DRIVER_SRC) \ - $(TELE_RECEIVER_SRC) \ - $(TELE_COMMON_SRC) \ - $(TELE_FAKE_SRC) \ - $(TI_MAIN_SRC) \ - $(DBG_DONGLE_SRC) - -TT_MAIN_SRC = \ - ao_teleterra.c -# -# All sources for TeleTerra -# -TT_SRC = \ - $(ALTOS_SRC) \ - $(ALTOS_DRIVER_SRC) \ - $(TELE_RECEIVER_SRC) \ - $(TELE_DRIVER_SRC) \ - $(TELE_COMMON_SRC) \ - $(TELE_FAKE_SRC) \ - $(TT_MAIN_SRC) - - -# -# Sources for TeleDongle -# - -TD_MAIN_SRC = \ - ao_teledongle.c - -TD_SRC = \ - $(ALTOS_SRC) \ - $(ALTOS_DRIVER_SRC) \ - $(TELE_RECEIVER_SRC) \ - $(TELE_COMMON_SRC) \ - $(TELE_FAKE_SRC) \ - $(TD_MAIN_SRC) - -SRC = \ - $(ALTOS_SRC) \ - $(ALTOS_DRIVER_SRC) \ - $(TELE_DRIVER_SRC) \ - $(TELE_RECEIVER_SRC) \ - $(TELE_COMMON_SRC) \ - $(TELE_FAKE_SRC) \ - $(TM_DRIVER_SRC) \ - $(TM_SIRF_DRIVER_SRC) \ - $(TM_SKY_DRIVER_SRC) \ - $(TM_TASK_SRC) \ - $(TM_MAIN_SRC) \ - $(TI_MAIN_SRC) \ - $(TD_MAIN_SRC) \ - $(TT_MAIN_SRC) - -TM_SIRF_REL=$(TM_SIRF_SRC:.c=.rel) ao_product-telemetrum.rel -TM_SKY_REL=$(TM_SKY_SRC:.c=.rel) ao_product-telemetrum.rel -TI_REL=$(TI_SRC:.c=.rel) ao_product-tidongle.rel -TT_REL=$(TT_SRC:.c=.rel) ao_product-teleterra.rel -TD_REL=$(TD_SRC:.c=.rel) ao_product-teledongle.rel - -PROD_REL=\ - ao_product-telemetrum.rel \ - ao_product-tidongle.rel \ - ao_product-teleterra.rel \ - ao_product-teledongle.rel - -REL=$(SRC:.c=.rel) $(PROD_REL) -ADB=$(REL:.rel=.adb) -ASM=$(REL:.rel=.asm) -LNK=$(REL:.rel=.lnk) -LST=$(REL:.rel=.lst) -RST=$(REL:.rel=.rst) -SYM=$(REL:.rel=.sym) - -PROGS= telemetrum-sirf.ihx telemetrum-sky.ihx tidongle.ihx \ - teleterra.ihx teledongle.ihx - -HOST_PROGS=ao_flight_test ao_gps_test ao_gps_test_skytraq - -PCDB=$(PROGS:.ihx=.cdb) -PLNK=$(PROGS:.ihx=.lnk) -PMAP=$(PROGS:.ihx=.map) -PMEM=$(PROGS:.ihx=.mem) -PAOM=$(PROGS:.ihx=) - -%.rel : %.c $(INC) - $(CC) -c $(CFLAGS) -o$*.rel $*.c - -all: $(PROGS) $(HOST_PROGS) - -telemetrum-sirf.ihx: $(TM_SIRF_REL) Makefile - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(TM_SIRF_REL) - sh check-stack ao.h telemetrum-sirf.mem - -telemetrum-sky.ihx: $(TM_SKY_REL) Makefile - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(TM_SKY_REL) - sh check-stack ao.h telemetrum-sky.mem - -telemetrum-sky.ihx: telemetrum-sirf.ihx - -tidongle.ihx: $(TI_REL) Makefile - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(TI_REL) - sh check-stack ao.h tidongle.mem - -tidongle.ihx: telemetrum-sky.ihx - -teleterra.ihx: $(TT_REL) Makefile - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(TT_REL) - sh check-stack ao.h teleterra.mem - -teleterra.ihx: tidongle.ihx - -teledongle.ihx: $(TD_REL) Makefile - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(TD_REL) - sh check-stack ao.h teledongle.mem - -teledongle.ihx: teleterra.ihx - -altitude.h: make-altitude - nickle make-altitude > altitude.h - -TELEMETRUM_DEFS=ao-telemetrum.h -TELETERRA_DEFS=ao-teleterra.h -TELEDONGLE_DEFS=ao-teledongle.h -TIDONGLE_DEFS=ao-tidongle.h - -ALL_DEFS=$(TELEMETRUM_DEFS) $(TELETERRA_DEFS) \ - $(TELEDONGLE_DEFS) $(TIDONGLE_DEFS) -ao_product-telemetrum.rel: ao_product.c $(TELEMETRUM_DEFS) - $(CC) -c $(CFLAGS) -D PRODUCT_DEFS='\"$(TELEMETRUM_DEFS)\"' -o$@ ao_product.c - -ao_product-teleterra.rel: ao_product.c $(TELETERRA_DEFS) - $(CC) -c $(CFLAGS) -D PRODUCT_DEFS='\"$(TELETERRA_DEFS)\"' -o$@ ao_product.c - -ao_product-teledongle.rel: ao_product.c $(TELEDONGLE_DEFS) - $(CC) -c $(CFLAGS) -D PRODUCT_DEFS='\"$(TELEDONGLE_DEFS)\"' -o$@ ao_product.c - -ao_product-tidongle.rel: ao_product.c $(TIDONGLE_DEFS) - $(CC) -c $(CFLAGS) -D PRODUCT_DEFS='\"$(TIDONGLE_DEFS)\"' -o$@ ao_product.c - -$(TELEMETRUM_DEFS): ao-make-product.5c - nickle ao-make-product.5c -m altusmetrum.org -p TeleMetrum -v $(VERSION) > $@ - -$(TELETERRA_DEFS): ao-make-product.5c - nickle ao-make-product.5c -m altusmetrum.org -p TeleTerra -v $(VERSION) > $@ - -$(TELEDONGLE_DEFS): ao-make-product.5c - nickle ao-make-product.5c -m altusmetrum.org -p TeleDongle -v $(VERSION) > $@ - -$(TIDONGLE_DEFS): ao-make-product.5c - nickle ao-make-product.5c -m altusmetrum.org -p TIDongle -v $(VERSION) > $@ +$(RECURSIVE_TARGETS): + @target=`echo $@ | sed 's/-recursive//'`; \ + for subdir in $(SUBDIRS); do \ + echo "Making $$target in $$subdir"; \ + (cd $$subdir && $(MAKE) $$target) || exit 1; \ + done distclean: clean -clean: - rm -f $(ADB) $(ASM) $(LNK) $(LST) $(REL) $(RST) $(SYM) - rm -f $(PROGS) $(PCDB) $(PLNK) $(PMAP) $(PMEM) $(PAOM) - rm -f $(ALL_DEFS) $(HOST_PROGS) - rm -f $(TELEMETRUM_DEFS) $(TELETERRA_DEFS) $(TELEDONGLE_DEFS) $(TIDONGLE_DEFS) +clean: clean-recursive -install: +install: install-recursive uninstall: - -ao_flight_test: ao_flight.c ao_flight_test.c ao_host.h - cc -g -o $@ ao_flight_test.c - -ao_gps_test: ao_gps_sirf.c ao_gps_test.c ao_gps_print.c ao_host.h - cc -g -o $@ ao_gps_test.c - -ao_gps_test_skytraq: ao_gps_skytraq.c ao_gps_test_skytraq.c ao_gps_print.c ao_host.h - cc -g -o $@ ao_gps_test_skytraq.c diff --git a/src/Makefile.proto b/src/Makefile.proto new file mode 100644 index 00000000..958b7572 --- /dev/null +++ b/src/Makefile.proto @@ -0,0 +1,217 @@ +# +# AltOS build +# +# +vpath %.c .. +vpath %.h .. +vpath make-altitude .. +vpath ao-make-product.5c .. + +CC=sdcc + +ifndef VERSION +VERSION=$(shell git describe) +endif + +CFLAGS=--model-small --debug --opt-code-speed + +LDFLAGS=--out-fmt-ihx --code-loc 0x0000 --code-size 0x8000 \ + --xram-loc 0xf000 --xram-size 0xda2 --iram-size 0xff + +INC = \ + ao.h \ + ao_pins.h \ + cc1111.h \ + altitude.h \ + 25lc1024.h + +# +# Common AltOS sources +# +ALTOS_SRC = \ + ao_cmd.c \ + ao_dma.c \ + ao_mutex.c \ + ao_panic.c \ + ao_task.c \ + ao_timer.c \ + _bp.c + +# +# Shared AltOS drivers +# +ALTOS_DRIVER_SRC = \ + ao_beep.c \ + ao_config.c \ + ao_led.c \ + ao_radio.c \ + ao_stdio.c \ + ao_usb.c + +TELE_COMMON_SRC = \ + ao_packet.c \ + ao_packet_slave.c \ + ao_state.c + +# +# Receiver code +# +TELE_RECEIVER_SRC =\ + ao_monitor.c \ + ao_gps_print.c \ + ao_packet_master.c \ + ao_rssi.c + +# +# Shared Tele drivers (on TeleMetrum, TeleTerra, TeleDongle) +# + +TELE_DRIVER_SRC = \ + ao_convert.c \ + ao_serial.c + +# +# Debug dongle driver (only on TI) +# +DBG_SRC = \ + ao_dbg.c + +# +# Drivers only on TeleMetrum +# +TM_DRIVER_SRC = \ + ao_adc.c \ + ao_gps_report.c \ + ao_ignite.c + +# +# 25LC1024 driver source +EE_DRIVER_SRC = \ + ao_ee.c + +# +# AT45DB161D driver source + +FLASH_DRIVER_SRC = \ + ao_flash.c + +# +# SiRF driver source +# +SIRF_DRIVER_SRC = \ + ao_gps_sirf.c +# +# Skytraq driver source +# +SKY_DRIVER_SRC = \ + ao_gps_skytraq.c + +# +# Tasks run on TeleMetrum +# +TM_TASK_SRC = \ + ao_flight.c \ + ao_log.c \ + ao_report.c \ + ao_telemetry.c + +TM_MAIN_SRC = \ + ao_telemetrum.c + +# +# Base sources for TeleMetrum +# +TM_BASE_SRC = \ + $(ALTOS_SRC) \ + $(ALTOS_DRIVER_SRC) \ + $(TELE_DRIVER_SRC) \ + $(TELE_COMMON_SRC) \ + $(TM_DRIVER_SRC) \ + $(TM_TASK_SRC) \ + $(TM_MAIN_SRC) + +TI_MAIN_SRC = \ + ao_tidongle.c + +# +# All sources for the TI debug dongle +# +TI_SRC = \ + $(ALTOS_SRC) \ + $(ALTOS_DRIVER_SRC) \ + $(TELE_RECEIVER_SRC) \ + $(TELE_COMMON_SRC) \ + $(TI_MAIN_SRC) \ + $(DBG_SRC) + +TT_MAIN_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_MAIN_SRC) + + +# +# Sources for TeleDongle +# + +TD_MAIN_SRC = \ + ao_teledongle.c + +TD_SRC = \ + $(ALTOS_SRC) \ + $(ALTOS_DRIVER_SRC) \ + $(TELE_RECEIVER_SRC) \ + $(TELE_COMMON_SRC) \ + $(TD_MAIN_SRC) + +include Makefile.defs + +REL=$(SRC:.c=.rel) ao_product.rel +ADB=$(REL:.rel=.adb) +ASM=$(REL:.rel=.asm) +LNK=$(REL:.rel=.lnk) +LST=$(REL:.rel=.lst) +RST=$(REL:.rel=.rst) +SYM=$(REL:.rel=.sym) + +PCDB=$(PROG:.ihx=.cdb) +PLNK=$(PROG:.ihx=.lnk) +PMAP=$(PROG:.ihx=.map) +PMEM=$(PROG:.ihx=.mem) +PAOM=$(PROG:.ihx=) + +%.rel : %.c $(INC) + $(CC) -c $(CFLAGS) -o$@ $< + +all: $(PROG) + +$(PROG): $(REL) Makefile Makefile.defs ../Makefile.proto + $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(REL) + +../altitude.h: make-altitude + nickle $< > $@ + +ao_product.h: ao-make-product.5c + nickle $< -m altusmetrum.org -p $(PRODUCT) -v $(VERSION) > $@ + +ao_product.rel: ao_product.c ao_product.h + $(CC) -c $(CFLAGS) -D PRODUCT_DEFS='\"ao_product.h\"' -o$@ $< + +distclean: clean + +clean: + rm -f $(ADB) $(ASM) $(LNK) $(LST) $(REL) $(RST) $(SYM) + rm -f $(PROG) $(PCDB) $(PLNK) $(PMAP) $(PMEM) $(PAOM) + rm -f ao_product.h + +install: + +uninstall: diff --git a/src/ao.h b/src/ao.h index d6be2223..b43f5ecd 100644 --- a/src/ao.h +++ b/src/ao.h @@ -23,6 +23,7 @@ #include #include #include "cc1111.h" +#include "ao_pins.h" #define TRUE 1 #define FALSE 0 @@ -148,15 +149,7 @@ void ao_clock_init(void); /* - * ao_adc.c - */ - -#define AO_ADC_RING 32 -#define ao_adc_ring_next(n) (((n) + 1) & (AO_ADC_RING - 1)) -#define ao_adc_ring_prev(n) (((n) - 1) & (AO_ADC_RING - 1)) - -/* - * One set of samples read from the A/D converter + * One set of samples read from the A/D converter or telemetry */ struct ao_adc { uint16_t tick; /* tick when the sample was read */ @@ -168,6 +161,20 @@ struct ao_adc { int16_t sense_m; /* main continuity sense */ }; +#ifndef HAS_ADC +#error Please define HAS_ADC +#endif + +#if HAS_ADC +/* + * ao_adc.c + */ + +#define AO_ADC_RING 32 +#define ao_adc_ring_next(n) (((n) + 1) & (AO_ADC_RING - 1)) +#define ao_adc_ring_prev(n) (((n) - 1) & (AO_ADC_RING - 1)) + + /* * A/D data is stored in a ring, with the next sample to be written * at ao_adc_head @@ -188,15 +195,16 @@ void ao_adc_get(__xdata struct ao_adc *packet); /* The A/D interrupt handler */ -#if !AO_NO_ADC_ISR + void ao_adc_isr(void) interrupt 1; -#endif /* Initialize the A/D converter */ void ao_adc_init(void); +#endif /* HAS_ADC */ + /* * ao_beep.c */ @@ -696,13 +704,16 @@ ao_dbg_init(void); * ao_serial.c */ -#if !AO_NO_SERIAL_ISR +#ifndef HAS_SERIAL_1 +#error Please define HAS_SERIAL_1 +#endif + +#if HAS_SERIAL_1 void ao_serial_rx1_isr(void) interrupt 3; void ao_serial_tx1_isr(void) interrupt 14; -#endif char ao_serial_getchar(void) __critical; @@ -719,6 +730,7 @@ ao_serial_set_speed(uint8_t speed); void ao_serial_init(void); +#endif /* * ao_gps.c diff --git a/src/ao_adc.c b/src/ao_adc.c index 2b972e6c..50f96848 100644 --- a/src/ao_adc.c +++ b/src/ao_adc.c @@ -16,6 +16,7 @@ */ #include "ao.h" +#include "ao_pins.h" volatile __xdata struct ao_adc ao_adc_ring[AO_ADC_RING]; volatile __data uint8_t ao_adc_head; @@ -52,11 +53,13 @@ ao_adc_isr(void) interrupt 1 a[0] = ADCL; a[1] = ADCH; if (sequence < 5) { +#if HAS_EXTERNAL_TEMP == 0 /* start next channel conversion */ /* v0.2 replaces external temp sensor with internal one */ if (sequence == 1) ADCCON3 = ADCCON3_EREF_1_25 | ADCCON3_EDIV_512 | ADCCON3_ECH_TEMP; else +#endif ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | (sequence + 1); } else { /* record this conversion series */ @@ -86,7 +89,9 @@ ao_adc_init(void) { ADCCFG = ((1 << 0) | /* acceleration */ (1 << 1) | /* pressure */ -/* (1 << 2) | v0.1 temperature */ +#if HAS_EXTERNAL_TEMP + (1 << 2) | /* v0.1 temperature */ +#endif (1 << 3) | /* battery voltage */ (1 << 4) | /* drogue sense */ (1 << 5)); /* main sense */ diff --git a/src/ao_config.c b/src/ao_config.c index 4349bca8..f8ea27fe 100644 --- a/src/ao_config.c +++ b/src/ao_config.c @@ -38,18 +38,22 @@ __xdata uint8_t ao_config_mutex; */ const uint32_t ao_radio_cal = 1186611; +#if HAS_EEPROM static void _ao_config_put(void) { ao_ee_write_config((uint8_t *) &ao_config, sizeof (ao_config)); } +#endif static void _ao_config_get(void) { if (ao_config_loaded) return; +#if HAS_EEPROM ao_ee_read_config((uint8_t *) &ao_config, sizeof (ao_config)); +#endif if (ao_config.major != AO_CONFIG_MAJOR) { ao_config.major = AO_CONFIG_MAJOR; ao_config.minor = AO_CONFIG_MINOR; @@ -149,6 +153,8 @@ ao_config_radio_channel_set(void) __reentrant ao_config_radio_channel_show(); } +#if HAS_ADC + void ao_config_main_deploy_show(void) __reentrant { @@ -259,6 +265,8 @@ ao_config_apogee_delay_set(void) __reentrant ao_config_apogee_delay_show(); } +#endif /* HAS_ADC */ + void ao_config_radio_cal_show(void) __reentrant { @@ -296,25 +304,31 @@ void ao_config_write(void) __reentrant; __code struct ao_config_var ao_config_vars[] = { +#if HAS_ADC { 'm', ao_config_main_deploy_set, ao_config_main_deploy_show, "m Set height above launch for main deploy (in meters)" }, { 'd', ao_config_apogee_delay_set, ao_config_apogee_delay_show, "d Set apogee igniter delay (in seconds)" }, +#endif /* HAS_ADC */ { 'r', ao_config_radio_channel_set, ao_config_radio_channel_show, "r Set radio channel (freq = 434.550 + channel * .1)" }, { 'c', ao_config_callsign_set, ao_config_callsign_show, "c Set callsign broadcast in each packet (8 char max)" }, +#if HAS_ADC { 'a', ao_config_accel_calibrate_set, ao_config_accel_calibrate_show, "a <+g> <-g> Set accelerometer calibration (0 for auto)" }, +#endif /* HAS_ADC */ { 'f', ao_config_radio_cal_set, ao_config_radio_cal_show, "f Set radio calibration value (cal = rf/(xtal/2^16))" }, { 's', ao_config_show, ao_config_show, "s Show current config values" }, +#if HAS_EEPROM { 'w', ao_config_write, ao_config_write, "w Write current values to eeprom" }, +#endif { '?', ao_config_help, ao_config_help, "? Show available config variables" }, - { 0, ao_config_main_deploy_set, ao_config_main_deploy_show, + { 0, ao_config_help, ao_config_help, NULL }, }; @@ -359,6 +373,7 @@ ao_config_show(void) __reentrant (*ao_config_vars[cmd].show)(); } +#if HAS_EEPROM void ao_config_write(void) __reentrant { @@ -370,6 +385,7 @@ ao_config_write(void) __reentrant } ao_mutex_put(&ao_config_mutex); } +#endif __code struct ao_cmds ao_config_cmds[] = { { 'c', ao_config_set, "c Set config variable (? for help, s to show)" }, diff --git a/src/ao_dbg.c b/src/ao_dbg.c index b218897c..d0633f92 100644 --- a/src/ao_dbg.c +++ b/src/ao_dbg.c @@ -16,19 +16,12 @@ */ #include "ao.h" - -#define DBG_CLOCK (1 << 3) -#define DBG_DATA (1 << 4) -#define DBG_RESET_N (1 << 5) - -#define DBG_CLOCK_PIN (P0_3) -#define DBG_DATA_PIN (P0_4) -#define DBG_RESET_N_PIN (P0_5) +#include "ao_pins.h" static void ao_dbg_send_bits(uint8_t msk, uint8_t val) __reentrant { - P0 = (P0 & ~msk) | (val & msk); + DBG_PORT = (DBG_PORT & ~msk) | (val & msk); _asm nop nop @@ -40,8 +33,8 @@ ao_dbg_send_byte(uint8_t byte) { __xdata uint8_t b, d; - P0 |= DBG_DATA; - P0DIR |= DBG_DATA; + DBG_PORT |= DBG_DATA; + DBG_PORT_DIR |= DBG_DATA; for (b = 0; b < 8; b++) { d = 0; if (byte & 0x80) @@ -50,7 +43,7 @@ ao_dbg_send_byte(uint8_t byte) ao_dbg_send_bits(DBG_CLOCK|DBG_DATA, DBG_CLOCK|d); ao_dbg_send_bits(DBG_CLOCK|DBG_DATA, 0 |d); } - P0DIR &= ~DBG_DATA; + DBG_PORT_DIR &= ~DBG_DATA; } uint8_t @@ -171,20 +164,15 @@ ao_dbg_read_byte(void) static void ao_dbg_set_pins(void) { - /* Disable peripheral use of P0 */ - ADCCFG = 0; - P0SEL = 0; - - - /* make P0_4 tri-state */ - P0INP = DBG_DATA; - P2INP &= ~(P2INP_PDUP0_PULL_DOWN); + /* make DBG_DATA tri-state */ + DBG_PORT_INP |= DBG_DATA; /* Raise RESET_N and CLOCK */ - P0 = DBG_RESET_N | DBG_CLOCK; + DBG_PORT |= DBG_RESET_N | DBG_CLOCK; /* RESET_N and CLOCK are outputs now */ - P0DIR = DBG_RESET_N | DBG_CLOCK; + DBG_PORT_DIR |= DBG_RESET_N | DBG_CLOCK; + DBG_PORT_DIR &= ~DBG_DATA; } static void diff --git a/src/ao_host.h b/src/ao_host.h index 6b42f9f9..fa03a910 100644 --- a/src/ao_host.h +++ b/src/ao_host.h @@ -117,30 +117,6 @@ struct ao_cmds { }; -static int16_t altitude_table[2048] = { -#include "altitude.h" -}; - -int16_t -ao_pres_to_altitude(int16_t pres) __reentrant -{ - pres = pres >> 4; - if (pres < 0) pres = 0; - if (pres > 2047) pres = 2047; - return altitude_table[pres]; -} - -int16_t -ao_altitude_to_pres(int16_t alt) __reentrant -{ - int16_t pres; - - for (pres = 0; pres < 2047; pres++) - if (altitude_table[pres] <= alt) - break; - return pres << 4; -} - struct ao_config { uint16_t main_deploy; int16_t accel_zero_g; diff --git a/src/ao_packet.c b/src/ao_packet.c index 98fdcb90..dcd1647c 100644 --- a/src/ao_packet.c +++ b/src/ao_packet.c @@ -113,6 +113,11 @@ ao_packet_recv(void) return dma_done; } +#ifndef PACKET_HAS_MASTER +#define PACKET_HAS_MASTER 1 +#endif + +#if PACKET_HAS_MASTER void ao_packet_flush(void) { @@ -122,12 +127,15 @@ ao_packet_flush(void) if (ao_packet_tx_used && ao_packet_master_sleeping) ao_wake_task(&ao_packet_task); } +#endif /* PACKET_HAS_MASTER */ void ao_packet_putchar(char c) __reentrant { while (ao_packet_tx_used == AO_PACKET_MAX && ao_packet_enable) { +#if PACKET_HAS_MASTER ao_packet_flush(); +#endif ao_sleep(&tx_data); } diff --git a/src/ao_packet_slave.c b/src/ao_packet_slave.c index 122c4da0..4c947fbf 100644 --- a/src/ao_packet_slave.c +++ b/src/ao_packet_slave.c @@ -56,5 +56,5 @@ ao_packet_slave_init(void) { ao_add_stdio(ao_packet_pollchar, ao_packet_putchar, - ao_packet_flush); + NULL); } diff --git a/src/ao_pins.h b/src/ao_pins.h new file mode 100644 index 00000000..84d8a1a1 --- /dev/null +++ b/src/ao_pins.h @@ -0,0 +1,144 @@ +/* + * Copyright © 2010 Keith Packard + * + * 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_PINS_H_ +#define _AO_PINS_H_ + +#if defined(TELEMETRUM_V_0_2) + #define HAS_SERIAL_1 1 + #define HAS_ADC 1 + #define HAS_EEPROM 1 + #define HAS_DBG 1 + #define DBG_ON_P1 1 + #define DBG_ON_P0 0 + #define PACKET_HAS_MASTER 0 + #define PACKET_HAS_SLAVE 1 + + #define LEDS_AVAILABLE (AO_LED_RED) + #define HAS_EXTERNAL_TEMP 0 +#endif + +#if defined(TELEDONGLE_V_0_2) + #define HAS_SERIAL_1 0 + #define HAS_ADC 0 + #define HAS_DBG 1 + #define HAS_EEPROM 0 + #define DBG_ON_P1 1 + #define DBG_ON_P0 0 + #define PACKET_HAS_MASTER 1 + #define PACKET_HAS_SLAVE 0 + #define LEDS_AVAILABLE (AO_LED_RED) +#endif + +#if defined(TELEMETRUM_V_0_1) + #define HAS_SERIAL_1 1 + #define HAS_ADC 1 + #define HAS_DBG 0 + #define HAS_EEPROM 1 + #define DBG_ON_P1 0 + #define DBG_ON_P0 1 + #define PACKET_HAS_MASTER 0 + #define PACKET_HAS_SLAVE 1 + #define LEDS_AVAILABLE (AO_LED_RED|AO_LED_GREEN) + #define HAS_EXTERNAL_TEMP 1 +#endif + +#if defined(TELEDONGLE_V_0_1) + #define HAS_SERIAL_1 0 + #define HAS_ADC 0 + #define HAS_DBG 0 + #define HAS_EEPROM 0 + #define DBG_ON_P1 0 + #define DBG_ON_P0 1 + #define PACKET_HAS_MASTER 1 + #define PACKET_HAS_SLAVE 0 + #define LEDS_AVAILABLE (AO_LED_RED|AO_LED_GREEN) +#endif + +#if defined(TIDONGLE) + #define HAS_SERIAL_1 0 + #define HAS_ADC 0 + #define HAS_DBG 1 + #define HAS_EEPROM 0 + #define DBG_ON_P1 0 + #define DBG_ON_P0 1 + #define PACKET_HAS_MASTER 1 + #define PACKET_HAS_SLAVE 0 + #define LEDS_AVAILABLE (AO_LED_RED) +#endif + +#if DBG_ON_P1 + + #define DBG_CLOCK (1 << 4) /* mi0 */ + #define DBG_DATA (1 << 5) /* mo0 */ + #define DBG_RESET_N (1 << 3) /* c0 */ + + #define DBG_CLOCK_PIN (P1_4) + #define DBG_DATA_PIN (P1_5) + #define DBG_RESET_N_PIN (P1_3) + + #define DBG_PORT_NUM 1 + #define DBG_PORT P1 + #define DBG_PORT_SEL P1SEL + #define DBG_PORT_INP P1INP + #define DBG_PORT_DIR P1DIR + +#endif /* DBG_ON_P1 */ + +#if DBG_ON_P0 + + #define DBG_CLOCK (1 << 3) + #define DBG_DATA (1 << 4) + #define DBG_RESET_N (1 << 5) + + #define DBG_CLOCK_PIN (P0_3) + #define DBG_DATA_PIN (P0_4) + #define DBG_RESET_N_PIN (P0_5) + + #define DBG_PORT_NUM 0 + #define DBG_PORT P0 + #define DBG_PORT_SEL P0SEL + #define DBG_PORT_INP P0INP + #define DBG_PORT_DIR P0DIR + +#endif /* DBG_ON_P0 */ + +#ifndef HAS_SERIAL_1 +#error Please define HAS_SERIAL_1 +#endif + +#ifndef HAS_ADC +#error Please define HAS_ADC +#endif + +#ifndef HAS_EEPROM +#error Please define HAS_EEPROM +#endif + +#ifndef HAS_DBG +#error Please define HAS_DBG +#endif + +#ifndef PACKET_HAS_MASTER +#error Please define PACKET_HAS_MASTER +#endif + +#ifndef PACKET_HAS_SLAVE +#error Please define PACKET_HAS_SLAVE +#endif + +#endif /* _AO_PINS_H_ */ diff --git a/src/ao_reboot.c b/src/ao_reboot.c new file mode 100644 index 00000000..82ea32e0 --- /dev/null +++ b/src/ao_reboot.c @@ -0,0 +1,28 @@ +/* + * Copyright © 2009 Keith Packard + * + * 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" + +/* Use the watchdog timer to force a complete reboot + */ +void +ao_reboot(void) +{ + WDCTL = WDCTL_EN | WDCTL_MODE_WATCHDOG | WDCTL_INT_32768; + ao_sleep(AO_SEC_TO_TICKS(2)); + ao_panic(AO_PANIC_REBOOT); +} diff --git a/src/ao_stdio.c b/src/ao_stdio.c index 7bc416e1..8add30b8 100644 --- a/src/ao_stdio.c +++ b/src/ao_stdio.c @@ -38,7 +38,8 @@ putchar(char c) void flush(void) { - stdios[ao_cur_stdio].flush(); + if (stdios[ao_cur_stdio].flush) + stdios[ao_cur_stdio].flush(); } __xdata uint8_t ao_stdin_ready; diff --git a/src/ao_teledongle.c b/src/ao_teledongle.c index e4828d80..b07b1746 100644 --- a/src/ao_teledongle.c +++ b/src/ao_teledongle.c @@ -15,8 +15,6 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#define AO_NO_SERIAL_ISR 1 -#define AO_NO_ADC_ISR 1 #include "ao.h" void @@ -35,6 +33,9 @@ main(void) ao_radio_init(); ao_packet_slave_init(); ao_packet_master_init(); +#if HAS_DBG + ao_dbg_init(); +#endif ao_config_init(); ao_start_scheduler(); } diff --git a/src/ao_telemetrum.c b/src/ao_telemetrum.c index 89743837..fd0adae8 100644 --- a/src/ao_telemetrum.c +++ b/src/ao_telemetrum.c @@ -16,6 +16,7 @@ */ #include "ao.h" +#include "ao_pins.h" /* stub so as telemetrum doesn't have monitor mode */ void @@ -31,7 +32,7 @@ main(void) /* Turn on the red LED until the system is stable */ - ao_led_init(AO_LED_RED); + ao_led_init(LEDS_AVAILABLE); ao_led_on(AO_LED_RED); /* A hack -- look at the SPI clock pin, if it's sitting at @@ -59,6 +60,9 @@ main(void) ao_radio_init(); ao_packet_slave_init(); ao_igniter_init(); +#if HAS_DBG + ao_dbg_init(); +#endif ao_config_init(); ao_start_scheduler(); } diff --git a/src/ao_timer.c b/src/ao_timer.c index e81f937d..d1731475 100644 --- a/src/ao_timer.c +++ b/src/ao_timer.c @@ -36,24 +36,30 @@ ao_delay(uint16_t ticks) #define T1_CLOCK_DIVISOR 8 /* 24e6/8 = 3e6 */ #define T1_SAMPLE_TIME 30000 /* 3e6/30000 = 100 */ +#if HAS_ADC volatile __data uint8_t ao_adc_interval = 1; volatile __data uint8_t ao_adc_count; +#endif void ao_timer_isr(void) interrupt 9 { ++ao_tick_count; +#if HAS_ADC if (++ao_adc_count == ao_adc_interval) { ao_adc_count = 0; ao_adc_poll(); } +#endif } +#if HAS_ADC void ao_timer_set_adc_interval(uint8_t interval) __critical { ao_adc_interval = interval; ao_adc_count = 0; } +#endif void ao_timer_init(void) diff --git a/src/teledongle-v0.1/Makefile b/src/teledongle-v0.1/Makefile new file mode 100644 index 00000000..d8867b19 --- /dev/null +++ b/src/teledongle-v0.1/Makefile @@ -0,0 +1 @@ +include ../Makefile.proto diff --git a/src/teledongle-v0.1/Makefile.defs b/src/teledongle-v0.1/Makefile.defs new file mode 100644 index 00000000..3526b4c5 --- /dev/null +++ b/src/teledongle-v0.1/Makefile.defs @@ -0,0 +1,9 @@ +PROG = teledongle-v0.1.ihx + +SRC = \ + $(TD_SRC) \ + $(DBG_SRC) + +PRODUCT=TeleDongle-v0.1 + +CFLAGS += -DTELEDONGLE_V_0_1 -I. diff --git a/src/teledongle-v0.2/Makefile b/src/teledongle-v0.2/Makefile new file mode 100644 index 00000000..d8867b19 --- /dev/null +++ b/src/teledongle-v0.2/Makefile @@ -0,0 +1 @@ +include ../Makefile.proto diff --git a/src/teledongle-v0.2/Makefile.defs b/src/teledongle-v0.2/Makefile.defs new file mode 100644 index 00000000..faad4dce --- /dev/null +++ b/src/teledongle-v0.2/Makefile.defs @@ -0,0 +1,9 @@ +PROG = teledongle-v0.2.ihx + +SRC = \ + $(TD_SRC) \ + $(DBG_SRC) + +PRODUCT=TeleDongle-v0.2 + +CFLAGS += -DTELEDONGLE_V_0_2 -I. diff --git a/src/telemetrum-v0.1-sirf/Makefile b/src/telemetrum-v0.1-sirf/Makefile new file mode 100644 index 00000000..d8867b19 --- /dev/null +++ b/src/telemetrum-v0.1-sirf/Makefile @@ -0,0 +1 @@ +include ../Makefile.proto diff --git a/src/telemetrum-v0.1-sirf/Makefile.defs b/src/telemetrum-v0.1-sirf/Makefile.defs new file mode 100644 index 00000000..1157d679 --- /dev/null +++ b/src/telemetrum-v0.1-sirf/Makefile.defs @@ -0,0 +1,11 @@ +PROG = telemetrum-v0.1-sirf.ihx + +SRC = \ + $(TM_BASE_SRC) \ + $(EE_DRIVER_SRC) \ + $(SIRF_DRIVER_SRC) \ + $(DBG_SRC) + +PRODUCT=TeleMetrum-v0.1-SiRF + +CFLAGS += -DTELEMETRUM_V_0_1 -I. diff --git a/src/telemetrum-v0.1-sky/Makefile b/src/telemetrum-v0.1-sky/Makefile new file mode 100644 index 00000000..d8867b19 --- /dev/null +++ b/src/telemetrum-v0.1-sky/Makefile @@ -0,0 +1 @@ +include ../Makefile.proto diff --git a/src/telemetrum-v0.1-sky/Makefile.defs b/src/telemetrum-v0.1-sky/Makefile.defs new file mode 100644 index 00000000..ff7fd1bf --- /dev/null +++ b/src/telemetrum-v0.1-sky/Makefile.defs @@ -0,0 +1,11 @@ +PROG = telemetrum-v0.1-sky.ihx + +SRC = \ + $(TM_BASE_SRC) \ + $(EE_DRIVER_SRC) \ + $(SKY_DRIVER_SRC) \ + $(DBG_SRC) + +PRODUCT=TeleMetrum-v0.1 + +CFLAGS += -DTELEMETRUM_V_0_1 -I. diff --git a/src/telemetrum-v0.2/Makefile b/src/telemetrum-v0.2/Makefile new file mode 100644 index 00000000..d8867b19 --- /dev/null +++ b/src/telemetrum-v0.2/Makefile @@ -0,0 +1 @@ +include ../Makefile.proto diff --git a/src/telemetrum-v0.2/Makefile.defs b/src/telemetrum-v0.2/Makefile.defs new file mode 100644 index 00000000..d5b0a962 --- /dev/null +++ b/src/telemetrum-v0.2/Makefile.defs @@ -0,0 +1,11 @@ +PROG = telemetrum-v0.2.ihx + +SRC = \ + $(TM_BASE_SRC) \ + $(FLASH_DRIVER_SRC) \ + $(SKY_DRIVER_SRC) \ + $(DBG_SRC) + +PRODUCT=TeleMetrum-v0.2 + +CFLAGS += -DTELEMETRUM_V_0_2 -I. diff --git a/src/test/Makefile b/src/test/Makefile new file mode 100644 index 00000000..f6e9b9f5 --- /dev/null +++ b/src/test/Makefile @@ -0,0 +1,24 @@ +vpath % .. + +PROGS=ao_flight_test ao_gps_test ao_gps_test_skytraq ao_convert_test + +CFLAGS=-I.. -I. + +all: $(PROGS) + +clean: + rm -f $(PROGS) + +install: + +ao_flight_test: ao_flight_test.c ao_flight_test.c ao_host.h + cc -g -o $@ $< + +ao_gps_test: ao_gps_test.c ao_gps_sirf.c ao_gps_print.c ao_host.h + cc -g -o $@ $< + +ao_gps_test_skytraq: ao_gps_test_skytraq.c ao_gps_skytraq.c ao_gps_print.c ao_host.h + cc -g -o $@ $< + +ao_convert_test: ao_convert_test.c ao_convert.c altitude.h + cc -g -o $@ $< diff --git a/src/tidongle/Makefile b/src/tidongle/Makefile new file mode 100644 index 00000000..d8867b19 --- /dev/null +++ b/src/tidongle/Makefile @@ -0,0 +1 @@ +include ../Makefile.proto diff --git a/src/tidongle/Makefile.defs b/src/tidongle/Makefile.defs new file mode 100644 index 00000000..16762940 --- /dev/null +++ b/src/tidongle/Makefile.defs @@ -0,0 +1,8 @@ +PROG = tidongle.ihx + +SRC = \ + $(TI_SRC) + +PRODUCT=TIDongle + +CFLAGS += -DTIDONGLE -I. -- 2.30.2