From 0b8d18ae49d0bfb303a36bfea44ad9830ab5ceba Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Mon, 24 Jun 2013 18:50:44 +0200 Subject: [PATCH] OP-994 Move common defines to architecture specific header +review OPReview-506 --- flight/modules/Battery/battery.c | 2 +- flight/modules/System/systemmod.c | 2 +- flight/pios/stm32f10x/inc/pios_architecture.h | 39 +++++++++++++++++++ flight/pios/stm32f10x/library.mk | 1 + flight/pios/stm32f10x/pios_adc.c | 3 +- flight/pios/stm32f4xx/inc/pios_architecture.h | 39 +++++++++++++++++++ flight/pios/stm32f4xx/pios_adc.c | 3 +- .../targets/boards/coptercontrol/pios_board.h | 9 +---- flight/targets/boards/oplinkmini/pios_board.h | 9 +---- flight/targets/boards/osd/pios_board.h | 8 ++-- .../boards/revolution/firmware/pios_board.c | 6 +-- flight/targets/boards/revolution/pios_board.h | 8 +--- flight/targets/boards/revoproto/pios_board.h | 7 +--- 13 files changed, 99 insertions(+), 37 deletions(-) create mode 100644 flight/pios/stm32f10x/inc/pios_architecture.h create mode 100644 flight/pios/stm32f4xx/inc/pios_architecture.h diff --git a/flight/modules/Battery/battery.c b/flight/modules/Battery/battery.c index 6325bb7c8..7509e6a03 100644 --- a/flight/modules/Battery/battery.c +++ b/flight/modules/Battery/battery.c @@ -141,7 +141,7 @@ static void onTimer(__attribute__((unused)) UAVObjEvent *ev) } if (currentADCPin >= 0) { - flightBatteryData.Current = PIOS_ADC_PinGetVolt(currentADCPin) * batterySettings.SensorCalibrations[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONS_CURRENTFACTOR]; // in Amps + flightBatteryData.Current = PIOS_ADC_PinGetVolt(currentADCPin) * batterySettings.SensorCalibrations[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONS_CURRENTFACTOR]; // in Amps if (flightBatteryData.Current > flightBatteryData.PeakCurrent) { flightBatteryData.PeakCurrent = flightBatteryData.Current; // in Amps } diff --git a/flight/modules/System/systemmod.c b/flight/modules/System/systemmod.c index 3268f7d95..52145fa42 100644 --- a/flight/modules/System/systemmod.c +++ b/flight/modules/System/systemmod.c @@ -472,7 +472,7 @@ static void updateStats() idleCounterClear = 1; #if defined(PIOS_INCLUDE_ADC) && defined(PIOS_ADC_USE_TEMP_SENSOR) float temp_voltage = PIOS_ADC_PinGetVolt(PIOS_ADC_TEMPERATURE_PIN); - stats.CPUTemp = PIOS_CONVERT_VOLT_TO_CPU_TEMP(temp_voltage);; + stats.CPUTemp = PIOS_CONVERT_VOLT_TO_CPU_TEMP(temp_voltage);; #endif SystemStatsSet(&stats); } diff --git a/flight/pios/stm32f10x/inc/pios_architecture.h b/flight/pios/stm32f10x/inc/pios_architecture.h new file mode 100644 index 000000000..bf9dd7742 --- /dev/null +++ b/flight/pios/stm32f10x/inc/pios_architecture.h @@ -0,0 +1,39 @@ +/** + ****************************************************************************** + * + * @file pios_architecture.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013. + * @brief Architecture specific macros and definitions + * -- + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * 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 3 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 PIOS_ARCHITECTURE_H +#define PIOS_ARCHITECTURE_H + +// defines for adc +#define PIOS_ADC_VOLTAGE_SCALE 3.30f / 4096.0f + +// defines for Temp measurements +#define PIOS_ADC_STM32_TEMP_V25 1.43f /* V */ +#define PIOS_ADC_STM32_TEMP_AVG_SLOPE 4.3f /* mV/C */ +#define PIOS_CONVERT_VOLT_TO_CPU_TEMP(x) ((PIOS_ADC_STM32_TEMP_V25 - x) * 1000.0f / PIOS_ADC_STM32_TEMP_AVG_SLOPE + 25.0f) + + +#endif /* PIOS_ARCHITECTURE_H */ diff --git a/flight/pios/stm32f10x/library.mk b/flight/pios/stm32f10x/library.mk index 42a611351..e468b0bb7 100644 --- a/flight/pios/stm32f10x/library.mk +++ b/flight/pios/stm32f10x/library.mk @@ -20,6 +20,7 @@ ASRC += $(PIOS_DEVLIB)startup_stm32f10x_$(MODEL)$(MODEL_SUFFIX).S # PIOS device library source and includes SRC += $(sort $(wildcard $(PIOS_DEVLIB)*.c)) +EXTRAINCDIRS += $(PIOS_DEVLIB)inc # CMSIS for the F1 include $(PIOSCOMMON)/libraries/CMSIS/library.mk diff --git a/flight/pios/stm32f10x/pios_adc.c b/flight/pios/stm32f10x/pios_adc.c index 413f34039..3f5701449 100644 --- a/flight/pios/stm32f10x/pios_adc.c +++ b/flight/pios/stm32f10x/pios_adc.c @@ -57,7 +57,8 @@ struct pios_adc_dev { enum pios_adc_dev_magic magic; }; -float PIOS_ADC_PinGetVolt(uint32_t pin){ +float PIOS_ADC_PinGetVolt(uint32_t pin) +{ return ((float)PIOS_ADC_PinGet(pin)) * PIOS_ADC_VOLTAGE_SCALE; } diff --git a/flight/pios/stm32f4xx/inc/pios_architecture.h b/flight/pios/stm32f4xx/inc/pios_architecture.h new file mode 100644 index 000000000..dddc4df63 --- /dev/null +++ b/flight/pios/stm32f4xx/inc/pios_architecture.h @@ -0,0 +1,39 @@ +/** + ****************************************************************************** + * + * @file pios_architecture.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013. + * @brief Architecture specific macros and definitions + * -- + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * 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 3 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 PIOS_ARCHITECTURE_H +#define PIOS_ARCHITECTURE_H + +// defines for adc +#define PIOS_ADC_VOLTAGE_SCALE 3.30f / 4096.0f + +// defines for Temp measurements +#define PIOS_ADC_STM32_TEMP_V25 0.76f /* V */ +#define PIOS_ADC_STM32_TEMP_AVG_SLOPE 2.5f /* mV/C */ +#define PIOS_CONVERT_VOLT_TO_CPU_TEMP(x) ((x - PIOS_ADC_STM32_TEMP_V25) * 1000.0f / PIOS_ADC_STM32_TEMP_AVG_SLOPE + 25.0f) + + +#endif /* PIOS_ARCHITECTURE_H */ diff --git a/flight/pios/stm32f4xx/pios_adc.c b/flight/pios/stm32f4xx/pios_adc.c index c40f91b2b..b6c2d6951 100644 --- a/flight/pios/stm32f4xx/pios_adc.c +++ b/flight/pios/stm32f4xx/pios_adc.c @@ -324,7 +324,8 @@ int32_t PIOS_ADC_PinGet(uint32_t pin) return -1; } -float PIOS_ADC_PinGetVolt(uint32_t pin){ +float PIOS_ADC_PinGetVolt(uint32_t pin) +{ return ((float)PIOS_ADC_PinGet(pin)) * PIOS_ADC_VOLTAGE_SCALE; } diff --git a/flight/targets/boards/coptercontrol/pios_board.h b/flight/targets/boards/coptercontrol/pios_board.h index 8987c4f36..9a63bffad 100644 --- a/flight/targets/boards/coptercontrol/pios_board.h +++ b/flight/targets/boards/coptercontrol/pios_board.h @@ -25,7 +25,7 @@ #ifndef PIOS_BOARD_H #define PIOS_BOARD_H - +#include // ------------------------ // Timers and Channels Used // ------------------------ @@ -213,12 +213,7 @@ extern uint32_t pios_com_hkosd_id; #define PIOS_ADC_RATE (72.0e6f / 1.0f / 8.0f / 252.0f / (PIOS_ADC_NUM_CHANNELS >> PIOS_ADC_USE_ADC2)) #define PIOS_ADC_MAX_OVERSAMPLING 36 -#define PIOS_ADC_VOLTAGE_SCALE 3.30f/4096.0f - -#define PIOS_ADC_TEMPERATURE_PIN 0 -#define PIOS_ADC_STM32_TEMP_V25 1.43f /* V */ -#define PIOS_ADC_STM32_TEMP_AVG_SLOPE 4.3f /* mV/C */ -#define PIOS_CONVERT_VOLT_TO_CPU_TEMP(x) ((PIOS_ADC_STM32_TEMP_V25 - x) * 1000.0f / PIOS_ADC_STM32_TEMP_AVG_SLOPE + 25.0f) +#define PIOS_ADC_TEMPERATURE_PIN 0 // ------------------------ // PIOS_RCVR diff --git a/flight/targets/boards/oplinkmini/pios_board.h b/flight/targets/boards/oplinkmini/pios_board.h index 2eda66945..a40800972 100644 --- a/flight/targets/boards/oplinkmini/pios_board.h +++ b/flight/targets/boards/oplinkmini/pios_board.h @@ -25,7 +25,7 @@ #ifndef PIOS_BOARD_H #define PIOS_BOARD_H - +#include #define ADD_ONE_ADC // ------------------------ @@ -233,12 +233,7 @@ extern uint32_t pios_ppm_out_id; #define PIOS_ADC_RATE (72.0e6 / 1.0 / 8.0 / 252.0 / (PIOS_ADC_NUM_CHANNELS >> PIOS_ADC_USE_ADC2)) #define PIOS_ADC_MAX_OVERSAMPLING 36 -#define PIOS_ADC_VOLTAGE_SCALE 3.30f/4096.0f - -#define PIOS_ADC_TEMPERATURE_PIN 0 -#define PIOS_ADC_STM32_TEMP_V25 1.43f /* V */ -#define PIOS_ADC_STM32_TEMP_AVG_SLOPE 4.3f /* mV/C */ -#define PIOS_CONVERT_VOLT_TO_CPU_TEMP(x) ((PIOS_ADC_STM32_TEMP_V25 - x) * 1000.0f / PIOS_ADC_STM32_TEMP_AVG_SLOPE + 25.0f) +#define PIOS_ADC_TEMPERATURE_PIN 0 // ------------------------ // PIOS_RCVR diff --git a/flight/targets/boards/osd/pios_board.h b/flight/targets/boards/osd/pios_board.h index 5c58a789f..b2246b514 100644 --- a/flight/targets/boards/osd/pios_board.h +++ b/flight/targets/boards/osd/pios_board.h @@ -28,6 +28,8 @@ #include +#include + // ***************************************************************** // Timers and Channels Used @@ -226,11 +228,7 @@ extern uint32_t pios_com_telem_usb_id; #define PIOS_ADC_USE_TEMP_SENSOR -#define PIOS_ADC_VOLTAGE_SCALE 3.30f/4096.0f -#define PIOS_ADC_TEMPERATURE_PIN 6 /* V */ -#define PIOS_ADC_STM32_TEMP_V25 0.76f /* mV/C */ -#define PIOS_ADC_STM32_TEMP_AVG_SLOPE 2.5f -#define PIOS_CONVERT_VOLT_TO_CPU_TEMP(x) ((x - PIOS_ADC_STM32_TEMP_V25) * 1000.0f / PIOS_ADC_STM32_TEMP_AVG_SLOPE + 25.0f) +#define PIOS_ADC_TEMPERATURE_PIN 6 /* V */ // ***************************************************************** // USB diff --git a/flight/targets/boards/revolution/firmware/pios_board.c b/flight/targets/boards/revolution/firmware/pios_board.c index 500f5125f..6f9d7a96d 100644 --- a/flight/targets/boards/revolution/firmware/pios_board.c +++ b/flight/targets/boards/revolution/firmware/pios_board.c @@ -847,11 +847,11 @@ void PIOS_Board_Init(void) #endif // Disable GPIO_A8 Pullup to prevent wrong results on battery voltage readout - GPIO_InitTypeDef gpioA8 ={ + GPIO_InitTypeDef gpioA8 = { .GPIO_Speed = GPIO_Speed_2MHz, .GPIO_Mode = GPIO_Mode_IN, - .GPIO_PuPd = GPIO_PuPd_NOPULL, - .GPIO_Pin = GPIO_Pin_8, + .GPIO_PuPd = GPIO_PuPd_NOPULL, + .GPIO_Pin = GPIO_Pin_8, .GPIO_OType = GPIO_OType_OD, }; GPIO_Init(GPIOA, &gpioA8); diff --git a/flight/targets/boards/revolution/pios_board.h b/flight/targets/boards/revolution/pios_board.h index 64a2cefbd..b1b617972 100644 --- a/flight/targets/boards/revolution/pios_board.h +++ b/flight/targets/boards/revolution/pios_board.h @@ -30,7 +30,7 @@ #define PIOS_BOARD_H #include - +#include // ------------------------ // Timers and Channels Used // ------------------------ @@ -292,13 +292,9 @@ extern uint32_t pios_packet_handler; #define PIOS_ADC_NUM_CHANNELS 4 #define PIOS_ADC_MAX_OVERSAMPLING 2 #define PIOS_ADC_USE_ADC2 0 -#define PIOS_ADC_VOLTAGE_SCALE 3.30f / 4096.0f #define PIOS_ADC_USE_TEMP_SENSOR -#define PIOS_ADC_TEMPERATURE_PIN 3 -#define PIOS_ADC_STM32_TEMP_V25 0.76f /* V */ -#define PIOS_ADC_STM32_TEMP_AVG_SLOPE 2.5f /* mV/C */ -#define PIOS_CONVERT_VOLT_TO_CPU_TEMP(x) ((x - PIOS_ADC_STM32_TEMP_V25) * 1000.0f / PIOS_ADC_STM32_TEMP_AVG_SLOPE + 25.0f) +#define PIOS_ADC_TEMPERATURE_PIN 3 // ------------------------- // USB diff --git a/flight/targets/boards/revoproto/pios_board.h b/flight/targets/boards/revoproto/pios_board.h index 66bb03073..ece8e41b8 100644 --- a/flight/targets/boards/revoproto/pios_board.h +++ b/flight/targets/boards/revoproto/pios_board.h @@ -30,6 +30,7 @@ #define PIOS_BOARD_H #include +#include // ------------------------ // Timers and Channels Used @@ -254,13 +255,9 @@ extern uint32_t pios_com_hkosd_id; #define PIOS_ADC_NUM_CHANNELS 4 #define PIOS_ADC_MAX_OVERSAMPLING 2 #define PIOS_ADC_USE_ADC2 0 -#define PIOS_ADC_VOLTAGE_SCALE 3.30f / 4096.0f #define PIOS_ADC_USE_TEMP_SENSOR -#define PIOS_ADC_TEMPERATURE_PIN 3 /* V */ -#define PIOS_ADC_STM32_TEMP_V25 0.76f /* mV/C */ -#define PIOS_ADC_STM32_TEMP_AVG_SLOPE 2.5f -#define PIOS_CONVERT_VOLT_TO_CPU_TEMP(x) ((x - PIOS_ADC_STM32_TEMP_V25) * 1000.0f / PIOS_ADC_STM32_TEMP_AVG_SLOPE + 25.0f) +#define PIOS_ADC_TEMPERATURE_PIN 3 /* V */ // ------------------------- // USB