ISSDK  1.8
IoT Sensing Software Development Kit
fxpq3115_normal_interrupt.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /**
10  * @file fxpq3115_normal_interrupt.c
11  * @brief The fxpq3115_normal_interrupt.c file implements the ISSDK FXPQ3115BV sensor driver
12  * example demonstration with interrupt mode.
13  */
14 
15 //-----------------------------------------------------------------------
16 // SDK Includes
17 //-----------------------------------------------------------------------
18 #include "pin_mux.h"
19 #include "clock_config.h"
20 #include "board.h"
21 #include "fsl_debug_console.h"
22 
23 //-----------------------------------------------------------------------
24 // CMSIS Includes
25 //-----------------------------------------------------------------------
26 #include "Driver_I2C.h"
27 
28 //-----------------------------------------------------------------------
29 // ISSDK Includes
30 //-----------------------------------------------------------------------
31 #include "issdk_hal.h"
32 #include "gpio_driver.h"
33 #include "fxpq3115_drv.h"
34 
35 //-----------------------------------------------------------------------
36 // Macros
37 //-----------------------------------------------------------------------
38 #define FXPQ3115_DATA_SIZE (5) /* 3 byte Pressure/Altitude and 2 byte Temperature. */
39 /*! In FXPQ3115 the Auto Acquisition Time Step (ODR) can be set only in powers of 2 (i.e. 2^x, where x is the
40  * SAMPLING_EXPONENT).
41  * This gives a range of 1 second to 2^15 seconds (9 hours). */
42 #define FXPQ3115_SAMPLING_EXPONENT (1) /* 2 seconds */
43 
44 //-----------------------------------------------------------------------
45 // Constants
46 //-----------------------------------------------------------------------
47 /*! @brief Register settings for Interrupt (non buffered) mode. */
49  /* Enable Data Ready and Event flags for Pressure, Temperature or either. */
53  /* Set Over Sampling Ratio to 128. */
55  /* Set Auto acquisition time step. */
57  /* Set INT1 Active High. */
59  /* Enable Interrupts for Data Ready Events. */
61  /* Route Interrupt to INT1. */
64 
65 /*! @brief Address and size of Raw Pressure+Temperature Data in Normal Mode. */
68 
69 //-----------------------------------------------------------------------
70 // Global Variables
71 //-----------------------------------------------------------------------
72 volatile uint8_t gB3115DataReady;
73 
74 //-----------------------------------------------------------------------
75 // Functions
76 //-----------------------------------------------------------------------
77 /*! -----------------------------------------------------------------------
78  * @brief This is the Sensor Data Ready ISR implementation.
79  * @details This function sets the flag which indicates if a new sample(s) is available for reading.
80  * @param[in] pUserData This is a void pointer to the instance of the user specific data structure for the ISR.
81  * @return void There is no return value.
82  * @constraints None
83  * @reeentrant Yes
84  * -----------------------------------------------------------------------*/
85 void fxpq3115_int_data_ready_callback(void *pUserData)
86 { /*! @brief Set flag to indicate Sensor has signalled data ready. */
87  gB3115DataReady = true;
88 }
89 
90 /*! -----------------------------------------------------------------------
91  * @brief This is the The main function implementation.
92  * @details This function invokes board initializes routines, then then brings up the sensor and
93  * finally enters an endless loop to continuously read available samples.
94  * @param[in] void This is no input parameter.
95  * @return void There is no return value.
96  * @constraints None
97  * @reeentrant No
98  * -----------------------------------------------------------------------*/
99 int main(void)
100 {
101  int16_t tempInDegrees;
102  uint32_t pressureInPascals;
103  int32_t status;
104  uint8_t data[FXPQ3115_DATA_SIZE];
106 
107  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER; // Now using the shield.h value!!!
108  fxpq3115_i2c_sensorhandle_t fxpq3115Driver;
110 
111  /*! Initialize the MCU hardware. */
112  BOARD_InitPins();
115 
116  PRINTF("\r\n ISSDK FXPQ3115 sensor driver example demonstration with interrupt mode.\r\n");
117 
118  /*! Initialize FXPQ3115BV pin used by FRDM board */
120 
121  /*! Initialize RGB LED pin used by FRDM board */
122  pGpioDriver->pin_init(&GREEN_LED, GPIO_DIRECTION_OUT, NULL, NULL, NULL);
123 
124  /*! Initialize the I2C driver. */
125  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
126  if (ARM_DRIVER_OK != status)
127  {
128  PRINTF("\r\n I2C Initialization Failed\r\n");
129  return -1;
130  }
131 
132  /*! Set the I2C Power mode. */
133  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
134  if (ARM_DRIVER_OK != status)
135  {
136  PRINTF("\r\n I2C Power Mode setting Failed\r\n");
137  return -1;
138  }
139 
140  /*! Set the I2C bus speed. */
141  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
142  if (ARM_DRIVER_OK != status)
143  {
144  PRINTF("\r\n I2C Control Mode setting Failed\r\n");
145  return -1;
146  }
147 
148  /*! Initialize FXPQ3115 sensor driver. */
151  if (SENSOR_ERROR_NONE != status)
152  {
153  PRINTF("\r\n Sensor Initialization Failed\r\n");
154  return -1;
155  }
156  PRINTF("\r\n Successfully Initiliazed Sensor\r\n");
157 
158  /*! Set the task to be executed while waiting for I2C transactions to complete. */
160 
161  gB3115DataReady = false;
162 
163  /*! Configure the FXPQ3115BV sensor driver. */
164  status = FXPQ3115_I2C_Configure(&fxpq3115Driver, B3115ConfigNormal);
165  if (SENSOR_ERROR_NONE != status)
166  {
167  PRINTF("\r\n FXPQ3115 Sensor Configuration Failed, Err = %d\r\n", status);
168  return -1;
169  }
170  PRINTF("\r\n Successfully Applied FXPQ3115 Sensor Configuration\r\n");
171 
172  for (;;) /* Forever loop */
173  { /* In ISR Mode we do not need to check Data Ready Register.
174  * The receipt of interrupt will indicate data is ready. */
175  if (false == gB3115DataReady)
176  { /* Loop, if new sample is not available. */
178  continue;
179  }
180  else
181  { /*! Clear the data ready flag, it will be set again by the ISR. */
182  gB3115DataReady = false;
183  pGpioDriver->toggle_pin(&GREEN_LED);
184  }
185 
186  /*! Read new raw sensor data from the FXPQ3115. */
187  status = FXPQ3115_I2C_ReadData(&fxpq3115Driver, B3115OutputNormal, data);
188  if (ARM_DRIVER_OK != status)
189  {
190  PRINTF("\r\n Read Failed. \r\n");
191  return -1;
192  }
193 
194  /*! Process the sample and convert the raw sensor data to signed 16-bit container. */
195  rawData.pressure = (uint32_t)((data[0]) << 16) | ((data[1]) << 8) | ((data[2]));
196  pressureInPascals = rawData.pressure / FXPQ3115_PRESSURE_CONV_FACTOR;
197 
198  rawData.temperature = (int16_t)((data[3]) << 8) | (data[4]);
199  tempInDegrees = rawData.temperature / FXPQ3115_TEMPERATURE_CONV_FACTOR;
200 
201  /* NOTE: PRINTF is relatively expensive in terms of CPU time, specially when used with-in execution loop. */
202  PRINTF("\r\nPressure = %d Pa\r\n", pressureInPascals);
203  PRINTF("\r\nTemperature = %d degC\r\n", tempInDegrees);
204  ASK_USER_TO_RESUME(8); /* Ask for user input after processing 8 samples. */
205  }
206 }
#define FXPQ3115_PRESSURE_CONV_FACTOR
Definition: fxpq3115_drv.h:28
This structure defines the Write command List.
Definition: sensor_drv.h:68
#define FXPQ3115_CTRL_REG5_INT_CFG_DRDY_MASK
Definition: fxpq3115.h:1131
#define FXPQ3115_CTRL_REG4_INT_EN_DRDY_INTENABLED
Definition: fxpq3115.h:1073
#define ASK_USER_TO_RESUME(x)
Definition: frdm_k64f.h:106
int32_t status
status_t SMC_SetPowerModeVlpr(void *arg)
Configures the system to VLPR power mode. API name used from Kinetis family to maintain compatibility...
Definition: lpc54114.c:169
Access structure of the GPIO Driver.
Definition: Driver_GPIO.h:38
#define SMC
Definition: lpc54114.h:118
#define FXPQ3115_PT_DATA_CFG_TDEFE_MASK
Definition: fxpq3115.h:550
#define FXPQ3115_SAMPLING_EXPONENT
#define FXPQ3115_PT_DATA_CFG_TDEFE_ENABLED
Definition: fxpq3115.h:564
#define FXPQ3115_CTRL_REG3_IPOL1_HIGH
Definition: fxpq3115.h:993
#define FXPQ3115_CTRL_REG1_OS_MASK
Definition: fxpq3115.h:855
#define FXPQ3115_DATA_SIZE
#define __END_WRITE_DATA__
Definition: sensor_drv.h:45
This structure defines the fxpq3115 data buffer in Pressure Mode.
Definition: fxpq3115_drv.h:45
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
volatile uint8_t gB3115DataReady
#define FXPQ3115_PT_DATA_CFG_PDEFE_MASK
Definition: fxpq3115.h:553
#define I2C_S_SIGNAL_EVENT
Definition: issdk_hal.h:34
#define I2C_S_DRIVER
Definition: issdk_hal.h:33
int32_t FXPQ3115_I2C_Configure(fxpq3115_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: fxpq3115_drv.c:61
#define BOARD_BootClockRUN
Definition: clock_config.h:19
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
void FXPQ3115_I2C_SetIdleTask(fxpq3115_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: fxpq3115_drv.c:53
const registerwritelist_t B3115ConfigNormal[]
Register settings for Interrupt (non buffered) mode.
int32_t FXPQ3115_I2C_Initialize(fxpq3115_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi)
The interface function to initialize the sensor.
Definition: fxpq3115_drv.c:22
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
Definition: gpio_driver.c:177
GENERIC_DRIVER_GPIO * pGpioDriver
#define FXPQ3115_PT_DATA_CFG_DREM_MASK
Definition: fxpq3115.h:556
The fxpq3115_drv.h file describes the fxpq3115 driver interface and structures.
uint8_t data[FXLS8962_DATA_SIZE]
#define FXPQ3115_CTRL_REG4_INT_EN_DRDY_MASK
Definition: fxpq3115.h:1051
#define __END_READ_DATA__
Definition: sensor_drv.h:51
#define FXPQ3115_INT1
#define FXPQ3115_CTRL_REG5_INT_CFG_DRDY_INT1
Definition: fxpq3115.h:1153
const registerreadlist_t B3115OutputNormal[]
Address and size of Raw Pressure+Temperature Data in Normal Mode.
#define FXPQ3115_CTRL_REG1_OS_OSR_128
Definition: fxpq3115.h:887
ARM_DRIVER_I2C * I2Cdrv
fxos8700_accelmagdata_t rawData
#define FXPQ3115_CTRL_REG3_IPOL1_MASK
Definition: fxpq3115.h:979
#define FXPQ3115_PT_DATA_CFG_PDEFE_ENABLED
Definition: fxpq3115.h:567
uint16_t readFrom
Definition: sensor_drv.h:80
void(* toggle_pin)(pinID_t aPinId)
Definition: Driver_GPIO.h:48
#define FXPQ3115_WHOAMI_VALUE
Definition: fxpq3115.h:65
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:155
void fxpq3115_int_data_ready_callback(void *pUserData)
This is the Sensor Data Ready ISR implementation.
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
Definition: Driver_GPIO.h:41
This structure defines the Read command List.
Definition: sensor_drv.h:78
int main(void)
This is the The main function implementation.
#define FXPQ3115_I2C_ADDR
gpioHandleKSDK_t GREEN_LED
Definition: frdm_k64f.c:188
#define I2C_S_DEVICE_INDEX
Definition: issdk_hal.h:35
This defines the sensor specific information.
Definition: fxpq3115_drv.h:36
void BOARD_InitDebugConsole(void)
Definition: board.c:15
int32_t FXPQ3115_I2C_ReadData(fxpq3115_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: fxpq3115_drv.c:106
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
Definition: pin_mux.c:47
#define FXPQ3115_PT_DATA_CFG_DREM_ENABLED
Definition: fxpq3115.h:570
#define FXPQ3115_CTRL_REG2_ST_MASK
Definition: fxpq3115.h:919
#define FXPQ3115_TEMPERATURE_CONV_FACTOR
Definition: fxpq3115_drv.h:30