ISF  2.1
Intelligent Sensing Framework for Kinetis with Processor Expert
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
App1.c
Go to the documentation of this file.
1 /* ###################################################################
2 ** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
3 ** Filename : App1.c
4 ** CDE edition : Standard
5 ** Project : ISF_K64F_CW_PROJ
6 ** Processor : MK64FN1M0VLL12
7 ** Component : ISFEmbApp
8 ** Version : Component 02.100, Driver 01.00, CPU db: 3.00.000
9 ** Compiler : GNU C Compiler
10 ** Date/Time : 2015-03-03, 11:16, # CodeGen: 3
11 ** Abstract :
12 **
13 ** Settings :
14 ** Contents :
15 ** No public methods
16 **
17 ** (c) Copyright Freescale Semiconductor, Inc., 2014
18 **
19 http://www.freescale.com
20 ** ###################################################################*/
21 /*!
22 ** @file App1.c
23 ** @version 01.00
24 ** @brief
25 **
26 */
27 /*!
28 ** @addtogroup App1_module App1 module documentation
29 ** @{
30 */
31 
32 /* MODULE App1. */
33 
34 #include "App1_Functions.h"
35 #include "App1.h"
36 #include "App1_types.h"
37 
38 /* MQX includes */
39 #include <mqxlite.h>
40 #include <lwevent.h>
41 #include "mqx_tasks.h"
42 
43 /* ISF includes */
44 #include "isf_target.h"
45 #include "isf_types.h"
46 #include "isf.h"
47 #include "isf_init.h"
48 #include "isf_ci.h"
49 #include "isf_ci_stream.h"
50 #include "isf_sm_types.h"
51 #include "isf_dsa_direct.h"
52 #include "isf_pm.h"
53 #include "Events.h"
55 
56 /* Generic sensor interfaces */
57 #include "isf_orientation_types.h"
58 #include "isf_pressure_types.h"
59 
60 /* Structure offset calculation macros */
61 #define startof(type,member) ((int32)&((type *)0)->member)
62 
63 /* Sensor data ready event masks. */
64 #define App1_Orientation0_DATA_READY_EVENT ((uint32)(1 << 0))
65 
66 #define App1_Pressure1_DATA_READY_EVENT ((uint32)(1 << 1))
67 
68 #define App1_ALL_SENSOR_DATA_READY (3)
69 
70 
71 /* This defines the error state of this application. */
72 typedef enum {
77 
78 
79 /*! @brief Macro that extracts one of the fields below. */
80 #define SET_FIELD(name,val) (((val)<<name##_SHIFT)&(name##_MASK))
81 #define GET_FIELD(name,val) ((val&name##_MASK)>>name##_SHIFT)
82 
83 /*! @brief Control register mask/shift definitions for the application. */
84 #define CTRL_STATE_MASK 0x0F
85 #define CTRL_STATE_SHIFT 0
86 #define CTRL_QREN_MASK 0x10
87 #define CTRL_QREN_SHIFT 4
88 #define CTRL_RESET_MASK 0x20
89 #define CTRL_RESET_SHIFT 5
90 #define CTRL_POWER_MASK 0xC0
91 #define CTRL_POWER_SHIFT 6
92 
93 /* Define the raw sensor identification type. */
94 typedef struct {
95  isf_SensorHandle_t smAdapterHandle; /* Sensor Adapter Handle */
96  uint8 sensorId; /* Global sensor identifier */
97 } SensorInfo_t;
98 
99 /* Define the sensor manager configuration type. */
100 typedef struct {
101  uint8 control; /* Current application state, see App1AppState_t for more information. */
102  isf_SubscriptionSettings_t OrientSettings_Sub0; /* Orientation sensor subscription data */
103  isf_SubscriptionSettings_t PressSettings_Sub1; /* Pressure sensor subscription data */
105 
106 /* Define the application instance type. */
107 typedef struct {
108  struct {
109  uint8 appId; /* Application ID of the application. */
110  LWEVENT_STRUCT smLWEvent; /* Sensor Manager lightweight event. */
111  LWSEM_STRUCT outputBufferLock; /* Output buffer lightweight semaphore. */
112  } instance; /* Application instance data */
113  struct {
114  SensorInfo_t OrientInfo_Sub0; /* Orientation sensor subscription data */
115  SensorInfo_t PressInfo_Sub1; /* Pressure sensor subscription data */
116  } info; /* Sensor identification information */
117  App1AppSettings_t settings; /* Sensor Manager settings */
118  struct {
119  isf_fifo_t orientDataFifo_Sub0; /* Orientation data fifo */
120  isf_fifo_t pressDataFifo_Sub1; /* Pressure data fifo */
121  } fifos; /* Sensor fifos */
124 
125 /* These defines set the start and ending byte offset into the mag3110ConfigRegister_t
126  * configuration data structure where the reported data rate resides. This information is used
127  * to determine if the host has updated the rate for reporting data.
128  */
129 #define CONFIG_SETTINGS_REPORTRATE_BYTE_START (4)
130 #define CONFIG_SETTINGS_REPORTRATE_BYTE_ENDS (7)
131 
132 
133 /******************************************************
134  * Global Variables
135  *****************************************************/
136 
137 /* Generate the initial default configuration statically for now.
138  Eventually this data should partially come from the actual sensor
139  components */
140 static App1AppInstance_t App1AppInstance = {
141  .instance.appId = 2,
142  .settings.control = SET_FIELD(CTRL_STATE,App1_STATE_STOPPED_UNSUBSCRIBED) | SET_FIELD(CTRL_POWER,1) | SET_FIELD(CTRL_QREN,1),
143  .info.OrientInfo_Sub0.sensorId = DSA_ORIENT_1,
144  .info.PressInfo_Sub1.sensorId = DSA_MPL3115_1,
145 };
146 
147 
148 /******************************************************
149  * Function Prototypes
150  *****************************************************/
151 int32 App1_GotoState(uint8 desiredState);
152 static int32 SettingsCompare(const isf_SubscriptionSettings_t *s1, const isf_SubscriptionSettings_t *s2);
153 static int32 SmSettingsCompare(const App1AppSettings_t *s1, const App1AppSettings_t *s2);
154 
155 
156 
157 /*
158 ** ===================================================================
159 ** Method : App1_OnTask (component ISFEmbApp)
160 **
161 ** Description :
162 ** This method is internal. It is used by Processor Expert only.
163 ** ===================================================================
164 */
165 void TaskApp1_task(uint32_t task_init_data)
166 {
167  /* Write your code here ... */
168  // Waiting for the system synchronisation.
169  // ISF initialization.
170  isf_lib_init(0);
171  isf_system_sync();
172  App1_MainTask();
173 
174 }
175 
176 /*
177 ** ===================================================================
178 ** Method : App1_MainTask()
179 **
180 ** Description :
181 ** The method functions as the main task for the Embedded Application.
182 ** The method initializes the Embedded Application global instance, calls the
183 ** user defined initialization, brings the selected subscriptions to a known state,
184 ** waits for raw sensor data as prescribed, calls the user defined data processing,
185 ** performs processed data output to the host interface. If the task should exit,
186 ** then it will call the user defined exit processing before the task is destroyed.
187 ** This method is internal. It is used by Processor Expert only.
188 ** Parameters : None.
189 ** Returns : None.
190 ** ===================================================================
191 */
192 
193 void App1_MainTask(void) {
194 
195  // User function for initialization.
196  App1_Initialization();
197 
198  // Initialize the application instance.
199  App1AppInstance.info.OrientInfo_Sub0.sensorId = DSA_ORIENT_1;
200  App1AppInstance.settings.OrientSettings_Sub0.resultType = 0;
201  App1AppInstance.settings.OrientSettings_Sub0.resultFormat = 1;
202  App1AppInstance.settings.OrientSettings_Sub0.nSamplePeriod = 40000;
203  App1AppInstance.settings.OrientSettings_Sub0.nSettingsToUse = 2;
204  App1AppInstance.settings.OrientSettings_Sub0.nFifoDepth = 1;
205  App1AppInstance.info.PressInfo_Sub1.sensorId = DSA_MPL3115_1;
206  App1AppInstance.settings.PressSettings_Sub1.resultType = 601;
207  App1AppInstance.settings.PressSettings_Sub1.resultFormat = 3;
208  App1AppInstance.settings.PressSettings_Sub1.nSamplePeriod = 1000000;
209  App1AppInstance.settings.PressSettings_Sub1.nSettingsToUse = 2;
210  App1AppInstance.settings.PressSettings_Sub1.nFifoDepth = 1;
211 
212  // Initialize and clear the lwevent passed to the Sensor Manager as part
213  // of the subscription to the App1 Sensor Adapter.
214  _lwevent_create(&App1AppInstance.instance.smLWEvent, LWEVENT_AUTO_CLEAR);
215  _lwevent_clear(&App1AppInstance.instance.smLWEvent, 0xFFFFFFFF);
216 
217  // Create the outputBufferLock used to prevent updates made while
218  // data is being read by the host.
219  _lwsem_create(&App1AppInstance.instance.outputBufferLock, 1);
220 
221  // initialize the fifo using an explicitly provided data buffer
223  isf_fifo_init(&App1AppInstance.fifos.pressDataFifo_Sub1, &App1AppInstance.data.rawPressData_Sub1, sizeof(DATA_TYPE_SUB1), DATA_FIFO_LEN_SUB1);
224  // Call the DSA direct interface to initialize the sensor.
225  init_sensor(
226  App1AppInstance.info.OrientInfo_Sub0.sensorId,
227  &App1AppInstance.info.OrientInfo_Sub0.smAdapterHandle,
228  &App1AppInstance.instance.smLWEvent,
230  );
231  init_sensor(
232  App1AppInstance.info.PressInfo_Sub1.sensorId,
233  &App1AppInstance.info.PressInfo_Sub1.smAdapterHandle,
234  &App1AppInstance.instance.smLWEvent,
236  );
237 
238  // Initialize the sensor subscriptions to Stopped/Unsubscribed state.
239  App1_GotoState(2);
240 
241  // Main task loop (forever).
242  while (1) {
243 
244  // Wait for sensor data.
245  _lwevent_wait_for(&App1AppInstance.instance.smLWEvent, App1_ALL_SENSOR_DATA_READY, 0, NULL);
246 
247  _lwsem_wait(&App1AppInstance.instance.outputBufferLock);
248 
249  // Get the signalled event.
250  uint32 signalledEvents = _lwevent_get_signalled();
251  // Updated based on received event(s).
252  if (signalledEvents & App1_Orientation0_DATA_READY_EVENT) // Orientation event.
253  {
254  isf_fifo_lock(&App1AppInstance.fifos.orientDataFifo_Sub0);
255  // User function to process the raw sensor data.
256  App1_ProcessData(&App1AppInstance.data, _lwevent_get_signalled());
257  // Have the Command Interpreter update the Quick-Read registers if they are enabled.
258  if (GET_FIELD(CTRL_QREN,App1AppInstance.settings.control))
259  {
260  // If the application is in a state that can produce streaming output, then send it to the host interface.
261  isf_ci_qr_update(App1AppInstance.instance.appId, sizeof App1AppInstance.data, (uint8 *)&App1AppInstance.data);
262  }
263  //TODO - Need to consider more elaborate default stream data sets and PEx CDE control for application to define them.
264  isf_ci_stream_update_data(0x01,sizeof(App1AppInstance.data), 0, (uint8 *)&App1AppInstance.data);
265  isf_fifo_el_clear(&App1AppInstance.fifos.orientDataFifo_Sub0);
266  isf_fifo_unlock(&App1AppInstance.fifos.orientDataFifo_Sub0);
267  }
268  if (signalledEvents & App1_Pressure1_DATA_READY_EVENT) // Pressure event.
269  {
270  isf_fifo_lock(&App1AppInstance.fifos.pressDataFifo_Sub1);
271  // User function to process the raw sensor data.
272  App1_ProcessData(&App1AppInstance.data, _lwevent_get_signalled());
273  // Have the Command Interpreter update the Quick-Read registers if they are enabled.
274  if (GET_FIELD(CTRL_QREN,App1AppInstance.settings.control))
275  {
276  // If the application is in a state that can produce streaming output, then send it to the host interface.
277  isf_ci_qr_update(App1AppInstance.instance.appId, sizeof App1AppInstance.data, (uint8 *)&App1AppInstance.data);
278  }
279  //TODO - Need to consider more elaborate default stream data sets and PEx CDE control for application to define them.
280  isf_ci_stream_update_data(0x01,sizeof(App1AppInstance.data), 0, (uint8 *)&App1AppInstance.data);
281  isf_fifo_el_clear(&App1AppInstance.fifos.pressDataFifo_Sub1);
282  isf_fifo_unlock(&App1AppInstance.fifos.pressDataFifo_Sub1);
283  }
284 
285 
286  // Unlock the buffer when it is no longer used.
287  _lwsem_post(&App1AppInstance.instance.outputBufferLock);
288 
289  } /* end while() */
290 
291  // User function to clean up on exit.
292  App1_Exit();
293 }
294 
295 /*
296 ** ===================================================================
297 ** Method : App1_HCIAppCallback
298 **
299 ** Description :
300 ** This function implements the App1 user application callback
301 ** for the Command Interpreter.
302 ** This function implements the predefined Command Interpreter command enumerations.
303 ** It will also include calling user-define commands if configured.
304 ** This method is internal. It is used by Processor Expert only.
305 ** Parameters :
306 ** NAME DESCRIPTION
307 ** pHostPacket Pointer to the host command.
308 ** pAppPacket Pointer to the response data.
309 ** Returns :
310 ** returns a value of type ci_response_t
311 ** ===================================================================
312 */
314  // New application configuration.
315  App1AppSettings_t NewConfig;
316  // Helper pointers to application configuration and data structures.
317  uint8 *pData = (uint8 *)&App1AppInstance.data;
318  App1AppSettings_t *pConfig = &App1AppInstance.settings;
319 
320  // Handle each valid host command.
321  switch(pHostPacket->cmd) {
322 
323  // Read data from the host output buffer.
325 
326  // Check if the command accesses bytes outside the valid range.
327  if (pHostPacket->byte_cnt > sizeof(App1AppInstance.data)) {
328  return CI_INVALID_COUNT;
329  }
330  if (pHostPacket->offset + pHostPacket->byte_cnt > sizeof(App1AppInstance.data)) {
331  return CI_ERROR_COMMAND;
332  }
333 
334  // Lock the output buffer, update the data to the CI, then unlock the buffer.
335  _lwsem_wait(&App1AppInstance.instance.outputBufferLock);
336  pAppPacket->bytes_xfer = isf_ci_app_write(pHostPacket->appId, pHostPacket->byte_cnt, (uint8*)pData + pHostPacket->offset);
337  _lwsem_post(&App1AppInstance.instance.outputBufferLock);
338 
339  break;
340 
341  // Update the Quick-Read data.
343  _lwsem_wait(&App1AppInstance.instance.outputBufferLock);
344  isf_ci_qr_update(App1AppInstance.instance.appId, (int8)sizeof(*pData), (uint8 *)pData);
345  _lwsem_post(&App1AppInstance.instance.outputBufferLock);
346  break;
347 
348  // Read or write the application configuration structure.
349  case CI_CMD_READ_CONFIG:
350  // Fall through
351  case CI_CMD_WRITE_CONFIG:
352 
353  // Check if the command accesses bytes outside the valid range.
354  if (pHostPacket->byte_cnt > sizeof(*pConfig))
355  return CI_INVALID_COUNT;
356  if (pHostPacket->offset + pHostPacket->byte_cnt > sizeof(*pConfig))
357  return CI_ERROR_COMMAND;
358 
359  if (CI_CMD_READ_CONFIG == pHostPacket->cmd) {
360 
361  // Create a copy of the current settings.
362  NewConfig = App1AppInstance.settings;
363 
364  // Convert the timestamp to big endian before sending data to the host.
365  NewConfig.OrientSettings_Sub0.nSamplePeriod = LONG_BE_TO_HOST(NewConfig.OrientSettings_Sub0.nSamplePeriod);
366  NewConfig.PressSettings_Sub1.nSamplePeriod = LONG_BE_TO_HOST(NewConfig.PressSettings_Sub1.nSamplePeriod);
367 
368  // Write the requested (READ) information to the host interface.
369  pAppPacket->bytes_xfer = (uint8)isf_ci_app_write(pHostPacket->appId, (uint32)pHostPacket->byte_cnt,
370  (uint8*)&NewConfig + pHostPacket->offset);
371 
372  }
373  else
374  {
375 
376  uint8 powerMode;
377 
378  // The host may not write the entire configuration buffer, so start with the current configuration.
379  NewConfig = App1AppInstance.settings;
380 
381  // Read the new data from the host.
382  pAppPacket->bytes_xfer = (uint8)isf_ci_app_read(pHostPacket->appId, (uint32)pHostPacket->byte_cnt,
383  (uint8*)&NewConfig + pHostPacket->offset);
384  // If the host updated the report rate, then convert big endian to little endian for each subscription.
385  if ((startof(App1AppSettings_t,OrientSettings_Sub0.nSamplePeriod) >= pHostPacket->offset) &&
386  ((startof(App1AppSettings_t,OrientSettings_Sub0.nSettingsToUse) - 1) <= (pHostPacket->offset + pHostPacket->byte_cnt) ))
387  {
388  NewConfig.OrientSettings_Sub0.nSamplePeriod = LONG_BE_TO_HOST(NewConfig.OrientSettings_Sub0.nSamplePeriod);
389  }
390  if ((startof(App1AppSettings_t,PressSettings_Sub1.nSamplePeriod) >= pHostPacket->offset) &&
391  ((startof(App1AppSettings_t,PressSettings_Sub1.nSettingsToUse) - 1) <= (pHostPacket->offset + pHostPacket->byte_cnt) ))
392  {
393  NewConfig.PressSettings_Sub1.nSamplePeriod = LONG_BE_TO_HOST(NewConfig.PressSettings_Sub1.nSamplePeriod);
394  }
395  // If the sensor settings are changed while subscribed, then unsubscribe and resubscribe to
396  // achieve the new settings. If not currently subscribed, then just store the new settings.
397  // Update the Quick-Read enable and power mode.
398  App1AppInstance.settings.control =
399  (App1AppInstance.settings.control & CTRL_STATE_MASK) |
400  SET_FIELD(CTRL_QREN,GET_FIELD(CTRL_QREN,NewConfig.control)) |
401  SET_FIELD(CTRL_POWER,GET_FIELD(CTRL_POWER,NewConfig.control));
402 
403  // Set the ISF power mode based on the host request.
404  powerMode = GET_FIELD(CTRL_POWER,App1AppInstance.settings.control);
405  powerMode = isf_power_set(powerMode);
406 
407  // Store the resulting mode into the application state structure.
408  App1AppInstance.settings.control =
409  (App1AppInstance.settings.control & ~CTRL_POWER_MASK) |
410  SET_FIELD(CTRL_POWER,powerMode);
411 
412  // If the embedded application settings have been changed by the host, then bring subscriptions to Stopped/Unsubscribed.
413  if ( SmSettingsCompare(&NewConfig, &App1AppInstance.settings)) {
415  App1AppInstance.settings.OrientSettings_Sub0 = NewConfig.OrientSettings_Sub0;
416  App1AppInstance.settings.PressSettings_Sub1 = NewConfig.PressSettings_Sub1;
417  }
418  // Return the subscriptions to the requested state.
419  if (App1_GotoState(GET_FIELD(CTRL_STATE,NewConfig.control))) {
420  return CI_ERROR_COMMAND;
421  }
422 
423  }
424  break;
425 
426  // Reset the application state.
427  case CI_CMD_RESET_APP:
428  if (App1_GotoState(2) != 0) {
429  return CI_ERROR_COMMAND;
430  }
431  break;
432 
433 
434  default:
435  return CI_ERROR_COMMAND;
436  break;
437  }
438  return CI_ERROR_NONE;
439 }
440 
441 /*
442 ** ===================================================================
443 ** Method : App1_ReturnSensorsToInit()
444 **
445 ** Description :
446 ** This function is used by the App1_GotoState() state machine to manually return the sensors
447 ** to the 'DSA_STATE_INITIALIZED' state when there is an error with any of the sensors. This is done
448 ** with the assumption that we are already in an Error state with at least one sensor AND that error will
449 ** be returned to a higher level, so don't try to check errors further here.
450 ** Parameters :
451 ** None.
452 ** Returns :
453 ** Nothing
454 ** ===================================================================
455 */
457 {
458  // Return the Accelerometer back to the DSA_STATE_INITIALIZED.
460  {
462  }
464  {
466  }
467  // Return the Accelerometer back to the DSA_STATE_INITIALIZED.
469  {
471  }
473  {
475  }
476 
477 }
478 /*
479 ** ===================================================================
480 ** Method : App1_GotoState()
481 **
482 ** Description :
483 ** This function implements the App1 sensor subscription state machine.
484 ** The implementation currently supports three states:
485 ** App1_STATE_STOPPED_UNSUBSCRIBED = 0, // Sensor is Unsubscribed; Data Flow is Stopped (Initial State).
486 ** App1_STATE_STOPPED_SUBSCRIBED = 1, // Sensor is Subscribed; Data Flow is Stopped.
487 ** App1_STATE_STARTED_SUBSCRIBED = 2, // Sensor is Subscribed; Data Flow has Started.
488 ** As the state machine transitions between the states, it makes calls to the ISF Sensor Manager
489 ** functions as necessary.
490 ** This method is internal. It is used by Processor Expert only.
491 ** Parameters :
492 ** NAME DESCRIPTION
493 ** desiredState The desiredstate for the application at the
494 ** completion of the function call.
495 ** pAppPacket Pointer to the response data.
496 ** Returns :
497 ** returns an int32 value indicating the status of its operation.
498 ** ===================================================================
499 */
501 {
502  isf_status_t smstt = 0;
503  int32 retval = 0;
504 
505  // Check that the desired state is within range, otherwise return an error.
506  if (desiredState > App1_STATE_STARTED_SUBSCRIBED)
507  {
508  return 1;
509  }
510 
511  // Loop until the desired state is reached or an error occurs.
512  while ( !smstt && (desiredState != GET_FIELD(CTRL_STATE,App1AppInstance.settings.control)) )
513  {
514  switch ( GET_FIELD(CTRL_STATE,App1AppInstance.settings.control) )
515  {
517  // The only valid transition from current state is to stopped, subscribed.
518  // Subscribe to the sensor data.
519  smstt = ISF_SUCCESS;
520  smstt |= configure_sensor(
521  &App1AppInstance.info.OrientInfo_Sub0.smAdapterHandle,
522  &App1AppInstance.settings.OrientSettings_Sub0,
523  &App1AppInstance.fifos.orientDataFifo_Sub0
524  );
525  smstt |= configure_sensor(
526  &App1AppInstance.info.PressInfo_Sub1.smAdapterHandle,
527  &App1AppInstance.settings.PressSettings_Sub1,
528  &App1AppInstance.fifos.pressDataFifo_Sub1
529  );
530 
531  if (smstt != ISF_SUCCESS) {
533  retval = 1;
534  }
535  else
536  {
537  // State transition.
538  App1AppInstance.settings.control = (App1AppInstance.settings.control & ~CTRL_STATE_MASK) |
540  }
541  break;
542 
544  // The only valid transition from the current state is to the stopped, subscribed state.
545  smstt = ISF_SUCCESS;
546  // End subscription to the sensor data.
547  smstt |= stop_sensor(&App1AppInstance.info.OrientInfo_Sub0.smAdapterHandle);
548  smstt |= stop_sensor(&App1AppInstance.info.PressInfo_Sub1.smAdapterHandle);
549  if (smstt != ISF_SUCCESS) {
551  retval = 1;
552  }
553  else
554  {
555  // State transition.
556  App1AppInstance.settings.control = (App1AppInstance.settings.control & ~CTRL_STATE_MASK) |
558  }
559  break;
560 
562  // From the current state, the valid transitions are to the stopped, unsubscribed, or started, subscribed states.
563  smstt = ISF_SUCCESS;
564  if (desiredState)
565  {
566  // Begin subscription to the sensor data.
567  smstt |= start_sensor(&App1AppInstance.info.OrientInfo_Sub0.smAdapterHandle);
568  smstt |= start_sensor(&App1AppInstance.info.PressInfo_Sub1.smAdapterHandle);
569  if (smstt != ISF_SUCCESS) {
571  retval = 1;
572  }
573  else
574  {
575  // State transition.
576  App1AppInstance.settings.control = (App1AppInstance.settings.control & ~CTRL_STATE_MASK) |
578  }
579  }
580  else
581  {
582  // Unsubscribe from the sensor adapter data.
583  smstt |= shutdown_sensor(&App1AppInstance.info.OrientInfo_Sub0.smAdapterHandle);
584  smstt |= shutdown_sensor(&App1AppInstance.info.PressInfo_Sub1.smAdapterHandle);
585  if (smstt != ISF_SUCCESS) {
587  retval = 1;
588  }
589  else
590  {
591  // State transition.
592  App1AppInstance.settings.control = (App1AppInstance.settings.control & ~CTRL_STATE_MASK) |
594  }
595  }
596  break;
597 
598  default:
599  // This is an invalid current state.
600  retval = 1;
601  }
602  }
603  return retval;
604 }
605 
606 /*
607 ** ===================================================================
608 ** Method : SettingsCompare()
609 **
610 ** Description :
611 ** This function compares the members of the App1AppSettings_t C structure
612 ** because C does not automatically provide for comparison of structures.
613 ** This method is internal. It is used by Processor Expert only.
614 ** Parameters :
615 ** NAME DESCRIPTION
616 ** s1 A pointer to the first structure to compare
617 ** s2 A pointer to the second structure to compare
618 ** Returns :
619 ** 0 The structures are equivalent. 1 The structures are different.
620 ** ===================================================================
621 */
622 static int32 SettingsCompare(const isf_SubscriptionSettings_t *s1, const isf_SubscriptionSettings_t *s2)
623 {
624  return
625  (
626  (s1->resultType != s2->resultType) ||
627  (s1->resultFormat != s2->resultFormat) ||
628  (s1->nSettingsToUse != s2->nSettingsToUse) ||
629  (s1->nFifoDepth != s2->nFifoDepth) ||
630  (s1->nSamplePeriod != s2->nSamplePeriod)
631  );
632 }
633 
634 /*
635 ** ===================================================================
636 ** Method : SmSettingsCompare()
637 **
638 ** Description :
639 ** This function compares the members of the App1AppConfig_t C structure
640 ** because C does not automatically provide for comparison of structures.
641 ** This method is internal. It is used by Processor Expert only.
642 ** Parameters :
643 ** NAME DESCRIPTION
644 ** s1 A pointer to the first structure to compare
645 ** s2 A pointer to the second structure to compare
646 ** Returns :
647 ** 0 The structures are equivalent. 1 The structures are different.
648 ** ===================================================================
649 */
650 static int32 SmSettingsCompare(const App1AppSettings_t *s1, const App1AppSettings_t *s2)
651 {
652  return
653  (
654  SettingsCompare(&s1->OrientSettings_Sub0,&s2->OrientSettings_Sub0) ||
655  SettingsCompare(&s1->PressSettings_Sub1,&s2->PressSettings_Sub1) ||
656  (1 != 1)
657  );
658 }
659 /* END App1. */
660 /*!
661 ** @}
662 */
663 /*
664 ** ###################################################################
665 **
666 ** This file was created by Processor Expert 10.3 [05.09]
667 ** for the Freescale Kinetis series of microcontrollers.
668 **
669 ** ###################################################################
670 */
struct App1AppInstance_t::@1 info
ISF board support header files.
void isf_system_sync(void)
This function synchronizes the user tasks and the system initialization.
Definition: isf_init.c:50
unsigned char uint8
This defines uint8 as unsigned char.
Definition: isf_types.h:18
isf_SensorHandle_t smAdapterHandle
Definition: App1.c:95
int32 stop_sensor(isf_SensorHandle_t *pSensorAdapterHandle)
ISF Command Interpreter (CI) stream protocol header file.
void App1_MainTask(void)
Definition: App1.c:193
isf_fifo_status_t isf_fifo_lock(isf_fifo_t *pFifo)
Lock a sample buffer for exclusive access.
Definition: isf_fifo.c:171
isf_fifo_status_t isf_fifo_unlock(isf_fifo_t *pFifo)
Release the exclusive access lock on a sample buffer.
Definition: isf_fifo.c:202
ci_response_t App1_ci_app_callback(ci_host_cmd_packet_t *pHostPacket, ci_app_resp_packet_t *pAppPacket)
Definition: App1.c:313
#define CTRL_POWER_MASK
Definition: App1.c:90
SensorInfo_t PressInfo_Sub1
Definition: App1.c:115
#define SET_FIELD(name, val)
Macro that extracts one of the fields below.
Definition: App1.c:80
This defines the DSA sensor device handle structure used to invoke the adapter access functions...
isf_fifo_status_t isf_fifo_el_clear(isf_fifo_t *pFifo)
Routine to clear the fifo.
Definition: isf_fifo.c:220
isf_dsa_result_types_t resultFormat
The format of the data to be returned- 0=RAW, 1=FIXED, 2=FLOAT.
#define DATA_TYPE_SUB0
Definition: App1_types.h:10
LWEVENT_STRUCT smLWEvent
Definition: App1.c:110
signed char int8
Definition: basic_types.h:12
The isf_sensor_configuration.h contains the enumerated list of Digital Sensor Abstraction (DSA) senso...
unsigned long uint32
This defines uint32 as unsigned long.
Definition: isf_types.h:36
#define startof(type, member)
Definition: App1.c:61
uint8 sensorId
Definition: App1.c:96
int32 App1_GotoState(uint8 desiredState)
Definition: App1.c:500
void TaskApp1_task(uint32_t task_init_data)
Definition: App1.c:165
power_level_t isf_power_set(power_level_t aLevel)
This API sets the requested power level for power management.
Definition: pm.c:57
isf_fifo_t orientDataFifo_Sub0
Definition: App1.c:119
uint8 nFifoDepth
1 = no FIFO, or another value < SM_MAX_FIFO_DEPTH
DATA_TYPE_SUB0 rawOrientData_Sub0[DATA_FIFO_LEN_SUB0]
Definition: App1_types.h:16
isf_pm.h describes the API definitions, types, and macros for the Intelligent Sensing Framework (ISF)...
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...
void App1_ReturnSensorsToInit()
Definition: App1.c:456
#define App1_Pressure1_DATA_READY_EVENT
Definition: App1.c:66
DATA_TYPE_SUB1 rawPressData_Sub1[DATA_FIFO_LEN_SUB1]
Definition: App1_types.h:17
App1AppSettings_t settings
Definition: App1.c:117
uint8 control
Definition: App1.c:101
isf_SubscriptionSettings_t OrientSettings_Sub0
Definition: App1.c:102
App1SensorData_t data
Definition: App1.c:122
int32 init_sensor(uint8 nSensorID, isf_SensorHandle_t *pSensorAdapterHandle, LWEVENT_STRUCT *pEventGroup, uint32 nEventFieldIndex)
This function initializes the sensor adapters in the absence of the Sensor Manager.
int32 configure_sensor(isf_SensorHandle_t *pSensorAdapterHandle, isf_SubscriptionSettings_t *pRequiredSettings, isf_fifo_t *pfifo)
isf_status_t isf_lib_init(void *pNull)
API ISF library get information.
Definition: isf_init.c:18
int32 start_sensor(isf_SensorHandle_t *pSensorAdapterHandle)
isf_fifo_status_t isf_fifo_init(isf_fifo_t *pFifo, void *pData, uint16 sampleSize, uint16 bufferCapacity)
Initializes a new fifo structure with a provided buffer.
Definition: isf_fifo.c:19
struct App1AppInstance_t::@0 instance
#define App1_Orientation0_DATA_READY_EVENT
Definition: App1.c:64
uint32 isf_ci_app_read(uint8 aAppId, uint32 anumBytes, uint8 *apDst)
This API reads data from the host via the mailboxes.
uint32 isf_ci_app_write(uint8 aAppId, uint32 anumBytes, uint8 *apSrc)
This API writes data to the host via the mailboxes.
#define DATA_FIFO_LEN_SUB0
Definition: App1_types.h:9
long int32
This defines int32 as long.
Definition: isf_types.h:32
isf_SensorDataTypes_t resultType
The desired data type of the subscription.
SensorInfo_t OrientInfo_Sub0
Definition: App1.c:114
Main ISF header file. Contains code common to all ISF components.
isf_dsa_AdapterStatus_t adapterStatus
isf_fifo_t pressDataFifo_Sub1
Definition: App1.c:120
struct App1AppInstance_t::@2 fifos
uint8 nSettingsToUse
1 = current; 2=given; 3=best possible
API definitions, types, and macros for the Intelligent Sensing Framework (ISF) Command Interpreter (C...
uint32 nSamplePeriod
Sample period in microseconds.
ci_status_t isf_ci_qr_update(uint8 aAppId, int8 anumBytes, uint8 *apSrc)
This API updates the Quick-Read mailboxes.
LWSEM_STRUCT outputBufferLock
Definition: App1.c:111
The isf_init.h file contains the task initialization attributes required for initialization of the fo...
#define CTRL_STATE_MASK
Control register mask/shift definitions for the application.
Definition: App1.c:84
#define GET_FIELD(name, val)
Definition: App1.c:81
This structure enables an application to read from or write to the host.
Definition: isf_ci.h:210
int32 isf_status_t
ISF return status type.
Definition: isf.h:51
#define DATA_FIFO_LEN_SUB1
Definition: App1_types.h:11
isf_SubscriptionSettings_t PressSettings_Sub1
Definition: App1.c:103
This structure contains host command information.
Definition: isf_ci.h:186
int32 shutdown_sensor(isf_SensorHandle_t *pSensorAdapterHandle)
The isf_sm_types.h contains the collection of type definitions used in the Sensor Manager Interface a...
ci_response_enum
These are the CI errors provided to the host.
Definition: isf_ci.h:107
isf_status_t isf_ci_stream_update_data(uint8 aDataSetID, uint16 aLength, uint16 aOffset, uint8 *apSrc)
This API updates the data of a dataset.
uint8 appId
Definition: App1.c:109
#define App1_ALL_SENSOR_DATA_READY
Definition: App1.c:68
#define DATA_TYPE_SUB1
Definition: App1_types.h:12
App1AppState_t
Definition: App1.c:72