Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
utilities.c File Reference

Implementation of low-level hardware drivers and utility functions. More...

#include "utilities.h"
#include <math.h>
Include dependency graph for utilities.c:

Go to the source code of this file.

Functions

int32_t imuP_write (void *handle, uint8_t reg_addr, const uint8_t *buf, uint16_t len)
 SPI write function for the primary IMU (LSM6DSO32).
 
int32_t imuP_read (void *handle, uint8_t reg_addr, uint8_t *buf, uint16_t len)
 SPI read function for the primary IMU (LSM6DSO32).
 
int32_t imuP_read_2 (void *handle, uint8_t reg_addr, uint8_t *buf, uint16_t len)
 SPI read function for the primary IMU (LSM6DSO32).
 
int8_t bmp390_P_write (uint8_t reg_addr, const uint8_t *buf, uint32_t len, void *intf_ptr)
 SPI write function for the primary Barometer (bmp390).
 
int8_t bmp390_P_read (uint8_t reg_addr, uint8_t *buf, uint32_t len, void *intf_ptr)
 SPI read function for the primary Barometer (bmp390).
 
static void bmp390_delay_us (uint32_t period, void *intf_ptr)
 
static int8_t bmp3_P_spi_init (struct bmp3_dev *dev)
 
int8_t init_imup (stmdev_ctx_t *imu, lsm6dso32_fs_xl_t acc_full_scale, lsm6dso32_fs_g_t gyro_full_scale, lsm6dso32_odr_xl_t acc_output_data_rate, lsm6dso32_odr_g_t gyro_output_data_rate)
 Initializes the primary IMU (LSM6DSO32).
 
int8_t init_bmp390_p (struct bmp3_dev *bmp390)
 Initializes the primary barometer (BMP390).
 
uint16_t compute_air_density (float_t temperature, float_t pressure)
 
int8_t calibrateIMU (stmdev_ctx_t *imu, uint16_t iterationNum, OFFSET_TYPE type)
 Calibrates the IMU by calculating sensor offsets.
 
int32_t imuB_write (void *handle, uint8_t reg_addr, const uint8_t *buf, uint16_t len)
 SPI write function for the backup IMU (LSM6DSO32).
 
int32_t imuB_read (void *handle, uint8_t reg_addr, uint8_t *buf, uint16_t len)
 SPI read function for the backup IMU (LSM6DSO32).
 
int8_t bmp390_B_write (uint8_t reg_addr, const uint8_t *buf, uint32_t len, void *intf_ptr)
 SPI write function for the backup Barometer (bmp390).
 
int8_t bmp390_B_read (uint8_t reg_addr, uint8_t *buf, uint32_t len, void *intf_ptr)
 SPI read function for the backup Barometer (bmp390).
 
static int8_t bmp3_B_spi_init (struct bmp3_dev *dev)
 
int8_t init_imuB (stmdev_ctx_t *imu, lsm6dso32_fs_xl_t acc_full_scale, lsm6dso32_fs_g_t gyro_full_scale, lsm6dso32_odr_xl_t acc_output_data_rate, lsm6dso32_odr_g_t gyro_output_data_rate)
 Initializes the backup IMU (LSM6DSO32).
 
int8_t init_bmp390_B (struct bmp3_dev *bmp390)
 Initializes the backup barometer (BMP390).
 
float_t readAltitude (float_t seaLevelPa, float_t seaLevelT, float_t currentPa)
 Calculates altitude based on the barometric formula.
 

Variables

SPI_HandleTypeDef hspi1
 
SPI_HandleTypeDef hspi2
 
SPI_HandleTypeDef hspi3
 
static uint8_t bmp390_p_addr = 0
 
static uint8_t bmp390_B_addr = 0
 

Detailed Description

Implementation of low-level hardware drivers and utility functions.

Author
Tommaso Gualtierotti & Francesco Abate
See also
utilities.h for function prototypes and high-level documentation.

Definition in file utilities.c.

Function Documentation

◆ bmp390_delay_us()

static void bmp390_delay_us ( uint32_t  period,
void *  intf_ptr 
)
static

Definition at line 163 of file utilities.c.

163 {
164 uint32_t i;
165
166 while (period--) {
167 for (i = 0; i < 96; i++) {
168 ;
169 }
170 }
171}

Referenced by bmp3_B_spi_init(), and bmp3_P_spi_init().

Here is the caller graph for this function:

◆ bmp3_B_spi_init()

static int8_t bmp3_B_spi_init ( struct bmp3_dev dev)
static

Definition at line 647 of file utilities.c.

647 {
648 int8_t result = BMP3_OK;
649
650 if (dev != NULL) {
651 bmp390_B_addr = 0;
652 dev -> read = bmp390_B_read;
653 dev -> write = bmp390_B_write;
654 dev -> intf = BMP3_SPI_INTF;
655
656 dev -> delay_us = bmp390_delay_us;
657 dev -> intf_ptr = &bmp390_B_addr;
658 } else {
659 result = -1;
660 }
661
662 return result;
663}
#define NULL
Definition bmp3_defs.h:88
@ BMP3_SPI_INTF
Definition bmp3_defs.h:505
#define BMP3_OK
Definition bmp3_defs.h:258
int8_t bmp390_B_read(uint8_t reg_addr, uint8_t *buf, uint32_t len, void *intf_ptr)
SPI read function for the backup Barometer (bmp390).
Definition utilities.c:623
int8_t bmp390_B_write(uint8_t reg_addr, const uint8_t *buf, uint32_t len, void *intf_ptr)
SPI write function for the backup Barometer (bmp390).
Definition utilities.c:603
static void bmp390_delay_us(uint32_t period, void *intf_ptr)
Definition utilities.c:163
static uint8_t bmp390_B_addr
Definition utilities.c:30

References bmp390_B_addr, bmp390_B_read(), bmp390_B_write(), bmp390_delay_us(), BMP3_OK, BMP3_SPI_INTF, and NULL.

Referenced by init_bmp390_B().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bmp3_P_spi_init()

static int8_t bmp3_P_spi_init ( struct bmp3_dev dev)
static

Definition at line 173 of file utilities.c.

173 {
174 int8_t result = BMP3_OK;
175
176 if (dev != NULL) {
177 bmp390_p_addr = 0;
178 dev -> read = bmp390_P_read;
179 dev -> write = bmp390_P_write;
180 dev -> intf = BMP3_SPI_INTF;
181
182 dev -> delay_us = bmp390_delay_us;
183 dev -> intf_ptr = &bmp390_p_addr;
184 } else {
185 result = -1;
186 }
187
188 return result;
189}
int8_t bmp390_P_read(uint8_t reg_addr, uint8_t *buf, uint32_t len, void *intf_ptr)
SPI read function for the primary Barometer (bmp390).
Definition utilities.c:122
int8_t bmp390_P_write(uint8_t reg_addr, const uint8_t *buf, uint32_t len, void *intf_ptr)
SPI write function for the primary Barometer (bmp390).
Definition utilities.c:103
static uint8_t bmp390_p_addr
Definition utilities.c:29

References bmp390_delay_us(), bmp390_p_addr, bmp390_P_read(), bmp390_P_write(), BMP3_OK, BMP3_SPI_INTF, and NULL.

Referenced by init_bmp390_p().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compute_air_density()

uint16_t compute_air_density ( float_t  temperature,
float_t  pressure 
)

Definition at line 319 of file utilities.c.

319 {
320 uint16_t air_d;
321
322 air_d = (uint16_t) pressure/(temperature*SPECIFIC_GAS_CONSTANT);
323 return air_d;
324}
#define SPECIFIC_GAS_CONSTANT
Definition utilities.h:51

References SPECIFIC_GAS_CONSTANT.

◆ readAltitude()

float_t readAltitude ( float_t  seaLevelPa,
float_t  seaLevelT,
float_t  currentPa 
)

Calculates altitude based on the barometric formula.

This function estimates the altitude in meters above sea level using the international barometric formula. It requires the current pressure, sea level pressure, and sea level temperature as inputs.

Parameters
[in]seaLevelPaThe reference pressure at sea level in Pascals (Pa).
[in]seaLevelTThe standard temperature at sea level in Kelvin (K).
[in]currentPaThe current atmospheric pressure measured by the sensor in Pascals (Pa).
Returns
The calculated altitude in meters (m).
Note
This calculation relies on several physical constants which must be defined elsewhere in the code:
  • GCONST: Standard gravity (~9.80665 m/s^2)
  • RAST: Specific gas constant for dry air (~287.058 J/(kg·K))
  • TAU: Standard temperature lapse rate (~0.0065 K/m)

Definition at line 780 of file utilities.c.

780 {
781 float_t altitude;
782
783
784 altitude = (seaLevelT/TAU)*(1-pow(currentPa/seaLevelPa,RAST*TAU/GCONST));
785
786 return altitude;
787}
#define TAU
Standard temperature lapse rate in K/m.
#define RAST
Specific gas constant for dry air in J/(kg·K).
#define GCONST
Standard gravity in m/s^2.
float_t altitude
Definition main.c:224

References altitude, GCONST, RAST, and TAU.

Referenced by StartSensor_Task().

Here is the caller graph for this function:

Variable Documentation

◆ bmp390_B_addr

uint8_t bmp390_B_addr = 0
static

Definition at line 30 of file utilities.c.

Referenced by bmp3_B_spi_init().

◆ bmp390_p_addr

uint8_t bmp390_p_addr = 0
static

Definition at line 29 of file utilities.c.

Referenced by bmp3_P_spi_init().

◆ hspi1

SPI_HandleTypeDef hspi1
extern

Definition at line 61 of file main.c.

Referenced by MX_SPI1_Init().

◆ hspi2

SPI_HandleTypeDef hspi2
extern

Definition at line 62 of file main.c.

Referenced by bmp390_P_read(), bmp390_P_write(), imuP_read(), imuP_read_2(), imuP_write(), and init_imup().

◆ hspi3

SPI_HandleTypeDef hspi3
extern

Definition at line 63 of file main.c.

Referenced by bmp390_B_read(), bmp390_B_write(), imuB_read(), imuB_write(), and init_imuB().