![]() |
ISSDK
1.8
IoT Sensing Software Development Kit
|
The fxos8700_freemaster.c file implements FreeMASTER demo using the ISSDK FXOS8700 sensor driver example demonstration with interrupt mode. More...
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_debug_console.h"
#include "math.h"
#include "fsl_uart.h"
#include "fsl_common.h"
#include "freemaster.h"
#include "freemaster_serial_uart.h"
#include "Driver_I2C.h"
#include "issdk_hal.h"
#include "gpio_driver.h"
#include "fxos8700_drv.h"
Go to the source code of this file.
Data Structures | |
struct | fxos8700_allregs_t |
This structure defines the fxos8700 all registers metadata. More... | |
struct | fxos8700_offset_noise_t |
This structure defines the fxos8700 offset and noise calculation parameters. More... | |
Macros | |
#define | FXOS8700_NUM_REGISTERS (FXOS8700_A_FFMT_THS_Z_LSB + 1) |
#define | FF_A_FFMT_THS (0x08) /* FreeFall Threshold Value. */ |
#define | A_FFMT_COUNT (0x18) /* Freefall/motion debounce count value. */ |
#define | PL_COUNT (0x15) /* Pulse debounce count value. */ |
#define | ASLP_COUNTER (0x07) /* Auto Sleep after ~5s. */ |
#define | ACCEL_2G_SENS (0.000244) /* Sensitivity factor for 2G FS */ |
#define | ACCEL_4G_SENS (0.000488) /* Sensitivity factor for 4G FS */ |
#define | ACCEL_8G_SENS (0.000976) /* Sensitivity factor for 8G FS */ |
#define | N (500U) /* Number of samples used to measure offset/noise */ |
#define | RAW_ACCELMAG_DATA_SIZE (12U) /* Accel + Mag Data Size */ |
#define | MAX8BITSTORAGE (255U) |
Typedefs | |
typedef enum fxos8700_operation_type | fxos8700_operation_type_t |
Defines host operation types. More... | |
Enumerations | |
enum | fxos8700_operation_type { FXOS8700_REG_WRITE = 1U, FXOS8700_REG_READ = 2U, FXOS8700_ALLREG_READ = 3U, FXOS8700_ACCEL_CONFIG_END } |
Defines host operation types. More... | |
Functions | |
void | fxos8700_isr_callback (void *pUserData) |
ISR for FXOS8700 data ready event. More... | |
int32_t | apply_register_write (fxos8700_i2c_sensorhandle_t FXOS8700drv, uint8_t offset, uint8_t value) |
Function to apply FXOS8700 register write operation. More... | |
int32_t | apply_register_read (fxos8700_i2c_sensorhandle_t FXOS8700drv, uint8_t offset, uint8_t *value) |
Function to apply FXOS8700 register read operation. More... | |
int32_t | apply_register_readall (fxos8700_i2c_sensorhandle_t FXOS8700drv) |
Function to apply FXOS8700 register read-all operation. More... | |
int32_t | update_dropdown_selection (fxos8700_allregs_t *registers, uint8_t caller) |
Function to update dropdown selection. More... | |
void | offset_noise_init (fxos8700_offset_noise_t *offnoiseptr) |
Function to initialize offset noise measurement. More... | |
void | accel_off_noise (fxos8700_accelmagdata_t *rawData, fxos8700_offset_noise_t *offnoiseptr, float sens) |
Function to measure accelerometer offset noise. More... | |
void | mag_off_noise (fxos8700_accelmagdata_t *rawData, fxos8700_offset_noise_t *offnoiseptr) |
Function to measure magnetometer offset noise. More... | |
void | FRM_Recorder_Init () |
FMSTR_TSA_TABLE_BEGIN (main_table) | |
Target Side Addressable (TSA) table created for this application. More... | |
int | main (void) |
Main function. More... | |
Variables | |
const registerwritelist_t | fxos8700_Config_Hybrid [] |
Defines the register write list to configure FXOS8700 in Hybrid mode. More... | |
const registerreadlist_t | cFXOS8700_whoami [] |
Defines the register read list to read the Data Ready Status. More... | |
const registerreadlist_t | cFXOS8700_int_src [] |
Defines the register read list to read the Interrupt Source. More... | |
const registerreadlist_t | cFXOS8700_fs_src [] |
Defines the register read list to read the FullScale range. More... | |
const registerreadlist_t | FXOS8700_ALL_REG_READ [] |
Defines the register read list to read all-registers. More... | |
const registerreadlist_t | cFXOS8700_ffmt_src [] |
Defines the register read list to read FFMT Source. More... | |
const registerreadlist_t | cFXOS8700_pl_status [] |
Defines the register read list to read the PL Status. More... | |
fxos8700_accelmagdata_t | rawData |
fxos8700_allregs_t | registers |
fxos8700_offset_noise_t | offnoise_data |
uint8_t | prev_toggle = 1 |
volatile bool | bFxos8700DataReady = false |
FMSTR_REC_BUFF | recBuffCfg |
FMSTR_REC_VAR | recVar |
FMSTR_REC_CFG | recCfg |
The fxos8700_freemaster.c file implements FreeMASTER demo using the ISSDK FXOS8700 sensor driver example demonstration with interrupt mode.
Definition in file fxos8700_freemaster_demo.c.
#define A_FFMT_COUNT (0x18) /* Freefall/motion debounce count value. */ |
Definition at line 39 of file fxos8700_freemaster_demo.c.
#define ACCEL_2G_SENS (0.000244) /* Sensitivity factor for 2G FS */ |
Definition at line 42 of file fxos8700_freemaster_demo.c.
Referenced by main().
#define ACCEL_4G_SENS (0.000488) /* Sensitivity factor for 4G FS */ |
Definition at line 43 of file fxos8700_freemaster_demo.c.
#define ACCEL_8G_SENS (0.000976) /* Sensitivity factor for 8G FS */ |
Definition at line 44 of file fxos8700_freemaster_demo.c.
#define ASLP_COUNTER (0x07) /* Auto Sleep after ~5s. */ |
Definition at line 41 of file fxos8700_freemaster_demo.c.
#define FF_A_FFMT_THS (0x08) /* FreeFall Threshold Value. */ |
Definition at line 38 of file fxos8700_freemaster_demo.c.
#define FXOS8700_NUM_REGISTERS (FXOS8700_A_FFMT_THS_Z_LSB + 1) |
Definition at line 37 of file fxos8700_freemaster_demo.c.
Referenced by apply_register_read(), and apply_register_write().
#define MAX8BITSTORAGE (255U) |
Definition at line 47 of file fxos8700_freemaster_demo.c.
#define N (500U) /* Number of samples used to measure offset/noise */ |
Definition at line 45 of file fxos8700_freemaster_demo.c.
Referenced by accel_off_noise(), and mag_off_noise().
#define PL_COUNT (0x15) /* Pulse debounce count value. */ |
Definition at line 40 of file fxos8700_freemaster_demo.c.
#define RAW_ACCELMAG_DATA_SIZE (12U) /* Accel + Mag Data Size */ |
Definition at line 46 of file fxos8700_freemaster_demo.c.
typedef enum fxos8700_operation_type fxos8700_operation_type_t |
Defines host operation types.
Defines host operation types.
Enumerator | |
---|---|
FXOS8700_REG_WRITE | |
FXOS8700_REG_READ | |
FXOS8700_ALLREG_READ | |
FXOS8700_ACCEL_CONFIG_END |
Definition at line 204 of file fxos8700_freemaster_demo.c.
void accel_off_noise | ( | fxos8700_accelmagdata_t * | rawData, |
fxos8700_offset_noise_t * | offnoiseptr, | ||
float | sens | ||
) |
Function to measure accelerometer offset noise.
This function measures accelerometer offset noise.
[in] | fxos8700_accelmagdata_t | *rawData, pointer to FXOS8700 rawdata metadata. |
Definition at line 819 of file fxos8700_freemaster_demo.c.
References fxos8700_accelmagdata_t::accel, fxos8700_offset_noise_t::complete_accel_offnoise, N, offset_noise_init(), fxos8700_offset_noise_t::offx, fxos8700_offset_noise_t::offy, fxos8700_offset_noise_t::offz, fxos8700_offset_noise_t::rmsx, fxos8700_offset_noise_t::rmsy, and fxos8700_offset_noise_t::rmsz.
int32_t apply_register_read | ( | fxos8700_i2c_sensorhandle_t | FXOS8700drv, |
uint8_t | offset, | ||
uint8_t * | value | ||
) |
Function to apply FXOS8700 register read operation.
Service register read trigger from Host.
This function apply FXOS8700 register read based on read trigger from host.
[in] | fxos8700_i2c_sensorhandle_t | FXOS8700drv, FXOS8700 sensor I2C handle. |
[in] | uint8_t | offset, the address of the register to read from. |
Set register offset with provided value
Definition at line 698 of file fxos8700_freemaster_demo.c.
References __END_READ_DATA__, FXOS8700_I2C_ReadData(), FXOS8700_NUM_REGISTERS, int32_t(), registerreadlist_t::readFrom, SENSOR_ERROR_INVALID_PARAM, SENSOR_ERROR_NONE, SENSOR_ERROR_WRITE, and status.
int32_t apply_register_readall | ( | fxos8700_i2c_sensorhandle_t | FXOS8700drv | ) |
Function to apply FXOS8700 register read-all operation.
Service register read all trigger from Host.
This function apply FXOS8700 all-registers read based on read-all trigger from host.
[in] | fxos8700_i2c_sensorhandle_t | FXOS8700drv, FXOS8700 sensor I2C handle. |
Set register offset with provided value
Definition at line 723 of file fxos8700_freemaster_demo.c.
References __END_READ_DATA__, FXOS8700_A_FFMT_THS_Z_LSB, FXOS8700_I2C_ReadData(), FXOS8700_STATUS, int32_t(), fxos8700_allregs_t::readall_value, registerreadlist_t::readFrom, SENSOR_ERROR_NONE, SENSOR_ERROR_READ, and status.
int32_t apply_register_write | ( | fxos8700_i2c_sensorhandle_t | FXOS8700drv, |
uint8_t | offset, | ||
uint8_t | value | ||
) |
Function to apply FXOS8700 register write operation.
Service register write trigger from Host.
This function apply FXOS8700 register write based on write trigger from host.
[in] | fxos8700_i2c_sensorhandle_t | FXOS8700drv, FXOS8700 sensor I2C handle. |
[in] | uint8_t | offset, the address of the register to start writing from. |
[in] | uint8_t | value, value to write on register offset. |
Set register offset with provided value
Definition at line 672 of file fxos8700_freemaster_demo.c.
References __END_WRITE_DATA__, FXOS8700_I2C_Configure(), FXOS8700_NUM_REGISTERS, int32_t(), SENSOR_ERROR_INVALID_PARAM, SENSOR_ERROR_NONE, SENSOR_ERROR_WRITE, and status.
FMSTR_TSA_TABLE_BEGIN | ( | main_table | ) |
Target Side Addressable (TSA) table created for this application.
FreeMASTER recorder initialization
Definition at line 310 of file fxos8700_freemaster_demo.c.
References recBuffCfg.
void FRM_Recorder_Init | ( | ) |
void fxos8700_isr_callback | ( | void * | pUserData | ) |
ISR for FXOS8700 data ready event.
This function implements ISR for FXOS8700 DRDY event.
[in] | void | *. |
This is the Sensor Data Ready ISR implementation.
Set flag to indicate Sensor has signalled data ready.
Definition at line 301 of file fxos8700_freemaster_demo.c.
References bFxos8700DataReady.
Referenced by main().
void mag_off_noise | ( | fxos8700_accelmagdata_t * | rawData, |
fxos8700_offset_noise_t * | offnoiseptr | ||
) |
Function to measure magnetometer offset noise.
This function measures magnetometer offset noise.
[in] | fxos8700_accelmagdata_t | *rawData, pointer to FXOS8700 rawdata metadata. |
Definition at line 903 of file fxos8700_freemaster_demo.c.
References fxos8700_offset_noise_t::complete_mag_offnoise, fxos8700_accelmagdata_t::mag, fxos8700_offset_noise_t::mag_off, fxos8700_offset_noise_t::mag_rms, N, and offset_noise_init().
int main | ( | void | ) |
Main function.
Initialize the MCU hardware.
Initialize FXOS8700_INT2 pin used by FRDM board
Initialize RGB LED pin used by FRDM board
FreeMASTER communication layer initialization
Initialize the I2C driver.
Set the I2C Power mode.
Set the I2C bus speed.
Initialize the FXOS8700 sensor driver.
Set the task to be executed while waiting for I2C transactions to complete.
Configure the fxos8700 sensor driver.
FreeMASTER Driver Initialization
FreeMASTER Recorder Initialization
Initialize trigger flags
Initialize read all values
Call Recorder#0 in execution loop for generic high-speed variables sampling.
Call FreeMASTER host in polling mode
Check for any write register trigger from Host
Apply Register Write
Update drop down menu selection based on updated register write
Check for any read register trigger from Host
Apply Register Write
Update drop down menu selection based on updated register read
Check for any read all register trigger from Host
Apply Register Write
Update drop down menu selection based on updated all-register read
Wait for data ready interrupt from the FXOS8700.
Clear the data ready flag, it will be set again by the ISR.
Calling Recorder#1 for sampling sensor data when we get sensor data ready interrupt based on ODR.
Read all FXOS8700 registers
Convert the raw sensor data to signed 16-bit container for display to the debug port.
Check the FS and apply sensitivity
Convert raw values to Gs
Increment data ready counter and check for rollover
Call offset and noise calculation function for FXOS8700 accelerometer
Call offset and noise calculation function for FXOS8700 magnetometer
The following condition checks for multiple interrupts occurring at the same time
Check for single-tap detection interrupt
Check for Vector Magnitude change interrupt
Check for Vector Magnitude change interrupt
Read FFMT interrupt source register to clear flags
Definition at line 381 of file fxos8700_freemaster_demo.c.
References ACCEL_2G_SENS, BOARD_BootClockRUN, BOARD_InitDebugConsole(), BOARD_InitPins(), Driver_GPIO_KSDK, FXOS8700_INT2, fxos8700_isr_callback(), GPIO_DIRECTION_IN, GPIO_DIRECTION_OUT, GREEN_LED, I2C_S_DRIVER, I2Cdrv, int32_t(), pGpioDriver, GENERIC_DRIVER_GPIO::pin_init, and status.
void offset_noise_init | ( | fxos8700_offset_noise_t * | offnoiseptr | ) |
Function to initialize offset noise measurement.
Initialize Offset-Noise Variables.
This function initializes offset noise measurement metadata.
Definition at line 799 of file fxos8700_freemaster_demo.c.
References fxos8700_offset_noise_t::complete_accel_offnoise, fxos8700_offset_noise_t::complete_mag_offnoise, fxos8700_offset_noise_t::mag_off, fxos8700_offset_noise_t::mag_rms, fxos8700_offset_noise_t::offx, fxos8700_offset_noise_t::offy, fxos8700_offset_noise_t::offz, fxos8700_offset_noise_t::rmsx, fxos8700_offset_noise_t::rmsy, and fxos8700_offset_noise_t::rmsz.
Referenced by accel_off_noise(), and mag_off_noise().
int32_t update_dropdown_selection | ( | fxos8700_allregs_t * | registers, |
uint8_t | caller | ||
) |
Function to update dropdown selection.
Update drop down selection values based on register write, read or readall.
This function updates the dropdown selection values in real-time based on read/write/read-all triggers.
Update drop down option based on updated read value
Update drop down option based on updated read value
Update drop down option based on updated read values
Definition at line 746 of file fxos8700_freemaster_demo.c.
References fxos8700_allregs_t::fs_value, FXOS8700_ALLREG_READ, FXOS8700_CTRL_REG2, FXOS8700_REG_READ, FXOS8700_REG_WRITE, FXOS8700_XYZ_DATA_CFG, int32_t(), fxos8700_allregs_t::mods_value, fxos8700_allregs_t::offset, fxos8700_allregs_t::read_offset, fxos8700_allregs_t::read_value, fxos8700_allregs_t::reg_addr, SENSOR_ERROR_INVALID_PARAM, SENSOR_ERROR_NONE, status, and fxos8700_allregs_t::value.
volatile bool bFxos8700DataReady = false |
Definition at line 222 of file fxos8700_freemaster_demo.c.
Referenced by fxos8700_isr_callback().
const registerreadlist_t cFXOS8700_ffmt_src[] |
Defines the register read list to read FFMT Source.
Definition at line 147 of file fxos8700_freemaster_demo.c.
const registerreadlist_t cFXOS8700_fs_src[] |
Defines the register read list to read the FullScale range.
Definition at line 136 of file fxos8700_freemaster_demo.c.
const registerreadlist_t cFXOS8700_int_src[] |
Defines the register read list to read the Interrupt Source.
Definition at line 131 of file fxos8700_freemaster_demo.c.
const registerreadlist_t cFXOS8700_pl_status[] |
Defines the register read list to read the PL Status.
Definition at line 152 of file fxos8700_freemaster_demo.c.
const registerreadlist_t cFXOS8700_whoami[] |
Defines the register read list to read the Data Ready Status.
Definition at line 126 of file fxos8700_freemaster_demo.c.
const registerreadlist_t FXOS8700_ALL_REG_READ[] |
Defines the register read list to read all-registers.
Definition at line 142 of file fxos8700_freemaster_demo.c.
const registerwritelist_t fxos8700_Config_Hybrid[] |
Defines the register write list to configure FXOS8700 in Hybrid mode.
Definition at line 55 of file fxos8700_freemaster_demo.c.
fxos8700_offset_noise_t offnoise_data |
Definition at line 220 of file fxos8700_freemaster_demo.c.
uint8_t prev_toggle = 1 |
Definition at line 221 of file fxos8700_freemaster_demo.c.
fxos8700_accelmagdata_t rawData |
Definition at line 218 of file fxos8700_freemaster_demo.c.
Referenced by main().
FMSTR_REC_BUFF recBuffCfg |
Definition at line 225 of file fxos8700_freemaster_demo.c.
Referenced by FMSTR_TSA_TABLE_BEGIN().
FMSTR_REC_CFG recCfg |
Definition at line 227 of file fxos8700_freemaster_demo.c.
FMSTR_REC_VAR recVar |
Definition at line 226 of file fxos8700_freemaster_demo.c.
fxos8700_allregs_t registers |
Definition at line 219 of file fxos8700_freemaster_demo.c.