| ISF 2.2 rev 5 Intelligent Sensing Framework for Kinetis with Processor Expert

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Macros | Functions | Variables
fsl_mag3110_i2c_3D_mag.c File Reference

MAG3110 Sensor Adapter header file. More...

`#include <isf.h>`
`#include <isf_types.h>`
`#include <isf_sm_api.h>`
`#include <isf_dsa_adapter.h>`
`#include <isf_bm.h>`
`#include <isf_sensor_types.h>`
`#include <isf_fifo.h>`
`#include <isf_magnetometer_types.h>`
`#include <isf_comm.h>`
`#include <isf_util.h>`
`#include <isf_sensors.h>`
`#include "fsl_os_abstraction.h"`
`#include "mag3110.h"`
`#include "fsl_i2c_master_driver.h"`
`#include "fsl_mag3110_i2c_3D_mag.h"`
Include dependency graph for fsl_mag3110_i2c_3D_mag.c:

Go to the source code of this file.

## Macros
#define | MAG3110_MAG_FLOAT_CONVERSION_FACTOR (0.1)
#define | MAG3110_MAG_FLOAT_CONVERSION_OFFSET (0.0)
#define | MAG3110_MAG_FIXED_CONVERSION_FACTOR (6554)
#define | MAG3110_MAG_FIXED_CONVERSION_OFFSET (0)

## Functions
void | mag3110_Reset (int32_t *status, isf_SensorHandle_t *pSensorHandle)
| This function resets the MAG3110 sensor resulting in a default configuration for all registers. More...
void | mag3110_CheckId (int32_t *status, isf_SensorHandle_t *pSensorHandle)
| This function validates the MAG3110 sensor is connected via the I2C bus. More...
void | mag3110_ValidateConfig (int32_t *status, isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSubSettings)
| This function validates the configuration for the MAG3110 sensor. More...
void | mag3110_SetMode (int32_t *status, isf_SensorHandle_t *pSensorHandle, int32_t Mode)
| This function sets the MAG3110 part to the requested mode. More...
void | mag3110_GetData (int32_t *status, isf_SensorHandle_t *pSensorHandle, void *pBuffer)
| This function retrieves the raw data from the MAG3110 sensor. More...
void | mag3110_SetConfig (int32_t *status, isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSubSettings)
| This function sets the MAG3110 sensor configuration. More...
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. More...
isf_dsa_status_t | fsl_mag3110_i2c_3D_mag_Initialize (isf_SensorHandle_t *pSensorHandle)
isf_dsa_status_t | fsl_mag3110_i2c_3D_mag_ValidateSettings (isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSubSettings)
isf_dsa_status_t | fsl_mag3110_i2c_3D_mag_Configure (isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
isf_dsa_status_t | fsl_mag3110_i2c_3D_mag_StartData (isf_SensorHandle_t *pSensorHandle)
isf_dsa_status_t | fsl_mag3110_i2c_3D_mag_EndData (isf_SensorHandle_t *pSensorHandle)
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)
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. More...

## Variables
isf_SensorTypes_t | mag3110_SupportedSensorTypes [] = { TYPE_MAGNETOMETER_3D, TYPE_NATIVE_SENSOR_TYPE }
| Supported sensor and data types for MMA8652. More...
isf_SensorDataTypes_t | mag3110_SupportedDataTypes [] = { TYPE_MAGNETIC_FIELD_STRENGTH_3D, TYPE_NATIVE_SENSOR_DATA_TYPE }

## Detailed Description

MAG3110 Sensor Adapter header file.

Copyright
  Copyright (c) 2015, Freescale Semiconductor, Inc.

Version
  01.00

Definition in file fsl_mag3110_i2c_3D_mag.c.

## Macro Definition Documentation

#define MAG3110_MAG_FIXED_CONVERSION_FACTOR (6554)

Definition at line 30 of file fsl_mag3110_i2c_3D_mag.c.

#define MAG3110_MAG_FIXED_CONVERSION_OFFSET (0)

Definition at line 31 of file fsl_mag3110_i2c_3D_mag.c.

#define MAG3110_MAG_FLOAT_CONVERSION_FACTOR (0.1)

Definition at line 28 of file fsl_mag3110_i2c_3D_mag.c.

#define MAG3110_MAG_FLOAT_CONVERSION_OFFSET (0.0)

Definition at line 29 of file fsl_mag3110_i2c_3D_mag.c.

## Function Documentation

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.

This function computes the rate bits (DR2, DR1, DR0) and oversample bits (OS1, OS0) corresponding to the requested configuration provided by the configuration. If the requested configuration is not supported, the configuration is adjusted to the closest supported rate and the adjusted values are returned. get_config_bits() uses binary bit operations to move between the MAG3110's rate and the oversample bit configuration patterns. The sample period is in usecs.

For example, when the rateBits are all zeros, the sample period is 12500 usecs. As the rateBits are provided as a 3 digit binary number, each increment of rateBits doubles the period. In general: Rate = 12500 << rateBits.

The oversample bits determine how many samples are taken internally for each output sample. With the OsBits viewed as a 2 digit binary number, an OsBits value of 0 means an over sample rate of 16 and each increment of the OsBits doubles the over sample rate. In general: Over sample Rate = 1 <<(OsBits + 4) The internal ADC sample period is then: ADC period = 12500 << ( rateBits + OsBits )

Given an arbitrary period in usecs and a desired over sample rate, the closest supported adc rate is computed by performing the following: The requested period is right shifted by the OsBits value + 2. This produces a normalized value of 3125 decimal for the the smallest supported rate (12500 usecs at 16x over sampling). 3125 decimal is 0b110000110101 and a findFirstOne (ff1) on this returns 20.

Since all supported rates are powers of 2 larger than this base number, a findFirstOne(ff1) is performed on this normalized rate and subtracting it from 20 is the number of rateBits that must be set to get the desired rate. If this is too large, the number can be limited to the maximum rateBits allowed (7) and/or the over sampling rate can be reduced to lower the internal ADC rate to an acceptable rate.

Parameters

  [in] | cfg | Magnetometer configuration information. mag_config_t is the structure type.
  [out] | ratebits | The data rate configuration bits.
  [out] | osbits | The over sample configuration bits.

Returns
  get_config_bits() returns a value of type uint8 indicating the success or failure of the function call.

Return values

  0 | is returned when the configuration is valid.
  1 | is returned when the configuration is modified.

Constraints:
  None

Reentrant: Yes

Link Libraries:
  lib_fsl_mag3110_i2c_3D_mag.lib

Definition at line 898 of file fsl_mag3110_i2c_3D_mag.c.

References ff1(), mag_config_t::overSampleRate, and mag_config_t::period.

Referenced by mag3110_SetConfig(), and mag3110_ValidateConfig().

Here is the call graph for this function:

Here is the caller graph for this function:

void mag3110_CheckId | ( | int32_t * | status,
|  | isf_SensorHandle_t * | pSensorHandle
| ) |  |

This function validates the MAG3110 sensor is connected via the I2C bus.

Definition at line 659 of file fsl_mag3110_i2c_3D_mag.c.

References DeviceDescriptor_struct::deviceHandle, dm_device_read(), ISF_SUCCESS, MAG3110_WHO_AM_I, MAG3110_WHOAMI_VALUE, isf_SensorHandle_st::pDeviceDescriptor, and SENSOR_ERROR_CHECKID.

Referenced by fsl_mag3110_i2c_3D_mag_Initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

void mag3110_GetData | ( | int32_t * | status,
|  | isf_SensorHandle_t * | pSensorHandle,
|  | void * | pBuffer
| ) |  |

This function retrieves the raw data from the MAG3110 sensor.

Definition at line 760 of file fsl_mag3110_i2c_3D_mag.c.

References DeviceDescriptor_struct::deviceHandle, dm_device_read(), ISF_SUCCESS, MAG3100_READ_BUF_SIZE, MAG3110_OUT_X_MSB, isf_SensorHandle_st::pDeviceDescriptor, and SENSOR_ERROR_GETDATA.

Referenced by fsl_mag3110_i2c_3D_mag_PeriodicCallback().

Here is the call graph for this function:

Here is the caller graph for this function:

void mag3110_Reset | ( | int32_t * | status,
|  | isf_SensorHandle_t * | pSensorHandle
| ) |  |

This function resets the MAG3110 sensor resulting in a default configuration for all registers.

Definition at line 651 of file fsl_mag3110_i2c_3D_mag.c.

References ISF_SUCCESS.

void mag3110_SetConfig | ( | int32_t * | status,
|  | isf_SensorHandle_t * | pSensorHandle,
|  | isf_dsa_SensorSettings_t * | pSubSettings
| ) |  |

This function sets the MAG3110 sensor configuration.

Definition at line 780 of file fsl_mag3110_i2c_3D_mag.c.

References DeviceDescriptor_struct::dataBlockSize, DeviceDescriptor_struct::deviceHandle, dm_device_read(), dm_device_write(), DSA_ERR_CONFIGURE, DSA_RET_SETTINGS_CHANGED, get_config_bits(), ISF_SUCCESS, MAG3110_CTRL_REG1, MAG3110_NUMBER_AXIS, MAG3110_NUMBER_BYTES_AXIS, MAG3110_SET_FIELD, isf_dsa_SensorSettings_st::nSamplePeriod, mag_config_t::overSampleRate, isf_SensorHandle_st::pDeviceDescriptor, mag_config_t::period, SensorConfig_st::pSensorSpecificSettings, and isf_SensorHandle_st::pSensorStaticConfig.

Referenced by fsl_mag3110_i2c_3D_mag_Configure().

Here is the call graph for this function:

Here is the caller graph for this function:

void mag3110_SetMode | ( | int32_t * | status,
|  | isf_SensorHandle_t * | pSensorHandle,
|  | int32_t | Mode
| ) |  |

This function sets the MAG3110 part to the requested mode.

Definition at line 710 of file fsl_mag3110_i2c_3D_mag.c.

References DeviceDescriptor_struct::deviceHandle, and isf_SensorHandle_st::pDeviceDescriptor.

Referenced by fsl_mag3110_i2c_3D_mag_Configure(), fsl_mag3110_i2c_3D_mag_EndData(), and fsl_mag3110_i2c_3D_mag_StartData().

Here is the caller graph for this function:

void mag3110_ValidateConfig | ( | int32_t * | status,
|  | isf_SensorHandle_t * | pSensorHandle,
|  | isf_dsa_SensorSettings_t * | pSubSettings
| ) |  |

This function validates the configuration for the MAG3110 sensor.

Definition at line 682 of file fsl_mag3110_i2c_3D_mag.c.

References DSA_RET_SETTINGS_CHANGED, get_config_bits(), ISF_SUCCESS, isf_dsa_SensorSettings_st::nSamplePeriod, mag_config_t::overSampleRate, mag3110_Sensor_Specific_Settings_t::overSamplingRatio, mag_config_t::period, SensorConfig_st::pSensorSpecificSettings, and isf_SensorHandle_st::pSensorStaticConfig.

Referenced by fsl_mag3110_i2c_3D_mag_ValidateSettings().

Here is the call graph for this function:

Here is the caller graph for this function:
- © Freescale Semiconductor, Inc. 2016. All Rights Reserved.