1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

OP-994 Move common defines to architecture specific header

+review OPReview-506
This commit is contained in:
Alessio Morale 2013-06-24 18:50:44 +02:00
parent 840e6aa4f7
commit 0b8d18ae49
13 changed files with 99 additions and 37 deletions

View File

@ -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
}

View File

@ -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);
}

View File

@ -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 */

View File

@ -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

View File

@ -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;
}

View File

@ -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 */

View File

@ -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;
}

View File

@ -25,7 +25,7 @@
#ifndef PIOS_BOARD_H
#define PIOS_BOARD_H
#include <pios_architecture.h>
// ------------------------
// 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

View File

@ -25,7 +25,7 @@
#ifndef PIOS_BOARD_H
#define PIOS_BOARD_H
#include <pios_architecture.h>
#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

View File

@ -28,6 +28,8 @@
#include <stdbool.h>
#include <pios_architecture.h>
// *****************************************************************
// 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

View File

@ -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);

View File

@ -30,7 +30,7 @@
#define PIOS_BOARD_H
#include <stdbool.h>
#include <pios_architecture.h>
// ------------------------
// 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

View File

@ -30,6 +30,7 @@
#define PIOS_BOARD_H
#include <stdbool.h>
#include <pios_architecture.h>
// ------------------------
// 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