ISSDK  1.7
IoT Sensing Software Development Kit
demo_11_axis_mult2b.c
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2017, 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 demo_11_axis_mult2b.c
37  * @brief The demo_11_axis_mult2b.c file implements the ISSDK MMA8652, MAG3110, FXAS21002 and MPL3115 sensors
38  * 11-Axis demo example demonstration using Bluetooth.
39  */
40 
41 //-----------------------------------------------------------------------
42 // SDK Includes
43 //-----------------------------------------------------------------------
44 #include "board.h"
45 #include "pin_mux.h"
46 #include "clock_config.h"
47 
48 //-----------------------------------------------------------------------
49 // CMSIS Includes
50 //-----------------------------------------------------------------------
51 #include "Driver_I2C.h"
52 #include "Driver_USART.h"
53 
54 //-----------------------------------------------------------------------
55 // ISSDK Includes
56 //-----------------------------------------------------------------------
57 #include "issdk_hal.h"
58 #include "gpio_driver.h"
59 #include "mag3110_drv.h"
60 #include "mpl3115_drv.h"
61 #include "mma865x_drv.h"
62 #include "fxas21002_drv.h"
63 #include "host_io_uart.h"
64 #include "systick_utils.h"
65 #include "auto_detection_service.h"
66 
67 //-----------------------------------------------------------------------
68 // Macros
69 //-----------------------------------------------------------------------
70 #define MPL3115_PADDING_SIZE (1)
71 #define MPL3115_PRESSURE_DATA_SIZE (3)
72 #define MPL3115_TEMPERATURE_DATA_SIZE (2)
73 
74 #define STREAMING_PKT_TIMESTAMP_LEN (4)
75 #define MMA865x_DATA_SIZE (6)
76 #define MAG3110_DATA_SIZE (6)
77 #define FXAS21002_DATA_SIZE (FXAS21002_GYRO_DATA_SIZE)
78 #define MPL3115_DATA_SIZE (MPL3115_PRESSURE_DATA_SIZE + MPL3115_TEMPERATURE_DATA_SIZE)
79 
80 #define STREAMING_PAYLOAD_LEN \
81  (STREAMING_PKT_TIMESTAMP_LEN + MMA865x_DATA_SIZE + MAG3110_DATA_SIZE + FXAS21002_DATA_SIZE + MPL3115_DATA_SIZE + \
82  MPL3115_PADDING_SIZE)
83 
84 /*! @brief Unique Name for this application which should match the target GUI pkg name. */
85 #define APPLICATION_NAME "11 Axis Sensor Demo"
86 /*! @brief Version to distinguish between instances the same application based on target Shield and updates. */
87 #define APPLICATION_VERSION "2.5"
88 
89 /* FF_MT freefall counter register values for High resolution Mode and ODR = 100Hz.
90  * These values have been derived based on the MMA865x DataSheet and Application Note AN4070 for MMA8451 (the same is
91  * applicable to MMA865x too).
92  * http://cache.freescale.com/files/sensors/doc/app_note/AN4070.pdf */
93 #define FF_MT_WT_DBCNT 0x32 /* Debounce count value. */
94 #define FF_MT_THS_VALUE 0x03 /* Threshold Value. */
95 
96 #define SDCD_FF_EVT_ID (0x01)
97 #define P_THS_EVENT_ID (0x02)
98 #define EVENT_PAYLOAD_LEN (1)
99 
100 //-----------------------------------------------------------------------
101 // Constants
102 //-----------------------------------------------------------------------
103 /*! @brief Register settings for freefall detection and poll mode. */
105  {/*! Configure the MMA865x to set FS Range as 2g. */
107  /*! Configure the MMA865x to set ODR to 50Hz. */
109  /*! Configure the MMA865x to set High Resolution mode. */
111  /*! Configure the MMA865x to set interrupt polarity as Active High. */
113  /*! Configure the MMA865x to enable Interrupts for Data Ready. */
115  /*! Configure the MMA865x to route Data Ready Interrupts to INT1. */
117  /*! Configure the MMA865x to set freefall Mode and enable all XYZ axis events and event latching. */
122  /*! Configure the MMA865x to set Debounce counter to be cleared on favourable events and the thresholds . */
125  /*! Configure the MMA865x to set Debounce counter value. */
128 
129 /*! Prepare the register read list to read the raw Accel data from MMA865x. */
132 
133 /*! @brief Address of Freefall Status Register. */
135 
136 /*! @brief Register settings for Normal (non buffered) mode. */
138  /* Set Ouput Rate @40HZ (ODR = 1 and OSR = 16). */
141  /* Set Auto Magnetic Sensor Reset. */
145 
146 /*! @brief Address and size of Raw Magnetic Data in Normal Mode. */
149 
150 /*! Prepare the register write list to configure FXAS21002 in non-FIFO mode. */
152  /*! Configure CTRL_REG1 register to put FXAS21002 to 25Hz sampling rate. */
154  /*! Configure CTRL_REG2 register to set interrupt configuration settings. */
159 
160 /*! Prepare the register read list to read the raw gyro data from the FXAS21002. */
163 
164 /*! @brief Register settings for Triggring One-Shot Sampling. */
166  /* Route Interrupt to INT1. */
168  /* Enable Interrupts for Pressure Threshold Events. */
170  /* Set INT Active High. */
172  /* Set the One ShoT Bit. */
175 
176 /*! @brief Address and size of Raw Pressure+Temperature Data in Normal Mode. */
179 
180 //-----------------------------------------------------------------------
181 // Global Variables
182 //-----------------------------------------------------------------------
185 volatile bool bStreamingEnabled = false, bFxas21002DataReady = false, bMult2bReady = false, bMma865xEventReady = false,
187 uint8_t gStreamID; /* The auto assigned Stream ID. */
190 
191 //-----------------------------------------------------------------------
192 // Functions
193 //-----------------------------------------------------------------------
194 /* This is the Sensor Data Ready ISR implementation.*/
196 { /*! @brief Set flag to indicate Sensor has signalled data ready. */
197  bFxas21002DataReady = true;
198 }
199 
200 /*! @brief This is the Sensor WT Event Ready ISR implementation. */
201 void mma865x_int_event_ready_callback(void *pUserData)
202 { /*! @brief Set flag to indicate Sensor has signalled event ready. */
203  bMma865xEventReady = true;
204 }
205 
206 /* This is the Sensor PTH Event Ready ISR implementation.*/
207 void mpl3115_int_event_ready_callback(void *pUserData)
208 { /*! @brief Set flag to indicate Sensor has signalled data ready. */
209  bMpl3115EventReady = true;
210 }
211 
212 /* Handler for Device Info and Streaming Control Commands. */
214  uint8_t tag, uint8_t *hostCommand, uint8_t *hostResponse, size_t *hostMsgSize, size_t respBufferSize)
215 {
216  bool success = false;
217 
218  /* If it is Host requesting Device Info, send Board Name and Shield Name. */
219  if (tag == HOST_PRO_INT_DEV_TAG)
220  { /* Byte 1 : Payload - Length of APPLICATION_NAME (b)
221  * Bytes=b : Payload Application Name
222  * Byte b+1 : Payload - Length of BOARD_NAME (s)
223  * Bytes=s : Payload Board Name
224  * Byte b+s+2 : Payload - Length of SHIELD_NAME (v)
225  * Bytes=v : Payload Shield Name */
226 
227  size_t appNameLen = strlen(embAppName);
228  size_t boardNameLen = strlen(boardString);
229  size_t shieldNameLen = strlen(shieldString);
230 
231  if (respBufferSize >= boardNameLen + shieldNameLen + appNameLen + 3)
232  { /* We have sufficient buffer. */
233  *hostMsgSize = 0;
234  }
235  else
236  {
237  return false;
238  }
239 
240  hostResponse[*hostMsgSize] = appNameLen;
241  *hostMsgSize += 1;
242 
243  memcpy(hostResponse + *hostMsgSize, embAppName, appNameLen);
244  *hostMsgSize += appNameLen;
245 
246  hostResponse[*hostMsgSize] = boardNameLen;
247  *hostMsgSize += 1;
248 
249  memcpy(hostResponse + *hostMsgSize, boardString, boardNameLen);
250  *hostMsgSize += boardNameLen;
251 
252  hostResponse[*hostMsgSize] = shieldNameLen;
253  *hostMsgSize += 1;
254 
255  memcpy(hostResponse + *hostMsgSize, shieldString, shieldNameLen);
256  *hostMsgSize += shieldNameLen;
257 
258  return true;
259  }
260 
261  /* If it is Host sending Streaming Commands, take necessary actions. */
262  if ((tag == (HOST_PRO_INT_CMD_TAG | HOST_PRO_CMD_W_CFG_TAG)) &&
264  { /* Byte 1 : Payload - Operation Code (Start/Stop Operation Code)
265  * Byte 2 : Payload - Stream ID (Target Stream for carrying out operation) */
266  switch (hostCommand[0]) /* Execute desired operation (Start/Stop) on the requested Stream. */
267  {
268  case HOST_CMD_START:
269  if (hostCommand[1] == gStreamID && bMult2bReady && bStreamingEnabled == false)
270  {
272  bStreamingEnabled = true;
273  success = true;
274  }
275  break;
276  case HOST_CMD_STOP:
277  if (hostCommand[1] == gStreamID && bMult2bReady && bStreamingEnabled == true)
278  {
279  pGpioDriver->clr_pin(&GREEN_LED);
280  bStreamingEnabled = false;
281  success = true;
282  }
283  break;
284  default:
285  break;
286  }
287  *hostMsgSize = 0; /* Zero payload in response. */
288  }
289 
290  return success;
291 }
292 
293 /*!
294  * @brief Main function
295  */
296 int main(void)
297 {
298  int32_t status;
299  uint8_t eventReady = 0, eventPacket[STREAMING_HEADER_LEN + EVENT_PAYLOAD_LEN], secondaryStreamID1,
300  secondaryStreamID2, secondaryStreamID3, /* Auto assigned StreamIDs not to be used for streaming. */
303 
304  mma865x_i2c_sensorhandle_t mma865xDriver;
305  mag3110_i2c_sensorhandle_t mag3110Driver;
306  fxas21002_i2c_sensorhandle_t fxas21002Driver;
307  mpl3115_i2c_sensorhandle_t mpl3115Driver;
308 
309  mma865x_acceldata_t rawData_mma865x;
310  mag3110_magdata_t rawData_mag3110;
311  fxas21002_gyrodata_t rawData_fxas21002;
312  mpl3115_pressuredata_t rawData_mpl3115;
313 
314  ARM_DRIVER_I2C *pI2cDriver = &I2C_S_DRIVER;
315  ARM_DRIVER_USART *pUartDriver = &HOST_B_DRIVER;
316 
317  /*! Initialize the MCU hardware. */
320 
321  /* Create the Short Application Name String for ADS. */
322  sprintf(embAppName, "%s:%s", APPLICATION_NAME, APPLICATION_VERSION);
323 
324  /* Run ADS. */
326 
327  /* Create the Full Application Name String for Device Info Response. */
329 
330  /*! Initialize FXAS21002 INT1 pin used by FRDM board */
332 
333  /*! Initialize MMA865x INT1 pin used by FRDM board */
335 
336  /*! Initialize INT1 MAG3110 used on FRDM board.
337  * NOTE: INT1 of MPL3115 pin on MULT2B maps to PTA0 of K64F which is used as OpenSDA CLK.
338  * Hence, we will wire connect INT1_MPL3115 to INT_MAG (J5_Pin3 to J3_Pin2) and use INT1_MAG3110 handle instead. */
340 
341  /*! Initialize RGB LED pin used by FRDM board */
342  pGpioDriver->pin_init(&GREEN_LED, GPIO_DIRECTION_OUT, NULL, NULL, NULL);
343 
344  /*! Initialize the I2C driver. */
345  status = pI2cDriver->Initialize(I2C_S_SIGNAL_EVENT);
346  if (ARM_DRIVER_OK != status)
347  {
348  return -1;
349  }
350 
351  /*! Set the I2C Power mode. */
352  status = pI2cDriver->PowerControl(ARM_POWER_FULL);
353  if (ARM_DRIVER_OK != status)
354  {
355  return -1;
356  }
357 
358  /*! Set the I2C bus speed. */
359  status = pI2cDriver->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
360  if (ARM_DRIVER_OK != status)
361  {
362  return -1;
363  }
364 
365  /*! Initialize the UART driver. */
366  status = pUartDriver->Initialize(HOST_B_SIGNAL_EVENT);
367  if (ARM_DRIVER_OK != status)
368  {
369  return -1;
370  }
371 
372  /*! Set the UART Power mode. */
373  status = pUartDriver->PowerControl(ARM_POWER_FULL);
374  if (ARM_DRIVER_OK != status)
375  {
376  return -1;
377  }
378 
379  /*! Set UART Baud Rate. */
380  status = pUartDriver->Control(ARM_USART_MODE_ASYNCHRONOUS, BOARD_DEBUG_UART_BAUDRATE);
381  if (ARM_DRIVER_OK != status)
382  {
383  return -1;
384  }
385 
386  do
387  { /*! Initialize the MMA865x sensor driver. */
390  if (SENSOR_ERROR_NONE != status)
391  {
392  break;
393  }
394  /*! Initialize MAG3110 sensor driver. */
397  if (SENSOR_ERROR_NONE != status)
398  {
399  break;
400  }
401  /*! Initialize the FXAS21002 sensor driver. */
404  if (SENSOR_ERROR_NONE != status)
405  {
406  break;
407  }
408  /*! Initialize the MPL3115 sensor driver. */
411  if (SENSOR_ERROR_NONE != status)
412  {
413  break;
414  }
415 
416  /*! Set the task to be executed while waiting for SPI transactions to complete. */
418  MAG3110_I2C_SetIdleTask(&mag3110Driver, (registeridlefunction_t)SMC_SetPowerModeWait, SMC);
419  FXAS21002_I2C_SetIdleTask(&fxas21002Driver, (registeridlefunction_t)SMC_SetPowerModeWait, SMC);
420  MPL3115_I2C_SetIdleTask(&mpl3115Driver, (registeridlefunction_t)SMC_SetPowerModeWait, SMC);
421 
422  /*! Configure the FXLS8962 sensor. */
423  status = MMA865x_I2C_Configure(&mma865xDriver, cMma865xConfigFreeFall);
424  if (SENSOR_ERROR_NONE != status)
425  {
426  break;
427  }
428  /*! Configure the MAG3110 sensor driver. */
429  status = MAG3110_I2C_Configure(&mag3110Driver, cMag3110ConfigNormal);
430  if (SENSOR_ERROR_NONE != status)
431  {
432  break;
433  }
434  /*! Configure the FXAS21002 sensor driver. */
435  status = FXAS21002_I2C_Configure(&fxas21002Driver, fxas21002_Config_Normal);
436  if (SENSOR_ERROR_NONE != status)
437  {
438  break;
439  }
440  /*! In One-Shot Mode we do not need to Configure MPL3115, instead we will set OST bit directly. */
441 
442  bMult2bReady = true;
443  } while (false);
444 
445  /*! Initialize streaming and assign a Stream ID. */
446  gStreamID =
447  Host_IO_Init(pUartDriver, (void *)mma865xDriver.pCommDrv, &mma865xDriver.deviceInfo, NULL, MMA8652_I2C_ADDR);
448  /* Confirm if a valid Stream ID has been allocated for this stream. */
449  if (0 == gStreamID)
450  {
451  bMult2bReady = false;
452  }
453  secondaryStreamID1 = /* This is required for registering the slave address with Host I/O for Register Read/Write. */
454  Host_IO_Init(pUartDriver, (void *)mag3110Driver.pCommDrv, &mag3110Driver.deviceInfo, NULL, MAG3110_I2C_ADDR);
455  /* Confirm if a valid Stream ID has been allocated for this stream. */
456  if (0 == secondaryStreamID1)
457  {
458  bMult2bReady = false;
459  }
460  secondaryStreamID2 = /* This is required for registering the slave address with Host I/O for Register Read/Write. */
461  Host_IO_Init(pUartDriver, (void *)fxas21002Driver.pCommDrv, &fxas21002Driver.deviceInfo, NULL,
463  /* Confirm if a valid Stream ID has been allocated for this stream. */
464  if (0 == secondaryStreamID2)
465  {
466  bMult2bReady = false;
467  }
468  secondaryStreamID3 = /* This is required for registering the slave address with Host I/O for Register Read/Write. */
469  Host_IO_Init(pUartDriver, (void *)mpl3115Driver.pCommDrv, &mpl3115Driver.deviceInfo, NULL, MPL3115_I2C_ADDR);
470  /* Confirm if a valid Stream ID has been allocated for this stream. */
471  if (0 == secondaryStreamID3)
472  {
473  bMult2bReady = false;
474  }
475 
476  if (true == bMult2bReady)
477  {
478  *((uint32_t *)&streamingPacket[STREAMING_HEADER_LEN]) = 0; /* Initialize time stamp field. */
479  pGpioDriver->clr_pin(&GREEN_LED); /* Set LED to indicate application is ready. */
480  /*! Populate streaming header. */
482  /*! Populate event header. */
484  }
485 
486  for (;;) /* Forever loop */
487  { /* Call UART Non-Blocking Receive. */
489 
490  if (bMma865xEventReady)
491  { /*! Read the Freefall event FLAGs from FXLS8962 to clear INT2. */
492  status = MMA865x_I2C_ReadData(&mma865xDriver, cMma865xFreeFallEvent, &eventReady);
493  if (SENSOR_ERROR_NONE != status)
494  {
495  return -1;
496  }
497 
499  { /* Update Event ID with Freefall event and send message to Host. */
500  eventPacket[STREAMING_HEADER_LEN] = SDCD_FF_EVT_ID;
501  Host_IO_Send(eventPacket, sizeof(eventPacket), HOST_FORMAT_HDLC);
502  }
503 
504  eventReady = 0;
505  bMma865xEventReady = false;
506  }
507 
508  if (bMpl3115EventReady)
509  { /* Send Pressure Threshold event message to Host. */
510  eventPacket[STREAMING_HEADER_LEN] = P_THS_EVENT_ID;
511  Host_IO_Send(eventPacket, sizeof(eventPacket), HOST_FORMAT_HDLC);
512  bMpl3115EventReady = false;
513  }
514 
515  /* Process packets only if streaming has been enabled by Host and ISR is available.
516  * In ISR Mode we do not need to check Data Ready Register.
517  * The receipt of interrupt will indicate data is ready. */
518  if (false == bStreamingEnabled || false == bFxas21002DataReady)
519  {
520  SMC_SetPowerModeWait(SMC); /* Power save, wait if nothing to do. */
521  continue;
522  }
523  else
524  { /*! Clear the data ready flag, it will be set again by the ISR. */
525  bFxas21002DataReady = false;
526  pGpioDriver->toggle_pin(&GREEN_LED);
527  }
528 
529  /* Read timestamp from Systick framework. */
530  *((uint32_t *)&streamingPacket[STREAMING_HEADER_LEN]) += BOARD_SystickElapsedTime_us(&gSystick);
531 
532  /*! Read new raw sensor data from the MMA865x. */
533  status = MMA865x_I2C_ReadData(&mma865xDriver, cMma865xOutputValues, data);
534  if (ARM_DRIVER_OK != status)
535  {
536  return -1;
537  }
538 
539  /* Convert to Little Endian, Right Justified, Even Padded Signed integer counts. */
540  rawData_mma865x.accel[0] = ((int16_t)data[0] << 8) | data[1];
541  rawData_mma865x.accel[0] /= 16;
542  rawData_mma865x.accel[1] = ((int16_t)data[2] << 8) | data[3];
543  rawData_mma865x.accel[1] /= 16;
544  rawData_mma865x.accel[2] = ((int16_t)data[4] << 8) | data[5];
545  rawData_mma865x.accel[2] /= 16;
546 
547  /* Copy Raw samples to Streaming Buffer. */
548  memcpy(streamingPacket + STREAMING_HEADER_LEN + STREAMING_PKT_TIMESTAMP_LEN, &rawData_mma865x.accel,
549  sizeof(rawData_mma865x.accel));
550 
551  /*! Read raw sensor data from the MAG3110. */
552  status = MAG3110_I2C_ReadData(&mag3110Driver, cMag3110OutputNormal, data + MMA865x_DATA_SIZE);
553  if (ARM_DRIVER_OK != status)
554  {
555  return -1;
556  }
557 
558  /* Convert to Little Endian, Right Justified, Even Padded Signed integer counts. */
559  rawData_mag3110.mag[0] = ((int16_t)data[6] << 8) | data[7];
560  rawData_mag3110.mag[1] = ((int16_t)data[8] << 8) | data[9];
561  rawData_mag3110.mag[2] = ((int16_t)data[10] << 8) | data[11];
562 
563  MAG3110_CalibrateHardIronOffset(&rawData_mag3110.mag[0], &rawData_mag3110.mag[1], &rawData_mag3110.mag[2]);
564 
565  /* Copy Raw samples to Streaming Buffer. */
566  memcpy(streamingPacket + STREAMING_HEADER_LEN + STREAMING_PKT_TIMESTAMP_LEN + MMA865x_DATA_SIZE,
567  &rawData_mag3110.mag, sizeof(rawData_mag3110.mag));
568 
569  /*! Read the raw sensor data from the FXAS21002. */
570  status = FXAS21002_I2C_ReadData(&fxas21002Driver, fxas21002_Output_Values,
572  if (ARM_DRIVER_OK != status)
573  {
574  return -1;
575  }
576 
577  /* Convert to Little Endian, Right Justified, Even Padded Signed integer counts. */
578  rawData_fxas21002.gyro[0] = ((int16_t)data[12] << 8) | data[13];
579  rawData_fxas21002.gyro[1] = ((int16_t)data[14] << 8) | data[15];
580  rawData_fxas21002.gyro[2] = ((int16_t)data[16] << 8) | data[17];
581 
582  /* Copy the converted sample to the streaming buffer. */
583  memcpy(streamingPacket + STREAMING_HEADER_LEN + STREAMING_PKT_TIMESTAMP_LEN + MMA865x_DATA_SIZE +
585  &rawData_fxas21002.gyro, sizeof(rawData_fxas21002.gyro));
586 
587  /*! Read raw sensor data from the MPL3115. */
588  status = MPL3115_I2C_ReadData(&mpl3115Driver, mpl3115_Output_Values,
590  if (ARM_DRIVER_OK != status)
591  {
592  return -1;
593  }
594 
595  /* Convert to Little Endian, Right Justified, Even Padded Signed integer counts. */
596  rawData_mpl3115.pressure = (uint32_t)((data[18]) << 16) | ((data[19]) << 8) | ((data[20]));
597  rawData_mpl3115.pressure /= 16;
598  rawData_mpl3115.temperature = (int16_t)((data[21]) << 8) | (data[22]);
599  rawData_mpl3115.temperature /= 16;
600 
601  /* Copy the converted sample to the streaming buffer. */
602  memcpy(streamingPacket + STREAMING_HEADER_LEN + STREAMING_PKT_TIMESTAMP_LEN + MMA865x_DATA_SIZE +
604  &rawData_mpl3115.pressure, sizeof(rawData_mpl3115.pressure));
605  memcpy(streamingPacket + STREAMING_HEADER_LEN + STREAMING_PKT_TIMESTAMP_LEN + MMA865x_DATA_SIZE +
607  &rawData_mpl3115.temperature, sizeof(rawData_mpl3115.temperature));
608 
609  /* Trigger acquisition of New Sample. */
610  status = Sensor_I2C_Write(mpl3115Driver.pCommDrv, &mpl3115Driver.deviceInfo, mpl3115Driver.slaveAddress,
611  cMpl3115SetOST);
612 
613  /* Send streaming packet to Host. */
614  Host_IO_Send(streamingPacket, sizeof(streamingPacket), HOST_FORMAT_HDLC);
615  }
616 }
registerDeviceInfo_t deviceInfo
Definition: mpl3115_drv.h:64
#define MAG3110_CTRL_REG1_OS_OSR_16
Definition: mag3110.h:417
uint32_t BOARD_SystickElapsedTime_us(int32_t *pStart)
Function to compute the Elapsed Time.
Definition: systick_utils.c:99
#define MMA865x_CTRL_REG3_IPOL_MASK
Definition: mma865x.h:1664
#define FXAS21002_CTRL_REG2_INT_EN_DRDY_MASK
Definition: fxas21002.h:783
#define FXAS21002_CTRL_REG2_INT_CFG_DRDY_INT1
Definition: fxas21002.h:812
#define MMA865x_XYZ_DATA_CFG_FS_MASK
Definition: mma865x.h:530
int32_t MAG3110_I2C_Initialize(mag3110_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: mag3110_drv.c:48
#define FXAS21002_CTRL_REG2_IPOL_MASK
Definition: fxas21002.h:780
ARM_DRIVER_I2C * pCommDrv
Definition: mpl3115_drv.h:65
#define __END_WRITE_DATA__
Definition: sensor_drv.h:71
int32_t MMA865x_I2C_Initialize(mma865x_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: mma865x_drv.c:48
#define HOST_PRO_CMD_W_CFG_TAG
Definition: host_io_uart.h:89
char embAppName[ADS_MAX_STRING_LENGTH]
#define FF_MT_THS_VALUE
volatile bool bMult2bReady
int32_t MPL3115_I2C_Initialize(mpl3115_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: mpl3115_drv.c:48
This structure defines the mma865x raw data buffer.
Definition: mma865x_drv.h:64
uint8_t gStreamID
#define MAG3110_CTRL_REG2_MAG_RST_EN
Definition: mag3110.h:471
void Host_IO_Receive(host_cmd_proc_fn_t process_host_command, uint8_t encoding)
Definition: host_io_uart.c:233
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
Definition: Driver_GPIO.h:67
#define MMA865x_DATA_SIZE
#define BOARD_BootClockRUN
Definition: clock_config.h:45
#define FXAS21002_CTRL_REG1_DR_MASK
Definition: fxas21002.h:710
int32_t MAG3110_I2C_Configure(mag3110_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: mag3110_drv.c:87
#define MMA865x_CTRL_REG5_INT_CFG_FF_MT_MASK
Definition: mma865x.h:1818
volatile bool bMpl3115EventReady
#define MMA865x_FF_MT_SRC_EA_DETECTED
Definition: mma865x.h:945
#define MMA865x_CTRL_REG3_IPOL_ACTIVE_HIGH
Definition: mma865x.h:1701
const registerreadlist_t cMma865xOutputValues[]
#define MPL3115_CTRL_REG3_IPOL1_MASK
Definition: mpl3115.h:976
The mag3110_drv.h file describes the MAG3110 driver interface and structures.
const registerreadlist_t cMag3110OutputNormal[]
Address and size of Raw Magnetic Data in Normal Mode.
int16_t accel[3]
Definition: mma865x_drv.h:67
volatile bool bStreamingEnabled
#define FXAS21002_DATA_SIZE
#define MMA865x_FF_MT_THS_THS_MASK
Definition: mma865x.h:983
This defines the sensor specific information.
Definition: mag3110_drv.h:55
uint8_t data[FXLS8962_DATA_SIZE]
int32_t MPL3115_I2C_ReadData(mpl3115_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: mpl3115_drv.c:130
int32_t MMA865x_I2C_ReadData(mma865x_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: mma865x_drv.c:132
#define MAG3110_CTRL_REG1_DR_ODR_1
Definition: mag3110.h:422
#define MPL3115_CTRL_REG5_INT_CFG_PTH_MASK
Definition: mpl3115.h:1116
#define MPL3115_CTRL_REG1_OST_SET
Definition: mpl3115.h:871
int32_t status
#define FXAS21002_CTRL_REG2_INT_EN_DRDY_ENABLE
Definition: fxas21002.h:809
void(* toggle_pin)(pinID_t aPinId)
Definition: Driver_GPIO.h:74
const registerreadlist_t mpl3115_Output_Values[]
Address and size of Raw Pressure+Temperature Data in Normal Mode.
#define APPLICATION_NAME
Unique Name for this application which should match the target GUI pkg name.
#define SHIELD_NAME
#define MMA865x_FF_MT_CFG_ELE_EN
Definition: mma865x.h:871
ARM_DRIVER_I2C * pCommDrv
Definition: mag3110_drv.h:58
#define HOST_B_SIGNAL_EVENT
Definition: frdm_k64f.h:124
#define ADS_MAX_STRING_LENGTH
#define MPL3115_CTRL_REG4_INT_EN_PTH_INTENABLED
Definition: mpl3115.h:1062
#define MPL3115_CTRL_REG1_OST_MASK
Definition: mpl3115.h:849
This defines the sensor specific information.
Definition: mma865x_drv.h:55
registerDeviceInfo_t deviceInfo
Definition: mma865x_drv.h:57
#define HOST_PRO_INT_DEV_TAG
Definition: host_io_uart.h:85
uint8_t streamingPacket[STREAMING_HEADER_LEN+FXLS8962_STREAM_DATA_SIZE]
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:123
GENERIC_DRIVER_GPIO * pGpioDriver
#define MAG3110_CTRL_REG1_OS_MASK
Definition: mag3110.h:401
The fxas21002_drv.h file describes the fxas21002 driver interface and structures. ...
#define HOST_PRO_INT_CMD_TAG
Bit aligned values for Host Protocol Interface IDs (Bits 5-6).
Definition: host_io_uart.h:83
#define MMA865x_CTRL_REG1_DR_MASK
Definition: mma865x.h:1534
#define MPL3115_CTRL_REG4_INT_EN_PTH_MASK
Definition: mpl3115.h:1036
#define MAG3110_CTRL_REG2_RAW_RAW
Definition: mag3110.h:474
#define __END_READ_DATA__
Definition: sensor_drv.h:77
#define MMA865x_CTRL_REG1_DR_50HZ
Definition: mma865x.h:1552
void MPL3115_I2C_SetIdleTask(mpl3115_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: mpl3115_drv.c:79
void mma865x_int_event_ready_callback(void *pUserData)
This is the Sensor WT Event Ready ISR implementation.
#define MMA865x_FF_MT_CFG_YEFE_MASK
Definition: mma865x.h:854
#define MPL3115_CTRL_REG5_INT_CFG_PTH_INT1
Definition: mpl3115.h:1142
#define MPL3115_WHOAMI_VALUE
Definition: mpl3115.h:65
#define HOST_B_DRIVER
Definition: frdm_k64f.h:123
#define MMA8652_I2C_ADDR
#define FXAS21002_CTRL_REG2_INT_CFG_DRDY_MASK
Definition: fxas21002.h:786
void MAG3110_I2C_SetIdleTask(mag3110_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: mag3110_drv.c:79
const registerwritelist_t cMma865xConfigFreeFall[]
Register settings for freefall detection and poll mode.
void MMA865x_I2C_SetIdleTask(mma865x_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: mma865x_drv.c:79
#define MMA8652_WHOAMI_VALUE
Definition: mma865x.h:65
#define MPL3115_DATA_SIZE
This structure defines the mag3110 data buffer.
Definition: mag3110_drv.h:64
#define MMA865x_CTRL_REG4_INT_EN_FF_MT_EN
Definition: mma865x.h:1776
gpioHandleKSDK_t GREEN_LED
Definition: frdm_k64f.c:214
This defines the sensor specific information.
Definition: mpl3115_drv.h:62
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
void MAG3110_CalibrateHardIronOffset(int16_t *xValue, int16_t *yValue, int16_t *zValue)
Calibrates the magnetometer reading by determining the current hard iron offset.
Definition: mag3110_drv.c:190
const registerreadlist_t fxas21002_Output_Values[]
const registerwritelist_t cMag3110ConfigNormal[]
Register settings for Normal (non buffered) mode.
#define MMA865x_FF_MT_CFG_OAE_FREEFALL
Definition: mma865x.h:872
#define MAG3110_CTRL_REG1_DR_MASK
Definition: mag3110.h:404
#define MAG3110_CTRL_REG2_MAG_RST_MASK
Definition: mag3110.h:458
#define MAG3110_DATA_SIZE
int32_t MMA865x_I2C_Configure(mma865x_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: mma865x_drv.c:87
#define MMA865x_FF_MT_CFG_XEFE_EN
Definition: mma865x.h:881
#define MAG3110_CTRL_REG2_RAW_MASK
Definition: mag3110.h:461
#define MMA865x_XYZ_DATA_CFG_FS_2G
Definition: mma865x.h:542
void Host_IO_Add_ISO_Header(uint8_t streamID, uint8_t *pStreamingPacket, size_t sizePayload)
Definition: host_io_uart.c:112
#define MMA865x_CTRL_REG4_INT_EN_FF_MT_MASK
Definition: mma865x.h:1743
#define APPLICATION_VERSION
Version to distinguish between instances the same application based on target Shield and updates...
void Host_IO_Send(uint8_t *pMsg, size_t size, uint8_t encoding)
Definition: host_io_uart.c:162
void(* clr_pin)(pinID_t aPinId)
Definition: Driver_GPIO.h:73
#define MMA865x_CTRL_REG2_MODS_MASK
Definition: mma865x.h:1592
#define MMA865x_FF_MT_CFG_ZEFE_EN
Definition: mma865x.h:875
#define MPL3115_PRESSURE_DATA_SIZE
char boardString[ADS_MAX_STRING_LENGTH]
#define STREAMING_PKT_TIMESTAMP_LEN
#define EVENT_PAYLOAD_LEN
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.
void BOARD_SystickEnable(void)
Function to enable systicks framework.
Definition: systick_utils.c:70
#define FXAS21002_INT1
#define MMA865x_FF_MT_CFG_ZEFE_MASK
Definition: mma865x.h:857
#define MMA865x_CTRL_REG5_INT_CFG_FF_MT_INT1
Definition: mma865x.h:1851
#define MAG3110_CTRL_REG2_AUTO_MSRT_EN_EN
Definition: mag3110.h:477
char shieldString[ADS_MAX_STRING_LENGTH]
int main(void)
Main function.
#define I2C_S_DEVICE_INDEX
Definition: issdk_hal.h:61
#define MMA8652_INT1
#define MMA865x_FF_MT_CFG_XEFE_MASK
Definition: mma865x.h:851
#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
The mma865x_drv.h file describes the MMA865x driver interface and structures.
void fxas21002_int_data_ready_callback(void *pUserData)
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
Definition: gpio_driver.c:203
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
#define MMA865x_FF_MT_THS_DBCNTM_INC_CLR
Definition: mma865x.h:994
volatile bool bFxas21002DataReady
#define STREAMING_PAYLOAD_LEN
void FXAS21002_I2C_SetIdleTask(fxas21002_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
#define BOARD_DEBUG_UART_BAUDRATE
Definition: board.h:57
#define MMA865x_FF_MT_CFG_ELE_MASK
Definition: mma865x.h:863
The mpl3115_drv.h file describes the MPL3115 driver interface and structures.
const registerwritelist_t cMpl3115SetOST[]
Register settings for Triggring One-Shot Sampling.
registerDeviceInfo_t deviceInfo
Definition: mag3110_drv.h:57
Access structure of the GPIO Driver.
Definition: Driver_GPIO.h:64
#define MPL3115_I2C_ADDR
void BOARD_SystickStart(int32_t *pStart)
Function to Record the Start systick.
Definition: systick_utils.c:79
volatile bool bMma865xEventReady
ARM Systick Utilities.
void BOARD_RunADS(const char *appName, char *boardString, char *shieldString, size_t bufferLength)
The function to register Application Name and initialte ADS.
#define MMA865x_FF_MT_SRC_EA_MASK
Definition: mma865x.h:937
uint8_t Host_IO_Init(ARM_DRIVER_USART *pDrv, void *pBus, void *pDevInfo, void *spiSlaveParams, uint16_t slaveAddress)
Definition: host_io_uart.c:126
#define MMA865x_CTRL_REG2_MODS_HR
Definition: mma865x.h:1623
This structure defines the Write command List.
Definition: sensor_drv.h:94
const registerreadlist_t cMma865xFreeFallEvent[]
Address of Freefall Status Register.
This structure defines the Read command List.
Definition: sensor_drv.h:104
#define SMC
Definition: lpc54114.h:144
#define MAG3110_WHOAMI_VALUE
Definition: mag3110.h:37
#define MMA865x_FF_MT_CFG_YEFE_EN
Definition: mma865x.h:878
The host_io_uart.h file contains the Host Protocol interface definitions and configuration.
int16_t mag[3]
Definition: mag3110_drv.h:67
#define STREAMING_HEADER_LEN
Definition: host_io_uart.h:51
#define MPL3115_PADDING_SIZE
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
int32_t MAG3110_I2C_ReadData(mag3110_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: mag3110_drv.c:130
const registerwritelist_t fxas21002_Config_Normal[]
#define FF_MT_WT_DBCNT
#define SDCD_FF_EVT_ID
#define FXAS21002_CTRL_REG2_IPOL_ACTIVE_HIGH
Definition: fxas21002.h:808
#define EVENT_STREAM_ID
Definition: host_io_uart.h:59
#define MAG3110_CTRL_REG2_AUTO_MSRT_EN_MASK
Definition: mag3110.h:464
void mpl3115_int_event_ready_callback(void *pUserData)
This structure defines the mpl3115 data buffer in Pressure Mode.
Definition: mpl3115_drv.h:71
#define MAG3110_I2C_ADDR
#define FXAS21002_CTRL_REG1_DR_25HZ
Definition: fxas21002.h:735
bool process_host_command(uint8_t tag, uint8_t *hostCommand, uint8_t *hostResponse, size_t *hostMsgSize, size_t respBufferSize)
#define P_THS_EVENT_ID
#define I2C_S_SIGNAL_EVENT
Definition: issdk_hal.h:60
int32_t gSystick
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.
#define MAG3110_INT1
#define MMA865x_FF_MT_THS_DBCNTM_MASK
Definition: mma865x.h:986
ARM_DRIVER_I2C * pCommDrv
Definition: mma865x_drv.h:58
int32_t Sensor_I2C_Write(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, const registerwritelist_t *pRegWriteList)
Write register data to a sensor.
Definition: sensor_io_i2c.c:97
#define MPL3115_CTRL_REG3_IPOL1_HIGH
Definition: mpl3115.h:990
#define MMA865x_FF_MT_CFG_OAE_MASK
Definition: mma865x.h:860
registerDeviceInfo_t deviceInfo
Definition: fxas21002_drv.h:72