21 #include "fsl_os_abstraction.h"
23 #include "fsl_i2c_master_driver.h"
28 #define MAG3110_MAG_FLOAT_CONVERSION_FACTOR (0.1)
29 #define MAG3110_MAG_FLOAT_CONVERSION_OFFSET (0.0)
30 #define MAG3110_MAG_FIXED_CONVERSION_FACTOR (6554)
31 #define MAG3110_MAG_FIXED_CONVERSION_OFFSET (0)
64 if ( NULL == pSensorHandle){
82 if (NULL == pDeviceDescriptor) {
91 pCurrentSampleBuffer->
mag[0] = 0;
92 pCurrentSampleBuffer->
mag[1] = 0;
93 pCurrentSampleBuffer->
mag[2] = 0;
132 if (kStatus_OSA_Success != OSA_SemaCreate(&pDeviceDescriptor->
deviceSemaphore, 1)){
159 if ((NULL == pSensorHandle) || (NULL == pSubSettings)) {
186 #ifdef DEBUG_READ_ALL_REGS
187 static uint8 debugRegs[18];
192 if((NULL == pSensorHandle) || (NULL == pSensorSettings) ){
204 if (NULL == pDeviceDescriptor)
215 goto unlockdescriptor;
221 goto unlockdescriptor;
236 #ifdef DEBUG_READ_ALL_REGS
237 for (
int i=0; i<
sizeof(debugRegs); i++)
289 if(NULL == pSensorHandle){
300 if (NULL == pDeviceDescriptor)
310 goto unlockdescriptor;
316 goto unlockdescriptor;
321 goto unlockdescriptor;
352 if(NULL == pSensorHandle){
365 if (NULL == pDeviceDescriptor)
374 goto unlockdescriptor;
381 goto unlockdescriptor;
388 goto unlockdescriptor;
438 if(NULL == pSensorHandle){
467 if(NULL == pSensorHandle){
481 if (NULL == pDeviceDescriptor){
500 if (kStatus_OSA_Success !=OSA_SemaWait(&pDeviceDescriptor->
deviceSemaphore, OSA_WAIT_FOREVER))
502 goto unlockdescriptor;
509 goto unlockdescriptor;
520 #ifdef DEBUG_READ_ALL_REGS
521 for (
int i=0; i<
sizeof(debugRegs); i++)
537 *pFifoEntry = *pCurrentSampleBuffer;
545 pCurrentSampleBuffer,
578 void *pConvertedSample,
587 switch (convertToType)
591 pConverter = float_magfs3d_converter;
593 pConverter = fixed_magfs3d_converter;
595 pConverter = count_magfs3d_converter;
601 if (pConverter == NULL)
604 retStat = pConverter(
606 (mag3110_DataBuffer_t *)pNativeSample,
715 uint8 buffer[1] = {0x00};
795 for (
uint32 reg=0; reg < pConfigSpecific->regCount; reg++)
797 buffer[0] = pConfigSpecific->regPairs[reg].regValue;
807 #if 0 // Mode is no longer set through subscription
808 uint8 buffer[1] = {0x00};
809 if((FSL_MAG3110_MODE_NON_RAW_FAST == pSubSettings->nMode) || (FSL_MAG3110_MODE_RAW_FAST == pSubSettings->nMode)){
909 shiftedPeriod = (cfg->
period)>>(*osbits+2);
914 op =
ff1(shiftedPeriod);
922 while ( opl > 20 && *osbits ) {
931 while ( opl < 13 && (*osbits < 3) ) {
939 if ( op > 20) opl = 20;
940 if ( op < 13) opl = 13;
943 *ratebits = 20 - opl;
946 cfg->
period = 12500<<(*ratebits + *osbits);
isf_status_t dm_channel_start(dm_ChannelDescriptor_t *apChannelDescriptor)
This function starts a channel.
void * pSensorSpecificSettings
This structure defines the dummy DSA data buffer format.
isf_dsa_status_t fsl_mag3110_i2c_3D_mag_Calibrate(isf_SensorHandle_t *pSensorHandle, void *pCalData)
isf_dsa_status_t fsl_mag3110_i2c_3D_mag_Shutdown(isf_SensorHandle_t *pSensorHandle)
void fsl_mag3110_i2c_3D_mag_PeriodicCallback(void *pSensorHandle)
Standard fixed type for three axis accelerometers.
The isf_magnetometer_types.h file contains the ISF data type definitions for use with the ISF generic...
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.
#define MAG3110_MAG_FIXED_CONVERSION_OFFSET
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_microTeslas_raw_16count_t fieldStrength[3]
isf_timestamp_t timestamp
isf_fifo_status_t isf_fifo_el_increment(isf_fifo_t *pFifo)
Routine increments the insert pointer after direct access.
isf_sensors.h contains the ISF Generic Sensor definitions and data structures required when a client ...
#define MAG3110_MAG_FLOAT_CONVERSION_OFFSET
void mag3110_Reset(int32_t *status, isf_SensorHandle_t *pSensorHandle)
This function resets the MAG3110 sensor resulting in a default configuration for all registers...
isf_fieldStrength_uT_float_t fieldStrength[3]
API definitions, types, and macros for the Intelligent Sensing Framework (ISF) Bus Manager (BM)...
dm_DeviceDescriptor_t deviceHandle
This defines the DSA sensor device handle structure used to invoke the adapter access functions...
isf_SensorDataTypes_t TYPE_MAGNETIC_FIELD_STRENGTH_3D
The fsl_mag3110_i2c_3D_mag.h file contains the definitions and functions supporting the MAG3110 Senso...
Define the sensor device descriptor.
isf_microTeslas_fixed_32s1i16_t fieldStrength[3]
isf_dsa_status_t fsl_mag3110_i2c_3D_mag_EndData(isf_SensorHandle_t *pSensorHandle)
uint8 get_config_bits(mag_config_t *cfg, uint8 *ratebits, uint8 *osbits)
This function obtains the configuration register values for a given user configuration of the MAG3110...
dm_ChannelDescriptor_t cDescriptor
isf_dsa_status_t fsl_mag3110_i2c_3D_mag_Initialize(isf_SensorHandle_t *pSensorHandle)
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.
isf_dsa_status_t fsl_mag3110_i2c_3D_mag_ValidateSettings(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSubSettings)
The isf_types.h file contains the ISF data type definitions and some of the globally used macros...
isf_dsa_status_t fsl_mag3110_i2c_3D_mag_Configure(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
isf_timestamp_t timestamp
isf_SensorDataTypes_t mag3110_SupportedDataTypes[]
The mag3110.h contains the MAG3110 Magnetometer register definitions, access macros, and device access functions.
int32 isf_dsa_status_t
This is the Sensor Manager API return type definition.
uint16 isf_swap2byte(uint16 n)
2 byte swapping method
isf_SensorTypes_t mag3110_SupportedSensorTypes[]
Supported sensor and data types for MMA8652.
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.
The isf_util.h file contains the utility method declarations and macros.
enum isf_dsa_result_enums isf_dsa_result_types_t
uint32 ff1(uint32 doubleword)
find first-in.
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.
void mag3110_CheckId(int32_t *status, isf_SensorHandle_t *pSensorHandle)
This function validates the MAG3110 sensor is connected via the I2C bus.
#define MAG3110_MAG_FIXED_CONVERSION_FACTOR
isf_dsa_result_types_t resultFormat
isf_status_t dm_channel_init(dm_ChannelId_t aChannelId, dm_ChannelDescriptor_t *apChannelDescriptor)
This function initializes a channel.
void mag3110_SetMode(int32_t *status, isf_SensorHandle_t *pSensorHandle, int32_t Mode)
This function sets the MAG3110 part to the requested mode.
#define MAG3110_SET_FIELD(name, val)
void mag3110_GetData(int32_t *status, isf_SensorHandle_t *pSensorHandle, void *pBuffer)
This function retrieves the raw data from the MAG3110 sensor.
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.
isf_timestamp_t timestamp
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...
The structure defines the MAG3110 configuration.
isf_dsa_AdapterStatus_t adapterStatus
sys_channelId_t channelId
isf_dsa_status_t fsl_mag3110_i2c_3D_mag_StartData(isf_SensorHandle_t *pSensorHandle)
#define MAG3110_NUMBER_BYTES_AXIS
#define MAG3100_READ_BUF_SIZE
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
#define MAG3110_WHOAMI_VALUE
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.
void mag3110_ValidateConfig(int32_t *status, isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSubSettings)
This function validates the configuration for the MAG3110 sensor.
isf_SensorDataTypes_t TYPE_MAGNETIC_FIELD_STRENGTH_3D
isf_dsa_status_t fsl_mag3110_i2c_3D_mag_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.
#define MAG3110_MAG_FLOAT_CONVERSION_FACTOR
semaphore_t deviceSemaphore
This structure is a declaration of a channel descriptor type.
bm_callback_token_t token
void mag3110_SetConfig(int32_t *status, isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSubSettings)
This function sets the MAG3110 sensor configuration.
#define MAG3110_NUMBER_AXIS
The MAG3110 registers, masks, and constants.