1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Merge remote-tracking branch 'origin/stac/i2c_decoupling' into next

This commit is contained in:
Stacey Sheldon 2012-01-17 22:35:36 -05:00
commit 64202ce092
18 changed files with 129 additions and 51 deletions

View File

@ -50,7 +50,7 @@ ENABLE_AUX_UART ?= NO
USE_GPS ?= YES
USE_I2C ?= NO
USE_I2C ?= YES
# Set to YES when using Code Sourcery toolchain
CODE_SOURCERY ?= YES
@ -65,7 +65,7 @@ endif
FLASH_TOOL = OPENOCD
# List of modules to include
OPTMODULES = CameraStab ComUsbBridge
OPTMODULES = CameraStab ComUsbBridge Altitude
ifeq ($(USE_GPS), YES)
OPTMODULES += GPS
endif
@ -181,6 +181,7 @@ SRC += $(OPUAVSYNTHDIR)/receiveractivity.c
SRC += $(OPUAVSYNTHDIR)/taskinfo.c
SRC += $(OPUAVSYNTHDIR)/mixerstatus.c
SRC += $(OPUAVSYNTHDIR)/ratedesired.c
SRC += $(OPUAVSYNTHDIR)/baroaltitude.c
endif
@ -224,6 +225,7 @@ SRC += $(PIOSCOMMON)/pios_flash_w25x.c
SRC += $(PIOSCOMMON)/pios_adxl345.c
SRC += $(PIOSCOMMON)/pios_com.c
SRC += $(PIOSCOMMON)/pios_i2c_esc.c
SRC += $(PIOSCOMMON)/pios_bmp085.c
SRC += $(PIOSCOMMON)/pios_iap.c
SRC += $(PIOSCOMMON)/pios_bl_helper.c
SRC += $(PIOSCOMMON)/pios_rcvr.c
@ -410,6 +412,9 @@ ifeq ($(USE_I2C), YES)
CDEFS += -DUSE_I2C
endif
# Declare all non-optional modules as built-in to force inclusion
CDEFS += ${foreach MOD, ${MODULES}, -DMODULE_$(MOD)_BUILTIN }
# Place project-specific -D and/or -U options for
# Assembler with preprocessor here.
#ADEFS = -DUSE_IRQ_ASM_WRAPPER

View File

@ -77,6 +77,8 @@
#define PIOS_INCLUDE_ADXL345
#define PIOS_INCLUDE_FLASH
#define PIOS_INCLUDE_BMP085
/* A really shitty setting saving implementation */
#define PIOS_INCLUDE_FLASH_SECTOR_SETTINGS

View File

@ -903,12 +903,12 @@ const struct pios_pwm_cfg pios_pwm_cfg = {
* I2C Adapters
*/
void PIOS_I2C_main_adapter_ev_irq_handler(void);
void PIOS_I2C_main_adapter_er_irq_handler(void);
void I2C2_EV_IRQHandler() __attribute__ ((alias ("PIOS_I2C_main_adapter_ev_irq_handler")));
void I2C2_ER_IRQHandler() __attribute__ ((alias ("PIOS_I2C_main_adapter_er_irq_handler")));
void PIOS_I2C_flexi_adapter_ev_irq_handler(void);
void PIOS_I2C_flexi_adapter_er_irq_handler(void);
void I2C2_EV_IRQHandler() __attribute__ ((alias ("PIOS_I2C_flexi_adapter_ev_irq_handler")));
void I2C2_ER_IRQHandler() __attribute__ ((alias ("PIOS_I2C_flexi_adapter_er_irq_handler")));
static const struct pios_i2c_adapter_cfg pios_i2c_main_adapter_cfg = {
static const struct pios_i2c_adapter_cfg pios_i2c_flexi_adapter_cfg = {
.regs = I2C2,
.init = {
.I2C_Mode = I2C_Mode_I2C,
@ -955,17 +955,17 @@ static const struct pios_i2c_adapter_cfg pios_i2c_main_adapter_cfg = {
},
};
uint32_t pios_i2c_main_adapter_id;
void PIOS_I2C_main_adapter_ev_irq_handler(void)
uint32_t pios_i2c_flexi_adapter_id;
void PIOS_I2C_flexi_adapter_ev_irq_handler(void)
{
/* Call into the generic code to handle the IRQ for this specific device */
PIOS_I2C_EV_IRQ_Handler(pios_i2c_main_adapter_id);
PIOS_I2C_EV_IRQ_Handler(pios_i2c_flexi_adapter_id);
}
void PIOS_I2C_main_adapter_er_irq_handler(void)
void PIOS_I2C_flexi_adapter_er_irq_handler(void)
{
/* Call into the generic code to handle the IRQ for this specific device */
PIOS_I2C_ER_IRQ_Handler(pios_i2c_main_adapter_id);
PIOS_I2C_ER_IRQ_Handler(pios_i2c_flexi_adapter_id);
}
#endif /* PIOS_INCLUDE_I2C */
@ -1464,7 +1464,7 @@ void PIOS_Board_Init(void) {
case HWSETTINGS_CC_FLEXIPORT_I2C:
#if defined(PIOS_INCLUDE_I2C)
{
if (PIOS_I2C_Init(&pios_i2c_main_adapter_id, &pios_i2c_main_adapter_cfg)) {
if (PIOS_I2C_Init(&pios_i2c_flexi_adapter_id, &pios_i2c_flexi_adapter_cfg)) {
PIOS_Assert(0);
}
}

View File

@ -37,6 +37,7 @@
*/
#include "openpilot.h"
#include "hwsettings.h"
#include "altitude.h"
#include "baroaltitude.h" // object that will be updated by the module
#if defined(PIOS_INCLUDE_HCSR04)
@ -46,8 +47,7 @@
// Private constants
#define STACK_SIZE_BYTES 500
#define TASK_PRIORITY (tskIDLE_PRIORITY+1)
//#define UPDATE_PERIOD 100
#define UPDATE_PERIOD 25
#define UPDATE_PERIOD 50
// Private types
@ -60,6 +60,8 @@ static int32_t alt_ds_temp = 0;
static int32_t alt_ds_pres = 0;
static int alt_ds_count = 0;
static bool altitudeEnabled;
// Private functions
static void altitudeTask(void *parameters);
@ -69,17 +71,19 @@ static void altitudeTask(void *parameters);
*/
int32_t AltitudeStart()
{
BaroAltitudeInitialize();
#if defined(PIOS_INCLUDE_HCSR04)
SonarAltitudeInitialze();
#endif
// Start main task
xTaskCreate(altitudeTask, (signed char *)"Altitude", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle);
TaskMonitorAdd(TASKINFO_RUNNING_ALTITUDE, taskHandle);
return 0;
if (altitudeEnabled) {
BaroAltitudeInitialize();
#if defined(PIOS_INCLUDE_HCSR04)
SonarAltitudeInitialze();
#endif
// Start main task
xTaskCreate(altitudeTask, (signed char *)"Altitude", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle);
TaskMonitorAdd(TASKINFO_RUNNING_ALTITUDE, taskHandle);
return 0;
}
return -1;
}
/**
@ -88,11 +92,23 @@ int32_t AltitudeStart()
*/
int32_t AltitudeInitialize()
{
#ifdef MODULE_Altitude_BUILTIN
altitudeEnabled = 1;
#else
HwSettingsInitialize();
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
HwSettingsOptionalModulesGet(optionalModules);
if (optionalModules[HWSETTINGS_OPTIONALMODULES_ALTITUDE] == HWSETTINGS_OPTIONALMODULES_ENABLED) {
altitudeEnabled = 1;
} else {
altitudeEnabled = 0;
}
#endif
// init down-sampling data
alt_ds_temp = 0;
alt_ds_pres = 0;
alt_ds_count = 0;
alt_ds_temp = 0;
alt_ds_pres = 0;
alt_ds_count = 0;
return 0;
}
@ -144,34 +160,42 @@ static void altitudeTask(void *parameters)
#endif
// Update the temperature data
PIOS_BMP085_StartADC(TemperatureConv);
#ifdef PIOS_BMP085_HAS_GPIOS
xSemaphoreTake(PIOS_BMP085_EOC, portMAX_DELAY);
#else
vTaskDelay(5 / portTICK_RATE_MS);
#endif
PIOS_BMP085_ReadADC();
alt_ds_temp += PIOS_BMP085_GetTemperature();
// Update the pressure data
PIOS_BMP085_StartADC(PressureConv);
#ifdef PIOS_BMP085_HAS_GPIOS
xSemaphoreTake(PIOS_BMP085_EOC, portMAX_DELAY);
#else
vTaskDelay(26 / portTICK_RATE_MS);
#endif
PIOS_BMP085_ReadADC();
alt_ds_pres += PIOS_BMP085_GetPressure();
if (++alt_ds_count >= alt_ds_size)
{
alt_ds_count = 0;
{
alt_ds_count = 0;
// Convert from 1/10ths of degC to degC
data.Temperature = alt_ds_temp / (10.0 * alt_ds_size);
alt_ds_temp = 0;
// Convert from 1/10ths of degC to degC
data.Temperature = alt_ds_temp / (10.0 * alt_ds_size);
alt_ds_temp = 0;
// Convert from Pa to kPa
data.Pressure = alt_ds_pres / (1000.0f * alt_ds_size);
alt_ds_pres = 0;
// Convert from Pa to kPa
data.Pressure = alt_ds_pres / (1000.0f * alt_ds_size);
alt_ds_pres = 0;
// Compute the current altitude (all pressures in kPa)
data.Altitude = 44330.0 * (1.0 - powf((data.Pressure / (BMP085_P0 / 1000.0)), (1.0 / 5.255)));
// Compute the current altitude (all pressures in kPa)
data.Altitude = 44330.0 * (1.0 - powf((data.Pressure / (BMP085_P0 / 1000.0)), (1.0 / 5.255)));
// Update the AltitudeActual UAVObject
BaroAltitudeSet(&data);
}
// Update the AltitudeActual UAVObject
BaroAltitudeSet(&data);
}
// Delay until it is time to read the next sample
vTaskDelayUntil(&lastSysTime, UPDATE_PERIOD / portTICK_RATE_MS);

View File

@ -78,6 +78,10 @@ static float bound(float val, float limit);
int32_t CameraStabInitialize(void)
{
bool cameraStabEnabled;
#ifdef MODULE_CameraStab_BUILTIN
cameraStabEnabled = true;
#else
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
HwSettingsInitialize();
@ -87,6 +91,7 @@ int32_t CameraStabInitialize(void)
cameraStabEnabled = true;
else
cameraStabEnabled = false;
#endif
if (cameraStabEnabled) {

View File

@ -94,6 +94,9 @@ static int32_t comUsbBridgeInitialize(void)
usart_port = PIOS_COM_BRIDGE;
vcp_port = PIOS_COM_VCP;
#ifdef MODULE_ComUsbBridge_BUILTIN
bridge_enabled = true;
#else
HwSettingsInitialize();
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
@ -104,6 +107,7 @@ static int32_t comUsbBridgeInitialize(void)
bridge_enabled = true;
else
bridge_enabled = false;
#endif
if (bridge_enabled) {
com2usb_buf = pvPortMalloc(BRIDGE_BUF_LEN);

View File

@ -40,6 +40,9 @@ static uint8_t active_fault;
static int32_t fault_initialize(void)
{
#ifdef MODULE_Fault_BUILTIN
module_enabled = true;
#else
HwSettingsInitialize();
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
@ -50,6 +53,7 @@ static int32_t fault_initialize(void)
} else {
module_enabled = false;
}
#endif
/* Do this outside the module_enabled test so that it
* can be changed even when the module has been disabled.

View File

@ -121,6 +121,9 @@ int32_t GPSInitialize(void)
{
gpsPort = PIOS_COM_GPS;
#ifdef MODULE_GPS_BUILTIN
gpsEnabled = true;
#else
HwSettingsInitialize();
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
@ -130,6 +133,7 @@ int32_t GPSInitialize(void)
gpsEnabled = true;
else
gpsEnabled = false;
#endif
if (gpsPort && gpsEnabled) {
GPSPositionInitialize();

View File

@ -370,6 +370,9 @@ ifeq ($(ENABLE_AUX_UART), YES)
CDEFS += -DPIOS_ENABLE_AUX_UART
endif
# Declare all non-optional modules as built-in to force inclusion
CDEFS += ${foreach MOD, ${MODULES}, -DMODULE_$(MOD)_BUILTIN }
# Place project-specific -D and/or -U options for
# Assembler with preprocessor here.
#ADEFS = -DUSE_IRQ_ASM_WRAPPER

View File

@ -110,8 +110,15 @@ TIM4 | RC In 1 | Servo 3 | Servo 2 | Servo 1
// See also pios_board.c
//------------------------
#define PIOS_I2C_MAX_DEVS 1
extern uint32_t pios_i2c_main_adapter_id;
#define PIOS_I2C_MAIN_ADAPTER (pios_i2c_main_adapter_id)
extern uint32_t pios_i2c_flexi_adapter_id;
#define PIOS_I2C_MAIN_ADAPTER (pios_i2c_flexi_adapter_id)
#define PIOS_I2C_ESC_ADAPTER (pios_i2c_flexi_adapter_id)
#define PIOS_I2C_BMP085_ADAPTER (pios_i2c_flexi_adapter_id)
//------------------------
// PIOS_BMP085
//------------------------
#define PIOS_BMP085_OVERSAMPLING 3
//-------------------------
// SPI

View File

@ -100,12 +100,14 @@ TIM8 | | | |
#define PIOS_I2C_MAX_DEVS 3
extern uint32_t pios_i2c_pres_mag_adapter_id;
#define PIOS_I2C_MAIN_ADAPTER (pios_i2c_pres_mag_adapter_id)
#define PIOS_I2C_BMP085_ADAPTER (pios_i2c_pres_mag_adapter_id)
extern uint32_t pios_i2c_gyro_adapter_id;
#define PIOS_I2C_GYRO_ADAPTER (pios_i2c_gyro_adapter_id)
//------------------------
// PIOS_BMP085
//------------------------
#define PIOS_BMP085_HAS_GPIOS
#define PIOS_BMP085_EOC_GPIO_PORT GPIOC
#define PIOS_BMP085_EOC_GPIO_PIN GPIO_Pin_2
#define PIOS_BMP085_EOC_PORT_SOURCE GPIO_PortSourceGPIOC

View File

@ -115,10 +115,13 @@ TIM8 | Servo 5 | Servo 6 | Servo 7 | Servo 8
#define PIOS_I2C_MAX_DEVS 1
extern uint32_t pios_i2c_main_adapter_id;
#define PIOS_I2C_MAIN_ADAPTER (pios_i2c_main_adapter_id)
#define PIOS_I2C_ESC_ADAPTER (pios_i2c_main_adapter_id)
#define PIOS_I2C_BMP085_ADAPTER (pios_i2c_main_adapter_id)
//------------------------
// PIOS_BMP085
//------------------------
#define PIOS_BMP085_HAS_GPIOS
#define PIOS_BMP085_EOC_GPIO_PORT GPIOC
#define PIOS_BMP085_EOC_GPIO_PIN GPIO_Pin_15
#define PIOS_BMP085_EOC_PORT_SOURCE GPIO_PortSourceGPIOC

View File

@ -38,12 +38,17 @@
/* Glocal Variables */
ConversionTypeTypeDef CurrentRead;
#ifdef PIOS_BMP085_HAS_GPIOS
#if defined(PIOS_INCLUDE_FREERTOS)
xSemaphoreHandle PIOS_BMP085_EOC;
#else
int32_t PIOS_BMP085_EOC;
#endif
#endif /* PIOS_BMP085_HAS_GPIOS */
/* Local Variables */
static BMP085CalibDataTypeDef CalibData;
@ -60,6 +65,9 @@ static volatile uint16_t Temperature;
*/
void PIOS_BMP085_Init(void)
{
#ifdef PIOS_BMP085_HAS_GPIOS
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
@ -101,6 +109,8 @@ void PIOS_BMP085_Init(void)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(PIOS_BMP085_XCLR_GPIO_PORT, &GPIO_InitStructure);
#endif /* PIOS_BMP085_HAS_GPIOS */
/* Read all 22 bytes of calibration data in one transfer, this is a very optimized way of doing things */
uint8_t Data[BMP085_CALIB_LEN];
while (!PIOS_BMP085_Read(BMP085_CALIB_ADDR, Data, BMP085_CALIB_LEN))
@ -235,7 +245,7 @@ bool PIOS_BMP085_Read(uint8_t address, uint8_t * buffer, uint8_t len)
}
};
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
return PIOS_I2C_Transfer(PIOS_I2C_BMP085_ADAPTER, txn_list, NELEMENTS(txn_list));
}
/**
@ -264,7 +274,7 @@ bool PIOS_BMP085_Write(uint8_t address, uint8_t buffer)
,
};
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
return PIOS_I2C_Transfer(PIOS_I2C_BMP085_ADAPTER, txn_list, NELEMENTS(txn_list));
}
/**

View File

@ -93,7 +93,7 @@ bool PIOS_I2C_ESC_SetSpeed(uint8_t speed[4])
}
};
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
return PIOS_I2C_Transfer(PIOS_I2C_ESC_ADAPTER, txn_list, NELEMENTS(txn_list));
}
bool PIOS_SetMKSpeed(uint8_t motornum, uint8_t speed) {
@ -115,7 +115,7 @@ bool PIOS_SetMKSpeed(uint8_t motornum, uint8_t speed) {
}
};
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
return PIOS_I2C_Transfer(PIOS_I2C_ESC_ADAPTER, txn_list, NELEMENTS(txn_list));
}
bool PIOS_SetAstec4Address(uint8_t new_address) {
@ -134,7 +134,7 @@ bool PIOS_SetAstec4Address(uint8_t new_address) {
}
};
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
return PIOS_I2C_Transfer(PIOS_I2C_ESC_ADAPTER, txn_list, NELEMENTS(txn_list));
}
bool PIOS_SetAstec4Speed(uint8_t motornum, uint8_t speed) {
@ -161,7 +161,7 @@ bool PIOS_SetAstec4Speed(uint8_t motornum, uint8_t speed) {
}
};
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
return PIOS_I2C_Transfer(PIOS_I2C_ESC_ADAPTER, txn_list, NELEMENTS(txn_list));
}
#endif

View File

@ -44,7 +44,7 @@ void EXTI15_10_IRQHandler(void)
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
#endif
#if defined(PIOS_INCLUDE_BMP085)
#if defined(PIOS_INCLUDE_BMP085) && defined(PIOS_BMP085_HAS_GPIOS)
if (EXTI_GetITStatus(PIOS_BMP085_EOC_EXTI_LINE) != RESET) {
/* Read the ADC Value */
#if defined(PIOS_INCLUDE_FREERTOS)

View File

@ -891,6 +891,10 @@ int32_t PIOS_I2C_Init(uint32_t * i2c_id, const struct pios_i2c_adapter_cfg * cfg
break;
}
if (i2c_adapter->cfg->remap) {
GPIO_PinRemapConfig(i2c_adapter->cfg->remap, ENABLE);
}
/* Initialize the state machine */
i2c_adapter_fsm_init(i2c_adapter);

View File

@ -37,6 +37,7 @@ struct pios_i2c_adapter_cfg {
uint32_t transfer_timeout_ms;
struct stm32_gpio scl;
struct stm32_gpio sda;
uint32_t remap;
struct stm32_irq event;
struct stm32_irq error;
};

View File

@ -16,7 +16,7 @@
<field name="USB_HIDPort" units="function" type="enum" elements="1" options="USBTelemetry,Disabled" defaultvalue="USBTelemetry"/>
<field name="USB_VCPPort" units="function" type="enum" elements="1" options="USBTelemetry,ComBridge,Disabled" defaultvalue="Disabled"/>
<field name="OptionalModules" units="" type="enum" elementnames="CameraStab,GPS,ComUsbBridge,Fault" options="Disabled,Enabled" defaultvalue="Disabled"/>
<field name="OptionalModules" units="" type="enum" elementnames="CameraStab,GPS,ComUsbBridge,Fault,Altitude" options="Disabled,Enabled" defaultvalue="Disabled"/>
<field name="DSMxBind" units="" type="uint8" elements="1" defaultvalue="0"/>
<access gcs="readwrite" flight="readwrite"/>