ISSDK  1.7
IoT Sensing Software Development Kit
fxas21002_fifo.c
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /**
36  * @file fxas21002_fifo.c
37  * @brief The fxas21002_fifo.c file implements the ISSDK FXAS21002 sensor driver
38  * example demonstration with FIFO mode.
39  */
40 
41 /* SDK Includes */
42 #include "board.h"
43 #include "pin_mux.h"
44 #include "clock_config.h"
45 #include "fsl_debug_console.h"
46 
47 /* CMSIS Includes */
48 #include "Driver_I2C.h"
49 
50 /* ISSDK Includes */
51 #include "issdk_hal.h"
52 #include "fxas21002_drv.h"
53 
54 /*******************************************************************************
55  * Macro Definitions
56  ******************************************************************************/
57 /*---------------------------------------------------------------------------*/
58 /*! @def FIFO_SIZE
59  * @brief The watermark value configured for FXAS21002 FIFO Buffer.
60  */
61 #define FIFO_SIZE 4
62 
63 /*******************************************************************************
64  * Constants
65  ******************************************************************************/
66 /*! Prepare the register write list to configure FXAS21002 in FIFO mode. */
68  /*! Configure CTRL_REG1 register to put FXAS21002 to 12.5Hz sampling rate. */
70  /*! Configure F_SETUP register to set FIFO in Stop mode, Watermark of 16. */
75 
76 /*! Prepare the register read list to read FXAS21002 FIFO event. */
78 
79 /*! Prepare the register read list to read the raw gyro data from the FXAS21002. */
82 
83 /*******************************************************************************
84  * Code
85  ******************************************************************************/
86 /*!
87  * @brief Main function
88  */
89 int main(void)
90 {
92  uint8_t fifoEvent;
95 
96  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER; // Now using the shield.h value!!!
97  fxas21002_i2c_sensorhandle_t FXAS21002drv;
98 
99  /*! Initialize the MCU hardware. */
100  BOARD_InitPins();
103 
104  PRINTF("\r\n ISSDK FXAS21002 sensor driver example demonstration with fifo mode\r\n");
105 
106  /*! Initialize the I2C driver. */
107  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
108  if (ARM_DRIVER_OK != status)
109  {
110  PRINTF("\r\n I2C Initialization Failed\r\n");
111  return -1;
112  }
113 
114  /*! Set the I2C Power mode. */
115  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
116  if (ARM_DRIVER_OK != status)
117  {
118  PRINTF("\r\n I2C Power Mode setting Failed\r\n");
119  return -1;
120  }
121 
122  /*! Set the I2C bus speed. */
123  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
124  if (ARM_DRIVER_OK != status)
125  {
126  PRINTF("\r\n I2C Control Mode setting Failed\r\n");
127  return -1;
128  }
129 
130  /*! Initialize the FXAS21002 sensor driver. */
133  if (SENSOR_ERROR_NONE != status)
134  {
135  PRINTF("\r\n Sensor Initialization Failed\r\n");
136  return -1;
137  }
138  PRINTF("\r\n Successfully Initiliazed Sensor\r\n");
139 
140  /*! Set the task to be executed while waiting for I2C transactions to complete. */
142 
143  /*! Configure the FXAS21002 sensor driver. */
144  status = FXAS21002_I2C_Configure(&FXAS21002drv, fxas21002_Config_with_Fifo);
145  if (SENSOR_ERROR_NONE != status)
146  {
147  PRINTF("\r\n FXAS21002 Sensor Configuration Failed, Err = %d\r\n", status);
148  return -1;
149  }
150  PRINTF("\r\n Successfully Applied FXAS21002 Sensor Configuration\r\n");
151 
152  for (;;) /* Forever loop */
153  {
154  /*! Wait for the FIFO watermark event. */
155  status = FXAS21002_I2C_ReadData(&FXAS21002drv, fxas21002_Fifo_Event, &fifoEvent);
156  if (0 == (fifoEvent & FXAS21002_F_EVENT_F_EVENT_MASK))
157  {
158  continue;
159  }
160 
161  /*! Read the raw sensor data from the FXAS21002. */
162  status = FXAS21002_I2C_ReadData(&FXAS21002drv, fxas21002_Output_Values, data);
163  if (ARM_DRIVER_OK != status)
164  {
165  PRINTF("\r\n Read Failed. \r\n");
166  return -1;
167  }
168 
169  for (uint8_t i = 0; i < FIFO_SIZE; i++)
170  {
171  /*! Convert the raw sensor data to signed 16-bit container for display to the debug port. */
172  rawData.gyro[0] =
173  ((int16_t)data[i * FXAS21002_GYRO_DATA_SIZE + 0] << 8) | data[i * FXAS21002_GYRO_DATA_SIZE + 1];
174  rawData.gyro[1] =
175  ((int16_t)data[i * FXAS21002_GYRO_DATA_SIZE + 2] << 8) | data[i * FXAS21002_GYRO_DATA_SIZE + 3];
176  rawData.gyro[2] =
177  ((int16_t)data[i * FXAS21002_GYRO_DATA_SIZE + 4] << 8) | data[i * FXAS21002_GYRO_DATA_SIZE + 5];
178  }
179  /* NOTE: PRINTF is relatively expensive in terms of CPU time, specially when used with-in execution loop. */
180  PRINTF("\r\n Gyro X = %d Y = %d Z = %d\r\n", rawData.gyro[0], rawData.gyro[1], rawData.gyro[2]);
181  ASK_USER_TO_RESUME(100 / FIFO_SIZE); /* Ask for user input after processing 100 samples. */
182  }
183 }
#define FXAS21002_F_EVENT_F_EVENT_MASK
Definition: fxas21002.h:337
#define __END_WRITE_DATA__
Definition: sensor_drv.h:71
#define BOARD_BootClockRUN
Definition: clock_config.h:45
#define FXAS21002_CTRL_REG1_DR_MASK
Definition: fxas21002.h:710
#define FIFO_SIZE
The watermark value configured for FXAS21002 FIFO Buffer.
uint8_t data[FXLS8962_DATA_SIZE]
int32_t status
void BOARD_InitDebugConsole(void)
Definition: board.c:41
#define FXAS21002_F_SETUP_F_MODE_MASK
Definition: fxas21002.h:299
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:123
The fxas21002_drv.h file describes the fxas21002 driver interface and structures. ...
int main(void)
Main function.
#define __END_READ_DATA__
Definition: sensor_drv.h:77
const registerreadlist_t fxas21002_Fifo_Event[]
This structure defines the fxas21002 raw data buffer.
Definition: fxas21002_drv.h:79
This defines the sensor specific information for I2C.
Definition: fxas21002_drv.h:70
#define ASK_USER_TO_RESUME(x)
Definition: frdm_k64f.h:132
const registerreadlist_t fxas21002_Output_Values[]
#define FXAS21002_F_SETUP_F_WMRK_SHIFT
Definition: fxas21002.h:297
int32_t FXAS21002_I2C_ReadData(fxas21002_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
#define FXAS21002_F_SETUP_F_WMRK_MASK
Definition: fxas21002.h:296
#define I2C_S_DEVICE_INDEX
Definition: issdk_hal.h:61
#define FXAS21002_WHO_AM_I_WHOAMI_PROD_VALUE
Definition: fxas21002.h:428
#define FXAS21002_I2C_ADDR
int32_t FXAS21002_I2C_Configure(fxas21002_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
#define I2C_S_DRIVER
Definition: issdk_hal.h:59
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
void FXAS21002_I2C_SetIdleTask(fxas21002_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
fxls8962_acceldataUser_t rawData
#define FXAS21002_CTRL_REG3_WRAPTOONE_ROLL_DATA
Definition: fxas21002.h:874
This structure defines the Write command List.
Definition: sensor_drv.h:94
#define FXAS21002_F_SETUP_F_MODE_STOP_MODE
Definition: fxas21002.h:308
This structure defines the Read command List.
Definition: sensor_drv.h:104
#define SMC
Definition: lpc54114.h:144
#define FXAS21002_GYRO_DATA_SIZE
The size of the FXAS21002 gyro data.
Definition: fxas21002_drv.h:87
status_t SMC_SetPowerModeWait(void *arg)
Configures the system to WAIT power mode. API name used from Kinetis family to maintain compatibility...
Definition: lpc54114.c:181
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
Definition: pin_mux.c:73
#define FXAS21002_CTRL_REG1_DR_12_5HZ
Definition: fxas21002.h:736
#define I2C_S_SIGNAL_EVENT
Definition: issdk_hal.h:60
int32_t FXAS21002_I2C_Initialize(fxas21002_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi)
The interface function to initialize the sensor.
const registerwritelist_t fxas21002_Config_with_Fifo[]
#define FXAS21002_CTRL_REG3_WRAPTOONE_MASK
Definition: fxas21002.h:855