Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
baro_board.h
Go to the documentation of this file.
1 
2 /*
3  * board specific fonctions for the lisa_m board
4  *
5  */
6 
7 #ifndef BOARDS_LISA_M_BARO_H
8 #define BOARDS_LISA_M_BARO_H
9 
10 #include "std.h"
11 #include "mcu_periph/i2c.h"
12 
13 // absolute addr
14 #define BMP085_ADDR 0xEE
15 // Over sample setting (0-3)
16 #define BMP085_OSS 3
17 
26 };
27 
28 struct BaroBoard {
30 };
31 
33  // These values come from EEPROM on sensor
45 
46  // These values are calculated
48 };
49 
50 extern struct BaroBoard baro_board;
51 extern struct i2c_transaction baro_trans;
53 
54 extern void baro_board_send_reset(void);
55 extern void baro_board_send_config(void);
56 
57 // Apply temp calibration and sensor calibration to raw measurement to get Pa (from BMP085 datasheet)
59 {
60  int32_t b6 = calibration.b5 - 4000;
61  int x1 = (calibration.b2 * (b6 * b6 >> 12)) >> 11;
62  int x2 = calibration.ac2 * b6 >> 11;
63  int32_t x3 = x1 + x2;
64  int32_t b3 = (((calibration.ac1 * 4 + x3) << BMP085_OSS) + 2)/4;
65  x1 = calibration.ac3 * b6 >> 13;
66  x2 = (calibration.b1 * (b6 * b6 >> 12)) >> 16;
67  x3 = ((x1 + x2) + 2) >> 2;
68  uint32_t b4 = (calibration.ac4 * (uint32_t) (x3 + 32768)) >> 15;
69  uint32_t b7 = (raw - b3) * (50000 >> BMP085_OSS);
70  int32_t p = b7 < 0x80000000 ? (b7 * 2) / b4 : (b7 / b4) * 2;
71  x1 = (p >> 8) * (p >> 8);
72  x1 = (x1 * 3038) >> 16;
73  x2 = (-7357 * p) >> 16;
74  return p + ((x1 + x2 + 3791) >> 4);
75 }
76 
77 static inline void baro_event(void (*b_abs_handler)(void), void (*b_diff_handler)(void))
78 {
79  if (baro_board.status == LBS_READING &&
83  int32_t tmp = (baro_trans.buf[0]<<16) | (baro_trans.buf[1] << 8) | baro_trans.buf[2];
84  tmp = tmp >> (8 - BMP085_OSS);
86  b_abs_handler();
87  }
88  }
93  // abuse differential to store temp in 0.1C for now
94  int32_t tmp = (baro_trans.buf[0] << 8) | baro_trans.buf[1];
95  int32_t x1 = ((tmp - calibration.ac6) * calibration.ac5) >> 15;
96  int32_t x2 = (calibration.mc << 11) / (x1 + calibration.md);
97  calibration.b5 = x1 + x2;
98  baro.differential = (calibration.b5 + 8) >> 4;
99  b_diff_handler();
100  }
101  }
102 }
103 
104 #define BaroEvent(_b_abs_handler, _b_diff_handler) baro_event(_b_abs_handler,_b_diff_handler)
105 
106 #endif /* BOARDS_LISA_M_BARO_H */
#define BMP085_OSS
Definition: baro_board.h:16
unsigned short uint16_t
Definition: types.h:16
LisaBaroStatus
Definition: baro_board.h:13
static void baro_event(void(*b_abs_handler)(void), void(*b_diff_handler)(void))
Definition: baro_board.h:77
void baro_board_send_config(void)
struct BaroBoard baro_board
Definition: baro_board.c:35
int32_t absolute
Definition: baro.h:42
struct Baro baro
Definition: baro_board.c:34
void baro_board_send_reset(void)
Definition: baro_board.c:84
int32_t differential
Definition: baro.h:43
unsigned long uint32_t
Definition: types.h:18
signed short int16_t
Definition: types.h:17
enum I2CTransactionStatus status
Definition: i2c.h:47
static int32_t baro_apply_calibration(int32_t raw)
Definition: baro_board.h:58
signed long int32_t
Definition: types.h:19
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
struct i2c_transaction baro_trans
Definition: baro_board.c:6
enum LisaBaroStatus status
Definition: baro_board.h:28
struct bmp085_baro_calibration calibration
Definition: baro_board.c:8