From 195e93c0d6e92f4891b94e669ee750e6cde178f9 Mon Sep 17 00:00:00 2001 From: chebuzz Date: Thu, 14 Apr 2011 09:46:23 +0000 Subject: [PATCH] OP-377 PiOS/BMP085 - Update BMP085 driver to be FreeRTOS agnostic. This is required since new INS does not run FreeRTOS. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@3160 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/PiOS/Boards/STM3210E_OP.h | 2 ++ flight/PiOS/Common/pios_bmp085.c | 47 ++++++++++++++++++++++++++++++-- flight/PiOS/inc/pios_bmp085.h | 1 + 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/flight/PiOS/Boards/STM3210E_OP.h b/flight/PiOS/Boards/STM3210E_OP.h index 6535f8a80..48653179c 100644 --- a/flight/PiOS/Boards/STM3210E_OP.h +++ b/flight/PiOS/Boards/STM3210E_OP.h @@ -146,6 +146,8 @@ extern uint32_t pios_i2c_main_adapter_id; #define PIOS_BMP085_EOC_EXTI_LINE EXTI_Line15 #define PIOS_BMP085_EOC_IRQn EXTI15_10_IRQn #define PIOS_BMP085_EOC_PRIO PIOS_IRQ_PRIO_LOW +#define PIOS_BMP085_XCLR_GPIO_PORT GPIOC // Not actually connected on OP mainboard +#define PIOS_BMP085_XCLR_GPIO_PIN GPIO_Pin_14 // Not actually connected on OP mainboard //#define PIOS_BMP085_OVERSAMPLING 2 #define PIOS_BMP085_OVERSAMPLING 3 diff --git a/flight/PiOS/Common/pios_bmp085.c b/flight/PiOS/Common/pios_bmp085.c index 7d97f9ebb..9a6a2310f 100644 --- a/flight/PiOS/Common/pios_bmp085.c +++ b/flight/PiOS/Common/pios_bmp085.c @@ -34,11 +34,15 @@ #if defined(PIOS_INCLUDE_BMP085) #if !defined(PIOS_INCLUDE_EXTI) #error PIOS_EXTI Must be included in the project! -#endif +#endif /* PIOS_INCLUDE_EXTI */ /* Glocal Variables */ ConversionTypeTypeDef CurrentRead; +#if defined(PIOS_INCLUDE_FREERTOS) xSemaphoreHandle PIOS_BMP085_EOC; +#else +int32_t PIOS_BMP085_EOC; +#endif /* Local Variables */ static BMP085CalibDataTypeDef CalibData; @@ -60,10 +64,14 @@ void PIOS_BMP085_Init(void) EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; +#if defined(PIOS_INCLUDE_FREERTOS) /* Semaphore used by ISR to signal End-Of-Conversion */ vSemaphoreCreateBinary(PIOS_BMP085_EOC); /* Must start off empty so that first transfer waits for EOC */ xSemaphoreTake(PIOS_BMP085_EOC, portMAX_DELAY); +#else + PIOS_BMP085_EOC = 0; +#endif /* Enable EOC GPIO clock */ RCC_APB2PeriphClockCmd(PIOS_BMP085_EOC_CLK | RCC_APB2Periph_AFIO, ENABLE); @@ -88,7 +96,12 @@ void PIOS_BMP085_Init(void) NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); - /* Read all 22 bytes of calibration data in one transfer, this is a very optimised way of doing things */ + /* Configure XCLR pin as push/pull alternate funtion output */ + GPIO_InitStructure.GPIO_Pin = PIOS_BMP085_XCLR_GPIO_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_Init(PIOS_BMP085_XCLR_GPIO_PORT, &GPIO_InitStructure); + + /* 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)) continue; @@ -254,4 +267,32 @@ bool PIOS_BMP085_Write(uint8_t address, uint8_t buffer) return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)); } -#endif +/** +* @brief Run self-test operation. +* \return 0 if self-test failed +* \return any non-0 number if test passed +*/ +int32_t PIOS_BMP085_Test() +{ + // TODO: Is there a better way to test this than just checking that pressure/temperature has changed? + int32_t passed = 1; + int32_t cur_value = 0; + + cur_value = Temperature; + PIOS_BMP085_StartADC(TemperatureConv); + PIOS_DELAY_WaitmS(5); + PIOS_BMP085_ReadADC(); + if (cur_value == Temperature) + passed = 0; + + cur_value=Pressure; + PIOS_BMP085_StartADC(PressureConv); + PIOS_DELAY_WaitmS(26); + PIOS_BMP085_ReadADC(); + if (cur_value == Pressure) + passed = 0; + + return passed; +} + +#endif /* PIOS_INCLUDE_BMP085 */ diff --git a/flight/PiOS/inc/pios_bmp085.h b/flight/PiOS/inc/pios_bmp085.h index 77b1ddee7..8cd796453 100644 --- a/flight/PiOS/inc/pios_bmp085.h +++ b/flight/PiOS/inc/pios_bmp085.h @@ -77,6 +77,7 @@ extern int16_t PIOS_BMP085_GetTemperature(void); extern int32_t PIOS_BMP085_GetPressure(void); extern bool PIOS_BMP085_Read(uint8_t address, uint8_t * buffer, uint8_t len); extern bool PIOS_BMP085_Write(uint8_t address, uint8_t buffer); +extern int32_t PIOS_BMP085_Test(); #endif /* PIOS_BMP085_H */