ISF  2.2 rev 5
Intelligent Sensing Framework for Kinetis with Processor Expert
fsl_mpl3115_i2c_1D_press.c
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2015, Freescale Semiconductor, Inc.
4  *
5 */
6 /**
7  ** @file fsl_mpl3115_i2c_1D_press.c
8  ** @version 01.00
9  ** @brief
10  **
11  */
12 /**
13  ** @addtogroup fsl_mpl3115_i2c_1D_press_module fsl_mpl3115_i2c_1D_press module documentation
14  ** @{
15  */
16 
17 /* MODULE fsl_mpl3115_i2c_1D_press. */
18 
19 #include <isf.h>
20 #include <isf_types.h>
21 #include <isf_sm_api.h>
22 #include <isf_dsa_adapter.h>
23 #include <isf_bm.h>
24 #include <isf_sensor_types.h>
25 #include <isf_fifo.h>
26 #include <isf_pressure_types.h>
27 #include <isf_altitude_types.h>
28 #include <isf_temperature_types.h>
29 #include <isf_comm.h>
30 #include <isf_util.h>
31 #include <isf_sensors.h>
32 #include "fsl_os_abstraction.h"
33 #include "mpl3115.h"
35 
36 
37 /*
38  * @brief This table contains the MPL3115 conversion factors based on the full-scale range selected.
39  */
40 #define MPL3115_PRESS_FLOAT_CONVERSION_FACTOR 0.000000061035
41 #define MPL3115_PRESS_FLOAT_CONVERSION_OFFSET 0.0
42 #define MPL3115_PRESS_FIXED_CONVERSION_FACTOR (1000/4)
43 #define MPL3115_PRESS_FIXED_CONVERSION_OFFSET 0
44 #define MPL3115_ALT_FLOAT_CONVERSION_FACTOR (1.0F/65536.0F)
45 #define MPL3115_ALT_FLOAT_CONVERSION_OFFSET 0.0
46 #define MPL3115_ALT_FIXED_CONVERSION_FACTOR 1
47 #define MPL3115_ALT_FIXED_CONVERSION_OFFSET 0
48 #define MPL3115_TEMP_FLOAT_CONVERSION_FACTOR (1.0F/256.0F)
49 #define MPL3115_TEMP_FLOAT_CONVERSION_OFFSET 0.0
50 #define MPL3115_TEMP_FIXED_CONVERSION_FACTOR 256
51 #define MPL3115_TEMP_FIXED_CONVERSION_OFFSET 0
52 enum {
56 };
57 
58 enum {
63 };
64 
65 typedef struct {
66  float x;
67  float y;
68 } dataPair_t;
69 
70 typedef struct {
71  unsigned char maxIdx;
72  unsigned char extrapolationBehavior;
73  dataPair_t dataPoints[];
74 } fLfiTable_t;
75 
76 long fLfi( const fLfiTable_t *lookupTable, float lFiIn, float *lfiOut);
77 // ! @brief Implements pressure to height equation in MPL3115A2 data sheet section 5.3.
78 // See MPL3115_Pressure_to_Height.xlsx file in the /Doc directory for calculation
79 // and formatting of the .dataPoints.
80 //Note: The values in the table below produce an altitude value approximately accurate to 0.25 meter.
81 static const fLfiTable_t pressure_to_height = {
82  .maxIdx = 61,
83  .extrapolationBehavior = LFI_TABLE_LIMITS,
84  .dataPoints =
85  {
86  // Paste directly from MPL3115_Pressure_to_Height.xlsx columns R through V here.
87  { 50000.0 , 5574.4366 },
88  { 51000.0 , 5428.1385 },
89  { 52000.0 , 5284.1450 },
90  { 53000.0 , 5142.3767 },
91  { 54000.0 , 5002.7580 },
92  { 55000.0 , 4865.2174 },
93  { 56000.0 , 4729.6871 },
94  { 57000.0 , 4596.1025 },
95  { 58000.0 , 4464.4024 },
96  { 59000.0 , 4334.5283 },
97  { 60000.0 , 4206.4245 },
98  { 61000.0 , 4080.0381 },
99  { 62000.0 , 3955.3185 },
100  { 63000.0 , 3832.2172 },
101  { 64000.0 , 3710.6880 },
102  { 65000.0 , 3590.6869 },
103  { 66000.0 , 3472.1715 },
104  { 67000.0 , 3355.1013 },
105  { 68000.0 , 3239.4376 },
106  { 69000.0 , 3125.1431 },
107  { 70000.0 , 3012.1820 },
108  { 71000.0 , 2900.5203 },
109  { 72000.0 , 2790.1248 },
110  { 73000.0 , 2680.9639 },
111  { 74000.0 , 2573.0073 },
112  { 75000.0 , 2466.2255 },
113  { 76000.0 , 2360.5905 },
114  { 77000.0 , 2256.0750 },
115  { 78000.0 , 2152.6530 },
116  { 79000.0 , 2050.2990 },
117  { 80000.0 , 1948.9888 },
118  { 81000.0 , 1848.6990 },
119  { 82000.0 , 1749.4067 },
120  { 83000.0 , 1651.0902 },
121  { 84000.0 , 1553.7282 },
122  { 85000.0 , 1457.3002 },
123  { 86000.0 , 1361.7865 },
124  { 87000.0 , 1267.1680 },
125  { 88000.0 , 1173.4260 },
126  { 89000.0 , 1080.5427 },
127  { 90000.0 , 988.5006 },
128  { 91000.0 , 897.2829 },
129  { 92000.0 , 806.8734 },
130  { 93000.0 , 717.2561 },
131  { 94000.0 , 628.4157 },
132  { 95000.0 , 540.3374 },
133  { 96000.0 , 453.0066 },
134  { 97000.0 , 366.4094 },
135  { 98000.0 , 280.5320 },
136  { 99000.0 , 195.3614 },
137  { 100000.0 , 110.8845 },
138  { 101000.0 , 27.0889 },
139  { 102000.0 , -56.0375 },
140  { 103000.0 , -138.5067 },
141  { 104000.0 , -220.3300 },
142  { 105000.0 , -301.5187 },
143  { 106000.0 , -382.0837 },
144  { 107000.0 , -462.0356 },
145  { 108000.0 , -541.3847 },
146  { 109000.0 , -620.1411 },
147  { 110000.0 , -698.3146 }
148  // End paste.
149  }
150 };
151 
152 /**
153  *
154  *@brief The table that describes the configuration value based on OS (oversample ratio).
155  *
156  */
158  { 10000, 1},
159  { 20000, 2},
160  { 40000, 3},
161  { 100000, 4},
162  { 200000, 5},
163  { 500000, 6},
164  { 1000000, 7},
165 };
166 
169 
170 /*
171  * Local function prototypes.
172  */
173 void mpl3115_Reset(int32_t *status, void* pSensorHandle);
174 void mpl3115_CheckId(int32_t *status, void* pSensorHandle);
175 void mpl3115_SetMode(int32_t *status, void* pSensorHandle, int32_t Mode);
176 void mpl3115_ValidateConfig(int32_t *status, void *pSensorHandle);
177 void mpl3115_StartSample(int32_t* status, void* pSensorHandle);
178 void mpl3115_DataReady(int32_t* status, void* pSensorHandle);
182 static int32 get_OS(uint32 samplePeriod);
183 
184 
185 // Converter routines for the supported data types
186 static isf_dsa_status_t float_press1d_converter(mpl3115_Sensor_Specific_Settings_t *pSensorSpecificConfig, mpl3115_DataBuffer_t *nativeSample, void *vpConvertedSample );
187 static isf_dsa_status_t fixed_press1d_converter(mpl3115_Sensor_Specific_Settings_t *pSensorSpecificConfig, mpl3115_DataBuffer_t *nativeSample, void *vpConvertedSample );
188 static isf_dsa_status_t float_alt1d_converter(mpl3115_Sensor_Specific_Settings_t *pSensorSpecificConfig, mpl3115_DataBuffer_t *nativeSample, void *vpConvertedSample );
189 static isf_dsa_status_t fixed_alt1d_converter(mpl3115_Sensor_Specific_Settings_t *pSensorSpecificConfig, mpl3115_DataBuffer_t *nativeSample, void *vpConvertedSample );
190 static isf_dsa_status_t float_temp1d_converter(mpl3115_Sensor_Specific_Settings_t *pSensorSpecificConfig, mpl3115_DataBuffer_t *nativeSample, void *vpConvertedSample );
191 static isf_dsa_status_t fixed_temp1d_converter(mpl3115_Sensor_Specific_Settings_t *pSensorSpecificConfig, mpl3115_DataBuffer_t *nativeSample, void *vpConvertedSample );
192 
193 /*
194  ** ===================================================================
195  ** Method : fsl_mpl3115_i2c_1D_press_Initialize (component ISFDSA)
196  ** @brief
197  **
198  ** Parameters :
199  ** NAME - DESCRIPTION
200  ** @param
201  ** isf_SensorHandle_t *pSensorHandle
202  ** @return
203  ** isf_dsa_status_t -
204  ** ===================================================================
205  */
207 {
208  if ( NULL == pSensorHandle){
209  return DSA_ERR_PARAM;
210  }
211 
212  int32_t status;
213 
214 
215  // Check if the sensor is available, and that it has already been initialized.
216  if (pSensorHandle->adapterStatus > DSA_STATE_NOT_INITIALIZED) {
217  return DSA_ERR_INITIALIZE;
218  }
219 
220  // Allocate the adapter specific memory for the descriptor
221  //pSensorHandle->pDeviceDescriptor = (DeviceDescriptor_t *)_lwmem_alloc_system_zero(sizeof(DeviceDescriptor_t));
222  pSensorHandle->pDeviceDescriptor = (DeviceDescriptor_t *)OSA_MemAllocZero(sizeof(DeviceDescriptor_t));
223 
224  // Create and validate helper reference pointers.
225  DeviceDescriptor_t *pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHandle->pDeviceDescriptor;
226 
227  if (NULL == pDeviceDescriptor) {
228  return DSA_ERR_INITIALIZE;
229  }
230 
231  // Allocate the current sample data buffer and initialize it.
232  //pDeviceDescriptor->pCurrentSample = _lwmem_alloc_system_zero(sizeof(mpl3115_DataBuffer_t));
233  pDeviceDescriptor->pCurrentSample = OSA_MemAllocZero(sizeof(mpl3115_DataBuffer_t));
234  mpl3115_DataBuffer_t *pCurrentSampleBuffer = (mpl3115_DataBuffer_t *)pDeviceDescriptor->pCurrentSample;
235  pCurrentSampleBuffer->timestamp = 0;
236  pCurrentSampleBuffer->pressure = 0;
237  pCurrentSampleBuffer->altitude = 0;
238  pCurrentSampleBuffer->temperature = 0;
239 
240  dm_ChannelDescriptor_t *pChannelDescriptor = &pDeviceDescriptor->cDescriptor;
241 
242  // Initialize the channel
243  if(ISF_SUCCESS != dm_channel_init(pSensorHandle->pSensorStaticConfig->channelId, pChannelDescriptor)){
244  return DSA_ERR_INITIALIZE;
245  }
246 
247  // Start the Bus
248  if(ISF_SUCCESS != dm_channel_start(pChannelDescriptor)){
249  return DSA_ERR_INITIALIZE;
250  }
251 
252  // Get the Channel state to check if it is ready to use
253  if (COMM_STATE_OK != dm_channel_get_state(pChannelDescriptor)) {
254  return DSA_ERR_INITIALIZE;
255  }
256 
257  // Open the device and get the device handler
258  if(ISF_SUCCESS != dm_device_open(pChannelDescriptor, (void *)pSensorHandle->pSensorStaticConfig->commInfo, &pDeviceDescriptor->deviceHandle)){
259  return DSA_ERR_INITIALIZE;
260  }
261 
262  // A very short delay is needed for device startup.
263  OSA_TimeDelay(1);
264 
265  // Query the sensor to validate Device Messaging initialization and the sensor identity.
266  mpl3115_CheckId(&status,pSensorHandle);
267  if (ISF_SUCCESS != status)
268  {
269  return DSA_ERR_INITIALIZE;
270  }
271 
272  // Set the adapter state to be initialized.
273  pSensorHandle->adapterStatus = DSA_STATE_INITIALIZED;
274 
275  // Create a semaphore to synchronize the device descriptor across tasks
276  //if (MQX_OK != _lwsem_create(&pDeviceDescriptor->deviceSemaphore, 1)){
277  if (kStatus_OSA_Success != OSA_SemaCreate(&pDeviceDescriptor->deviceSemaphore, 1)){
278  return DSA_ERR_INITIALIZE;
279  }
280 
281  pDeviceDescriptor->skipFramecnt = 0;
282 
283  return ISF_SUCCESS;
284 }
285 
286 /*
287  ** ===================================================================
288  ** Method : fsl_mpl3115_i2c_1D_press_ValidateSettings (component ISFDSA)
289  ** @brief
290  **
291  ** Parameters :
292  ** NAME - DESCRIPTION
293  ** @param
294  ** isf_SensorHandle_t *pSensorHandle
295  ** @param
296  ** isf_SubscriptionSettings_t *pSettings
297  ** @return
298  ** isf_dsa_status_t -
299  ** ===================================================================
300  */
302 {
303  // Check the input arguments.
304  if ((NULL == pSensorHandle) || (NULL == pSensorSettings)) {
305  return DSA_ERR_PARAM;
306  }
307 
308  int32_t status;
309 
310  mpl3115_ValidateConfig(&status,pSensorHandle);
311 
312  return status;
313 }
314 
315 /*
316  ** ===================================================================
317  ** Method : fsl_mpl3115_i2c_1D_press_Configure (component ISFDSA)
318  ** @brief
319  **
320  ** Parameters :
321  ** NAME - DESCRIPTION
322  ** @param
323  ** isf_SensorHandle_t *pSensorHandle
324  ** @param
325  ** isf_SubscriptionSettings_t *pConfigSettings
326  ** @return
327  ** isf_dsa_status_t -
328  ** ===================================================================
329  */
331 {
332  // Check pointers.
333  if((NULL == pSensorHandle) || (NULL == pSensorSettings) ){
334  return DSA_ERR_PARAM;
335  }
336 
337  int32_t status;
338 
339  int32_t retStat = DSA_ERR_CONFIGURE; // Return Status
340 
341  // Create helper reference pointers.
342  DeviceDescriptor_t *pDeviceDescriptor = (DeviceDescriptor_t*) pSensorHandle->pDeviceDescriptor;
343 
344  // Check the device descriptor pointer.
345  if (NULL == pDeviceDescriptor)
346  {
347  return retStat;
348  }
349 
350  // Lock the device descriptor.
351  //_lwsem_wait_ticks(&pDeviceDescriptor->deviceSemaphore, 0);
352  OSA_SemaWait(&pDeviceDescriptor->deviceSemaphore, OSA_WAIT_FOREVER);
353 
354  // Check the driver state.
355  if (DSA_STATE_INITIALIZED > pSensorHandle->adapterStatus){
356  goto unlockdescriptor;
357  }
358 
359  // User Notice: This is a required function call. If it is not here, there may be conflicts, data loss,
360  // or any number of undesirable things may occur.
361  if (ISF_SUCCESS != dm_channel_acquire_lock(&pDeviceDescriptor->cDescriptor, 0)) {
362  goto unlockdescriptor;
363  }
364 
365  // Set the sensor into STANDBY mode for configuration.
366  mpl3115_SetMode(&status, pSensorHandle, SENSOR_STANDBY);
367  if (ISF_SUCCESS != status) {
368  goto unlockchannel;
369  }
370 
371  // Configure the sensor.
372  retStat = mpl3115_SetConfig(pSensorHandle, pSensorSettings);
373  if (ISF_SUCCESS != retStat) {
374  goto unlockchannel;
375  }
376 
377  // Register the periodic callback function with the Bus Manager.
378  pDeviceDescriptor->token = bm_register_periodic_callback( pSensorSettings->nSamplePeriod, fsl_mpl3115_i2c_1D_press_PeriodicCallback , pSensorHandle);
379  if(BM_ERROR & pDeviceDescriptor->token){
380  goto unlockchannel;
381  }
382 
383  //Store the configured settings
384  pSensorHandle->controlData.sensorSettings = *pSensorSettings;
385 
387  retStat = ISF_SUCCESS;
388 
389  unlockchannel:
390  // Unlock the channel.
391  // The explicit lock must be released when the configuration is done allowing the bus to be used by others.
392  // User Notice: This is a required function call.
393  status = dm_channel_release_lock(&pDeviceDescriptor->cDescriptor);
394  if (ISF_SUCCESS != status)
395  {
396  retStat = status;
397  }
398 
399  unlockdescriptor:
400 
401  // Unlock the device descriptor.
402  //_lwsem_post(&pDeviceDescriptor->deviceSemaphore);
403  OSA_SemaPost(&pDeviceDescriptor->deviceSemaphore);
404 
405  return retStat;
406 }
407 
408 /*
409  ** ===================================================================
410  ** Method : fsl_mpl3115_i2c_1D_press_StartData (component ISFDSA)
411  ** @brief
412  **
413  ** Parameters :
414  ** NAME - DESCRIPTION
415  ** @param
416  ** isf_SensorHandle_t *pSensorHandle
417  ** @return
418  ** isf_dsa_status_t -
419  ** ===================================================================
420  */
422 {
423  // Check pointers.
424  if(NULL == pSensorHandle){
425  return DSA_ERR_PARAM;
426  }
427 
428  int32_t status;
429  int32_t retStat = DSA_ERR_START_DATA;
430  uint8 buffer[1];
431 
432  // Create helper reference pointers.
433  DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHandle->pDeviceDescriptor;
434 
435  // Check the device descriptor.
436  if (NULL == pDeviceDescriptor)
437  return DSA_ERR_PARAM;
438 
439  // Lock the device descriptor.
440  //_lwsem_wait_ticks(&pDeviceDescriptor->deviceSemaphore, 0);
441  OSA_SemaWait(&pDeviceDescriptor->deviceSemaphore, OSA_WAIT_FOREVER);
442 
443  // Check the driver state.
444  if (DSA_STATE_CONFIGURED_STOPPED > pSensorHandle->adapterStatus)
445  {
446  goto unlockdescriptor;
447  }
448 
449  // Start the One-Shot sampling.
450  mpl3115_StartSample(&status, pSensorHandle);
451  if (ISF_SUCCESS != status) {
452  goto unlockdescriptor;
453  }
454 
455  // Start the Bus Manager sampling timer.
456  if (BM_ERROR & bm_start(FALSE, pDeviceDescriptor->token)) // Check for Bus Manager error and return on failure.
457  goto unlockdescriptor;
458 
459  // Set device to active state.
461  retStat = ISF_SUCCESS;
462 
463  unlockdescriptor:
464  // Unlock the device descriptor.
465  //_lwsem_post(&pDeviceDescriptor->deviceSemaphore);
466  OSA_SemaPost(&pDeviceDescriptor->deviceSemaphore);
467 
468  return retStat;
469 }
470 
471 /*
472  ** ===================================================================
473  ** Method : fsl_mpl3115_i2c_1D_press_EndData (component ISFDSA)
474  ** @brief
475  **
476  ** Parameters :
477  ** NAME - DESCRIPTION
478  ** @param
479  ** isf_SensorHandle_t *pSensorHandle
480  ** @return
481  ** isf_dsa_status_t -
482  ** ===================================================================
483  */
485 {
486  // Check pointers.
487  if(NULL == pSensorHandle){
488  return DSA_ERR_PARAM;
489  }
490 
491  int32_t status;
492 
493  // Create helper reference pointers.
494  DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHandle->pDeviceDescriptor;
495 
496  // Set the default return status.
497  int32_t retStat = DSA_ERR_END_DATA;
498 
499  // Check the device descriptor.
500  if (NULL == pDeviceDescriptor)
501  return retStat;
502 
503  // Lock the device descriptor.
504  //_lwsem_wait_ticks(&pDeviceDescriptor->deviceSemaphore, 0);
505  OSA_SemaWait(&pDeviceDescriptor->deviceSemaphore, OSA_WAIT_FOREVER);
506 
507  // Check the driver state.
508  if (DSA_STATE_CONFIGURED_STOPPED >= pSensorHandle->adapterStatus)
509  goto unlockdescriptor;
510 
511  // Check that the adapter is not already started.
512  if (DSA_STATE_CONFIGURED_STARTED == pSensorHandle->adapterStatus) {
513  // If it is, then stop the Bus Manager (BM) sample timer.
514  isf_status_t bmStopStatus = bm_stop(pDeviceDescriptor->token);
515  if (BM_ERROR & bmStopStatus)
516  goto unlockdescriptor;
517  }
518 #if 0
519  // Set the sensor into STANDBY mode for configuration.
520  mpl3115_SetMode(&status, pSensorHandle, SENSOR_STANDBY);
521 #endif
522  if (ISF_SUCCESS != status) {
523  goto unlockdescriptor;
524  }
525 
527  retStat = ISF_SUCCESS;
528 
529 
530  unlockdescriptor:
531  // Unlock the device descriptor.
532  //_lwsem_post(&pDeviceDescriptor->deviceSemaphore);
533  OSA_SemaPost(&pDeviceDescriptor->deviceSemaphore);
534 
535  return retStat;
536 }
537 
538 /*
539  ** ===================================================================
540  ** Method : fsl_mpl3115_i2c_1D_press_Calibrate (component ISFDSA)
541  ** @brief
542  **
543  ** Parameters :
544  ** NAME - DESCRIPTION
545  ** @param
546  ** isf_SensorHandle_t *pSensorHandle
547  ** @return
548  ** isf_dsa_status_t -
549  ** ===================================================================
550  */
552 {
553  int32_t retStat = ISF_SUCCESS;
554 
555  return retStat;
556 }
557 
558 /*
559  ** ===================================================================
560  ** Method : fsl_mpl3115_i2c_1D_press_Shutdown (component ISFDSA)
561  ** @brief
562  **
563  ** Parameters :
564  ** NAME - DESCRIPTION
565  ** @param
566  ** isf_SensorHandle_t *pSensorHandle
567  ** @return
568  ** isf_dsa_status_t -
569  ** ===================================================================
570  */
572 {
573  if(NULL == pSensorHandle){
574  return DSA_ERR_PARAM;
575  }
576 
577  // Create helper reference pointers.
578  DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHandle->pDeviceDescriptor;
579 
580  // Remove the sensor adapter from the Bus Manager callbacks.
581  bm_unregister_callback(pDeviceDescriptor->token);
582  pSensorHandle->adapterStatus = DSA_STATE_INITIALIZED;
583  return ISF_SUCCESS;
584 
585 }
586 
587 /*
588  ** ===================================================================
589  ** Method : fsl_mpl3115_i2c_1D_press_PeriodicCallback (component ISFDSA)
590  ** @brief
591  **
592  ** Parameters :
593  ** NAME - DESCRIPTION
594  ** @param
595  ** void* pSensorHandle -
596  ** @return
597  ** void -
598  ** ===================================================================
599  */
601 {
602  int32_t status = 0;
603 
604  // Check pointers.
605  if(NULL == pSensorHandle){
606  return;
607  }
608 
609  // Create helper reference pointers.
610  volatile isf_SensorHandle_t *pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
612  DeviceDescriptor_t *pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHdl->pDeviceDescriptor;
613  isf_status_t st;
614  int32 numBytes;
615 
616  // Check the device descriptor
617  if (NULL == pDeviceDescriptor){
618  return;
619  }
620 
621  // Create a helper pointer to the current sample buffer.
622  mpl3115_DataBuffer_t *pCurrentSampleBuffer = (mpl3115_DataBuffer_t *)pDeviceDescriptor->pCurrentSample;
623 
624  // Apply sample skip if necessary.
625  if (pDeviceDescriptor->skipFramecnt) {
626  // Not done skipping samples.
627  --pDeviceDescriptor->skipFramecnt;
628  return;
629  }
630 
631  // Wait for Data Ready
632 // static int32 count = 0;
633 // while (0 == status)
634 // {
635 // mpl3115_DataReady(&status,pSensorHandle);
636 // count++;
637 // }
638 
639  // Get the time stamp
640  pCurrentSampleBuffer->timestamp = isf_time_util_get_usec();
641 
642  // Lock the device descriptor.
643  //if (MQX_OK !=_lwsem_wait_ticks(&pDeviceDescriptor->deviceSemaphore, 0))
644  if (kStatus_OSA_Success !=OSA_SemaWait(&pDeviceDescriptor->deviceSemaphore, OSA_WAIT_FOREVER))
645  {
646  goto unlockdescriptor;
647  }
648 
649 
650  // Check the driver state.
651  if (DSA_STATE_CONFIGURED_STARTED != pSensorHdl->adapterStatus)
652  {
653  goto unlockdescriptor;
654  }
655 
656  // Get sensor data.
657  mpl3115_GetData(pSensorHandle, pCurrentSampleBuffer); // Returns samples in big endian.
658 
659  // Lock the fifo for update.
660  if(kStatus_OSA_Success != isf_fifo_lock(pFifo)){
661  return;
662  }
663 
665 
666 
667  // write the new data
669  {
670  *pFifoEntry = *pCurrentSampleBuffer;
671  }
672  else
673  {
675  pSensorHdl,
678  pCurrentSampleBuffer,
679  pFifoEntry,
680  &numBytes);
681  }
682 
683  // Increment the fifo to the next sample entry.
684  st = isf_fifo_el_increment(pFifo);
685 
686  // Unlock the fifo.
687  isf_fifo_unlock(pFifo);
688 
689  if (st == ISF_FIFO_FULL)
690  {
691  // Notify the user using their registered event information
692  //_lwevent_set(pSensorHdl->controlData.pEventGroup,(uint32_t)pSensorHdl->controlData.nEventFieldIndex);
693  OSA_EventSet(pSensorHdl->controlData.pEventGroup,(uint32_t)pSensorHdl->controlData.nEventFieldIndex);
694  }
695 
696  unlockdescriptor:
697  // Unlock the device descriptor.
698  //_lwsem_post(&pDeviceDescriptor->deviceSemaphore);
699  OSA_SemaPost(&pDeviceDescriptor->deviceSemaphore);
700 
701  // Start the next One-Shot sampling.
702  mpl3115_StartSample(&status, pSensorHandle);
703  if (ISF_SUCCESS != status) {
704  goto unlockdescriptor;
705  }
706 
707 }
708 
709 /*!
710  * @brief This function coverts the raw sample data to the desired output type.
711  */
713 (
714  volatile isf_SensorHandle_t *pSensorHandle,
715  isf_SensorDataTypes_t convertToType, isf_dsa_result_types_t resultType,
716  void *pNativeSample,
717  void *pConvertedSample,
718  int32 *numBytes
719 )
720 {
723 
724  pConverter = NULL;
725 
726  switch (convertToType)
727  {
728  case TYPE_PRESSURE:
729  if (resultType == DSA_RESULT_TYPE_ENG_FLOAT)
730  pConverter = float_press1d_converter;
731  else if (resultType == DSA_RESULT_TYPE_ENG_FIXED)
732  pConverter = fixed_press1d_converter;
733  break;
734 
735  case TYPE_ALTITUDE:
736  if (resultType == DSA_RESULT_TYPE_ENG_FLOAT)
737  pConverter = float_alt1d_converter;
738  else if (resultType == DSA_RESULT_TYPE_ENG_FIXED)
739  pConverter = fixed_alt1d_converter;
740  break;
741 
742  case TYPE_TEMPERATURE:
743  if (resultType == DSA_RESULT_TYPE_ENG_FLOAT)
744  pConverter = float_temp1d_converter;
745  else if (resultType == DSA_RESULT_TYPE_ENG_FIXED)
746  pConverter = fixed_temp1d_converter;
747  break;
748 
749  default:
751  }
752  if (pConverter == NULL)
754 
755  retStat = pConverter(
757  (mpl3115_DataBuffer_t *)pNativeSample,
758  pConvertedSample
759  );
760 
761  return retStat;
762 }
763 
764 static isf_dsa_status_t float_press1d_converter(mpl3115_Sensor_Specific_Settings_t *pSensorSpecificConfig, mpl3115_DataBuffer_t *nativeSample, void *vpConvertedSample )
765 {
766  isf_KiloPascals1D_float_t *convertedSample = (isf_KiloPascals1D_float_t *)vpConvertedSample;
767  convertedSample->timestamp = nativeSample->timestamp;
769  return ISF_SUCCESS;
770 }
771 
772 static isf_dsa_status_t fixed_press1d_converter(mpl3115_Sensor_Specific_Settings_t *pSensorSpecificConfig, mpl3115_DataBuffer_t *nativeSample, void *vpConvertedSample )
773 {
774  isf_KiloPascals1D_EngFixed_t *convertedSample = (isf_KiloPascals1D_EngFixed_t *)vpConvertedSample;
775  convertedSample->timestamp = nativeSample->timestamp;
777  return ISF_SUCCESS;
778 }
779 
780 
781 static isf_dsa_status_t float_alt1d_converter(mpl3115_Sensor_Specific_Settings_t *pSensorSpecificConfig, mpl3115_DataBuffer_t *nativeSample, void *vpConvertedSample )
782 {
783  isf_Meters1D_float_t *convertedSample = (isf_Meters1D_float_t *)vpConvertedSample;
784  convertedSample->timestamp = nativeSample->timestamp;
785  // Convert the sensor pressure measurement into altitude.
787  return ISF_SUCCESS;
788 }
789 
790 static isf_dsa_status_t fixed_alt1d_converter(mpl3115_Sensor_Specific_Settings_t *pSensorSpecificConfig, mpl3115_DataBuffer_t *nativeSample, void *vpConvertedSample )
791 {
792  isf_Meters1D_EngFixed_t *convertedSample = (isf_Meters1D_EngFixed_t *)vpConvertedSample;
793  convertedSample->timestamp = nativeSample->timestamp;
795  return ISF_SUCCESS;
796 }
797 
798 static isf_dsa_status_t float_temp1d_converter(mpl3115_Sensor_Specific_Settings_t *pSensorSpecificConfig, mpl3115_DataBuffer_t *nativeSample, void *vpConvertedSample )
799 {
800  isf_DegreesCelsius1D_float_t *convertedSample = (isf_DegreesCelsius1D_float_t *)vpConvertedSample;
801  convertedSample->timestamp = nativeSample->timestamp;
803  return ISF_SUCCESS;
804 }
805 
806 static isf_dsa_status_t fixed_temp1d_converter(mpl3115_Sensor_Specific_Settings_t *pSensorSpecificConfig, mpl3115_DataBuffer_t *nativeSample, void *vpConvertedSample )
807 {
808  isf_DegreesCelsius1D_EngFixed_t *convertedSample = (isf_DegreesCelsius1D_EngFixed_t *)vpConvertedSample;
809  convertedSample->timestamp = nativeSample->timestamp;
811  return ISF_SUCCESS;
812 }
813 
814 /*!
815  * @brief This function resets the MPL3115 sensor resulting in a default configuration for
816  * all registers.
817  */
818 void mpl3115_Reset(int32_t* status, void* pSensorHandle)
819 {
820  uint8 buffer[1] = {0};
821 
822  // Create and validate helper reference pointers.
823  isf_SensorHandle_t* pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
824  DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHdl->pDeviceDescriptor;
825  dm_DeviceDescriptor_t* pDeviceHandle = &pDeviceDescriptor->deviceHandle;
826 
827  // Reset the device.
828  // Put the device the STANDBY state which is required before any configuration registers are set.
829  buffer[0]= MPL3115_RST_MASK; // no shift
830  if (ISF_SUCCESS != dm_device_write(pDeviceHandle, MPL3115_CTRL_REG1, buffer, 1, 1)){
831  *status = DSA_ERR_INITIALIZE;
832  return;
833  }
834 
835  OSA_TimeDelay(1000/5); // Turn-on time = 1 second (MPL3115 Data Sheet) for OSR = 2^7 (128).
836 
837  *status = ISF_SUCCESS;
838 }
839 
840 /*!
841  * @brief This function validates the MPL3115 sensor is connected via the I2C bus.
842  */
843 void mpl3115_CheckId(int32_t *status, void* pSensorHandle)
844 {
845  uint8 buffer[1] = {0};
846  int32 retStat = SENSOR_ERROR_CHECKID;
847 
848  // Create and validate helper reference pointers.
849  isf_SensorHandle_t* pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
850  DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHdl->pDeviceDescriptor;
851  dm_DeviceDescriptor_t* pDeviceHandle = &pDeviceDescriptor->deviceHandle;
852 
853  if (ISF_SUCCESS != dm_device_read(pDeviceHandle, MPL3115_WHO_AM_I, &buffer[0], 1, 1)){
854  *status = retStat;
855  }
856  if (MPL3115_WHOAMI_VALUE != buffer[0]) {
857  *status = retStat;
858  }
859 
860  *status = ISF_SUCCESS;
861 }
862 
863 /*!
864  * @brief This function validates the configuration for the MPL3115 sensor.
865  */
866 void mpl3115_ValidateConfig(int32_t *status, void *pSensorHandle)
867 {
868  int32 os;
869 
870  // Check the input arguments.
871  if (NULL == pSensorHandle) {
872  *status = DSA_ERR_PARAM;
873  return;
874  }
875  // Create and validate helper reference pointers.
876  isf_SensorHandle_t* pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
878 
879 
880  // Check the sample period
881  os = get_OS(pSettings->nSamplePeriod);
882 
883  if (os < 0)
884  {
885  *status = DSA_ERR_VALIDATE_SETTINGS;
886  return;
887  }
888 
889  *status = ISF_SUCCESS;
890 }
891 
892 /*!
893  * @brief This function sets the MPL3115 part to the requested mode.
894  */
895 void mpl3115_SetMode(int32_t* status, void* pSensorHandle, int32_t Mode)
896 {
897  isf_SensorHandle_t* pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
898  DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHdl->pDeviceDescriptor;
899  dm_DeviceDescriptor_t* pDeviceHandle = &pDeviceDescriptor->deviceHandle;
900 
901  uint8 buffer[1] = {0x00};
902 
903  switch(Mode)
904  {
905  // This will put the sensor into the standby mode
906  case SENSOR_STANDBY:
907  case SENSOR_BOOT:
908  case SENSOR_READY:
909  {
910  // this sensor requires read-modify-write
911  if (ISF_SUCCESS != dm_device_read(pDeviceHandle, MPL3115_CTRL_REG1, buffer, 1, 1) ){
912  *status = SENSOR_ERROR_SETMODE;
913  return;
914  }
915  buffer[0] = (buffer[0] & ~MPL3115_ACTIVE_MASK);
916  if (ISF_SUCCESS != dm_device_write(pDeviceHandle, MPL3115_CTRL_REG1, buffer, 1, 1) ){
917  *status = SENSOR_ERROR_SETMODE;
918  return;
919  }
920  }
921  break;
922 
923  // This will put the sensor into the active state
924  case SENSOR_ACTIVE:
925  {
926  // this sensor requires read-modify-write
927  if (ISF_SUCCESS != dm_device_read(pDeviceHandle, MPL3115_CTRL_REG1, buffer, 1, 1) ){
928  *status = SENSOR_ERROR_SETMODE;
929  return;
930  }
931  buffer[0] = (buffer[0] | MPL3115_ACTIVE_MASK);
932  if (ISF_SUCCESS != dm_device_write(pDeviceHandle, MPL3115_CTRL_REG1, buffer, 1, 1) ){
933  *status = SENSOR_ERROR_SETMODE;
934  return;
935  }
936  // Read the value of the status register to wait for valid data
937  buffer[0] = 0;
938  do {
939  if (ISF_SUCCESS != dm_device_read(pDeviceHandle, MPL3115_STATUS_00, buffer, 1, 1) ){
940  *status = SENSOR_ERROR_SETMODE;
941  return;
942  }
943  OSA_TimeDelay(1); // short delay to yield CPU/RTOS.
944  } while (0 == MPL3115_GET_FIELD(PTDR,buffer[0]) ); // Wait for Data Ready.
945  }
946  break;
947 
948  default:
949  *status = SENSOR_ERROR_SETMODE;
950  return;
951  }
952  // return success
953  *status = ISF_SUCCESS;
954 }
955 /*!
956  * @brief This function sets the MPL3115 part to the requested mode.
957  */
958 void mpl3115_StartSample(int32_t* status, void* pSensorHandle)
959 {
960  isf_SensorHandle_t* pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
961  DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHdl->pDeviceDescriptor;
962  dm_DeviceDescriptor_t* pDeviceHandle = &pDeviceDescriptor->deviceHandle;
963 
964  uint8 buffer[1] = {0x00};
965 
966  // this sensor requires read-modify-write
967  if (ISF_SUCCESS != dm_device_read(pDeviceHandle, MPL3115_CTRL_REG1, buffer, 1, 1) ){
968  *status = SENSOR_ERROR_SETMODE;
969  return;
970  }
971  buffer[0] = (buffer[0] | MPL3115_SET_FIELD(SBYB,0) | MPL3115_SET_FIELD(OST,1));
972  if (ISF_SUCCESS != dm_device_write(pDeviceHandle, MPL3115_CTRL_REG1, buffer, 1, 1) ){
973  *status = SENSOR_ERROR_SETMODE;
974  return;
975  }
976 
977  // return success
978  *status = ISF_SUCCESS;
979 }
980 
981 /*!
982  * @brief This function sets the MPL3115 part to the requested mode.
983  */
984 void mpl3115_DataReady(int32_t* status, void* pSensorHandle)
985 {
986  isf_SensorHandle_t* pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
987  DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHdl->pDeviceDescriptor;
988  dm_DeviceDescriptor_t* pDeviceHandle = &pDeviceDescriptor->deviceHandle;
989 
990  uint8 buffer[1] = {0x00};
991 
992  // this sensor requires read-modify-write
993  if (ISF_SUCCESS != dm_device_read(pDeviceHandle, MPL3115_STATUS_00, buffer, 1, 1) ){
994  *status = SENSOR_ERROR_SETMODE;
995  return;
996  }
997  *status = MPL3115_GET_FIELD(PTDR,buffer[0]); // Data Ready.
998 }
999 
1000 /*!
1001  * @brief This function retrieves the raw data from the MPL3115 sensor.
1002  */
1003 #define BYTES_FOR_FULL_READ 5
1004 
1006 {
1008 
1009  DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHandle->pDeviceDescriptor;
1010  dm_DeviceDescriptor_t* pDeviceHandle = &pDeviceDescriptor->deviceHandle;
1011 
1012  uint8 registerData[BYTES_FOR_FULL_READ];
1013 
1014  // read the full width of the data for both full or short reads
1016  {
1017  return retStat;
1018  }
1019  // copy the pressure data into the raw sample buffer.
1020  pData->pressure = (((uint32)registerData[0]) << 24) | (((uint32)registerData[1] << 16)) | (((uint32)registerData[2] << 8));
1021  pData->altitude = convertPressureToAltitude(pData->pressure);
1022  // copy the temperature data into the destination buffer.
1023  pData->temperature = (int16)(((int16)registerData[3]) << 8) | (((uint32)registerData[4]));
1024 
1025  // return success
1026  return ISF_SUCCESS;
1027 }
1028 
1029 //#define MPL3115_DEBUG
1030 #ifdef MPL3115_DEBUG
1031 static uint8 mpl3115_Reg[50];
1032 void mpl3115_ReadRegisters( isf_SensorHandle_t *pSensorHandle )
1033 {
1034  uint8 buffer[1];
1035  DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHandle->pDeviceDescriptor;
1036  dm_DeviceDescriptor_t* pDeviceHandle = &pDeviceDescriptor->deviceHandle;
1037 
1038  for (uint8 i = MPL3115_WHO_AM_I; i<=MPL3115_OFF_H; i++)
1039  {
1040  dm_device_read(pDeviceHandle, i, buffer, 1, 1);
1041  mpl3115_Reg[i] = buffer[0];
1042  }
1043 }
1044 #endif
1045 
1046 /*!
1047  * @brief This function sets the MPL3115 sensor configuration.
1048  */
1050 {
1051  int32_t retStat = DSA_ERR_CONFIGURE; // Return Status
1052 
1053  // Create helper reference pointers.
1054  DeviceDescriptor_t *pDeviceDescriptor = (DeviceDescriptor_t*) pSensorHandle->pDeviceDescriptor;
1056  dm_DeviceDescriptor_t *pDeviceHandle = &pDeviceDescriptor->deviceHandle;
1057 
1058  /* Write the sensor specific data based on the pre-computed register level pairs (Addr, Value) */
1059  uint8 buffer[1];
1060  for (uint32 reg=0; reg < pConfigSpecific->regCount; reg++)
1061  {
1062  buffer[0] = pConfigSpecific->regPairs[reg].regValue;
1063  if (ISF_SUCCESS != dm_device_write(pDeviceHandle, pConfigSpecific->regPairs[reg].regAddr,&buffer[0],1,1))
1064  {
1065  return retStat;
1066  }
1067  }
1068 
1069 #if 0
1070  // Check the sample period
1071  int32 os = get_OS(pConfigSettings->nSamplePeriod);
1072 
1073  // Set up the Control register #1.
1074  buffer[0] = MPL3115_SET_FIELD(OS,os); // Set over-sample ratio.
1075  if (ISF_SUCCESS != dm_device_write(&pDeviceDescriptor->deviceHandle, MPL3115_CTRL_REG1, buffer, 1, 1) ) return MPL3115_ERROR;
1076 #endif
1077 
1078  // Set up the Control register #2.
1079  buffer[0] = MPL3115_SET_FIELD(ST,0); // Set to 1 Hz
1080  if (ISF_SUCCESS != dm_device_write(&pDeviceDescriptor->deviceHandle, MPL3115_CTRL_REG2, buffer, 1, 1) ) return MPL3115_ERROR;
1081 
1082 #ifdef MPL3115_DEBUG
1083  // DEBUG: Read back the entire set of device registers
1084  mpl3115_ReadRegisters( pSensorHandle );
1085 #endif
1086 
1087  return ISF_SUCCESS;
1088 }
1089 
1091 {
1092  // pressure from sensor is 20-bit unsigned and shift to LSB.
1093  // LS 2-bits are fractional Pascals, so shift, cast, then divide by 2^2.
1094  float fPressure = ((float)(pressure >> 12)/(float)4.0);
1095  float fHeight;
1096 
1097  fLfi(&pressure_to_height,fPressure,&fHeight);
1098 
1099  return (((int32)(fHeight*16.0))<<12);
1100 }
1101 
1102 
1103 
1104 #define ABSOLUTE_VALUE(x) ( (x) < 0.0 ? (-(x)) : (x))
1105 #define ZERO_EPSILON (1.0E-10)
1106 #define IS_PRACTICALLY_ZERO(x) ( ABSOLUTE_VALUE(x) < ZERO_EPSILON )
1107 long fLfi(const fLfiTable_t *lookupTable, float x_in, float *y_out)
1108 {
1109  int i = 0;
1110  float delta_x_table;
1111  float delta_y_table;
1112  float delta_x_point;
1113 
1114  if (lookupTable == 0 ) return LFI_BAD_PTR;
1115 
1116  if (lookupTable->maxIdx < 1) return LFI_BAD_TABLE;
1117 
1118  /* Check if x_in is below the table bottom */
1119  if ( x_in < lookupTable->dataPoints[i].x )
1120  {
1121  if ( lookupTable->extrapolationBehavior == LFI_TABLE_LIMITS )
1122  {
1123  *y_out = lookupTable->dataPoints[i].y;
1124  return LFI_SUCCESS;
1125  }
1126  else if (lookupTable->extrapolationBehavior == LFI_NO_EXTRAPOLATION )
1127  {
1128  return LFI_OUT_OF_RANGE;
1129  }
1130  }
1131 
1132  /* just use sequential search for now */
1133  for (i=1; i < lookupTable->maxIdx; i++ )
1134  {
1135  if ( x_in < lookupTable->dataPoints[i].x ) break;
1136  }
1137 
1138  /* Check if x_in is above the table top */
1139  if ( x_in > lookupTable->dataPoints[i].x )
1140  {
1141  if (lookupTable->extrapolationBehavior == LFI_TABLE_LIMITS)
1142  {
1143  *y_out = lookupTable->dataPoints[i].y;
1144  return LFI_SUCCESS;
1145  }
1146  else if ( lookupTable->extrapolationBehavior == LFI_NO_EXTRAPOLATION )
1147  {
1148  return LFI_OUT_OF_RANGE;
1149  }
1150  }
1151 
1152  /* Perform interpolation/extrapolation */
1153  delta_x_table = lookupTable->dataPoints[i].x - lookupTable->dataPoints[i-1].x;
1154  if ( IS_PRACTICALLY_ZERO(delta_x_table))
1155  {
1156  return LFI_BAD_TABLE;
1157  }
1158  delta_y_table = lookupTable->dataPoints[i].y - lookupTable->dataPoints[i-1].y;
1159  delta_x_point = x_in - lookupTable->dataPoints[i].x;
1160  *y_out = delta_y_table/delta_x_table *(delta_x_point) + lookupTable->dataPoints[i].y;
1161 
1162  return LFI_SUCCESS;
1163 }
1164 
1165 /*! @brief The local function to validate the sample rate and establish the over-sample ratio appropriate for the desired rate.
1166  *
1167  * @param[in] samplePeriod This sample period.
1168  *
1169  * @return ::get_OS() returns a value of uint32 indicating the ODR value.
1170  *
1171  * @Constraints None
1172  *
1173  * @Reentrant Yes
1174  */
1175 static int32 get_OS(uint32 samplePeriod)
1176 {
1177  uint8 i = 0, flag=0;
1178 
1179  for (i = 0; i < (sizeof(mpl3115_osTable)/sizeof(mpl3115_OS_Table_t)); i++)
1180  {
1181  if(mpl3115_osTable[i].samplePeriod == samplePeriod)
1182  {
1183  flag=1;
1184  break;
1185  }
1186 
1187  }
1188  if(flag==1)
1189  {
1190  return mpl3115_osTable[i].osConfigVal;
1191  }
1192  else
1193  {
1194  return -1;
1195  }
1196  return -1; // Should never get here.
1197 }
1198 
1199 
1200 /*
1201  * Local Subroutines
1202  */
1203 
1204 /*!
1205  ** @}
1206  */
1207 /* END fsl_mpl3115_i2c_1D_press.c */
1208 
1209 
isf_status_t dm_channel_start(dm_ChannelDescriptor_t *apChannelDescriptor)
This function starts a channel.
isf_temperature_degC_float_t temperature
void * pSensorSpecificSettings
#define MPL3115_ALT_FLOAT_CONVERSION_OFFSET
unsigned char uint8
Definition: isf_types.h:76
#define MPL3115_PRESS_FLOAT_CONVERSION_OFFSET
#define MPL3115_TEMP_FLOAT_CONVERSION_FACTOR
isf_dsa_status_t fsl_mpl3115_i2c_1D_press_Shutdown(isf_SensorHandle_t *pSensorHandle)
uint32 isf_time_util_get_usec(void)
This API returns the time in microseconds.
Definition: isf_util.c:55
Standard fixed type for single axis altitude sensor.
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.
const void * commInfo
isf_dsa_ControlData_t controlData
isf_fifo_status_t isf_fifo_lock(isf_fifo_t *pFifo)
Lock a sample buffer for exclusive access.
Definition: isf_fifo.c:170
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.
Definition: isf_fifo.c:199
Standard floating point type for single axis temperature sensor.
isf_fifo_status_t isf_fifo_el_increment(isf_fifo_t *pFifo)
Routine increments the insert pointer after direct access.
Definition: isf_fifo.c:237
isf_sensors.h contains the ISF Generic Sensor definitions and data structures required when a client ...
#define FALSE
Definition: isf_types.h:86
void mpl3115_ValidateConfig(int32_t *status, void *pSensorHandle)
This function validates the configuration for the MPL3115 sensor.
API definitions, types, and macros for the Intelligent Sensing Framework (ISF) Bus Manager (BM)...
isf_altitude_meters_float_t altitude
isf_dsa_status_t fsl_mpl3115_i2c_1D_press_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.
dm_DeviceDescriptor_t deviceHandle
Definition: isf_sensors.h:52
#define MPL3115_ALT_FIXED_CONVERSION_OFFSET
This defines the DSA sensor device handle structure used to invoke the adapter access functions...
long fLfi(const fLfiTable_t *lookupTable, float lFiIn, float *lfiOut)
isf_timestamp_t timestamp
#define MPL3115_PRESS_FIXED_CONVERSION_FACTOR
Define the sensor device descriptor.
Definition: isf_sensors.h:49
#define MPL3115_TEMP_FLOAT_CONVERSION_OFFSET
void mpl3115_Reset(int32_t *status, void *pSensorHandle)
This function resets the MPL3115 sensor resulting in a default configuration for all registers...
isf_pressure_kPa_fixed_32s1i16_t pressure
#define MPL3115_TEMP_FIXED_CONVERSION_OFFSET
isf_SensorTypes_t
dm_ChannelDescriptor_t cDescriptor
Definition: isf_sensors.h:51
unsigned char maxIdx
void mpl3115_DataReady(int32_t *status, void *pSensorHandle)
This function sets the MPL3115 part to the requested mode.
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_SensorDataTypes_t mpl3115_SupportedDataTypes[]
#define MPL3115_WHOAMI_VALUE
Definition: mpl3115.h:101
#define MPL3115_TEMP_FIXED_CONVERSION_FACTOR
the structure defines the OS table for MPL3115 operation.
The isf_types.h file contains the ISF data type definitions and some of the globally used macros...
The isf_pressure_types.h file contains the ISF data type definitions for use with the ISF generic pre...
#define MPL3115_ACTIVE_MASK
Definition: mpl3115.h:108
void mpl3115_CheckId(int32_t *status, void *pSensorHandle)
This function validates the MPL3115 sensor is connected via the I2C bus.
const mpl3115_OS_Table_t mpl3115_osTable[]
The table that describes the configuration value based on OS (oversample ratio).
#define BYTES_FOR_FULL_READ
This function retrieves the raw data from the MPL3115 sensor.
isf_dsa_status_t fsl_mpl3115_i2c_1D_press_Configure(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
isf_dsa_status_t fsl_mpl3115_i2c_1D_press_Calibrate(isf_SensorHandle_t *pSensorHandle, void *pCalData)
isf_temperature_degC_fixed_32s1i16_t temperature
mpl3115_status_t
Definition: mpl3115.h:218
int32 isf_dsa_status_t
This is the Sensor Manager API return type definition.
#define MPL3115_PRESS_FIXED_CONVERSION_OFFSET
This structure defines the dummy DSA data buffer format.
isf_alt_meters_fixed_32s1i16_t altitude
isf_dsa_status_t fsl_mpl3115_i2c_1D_press_ValidateSettings(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
signed short int int16
Definition: isf_types.h:73
#define MPL3115_RST_MASK
Definition: mpl3115.h:147
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.
void mpl3115_SetMode(int32_t *status, void *pSensorHandle, int32_t Mode)
This function sets the MPL3115 part to the requested mode.
The isf_util.h file contains the utility method declarations and macros.
enum isf_dsa_result_enums isf_dsa_result_types_t
Standard floating point type for single axis pressure sensor.
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.
The fsl_mpl3115_i2c_1D_press.h file contains the definitions and functions supporting the MMA8652 Sen...
isf_dsa_status_t mpl3115_GetData(isf_SensorHandle_t *pSensorHandle, mpl3115_DataBuffer_t *pData)
The mpl3115.h contains the MPL3115 Pressure sensor register definitions, access macros, and device access functions.
#define MPL3115_ALT_FLOAT_CONVERSION_FACTOR
isf_dsa_result_types_t resultFormat
isf_SensorDataTypes_t
void fsl_mpl3115_i2c_1D_press_PeriodicCallback(void *pSensorHandle)
isf_status_t dm_channel_init(dm_ChannelId_t aChannelId, dm_ChannelDescriptor_t *apChannelDescriptor)
This function initializes a channel.
#define IS_PRACTICALLY_ZERO(x)
The isf_altitude_types.h file contains the ISF data type definitions for use with the ISF generic alt...
The isf_temperature_fixed_t.h file contains the ISF data type definitions for use with the ISF generi...
isf_dsa_status_t mpl3115_SetConfig(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pConfigSettings)
This function sets the MPL3115 sensor configuration.
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.
Standard fixed type for single axis pressure sensor.
isf_pressure_kPa_float_t pressure
isf_SensorDataTypes_t resultType
#define MPL3115_ALT_FIXED_CONVERSION_FACTOR
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...
#define MPL3115_SET_FIELD(name, val)
Definition: mpl3115.h:81
isf_dsa_status_t fsl_mpl3115_i2c_1D_press_StartData(isf_SensorHandle_t *pSensorHandle)
isf_dsa_AdapterStatus_t adapterStatus
signed long int int32
Definition: isf_types.h:74
sys_channelId_t channelId
Standard fixed type for single axis pressure sensor.
isf_SensorTypes_t mpl3115_SupportedSensorTypes[]
Supported sensor and data types for MPL3115.
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...
Definition: isf_bm.h:57
unsigned char extrapolationBehavior
int32 isf_status_t
ISF return status type.
Definition: isf.h:76
Standard floating point type for single axis altitude sensor.
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 MPL3115_GET_FIELD(name, val)
Definition: mpl3115.h:82
void * isf_fifo_el_get_insert_pointer(isf_fifo_t *pFifo)
Routine returns the insert pointer for direct access.
Definition: isf_fifo.c:229
isf_status_t dm_channel_release_lock(dm_ChannelDescriptor_t *apChannelDescriptor)
This function releases exclusive channel access.
unsigned long int uint32
Definition: isf_types.h:78
This structure defines a handle for the device.
Definition: isf_devmsg.h:61
void mpl3115_StartSample(int32_t *status, void *pSensorHandle)
This function sets the MPL3115 part to the requested mode.
int32 convertPressureToAltitude(uint32 pressure)
isf_dsa_status_t fsl_mpl3115_i2c_1D_press_Initialize(isf_SensorHandle_t *pSensorHandle)
semaphore_t deviceSemaphore
Definition: isf_sensors.h:54
This structure is a declaration of a channel descriptor type.
Definition: isf_devmsg.h:50
#define ISF_FIFO_FULL
Definition: isf_fifo.h:33
dataPair_t dataPoints[]
bm_callback_token_t token
Definition: isf_sensors.h:53
#define MPL3115_PRESS_FLOAT_CONVERSION_FACTOR
isf_dsa_status_t fsl_mpl3115_i2c_1D_press_EndData(isf_SensorHandle_t *pSensorHandle)
uint32 timestamp
Time stamp value in micro-seconds.