29 #include "fsl_os_abstraction.h"
64 static void _mem_copy(
const void *pSource,
void *pDestination,
int32 numBytes);
80 #define FXLS8952_ACCEL_FLOAT_CONVERSION_FACTOR (0.1)
81 #define FXLS8952_ACCEL_FLOAT_CONVERSION_OFFSET (0.0)
82 #define FXLS8952_ACCEL_FIXED_CONVERSION_FACTOR (1638)
83 #define FXLS8952_ACCEL_FIXED_CONVERSION_OFFSET (0)
85 #define MAX_ACCEL_FULL_SCALE_RANGE FXLS8952_RANGE_MAX
87 #define FXLS8952_SAMPLE_PERIOD_MAX 1280409 // Maximum sample period supported by the FXLS8952.
88 #define FXLS8952_SAMPLE_PERIOD_MIN 312 // Minimum sample period supported by the FXLS8952.
89 #define GET_ODR_CONFIG 0x0 // Flag enables the configuration value.
90 #define GET_ODR_VALUE 0x01 // Flag enables the ODR value.
92 #define NUM_STATUS_BYTES 1 // Number of status byte.
94 #define NUMBER_OF_AXES_3D 0x3 // Number of Axes for 3 dimension.
95 #define MAX_NUM_AXES 0x3 // Maximum number of axes.
96 #define MAX_FXLS8952_DM_BYTES 0x30 // Maximum number of read/write using direct device messaging to address the registers,
98 #define NUM_INTERNAL_ADDRESS_BYTES 0x1 // Size of the internal address byte.
102 #define ASSIGN_REG_BITS_VALUE(addr, val, mask, shift) (addr) = (((addr) & ~ (mask)) | (((val) << shift)& (mask)) )
105 #define GET_MODE(mode) ((mode) <= FXLS8952_MODE_HYBRID) ? (mode) : FXLS8952_MODE_HYBRID
108 #define GET_STRUCT_MEMBER_ADDRESS(p, m) (&(p)->m)
110 #define GET_MEMBER_SIZE(p, m) sizeof((p)->m)
158 { 0.000061, 0.0, 16, 0},
159 { 0.000122, 0.0, 32, 0},
160 { 0.000244, 0.0, 64, 0},
161 { 0.000488, 0.0, 128, 0}
182 if (NULL == pSensorHandle) {
197 if (NULL == pDeviceDescriptor) {
205 pCurrentSampleBuffer->
accel[0] = 0;
206 pCurrentSampleBuffer->
accel[1] = 0;
207 pCurrentSampleBuffer->
accel[2] = 0;
240 if (kStatus_OSA_Success != OSA_SemaCreate(&pDeviceDescriptor->
deviceSemaphore, 1)){
267 if ((NULL == pSensorHandle) || (NULL == pSensorSettings)) {
306 #ifdef DEBUG_READ_ALL_REGS
307 static uint8 debugRegs[120];
314 if ((NULL == pSensorHandle) || (NULL == pSensorSettings)) {
327 if ((NULL == pDeviceDescriptor) || (NULL == pSpecificSettings))
337 goto unlockdescriptor;
343 goto unlockdescriptor;
391 #ifdef DEBUG_READ_ALL_REGS
392 for (
int i=0; i<
sizeof(debugRegs); i++)
409 if (pDeviceDescriptor->
token < 0)
453 if (NULL == pSensorHandle) {
465 if (NULL == pDeviceDescriptor)
474 goto unlockdescriptor;
479 goto unlockdescriptor;
484 goto unlockdescriptor;
491 goto unlockdescriptor;
520 if(NULL == pSensorHandle){
531 if (NULL == pDeviceDescriptor)
539 goto unlockdescriptor;
546 goto unlockdescriptor;
551 goto unlockdescriptor;
597 if(NULL == pSensorHandle){
637 if (NULL == pSensorHandle) {
659 if (NULL == pDeviceDescriptor){
677 if (kStatus_OSA_Success != OSA_SemaWait(&pDeviceDescriptor->
deviceSemaphore, OSA_WAIT_FOREVER))
679 goto unlockdescriptor;
686 goto unlockdescriptor;
692 #ifdef DEBUG_READ_ALL_REGS
693 for (
int i=0; i<
sizeof(debugRegs); i++)
711 if (sampleCount == 0)
724 for (sample=0; sample < sampleCount; sample++)
727 pCurrentSampleBuffer->
timeStamp = currentTimestamp - ((sampleCount - (sample+1)) * pSpecificSettings->
samplePeriod);
742 pCurrentSampleBuffer->
accel[0]<<= 4;
743 pCurrentSampleBuffer->
accel[1]<<= 4;
744 pCurrentSampleBuffer->
accel[2]<<= 4;
767 *pFifoEntry = *pCurrentSampleBuffer;
775 pCurrentSampleBuffer,
805 void *pConvertedSample,
814 switch (convertToType)
818 pConverter = float_accel3d_converter;
820 pConverter = fixed_accel3d_converter;
822 pConverter = count_accel3d_converter;
828 if (pConverter == NULL)
831 retStat = pConverter(
833 (fxls8952_DataBuffer_t *)pNativeSample,
867 convertedSample->
accel[0] = nativeSample->
accel[0];
868 convertedSample->
accel[1] = nativeSample->
accel[1];
869 convertedSample->
accel[2] = nativeSample->
accel[2];
889 uint8 buffer[1] = {0x00};
893 const uint32 RESET_WAIT_MS = 1;
894 OSA_TimeDelay(RESET_WAIT_MS);
917 uint8 buffer[1] = {0x00};
920 if (whoami == buffer[0]) {
954 _mem_copy(pSource, &buffer[0], numBytes);
1051 uint8 i = 0, flag=0;
1055 if(fxls8952_odrTable[i].periodNormalMode == samplePeriod)
1084 static void _mem_copy(
const void *pSource,
void *pDestination,
int32 numBytes) {
1085 const uint8 *pSourceByte = pSource;
1086 uint8 *pDestinationByte = pDestination;
1087 while (numBytes--) {
1088 *pDestinationByte++ = *pSourceByte++;
isf_status_t dm_channel_start(dm_ChannelDescriptor_t *apChannelDescriptor)
This function starts a channel.
Standard raw type for three axes accelerometers.
void * pSensorSpecificSettings
void fsl_fxls8952_i2c_3D_accel_PeriodicCallback(void *pSensorHandle)
The callback function for the Bus Manager(BM).
int32 isf_EventHandler_RegisterEvent(eventCallback_t *pCallback, void *pUserData)
Standard fixed type for three axis accelerometers.
isf_timestamp_t timestamp
isf_SensorDataTypes_t fxls8952_SupportedDataTypes[]
uint32 isf_time_util_get_usec(void)
This API returns the time in microseconds.
isf_status_t dm_device_open(dm_ChannelDescriptor_t *apChannelDescriptor, void *apDevice, dm_DeviceDescriptor_t *apDeviceDescriptor)
This function creates a device handle for a device at a specified channel address.
isf_dsa_ControlData_t controlData
isf_fifo_status_t isf_fifo_lock(isf_fifo_t *pFifo)
Lock a sample buffer for exclusive access.
comm_State_t dm_channel_get_state(dm_ChannelDescriptor_t *apChannelDescriptor)
This function returns the channel state.
isf_fifo_status_t isf_fifo_unlock(isf_fifo_t *pFifo)
Release the exclusive access lock on a sample buffer.
isf_fifo_status_t isf_fifo_el_increment(isf_fifo_t *pFifo)
Routine increments the insert pointer after direct access.
the structure defines the ODR table between Hybrid and normal mode of device operation.
isf_sensors.h contains the ISF Generic Sensor definitions and data structures required when a client ...
#define FXLS8952_LE_BE_MASK
#define MAX_FXLS8952_DM_BYTES
API definitions, types, and macros for the Intelligent Sensing Framework (ISF) Bus Manager (BM)...
#define NUM_INTERNAL_ADDRESS_BYTES
dm_DeviceDescriptor_t deviceHandle
This defines the DSA sensor device handle structure used to invoke the adapter access functions...
isf_dsa_status_t fsl_fxls8952_i2c_3D_accel_Shutdown(isf_SensorHandle_t *pSensorHandle)
This is the concrete implementation of the FXLS8952 sensor adapter for shutdown . ...
isf_dsa_status_t fsl_fxls8952_i2c_3D_accel_Calibrate(isf_SensorHandle_t *pSensorHandle, void *pCalData)
This is the concrete implementation of the FXLS8952 sensor adapter for calibration ...
Define the sensor device descriptor.
isf_dsa_status_t fsl_fxls8952_i2c_3D_accel_ValidateSettings(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
This is the concrete implementation of the FXLS8952 sensor adapter for validating current settings...
isf_dsa_status_t fsl_fxls8952_i2c_3D_accel_Configure(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
This is the concrete implementation of the FXLS8952 sensor adapter for configuration.
The fxls8952.h contains the FXLS8952 Accelerometer register definitions, access macros, and device access functions.
isf_dsa_status_t fsl_fxls8952_i2c_3D_accel_Initialize(isf_SensorHandle_t *pSensorHandle)
This is the concrete implementation of the FXLS8952 sensor adapter initialization.
dm_ChannelDescriptor_t cDescriptor
isf_status_t dm_device_write(dm_DeviceDescriptor_t *apDeviceDescriptor, int32 aOffset, uint8 *apWriteBuffer, uint32 aBuffsize, uint32 aNbyteWrite)
This function writes to a device.
isf_status_t bm_unregister_callback(bm_callback_token_t aToken)
This API unregisters one or more callbacks.
uint8 accelFullScaleRange
The isf_types.h file contains the ISF data type definitions and some of the globally used macros...
isf_acceleration_g_fixed_32s1i16_t accel[3]
int32 isf_dsa_status_t
This is the Sensor Manager API return type definition.
const struct @19 fxls8952AccelConvTable[]
uint16 isf_swap2byte(uint16 n)
2 byte swapping method
const fxls8952_ODR_Table_t fxls8952_odrTable[]
The table that describes the configuration value based on ODR (output data rate). Note: This table is...
#define FXLS8952_WHOAMI_VALUE
isf_acceleration_g_float_t accel[3]
int32 fxls8952_Status_t
fxls8952 internal return codes.
isf_status_t dm_channel_acquire_lock(dm_ChannelDescriptor_t *apChannelDescriptor, isf_duration_t aTimeout)
This function locks the channel for exclusive access.
The isf_sensor_types.h contains the enumerated list of sensor types used by ISF.
#define FXLS8952_SRC_DRDY_MASK
The isf_util.h file contains the utility method declarations and macros.
enum isf_dsa_result_enums isf_dsa_result_types_t
fxls8952_Sensor_Specific_Reg_t regPairs[]
int32 isf_EventHandler_GetSignal(uint32 token)
bm_callback_token_t bm_register_periodic_callback(isf_duration_t aPeriod, bm_callback_t *pCallback, void *pCbData)
This API schedules a callback at the specified period.
isf_SensorTypes_t fxls8952_SupportedSensorTypes[]
Supported sensor and data types for FXLS8952.
The fsl_fxls8952_i2c_3D_accel.h file contains the definitions and functions supporting the FXLS8952 S...
isf_dsa_result_types_t resultFormat
isf_dsa_status_t fsl_fxls8952_i2c_3D_accel_Convert(volatile isf_SensorHandle_t *pSensorHandle, isf_SensorDataTypes_t convertToType, isf_dsa_result_types_t resultType, void *pNativeSample, void *pConvertedSample, int32 *numBytes)
This function coverts the raw sample data to the desired output type.
isf_status_t dm_channel_init(dm_ChannelId_t aChannelId, dm_ChannelDescriptor_t *apChannelDescriptor)
This function initializes a channel.
enum fxls8952_Power_tag fxls8952_Power_t
Enumeration for the fxls8952 power modes.
isf_timestamp_t timestamp
isf_status_t bm_stop(bm_callback_token_t aTokens)
This API stops one or more callback(s) by setting them to the inactive state.
const isf_SensorConfig_t * pSensorStaticConfig
isf_status_t bm_start(boolean aSync, bm_callback_token_t aTokens)
This API sets one or more callback(s) to the active state.
uint32 isf_duration_t
ISF time duration in microseconds.
isf_SensorDataTypes_t resultType
Main ISF header file. Contains code common to all ISF components.
The isf_sm_api.h contains the collection of APIs for the Sensor Manager as well as related defines an...
isf_dsa_AdapterStatus_t adapterStatus
sys_channelId_t channelId
unsigned short int uint16
Standard float type for three axis accelerometers.
isf_dsa_status_t fsl_fxls8952_i2c_3D_accel_StartData(isf_SensorHandle_t *pSensorHandle)
This is the concrete implementation of the FXLS8952 sensor adapter for start Data.
int32 isf_EventHandler_UnregisterEvent(uint32 token)
isf_fifo_t * pSampleBufferInfo
isf_status_t dm_device_read(dm_DeviceDescriptor_t *apDeviceDescriptor, int32 aOffset, uint8 *apReadBuffer, uint32 aBuffsize, uint32 aNbyteRead)
This function reads from a device.
#define BM_ERROR
This value specifies a general Bus Manager error. If an error occurs in registering a callback...
int32 isf_status_t
ISF return status type.
This defines the DSA sensor configuration parameter structure configuring the sensor settings by a su...
isf_comm.h defines the common types for the Communications Service Family of the Intelligent Sensing ...
isf_dsa_SensorSettings_t sensorSettings
isf_timestamp_t timestamp
#define FXLS8952_SET_FIELD(name, val)
#define FXLS8952_BUF_FLUSH_MASK
void * isf_fifo_el_get_insert_pointer(isf_fifo_t *pFifo)
Routine returns the insert pointer for direct access.
isf_status_t dm_channel_release_lock(dm_ChannelDescriptor_t *apChannelDescriptor)
This function releases exclusive channel access.
This structure defines a handle for the device.
#define FXLS8952_GET_FIELD(name, val)
#define FXLS8952_ACTIVE_MASK
The isf_accelerometer_types.h file contains the ISF data type definitions for use with the ISF generi...
semaphore_t deviceSemaphore
This structure is a declaration of a channel descriptor type.
isf_dsa_status_t fsl_fxls8952_i2c_3D_accel_EndData(isf_SensorHandle_t *pSensorHandle)
This is the concrete implementation of the FXLS8952 sensor adapter for End Data.
isf_acceleration_g_rawCount_t accel[3]
bm_callback_token_t token
This structure defines the dummy DSA data buffer format.