Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
baro_board_ms5611_spi.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011-2013 The Paparazzi Team
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 
31 #include "peripherals/ms5611_spi.h"
32 
33 #include "mcu_periph/sys_time.h"
34 #include "led.h"
35 #include "std.h"
36 #include "subsystems/abi.h"
37 
38 #include "mcu_periph/uart.h"
39 #include "pprzlink/messages.h"
41 
42 #include "filters/median_filter.h"
43 
44 #if BARO_PERIODIC_FREQUENCY > 100
45 #error "For MS5611 BARO_PERIODIC_FREQUENCY has to be <= 100"
46 #endif
47 
48 PRINT_CONFIG_VAR(BB_MS5611_SLAVE_IDX)
49 PRINT_CONFIG_VAR(BB_MS5611_SPI_DEV)
50 
51 #ifndef BB_MS5611_TYPE_MS5607
53 #define BB_MS5611_TYPE_MS5607 FALSE
54 #endif
55 
58 
59 void baro_init(void)
60 {
61  ms5611_spi_init(&bb_ms5611, &BB_MS5611_SPI_DEV, BB_MS5611_SLAVE_IDX, BB_MS5611_TYPE_MS5607);
62 
63 #ifdef BARO_LED
64  LED_OFF(BARO_LED);
65 #endif
66 
68 }
69 
70 void baro_periodic(void)
71 {
72  if (sys_time.nb_sec > 1) {
73 
74  /* call the convenience periodic that initializes the sensor and starts reading*/
76 
77 #if DEBUG
79  RunOnceEvery((50 * 30), DOWNLINK_SEND_MS5611_COEFF(DefaultChannel, DefaultDevice,
80  &bb_ms5611.data.c[0],
81  &bb_ms5611.data.c[1],
82  &bb_ms5611.data.c[2],
83  &bb_ms5611.data.c[3],
84  &bb_ms5611.data.c[4],
85  &bb_ms5611.data.c[5],
86  &bb_ms5611.data.c[6],
87  &bb_ms5611.data.c[7]));
88 #endif
89  }
90 }
91 
92 void baro_event(void)
93 {
94  if (sys_time.nb_sec > 1) {
96 
98  uint32_t now_ts = get_sys_time_usec();
99  float pressure = update_median_filter_f(&bb_ms5611_filt, (float)bb_ms5611.data.pressure);
100  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, now_ts, pressure);
101  float temp = bb_ms5611.data.temperature / 100.0f;
102  AbiSendMsgTEMPERATURE(BARO_BOARD_SENDER_ID, temp);
103  bb_ms5611.data_available = false;
104 
105 #ifdef BARO_LED
106  RunOnceEvery(10, LED_TOGGLE(BARO_LED));
107 #endif
108 
109 #if DEBUG
110  float fbaroms = bb_ms5611.data.pressure / 100.;
111  DOWNLINK_SEND_BARO_MS5611(DefaultChannel, DefaultDevice,
113  &fbaroms, &temp);
114 #endif
115  }
116  }
117 }
BARO_BOARD_SENDER_ID
#define BARO_BOARD_SENDER_ID
default onboard baro
Definition: abi_sender_ids.h:33
Ms5611Data::temperature
int32_t temperature
temperature with 0.01 degrees Celsius resolution
Definition: ms5611.h:53
LED_OFF
#define LED_OFF(i)
Definition: led_hw.h:52
abi.h
uint32_t
unsigned long uint32_t
Definition: types.h:18
bb_ms5611_filt
struct MedianFilterFloat bb_ms5611_filt
Definition: baro_board_ms5611_spi.c:57
ms5611_spi.h
Ms5611Data::d2
uint32_t d2
Definition: ms5611.h:56
Ms5611_Spi
Definition: ms5611_spi.h:36
LED_TOGGLE
#define LED_TOGGLE(i)
Definition: led_hw.h:53
update_median_filter_f
static float update_median_filter_f(struct MedianFilterFloat *filter, float new_data)
Definition: median_filter.h:175
baro_event
void baro_event(void)
Definition: baro_board_ms5611_spi.c:92
Ms5611_Spi::data_available
volatile bool data_available
data ready flag
Definition: ms5611_spi.h:44
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
std.h
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
fbaroms
float fbaroms
Definition: baro_ms5611_i2c.c:51
Ms5611_Spi::initialized
bool initialized
config done flag
Definition: ms5611_spi.h:43
sys_time.h
Architecture independent timing functions.
bb_ms5611
struct Ms5611_Spi bb_ms5611
Definition: baro_board_ms5611_spi.c:56
led.h
arch independent LED (Light Emitting Diodes) API
median_filter.h
ms5611_spi_periodic
static void ms5611_spi_periodic(struct Ms5611_Spi *ms)
convenience function
Definition: ms5611_spi.h:71
baro.h
MedianFilterFloat
Definition: median_filter.h:142
baro_init
void baro_init(void)
Definition: baro_board_ms5611_spi.c:59
sys_time
Definition: sys_time.h:71
baro_periodic
void baro_periodic(void)
Definition: baro_board_ms5611_spi.c:70
init_median_filter_f
static void init_median_filter_f(struct MedianFilterFloat *filter, uint8_t size)
Definition: median_filter.h:148
sys_time::nb_sec
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
ms5611_spi_event
void ms5611_spi_event(struct Ms5611_Spi *ms)
Definition: ms5611_spi.c:133
BB_MS5611_TYPE_MS5607
#define BB_MS5611_TYPE_MS5607
set to TRUE if baro is actually a MS5607
Definition: baro_board_ms5611_spi.c:53
Ms5611Data::pressure
uint32_t pressure
pressure in Pascal (0.01mbar)
Definition: ms5611.h:52
Ms5611Data::d1
uint32_t d1
Definition: ms5611.h:55
Ms5611Data::c
uint16_t c[PROM_NB]
Definition: ms5611.h:54
Ms5611_Spi::data
struct Ms5611Data data
Definition: ms5611_spi.h:45
ms5611_spi_init
void ms5611_spi_init(struct Ms5611_Spi *ms, struct spi_periph *spi_p, uint8_t slave_idx, bool is_ms5607)
Definition: ms5611_spi.c:33