18 #include "clock_config.h" 20 #include "fsl_debug_console.h" 23 #include "fsl_common.h" 24 #include "freemaster.h" 25 #include "freemaster_serial_uart.h" 29 #include "Driver_I2C.h" 34 #include "issdk_hal.h" 35 #include "gpio_driver.h" 42 #define FXLS896x_NUM_REGISTERS (FXLS896x_SELF_TEST_CONFIG2 + 1) 43 #define FF_A_FFMT_THS (0x08) 44 #define A_FFMT_COUNT (0x18) 45 #define PL_COUNT (0x15) 46 #define ASLP_COUNTER (0x07) 47 #define ACCEL_2G_SENS (0.000976) 48 #define ACCEL_4G_SENS (0.001953) 49 #define ACCEL_8G_SENS (0.003906) 50 #define ACCEL_16G_SENS (0.007813) 52 #define RAW_ACCEL_DATA_SIZE (6U) 53 #define MAX8BITSTORAGE (255U) 54 #define FXLS896x_DATA_SIZE 6 159 uint8_t read_trigger;
161 uint8_t readall_size;
162 uint8_t readall_trigger;
164 uint8_t trigger_accel_offnoise;
165 uint8_t trigger_selftest;
170 uint8_t dataready_cntr;
188 uint8_t complete_accel_offnoise;
200 uint8_t complete_selftest;
239 static FMSTR_U8 recBuffer[1024*10];
245 static unsigned char pipe3_rxb[512];
246 static unsigned char pipe3_txb[0x1000];
250 int16_t
XSTP[2]={0,0},
YSTP[2]={0,0},
ZSTP[2]={0,0},
XSTN[2]={0,0},
YSTN[2]={0,0},
ZSTN[2]={0,0};
261 static void init_freemaster_uart(
void);
393 FMSTR_TSA_TABLE_END()
395 FMSTR_TSA_TABLE_LIST_BEGIN()
396 FMSTR_TSA_TABLE(main_table)
397 FMSTR_TSA_TABLE_LIST_END()
410 recBuffCfg.name =
"FXLS896x 3-Axis Accelerometer Data";
443 init_freemaster_uart();
447 if (ARM_DRIVER_OK != status)
453 status = I2Cdrv->PowerControl(ARM_POWER_FULL);
454 if (ARM_DRIVER_OK != status)
460 status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
461 if (ARM_DRIVER_OK != status)
491 FMSTR_HPIPE hpipe = FMSTR_PipeOpen(3, NULL, (FMSTR_ADDR)pipe3_rxb,
sizeof(pipe3_rxb), (FMSTR_ADDR)pipe3_txb,
sizeof(pipe3_txb),
492 FMSTR_PIPE_TYPE_ANSI_TERMINAL,
"streaming");
582 if (ARM_DRIVER_OK != status)
601 rawData.
accel[0] = (int16_t)(((int16_t)(((int16_t)registers.
reg_addr[3] << 8) | registers.
reg_addr[2])));
602 rawData.
accel[1] = (int16_t)(((int16_t)(((int16_t)registers.
reg_addr[5] << 8) | registers.
reg_addr[4])));
603 rawData.
accel[2] = (int16_t)(((int16_t)(((int16_t)registers.
reg_addr[7] << 8) | registers.
reg_addr[6])));
620 else if ((regdata & FXLS896x_SENS_CONFIG1_FSR_MASK) == 4)
624 else if ((regdata & FXLS896x_SENS_CONFIG1_FSR_MASK) == 6)
634 registers.
accel[0] = (float) (rawData.
accel[0] * sensitivity);
635 registers.
accel[1] = (float) (rawData.
accel[1] * sensitivity);
636 registers.
accel[2] = (float) (rawData.
accel[2] * sensitivity);
816 offnoiseptr->
offx = 0.0;
817 offnoiseptr->
offy = 0.0;
818 offnoiseptr->
offz = 0.0;
819 offnoiseptr->
rmsx = 0.0;
820 offnoiseptr->
rmsy = 0.0;
821 offnoiseptr->
rmsz = 0.0;
831 static uint16_t cntr=0;
835 static float xx[
N], yy[
N], zz[
N];
836 static float xm[
N], ym[
N], zm[
N];
837 static float xsq[
N], ysq[
N], zsq[
N];
839 static float sumx=0.0;
840 static float sumy=0.0;
841 static float sumz=0.0;
851 am[0]=rawData->
accel[0]*sens;
852 am[1]=rawData->
accel[1]*sens;
853 am[2]=rawData->
accel[2]*sens;
873 offnoiseptr->
offx=0-sumx;
874 offnoiseptr->
offy=0-sumy;
875 offnoiseptr->
offz=1-sumz;
884 xsq[j]=(float)pow(xm[j],2);
885 ysq[j]=(float)pow(ym[j],2);
886 zsq[j]=(float)pow(zm[j],2);
896 offnoiseptr->
rmsx=(float)pow(stdx,0.5);
897 offnoiseptr->
rmsy=(float)pow(stdy,0.5);
898 offnoiseptr->
rmsz=(float)pow(stdz,0.5);
905 sumx = sumy = sumz = 0;
906 stdx = stdy = stdz = 0;
948 if (ARM_DRIVER_OK != status)
954 for(counter=0;counter<1;counter++)
967 if (ARM_DRIVER_OK != status)
978 if (ARM_DRIVER_OK != status)
1018 static void init_freemaster_uart(
void)
1020 uart_config_t config;
1031 UART_GetDefaultConfig(&config);
1032 config.baudRate_Bps = 115200U;
1033 config.enableTx =
false;
1034 config.enableRx =
false;
1039 FMSTR_SerialSetBaseAddress((UART_Type*)BOARD_DEBUG_UART_BASEADDR);
1041 #if FMSTR_SHORT_INTR || FMSTR_LONG_INTR 1048 #if FMSTR_SHORT_INTR || FMSTR_LONG_INTR 1066 #if defined __CORTEX_M && (__CORTEX_M == 4U) const registerreadlist_t cFXLS896x_whoami[]
int32_t perform_selftest(fxls896x_i2c_sensorhandle_t fxls896xDriver, fxls896x_selftest_t *selftest)
Function to perform FXLS896x self test.
enum fxls896x_operation_type fxls896x_operation_type_t
This structure defines the fxls896x host operation type.
The fxls896x_drv.h file describes the FXLS8964/67AF driver interface and structures.
#define FXLS896x_SENS_CONFIG2_ANIC_TEMP_EN
This structure defines the Write command List.
#define FXLS896x_SENS_CONFIG1_FSR_4G
const registerreadlist_t cFXLS896x_fs_src[]
Prepare the register read for FullScale range Register.
#define FXLS896x_SENS_CONFIG3_WAKE_ODR_12_5HZ
#define FXLS896x_I2C_ADDR
status_t SMC_SetPowerModeVlpr(void *arg)
Configures the system to VLPR power mode. API name used from Kinetis family to maintain compatibility...
const registerwritelist_t cFxls896xSTXN[]
Register settings for Self-Test in X Axis (Negative polarity).
int32_t Register_I2C_Write(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, uint8_t offset, uint8_t value, uint8_t mask, bool repeatedStart)
The interface function to write a sensor register.
This structure defines the fxls896x all registers metadata.
#define FXLS896x_SENS_CONFIG1_ST_POL_POSITIVE
void BOARD_DELAY_ms(uint32_t delay_ms)
Function to insert delays.
uint8_t complete_accel_offnoise
#define BOARD_DEBUG_UART_CLK_FREQ
int main(void)
Main function.
int32_t apply_register_readall(fxls896x_i2c_sensorhandle_t fxls896xDriver)
Function to apply FXLS896x register read-all operation.
int32_t FXLS896x_I2C_Initialize(fxls896x_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t *whoami)
The interface function to initialize the sensor.
Access structure of the GPIO Driver.
registerDeviceInfo_t deviceInfo
const registerwritelist_t cFxls896xSTZN[]
Register settings for Self-Test in Z Axis (Negative polarity).
int32_t apply_register_read(fxls896x_i2c_sensorhandle_t fxls896xDriver, uint8_t offset, uint8_t *value)
Function to apply FXLS896x register read operation.
const registerreadlist_t cFxls896xOutputNormal[]
Address of Raw Accel Data in Normal Mode.
uint8_t complete_selftest
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_MASK
#define FXLS896x_SENS_CONFIG1_FSR_16G
const registerwritelist_t cFxls896xSTYP[]
Register settings for Self-Test in Y Axis (Positive polarity).
const registerreadlist_t FXLS896x_ALL_REG_READ[]
FXLS896x register list to read all registers.
This structure defines variables to compute self-test output change (STOC) and self-test offset (STOF...
#define __END_WRITE_DATA__
const registerwritelist_t cFxls896xSTYN[]
Register settings for Self-Test in Y Axis (Negative polarity).
#define FXLS896x_DATA_SIZE
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
int32_t apply_register_write(fxls896x_i2c_sensorhandle_t fxls896xDriver, uint8_t offset, uint8_t value)
Function to apply FXLS896x register write operation.
#define FXLS896x_NUM_REGISTERS
This structure defines the fxls896x raw data buffer.
#define FXLS896x_SENS_CONFIG1_ST_POL_MASK
#define I2C_S_SIGNAL_EVENT
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_EN_Z
const registerwritelist_t cFxls896xConfigNormal[]
Defines the register write list to configure FXLS896x in Interrupt mode.
void accel_off_noise(fxls896x_acceldata_t *rawData, fxls896x_offset_noise_t *offnoiseptr, float sens)
Function to measure accelerometer offset noise.
#define FXLS896x_SENS_CONFIG1_ST_POL_NEGATIVE
#define BOARD_BootClockRUN
This structure defines the fxls896x offset and noise calculation parameters.
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
#define FXLS896x_SENS_CONFIG1_FSR_MASK
fxls896x_operation_type
This structure defines the fxls8962 host operation type.
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
GENERIC_DRIVER_GPIO * pGpioDriver
#define FXLS896x_INT_EN_DRDY_EN_MASK
This defines the sensor specific information for I2C.
uint32_t BOARD_SystickElapsedTime_us(int32_t *pStart)
Function to compute the Elapsed Time.
fxls896x_allregs_t registers
FMSTR_REC_BUFF recBuffCfg
#define BOARD_UART_IRQ_HANDLER
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_EN_Y
fxls896x_offset_noise_t offnoise_data
int32_t FXLS896x_I2C_Configure(fxls896x_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
#define __END_READ_DATA__
int32_t FXLS896x_I2C_ReadData(fxls896x_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
FMSTR_TSA_TABLE_BEGIN(main_table)
Target Side Addressable (TSA) table created for this application.
void offset_noise_init(fxls896x_offset_noise_t *offnoiseptr)
Function to initialize offset noise measurement.
#define FXLS896x_SENS_CONFIG2_ANIC_TEMP_MASK
void fxls896x_isr_callback(void *pUserData)
ISR for FXLS896x interrupt source event.
#define BOARD_DEBUG_UART_BASEADDR
int32_t update_dropdown_selection(fxls896x_allregs_t *registers, uint8_t caller)
Function to update dropdown selection.
void selftest_init(fxls896x_selftest_t *selftest)
Function to initialize FXLS896x self test metadata.
fxls896x_i2c_sensorhandle_t fxls896xDriver
void FXLS896x_I2C_SetIdleTask(fxls896x_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
void(* toggle_pin)(pinID_t aPinId)
volatile bool bFxls896xIntFlag
uint8_t reg_addr[FXLS896x_NUM_REGISTERS]
void BOARD_SystickEnable(void)
Function to enable systicks framework.
status_t SMC_SetPowerModeWait(void *arg)
Configures the system to WAIT power mode. API name used from Kinetis family to maintain compatibility...
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
This structure defines the Read command List.
const registerreadlist_t cFXLS896x_int_src[]
Prepare the register read for INT Status Register.
gpioHandleKSDK_t GREEN_LED
const registerwritelist_t cFxls896xSTZP[]
Register settings for Self-Test in Z Axis (Positive polarity).
#define I2C_S_DEVICE_INDEX
void BOARD_InitDebugConsole(void)
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_DISABLED
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_EN_X
uint8_t trigger_accel_offnoise
fxls896x_selftest_t selftest
fxls896x_acceldata_t rawData
#define FXLS896x_INT_EN_DRDY_EN_EN
#define FXLS896x_SENS_CONFIG3_WAKE_ODR_MASK
uint8_t readall_value[FXLS896x_NUM_REGISTERS]
This structure defines the fxls8962 raw data buffer.
uint8_t byte_data[sizeof(sensor_data)]
const registerwritelist_t cFxls896xSTXP[]
Register settings for Self-Test in X Axis (Positive polarity).