#include "spp/services/bmp390/bmp390.h"#include "spp/hal/spi/spi.h"#include "spp/hal/time/time.h"#include "spp/services/log/log.h"#include "spp/services/databank/databank.h"#include "spp/core/packet.h"#include "spp/core/pubsub/pubsub.h"#include "spp/services/fsm/fsm.h"#include <string.h>#include <math.h>Go to the source code of this file.
Macros | |
| #define | K_BMP390_TASK_TIMEOUT_MS 5000U |
| #define | K_BMP390_TAG "BMP390" |
| #define | K_BMP390_PERFORMANCE_SAMPLES (10000U) |
Functions | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_init (void) |
| BMP390 sensor instance initialisation. This function is called by the service task. It is responsible for initialising the SPI bus, the GPIO ISR, and the sensor driver. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_acquireData (SPP_Kpid_t kpid) |
| Acquisition callback invoked by the SPP service task on each cycle. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_softReset (void *p_spiHandler) |
| Sends a soft-reset command to the sensor and waits 100 ms for it to reboot. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_enableSpiMode (void *p_spiHandler) |
| Writes the interface-config register to lock the sensor into SPI mode. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_configCheck (void *p_spiHandler) |
| Reads the chip-ID register and returns an error if the value is not 0x60. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_auxConfig (void *p_spiHandler) |
| Resets the sensor, enables SPI mode, and verifies the chip ID. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_prepareMeasure (void *p_spiHandler) |
| Writes OSR, ODR, IIR and power-control registers to start continuous measurements. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_readRawTempCoeffs (void *p_spiHandler, BMP390_temp_calib_t *tcalib) |
| Polls the DRDY flag until set or until the timeout elapses. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_calibrateTempParams (void *p_spiHandler, BMP390_temp_params_t *out) |
| Reads raw temperature coefficients and scales them to floating-point parameters. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_readRawTemp (void *p_spiHandler, uint32_t *raw_temp) |
| Reads the 24-bit raw temperature ADC value from the sensor. | |
| static float | SPP_SERVICES_BMP390_compensateTemperature (spp_uint32_t raw_temp, BMP390_temp_params_t *params) |
| Applies the BMP390 double-quadratic temperature compensation formula. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_auxGetTemp (void *p_spiHandler, const BMP390_temp_params_t *temp_params, spp_uint32_t *raw_temp, float *comp_temp) |
| Reads the raw temperature ADC and returns the compensated value. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_readRawPressCoeffs (void *p_spiHandler, BMP390_press_calib_t *pcalib) |
| Reads raw pressure calibration coefficients from the sensor's NVM registers. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_calibratePressParams (void *p_spiHandler, BMP390_press_params_t *out) |
| Reads raw pressure coefficients and scales them to floating-point parameters. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_readRawPress (void *p_spiHandler, spp_uint32_t *raw_press) |
| Reads the 24-bit raw pressure ADC value from the sensor. | |
| static float | SPP_SERVICES_BMP390_compensatePressure (spp_uint32_t raw_press, float t_lin, BMP390_press_params_t *p) |
| Applies the BMP390 pressure compensation formula using the linearised temperature. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_auxGetPress (void *p_spiHandler, const BMP390_press_params_t *press_params, float t_lin, spp_uint32_t *raw_press, float *comp_press) |
| Reads raw pressure ADC and returns the compensated value in Pa. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_getAltitude (void *p_spiHandler, float *altitude_m, float *pressure_pa, float *temperature_c) |
| Reads compensated altitude, pressure and temperature from the sensor. | |
| static SPP_RetVal_t | SPP_SERVICES_BMP390_intEnableDrdy (void *p_spiHandler) |
| Enables the active-high data-ready interrupt output on the sensor. | |
| const SPP_SERVICE_ProducerContract_t * | SPP_SERVICES_BMP390_getProducerContract (void) |
Variables | |
| static const SPP_SERVICE_ProducerContract_t | g_bmp390ProducerContract |
| static BMP390_t | s_bmpData |
| static const char *const | k_svcTag = "BMP_SVC" |
| static float | s_pd1 |
| static float | s_pd2 |
| static float | s_pd3 |
| static float | s_pd4 |
| static float | s_po1 |
| static float | s_po2 |
| static float | s_compPress |
| #define K_BMP390_TAG "BMP390" |
Definition at line 30 of file bmp390.c.
Referenced by SPP_SERVICES_BMP390_acquireData(), and SPP_SERVICES_BMP390_configCheck().
|
static |
BMP390 sensor instance initialisation. This function is called by the service task. It is responsible for initialising the SPI bus, the GPIO ISR, and the sensor driver.
| p_data | Pointer to the BMP390 sensor instance. |
Definition at line 122 of file bmp390.c.
References BMP390_GpioConfig_t::drdyFlag, BMP390_t::gpioConfig, BMP390_GpioConfig_t::intIntrType, BMP390_GpioConfig_t::intPin, BMP390_GpioConfig_t::intPull, BMP390_GpioConfig_t::isrCtx, K_BMP390_INT_INTR_TYPE, K_BMP390_INT_PIN_NUM, K_BMP390_INT_PULL, K_BMP390_SPI_BUS_IDX, K_SPP_ERROR, K_SPP_OK, SPP_GpioIsrCtx_t::p_flag, BMP390_SpiConfig_t::p_spiHandler, s_bmpData, BMP390_t::spiConfig, BMP390_SpiConfig_t::spiDevIdx, SPP_HAL_GPIO_configInterrupt(), SPP_HAL_GPIO_registerIsr(), SPP_HAL_SPI_deviceInit(), SPP_HAL_SPI_getHandle(), SPP_SERVICES_BMP390_auxConfig(), SPP_SERVICES_BMP390_init(), SPP_SERVICES_BMP390_intEnableDrdy(), and SPP_SERVICES_BMP390_prepareMeasure().
Referenced by SPP_SERVICES_BMP390_init().
|
static |
Acquisition callback invoked by the SPP service task on each cycle.
Checks the DRDY flag, reads compensated altitude, pressure and temperature from the sensor, packs the values into an SPP packet and publishes it. Silently returns if DRDY is not set or no free packet is available.
| p_data | Pointer to the BMP390_t sensor instance. |
Definition at line 174 of file bmp390.c.
References BMP390_GpioConfig_t::drdyFlag, BMP390_t::gpioConfig, K_BMP390_TAG, K_SPP_ERROR, K_SPP_OK, k_svcTag, BMP390_SpiConfig_t::p_spiHandler, s_bmpData, BMP390_t::seq, BMP390_t::spiConfig, SPP_LOGE, SPP_LOGI, SPP_LOGW, SPP_Packet_t, SPP_SERVICES_BMP390_acquireData(), SPP_SERVICES_BMP390_getAltitude(), SPP_SERVICES_DATABANK_getPacket(), SPP_SERVICES_DATABANK_packetData(), SPP_SERVICES_DATABANK_returnPacket(), SPP_SERVICES_PUBSUB_publish(), and SPP_Kpid_t::value.
Referenced by SPP_SERVICES_BMP390_acquireData().
|
static |
Sends a soft-reset command to the sensor and waits 100 ms for it to reboot.
| p_spiHandler | SPI device handle. |
Definition at line 258 of file bmp390.c.
References BMP390_SOFT_RESET_CMD, K_BMP390_SOFT_RESET_REG, SPP_HAL_SPI_transmit(), SPP_HAL_TIME_delayMs(), and SPP_SERVICES_BMP390_softReset().
Referenced by SPP_SERVICES_BMP390_auxConfig(), and SPP_SERVICES_BMP390_softReset().
|
static |
Writes the interface-config register to lock the sensor into SPI mode.
| p_spiHandler | SPI device handle. |
Definition at line 271 of file bmp390.c.
References BMP390_IF_CONF_SPI, K_BMP390_IF_CONF_REG, SPP_HAL_SPI_transmit(), SPP_HAL_TIME_delayMs(), and SPP_SERVICES_BMP390_enableSpiMode().
Referenced by SPP_SERVICES_BMP390_auxConfig(), and SPP_SERVICES_BMP390_enableSpiMode().
|
static |
Reads the chip-ID register and returns an error if the value is not 0x60.
| p_spiHandler | SPI device handle. |
Definition at line 284 of file bmp390.c.
References K_BMP390_CHIP_ID_REG, K_BMP390_IF_CONF_REG, K_BMP390_SOFT_RESET_REG, K_BMP390_SPI_READ, K_BMP390_SPI_WRITE, K_BMP390_TAG, K_SPP_ERROR, K_SPP_OK, SPP_HAL_SPI_transmit(), SPP_LOGE, SPP_LOGI, and SPP_SERVICES_BMP390_configCheck().
Referenced by SPP_SERVICES_BMP390_auxConfig(), and SPP_SERVICES_BMP390_configCheck().
|
static |
Resets the sensor, enables SPI mode, and verifies the chip ID.
| p_spiHandler | SPI device handle. |
Definition at line 313 of file bmp390.c.
References K_SPP_OK, SPP_SERVICES_BMP390_auxConfig(), SPP_SERVICES_BMP390_configCheck(), SPP_SERVICES_BMP390_enableSpiMode(), and SPP_SERVICES_BMP390_softReset().
Referenced by SPP_SERVICES_BMP390_auxConfig(), and SPP_SERVICES_BMP390_init().
|
static |
Writes OSR, ODR, IIR and power-control registers to start continuous measurements.
| p_spiHandler | SPI device handle. |
Definition at line 343 of file bmp390.c.
References BMP390_VALUE_IIR, BMP390_VALUE_ODR, BMP390_VALUE_OSR, BMP390_VALUE_PWRCTRL, K_BMP390_REG_IIR, K_BMP390_REG_ODR, K_BMP390_REG_OSR, K_BMP390_REG_PWRCTRL, SPP_HAL_SPI_transmit(), and SPP_SERVICES_BMP390_prepareMeasure().
Referenced by SPP_SERVICES_BMP390_init(), and SPP_SERVICES_BMP390_prepareMeasure().
|
static |
Polls the DRDY flag until set or until the timeout elapses.
| p_bmp | Pointer to the driver context containing the ISR flag. |
| timeout_ms | Maximum time to wait in milliseconds. |
Reads raw temperature calibration coefficients from the sensor's NVM registers.
| p_spiHandler | SPI device handle. |
| tcalib | Output struct populated with raw par_t1/t2/t3 values. |
Definition at line 370 of file bmp390.c.
References K_BMP390_SPI_READ, K_BMP390_SPI_WRITE, K_BMP390_TEMP_CALIB_REG_START, K_SPP_OK, BMP390_temp_calib_t::par_t1, BMP390_temp_calib_t::par_t2, BMP390_temp_calib_t::par_t3, SPP_HAL_SPI_transmit(), and SPP_SERVICES_BMP390_readRawTempCoeffs().
Referenced by SPP_SERVICES_BMP390_calibrateTempParams(), and SPP_SERVICES_BMP390_readRawTempCoeffs().
|
static |
Reads raw temperature coefficients and scales them to floating-point parameters.
| p_spiHandler | SPI device handle. |
| out | Output struct populated with scaled PAR_T1/T2/T3. |
Definition at line 405 of file bmp390.c.
References K_SPP_OK, BMP390_temp_params_t::PAR_T1, BMP390_temp_calib_t::par_t1, BMP390_temp_params_t::PAR_T2, BMP390_temp_calib_t::par_t2, BMP390_temp_params_t::PAR_T3, BMP390_temp_calib_t::par_t3, SPP_SERVICES_BMP390_calibrateTempParams(), and SPP_SERVICES_BMP390_readRawTempCoeffs().
Referenced by SPP_SERVICES_BMP390_calibrateTempParams(), and SPP_SERVICES_BMP390_getAltitude().
|
static |
Reads the 24-bit raw temperature ADC value from the sensor.
| p_spiHandler | SPI device handle. |
| raw_temp | Output: raw 24-bit ADC reading. |
Definition at line 428 of file bmp390.c.
References K_BMP390_SPI_READ, K_BMP390_SPI_WRITE, K_BMP390_TEMP_RAW_REG, K_SPP_OK, SPP_HAL_SPI_transmit(), and SPP_SERVICES_BMP390_readRawTemp().
Referenced by SPP_SERVICES_BMP390_auxGetTemp(), and SPP_SERVICES_BMP390_readRawTemp().
|
static |
Applies the BMP390 double-quadratic temperature compensation formula.
| raw_temp | Raw 24-bit ADC reading from the sensor. |
| params | Scaled calibration parameters (PAR_T1/T2/T3). |
Definition at line 461 of file bmp390.c.
References BMP390_temp_params_t::PAR_T1, BMP390_temp_params_t::PAR_T2, BMP390_temp_params_t::PAR_T3, and SPP_SERVICES_BMP390_compensateTemperature().
Referenced by SPP_SERVICES_BMP390_auxGetTemp(), and SPP_SERVICES_BMP390_compensateTemperature().
|
static |
Reads the raw temperature ADC and returns the compensated value.
| p_spiHandler | SPI device handle. |
| temp_params | Scaled calibration parameters. |
| raw_temp | Output: raw ADC reading. |
| comp_temp | Output: compensated temperature in °C. |
Definition at line 478 of file bmp390.c.
References K_SPP_OK, SPP_SERVICES_BMP390_auxGetTemp(), SPP_SERVICES_BMP390_compensateTemperature(), and SPP_SERVICES_BMP390_readRawTemp().
Referenced by SPP_SERVICES_BMP390_auxGetTemp(), and SPP_SERVICES_BMP390_getAltitude().
|
static |
Reads raw pressure calibration coefficients from the sensor's NVM registers.
| p_spiHandler | SPI device handle. |
| pcalib | Output struct populated with raw par_p1..p11 values. |
Definition at line 502 of file bmp390.c.
References K_BMP390_PRESS_CALIB_REG_START, K_BMP390_SPI_READ, K_BMP390_SPI_WRITE, K_SPP_OK, BMP390_press_calib_t::par_p1, BMP390_press_calib_t::par_p10, BMP390_press_calib_t::par_p11, BMP390_press_calib_t::par_p2, BMP390_press_calib_t::par_p3, BMP390_press_calib_t::par_p4, BMP390_press_calib_t::par_p5, BMP390_press_calib_t::par_p6, BMP390_press_calib_t::par_p7, BMP390_press_calib_t::par_p8, BMP390_press_calib_t::par_p9, SPP_HAL_SPI_transmit(), and SPP_SERVICES_BMP390_readRawPressCoeffs().
Referenced by SPP_SERVICES_BMP390_calibratePressParams(), and SPP_SERVICES_BMP390_readRawPressCoeffs().
|
static |
Reads raw pressure coefficients and scales them to floating-point parameters.
| p_spiHandler | SPI device handle. |
| out | Output struct populated with scaled PAR_P1..P11. |
Definition at line 586 of file bmp390.c.
References K_SPP_OK, BMP390_press_params_t::PAR_P1, BMP390_press_calib_t::par_p1, BMP390_press_params_t::PAR_P10, BMP390_press_calib_t::par_p10, BMP390_press_params_t::PAR_P11, BMP390_press_calib_t::par_p11, BMP390_press_params_t::PAR_P2, BMP390_press_calib_t::par_p2, BMP390_press_params_t::PAR_P3, BMP390_press_calib_t::par_p3, BMP390_press_params_t::PAR_P4, BMP390_press_calib_t::par_p4, BMP390_press_params_t::PAR_P5, BMP390_press_calib_t::par_p5, BMP390_press_params_t::PAR_P6, BMP390_press_calib_t::par_p6, BMP390_press_params_t::PAR_P7, BMP390_press_calib_t::par_p7, BMP390_press_params_t::PAR_P8, BMP390_press_calib_t::par_p8, BMP390_press_params_t::PAR_P9, BMP390_press_calib_t::par_p9, SPP_SERVICES_BMP390_calibratePressParams(), and SPP_SERVICES_BMP390_readRawPressCoeffs().
Referenced by SPP_SERVICES_BMP390_calibratePressParams(), and SPP_SERVICES_BMP390_getAltitude().
|
static |
Reads the 24-bit raw pressure ADC value from the sensor.
| p_spiHandler | SPI device handle. |
| raw_press | Output: raw 24-bit ADC reading. |
Definition at line 617 of file bmp390.c.
References K_BMP390_PRESS_RAW_REG, K_BMP390_SPI_READ, K_BMP390_SPI_WRITE, K_SPP_OK, SPP_HAL_SPI_transmit(), and SPP_SERVICES_BMP390_readRawPress().
Referenced by SPP_SERVICES_BMP390_auxGetPress(), and SPP_SERVICES_BMP390_readRawPress().
|
static |
Applies the BMP390 pressure compensation formula using the linearised temperature.
| raw_press | Raw 24-bit ADC pressure reading. |
| t_lin | Linearised (compensated) temperature in °C. |
| p | Scaled pressure calibration parameters. |
Definition at line 651 of file bmp390.c.
References BMP390_press_params_t::PAR_P1, BMP390_press_params_t::PAR_P10, BMP390_press_params_t::PAR_P11, BMP390_press_params_t::PAR_P2, BMP390_press_params_t::PAR_P3, BMP390_press_params_t::PAR_P4, BMP390_press_params_t::PAR_P5, BMP390_press_params_t::PAR_P6, BMP390_press_params_t::PAR_P7, BMP390_press_params_t::PAR_P8, BMP390_press_params_t::PAR_P9, s_compPress, s_pd1, s_pd2, s_pd3, s_pd4, s_po1, s_po2, and SPP_SERVICES_BMP390_compensatePressure().
Referenced by SPP_SERVICES_BMP390_auxGetPress(), and SPP_SERVICES_BMP390_compensatePressure().
|
static |
Reads raw pressure ADC and returns the compensated value in Pa.
| p_spiHandler | SPI device handle. |
| press_params | Scaled pressure calibration parameters. |
| t_lin | Linearised temperature used for pressure compensation. |
| raw_press | Output: raw 24-bit ADC reading. |
| comp_press | Output: compensated pressure in Pa. |
Definition at line 682 of file bmp390.c.
References K_SPP_OK, SPP_SERVICES_BMP390_auxGetPress(), SPP_SERVICES_BMP390_compensatePressure(), and SPP_SERVICES_BMP390_readRawPress().
Referenced by SPP_SERVICES_BMP390_auxGetPress(), and SPP_SERVICES_BMP390_getAltitude().
|
static |
Reads compensated altitude, pressure and temperature from the sensor.
| p_spiHandler | SPI device handle. |
| p_bmp | Driver context (unused; DRDY is handled by the caller). |
| altitude_m | Output: altitude in metres (barometric formula, ref 1013.25 hPa). |
| pressure_pa | Output: compensated pressure in Pa. |
| temperature_c | Output: compensated temperature in °C. |
Definition at line 710 of file bmp390.c.
References K_SPP_ERROR_NULL_POINTER, K_SPP_OK, SPP_SERVICES_BMP390_auxGetPress(), SPP_SERVICES_BMP390_auxGetTemp(), SPP_SERVICES_BMP390_calibratePressParams(), SPP_SERVICES_BMP390_calibrateTempParams(), and SPP_SERVICES_BMP390_getAltitude().
Referenced by SPP_SERVICES_BMP390_acquireData(), and SPP_SERVICES_BMP390_getAltitude().
|
static |
Enables the active-high data-ready interrupt output on the sensor.
| p_spiHandler | SPI device handle. |
Definition at line 772 of file bmp390.c.
References K_BMP390_INT_CTRL_DRDY_EN, K_BMP390_INT_CTRL_LEVEL, K_BMP390_REG_INT_CTRL, SPP_HAL_SPI_transmit(), and SPP_SERVICES_BMP390_intEnableDrdy().
Referenced by SPP_SERVICES_BMP390_init(), and SPP_SERVICES_BMP390_intEnableDrdy().
| const SPP_SERVICE_ProducerContract_t * SPP_SERVICES_BMP390_getProducerContract | ( | void | ) |
Definition at line 87 of file bmp390.c.
References g_bmp390ProducerContract, and SPP_SERVICES_BMP390_getProducerContract().
Referenced by CUSTOM_registerConsumerProducer(), and SPP_SERVICES_BMP390_getProducerContract().
|
static |
Definition at line 74 of file bmp390.c.
Referenced by SPP_SERVICES_BMP390_getProducerContract().
|
static |
Definition at line 78 of file bmp390.c.
Referenced by SPP_SERVICES_BMP390_acquireData(), and SPP_SERVICES_BMP390_init().
|
static |
Definition at line 79 of file bmp390.c.
Referenced by SPP_SERVICES_BMP390_acquireData().
|
static |
Definition at line 80 of file bmp390.c.
Referenced by SPP_SERVICES_BMP390_compensatePressure().
|
static |
Definition at line 80 of file bmp390.c.
Referenced by SPP_SERVICES_BMP390_compensatePressure().
|
static |
Definition at line 80 of file bmp390.c.
Referenced by SPP_SERVICES_BMP390_compensatePressure().
|
static |
Definition at line 80 of file bmp390.c.
Referenced by SPP_SERVICES_BMP390_compensatePressure().
|
static |
Definition at line 81 of file bmp390.c.
Referenced by SPP_SERVICES_BMP390_compensatePressure().
|
static |
Definition at line 81 of file bmp390.c.
Referenced by SPP_SERVICES_BMP390_compensatePressure().
|
static |
Definition at line 82 of file bmp390.c.
Referenced by SPP_SERVICES_BMP390_compensatePressure().