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

The mma865x_freemaster_demo.c file implements FreeMASTER demo using the ISSDK MMA865x 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 "mma865x_drv.h"
Include dependency graph for mma865x_freemaster_demo.c:

Go to the source code of this file.

Data Structures

struct  mma865x_allregs_t
 This structure defines the mma865x all registers metadata. More...
 
struct  mma865x_offset_noise_t
 This structure defines offset and noise calculation parameters. More...
 

Macros

#define MMA865x_NUM_REGISTERS   (MMA865x_OFF_Z + 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.000976) /* Sensitivity factor for 2G FS */
 
#define ACCEL_4G_SENS   (0.001953) /* Sensitivity factor for 4G FS */
 
#define ACCEL_8G_SENS   (0.003906) /* Sensitivity factor for 8G FS */
 
#define N   (500U) /* Number of samples used to measure offset/noise */
 
#define RAW_ACCEL_DATA_SIZE   (6U) /* Accel Data Size */
 
#define MAX8BITSTORAGE   (255U)
 

Typedefs

typedef enum mma8652_operation_type mma865x_operation_type_t
 Defines MMA8652 host operation types. More...
 

Enumerations

enum  mma8652_operation_type { MMA865x_REG_WRITE = 1U, MMA865x_REG_READ = 2U, MMA865x_ALLREG_READ = 3U, MMA865x_ACCEL_CONFIG_END }
 Defines MMA8652 host operation types. More...
 

Functions

void mma8652_isr_callback (void *pUserData)
 ISR for MMA8652 data ready event. More...
 
int32_t apply_register_write (mma865x_i2c_sensorhandle_t MMA8652drv, uint8_t offset, uint8_t value)
 Function to apply MMA8652 register write operation. More...
 
int32_t apply_register_read (mma865x_i2c_sensorhandle_t MMA8652drv, uint8_t offset, uint8_t *value)
 Function to apply MMA8652 register read operation. More...
 
int32_t apply_register_readall (mma865x_i2c_sensorhandle_t MMA8652drv)
 Function to apply MMA8652 register read-all operation. More...
 
int32_t update_dropdown_selection (mma865x_allregs_t *registers, uint8_t caller)
 Function to update dropdown selection. More...
 
void offset_noise_init (mma865x_offset_noise_t *offnoiseptr)
 Function to initialize offset noise measurement. More...
 
void accel_off_noise (mma865x_acceldata_t *rawData, mma865x_offset_noise_t *offnoiseptr, float sens)
 Function to measure accelerometer 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 Mma865x_Config []
 Prepare the register write list to configure MMA865x in non-FIFO and ISR mode. More...
 
const registerreadlist_t cMMA865x_whoami []
 Prepare the register read for WHOAMI Register. More...
 
const registerreadlist_t cMMA865x_int_src []
 Prepare the register read for INT Status Register. More...
 
const registerreadlist_t cMMA865x_fs_src []
 Prepare the register read for FullScale range Register. More...
 
const registerreadlist_t cMMA865x_ffmt_src []
 Prepare the register read for FFMT Register. More...
 
const registerreadlist_t cMMA865x_pl_status []
 Prepare the register read for PL Status Register. More...
 
const registerreadlist_t MMA865x_ALL_REG_READ []
 MMA865x register list to read all registers. More...
 
mma865x_acceldata_t rawData
 
mma865x_allregs_t registers
 
mma865x_offset_noise_t offnoise_data
 
uint8_t prev_toggle = 1
 
volatile bool bMma8652IntFlag = false
 
FMSTR_REC_BUFF recBuffCfg
 
FMSTR_REC_VAR recVar
 
FMSTR_REC_CFG recCfg
 

Detailed Description

The mma865x_freemaster_demo.c file implements FreeMASTER demo using the ISSDK MMA865x sensor driver example demonstration with interrupt mode.

Definition in file mma865x_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 mma865x_freemaster_demo.c.

◆ ACCEL_2G_SENS

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

Definition at line 42 of file mma865x_freemaster_demo.c.

Referenced by main().

◆ ACCEL_4G_SENS

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

Definition at line 43 of file mma865x_freemaster_demo.c.

◆ ACCEL_8G_SENS

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

Definition at line 44 of file mma865x_freemaster_demo.c.

◆ ASLP_COUNTER

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

Definition at line 41 of file mma865x_freemaster_demo.c.

◆ FF_A_FFMT_THS

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

Definition at line 38 of file mma865x_freemaster_demo.c.

◆ MAX8BITSTORAGE

#define MAX8BITSTORAGE   (255U)

Definition at line 47 of file mma865x_freemaster_demo.c.

◆ MMA865x_NUM_REGISTERS

#define MMA865x_NUM_REGISTERS   (MMA865x_OFF_Z + 1)

Definition at line 37 of file mma865x_freemaster_demo.c.

Referenced by apply_register_read(), and apply_register_write().

◆ N

#define N   (500U) /* Number of samples used to measure offset/noise */

Definition at line 45 of file mma865x_freemaster_demo.c.

Referenced by accel_off_noise().

◆ PL_COUNT

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

Definition at line 40 of file mma865x_freemaster_demo.c.

◆ RAW_ACCEL_DATA_SIZE

#define RAW_ACCEL_DATA_SIZE   (6U) /* Accel Data Size */

Definition at line 46 of file mma865x_freemaster_demo.c.

Typedef Documentation

◆ mma865x_operation_type_t

Defines MMA8652 host operation types.

Enumeration Type Documentation

◆ mma8652_operation_type

Defines MMA8652 host operation types.

Enumerator
MMA865x_REG_WRITE 
MMA865x_REG_READ 
MMA865x_ALLREG_READ 
MMA865x_ACCEL_CONFIG_END 

Definition at line 158 of file mma865x_freemaster_demo.c.

Function Documentation

◆ accel_off_noise()

void accel_off_noise ( mma865x_acceldata_t rawData,
mma865x_offset_noise_t offnoiseptr,
float  sens 
)

Function to measure accelerometer offset noise.

This function measures accelerometer offset noise.

Parameters
[in]mma865x_acceldata_t*rawData, pointer to MMA8652 rawdata metadata.

Definition at line 737 of file mma865x_freemaster_demo.c.

References mma865x_acceldata_t::accel, mma865x_offset_noise_t::complete_accel_offnoise, N, offset_noise_init(), mma865x_offset_noise_t::offx, mma865x_offset_noise_t::offy, mma865x_offset_noise_t::offz, mma865x_offset_noise_t::rmsx, mma865x_offset_noise_t::rmsy, and mma865x_offset_noise_t::rmsz.

Here is the call graph for this function:

◆ apply_register_read()

int32_t apply_register_read ( mma865x_i2c_sensorhandle_t  MMA8652drv,
uint8_t  offset,
uint8_t *  value 
)

Function to apply MMA8652 register read operation.

Service register read trigger from Host.

This function apply MMA8652 register read based on read trigger from host.

Parameters
[in]mma865x_i2c_sensorhandle_tMMA8652drv, MMA8652 sensor I2C handle.
[in]uint8_toffset, the address of the register to read from.

Set register offset with provided value

Definition at line 623 of file mma865x_freemaster_demo.c.

References __END_READ_DATA__, int32_t(), MMA865x_I2C_ReadData(), MMA865x_NUM_REGISTERS, 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 ( mma865x_i2c_sensorhandle_t  MMA8652drv)

Function to apply MMA8652 register read-all operation.

Service register read all trigger from Host.

This function apply MMA8652 all-registers read based on read-all trigger from host.

Parameters
[in]mma865x_i2c_sensorhandle_tMMA8652drv, MMA8652 sensor I2C handle.
Returns
returns the status of the operation.

Set register offset with provided value

Definition at line 648 of file mma865x_freemaster_demo.c.

References __END_READ_DATA__, int32_t(), MMA865x_I2C_ReadData(), MMA865x_OFF_Z, MMA865x_STATUS, mma865x_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 ( mma865x_i2c_sensorhandle_t  MMA8652drv,
uint8_t  offset,
uint8_t  value 
)

Function to apply MMA8652 register write operation.

Service register write trigger from Host.

This function apply MMA8652 register write based on write trigger from host.

Parameters
[in]mma865x_i2c_sensorhandle_tMMA8652drv, MMA8652 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 597 of file mma865x_freemaster_demo.c.

References __END_WRITE_DATA__, int32_t(), MMA865x_I2C_Configure(), MMA865x_NUM_REGISTERS, 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 257 of file mma865x_freemaster_demo.c.

References recBuffCfg.

◆ FRM_Recorder_Init()

void FRM_Recorder_Init ( )

◆ main()

int main ( void  )

Main function.

Initialize the MCU hardware.

Initialize MMA8652_INT1 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 MMA865x sensor driver.

Set the task to be executed while waiting for I2C transactions to complete.

Configure the mma865x sensor driver.

FreeMASTER Driver Initialization

FreeMASTER Recorder Initialization

Initialize trigger flags

Calling Recorder#0 in execution loop for generic high-speed variables sampling.

FreeMASTER host communication 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 from the MMA865x.

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 MMA865x 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 MMA8652

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 323 of file mma865x_freemaster_demo.c.

References ACCEL_2G_SENS, BOARD_BootClockRUN, BOARD_InitDebugConsole(), BOARD_InitPins(), Driver_GPIO_KSDK, GPIO_DIRECTION_IN, GPIO_DIRECTION_OUT, GREEN_LED, I2C_S_DRIVER, I2Cdrv, int32_t(), MMA8652_INT1, mma8652_isr_callback(), pGpioDriver, GENERIC_DRIVER_GPIO::pin_init, and status.

Here is the call graph for this function:

◆ mma8652_isr_callback()

void mma8652_isr_callback ( void *  pUserData)

ISR for MMA8652 data ready event.

This function implements ISR for MMA8652 DRDY event.

Parameters
[in]void*.
Returns
void.

Set flag to indicate Sensor has signalled data ready.

Definition at line 248 of file mma865x_freemaster_demo.c.

References bMma8652IntFlag.

Referenced by main().

Here is the caller graph for this function:

◆ offset_noise_init()

void offset_noise_init ( mma865x_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 724 of file mma865x_freemaster_demo.c.

References mma865x_offset_noise_t::complete_accel_offnoise, mma865x_offset_noise_t::offx, mma865x_offset_noise_t::offy, mma865x_offset_noise_t::offz, mma865x_offset_noise_t::rmsx, mma865x_offset_noise_t::rmsy, and mma865x_offset_noise_t::rmsz.

Referenced by accel_off_noise().

Here is the caller graph for this function:

◆ update_dropdown_selection()

int32_t update_dropdown_selection ( mma865x_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 671 of file mma865x_freemaster_demo.c.

References mma865x_allregs_t::fs_value, int32_t(), MMA865x_ALLREG_READ, MMA865x_CTRL_REG2, MMA865x_REG_READ, MMA865x_REG_WRITE, MMA865x_XYZ_DATA_CFG, mma865x_allregs_t::mods_value, mma865x_allregs_t::offset, mma865x_allregs_t::read_offset, mma865x_allregs_t::read_value, mma865x_allregs_t::reg_addr, SENSOR_ERROR_INVALID_PARAM, SENSOR_ERROR_NONE, status, and mma865x_allregs_t::value.

Here is the call graph for this function:

Variable Documentation

◆ bMma8652IntFlag

volatile bool bMma8652IntFlag = false

Definition at line 176 of file mma865x_freemaster_demo.c.

Referenced by mma8652_isr_callback().

◆ cMMA865x_ffmt_src

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

Prepare the register read for FFMT Register.

Definition at line 108 of file mma865x_freemaster_demo.c.

◆ cMMA865x_fs_src

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

Prepare the register read for FullScale range Register.

Definition at line 104 of file mma865x_freemaster_demo.c.

◆ cMMA865x_int_src

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

Prepare the register read for INT Status Register.

Definition at line 100 of file mma865x_freemaster_demo.c.

◆ cMMA865x_pl_status

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

Prepare the register read for PL Status Register.

Definition at line 112 of file mma865x_freemaster_demo.c.

◆ cMMA865x_whoami

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

Prepare the register read for WHOAMI Register.

Definition at line 96 of file mma865x_freemaster_demo.c.

◆ MMA865x_ALL_REG_READ

const registerreadlist_t MMA865x_ALL_REG_READ[]
Initial value:
= {{.readFrom = MMA865x_STATUS, .numBytes = MMA865x_NUM_REGISTERS},
#define MMA865x_NUM_REGISTERS
#define __END_READ_DATA__
Definition: sensor_drv.h:51

MMA865x register list to read all registers.

Definition at line 116 of file mma865x_freemaster_demo.c.

◆ Mma865x_Config

const registerwritelist_t Mma865x_Config[]

Prepare the register write list to configure MMA865x in non-FIFO and ISR mode.

Definition at line 53 of file mma865x_freemaster_demo.c.

◆ offnoise_data

mma865x_offset_noise_t offnoise_data

Definition at line 174 of file mma865x_freemaster_demo.c.

◆ prev_toggle

uint8_t prev_toggle = 1

Definition at line 175 of file mma865x_freemaster_demo.c.

◆ rawData

Definition at line 172 of file mma865x_freemaster_demo.c.

◆ recBuffCfg

FMSTR_REC_BUFF recBuffCfg

Definition at line 179 of file mma865x_freemaster_demo.c.

Referenced by FMSTR_TSA_TABLE_BEGIN().

◆ recCfg

FMSTR_REC_CFG recCfg

Definition at line 181 of file mma865x_freemaster_demo.c.

◆ recVar

FMSTR_REC_VAR recVar

Definition at line 180 of file mma865x_freemaster_demo.c.

◆ registers

mma865x_allregs_t registers

Definition at line 173 of file mma865x_freemaster_demo.c.