Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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 ) {
70 #ifdef BARO_LED
71  LED_OFF(BARO_LED);
72 #endif
74 }
75 
76 void baro_periodic( void ) {
77 
78  // Baro is slave of the MPU, only start reading it after MPU is configured
80 
82  // Run some loops to get correct readings from the adc
83  --startup_cnt;
85 #ifdef BARO_LED
86  LED_TOGGLE(BARO_LED);
87  if (startup_cnt == 0) {
88  LED_ON(BARO_LED);
89  }
90 #endif
91  }
92  // Read the sensor
94  }
95 }
96 
97 void apogee_baro_event(void) {
100  float pressure = ((float)apogee_baro.pressure/(1<<2));
101  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, &pressure);
103  }
104 }
105 
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
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
#define LED_ON(i)
Definition: led_hw.h:28
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: imu_chimu.h:141
void baro_periodic(void)
Definition: baro_board.c:76
void mpl3115_periodic(struct Mpl3115 *mpl)
Definition: mpl3115.c:157
#define MPL3115_I2C_ADDR
Definition: mpl3115.h:35
volatile bool_t data_available
data ready flag
Definition: mpl3115.h:76
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)
#define LED_TOGGLE(i)
Definition: led_hw.h:30
void apogee_baro_event(void)
Definition: baro_board.c:97
struct Mpu60x0Config config
Definition: mpu60x0_i2c.h:67
#define LED_OFF(i)
Definition: led_hw.h:29
arch independent LED (Light Emitting Diodes) API
struct Mpu60x0_I2c mpu
Definition: imu_apogee.h:100
struct ImuApogee imu_apogee
Definition: imu_apogee.c:59