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

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

fsl_mma865x_i2c_3D_accel.c
Go to the documentation of this file.
1 /*
2 *
3 * Copyright (c) 2015, Freescale Semiconductor, Inc.
4 *
5 */
6 /**
7 ** @file fsl_mma865x_i2c_3D_accel.c
8 ** @version 01.00
9 ** @brief
10 **
11 */
12 /**
13 ** @addtogroup fsl_mma865x_i2c_3D_accel_module fsl_mma865x_i2c_3D_accel module documentation
14 ** @{
15 */
16
17 /* MODULE fsl_mma865x_i2c_3D_accel. */
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_accelerometer_types.h>
27 #include <isf_comm.h>
28 #include <isf_util.h>
29 #include <isf_sensors.h>
30 #include "fsl_os_abstraction.h"
31 #include "mma865x.h"
32 #include "fsl_mma865x_i2c_3D_accel.h"
33
34
35 /*! @brief User specified settings that may change */
36 static mma865x_Specific_Settings_t mma865x_settings;
37
38
39 /*! @brief The constant array, fsl_mma865x_period, maps the available sample rates into the compatible sampling periods. */
40 static const isf_duration_t fsl_mma865x_period[] =
41 {
42 1250, // 800 Hz
43 2500, // 400 Hz
44 5000, // 200 Hz
45 10000, // 100 Hz
46 20000, // 50 Hz
47 80000, // 12.5 Hz
48 160000, // 6.25 Hz
49 640000 // 1.56 Hz
50 };
51
52 /*
53 * @brief This table contains the Accel conversion factors based on the full-scale range selected.
54 */
55 const struct
56 {
57 float floatFactor;
58 float floatOffset;
59 int32 fixedFactor;
60 int32 fixedOffset;
61 }mma865xAccelConvTable[] =
62 {
63 { 0.000061, 0.0, 16, 0},
64 { 0.000122, 0.0, 32, 0},
65 { 0.000244, 0.0, 64, 0}
66 };
67
68 isf_SensorTypes_t mma865x_SupportedSensorTypes[] = { TYPE_ACCELEROMETER_3D, TYPE_NATIVE_SENSOR_TYPE };
69 isf_SensorDataTypes_t mma865x_SupportedDataTypes[] = { TYPE_RAW_ACCELERATION_3D, TYPE_NATIVE_SENSOR_DATA_TYPE };
70
71 // Define the MMA865x functional interface status return type.
72 typedef int32 mma865x_status_t;
73
74 /*
75 * Local function prototypes.
76 */
77 void mma865x_Reset(int32_t *status, void* pSensorHandle);
78 void mma865x_CheckId(int32_t *status, void* pSensorHandle);
79 void mma865x_SetMode(int32_t *status, void* pSensorHandle, int32_t Mode);
80 void mma865x_ValidateConfig(int32_t *status, void* pSensorHandle, void* pSettings);
81 isf_dsa_status_t mma865x_GetConfig(isf_dsa_SensorSettings_t* pRequiredSettings, DeviceDescriptor_t* pDeviceDes);
82 isf_dsa_status_t mma865x_SetConfig(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pConfigSettings);
83 isf_dsa_status_t mma865x_GetData(isf_SensorHandle_t *pSensorHandle, void* pBuffer);
84
85 // Converter routines for the supported data types
86 static isf_dsa_status_t float_accel3d_converter(mma865x_Sensor_Specific_Settings_t *pSensorSpecificConfig, mma865x_DataBuffer_t *nativeSample, void *vpConvertedSample );
87 static isf_dsa_status_t fixed_accel3d_converter(mma865x_Sensor_Specific_Settings_t *pSensorSpecificConfig, mma865x_DataBuffer_t *nativeSample, void *vpConvertedSample );
88 static isf_dsa_status_t count_accel3d_converter(mma865x_Sensor_Specific_Settings_t *pSensorSpecificConfig, mma865x_DataBuffer_t *nativeSample, void *vpConvertedSample );
89 /*
90 ** ===================================================================
91 ** Method : fsl_mma865x_i2c_3D_accel_Initialize (component ISFDSA)
92 ** @brief
93 **
94 ** Parameters :
95 ** NAME - DESCRIPTION
96 ** @param
97 ** isf_SensorHandle_t *pSensorHandle
98 ** @return
99 ** isf_dsa_status_t -
100 ** ===================================================================
101 */
102 isf_dsa_status_t fsl_mma865x_i2c_3D_accel_Initialize(isf_SensorHandle_t *pSensorHandle)
103 {
104 if ( NULL == pSensorHandle){
105 return DSA_ERR_PARAM;
106 }
107
108 int32_t status;
109
110 // Check if the sensor is available, and that it has already been initialized.
111 if (pSensorHandle->adapterStatus > DSA_STATE_NOT_INITIALIZED) {
112 return DSA_ERR_INITIALIZE;
113 }
114
115 // Allocate the adapter specific memory for the descriptor
116 //pSensorHandle->pDeviceDescriptor = (DeviceDescriptor_t *)_lwmem_alloc_system_zero(sizeof(DeviceDescriptor_t));
117 pSensorHandle->pDeviceDescriptor = (DeviceDescriptor_t *)OSA_MemAllocZero(sizeof(DeviceDescriptor_t));
118
119 // Create and validate helper reference pointers.
120 DeviceDescriptor_t *pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHandle->pDeviceDescriptor;
121
122 if (NULL == pDeviceDescriptor) {
123 return DSA_ERR_INITIALIZE;
124 }
125
126 // Allocate the current sample data buffer and initialize it.
127 //pDeviceDescriptor->pCurrentSample = _lwmem_alloc_system_zero(sizeof(mma865x_DataBuffer_t));
128 pDeviceDescriptor->pCurrentSample = OSA_MemAllocZero(sizeof(mma865x_DataBuffer_t));
129 mma865x_DataBuffer_t *pCurrentSampleBuffer = (mma865x_DataBuffer_t *)pDeviceDescriptor->pCurrentSample;
130 pCurrentSampleBuffer->timeStamp = 0;
131 pCurrentSampleBuffer->accel[0] = 0;
132 pCurrentSampleBuffer->accel[1] = 0;
133 pCurrentSampleBuffer->accel[2] = 0;
134 pCurrentSampleBuffer->addr = ((i2c_device_t *)pSensorHandle->pSensorStaticConfig->commInfo)->address;
135
136 dm_ChannelDescriptor_t *pChannelDescriptor = &pDeviceDescriptor->cDescriptor;
137
138 // Initialize the channel
139 if(ISF_SUCCESS != dm_channel_init(pSensorHandle->pSensorStaticConfig->channelId, pChannelDescriptor)){
140 return DSA_ERR_INITIALIZE;
141 }
142 // Start the Bus
143 if(ISF_SUCCESS != dm_channel_start(pChannelDescriptor)){
144 return DSA_ERR_INITIALIZE;
145 }
146
147 // Get the Channel state to check if it is ready to use
148 if (COMM_STATE_OK != dm_channel_get_state(pChannelDescriptor)) {
149 return DSA_ERR_INITIALIZE;
150 }
151
152 // Open the device and get the device handler
153 if(ISF_SUCCESS != dm_device_open(pChannelDescriptor, (void *)pSensorHandle->pSensorStaticConfig->commInfo, &pDeviceDescriptor->deviceHandle)){
154 return DSA_ERR_INITIALIZE;
155 }
156
157 // A very short delay is needed for device startup.
158 OSA_TimeDelay(1);
159
160 // Query the sensor to validate Device Messaging initialization and the sensor identity.
161 mma865x_CheckId(&status,pSensorHandle);
162 if (ISF_SUCCESS != status)
163 {
164 return DSA_ERR_INITIALIZE;
165 }
166
167 // Set the adapter state to be initialized.
168 pSensorHandle->adapterStatus = DSA_STATE_INITIALIZED;
169
170 // Create a semaphore to synchronize the device descriptor across tasks
171 //if (MQX_OK != _lwsem_create(&pDeviceDescriptor->deviceSemaphore, 1)){
172 if (kStatus_OSA_Success != OSA_SemaCreate(&pDeviceDescriptor->deviceSemaphore, 1)){
173 return DSA_ERR_INITIALIZE;
174 }
175
176 pDeviceDescriptor->skipFramecnt = 0;
177
178 return ISF_SUCCESS;
179 }
180
181 /*
182 ** ===================================================================
183 ** Method : fsl_mma865x_i2c_3D_accel_ValidateSettings (component ISFDSA)
184 ** @brief
185 **
186 ** Parameters :
187 ** NAME - DESCRIPTION
188 ** @param
189 ** isf_SensorHandle_t *pSensorHandle
190 ** @param
191 ** isf_SubscriptionSettings_t *pSettings
192 ** @return
193 ** isf_dsa_status_t -
194 ** ===================================================================
195 */
196 isf_dsa_status_t fsl_mma865x_i2c_3D_accel_ValidateSettings(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
197 {
198 // Check the input arguments.
199 if ((NULL == pSensorHandle) || (NULL == pSensorSettings)) {
200 return DSA_ERR_PARAM;
201 }
202
203 int32_t status;
204
205 mma865x_ValidateConfig(&status,pSensorHandle,pSensorSettings);
206
207 return status;
208 }
209
210 /*
211 ** ===================================================================
212 ** Method : fsl_mma865x_i2c_3D_accel_Configure (component ISFDSA)
213 ** @brief
214 **
215 ** Parameters :
216 ** NAME - DESCRIPTION
217 ** @param
218 ** isf_SensorHandle_t *pSensorHandle
219 ** @param
220 ** isf_SubscriptionSettings_t *pConfigSettings
221 ** @return
222 ** isf_dsa_status_t -
223 ** ===================================================================
224 */
225 isf_dsa_status_t fsl_mma865x_i2c_3D_accel_Configure(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
226 {
227 // Check pointers.
228 if((NULL == pSensorHandle) || (NULL == pSensorSettings) ){
229 return DSA_ERR_PARAM;
230 }
231
232 int32_t status;
233
234 int32_t retStat = DSA_ERR_CONFIGURE; // Return Status
235
236 // Create helper reference pointers.
237 DeviceDescriptor_t *pDeviceDescriptor = (DeviceDescriptor_t*) pSensorHandle->pDeviceDescriptor;
238
239 // Check the device descriptor pointer.
240 if (NULL == pDeviceDescriptor)
241 {
242 return retStat;
243 }
244
245 // Lock the device descriptor.
246 //_lwsem_wait_ticks(&pDeviceDescriptor->deviceSemaphore, 0);
247 OSA_SemaWait(&pDeviceDescriptor->deviceSemaphore, OSA_WAIT_FOREVER);
248
249 // Check the driver state.
250 if (DSA_STATE_INITIALIZED > pSensorHandle->adapterStatus){
251 goto unlockdescriptor;
252 }
253
254 // User Notice: This is a required function call. If it is not here, there may be conflicts, data loss,
255 // or any number of undesirable things may occur.
256 if (ISF_SUCCESS != dm_channel_acquire_lock(&pDeviceDescriptor->cDescriptor, 0)) {
257 goto unlockdescriptor;
258 }
259
260 // Set the sensor into STANDBY mode for configuration.
261 mma865x_SetMode(&status, pSensorHandle, SENSOR_STANDBY);
262 if (ISF_SUCCESS != status) {
263 goto unlockchannel;
264 }
265
266 // Configure the sensor.
267 retStat = mma865x_SetConfig(pSensorHandle, pSensorSettings);
268 if (ISF_SUCCESS != retStat) {
269 goto unlockchannel;
270 }
271
272 // Register the periodic callback function with the Bus Manager.
273 pDeviceDescriptor->token = bm_register_periodic_callback( pSensorSettings->nSamplePeriod, fsl_mma865x_i2c_3D_accel_PeriodicCallback , pSensorHandle);
274 if(BM_ERROR & pDeviceDescriptor->token){
275 goto unlockchannel;
276 }
277
278 //Store the configured settings
279 pSensorHandle->controlData.sensorSettings = *pSensorSettings;
280
281 pSensorHandle->adapterStatus = DSA_STATE_CONFIGURED_STOPPED;
282 retStat = ISF_SUCCESS;
283
284 unlockchannel:
285 // Unlock the channel.
286 // The explicit lock must be released when the configuration is done allowing the bus to be used by others.
287 // User Notice: This is a required function call.
288 status = dm_channel_release_lock(&pDeviceDescriptor->cDescriptor);
289 if (ISF_SUCCESS != status)
290 {
291 retStat = status;
292 }
293
294 unlockdescriptor:
295
296 // Unlock the device descriptor.
297 //_lwsem_post(&pDeviceDescriptor->deviceSemaphore);
298 OSA_SemaPost(&pDeviceDescriptor->deviceSemaphore);
299
300 return retStat;
301 }
302
303 /*
304 ** ===================================================================
305 ** Method : fsl_mma865x_i2c_3D_accel_StartData (component ISFDSA)
306 ** @brief
307 **
308 ** Parameters :
309 ** NAME - DESCRIPTION
310 ** @param
311 ** isf_SensorHandle_t *pSensorHandle
312 ** @return
313 ** isf_dsa_status_t -
314 ** ===================================================================
315 */
316 isf_dsa_status_t fsl_mma865x_i2c_3D_accel_StartData(isf_SensorHandle_t *pSensorHandle)
317 {
318 // Check pointers.
319 if(NULL == pSensorHandle){
320 return DSA_ERR_PARAM;
321 }
322
323 int32_t status;
324 int32_t retStat = DSA_ERR_START_DATA;
325
326 // Create helper reference pointers.
327 DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHandle->pDeviceDescriptor;
328
329 // Check the device descriptor.
330 if (NULL == pDeviceDescriptor)
331 return DSA_ERR_PARAM;
332
333 // Lock the device descriptor.
334 //_lwsem_wait_ticks(&pDeviceDescriptor->deviceSemaphore, 0);
335 OSA_SemaWait(&pDeviceDescriptor->deviceSemaphore, OSA_WAIT_FOREVER);
336
337 // Check the driver state.
338 if (DSA_STATE_CONFIGURED_STOPPED > pSensorHandle->adapterStatus)
339 {
340 goto unlockdescriptor;
341 }
342
343 // Set the sensor into ACTIVE mode for operation.
344 mma865x_SetMode(&status, pSensorHandle, SENSOR_ACTIVE);
345 if (ISF_SUCCESS != status) {
346 goto unlockdescriptor;
347 }
348
349 // Start the Bus Manager sampling timer.
350 if (BM_ERROR & bm_start(FALSE, pDeviceDescriptor->token)) // Check for Bus Manager error and return on failure.
351 goto unlockdescriptor;
352
353 // Set device to active state.
354 pSensorHandle->adapterStatus = DSA_STATE_CONFIGURED_STARTED;
355 retStat = ISF_SUCCESS;
356
357 unlockdescriptor:
358 // Unlock the device descriptor.
359 //_lwsem_post(&pDeviceDescriptor->deviceSemaphore);
360 OSA_SemaPost(&pDeviceDescriptor->deviceSemaphore);
361
362 return retStat;
363 }
364
365 /*
366 ** ===================================================================
367 ** Method : fsl_mma865x_i2c_3D_accel_EndData (component ISFDSA)
368 ** @brief
369 **
370 ** Parameters :
371 ** NAME - DESCRIPTION
372 ** @param
373 ** isf_SensorHandle_t *pSensorHandle
374 ** @return
375 ** isf_dsa_status_t -
376 ** ===================================================================
377 */
378 isf_dsa_status_t fsl_mma865x_i2c_3D_accel_EndData(isf_SensorHandle_t *pSensorHandle)
379 {
380 // Check pointers.
381 if(NULL == pSensorHandle){
382 return DSA_ERR_PARAM;
383 }
384
385 int32_t status;
386
387 // Create helper reference pointers.
388 DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHandle->pDeviceDescriptor;
389
390 // Set the default return status.
391 int32_t retStat = DSA_ERR_END_DATA;
392
393 // Check the device descriptor.
394 if (NULL == pDeviceDescriptor)
395 return retStat;
396
397 // Lock the device descriptor.
398 //_lwsem_wait_ticks(&pDeviceDescriptor->deviceSemaphore, 0);
399 OSA_SemaWait(&pDeviceDescriptor->deviceSemaphore, OSA_WAIT_FOREVER);
400
401 // Check the driver state.
402 if (DSA_STATE_CONFIGURED_STOPPED >= pSensorHandle->adapterStatus)
403 goto unlockdescriptor;
404
405 // Check that the adapter is not already started.
406 if (DSA_STATE_CONFIGURED_STARTED == pSensorHandle->adapterStatus) {
407 // If it is, then stop the Bus Manager (BM) sample timer.
408 isf_status_t bmStopStatus = bm_stop(pDeviceDescriptor->token);
409 if (BM_ERROR & bmStopStatus)
410 goto unlockdescriptor;
411 }
412 #if 0
413 // Set the sensor into STANDBY mode for configuration.
414 mma865x_SetMode(&status, pSensorHandle, SENSOR_STANDBY);
415 #endif
416 if (ISF_SUCCESS != status) {
417 goto unlockdescriptor;
418 }
419
420 pSensorHandle->adapterStatus = DSA_STATE_CONFIGURED_STOPPED;
421 retStat = ISF_SUCCESS;
422
423
424 unlockdescriptor:
425 // Unlock the device descriptor.
426 //_lwsem_post(&pDeviceDescriptor->deviceSemaphore);
427 OSA_SemaPost(&pDeviceDescriptor->deviceSemaphore);
428
429 return retStat;
430 }
431
432 /*
433 ** ===================================================================
434 ** Method : fsl_mma865x_i2c_3D_accel_Calibrate (component ISFDSA)
435 ** @brief
436 **
437 ** Parameters :
438 ** NAME - DESCRIPTION
439 ** @param
440 ** isf_SensorHandle_t *pSensorHandle
441 ** @return
442 ** isf_dsa_status_t -
443 ** ===================================================================
444 */
445 isf_dsa_status_t fsl_mma865x_i2c_3D_accel_Calibrate(isf_SensorHandle_t *pSensorHandle, void *pCalData )
446 {
447 int32_t retStat = ISF_SUCCESS;
448
449 return retStat;
450 }
451
452 /*
453 ** ===================================================================
454 ** Method : fsl_mma865x_i2c_3D_accel_Shutdown (component ISFDSA)
455 ** @brief
456 **
457 ** Parameters :
458 ** NAME - DESCRIPTION
459 ** @param
460 ** isf_SensorHandle_t *pSensorHandle
461 ** @return
462 ** isf_dsa_status_t -
463 ** ===================================================================
464 */
465 isf_dsa_status_t fsl_mma865x_i2c_3D_accel_Shutdown(isf_SensorHandle_t *pSensorHandle )
466 {
467 if(NULL == pSensorHandle){
468 return DSA_ERR_PARAM;
469 }
470
471 // Create helper reference pointers.
472 DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHandle->pDeviceDescriptor;
473
474 // Remove the sensor adapter from the Bus Manager callbacks.
475 bm_unregister_callback(pDeviceDescriptor->token);
476 pSensorHandle->adapterStatus = DSA_STATE_INITIALIZED;
477 return ISF_SUCCESS;
478
479 }
480
481 /*
482 ** ===================================================================
483 ** Method : fsl_mma865x_i2c_3D_accel_PeriodicCallback (component ISFDSA)
484 ** @brief
485 **
486 ** Parameters :
487 ** NAME - DESCRIPTION
488 ** @param
489 ** void* pSensorHandle -
490 ** @return
491 ** void -
492 ** ===================================================================
493 */
494 void fsl_mma865x_i2c_3D_accel_PeriodicCallback(void* pSensorHandle)
495 {
496 // Check pointers.
497 if(NULL == pSensorHandle){
498 return;
499 }
500
501 // Create helper reference pointers.
502 volatile isf_SensorHandle_t *pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
503 isf_fifo_t *pFifo = pSensorHdl->controlData.sensorSettings.pSampleBufferInfo;
504 DeviceDescriptor_t *pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHdl->pDeviceDescriptor;
505 isf_status_t st;
506 int32 numBytes;
507
508 // Check the device descriptor
509 if (NULL == pDeviceDescriptor){
510 return;
511 }
512
513 // Create a helper pointer to the current sample buffer.
514 mma865x_DataBuffer_t *pCurrentSampleBuffer = (mma865x_DataBuffer_t *)pDeviceDescriptor->pCurrentSample;
515
516 // Apply sample skip if necessary.
517 if (pDeviceDescriptor->skipFramecnt) {
518 // Not done skipping samples.
519 --pDeviceDescriptor->skipFramecnt;
520 return;
521 }
522
523 // Get the time stamp
524 pCurrentSampleBuffer->timeStamp = isf_time_util_get_usec();
525
526 // Lock the device descriptor.
527 //if (MQX_OK !=_lwsem_wait_ticks(&pDeviceDescriptor->deviceSemaphore, 0))
528 if (kStatus_OSA_Success != OSA_SemaWait(&pDeviceDescriptor->deviceSemaphore, OSA_WAIT_FOREVER))
529 {
530 goto unlockdescriptor;
531 }
532
533
534 // Check the driver state.
535 if (DSA_STATE_CONFIGURED_STARTED != pSensorHdl->adapterStatus)
536 {
537 goto unlockdescriptor;
538 }
539
540 // Get sensor data.
541 mma865x_GetData(pSensorHandle, ((uint8*)&pCurrentSampleBuffer->accel[0])); // Returns samples in big endian.
542
543 // Lock the fifo for update.
544 if(kStatus_OSA_Success != isf_fifo_lock(pFifo)){
545 return;
546 }
547
548 mma865x_DataBuffer_t *pFifoEntry = (mma865x_DataBuffer_t *)isf_fifo_el_get_insert_pointer(pFifo);
549
550
551 // write the new data
552 if (pSensorHdl->controlData.sensorSettings.resultType == TYPE_NATIVE_SENSOR_DATA_TYPE )
553 {
554 *pFifoEntry = *pCurrentSampleBuffer;
555 }
556 else
557 {
558 fsl_mma865x_i2c_3D_accel_Convert(
559 pSensorHdl,
560 pSensorHdl->controlData.sensorSettings.resultType,
561 pSensorHdl->controlData.sensorSettings.resultFormat,
562 pCurrentSampleBuffer,
563 pFifoEntry,
564 &numBytes);
565 }
566
567 // Increment the fifo to the next sample entry.
568 st = isf_fifo_el_increment(pFifo);
569
570 // Unlock the fifo.
571 isf_fifo_unlock(pFifo);
572
573 if (st == ISF_FIFO_FULL)
574 {
575 // Notify the user using their registered event information
576 //_lwevent_set(pSensorHdl->controlData.pEventGroup,(uint32_t)pSensorHdl->controlData.nEventFieldIndex);
577 OSA_EventSet(pSensorHdl->controlData.pEventGroup,(uint32_t)pSensorHdl->controlData.nEventFieldIndex);
578 }
579
580 unlockdescriptor:
581 // Unlock the device descriptor.
582 //_lwsem_post(&pDeviceDescriptor->deviceSemaphore);
583 OSA_SemaPost(&pDeviceDescriptor->deviceSemaphore);
584
585 }
586
587 /*!
588 * @brief This function coverts the raw sample data to the desired output type.
589 */
590 isf_dsa_status_t fsl_mma865x_i2c_3D_accel_Convert
591 (
592 volatile isf_SensorHandle_t *pSensorHandle,
593 isf_SensorDataTypes_t convertToType, isf_dsa_result_types_t resultType,
594 void *pNativeSample,
595 void *pConvertedSample,
596 int32 *numBytes
597 )
598 {
599 isf_dsa_status_t retStat = DSA_ERR_BAD_SENSOR_DATA_TYPE;
600 isf_dsa_status_t (*pConverter)(mma865x_Sensor_Specific_Settings_t *, mma865x_DataBuffer_t *, void *);
601
602 pConverter = NULL;
603
604 switch (convertToType)
605 {
606 case TYPE_RAW_ACCELERATION_3D:
607 if (resultType == DSA_RESULT_TYPE_ENG_FLOAT)
608 pConverter = float_accel3d_converter;
609 else if (resultType == DSA_RESULT_TYPE_ENG_FIXED)
610 pConverter = fixed_accel3d_converter;
611 else if (resultType == DSA_RESULT_TYPE_RAW_COUNTS)
612 pConverter = count_accel3d_converter;
613 break;
614
615
616 default:
617 return DSA_ERR_BAD_SENSOR_DATA_TYPE;
618 }
619 if (pConverter == NULL)
620 return DSA_ERR_BAD_RESULT_TYPE;
621
622 retStat = pConverter(
623 (mma865x_Sensor_Specific_Settings_t*)pSensorHandle->pSensorStaticConfig->pSensorSpecificSettings,
624 (mma865x_DataBuffer_t *)pNativeSample,
625 pConvertedSample
626 );
627
628 return retStat;
629 }
630
631 static isf_dsa_status_t float_accel3d_converter(mma865x_Sensor_Specific_Settings_t *pSensorSpecificConfig, mma865x_DataBuffer_t *nativeSample, void *vpConvertedSample )
632 {
633 isf_Acceleration3D_Float_t *convertedSample = (isf_Acceleration3D_Float_t *)vpConvertedSample;
634 convertedSample->timestamp = nativeSample->timeStamp;
635 // These factors and offsets really depends on the configured sensor Range in pSensorSpecificConfig
636 //convertedSample->accel[0] = nativeSample->accel[0] * MMA865x_ACCEL_FLOAT_CONVERSION_FACTOR + MMA865x_ACCEL_FLOAT_CONVERSION_OFFSET;
637 //convertedSample->accel[1] = nativeSample->accel[1] * MMA865x_ACCEL_FLOAT_CONVERSION_FACTOR + MMA865x_ACCEL_FLOAT_CONVERSION_OFFSET;
638 //convertedSample->accel[2] = nativeSample->accel[2] * MMA865x_ACCEL_FLOAT_CONVERSION_FACTOR + MMA865x_ACCEL_FLOAT_CONVERSION_OFFSET;
639
640 // Convert the sample based on the full-scale range.
641 convertedSample->accel[0] = nativeSample->accel[0] * mma865xAccelConvTable[pSensorSpecificConfig->accelFullScaleRange].floatFactor + mma865xAccelConvTable[pSensorSpecificConfig->accelFullScaleRange].floatOffset;
642 convertedSample->accel[1] = nativeSample->accel[1] * mma865xAccelConvTable[pSensorSpecificConfig->accelFullScaleRange].floatFactor + mma865xAccelConvTable[pSensorSpecificConfig->accelFullScaleRange].floatOffset;
643 convertedSample->accel[2] = nativeSample->accel[2] * mma865xAccelConvTable[pSensorSpecificConfig->accelFullScaleRange].floatFactor + mma865xAccelConvTable[pSensorSpecificConfig->accelFullScaleRange].floatOffset;
644 return ISF_SUCCESS;
645 }
646
647 static isf_dsa_status_t fixed_accel3d_converter(mma865x_Sensor_Specific_Settings_t *pSensorSpecificConfig, mma865x_DataBuffer_t *nativeSample, void *vpConvertedSample )
648 {
649 isf_Acceleration3D_EngFixed_t *convertedSample = (isf_Acceleration3D_EngFixed_t *)vpConvertedSample;
650 convertedSample->timestamp = nativeSample->timeStamp;
651 // These factors and offsets really depend on the configured sensor Range in pSensorSpecificConfig
652 //convertedSample->accel[0] = nativeSample->accel[0] * MMA865x_ACCEL_FIXED_CONVERSION_FACTOR + MMA865x_ACCEL_FIXED_CONVERSION_OFFSET;
653 //convertedSample->accel[1] = nativeSample->accel[1] * MMA865x_ACCEL_FIXED_CONVERSION_FACTOR + MMA865x_ACCEL_FIXED_CONVERSION_OFFSET;
654 //convertedSample->accel[2] = nativeSample->accel[2] * MMA865x_ACCEL_FIXED_CONVERSION_FACTOR + MMA865x_ACCEL_FIXED_CONVERSION_OFFSET;
655
656 // Convert the sample based on the full-scale range.
657 convertedSample->accel[0] = (nativeSample->accel[0] * mma865xAccelConvTable[pSensorSpecificConfig->accelFullScaleRange].fixedFactor + mma865xAccelConvTable[pSensorSpecificConfig->accelFullScaleRange].fixedOffset)/4;
658 convertedSample->accel[1] = (nativeSample->accel[1] * mma865xAccelConvTable[pSensorSpecificConfig->accelFullScaleRange].fixedFactor + mma865xAccelConvTable[pSensorSpecificConfig->accelFullScaleRange].fixedOffset)/4;
659 convertedSample->accel[2] = (nativeSample->accel[2] * mma865xAccelConvTable[pSensorSpecificConfig->accelFullScaleRange].fixedFactor + mma865xAccelConvTable[pSensorSpecificConfig->accelFullScaleRange].fixedOffset)/4;
660 return ISF_SUCCESS;
661 }
662 static isf_dsa_status_t count_accel3d_converter(mma865x_Sensor_Specific_Settings_t *pSensorSpecificConfig, mma865x_DataBuffer_t *nativeSample, void *vpConvertedSample )
663 {
664 isf_Acceleration3D_RawCount_t *convertedSample = (isf_Acceleration3D_RawCount_t *)vpConvertedSample;
665 convertedSample->timestamp = nativeSample->timeStamp;
666 // Convert the sample based on the full-scale range.
667 convertedSample->accel[0] = nativeSample->accel[0];
668 convertedSample->accel[1] = nativeSample->accel[1];
669 convertedSample->accel[2] = nativeSample->accel[2];
670
671 return ISF_SUCCESS;
672 }
673 /*!
674 * @brief This function resets the MMA865x sensor resulting in a default configuration for
675 * all registers.
676 */
677 void mma865x_Reset(int32_t* status, void* pSensorHandle)
678 {
679 uint8 buffer[1] = {0};
680
681 // Create and validate helper reference pointers.
682 isf_SensorHandle_t* pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
683 DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHdl->pDeviceDescriptor;
684 dm_DeviceDescriptor_t* pDeviceHandle = &pDeviceDescriptor->deviceHandle;
685
686 // Reset the device.
687 // Put the device the STANDBY state which is required before any configuration registers are set.
688 buffer[0]= MMA865x_RST_MASK; // no shift
689 if (ISF_SUCCESS != dm_device_write(pDeviceHandle, MMA865x_CTRL_REG2, buffer, 1, 1)){
690 *status = DSA_ERR_INITIALIZE;
691 return;
692 }
693
694 // Burn a write and ignore the return.
695 buffer[0] = 0;
696 ( void ) dm_device_write(pDeviceHandle, MMA865x_ASLP_COUNT, buffer, 1, 1);
697
698 // Turn-on time = 1 second (MMA865x Data Sheet) for OSR = 2^7 (128).
699 OSA_TimeDelay(1000/5);
700
701 *status = ISF_SUCCESS;
702 }
703
704 /*!
705 * @brief This function validates the MMA865x sensor is connected via the I2C bus.
706 */
707 void mma865x_CheckId(int32_t *status, void* pSensorHandle)
708 {
709 uint8 buffer[1] = {0};
710 int32 retStat = SENSOR_ERROR_CHECKID;
711
712 // Create and validate helper reference pointers.
713 isf_SensorHandle_t* pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
714 DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHdl->pDeviceDescriptor;
715 dm_DeviceDescriptor_t* pDeviceHandle = &pDeviceDescriptor->deviceHandle;
716
717 if (ISF_SUCCESS != dm_device_read(pDeviceHandle, MMA865x_WHO_AM_I, &buffer[0], 1, 1)){
718 *status = retStat;
719 }
720 if ((MMA865x_WHOAMI_VALUE_8652 != buffer[0]) && (MMA865x_WHOAMI_VALUE_8653 != buffer[0])) {
721 *status = retStat;
722 }
723
724 *status = ISF_SUCCESS;
725 }
726
727 /*!
728 * @brief This function validates the configuration for the MMA865x sensor.
729 */
730 void mma865x_ValidateConfig(int32_t* status, void* pSensorHandle, void* pSettings)
731 {
732 isf_dsa_status_t st; // The status variable.
733 isf_SensorHandle_t *pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
734 DeviceDescriptor_t *pDeviceDescriptor = (DeviceDescriptor_t*) pSensorHdl->pDeviceDescriptor;
735 isf_dsa_SensorSettings_t *pConfig = (isf_dsa_SensorSettings_t*)pSettings;
736
737 // Validate the configuration data using the global data
738 st = mma865x_GetConfig( pConfig, pDeviceDescriptor );
739
740 // If the configuration data has been modified. convey this information to user Application.
741 if (st) {
742 *status = DSA_RET_SETTINGS_CHANGED;
743 return;
744 }
745
746 *status = ISF_SUCCESS;
747 }
748
749 /*!
750 * @brief This function sets the MMA865x part to the requested mode.
751 */
752 void mma865x_SetMode(int32_t* status, void* pSensorHandle, int32_t Mode)
753 {
754 isf_SensorHandle_t* pSensorHdl = (isf_SensorHandle_t *)pSensorHandle;
755 DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHdl->pDeviceDescriptor;
756 dm_DeviceDescriptor_t* pDeviceHandle = &pDeviceDescriptor->deviceHandle;
757
758 uint8 buffer[1] = {0x00};
759
760 switch(Mode)
761 {
762 // This will put the sensor into the standby mode
763 case SENSOR_STANDBY:
764 case SENSOR_BOOT:
765 case SENSOR_READY:
766 {
767 // this sensor requires read-modify-write
768 if (ISF_SUCCESS != dm_device_read(pDeviceHandle, MMA865x_CTRL_REG1, buffer, 1, 1) ){
769 *status = SENSOR_ERROR_SETMODE;
770 return;
771 }
772 buffer[0] = (buffer[0] & ~MMA865x_ACTIVE_MASK);
773 if (ISF_SUCCESS != dm_device_write(pDeviceHandle, MMA865x_CTRL_REG1, buffer, 1, 1) ){
774 *status = SENSOR_ERROR_SETMODE;
775 return;
776 }
777 }
778 break;
779
780 // This will put the sensor into the active state
781 case SENSOR_ACTIVE:
782 {
783 // this sensor requires read-modify-write
784 if (ISF_SUCCESS != dm_device_read(pDeviceHandle, MMA865x_CTRL_REG1, buffer, 1, 1) ){
785 *status = SENSOR_ERROR_SETMODE;
786 return;
787 }
788 buffer[0] = (buffer[0] | MMA865x_ACTIVE_MASK);
789 if (ISF_SUCCESS != dm_device_write(pDeviceHandle, MMA865x_CTRL_REG1, buffer, 1, 1) ){
790 *status = SENSOR_ERROR_SETMODE;
791 return;
792 }
793 // Read the value of the status register to wait for valid data
794 buffer[0] = 0;
795 do {
796 if (ISF_SUCCESS != dm_device_read(pDeviceHandle, MMA865x_STATUS_00, buffer, 1, 1) ){
797 *status = SENSOR_ERROR_SETMODE;
798 return;
799 }
800 OSA_TimeDelay(1); // short delay to yield CPU/RTOS.
801 } while (0 == MMA865x_GET_FIELD(ZYXDR,buffer[0]) ); // Wait for Data Ready.
802 }
803 break;
804
805 default:
806 *status = SENSOR_ERROR_SETMODE;
807 return;
808 }
809 // return success
810 *status = ISF_SUCCESS;
811 }
812
813 /*!
814 * @brief This function retrieves the raw data from the MMA865x sensor.
815 */
816 #define BYTES_FOR_FULL_READ 7
817
818 isf_dsa_status_t mma865x_GetData(isf_SensorHandle_t *pSensorHandle, void* pBuffer)
819 {
820 mma865x_status_t retStat = SENSOR_ERROR_GETDATA;
821
822 DeviceDescriptor_t* pDeviceDescriptor = (DeviceDescriptor_t*)pSensorHandle->pDeviceDescriptor;
823 dm_DeviceDescriptor_t* pDeviceHandle = &pDeviceDescriptor->deviceHandle;
824
825 uint16* pSensorData = (uint16*)pBuffer;
826 uint8 registerData[BYTES_FOR_FULL_READ];
827
828 // read the full width of the data for both full or short reads
829 if (ISF_SUCCESS != dm_device_read(pDeviceHandle, MMA865x_STATUS_00, registerData, BYTES_FOR_FULL_READ, BYTES_FOR_FULL_READ) )
830 { // return error SENSOR_ERROR_GETDATA
831 return retStat;
832 }
833
834 // If there is any data, then format and copy it to the output buffer.
835 if ( MMA865x_GET_FIELD(ZYXDR, registerData[0] ) > 0 )
836 {
837 // collect the full 16-bit data for each of x,y,z
838 pSensorData[0] = ((int16)registerData[1])<<8 | registerData[2];
839 pSensorData[1] = ((int16)registerData[3])<<8 | registerData[4];
840 pSensorData[2] = ((int16)registerData[5])<<8 | registerData[6];
841 }
842 // return success
843 return ISF_SUCCESS;
844 }
845
846
847 /*!
848 * @brief This function sets the MMA865x sensor configuration.
849 */
850 isf_dsa_status_t mma865x_SetConfig(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pConfigSettings)
851 {
852 int32_t retStat = DSA_ERR_CONFIGURE; // Return Status
853
854 // Create helper reference pointers.
855 DeviceDescriptor_t *pDeviceDescriptor = (DeviceDescriptor_t*) pSensorHandle->pDeviceDescriptor;
856 mma865x_Sensor_Specific_Settings_t *pConfigSpecific = (mma865x_Sensor_Specific_Settings_t*) pSensorHandle->pSensorStaticConfig->pSensorSpecificSettings;
857 dm_DeviceDescriptor_t *pDeviceHandle = &pDeviceDescriptor->deviceHandle;
858
859 /* Write the sensor specific data based on the pre-computed register level pairs (Addr, Value) */
860 uint8 buffer[1];
861 for (uint32 reg=0; reg < pConfigSpecific->regCount; reg++)
862 {
863 buffer[0] = pConfigSpecific->regPairs[reg].regValue;
864 if (ISF_SUCCESS != dm_device_write(pDeviceHandle, pConfigSpecific->regPairs[reg].regAddr,&buffer[0],1,1))
865 {
866 return retStat;
867 }
868 }
869
870 // Set up the Control register #1 functions: ODR override for SLEEP mode and the WAKE mode ODR.
871 buffer[0] = MMA865x_SET_FIELD(DR,mma865x_settings.sampleRateIndex);
872 if (ISF_SUCCESS != dm_device_write(&pDeviceDescriptor->deviceHandle, MMA865x_CTRL_REG1, buffer, 1, 1) ) return MMA865x_ERROR;
873
874 return ISF_SUCCESS;
875 }
876
877 /*
878 * Local Subroutines
879 */
880
881 /*! @brief This function obtains the configuration register values for a given user configuration of the MMA865x.
882 * If the configuration has changed then it returns true and saves the new configuration.
883 *
884 * @param[out] pRequiredSettings update the data period in settings
885 * @param[out] pDeviceDes update the data rate in the generic sensor structure for this device
886 * @return ::mma865x_GetConfig() returns a value of type ::isf_dsa_status_t indicating the success or failure of the function
887 * call.
888 * @retval 0 is returned when the configuration is valid.
889 * @retval 1 is returned when the configuration is modified.
890 *
891 * @Constraints None
892 *
893 * @Reentrant Yes
894 * @Libs lib_fsl_mma865x_i2c_3D_accel.lib
895 */
896 isf_dsa_status_t mma865x_GetConfig(isf_dsa_SensorSettings_t* pRequiredSettings, DeviceDescriptor_t* pDeviceDes)
897 {
898 // Validate the reporting rate.
899 uint8 retStat = 0; // no changes
900 uint8 periodFound = FALSE; // not found
901 uint8 dataRate;
902
903 // get the number of array entries, which is not the max data rate by rather the size
904 // of the array (number or elements in the array), max index = size - 1
905 uint8 maxDataRateIndex = sizeof fsl_mma865x_period / sizeof fsl_mma865x_period[0];
906
907 for (dataRate = 0; dataRate < maxDataRateIndex; dataRate++)
908 {
909 if (fsl_mma865x_period[dataRate] == pRequiredSettings->nSamplePeriod)
910 {
911 periodFound = TRUE;
912 break;
913 }
914 }
915
916 // If a valid reporting rate has not been set, then default to the MMA865x hardware default of 800Hz.
917 if ( !periodFound )
918 {
919 retStat = (isf_dsa_status_t)DSA_RET_SETTINGS_CHANGED;
920 pRequiredSettings->nSamplePeriod = FSL_MMA865x_ACCEL_800HZ;
921 mma865x_settings.sampleRateIndex = maxDataRateIndex - 1; // max range index
922 }
923 else
924 { // copy the rate index to local storage as needed
925 mma865x_settings.sampleRateIndex = dataRate;
926 }
927
928 return retStat;
929 }
930
931 /*!
932 ** @}
933 */
934 /* END fsl_mma865x_i2c_3D_accel. */
935
936
isf_SensorHandle_st::pDeviceDescriptor
void * pDeviceDescriptor
Definition: isf_dsa_adapter.h:109
MMA865x_WHO_AM_I
Definition: mma865x.h:34
fsl_mma865x_i2c_3D_accel_Initialize
isf_dsa_status_t fsl_mma865x_i2c_3D_accel_Initialize(isf_SensorHandle_t *pSensorHandle)
Definition: fsl_mma865x_i2c_3D_accel.c:102
dm_channel_start
isf_status_t dm_channel_start(dm_ChannelDescriptor_t *apChannelDescriptor)
This function starts a channel.
Definition: isf_device_messaging.c:137
isf_Acceleration3D_RawCount_t
Standard raw type for three axes accelerometers.
Definition: isf_accelerometer_types.h:58
SensorConfig_st::pSensorSpecificSettings
void * pSensorSpecificSettings
Definition: isf_dsa_adapter.h:157
mma865x_DataBuffer_t
This structure defines the dummy DSA data buffer format.
Definition: fsl_mma865x_i2c_3D_accel.h:55
uint8
unsigned char uint8
Definition: isf_types.h:76
TRUE
#define TRUE
Definition: isf_types.h:82
isf_dsa_adapter.h
DSA_ERR_BAD_RESULT_TYPE
Definition: isf_dsa_adapter.h:39
fsl_mma865x_i2c_3D_accel_EndData
isf_dsa_status_t fsl_mma865x_i2c_3D_accel_EndData(isf_SensorHandle_t *pSensorHandle)
Definition: fsl_mma865x_i2c_3D_accel.c:378
SENSOR_STANDBY
Definition: isf_sensors.h:22
mma865x_SetMode
void mma865x_SetMode(int32_t *status, void *pSensorHandle, int32_t Mode)
This function sets the MMA865x part to the requested mode.
Definition: fsl_mma865x_i2c_3D_accel.c:752
isf_Acceleration3D_EngFixed_t
Standard fixed type for three axis accelerometers.
Definition: isf_accelerometer_types.h:39
mma865x_Sensor_Specific_Settings_t::accelFullScaleRange
uint8 accelFullScaleRange
Definition: mma865x.h:518
fsl_mma865x_i2c_3D_accel.h
The fsl_mma865x_i2c_3D_accel.h file contains the definitions and functions supporting the MMA865x Sen...
isf_Acceleration3D_Float_t::timestamp
isf_timestamp_t timestamp
Definition: isf_accelerometer_types.h:81
SENSOR_ERROR_SETMODE
Definition: isf_sensors.h:42
mma865x_Reset
void mma865x_Reset(int32_t *status, void *pSensorHandle)
This function resets the MMA865x sensor resulting in a default configuration for all registers...
Definition: fsl_mma865x_i2c_3D_accel.c:677
ISF_SUCCESS
Definition: isf.h:31
isf_time_util_get_usec
uint32 isf_time_util_get_usec(void)
This API returns the time in microseconds.
Definition: isf_util.c:55
dm_device_open
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.
Definition: isf_device_messaging.c:227
DSA_ERR_BAD_SENSOR_DATA_TYPE
Definition: isf_dsa_adapter.h:38
SensorConfig_st::commInfo
const void * commInfo
Definition: isf_dsa_adapter.h:159
isf_SensorHandle_st::controlData
isf_dsa_ControlData_t controlData
Definition: isf_dsa_adapter.h:111
isf_fifo_lock
isf_fifo_status_t isf_fifo_lock(isf_fifo_t *pFifo)
Lock a sample buffer for exclusive access.
Definition: isf_fifo.c:170
dm_channel_get_state
comm_State_t dm_channel_get_state(dm_ChannelDescriptor_t *apChannelDescriptor)
This function returns the channel state.
Definition: isf_device_messaging.c:100
MMA865x_WHOAMI_VALUE_8653
#define MMA865x_WHOAMI_VALUE_8653
Definition: mma865x.h:74
isf_fifo_unlock
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
MMA865x_CTRL_REG1
Definition: mma865x.h:63
fsl_mma865x_i2c_3D_accel_Calibrate
isf_dsa_status_t fsl_mma865x_i2c_3D_accel_Calibrate(isf_SensorHandle_t *pSensorHandle, void *pCalData)
Definition: fsl_mma865x_i2c_3D_accel.c:445
DSA_STATE_CONFIGURED_STARTED
Definition: isf_dsa_adapter.h:60
isf_fifo_el_increment
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
FSL_MMA865x_ACCEL_800HZ
800 Hz
Definition: fsl_mma865x_i2c_3D_accel.h:25
isf_sensors.h
isf_sensors.h contains the ISF Generic Sensor definitions and data structures required when a client ...
SENSOR_ACTIVE
Definition: isf_sensors.h:24
FALSE
#define FALSE
Definition: isf_types.h:86
floatFactor
float floatFactor
Definition: fsl_mma865x_i2c_3D_accel.c:57
isf_bm.h
API definitions, types, and macros for the Intelligent Sensing Framework (ISF) Bus Manager (BM)...
DeviceDescriptor_struct::deviceHandle
dm_DeviceDescriptor_t deviceHandle
Definition: isf_sensors.h:52
isf_SensorHandle_st
This defines the DSA sensor device handle structure used to invoke the adapter access functions...
Definition: isf_dsa_adapter.h:107
mma865x.h
The mma865x.h contains the MMA865x Accelerometer register definitions, access macros, and device access functions.
mma865x_Specific_Settings_t::sampleRateIndex
uint8 sampleRateIndex
Holds the ODR index into the rate array fsl_mma865x_period */.
Definition: fsl_mma865x_i2c_3D_accel.h:51
DeviceDescriptor_struct::skipFramecnt
uint8 skipFramecnt
Definition: isf_sensors.h:59
DSA_RESULT_TYPE_RAW_COUNTS
Definition: isf_dsa_adapter.h:47
isf_dsa_SensorSettings_st::nSamplePeriod
uint32 nSamplePeriod
Definition: isf_dsa_adapter.h:82
DeviceDescriptor_struct
Define the sensor device descriptor.
Definition: isf_sensors.h:49
MMA865x_ERROR
Definition: mma865x.h:507
fsl_mma865x_i2c_3D_accel_StartData
isf_dsa_status_t fsl_mma865x_i2c_3D_accel_StartData(isf_SensorHandle_t *pSensorHandle)
Definition: fsl_mma865x_i2c_3D_accel.c:316
floatOffset
float floatOffset
Definition: fsl_mma865x_i2c_3D_accel.c:58
pSensorData
void * pSensorData[]
Definition: BasicApp1.c:408
SENSOR_BOOT
Definition: isf_sensors.h:21
mma865x_GetConfig
isf_dsa_status_t mma865x_GetConfig(isf_dsa_SensorSettings_t *pRequiredSettings, DeviceDescriptor_t *pDeviceDes)
This function obtains the configuration register values for a given user configuration of the MMA865x...
Definition: fsl_mma865x_i2c_3D_accel.c:896
mma865x_SupportedDataTypes
isf_SensorDataTypes_t mma865x_SupportedDataTypes[]
Definition: fsl_mma865x_i2c_3D_accel.c:69
isf_SensorTypes_t
isf_SensorTypes_t
Definition: isf_sensor_types.h:14
DeviceDescriptor_struct::cDescriptor
dm_ChannelDescriptor_t cDescriptor
Definition: isf_sensors.h:51
dm_device_write
isf_status_t dm_device_write(dm_DeviceDescriptor_t *apDeviceDescriptor, int32 aOffset, uint8 *apWriteBuffer, uint32 aBuffsize, uint32 aNbyteWrite)
This function writes to a device.
Definition: isf_device_messaging.c:309
bm_unregister_callback
isf_status_t bm_unregister_callback(bm_callback_token_t aToken)
This API unregisters one or more callbacks.
Definition: bus_management.c:178
MMA865x_GET_FIELD
#define MMA865x_GET_FIELD(name, val)
Definition: mma865x.h:82
isf_dsa_ControlData_st::pEventGroup
event_t * pEventGroup
Definition: isf_dsa_adapter.h:92
BYTES_FOR_FULL_READ
#define BYTES_FOR_FULL_READ
This function retrieves the raw data from the MMA865x sensor.
Definition: fsl_mma865x_i2c_3D_accel.c:816
mma865x_ValidateConfig
void mma865x_ValidateConfig(int32_t *status, void *pSensorHandle, void *pSettings)
This function validates the configuration for the MMA865x sensor.
Definition: fsl_mma865x_i2c_3D_accel.c:730
MMA865x_SET_FIELD
#define MMA865x_SET_FIELD(name, val)
Definition: mma865x.h:81
isf_types.h
The isf_types.h file contains the ISF data type definitions and some of the globally used macros...
DSA_ERR_INITIALIZE
Definition: isf_dsa_adapter.h:29
MMA865x_CTRL_REG2
Definition: mma865x.h:64
mma865x_Sensor_Specific_Settings_t
Definition: mma865x.h:516
isf_Acceleration3D_EngFixed_t::accel
isf_acceleration_g_fixed_32s1i16_t accel[3]
Definition: isf_accelerometer_types.h:41
SENSOR_ERROR_CHECKID
Definition: isf_sensors.h:41
DSA_ERR_END_DATA
Definition: isf_dsa_adapter.h:33
DSA_RESULT_TYPE_ENG_FIXED
Definition: isf_dsa_adapter.h:48
DSA_STATE_INITIALIZED
Definition: isf_dsa_adapter.h:58
isf_dsa_status_t
int32 isf_dsa_status_t
This is the Sensor Manager API return type definition.
Definition: isf_dsa_adapter.h:21
TYPE_NATIVE_SENSOR_TYPE
Definition: isf_sensor_types.h:15
mma865x_SupportedSensorTypes
isf_SensorTypes_t mma865x_SupportedSensorTypes[]
Supported sensor and data types for MMA865x.
Definition: fsl_mma865x_i2c_3D_accel.c:68
isf_Acceleration3D_Float_t::accel
isf_acceleration_g_float_t accel[3]
Definition: isf_accelerometer_types.h:82
int16
signed short int int16
Definition: isf_types.h:73
fsl_mma865x_i2c_3D_accel_Convert
isf_dsa_status_t fsl_mma865x_i2c_3D_accel_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.
Definition: fsl_mma865x_i2c_3D_accel.c:591
MMA865x_ASLP_COUNT
Definition: mma865x.h:62
dm_channel_acquire_lock
isf_status_t dm_channel_acquire_lock(dm_ChannelDescriptor_t *apChannelDescriptor, isf_duration_t aTimeout)
This function locks the channel for exclusive access.
Definition: isf_device_messaging.c:174
isf_sensor_types.h
The isf_sensor_types.h contains the enumerated list of sensor types used by ISF.
fsl_mma865x_i2c_3D_accel_Shutdown
isf_dsa_status_t fsl_mma865x_i2c_3D_accel_Shutdown(isf_SensorHandle_t *pSensorHandle)
Definition: fsl_mma865x_i2c_3D_accel.c:465
MMA865x_RST_MASK
#define MMA865x_RST_MASK
Definition: mma865x.h:414
isf_util.h
The isf_util.h file contains the utility method declarations and macros.
fixedFactor
int32 fixedFactor
Definition: fsl_mma865x_i2c_3D_accel.c:59
isf_dsa_result_types_t
enum isf_dsa_result_enums isf_dsa_result_types_t
bm_register_periodic_callback
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.
Definition: bus_management.c:94
mma865x_CheckId
void mma865x_CheckId(int32_t *status, void *pSensorHandle)
This function validates the MMA865x sensor is connected via the I2C bus.
Definition: fsl_mma865x_i2c_3D_accel.c:707
fsl_mma865x_i2c_3D_accel_PeriodicCallback
void fsl_mma865x_i2c_3D_accel_PeriodicCallback(void *pSensorHandle)
Definition: fsl_mma865x_i2c_3D_accel.c:494
COMM_STATE_OK
Definition: isf_comm.h:28
isf_dsa_SensorSettings_st::resultFormat
isf_dsa_result_types_t resultFormat
Definition: isf_dsa_adapter.h:84
isf_SensorDataTypes_t
isf_SensorDataTypes_t
Definition: isf_sensor_types.h:61
dm_channel_init
isf_status_t dm_channel_init(dm_ChannelId_t aChannelId, dm_ChannelDescriptor_t *apChannelDescriptor)
This function initializes a channel.
Definition: isf_device_messaging.c:48
isf_Acceleration3D_RawCount_t::timestamp
isf_timestamp_t timestamp
Definition: isf_accelerometer_types.h:59
mma865x_GetData
isf_dsa_status_t mma865x_GetData(isf_SensorHandle_t *pSensorHandle, void *pBuffer)
Definition: fsl_mma865x_i2c_3D_accel.c:818
bm_stop
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.
Definition: bus_management.c:349
isf_fifo_t
Definition: isf_fifo.h:19
isf_SensorHandle_st::pSensorStaticConfig
const isf_SensorConfig_t * pSensorStaticConfig
Definition: isf_dsa_adapter.h:110
bm_start
isf_status_t bm_start(boolean aSync, bm_callback_token_t aTokens)
This API sets one or more callback(s) to the active state.
Definition: bus_management.c:278
isf_duration_t
uint32 isf_duration_t
ISF time duration in microseconds.
Definition: isf.h:84
isf_dsa_SensorSettings_st::resultType
isf_SensorDataTypes_t resultType
Definition: isf_dsa_adapter.h:83
mma865x_DataBuffer_t::timeStamp
uint32 timeStamp
Definition: fsl_mma865x_i2c_3D_accel.h:56
isf.h
Main ISF header file. Contains code common to all ISF components.
MMA865x_ACTIVE_MASK
#define MMA865x_ACTIVE_MASK
Definition: mma865x.h:372
isf_sm_api.h
The isf_sm_api.h contains the collection of APIs for the Sensor Manager as well as related defines an...
fixedOffset
int32 fixedOffset
Definition: fsl_mma865x_i2c_3D_accel.c:60
TYPE_ACCELEROMETER_3D
Definition: isf_sensor_types.h:20
isf_SensorHandle_st::adapterStatus
isf_dsa_AdapterStatus_t adapterStatus
Definition: isf_dsa_adapter.h:112
int32
signed long int int32
Definition: isf_types.h:74
SensorConfig_st::channelId
sys_channelId_t channelId
Definition: isf_dsa_adapter.h:158
uint16
unsigned short int uint16
Definition: isf_types.h:77
DSA_STATE_CONFIGURED_STOPPED
Definition: isf_dsa_adapter.h:59
DSA_ERR_PARAM
Definition: isf_dsa_adapter.h:36
isf_Acceleration3D_Float_t
Standard float type for three axis accelerometers.
Definition: isf_accelerometer_types.h:80
DSA_RESULT_TYPE_ENG_FLOAT
Definition: isf_dsa_adapter.h:49
MMA865x_WHOAMI_VALUE_8652
#define MMA865x_WHOAMI_VALUE_8652
Definition: mma865x.h:73
DSA_RET_SETTINGS_CHANGED
Definition: isf_dsa_adapter.h:40
isf_dsa_ControlData_st::nEventFieldIndex
uint32 nEventFieldIndex
Definition: isf_dsa_adapter.h:93
isf_dsa_SensorSettings_st::pSampleBufferInfo
isf_fifo_t * pSampleBufferInfo
Definition: isf_dsa_adapter.h:81
dm_device_read
isf_status_t dm_device_read(dm_DeviceDescriptor_t *apDeviceDescriptor, int32 aOffset, uint8 *apReadBuffer, uint32 aBuffsize, uint32 aNbyteRead)
This function reads from a device.
Definition: isf_device_messaging.c:271
mma865x_DataBuffer_t::accel
int16 accel[3]
Definition: fsl_mma865x_i2c_3D_accel.h:57
BM_ERROR
#define BM_ERROR
This value specifies a general Bus Manager error. If an error occurs in registering a callback...
Definition: isf_bm.h:57
mma865x_SetConfig
isf_dsa_status_t mma865x_SetConfig(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pConfigSettings)
This function sets the MMA865x sensor configuration.
Definition: fsl_mma865x_i2c_3D_accel.c:850
isf_status_t
int32 isf_status_t
ISF return status type.
Definition: isf.h:76
isf_fifo.h
DSA_STATE_NOT_INITIALIZED
Definition: isf_dsa_adapter.h:57
isf_dsa_SensorSettings_st
This defines the DSA sensor configuration parameter structure configuring the sensor settings by a su...
Definition: isf_dsa_adapter.h:79
DeviceDescriptor_struct::pCurrentSample
void * pCurrentSample
Definition: isf_sensors.h:56
isf_comm.h
isf_comm.h defines the common types for the Communications Service Family of the Intelligent Sensing ...
isf_dsa_ControlData_st::sensorSettings
isf_dsa_SensorSettings_t sensorSettings
Definition: isf_dsa_adapter.h:94
isf_Acceleration3D_EngFixed_t::timestamp
isf_timestamp_t timestamp
Definition: isf_accelerometer_types.h:40
fsl_mma865x_i2c_3D_accel_Configure
isf_dsa_status_t fsl_mma865x_i2c_3D_accel_Configure(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
Definition: fsl_mma865x_i2c_3D_accel.c:225
fsl_mma865x_i2c_3D_accel_ValidateSettings
isf_dsa_status_t fsl_mma865x_i2c_3D_accel_ValidateSettings(isf_SensorHandle_t *pSensorHandle, isf_dsa_SensorSettings_t *pSensorSettings)
Definition: fsl_mma865x_i2c_3D_accel.c:196
mma865x_Specific_Settings_t
This structure defines important settings.
Definition: fsl_mma865x_i2c_3D_accel.h:49
mma865x_DataBuffer_t::addr
uint8 addr
Definition: fsl_mma865x_i2c_3D_accel.h:58
isf_fifo_el_get_insert_pointer
void * isf_fifo_el_get_insert_pointer(isf_fifo_t *pFifo)
Routine returns the insert pointer for direct access.
Definition: isf_fifo.c:229
MMA865x_STATUS_00
Definition: mma865x.h:21
dm_channel_release_lock
isf_status_t dm_channel_release_lock(dm_ChannelDescriptor_t *apChannelDescriptor)
This function releases exclusive channel access.
Definition: isf_device_messaging.c:191
DSA_ERR_START_DATA
Definition: isf_dsa_adapter.h:32
uint32
unsigned long int uint32
Definition: isf_types.h:78
SENSOR_ERROR_GETDATA
Definition: isf_sensors.h:43
mma865x_status_t
int32 mma865x_status_t
Definition: fsl_mma865x_i2c_3D_accel.c:72
dm_DeviceDescriptor_struct
This structure defines a handle for the device.
Definition: isf_devmsg.h:61
mma865xAccelConvTable
const struct @21 mma865xAccelConvTable[]
TYPE_RAW_ACCELERATION_3D
Definition: isf_sensor_types.h:71
isf_accelerometer_types.h
The isf_accelerometer_types.h file contains the ISF data type definitions for use with the ISF generi...
SENSOR_READY
Definition: isf_sensors.h:23
TYPE_NATIVE_SENSOR_DATA_TYPE
Definition: isf_sensor_types.h:63
DeviceDescriptor_struct::deviceSemaphore
semaphore_t deviceSemaphore
Definition: isf_sensors.h:54
dm_ChannelDescriptor_struct
This structure is a declaration of a channel descriptor type.
Definition: isf_devmsg.h:50
ISF_FIFO_FULL
#define ISF_FIFO_FULL
Definition: isf_fifo.h:33
DSA_ERR_CONFIGURE
Definition: isf_dsa_adapter.h:31
isf_Acceleration3D_RawCount_t::accel
isf_acceleration_g_rawCount_t accel[3]
Definition: isf_accelerometer_types.h:60
DeviceDescriptor_struct::token
bm_callback_token_t token
Definition: isf_sensors.h:53
- © Freescale Semiconductor, Inc. 2016. All Rights Reserved.