diff --git a/conf/autopilot/rotorcraft.makefile b/conf/autopilot/rotorcraft.makefile index 8966f4bed8..69a38e4fa8 100644 --- a/conf/autopilot/rotorcraft.makefile +++ b/conf/autopilot/rotorcraft.makefile @@ -134,7 +134,7 @@ ap.srcs += $(SRC_BOOZ)/booz2_commands.c # ap.srcs += $(SRC_BOARD)/baro_board.c ifeq ($(BOARD), booz) -ap.CFLAGS += -DROTORCRAFT_BARO_LED=$(BARO_LED) -DBOOZ2_ANALOG_BARO_PERIOD='SYS_TICS_OF_SEC((1./100.))' +ap.CFLAGS += -DROTORCRAFT_BARO_LED=$(BARO_LED) else ifeq ($(BOARD), lisa_l) ap.CFLAGS += -DUSE_I2C2 endif @@ -142,18 +142,27 @@ endif # # Analog Backend # + ifeq ($(ARCH), lpc21) -ap.CFLAGS += -DBOOZ2_ANALOG_BATTERY_PERIOD='SYS_TICS_OF_SEC((1./10.))' -ap.srcs += $(SRC_FIRMWARE)/battery.c ap.CFLAGS += -DADC0_VIC_SLOT=2 ap.CFLAGS += -DADC1_VIC_SLOT=3 -ap.srcs += $(SRC_BOOZ)/booz2_analog.c \ - $(SRC_BOOZ_ARCH)/booz2_analog_hw.c +ap.CFLAGS += -DUSE_ADC +ap.srcs += $(SRC_ARCH)/mcu_periph/adc_arch.c +ap.srcs += subsystems/electrical.c +# baro has variable offset amplifier on booz board +ap.CFLAGS += -DUSE_DAC +ap.srcs += $(SRC_ARCH)/mcu_periph/dac_arch.c else ifeq ($(ARCH), stm32) -ap.srcs += lisa/lisa_analog_plug.c +#ap.srcs += lisa/lisa_analog_plug.c +ap.CFLAGS += -DUSE_ADC +ap.CFLAGS += -DUSE_AD1 -DUSE_AD1_1 -DUSE_AD1_2 -DUSE_AD1_3 -DUSE_AD1_4 +ap.CFLAGS += -DUSE_ADC1_2_IRQ_HANDLER +ap.srcs += $(SRC_ARCH)/mcu_periph/adc_arch.c +ap.srcs += subsystems/electrical.c endif + # # GPS choice # diff --git a/sw/airborne/arch/lpc21/mcu_periph/dac_arch.c b/sw/airborne/arch/lpc21/mcu_periph/dac_arch.c new file mode 100644 index 0000000000..adda46e12b --- /dev/null +++ b/sw/airborne/arch/lpc21/mcu_periph/dac_arch.c @@ -0,0 +1,6 @@ +#include "mcu_periph/dac.h" + +/* turn on DAC pins */ +void dac_init(void) { + PINSEL1 |= 2 << 18; +} diff --git a/sw/airborne/arch/lpc21/mcu_periph/dac_arch.h b/sw/airborne/arch/lpc21/mcu_periph/dac_arch.h new file mode 100644 index 0000000000..e27b929e34 --- /dev/null +++ b/sw/airborne/arch/lpc21/mcu_periph/dac_arch.h @@ -0,0 +1,12 @@ +#ifndef LPC21_MCU_PERIPH_DAC_ARCH_H +#define LPC21_MCU_PERIPH_DAC_ARCH_H + +#include "std.h" +#include "LPC21xx.h" + +static inline void DACSet(uint16_t x) { + DACR = x << 6; +} + + +#endif /* LPC21_MCU_PERIPH_DAC_ARCH_H */ diff --git a/sw/airborne/boards/booz/baro_board.c b/sw/airborne/boards/booz/baro_board.c index aa43c684a5..4277379a87 100644 --- a/sw/airborne/boards/booz/baro_board.c +++ b/sw/airborne/boards/booz/baro_board.c @@ -37,7 +37,10 @@ struct Baro baro; struct BaroBoard baro_board; + void baro_init( void ) { + + adc_buf_channel(ADC_CHANNEL_BARO, &baro_board.buf, DEFAULT_AV_NB_SAMPLE); baro.status = BS_UNINITIALIZED; baro.absolute = 0; @@ -53,7 +56,16 @@ void baro_init( void ) { #endif } -void baro_periodic(void) {} +void baro_periodic(void) { + + baro.absolute = baro_board.buf.sum/baro_board.buf.av_nb_sample; + baro_board.value_filtered = (3*baro_board.value_filtered + baro.absolute)/4; + if (baro.status == BS_UNINITIALIZED) { + RunOnceEvery(10, { baro_board_calibrate();}); + } + /* else */ + baro_board.data_available = TRUE; +} /* decrement offset until adc reading is over a threshold */ void baro_board_calibrate(void) { diff --git a/sw/airborne/boards/booz/baro_board.h b/sw/airborne/boards/booz/baro_board.h index f1fae16a48..f24568adae 100644 --- a/sw/airborne/boards/booz/baro_board.h +++ b/sw/airborne/boards/booz/baro_board.h @@ -4,14 +4,15 @@ #include "std.h" #include "subsystems/sensors/baro.h" -#include "booz/booz2_analog.h" +#include "mcu_periph/adc.h" +#include "booz/booz2_analog.h" // le DAC -/* we don't need that on this board */ struct BaroBoard { uint16_t offset; uint16_t value_filtered; bool_t data_available; + struct adc_buf buf; }; extern struct BaroBoard baro_board; @@ -30,17 +31,5 @@ static inline void baro_board_SetOffset(uint16_t _o) { Booz2AnalogSetDAC(_o); } -static inline void BoozBaroISRHandler(uint16_t _val) { - baro.absolute = _val; - baro_board.value_filtered = (3*baro_board.value_filtered + baro.absolute)/4; - if (baro.status == BS_UNINITIALIZED) { - RunOnceEvery(10, { baro_board_calibrate();}); - } - /* else */ - baro_board.data_available = TRUE; -} - - - #endif /* BOARDS_BOOZ_BARO_H */ diff --git a/sw/airborne/boards/booz_1.0.h b/sw/airborne/boards/booz_1.0.h index 9f44e89514..4d9dda8dc6 100644 --- a/sw/airborne/boards/booz_1.0.h +++ b/sw/airborne/boards/booz_1.0.h @@ -61,6 +61,24 @@ #define ANALOG_BARO_ADC 1 +/* battery */ +#define ADC_CHANNEL_VSUPPLY AdcBank0(2) +#ifndef USE_AD0 +#define USE_AD0 +#endif +#define USE_AD0_2 + +#define DefaultVoltageOfAdc(adc) (0.0183*adc) + + +/* baro */ +#define ADC_CHANNEL_BARO AdcBank1(2) +#ifndef USE_AD1 +#define USE_AD1 +#endif +#define USE_AD1_2 + + /* MS2100 on SSP, IMU connector */ #define MS2100_SS_PIN 28 diff --git a/sw/airborne/booz/arch/lpc21/booz2_analog_hw.c b/sw/airborne/booz/arch/lpc21/booz2_analog_hw.c deleted file mode 100644 index a991d3e3ed..0000000000 --- a/sw/airborne/booz/arch/lpc21/booz2_analog_hw.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2008-2009 Antoine Drouin - * - * This file is part of paparazzi. - * - * paparazzi 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, or (at your option) - * any later version. - * - * paparazzi 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 paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "booz2_analog.h" - -/* analog_arch includes baro ??? naaaa we don't want double references */ -#include "subsystems/sensors/baro.h" -#include "firmwares/rotorcraft/battery.h" - -#ifndef USE_EXTRA_ADC -/* Default mode - * Bust OFF - * Only one ADC can be read on each bank - * Baro and Bat are read on interrupt - */ - -#include "armVIC.h" -#include "sys_time.h" - -void ADC0_ISR ( void ) __attribute__((naked)); -void ADC1_ISR ( void ) __attribute__((naked)); - -void booz2_analog_init_hw( void ) { - - /* start ADC0 */ - /* select P0.29 as AD0.2 for bat meas*/ - PINSEL1 |= 0x01 << 26; - /* sample AD0.2 - PCLK/4 ( 3.75MHz) - ON */ - AD0CR = 1 << 2 | 0x03 << 8 | 1 << 21; - /* AD0 selected as IRQ */ - VICIntSelect &= ~VIC_BIT(VIC_AD0); - /* AD0 interrupt enabled */ - VICIntEnable = VIC_BIT(VIC_AD0); - /* AD0 interrupt as VIC2 */ - _VIC_CNTL(ADC0_VIC_SLOT) = VIC_ENABLE | VIC_AD0; - _VIC_ADDR(ADC0_VIC_SLOT) = (uint32_t)ADC0_ISR; - /* start convertion on T0M1 match */ - AD0CR |= 4 << 24; - - - /* clear match 1 */ - T0EMR &= ~TEMR_EM1; - /* set high on match 1 */ - T0EMR |= TEMR_EMC1_2; - /* first match in a while */ - T0MR1 = 1024; - - - /* start ADC1 */ - /* select P0.10 as AD1.2 for baro*/ - ANALOG_BARO_PINSEL |= ANALOG_BARO_PINSEL_VAL << ANALOG_BARO_PINSEL_BIT; - /* sample AD1.2 - PCLK/4 ( 3.75MHz) - ON */ - AD1CR = 1 << 2 | 0x03 << 8 | 1 << 21; - /* AD0 selected as IRQ */ - VICIntSelect &= ~VIC_BIT(VIC_AD1); - /* AD0 interrupt enabled */ - VICIntEnable = VIC_BIT(VIC_AD1); - /* AD0 interrupt as VIC2 */ - _VIC_CNTL(ADC1_VIC_SLOT) = VIC_ENABLE | VIC_AD1; - _VIC_ADDR(ADC1_VIC_SLOT) = (uint32_t)ADC1_ISR; - /* start convertion on T0M3 match */ - AD1CR |= 5 << 24; - - - /* clear match 2 */ - T0EMR &= ~TEMR_EM3; - /* set high on match 2 */ - T0EMR |= TEMR_EMC3_2; - /* first match in a while */ - T0MR3 = 512; - - /* turn on DAC pins */ - PINSEL1 |= 2 << 18; -} - - -void ADC0_ISR ( void ) { - ISR_ENTRY(); - uint32_t tmp = AD0GDR; - uint16_t tmp2 = (uint16_t)(tmp >> 6) & 0x03FF; - BatteryISRHandler(tmp2); - /* trigger next convertion */ - T0MR1 += BOOZ2_ANALOG_BATTERY_PERIOD; - /* lower clock */ - T0EMR &= ~TEMR_EM1; - VICVectAddr = 0x00000000; // clear this interrupt from the VIC - ISR_EXIT(); // recover registers and return -} - -void ADC1_ISR ( void ) { - ISR_ENTRY(); - uint32_t tmp = AD1GDR; - uint16_t tmp2 = (uint16_t)(tmp >> 6) & 0x03FF; - BoozBaroISRHandler(tmp2); - /* trigger next convertion */ - T0MR3 += BOOZ2_ANALOG_BARO_PERIOD; - /* lower clock */ - T0EMR &= ~TEMR_EM3; - VICVectAddr = 0x00000000; // clear this interrupt from the VIC - ISR_EXIT(); // recover registers and return -} - -#else // USE_EXTRA_ADC -/* Extra ADCs are read - * Bust ON - * Baro and Bat values are updated by hand - * Four ADCs can be configured - * ADC_1 is available on the cam connector - */ - -#include "LPC21xx.h" -#include "sys_time.h" - -uint16_t booz2_adc_1; -uint16_t booz2_adc_2; -uint16_t booz2_adc_3; -uint16_t booz2_adc_4; - -void booz2_analog_init_hw( void ) { - - /* AD0 */ - /* PCLK/4 ( 3.75MHz) - BURST - ON */ - AD0CR = 0x03 << 8 | 1 << 16 | 1 << 21; - /* disable global interrupt */ - ClearBit(AD0INTEN,8); - - /* AD1 */ - /* PCLK/4 ( 3.75MHz) - BURST - ON */ - AD1CR = 0x03 << 8 | 1 << 16 | 1 << 21; - /* disable global interrupt */ - ClearBit(AD1INTEN,8); - - /* select P0.29 as AD0.2 for bat meas*/ - PINSEL1 |= 0x01 << 26; - /* sample AD0.2 */ - AD0CR |= 1 << 2; - - - /* select P0.10 as AD1.2 for baro*/ - ANALOG_BARO_PINSEL |= ANALOG_BARO_PINSEL_VAL << ANALOG_BARO_PINSEL_BIT; - /* sample AD1.2 */ - AD1CR |= 1 << 2; - /* turn on DAC pins */ - PINSEL1 |= 2 << 18; - -#ifdef USE_ADC_1 - /* select P0.13 (ADC_SPARE) as AD1.4 adc 1 */ - PINSEL0 |= 0x03 << 26; - AD1CR |= 1 << 4; -#endif -#ifdef USE_ADC_2 - /* select P0.4 (SCK_0) as AD0.6 adc 2 */ - PINSEL0 |= 0x03 << 8; - AD0CR |= 1 << 6; -#endif -#ifdef USE_ADC_3 - /* select P0.5 (MISO_0) as AD0.7 adc 3 */ - PINSEL0 |= 0x03 << 10; - AD0CR |= 1 << 7; -#endif -#ifdef USE_ADC_4 - /* select P0.6 (MOSI_0) as AD1.0 adc 4 */ - PINSEL0 |= 0x03 << 12; - AD1CR |= 1 << 0; -#endif - - booz2_adc_1 = 0; - booz2_adc_2 = 0; - booz2_adc_3 = 0; - booz2_adc_4 = 0; -} - -void booz2_analog_baro_read(void) { - uint32_t tmp = AD1DR2; - uint16_t tmp2 = (uint16_t)(tmp >> 6) & 0x03FF; - BoozBaroISRHandler(tmp2); -} - -void booz2_analog_bat_read(void) { - uint32_t tmp = AD0DR2; - uint16_t tmp2 = (uint16_t)(tmp >> 6) & 0x03FF; - BatteryISRHandler(tmp2); -} - -void booz2_analog_extra_adc_read(void) { - uint32_t tmp,tmp2; -#ifdef USE_ADC_1 - tmp = AD1DR4; - tmp2 = (uint16_t)(tmp >> 6) & 0x03FF; - booz2_adc_1 = tmp2; -#endif -#ifdef USE_ADC_2 - tmp = AD0DR6; - tmp2 = (uint16_t)(tmp >> 6) & 0x03FF; - booz2_adc_2 = tmp2; -#endif -#ifdef USE_ADC_3 - tmp = AD0DR7; - tmp2 = (uint16_t)(tmp >> 6) & 0x03FF; - booz2_adc_3 = tmp2; -#endif -#ifdef USE_ADC_4 - tmp = AD1DR0; - tmp2 = (uint16_t)(tmp >> 6) & 0x03FF; - booz2_adc_4 = tmp2; -#endif -} - -#endif // USE_EXTRA_ADC diff --git a/sw/airborne/booz/arch/lpc21/booz2_analog_hw.h b/sw/airborne/booz/arch/lpc21/booz2_analog_hw.h deleted file mode 100644 index ae87ad0c84..0000000000 --- a/sw/airborne/booz/arch/lpc21/booz2_analog_hw.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2008-2009 Antoine Drouin - * - * This file is part of paparazzi. - * - * paparazzi 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, or (at your option) - * any later version. - * - * paparazzi 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 paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef BOOZ2_ANALOG_HW_H -#define BOOZ2_ANALOG_HW_H - -#include "LPC21xx.h" -#include "std.h" - -static inline void Booz2AnalogSetDAC(uint16_t x) { - DACR = x << 6; -} - -extern void booz2_analog_init_hw(void); - -#endif /* BOOZ2_ANALOG_HW_H */ diff --git a/sw/airborne/booz/arch/sim/booz2_analog_hw.c b/sw/airborne/booz/arch/sim/booz2_analog_hw.c deleted file mode 100644 index 25404f6ec4..0000000000 --- a/sw/airborne/booz/arch/sim/booz2_analog_hw.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2008-2009 Antoine Drouin - * - * This file is part of paparazzi. - * - * paparazzi 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, or (at your option) - * any later version. - * - * paparazzi 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 paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "booz2_analog.h" - -void booz2_analog_init_hw(void) { - -} - diff --git a/sw/airborne/booz/arch/sim/booz2_analog_hw.h b/sw/airborne/booz/arch/sim/booz2_analog_hw.h deleted file mode 100644 index 7e2c3231d9..0000000000 --- a/sw/airborne/booz/arch/sim/booz2_analog_hw.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2008-2009 Antoine Drouin - * - * This file is part of paparazzi. - * - * paparazzi 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, or (at your option) - * any later version. - * - * paparazzi 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 paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef BOOZ2_ANALOG_HW_H -#define BOOZ2_ANALOG_HW_H - -#define Booz2AnalogSetDAC(x) { } - -extern void booz2_analog_init_hw(void); - -#endif /* BOOZ2_ANALOG_HW_H */ diff --git a/sw/airborne/booz/arch/stm32/booz2_analog_hw.h b/sw/airborne/booz/arch/stm32/booz2_analog_hw.h deleted file mode 100644 index 9c074731f2..0000000000 --- a/sw/airborne/booz/arch/stm32/booz2_analog_hw.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * $Id: booz2_analog_hw.h 4172 2009-09-18 11:57:13Z flixr $ - * - * Copyright (C) 2008-2009 Antoine Drouin - * - * This file is part of paparazzi. - * - * paparazzi 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, or (at your option) - * any later version. - * - * paparazzi 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 paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef BOOZ2_ANALOG_HW_H -#define BOOZ2_ANALOG_HW_H - -#include "std.h" - -static inline void Booz2AnalogSetDAC(uint16_t x) {} - -extern void booz2_analog_init_hw(void); - -#endif /* BOOZ2_ANALOG_HW_H */ diff --git a/sw/airborne/booz/booz2_analog.c b/sw/airborne/booz/booz2_analog.c deleted file mode 100644 index 2e0f153b78..0000000000 --- a/sw/airborne/booz/booz2_analog.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2008-2009 Antoine Drouin - * - * This file is part of paparazzi. - * - * paparazzi 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, or (at your option) - * any later version. - * - * paparazzi 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 paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "booz2_analog.h" - -#include "std.h" - -// battery on AD0.3 on P0.30 -// baro on AD0.1 on P0.28 - -#define CHAN_BAT 3 -#define CHAN_BARO 1 - - -void booz2_analog_init( void ) { - - booz2_analog_init_hw(); - -} - -#ifdef USE_EXTRA_ADC -// Read manually baro (100Hz) and bat (10Hz) -void booz2_analog_periodic( void ) { - // baro - RunOnceEvery(5,booz2_analog_baro_read()); - // bat - RunOnceEvery(50,booz2_analog_bat_read()); -} -#endif diff --git a/sw/airborne/booz/booz2_analog.h b/sw/airborne/booz/booz2_analog.h deleted file mode 100644 index 1c4aa63481..0000000000 --- a/sw/airborne/booz/booz2_analog.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2008-2009 Antoine Drouin - * - * This file is part of paparazzi. - * - * paparazzi 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, or (at your option) - * any later version. - * - * paparazzi 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 paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef BOOZ2_ANALOG_H -#define BOOZ2_ANALOG_H - -extern void booz2_analog_init( void ); - -#ifdef USE_EXTRA_ADC -#include "std.h" - -extern uint16_t booz2_adc_1; -extern uint16_t booz2_adc_2; -extern uint16_t booz2_adc_3; -extern uint16_t booz2_adc_4; - -extern void booz2_analog_periodic( void ); - -extern void booz2_analog_baro_read(void); -extern void booz2_analog_bat_read(void); -extern void booz2_analog_extra_adc_read(void); -#endif - - -#include "booz2_analog_hw.h" - -#endif /* BOOZ2_ANALOG_H */ diff --git a/sw/airborne/firmwares/rotorcraft/main.c b/sw/airborne/firmwares/rotorcraft/main.c index ad0bf0e3c0..fd6ce9a3ee 100644 --- a/sw/airborne/firmwares/rotorcraft/main.c +++ b/sw/airborne/firmwares/rotorcraft/main.c @@ -41,11 +41,10 @@ #include "subsystems/imu.h" #include "booz_gps.h" -#include "booz/booz2_analog.h" #include "subsystems/sensors/baro.h" #include "baro_board.h" -#include "firmwares/rotorcraft/battery.h" +#include "subsystems/electrical.h" // #include "booz_fms.h" // FIXME #include "firmwares/rotorcraft/autopilot.h" @@ -98,6 +97,7 @@ STATIC_INLINE void main_init( void ) { mcu_init(); sys_time_init(); + electrical_init(); actuators_init(); radio_control_init(); @@ -106,12 +106,8 @@ STATIC_INLINE void main_init( void ) { xbee_init(); #endif - booz2_analog_init(); baro_init(); - - battery_init(); imu_init(); - // booz_fms_init(); // FIXME autopilot_init(); nav_init(); @@ -156,7 +152,7 @@ STATIC_INLINE void main_periodic( void ) { /* booz_fms_periodic(); FIXME */ \ }, \ { \ - /*BoozControlSurfacesSetFromCommands();*/ \ + electrical_periodic(); \ }, \ { \ LED_PERIODIC(); \ @@ -172,16 +168,12 @@ STATIC_INLINE void main_periodic( void ) { } ); #ifdef USE_GPS - if (radio_control.status != RC_OK && \ + if (radio_control.status != RC_OK && \ autopilot_mode == AP_MODE_NAV && GpsIsLost()) \ autopilot_set_mode(AP_MODE_FAILSAFE); \ booz_gps_periodic(); #endif -#ifdef USE_EXTRA_ADC - booz2_analog_periodic(); -#endif - modules_periodic_task(); if (autopilot_in_flight) { diff --git a/sw/airborne/firmwares/rotorcraft/telemetry.h b/sw/airborne/firmwares/rotorcraft/telemetry.h index 1cf5801b80..e9cbe76fae 100644 --- a/sw/airborne/firmwares/rotorcraft/telemetry.h +++ b/sw/airborne/firmwares/rotorcraft/telemetry.h @@ -45,7 +45,7 @@ #define PERIODIC_SEND_ALIVE(_chan) DOWNLINK_SEND_ALIVE(_chan, 16, MD5SUM) -#include "firmwares/rotorcraft/battery.h" +#include "subsystems/electrical.h" #include "subsystems/imu.h" #include "booz_gps.h" #include "subsystems/ins.h" @@ -56,43 +56,43 @@ extern uint8_t telemetry_mode_Main_DefaultChannel; #ifdef USE_GPS -#define PERIODIC_SEND_ROTORCRAFT_STATUS(_chan) { \ - uint32_t imu_nb_err = 0; \ +#define PERIODIC_SEND_ROTORCRAFT_STATUS(_chan) { \ + uint32_t imu_nb_err = 0; \ uint8_t _twi_blmc_nb_err = 0; \ - DOWNLINK_SEND_ROTORCRAFT_STATUS(_chan, \ - &imu_nb_err, \ - &_twi_blmc_nb_err, \ - &radio_control.status, \ - &radio_control.frame_rate, \ - &booz_gps_state.fix, \ - &autopilot_mode, \ - &autopilot_in_flight, \ - &autopilot_motors_on, \ - &guidance_h_mode, \ - &guidance_v_mode, \ - &battery_voltage, \ - &cpu_time_sec \ - ); \ + DOWNLINK_SEND_ROTORCRAFT_STATUS(_chan, \ + &imu_nb_err, \ + &_twi_blmc_nb_err, \ + &radio_control.status, \ + &radio_control.frame_rate, \ + &booz_gps_state.fix, \ + &autopilot_mode, \ + &autopilot_in_flight, \ + &autopilot_motors_on, \ + &guidance_h_mode, \ + &guidance_v_mode, \ + &electrical.vsupply, \ + &cpu_time_sec \ + ); \ } #else /* !USE_GPS */ -#define PERIODIC_SEND_ROTORCRAFT_STATUS(_chan) { \ - uint32_t imu_nb_err = 0; \ +#define PERIODIC_SEND_ROTORCRAFT_STATUS(_chan) { \ + uint32_t imu_nb_err = 0; \ uint8_t twi_blmc_nb_err = 0; \ uint8_t fix = BOOZ2_GPS_FIX_NONE; \ - DOWNLINK_SEND_ROTORCRAFT_STATUS(_chan, \ - &imu_nb_err, \ - &twi_blmc_nb_err, \ - &radio_control.status, \ - &radio_control.frame_rate, \ - &fix, \ - &autopilot_mode, \ - &autopilot_in_flight, \ - &autopilot_motors_on, \ - &guidance_h_mode, \ - &guidance_v_mode, \ - &battery_voltage, \ - &cpu_time_sec \ - ); \ + DOWNLINK_SEND_ROTORCRAFT_STATUS(_chan, \ + &imu_nb_err, \ + &twi_blmc_nb_err, \ + &radio_control.status, \ + &radio_control.frame_rate, \ + &fix, \ + &autopilot_mode, \ + &autopilot_in_flight, \ + &autopilot_motors_on, \ + &guidance_h_mode, \ + &guidance_v_mode, \ + &electrical.vsupply, \ + &cpu_time_sec \ + ); \ } #endif /* USE_GPS */ diff --git a/sw/airborne/mcu.c b/sw/airborne/mcu.c index e0853e4bab..1e8fee07d7 100644 --- a/sw/airborne/mcu.c +++ b/sw/airborne/mcu.c @@ -48,6 +48,9 @@ #ifdef USE_SPI #include "mcu_periph/spi.h" #endif +#ifdef USE_DAC +#include "mcu_periph/dac.h" +#endif #endif /* PERIPHERALS_AUTO_INIT */ void mcu_init(void) { @@ -98,6 +101,9 @@ void mcu_init(void) { #ifdef USE_SPI spi_init(); #endif +#ifdef USE_DAC + dac_init(); +#endif #endif /* PERIPHERALS_AUTO_INIT */ } diff --git a/sw/airborne/mcu_periph/dac.h b/sw/airborne/mcu_periph/dac.h new file mode 100644 index 0000000000..f1a7d23b41 --- /dev/null +++ b/sw/airborne/mcu_periph/dac.h @@ -0,0 +1,9 @@ +#ifndef MCU_PERIPH_DAC_H +#define MCU_PERIPH_DAC_H + +#include "mcu_periph/dac_arch.h" + +extern void dac_init(void); + + +#endif /* MCU_PERIPH_DAC_H */