Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
baro_board.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2013 Gautier Hattenberger (ENAC)
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 */
22 
29 #include "std.h"
31 #include "peripherals/mpl3115.h"
32 
33 // to get MPU status
35 
36 #include "subsystems/abi.h"
37 #include "led.h"
38 
43 #ifndef BARO_BOARD_APOGEE_FREQ
44 #define BARO_BOARD_APOGEE_FREQ 5
45 #endif
46 
51 #ifdef BARO_PERIODIC_FREQUENCY
52 #define MPL_PRESCALER ((BARO_PERIODIC_FREQUENCY)/BARO_BOARD_APOGEE_FREQ)
53 #else
54 #ifdef PERIODIC_FREQUENCY
55 #define MPL_PRESCALER ((PERIODIC_FREQUENCY)/BARO_BOARD_APOGEE_FREQ)
56 #else
57 // default: assuming 60Hz for a 5Hz baro update
58 #define MPL_PRESCALER 12
59 #endif
60 #endif
61 
63 #define BARO_STARTUP_COUNTER (200/(MPL_PRESCALER))
65 
67 
68 void baro_init(void)
69 {
71 #ifdef BARO_LED
72  LED_OFF(BARO_LED);
73 #endif
75 }
76 
77 void baro_periodic(void)
78 {
79 
80  // Baro is slave of the MPU, only start reading it after MPU is configured
82 
84  // Run some loops to get correct readings from the adc
85  --startup_cnt;
87 #ifdef BARO_LED
88  LED_TOGGLE(BARO_LED);
89  if (startup_cnt == 0) {
90  LED_ON(BARO_LED);
91  }
92 #endif
93  }
94  // Read the sensor
96  }
97 }
98 
100 {
102  if (apogee_baro.data_available && startup_cnt == 0) {
103  float pressure = ((float)apogee_baro.pressure / (1 << 2));
104  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, pressure);
105  float temp = apogee_baro.temperature / 16.0f;
106  AbiSendMsgTEMPERATURE(BARO_BOARD_SENDER_ID, temp);
108  }
109 }
110 
struct Mpu60x0_I2c mpu
Definition: imu_apogee.h:98
unsigned short uint16_t
Definition: types.h:16
uint16_t startup_cnt
Definition: baro_board.c:64
Driver for the IMU on the Apogee board.
Common barometric sensor implementation.
struct Mpl3115 apogee_baro
Definition: baro_board.c:66
struct Mpu60x0Config config
Definition: mpu60x0_i2c.h:68
void mpl3115_init(struct Mpl3115 *mpl, struct i2c_periph *i2c_p, uint8_t addr)
Definition: mpl3115.c:31
#define MPL_PRESCALER
Baro periodic prescaler.
Definition: baro_board.c:58
Main include for ABI (AirBorneInterface).
void mpl3115_event(struct Mpl3115 *mpl)
Definition: mpl3115.c:107
void baro_init(void)
Definition: baro_board.c:68
#define BARO_STARTUP_COUNTER
Counter to init ads1114 at startup.
Definition: baro_board.c:63
#define FALSE
Definition: std.h:5
void baro_periodic(void)
Definition: baro_board.c:77
void mpl3115_periodic(struct Mpl3115 *mpl)
Definition: mpl3115.c:153
#define LED_TOGGLE(i)
Definition: led_hw.h:44
#define MPL3115_I2C_ADDR
Definition: mpl3115.h:35
uint32_t pressure
pressure in 1/4 Pascal
Definition: mpl3115.h:80
bool_t initialized
config done flag
Definition: mpu60x0.h:82
#define BARO_BOARD_SENDER_ID
default onboard baro
Driver for the baro MPL3115A2 from Freescale (i2c)
void apogee_baro_event(void)
Definition: baro_board.c:99
int16_t temperature
temperature in 1/16 degrees Celcius
Definition: mpl3115.h:79
#define LED_ON(i)
Definition: led_hw.h:42
arch independent LED (Light Emitting Diodes) API
#define LED_OFF(i)
Definition: led_hw.h:43
volatile bool_t data_available
data ready flag
Definition: mpl3115.h:76
struct ImuApogee imu_apogee
Definition: imu_apogee.c:69