mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Fix the BMP085 interrupt handler and get it producing data. Driver needs some
work to abstract away the actual calculation of altitude from pressure and temperature.
This commit is contained in:
parent
62f51fc92d
commit
80c2d45d93
@ -448,9 +448,11 @@ uint32_t total_conversion_blocks;
|
||||
|
||||
|
||||
int32_t gyro_error;
|
||||
int16_t gyro[3];
|
||||
int16_t gyro[4];
|
||||
int16_t mag[3];
|
||||
float altitude;
|
||||
int32_t pressure;
|
||||
|
||||
int main()
|
||||
{
|
||||
gps_data.quality = -1;
|
||||
@ -481,18 +483,26 @@ int main()
|
||||
//if(PIOS_BMA180_Test() != 0)
|
||||
// panic(2);
|
||||
|
||||
//if(PIOS_HMC5883_Test() != 0)
|
||||
// panic(3);
|
||||
if(PIOS_HMC5883_Test() != 0)
|
||||
panic(3);
|
||||
|
||||
//if(PIOS_BMP085_Test() != 0)
|
||||
// panic(4);
|
||||
if(PIOS_BMP085_Test() != 0)
|
||||
panic(4);
|
||||
|
||||
uint32_t count = 500;
|
||||
while(count--) {
|
||||
gyro_error = PIOS_IMU3000_ReadGyros(gyro);
|
||||
// if(PIOS_HMC5883_NewDataAvailable())
|
||||
// PIOS_HMC5883_ReadMag(mag);
|
||||
// pressure = PIOS_BMP085_GetPressure();
|
||||
// Update the pressure data
|
||||
PIOS_BMP085_StartADC(PressureConv);
|
||||
PIOS_DELAY_WaitmS(50);
|
||||
if(PIOS_BMP085_ReadADC() == 0) {
|
||||
pressure = PIOS_BMP085_GetPressure();
|
||||
altitude = 44330.0 * (1.0 - powf((float) pressure / BMP085_P0, (1.0 / 5.255)));
|
||||
}
|
||||
|
||||
PIOS_IMU3000_ReadGyros(gyro);
|
||||
PIOS_DELAY_WaitmS(50);
|
||||
|
||||
PIOS_HMC5883_ReadMag(mag);
|
||||
PIOS_DELAY_WaitmS(50);
|
||||
}
|
||||
|
||||
|
@ -663,8 +663,8 @@ static const struct pios_bmp085_cfg pios_bmp085_cfg = {
|
||||
},
|
||||
},
|
||||
.eoc_exti = {
|
||||
// .pin_source = GPIO_PinSource2,
|
||||
// .port_source = GPIO_PortSourceGPIOC,
|
||||
.pin_source = EXTI_PinSource2,
|
||||
.port_source = EXTI_PortSourceGPIOC,
|
||||
.init = {
|
||||
.EXTI_Line = EXTI_Line2, // matches above GPIO pin
|
||||
.EXTI_Mode = EXTI_Mode_Interrupt,
|
||||
@ -674,7 +674,7 @@ static const struct pios_bmp085_cfg pios_bmp085_cfg = {
|
||||
},
|
||||
.eoc_irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = EXTI15_10_IRQn,
|
||||
.NVIC_IRQChannel = EXTI2_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
@ -745,8 +745,8 @@ void PIOS_Board_Init(void) {
|
||||
/*PIOS_BMA180_Attach(pios_spi_accel_id);
|
||||
PIOS_BMA180_Init(&pios_bma180_cfg);*/
|
||||
PIOS_IMU3000_Init(&pios_imu3000_cfg);
|
||||
/*PIOS_HMC5883_Init(&pios_hmc5883_cfg);
|
||||
PIOS_BMP085_Init(&pios_bmp085_cfg);*/
|
||||
PIOS_HMC5883_Init(&pios_hmc5883_cfg);
|
||||
PIOS_BMP085_Init(&pios_bmp085_cfg);
|
||||
|
||||
|
||||
/* Set up the SPI interface to the OP board */
|
||||
|
@ -54,6 +54,8 @@ static const struct pios_bma180_cfg * dev_cfg;
|
||||
*/
|
||||
void PIOS_BMA180_Init(const struct pios_bma180_cfg * cfg)
|
||||
{
|
||||
dev_cfg = cfg; // store config before enabling interrupt
|
||||
|
||||
fifoBuf_init(&pios_bma180_fifo, (uint8_t *) pios_bma180_buffer, sizeof(pios_bma180_buffer));
|
||||
|
||||
/* Configure EOC pin as input floating */
|
||||
@ -73,8 +75,6 @@ void PIOS_BMA180_Init(const struct pios_bma180_cfg * cfg)
|
||||
PIOS_BMA180_SetRange(BMA_RANGE_8G);
|
||||
PIOS_DELAY_WaituS(50);
|
||||
PIOS_BMA180_EnableIrq();
|
||||
|
||||
dev_cfg = cfg;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -339,9 +339,9 @@ void PIOS_BMA180_IRQHandler(void)
|
||||
*/
|
||||
void EXTI4_IRQHandler(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(EXTI_Line4) != RESET) {
|
||||
if (EXTI_GetITStatus(dev_cfg->eoc_exti.init.EXTI_Line) != RESET) {
|
||||
PIOS_BMA180_IRQHandler();
|
||||
EXTI_ClearITPendingBit(EXTI_Line4);
|
||||
EXTI_ClearITPendingBit(dev_cfg->eoc_exti.init.EXTI_Line);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,22 +63,18 @@ static int32_t PIOS_BMP085_Write(uint8_t address, uint8_t buffer);
|
||||
|
||||
// Move into proper driver structure with cfg stored
|
||||
static uint32_t oversampling;
|
||||
const struct pios_bmp085_cfg * dev_cfg;
|
||||
static const struct pios_bmp085_cfg * dev_cfg;
|
||||
|
||||
/**
|
||||
* Initialise the BMP085 sensor
|
||||
*/
|
||||
void PIOS_BMP085_Init(const struct pios_bmp085_cfg * cfg)
|
||||
{
|
||||
#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
|
||||
|
||||
oversampling = cfg->oversampling;
|
||||
dev_cfg = cfg; // Store cfg before enabling interrupt
|
||||
|
||||
/* Configure EOC pin as input floating */
|
||||
GPIO_Init(cfg->drdy.gpio, &cfg->drdy.init);
|
||||
|
||||
@ -89,17 +85,10 @@ void PIOS_BMP085_Init(const struct pios_bmp085_cfg * cfg)
|
||||
/* Enable and set EOC EXTI Interrupt to the lowest priority */
|
||||
NVIC_Init(&cfg->eoc_irq.init);
|
||||
|
||||
oversampling = cfg->oversampling;
|
||||
dev_cfg = cfg;
|
||||
/* Configure anothing GPIO pin pin as output to set address */
|
||||
GPIO_Init(cfg->xclr.gpio, &cfg->xclr.init);
|
||||
GPIO_SetBits(cfg->xclr.gpio,cfg->xclr.init.GPIO_Pin);
|
||||
|
||||
/* Configure anothing GPIO pin pin as input floating */
|
||||
/* WHAT DID THIS DO?
|
||||
GPIO_Init(cfg->drdy.gpio, &cfg->drdy.init);
|
||||
|
||||
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) != 0)
|
||||
@ -126,10 +115,13 @@ void PIOS_BMP085_Init(const struct pios_bmp085_cfg * cfg)
|
||||
/**
|
||||
* Start the ADC conversion
|
||||
* \param[in] PresOrTemp BMP085_PRES_ADDR or BMP085_TEMP_ADDR
|
||||
* \return Raw ADC value
|
||||
* \return 0 for success, -1 for failure (conversion completed and not read)
|
||||
*/
|
||||
void PIOS_BMP085_StartADC(ConversionTypeTypeDef Type)
|
||||
int32_t PIOS_BMP085_StartADC(ConversionTypeTypeDef Type)
|
||||
{
|
||||
if(PIOS_BMP085_EOC)
|
||||
return -1;
|
||||
|
||||
/* Start the conversion */
|
||||
if (Type == TemperatureConv) {
|
||||
while (PIOS_BMP085_Write(BMP085_CTRL_ADDR, BMP085_TEMP_ADDR) != 0)
|
||||
@ -140,25 +132,33 @@ void PIOS_BMP085_StartADC(ConversionTypeTypeDef Type)
|
||||
}
|
||||
|
||||
CurrentRead = Type;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the ADC conversion value (once ADC conversion has completed)
|
||||
* \param[in] PresOrTemp BMP085_PRES_ADDR or BMP085_TEMP_ADDR
|
||||
* \return Raw ADC value
|
||||
* \return 0 if successfully read the ADC, -1 if failed
|
||||
*/
|
||||
void PIOS_BMP085_ReadADC(void)
|
||||
int32_t PIOS_BMP085_ReadADC(void)
|
||||
{
|
||||
uint8_t Data[3];
|
||||
Data[0] = 0;
|
||||
Data[1] = 0;
|
||||
Data[2] = 0;
|
||||
|
||||
|
||||
if(!PIOS_BMP085_EOC)
|
||||
return -1;
|
||||
|
||||
PIOS_BMP085_EOC = 0;
|
||||
|
||||
/* Read and store the 16bit result */
|
||||
if (CurrentRead == TemperatureConv) {
|
||||
/* Read the temperature conversion */
|
||||
while (PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 2) != 0)
|
||||
continue;
|
||||
if (PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 2) != 0)
|
||||
return -1;
|
||||
|
||||
RawTemperature = ((Data[0] << 8) | Data[1]);
|
||||
|
||||
X1 = (RawTemperature - CalibData.AC6) * CalibData.AC5 >> 15;
|
||||
@ -167,8 +167,8 @@ void PIOS_BMP085_ReadADC(void)
|
||||
Temperature = (B5 + 8) >> 4;
|
||||
} else {
|
||||
/* Read the pressure conversion */
|
||||
while (PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 3) != 0)
|
||||
continue;
|
||||
if (PIOS_BMP085_Read(BMP085_ADC_MSB, Data, 3) != 0)
|
||||
return -1;
|
||||
RawPressure = ((Data[0] << 16) | (Data[1] << 8) | Data[2]) >> (8 - oversampling);
|
||||
|
||||
B6 = B5 - 4000;
|
||||
@ -188,6 +188,7 @@ void PIOS_BMP085_ReadADC(void)
|
||||
X2 = (-7357 * P) >> 16;
|
||||
Pressure = P + ((X1 + X2 + 3791) >> 4);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int16_t PIOS_BMP085_GetTemperature(void)
|
||||
@ -294,14 +295,17 @@ int32_t PIOS_BMP085_Test()
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle external lines 15 to 10 interrupt requests
|
||||
* Handle external line 2 interrupt requests
|
||||
*/
|
||||
void EXTI15_10_IRQHandler(void)
|
||||
uint32_t bmp_eocs = 0;
|
||||
void EXTI2_IRQHandler(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(dev_cfg->eoc_exti.init.EXTI_Line) != RESET) {
|
||||
/* Read the ADC Value */
|
||||
PIOS_BMP085_EOC=1;
|
||||
|
||||
bmp_eocs++;
|
||||
|
||||
/* Clear the EXTI line pending bit */
|
||||
EXTI_ClearITPendingBit(dev_cfg->eoc_exti.init.EXTI_Line);
|
||||
}
|
||||
|
@ -59,6 +59,8 @@ static const struct pios_hmc5883_cfg * dev_cfg;
|
||||
*/
|
||||
void PIOS_HMC5883_Init(const struct pios_hmc5883_cfg * cfg)
|
||||
{
|
||||
dev_cfg = cfg; // store config before enabling interrupt
|
||||
|
||||
/* Configure EOC pin as input floating */
|
||||
GPIO_Init(cfg->drdy.gpio, &cfg->drdy.init);
|
||||
|
||||
@ -80,8 +82,6 @@ void PIOS_HMC5883_Init(const struct pios_hmc5883_cfg * cfg)
|
||||
PIOS_Assert(val == 0);
|
||||
|
||||
pios_hmc5883_data_ready = false;
|
||||
|
||||
dev_cfg = cfg;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,8 +82,8 @@ struct pios_bmp085_cfg {
|
||||
|
||||
/* Public Functions */
|
||||
extern void PIOS_BMP085_Init(const struct pios_bmp085_cfg * cfg);
|
||||
extern void PIOS_BMP085_StartADC(ConversionTypeTypeDef Type);
|
||||
extern void PIOS_BMP085_ReadADC(void);
|
||||
extern int32_t PIOS_BMP085_StartADC(ConversionTypeTypeDef Type);
|
||||
extern int32_t PIOS_BMP085_ReadADC(void);
|
||||
extern int16_t PIOS_BMP085_GetTemperature(void);
|
||||
extern int32_t PIOS_BMP085_GetPressure(void);
|
||||
extern int32_t PIOS_BMP085_Test();
|
||||
|
Loading…
x
Reference in New Issue
Block a user