From d4b1dffeef3e9ea96e143f74782e4da7d116c0d4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 6 Oct 2012 18:25:15 -0700 Subject: altos/telefire: Make sure armed alarm goes off on time Instead of turning the alarm off when a packet is received after the deadline, just do it in the thread which is awake all of the time. This prevents the alarm from sticking on when the LCO box is turned off while the arming key is on. Signed-off-by: Keith Packard --- src/drivers/ao_pad.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/ao_pad.c b/src/drivers/ao_pad.c index 55e6289d..120ce539 100644 --- a/src/drivers/ao_pad.c +++ b/src/drivers/ao_pad.c @@ -139,6 +139,9 @@ ao_pad_monitor(void) prev = cur; } + if (ao_pad_armed && (int16_t) (ao_time() - ao_pad_arm_time) > AO_PAD_ARM_TIME) + ao_pad_armed = 0; + if (ao_pad_armed) { if (sample & 2) ao_beep(AO_BEEP_HIGH); @@ -197,9 +200,6 @@ ao_pad(void) PRINTD ("tick %d box %d cmd %d channels %02x\n", command.tick, command.box, command.cmd, command.channels); - if (ao_pad_armed && (int16_t) (ao_time() - ao_pad_arm_time) > AO_PAD_ARM_TIME) - ao_pad_armed = 0; - switch (command.cmd) { case AO_LAUNCH_ARM: if (command.box != ao_pad_box) { -- cgit v1.2.3 From 3f059f8878a79b3154a19b6803fbc367eda80dc9 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 10 Oct 2012 14:28:07 -0700 Subject: altos/telefire: Add siren/strobe support This also involved hacking up the code to allow for non-zero offsets for the pad firing and continuity pins. Signed-off-by: Keith Packard --- src/cc1111/ao_adc.c | 8 ++++-- src/drivers/ao_pad.c | 63 ++++++++++++++++++++++++++++++++++++++------- src/telefire-v0.1/ao_pins.h | 49 +++++++++++++++++++++++------------ 3 files changed, 92 insertions(+), 28 deletions(-) (limited to 'src/drivers') diff --git a/src/cc1111/ao_adc.c b/src/cc1111/ao_adc.c index f7b52281..f8000410 100644 --- a/src/cc1111/ao_adc.c +++ b/src/cc1111/ao_adc.c @@ -20,6 +20,10 @@ volatile __xdata struct ao_data ao_data_ring[AO_DATA_RING]; volatile __data uint8_t ao_data_head; +#ifndef AO_ADC_FIRST_PIN +#define AO_ADC_FIRST_PIN 0 +#endif + void ao_adc_poll(void) { @@ -29,7 +33,7 @@ ao_adc_poll(void) # ifdef TELENANO_V_0_1 ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 1; # else - ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 0; + ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | AO_ADC_FIRST_PIN; # endif #endif } @@ -141,7 +145,7 @@ ao_adc_isr(void) __interrupt 1 #endif /* telemini || telenano */ #ifdef TELEFIRE_V_0_1 - a = (uint8_t __xdata *) (&ao_data_ring[ao_data_head].adc.sense[0] + sequence); + a = (uint8_t __xdata *) (&ao_data_ring[ao_data_head].adc.sense[0] + sequence - AO_ADC_FIRST_PIN); a[0] = ADCL; a[1] = ADCH; if (sequence < 5) diff --git a/src/drivers/ao_pad.c b/src/drivers/ao_pad.c index 120ce539..36905136 100644 --- a/src/drivers/ao_pad.c +++ b/src/drivers/ao_pad.c @@ -39,25 +39,63 @@ static __pdata uint8_t ao_pad_debug; #define FLUSHD() #endif +static void +ao_siren(uint8_t v) +{ +#ifdef AO_SIREN + ao_gpio_set(AO_SIREN_PORT, AO_SIREN_PIN, AO_SIREN, v); +#else + ao_beep(v ? AO_BEEP_MID : 0); +#endif +} + +static void +ao_strobe(uint8_t v) +{ +#ifdef AO_STROBE + ao_gpio_set(AO_STROBE_PORT, AO_STROBE_PIN, AO_STROBE, v); +#endif +} + static void ao_pad_run(void) { + uint8_t pins; + for (;;) { while (!ao_pad_ignite) ao_sleep(&ao_pad_ignite); /* * Actually set the pad bits */ - AO_PAD_PORT = (AO_PAD_PORT & (~AO_PAD_ALL_PINS)) | ao_pad_ignite; + pins = 0; +#if AO_PAD_NUM > 0 + if (ao_pad_ignite & (1 << 0)) + pins |= (1 << AO_PAD_PIN_0); +#endif +#if AO_PAD_NUM > 1 + if (ao_pad_ignite & (1 << 1)) + pins |= (1 << AO_PAD_PIN_1); +#endif +#if AO_PAD_NUM > 2 + if (ao_pad_ignite & (1 << 2)) + pins |= (1 << AO_PAD_PIN_2); +#endif +#if AO_PAD_NUM > 3 + if (ao_pad_ignite & (1 << 3)) + pins |= (1 << AO_PAD_PIN_3); +#endif + AO_PAD_PORT = (AO_PAD_PORT & (~AO_PAD_ALL_PINS)) | pins; while (ao_pad_ignite) { ao_pad_ignite = 0; + ao_delay(AO_PAD_FIRE_TIME); } AO_PAD_PORT &= ~(AO_PAD_ALL_PINS); } } -#define AO_PAD_ARM_BEEP_INTERVAL 200 +#define AO_PAD_ARM_SIREN_INTERVAL 200 static void ao_pad_monitor(void) @@ -143,21 +181,23 @@ ao_pad_monitor(void) ao_pad_armed = 0; if (ao_pad_armed) { + ao_strobe(1); if (sample & 2) - ao_beep(AO_BEEP_HIGH); + ao_siren(1); else - ao_beep(AO_BEEP_LOW); + ao_siren(0); beeping = 1; } else if (query.arm_status == AO_PAD_ARM_STATUS_ARMED && !beeping) { if (arm_beep_time == 0) { - arm_beep_time = AO_PAD_ARM_BEEP_INTERVAL; + arm_beep_time = AO_PAD_ARM_SIREN_INTERVAL; beeping = 1; - ao_beep(AO_BEEP_HIGH); + ao_siren(1); } --arm_beep_time; } else if (beeping) { beeping = 0; - ao_beep(0); + ao_siren(0); + ao_strobe(0); } } } @@ -184,7 +224,6 @@ ao_pad(void) int16_t time_difference; int8_t ret; - ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200)); ao_pad_box = 0; ao_led_set(0); ao_led_on(AO_LED_POWER); @@ -207,7 +246,7 @@ ao_pad(void) break; } - if (command.channels & ~(AO_PAD_ALL_PINS)) + if (command.channels & ~(AO_PAD_ALL_CHANNELS)) break; time_difference = command.tick - ao_time(); @@ -348,6 +387,12 @@ ao_pad_init(void) #endif #if AO_PAD_NUM > 3 ao_enable_output(AO_PAD_PORT, AO_PAD_PIN_3, AO_PAD_3, 0); +#endif +#ifdef AO_STROBE + ao_enable_output(AO_STROBE_PORT, AO_STROBE_PIN, AO_STROBE, 0); +#endif +#ifdef AO_SIREN + ao_enable_output(AO_SIREN_PORT, AO_SIREN_PIN, AO_SIREN, 0); #endif ao_cmd_register(&ao_pad_cmds[0]); ao_add_task(&ao_pad_task, ao_pad, "pad listener"); diff --git a/src/telefire-v0.1/ao_pins.h b/src/telefire-v0.1/ao_pins.h index eecf783e..774d59f4 100644 --- a/src/telefire-v0.1/ao_pins.h +++ b/src/telefire-v0.1/ao_pins.h @@ -38,8 +38,8 @@ #define PACKET_HAS_MASTER 0 #define PACKET_HAS_SLAVE 0 -#define AO_LED_CONTINUITY(c) (1 << (c)) -#define AO_LED_CONTINUITY_MASK (0xf) +#define AO_LED_CONTINUITY(c) (1 << ((c) + 2)) +#define AO_LED_CONTINUITY_MASK (0xc) #define AO_LED_RX 0x10 #define AO_LED_TX 0x20 #define AO_LED_ARMED 0x40 @@ -74,40 +74,55 @@ #define AO_PCA9922_CS_PIN 4 #define AO_PCA9922_CS P1_4 -#define AO_PAD_NUM 4 +#define AO_PAD_NUM 2 #define AO_PAD_PORT P1 #define AO_PAD_DIR P1DIR -#define AO_PAD_PIN_0 0 -#define AO_PAD_0 P1_0 -#define AO_PAD_PIN_1 1 -#define AO_PAD_1 P1_1 -#define AO_PAD_PIN_2 2 -#define AO_PAD_2 P1_2 -#define AO_PAD_PIN_3 3 -#define AO_PAD_3 P1_3 -#define AO_PAD_ALL_PINS ((1 << AO_PAD_PIN_0) | (1 << AO_PAD_PIN_1) | (1 << AO_PAD_PIN_2) | (1 << AO_PAD_PIN_3)) + +#define AO_PAD_PIN_0 2 +#define AO_PAD_0 P1_2 +#define AO_PAD_ADC_0 2 + +#define AO_PAD_PIN_1 3 +#define AO_PAD_1 P1_3 +#define AO_PAD_ADC_1 3 + +#define AO_PAD_ALL_PINS ((1 << AO_PAD_PIN_0) | (1 << AO_PAD_PIN_1)) +#define AO_PAD_ALL_CHANNELS ((1 << 0) | (1 << 1)) + +#define AO_SIREN_PORT P1 +#define AO_SIREN_DIR P1DIR +#define AO_SIREN_PIN 0 +#define AO_SIREN P1_0 + +#define AO_STROBE_PORT P1 +#define AO_STROBE_DIR P1DIR +#define AO_STROBE_PIN 1 +#define AO_STROBE P1_1 /* test these values with real igniters */ #define AO_PAD_RELAY_CLOSED 3524 #define AO_PAD_NO_IGNITER 16904 #define AO_PAD_GOOD_IGNITER 22514 +#define AO_PAD_ADC_PYRO 4 +#define AO_PAD_ADC_BATT 5 + +#define AO_ADC_FIRST_PIN 2 + struct ao_adc { - int16_t sense[4]; + int16_t sense[AO_PAD_NUM]; int16_t pyro; int16_t batt; }; #define AO_ADC_DUMP(p) \ - printf ("tick: %5u 0: %5d 1: %5d 2: %5d 3: %5d pyro: %5d batt %5d\n", \ + printf ("tick: %5u 0: %5d 1: %5d pyro: %5d batt %5d\n", \ (p)->tick, \ (p)->adc.sense[0], \ (p)->adc.sense[1], \ - (p)->adc.sense[2], \ - (p)->adc.sense[3], \ (p)->adc.pyro, \ (p)->adc.batt) -#define AO_ADC_PINS ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5)) +#define AO_ADC_PINS ((1 << AO_PAD_ADC_0) | (1 << AO_PAD_ADC_1) | (1 << AO_PAD_ADC_PYRO) | (1 << AO_PAD_ADC_BATT)) #endif /* _AO_PINS_H_ */ -- cgit v1.2.3 From 7795d8309b3e1147bc37d31a0adde42d7dee6cd1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 12 Oct 2012 13:37:07 -0700 Subject: altos: Prepare ms5607 driver for use in non-tasking products Micropeak doesn't have tasking, prepare the ms5607 driver for that Signed-off-by: Keith Packard --- src/drivers/ao_ms5607.c | 30 ++++++++++++++++++------------ src/drivers/ao_ms5607.h | 3 +++ 2 files changed, 21 insertions(+), 12 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/ao_ms5607.c b/src/drivers/ao_ms5607.c index 76931b4b..1e69cccb 100644 --- a/src/drivers/ao_ms5607.c +++ b/src/drivers/ao_ms5607.c @@ -17,7 +17,7 @@ #include #include -#include "ao_ms5607.h" +#include #if HAS_MS5607 || HAS_MS5611 @@ -27,12 +27,12 @@ static uint8_t ms5607_configured; static void ao_ms5607_start(void) { ao_spi_get(AO_MS5607_SPI_INDEX,AO_SPI_SPEED_FAST); - stm_gpio_set(AO_MS5607_CS_PORT, AO_MS5607_CS_PIN, 0); + ao_gpio_set(AO_MS5607_CS_PORT, AO_MS5607_CS_PIN, AO_MS5607_CS, 0); } static void ao_ms5607_stop(void) { - stm_gpio_set(AO_MS5607_CS_PORT, AO_MS5607_CS_PIN, 1); + ao_gpio_set(AO_MS5607_CS_PORT, AO_MS5607_CS_PIN, AO_MS5607_CS, 1); ao_spi_put(AO_MS5607_SPI_INDEX); } @@ -53,7 +53,6 @@ ao_ms5607_crc(uint8_t *prom) uint8_t crc_byte = prom[15]; uint8_t cnt; uint16_t n_rem = 0; - uint16_t crc_read; uint8_t n_bit; prom[15] = 0; @@ -89,9 +88,11 @@ ao_ms5607_prom_read(struct ao_ms5607_prom *prom) } crc = ao_ms5607_crc((uint8_t *) prom); if (crc != (((uint8_t *) prom)[15] & 0xf)) { +#if HAS_TASK printf ("MS5607 PROM CRC error (computed %x actual %x)\n", crc, (((uint8_t *) prom)[15] & 0xf)); flush(); +#endif ao_panic(AO_PANIC_SELF_TEST_MS5607); } @@ -105,7 +106,7 @@ ao_ms5607_prom_read(struct ao_ms5607_prom *prom) #endif } -static void +void ao_ms5607_setup(void) { if (ms5607_configured) @@ -115,33 +116,34 @@ ao_ms5607_setup(void) ao_ms5607_prom_read(&ms5607_prom); } -static uint8_t ao_ms5607_done; +static volatile uint8_t ao_ms5607_done; static void ao_ms5607_isr(void) { ao_exti_disable(AO_MS5607_MISO_PORT, AO_MS5607_MISO_PIN); ao_ms5607_done = 1; - ao_wakeup(&ao_ms5607_done); + ao_wakeup((void *) &ao_ms5607_done); } static uint32_t ao_ms5607_get_sample(uint8_t cmd) { uint8_t reply[3]; uint8_t read; - uint16_t now; ao_ms5607_done = 0; ao_ms5607_start(); ao_spi_send(&cmd, 1, AO_MS5607_SPI_INDEX); + ao_exti_enable(AO_MS5607_MISO_PORT, AO_MS5607_MISO_PIN); + #if AO_MS5607_PRIVATE_PINS ao_spi_put(AO_MS5607_SPI_INDEX); #endif cli(); while (!ao_ms5607_done) - ao_sleep(&ao_ms5607_done); + ao_sleep((void *) &ao_ms5607_done); sei(); #if AO_MS5607_PRIVATE_PINS stm_gpio_set(AO_MS5607_CS_PORT, AO_MS5607_CS_PIN, 1); @@ -168,12 +170,10 @@ ao_ms5607_sample(struct ao_ms5607_sample *sample) void ao_ms5607_convert(struct ao_ms5607_sample *sample, struct ao_ms5607_value *value) { - uint8_t addr; int32_t dT; int32_t TEMP; int64_t OFF; int64_t SENS; - int32_t P; dT = sample->temp - ((int32_t) ms5607_prom.tref << 8); @@ -207,6 +207,7 @@ ao_ms5607_convert(struct ao_ms5607_sample *sample, struct ao_ms5607_value *value value->temp = TEMP; } +#if HAS_TASK static void ao_ms5607(void) { @@ -254,15 +255,18 @@ __code struct ao_cmds ao_ms5607_cmds[] = { { ao_ms5607_dump, "B\0Display MS5607 data" }, { 0, NULL }, }; +#endif /* HAS_TASK */ void ao_ms5607_init(void) { ms5607_configured = 0; - ao_cmd_register(&ao_ms5607_cmds[0]); ao_spi_init_cs(AO_MS5607_CS_PORT, (1 << AO_MS5607_CS_PIN)); +#if HAS_TASK + ao_cmd_register(&ao_ms5607_cmds[0]); ao_add_task(&ao_ms5607_task, ao_ms5607, "ms5607"); +#endif /* Configure the MISO pin as an interrupt; when the * conversion is complete, the MS5607 will raise this @@ -273,12 +277,14 @@ ao_ms5607_init(void) AO_EXTI_MODE_RISING, ao_ms5607_isr); +#ifdef STM_MODER_ALTERNATE /* Reset the pin from INPUT to ALTERNATE so that SPI works * This needs an abstraction at some point... */ stm_moder_set(AO_MS5607_MISO_PORT, AO_MS5607_MISO_PIN, STM_MODER_ALTERNATE); +#endif } #endif diff --git a/src/drivers/ao_ms5607.h b/src/drivers/ao_ms5607.h index e9c364d9..5c31fd8b 100644 --- a/src/drivers/ao_ms5607.h +++ b/src/drivers/ao_ms5607.h @@ -56,6 +56,9 @@ struct ao_ms5607_value { int32_t temp; /* in °C * 100 */ }; +void +ao_ms5607_setup(void); + void ao_ms5607_init(void); -- cgit v1.2.3 From 6cfb2d3b1c75916ee69d069519edc675e37e1aa1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 12 Oct 2012 14:26:08 -0700 Subject: altos: Add (untested) driver for AT24C i2c flash parts Signed-off-by: Keith Packard --- src/drivers/ao_at24c.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/drivers/ao_at24c.c (limited to 'src/drivers') diff --git a/src/drivers/ao_at24c.c b/src/drivers/ao_at24c.c new file mode 100644 index 00000000..2a23be3a --- /dev/null +++ b/src/drivers/ao_at24c.c @@ -0,0 +1,104 @@ +/* + * Copyright © 2012 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 + +#if HAS_EEPROM +#define AO_AT24C_ADDR 0xa0 +#define AO_AT24C_ADDR_WRITE (AO_AT24C_ADDR|0) +#define AO_AT24C_ADDR_READ (AO_AT24C_ADDR|1) +#define AO_AT24C_PAGE_LEN 128 + +/* Total bytes of available storage */ +__pdata ao_pos_t ao_storage_total = 64l * 1024l; + +/* Storage unit size - device reads and writes must be within blocks of this size. */ +__pdata uint16_t ao_storage_unit = 128; + +static void +ao_at24c_set_address(uint8_t addr, ao_pos_t pos) +{ + uint8_t a[2]; + + a[0] = pos >> 8; + a[1] = pos; + ao_i2c_start_bus(addr); + ao_i2c_send_bus(a, 2, 0); +} + +/* + * Erase the specified sector + */ +uint8_t +ao_storage_erase(ao_pos_t pos) __reentrant +{ + if (pos >= ao_storage_total || pos + AO_AT24C_PAGE_LEN > ao_storage_total) + return 0; + + ao_mutex_get(&ao_at24c_mutex); + ao_at24c_set_address(AO_AT24C_ADDR_WRITE, pos); + ao_i2c_send_fixed_bus(0xff, AO_AT24C_PAGE_LEN, 1); + ao_mutex_put(&ao_at24c_mutex); + return 1; +} + +/* + * Write to flash + */ +uint8_t +ao_storage_device_write(ao_pos_t pos, __xdata void *d, uint16_t len) __reentrant +{ + if (pos >= ao_storage_total || pos + len > ao_storage_total) + return 0; + + ao_mutex_get(&ao_m25_mutex); + ao_at24c_set_address(AO_AT24C_ADDR_WRITE, pos); + ao_i2c_send_bus(d, len, 1); + ao_mutex_put(&ao_m25_mutex); + return 1; +} + +/* + * Read from flash + */ +uint8_t +ao_storage_device_read(ao_pos_t pos, __xdata void *d, uint16_t len) __reentrant +{ + if (pos >= ao_storage_total || pos + len > ao_storage_total) + return 0; + ao_mutex_get(&ao_m25_mutex); + ao_at24c_set_address(AO_AT24C_ADDR_READ, pos); + ao_i2c_recv_bus(d, len, 1); + ao_mutex_put(&ao_m25_mutex); + return 1; +} + +void +ao_storage_flush(void) __reentrant +{ +} + +void +ao_storage_setup(void) +{ +} + +void +ao_storage_device_init(void) +{ +} +#endif -- cgit v1.2.3 From 2733d1b71bbac2c5ef4a2c3a1992ba448e981267 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 13 Oct 2012 13:35:42 -0700 Subject: altos: Split out ms5607 conversion code for use in ao_flight_test Makes the conversion code available even where the driver isn't needed Signed-off-by: Keith Packard --- src/drivers/ao_ms5607.c | 40 +--------------------------- src/drivers/ao_ms5607_convert.c | 58 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 39 deletions(-) create mode 100644 src/drivers/ao_ms5607_convert.c (limited to 'src/drivers') diff --git a/src/drivers/ao_ms5607.c b/src/drivers/ao_ms5607.c index 1e69cccb..fdd2c31e 100644 --- a/src/drivers/ao_ms5607.c +++ b/src/drivers/ao_ms5607.c @@ -167,45 +167,7 @@ ao_ms5607_sample(struct ao_ms5607_sample *sample) sample->temp = ao_ms5607_get_sample(AO_MS5607_CONVERT_D2_2048); } -void -ao_ms5607_convert(struct ao_ms5607_sample *sample, struct ao_ms5607_value *value) -{ - int32_t dT; - int32_t TEMP; - int64_t OFF; - int64_t SENS; - - dT = sample->temp - ((int32_t) ms5607_prom.tref << 8); - - TEMP = 2000 + (((int64_t) dT * ms5607_prom.tempsens) >> 23); - -#if HAS_MS5611 - OFF = ((int64_t) ms5607_prom.off << 16) + (((int64_t) ms5607_prom.tco * dT) >> 7); - SENS = ((int64_t) ms5607_prom.sens << 15) + (((int64_t) ms5607_prom.tcs * dT) >> 8); -#else - OFF = ((int64_t) ms5607_prom.off << 17) + (((int64_t) ms5607_prom.tco * dT) >> 6); - SENS = ((int64_t) ms5607_prom.sens << 16) + (((int64_t) ms5607_prom.tcs * dT) >> 7); -#endif - - if (TEMP < 2000) { - int32_t T2 = ((int64_t) dT * (int64_t) dT) >> 31; - int32_t TEMPM = TEMP - 2000; - int64_t OFF2 = (61 * (int64_t) TEMPM * (int64_t) TEMPM) >> 4; - int64_t SENS2 = 2 * (int64_t) TEMPM * (int64_t) TEMPM; - if (TEMP < 1500) { - int32_t TEMPP = TEMP + 1500; - int64_t TEMPP2 = TEMPP * TEMPP; - OFF2 = OFF2 + 15 * TEMPP2; - SENS2 = SENS2 + 8 * TEMPP2; - } - TEMP -= T2; - OFF -= OFF2; - SENS -= SENS2; - } - - value->pres = ((((int64_t) sample->pres * SENS) >> 21) - OFF) >> 15; - value->temp = TEMP; -} +#include "ao_ms5607_convert.c" #if HAS_TASK static void diff --git a/src/drivers/ao_ms5607_convert.c b/src/drivers/ao_ms5607_convert.c new file mode 100644 index 00000000..e61d19ed --- /dev/null +++ b/src/drivers/ao_ms5607_convert.c @@ -0,0 +1,58 @@ +/* + * Copyright © 2012 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 + +void +ao_ms5607_convert(struct ao_ms5607_sample *sample, struct ao_ms5607_value *value) +{ + int32_t dT; + int32_t TEMP; + int64_t OFF; + int64_t SENS; + + dT = sample->temp - ((int32_t) ms5607_prom.tref << 8); + + TEMP = 2000 + (((int64_t) dT * ms5607_prom.tempsens) >> 23); + +#if HAS_MS5611 + OFF = ((int64_t) ms5607_prom.off << 16) + (((int64_t) ms5607_prom.tco * dT) >> 7); + SENS = ((int64_t) ms5607_prom.sens << 15) + (((int64_t) ms5607_prom.tcs * dT) >> 8); +#else + OFF = ((int64_t) ms5607_prom.off << 17) + (((int64_t) ms5607_prom.tco * dT) >> 6); + SENS = ((int64_t) ms5607_prom.sens << 16) + (((int64_t) ms5607_prom.tcs * dT) >> 7); +#endif + + if (TEMP < 2000) { + int32_t T2 = ((int64_t) dT * (int64_t) dT) >> 31; + int32_t TEMPM = TEMP - 2000; + int64_t OFF2 = (61 * (int64_t) TEMPM * (int64_t) TEMPM) >> 4; + int64_t SENS2 = 2 * (int64_t) TEMPM * (int64_t) TEMPM; + if (TEMP < 1500) { + int32_t TEMPP = TEMP + 1500; + int64_t TEMPP2 = TEMPP * TEMPP; + OFF2 = OFF2 + 15 * TEMPP2; + SENS2 = SENS2 + 8 * TEMPP2; + } + TEMP -= T2; + OFF -= OFF2; + SENS -= SENS2; + } + + value->pres = ((((int64_t) sample->pres * SENS) >> 21) - OFF) >> 15; + value->temp = TEMP; +} -- cgit v1.2.3 From c6eec0bec06d2e246ea3c9552818ad3180c1e318 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 13 Oct 2012 15:04:00 -0700 Subject: altos: Define full-scale gyro and accel values for MPU6000 This lets other code convert MPU6000 readings into canonical units Signed-off-by: Keith Packard --- src/drivers/ao_mpu6000.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/drivers') diff --git a/src/drivers/ao_mpu6000.h b/src/drivers/ao_mpu6000.h index ca76b081..5c0cee1b 100644 --- a/src/drivers/ao_mpu6000.h +++ b/src/drivers/ao_mpu6000.h @@ -145,6 +145,9 @@ /* Self test gyro is approximately 50°/s */ #define MPU6000_ST_GYRO(full_scale) ((int16_t) (((int32_t) 32767 * (int32_t) 50) / (full_scale))) +#define MPU6000_GYRO_FULLSCALE 2000 +#define MPU6000_ACCEL_FULLSCALE 16 + struct ao_mpu6000_sample { int16_t accel_x; int16_t accel_y; -- cgit v1.2.3 From 84c56b1e92fca181207c468ea6351db3c2f196fb Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 14 Oct 2012 23:04:44 -0700 Subject: altos/telefire: Report valid channels instead of valid pins Now that pins don't match channels 1:1, make sure that the report back to the LCO names the channels instead of the pin numbers. Signed-off-by: Keith Packard --- src/drivers/ao_pad.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/drivers') diff --git a/src/drivers/ao_pad.c b/src/drivers/ao_pad.c index 36905136..6cec98ab 100644 --- a/src/drivers/ao_pad.c +++ b/src/drivers/ao_pad.c @@ -271,7 +271,7 @@ ao_pad(void) query.tick = ao_time(); query.box = ao_pad_box; - query.channels = AO_PAD_ALL_PINS; + query.channels = AO_PAD_ALL_CHANNELS; query.armed = ao_pad_armed; PRINTD ("query tick %d box %d channels %02x arm %d arm_status %d igniter %d,%d,%d,%d\n", query.tick, query.box, query.channels, query.armed, -- cgit v1.2.3 From c6069e38d6d2f9b37aa8671c41b4a470d92996a4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 15 Oct 2012 00:06:57 -0700 Subject: altos/telelco: Crank up SPI speed to cc1111 The cc1111 can handle up to 3MHz, so use 2MHz. Also, crank down the packet wait time to 10ms, which should be plenty long for the remote box to receive and return a packet. Signed-off-by: Keith Packard --- src/drivers/ao_lco_func.c | 2 +- src/drivers/ao_radio_master.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/ao_lco_func.c b/src/drivers/ao_lco_func.c index 99e58b76..4af17fd6 100644 --- a/src/drivers/ao_lco_func.c +++ b/src/drivers/ao_lco_func.c @@ -37,7 +37,7 @@ ao_lco_query(uint16_t box, struct ao_pad_query *query, uint16_t *tick_offset) command.channels = 0; ao_radio_cmac_send(&command, sizeof (command)); sent_time = ao_time(); - r = ao_radio_cmac_recv(query, sizeof (*query), AO_MS_TO_TICKS(20)); + r = ao_radio_cmac_recv(query, sizeof (*query), AO_MS_TO_TICKS(10)); if (r == AO_RADIO_CMAC_OK) *tick_offset = sent_time - query->tick; ao_mutex_put(&ao_lco_mutex); diff --git a/src/drivers/ao_radio_master.c b/src/drivers/ao_radio_master.c index 73ac3c03..4a37ace0 100644 --- a/src/drivers/ao_radio_master.c +++ b/src/drivers/ao_radio_master.c @@ -53,7 +53,7 @@ ao_radio_master_start(void) { ao_spi_get_bit(AO_RADIO_CS_PORT, AO_RADIO_CS_PIN, AO_RADIO_CS, AO_RADIO_SPI_BUS, - AO_SPI_SPEED_200kHz); + AO_SPI_SPEED_2MHz); } static void -- cgit v1.2.3 From 5f31f6652f4b0898214d06d009af823a1ed3b96a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 15 Oct 2012 00:24:28 -0700 Subject: altos/telelco: 10ms is not enough time to get a packet back Not reliable, so bump to 20ms Signed-off-by: Keith Packard --- src/drivers/ao_lco_func.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/drivers') diff --git a/src/drivers/ao_lco_func.c b/src/drivers/ao_lco_func.c index 4af17fd6..99e58b76 100644 --- a/src/drivers/ao_lco_func.c +++ b/src/drivers/ao_lco_func.c @@ -37,7 +37,7 @@ ao_lco_query(uint16_t box, struct ao_pad_query *query, uint16_t *tick_offset) command.channels = 0; ao_radio_cmac_send(&command, sizeof (command)); sent_time = ao_time(); - r = ao_radio_cmac_recv(query, sizeof (*query), AO_MS_TO_TICKS(10)); + r = ao_radio_cmac_recv(query, sizeof (*query), AO_MS_TO_TICKS(20)); if (r == AO_RADIO_CMAC_OK) *tick_offset = sent_time - query->tick; ao_mutex_put(&ao_lco_mutex); -- cgit v1.2.3