ISSDK  1.8
IoT Sensing Software Development Kit
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
fxos8700_freemaster_demo.c File Reference

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"
Include dependency graph for fxos8700_freemaster_demo.c:

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
 

Detailed Description

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.

Macro Definition Documentation

◆ A_FFMT_COUNT

#define A_FFMT_COUNT   (0x18) /* Freefall/motion debounce count value. */

Definition at line 39 of file fxos8700_freemaster_demo.c.

◆ ACCEL_2G_SENS

#define ACCEL_2G_SENS   (0.000244) /* Sensitivity factor for 2G FS */

Definition at line 42 of file fxos8700_freemaster_demo.c.

Referenced by main().

◆ ACCEL_4G_SENS

#define ACCEL_4G_SENS   (0.000488) /* Sensitivity factor for 4G FS */

Definition at line 43 of file fxos8700_freemaster_demo.c.

◆ ACCEL_8G_SENS

#define ACCEL_8G_SENS   (0.000976) /* Sensitivity factor for 8G FS */

Definition at line 44 of file fxos8700_freemaster_demo.c.

◆ ASLP_COUNTER

#define ASLP_COUNTER   (0x07) /* Auto Sleep after ~5s. */

Definition at line 41 of file fxos8700_freemaster_demo.c.

◆ FF_A_FFMT_THS

#define FF_A_FFMT_THS   (0x08) /* FreeFall Threshold Value. */

Definition at line 38 of file fxos8700_freemaster_demo.c.

◆ FXOS8700_NUM_REGISTERS

#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().

◆ MAX8BITSTORAGE

#define MAX8BITSTORAGE   (255U)

Definition at line 47 of file fxos8700_freemaster_demo.c.

◆ N

#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().

◆ PL_COUNT

#define PL_COUNT   (0x15) /* Pulse debounce count value. */

Definition at line 40 of file fxos8700_freemaster_demo.c.

◆ RAW_ACCELMAG_DATA_SIZE

#define RAW_ACCELMAG_DATA_SIZE   (12U) /* Accel + Mag Data Size */

Definition at line 46 of file fxos8700_freemaster_demo.c.

Typedef Documentation

◆ fxos8700_operation_type_t

Defines host operation types.

Enumeration Type Documentation

◆ fxos8700_operation_type

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.

Function Documentation

◆ accel_off_noise()

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.

Parameters
[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.

Here is the call graph for this function:

◆ apply_register_read()

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.

Parameters
[in]fxos8700_i2c_sensorhandle_tFXOS8700drv, FXOS8700 sensor I2C handle.
[in]uint8_toffset, 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.

Here is the call graph for this function:

◆ apply_register_readall()

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.

Parameters
[in]fxos8700_i2c_sensorhandle_tFXOS8700drv, FXOS8700 sensor I2C handle.
Returns
returns the status of the operation.

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.

Here is the call graph for this function:

◆ apply_register_write()

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.

Parameters
[in]fxos8700_i2c_sensorhandle_tFXOS8700drv, FXOS8700 sensor I2C handle.
[in]uint8_toffset, the address of the register to start writing from.
[in]uint8_tvalue, value to write on register offset.
Returns
returns the status of the operation.

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.

Here is the call graph for this function:

◆ FMSTR_TSA_TABLE_BEGIN()

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.

◆ FRM_Recorder_Init()

void FRM_Recorder_Init ( )

◆ fxos8700_isr_callback()

void fxos8700_isr_callback ( void *  pUserData)

ISR for FXOS8700 data ready event.

This function implements ISR for FXOS8700 DRDY event.

Parameters
[in]void*.
Returns
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().

Here is the caller graph for this function:

◆ mag_off_noise()

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.

Parameters
[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().

Here is the call graph for this function:

◆ main()

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.

Here is the call graph for this function:

◆ offset_noise_init()

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.

Parameters

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().

Here is the caller graph for this function:

◆ update_dropdown_selection()

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.

Parameters

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.

Here is the call graph for this function:

Variable Documentation

◆ bFxos8700DataReady

volatile bool bFxos8700DataReady = false

Definition at line 222 of file fxos8700_freemaster_demo.c.

Referenced by fxos8700_isr_callback().

◆ cFXOS8700_ffmt_src

const registerreadlist_t cFXOS8700_ffmt_src[]
Initial value:
= {
{.readFrom = FXOS8700_A_FFMT_SRC , .numBytes = 1}, __END_READ_DATA__}
#define __END_READ_DATA__
Definition: sensor_drv.h:51

Defines the register read list to read FFMT Source.

Definition at line 147 of file fxos8700_freemaster_demo.c.

◆ cFXOS8700_fs_src

const registerreadlist_t cFXOS8700_fs_src[]
Initial value:
= {
{.readFrom = FXOS8700_XYZ_DATA_CFG, .numBytes = 1}, __END_READ_DATA__}
#define __END_READ_DATA__
Definition: sensor_drv.h:51

Defines the register read list to read the FullScale range.

Definition at line 136 of file fxos8700_freemaster_demo.c.

◆ cFXOS8700_int_src

const registerreadlist_t cFXOS8700_int_src[]
Initial value:
= {
{.readFrom = FXOS8700_INT_SOURCE, .numBytes = 1}, __END_READ_DATA__}
#define __END_READ_DATA__
Definition: sensor_drv.h:51

Defines the register read list to read the Interrupt Source.

Definition at line 131 of file fxos8700_freemaster_demo.c.

◆ cFXOS8700_pl_status

const registerreadlist_t cFXOS8700_pl_status[]
Initial value:
= {
{.readFrom = FXOS8700_PL_STATUS, .numBytes = 1}, __END_READ_DATA__}
#define __END_READ_DATA__
Definition: sensor_drv.h:51

Defines the register read list to read the PL Status.

Definition at line 152 of file fxos8700_freemaster_demo.c.

◆ cFXOS8700_whoami

const registerreadlist_t cFXOS8700_whoami[]
Initial value:
= {
{.readFrom = FXOS8700_WHO_AM_I, .numBytes = 1}, __END_READ_DATA__}
#define __END_READ_DATA__
Definition: sensor_drv.h:51

Defines the register read list to read the Data Ready Status.

Definition at line 126 of file fxos8700_freemaster_demo.c.

◆ FXOS8700_ALL_REG_READ

const registerreadlist_t FXOS8700_ALL_REG_READ[]
Initial value:
= {{.readFrom = FXOS8700_STATUS, .numBytes = FXOS8700_NUM_REGISTERS},
#define FXOS8700_NUM_REGISTERS
#define __END_READ_DATA__
Definition: sensor_drv.h:51

Defines the register read list to read all-registers.

Definition at line 142 of file fxos8700_freemaster_demo.c.

◆ fxos8700_Config_Hybrid

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.

◆ offnoise_data

fxos8700_offset_noise_t offnoise_data

Definition at line 220 of file fxos8700_freemaster_demo.c.

◆ prev_toggle

uint8_t prev_toggle = 1

Definition at line 221 of file fxos8700_freemaster_demo.c.

◆ rawData

Definition at line 218 of file fxos8700_freemaster_demo.c.

Referenced by main().

◆ recBuffCfg

FMSTR_REC_BUFF recBuffCfg

Definition at line 225 of file fxos8700_freemaster_demo.c.

Referenced by FMSTR_TSA_TABLE_BEGIN().

◆ recCfg

FMSTR_REC_CFG recCfg

Definition at line 227 of file fxos8700_freemaster_demo.c.

◆ recVar

FMSTR_REC_VAR recVar

Definition at line 226 of file fxos8700_freemaster_demo.c.

◆ registers

fxos8700_allregs_t registers

Definition at line 219 of file fxos8700_freemaster_demo.c.