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

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

isf_sm_api.h
Go to the documentation of this file.
1 /**
2 * @file isf_sm_api.h
3 * @brief The \b isf_sm_api.h contains the collection of APIs for the Sensor Manager as well as related defines and data structures
4 * required.
5 *
6 * @copyright Copyright (c) 2015, Freescale Semiconductor, Inc.
7 */
8
9 #ifndef ISF_SM_API_H_
10 #define ISF_SM_API_H_
11
12 #include "isf.h"
13 #include "isf_dsa_adapter.h"
14 #include "isf_sm_types.h"
15
16
17 /*! @brief This is the Sensor Manager API used to find a sensor of the requested type.
18 *
19 * @Purpose This API allows a subscriber to find a sensor of a given type without knowing
20 * exactly which sensors have been composed into a particular system. A subscriber
21 * may search for a sensor by type with an optional data type constraint. The function
22 * returns the number of sensors found that support the requested types, and fills
23 * the provided list buffer (up to the specified buffer size) with the sensor IDs
24 * of the sensors meeting the specified search criteria.
25 * The function will fill the sensorList with sensorIDs in the same order they exist in
26 * the gSensorList array.
27 * When only a single sensorID is desired, set the sensorListSize to 1.
28 *
29 * @param[in] typeToFind The type of the sensor to search for.
30 * @param[in] dataTypeToFind An additional data type that must be supported by the sensors.
31 * @param[in,out] sensorList Pointer to a buffer for the returned sensor IDs
32 * @param[in] sensorListSize The maximum number of sensorIDs to be returned (the size of the
33 * sensorList)
34 *
35 * @return ::isf_sm_find_sensor_by_type() returns the number of sensors found that match the
36 * specified search criteria.
37 *
38 * @retval A return value of zero indicates that no matching sensors were found.
39
40 *
41 * @retval A non-zero return value indicates the number of sensorIDs that were placed
42 * in the sensorList that matched the specified search criteria.
43 *
44 * @Reentrant Yes
45 * @Libs isf_core.lib
46 *
47 */
48 uint8 isf_sm_find_sensor_by_type(isf_SensorTypes_t typeToFind, isf_SensorDataTypes_t dataTypeToFind,
49 uint8 *sensorList, uint8 sensorListSize);
50
51 /*! @brief This is the Sensor Manager API used to subscribe to sensor data.
52 *
53 * @Purpose This API allows a subscriber to register for data
54 * from this sensor and to define the preferred sensor settings,
55 * if necessary.
56 *
57 * @param[in] nSensorID ISF unique sensor obtained from the sensor list.
58 * @param[in,out] pRequiredSettings On input, the parameter contains a valid pointer to the
59 * desired sensor sample settings. \n On output, alternate
60 * sensor sample settings are provided, if the requested
61 * settings are not possible.
62 * @param[in] pEventGroup Pointer to the event group for SM to signal when sensor data is ready.
63 * @param[in] nEventFieldIndex Bit number or index in the event group for SM to signal when sensor data is ready.
64 * @param[in,out] pTokenAssigned On input, parameter contains a valid pointer to memory to send
65 * the assigned token ID. \n On successful output, the parameter
66 * contains the assigned token ID.
67 *
68 * @return ::isf_sm_subscribe_sensor_data() returns a value of type ::sm_result_t indicating the current state
69 * of the subscription.
70 *
71 * @retval ::ISF_SUCCESS is returned when the subscriber is registered to receive sensor
72 * data for the given sampling settings.
73 *
74 * @retval ::SM_API_ALTERNATE_OFFERED is returned when an alternate rate is provided.
75 * @retval ::SM_API_ERR_SENSOR_ID is returned when an invalid sensor ID is provided.
76 *
77 * @Constraints When the call completes successfully, the subscriber is registered to receive
78 * sensor data at the desired sample settings. The token ID for the subscription is returned to
79 * the subscriber.
80 *
81 * Otherwise, the subscriber is not registered to receive sensor data. Based on the return status,
82 * alternative sample settings may be proposed.
83 *
84 * @Reentrant Yes
85 * @Libs isf_core.lib
86 *
87 */
88 sm_result_t isf_sm_subscribe_sensor_data( uint8 nSensorID, isf_SubscriptionSettings_t *pRequiredSettings,
89 event_t *pEventGroup, uint32 nEventFieldIndex, uint32 *pTokenAssigned );
90
91 /*!<
92 *
93 * @Example
94 * AFE Accelerometer subscribes to data at rate of 50 Hz or a period of 20,000 microseconds with no FIFO
95 * ------------------------------------------------------------------------------------------
96 * ACCEL_SENSOR_3D : The ID of the accelerometer sensor to subscribe to.
97 * Subscription_EventGrp : Event group for Sensor Manager to post events to this task when new accelerometer
98 * data is available.
99 * EV_ACCEL_DATA_RDY : event flag (bit) in the gHostProxy_EventGrp to be signaled.
100 * SM_GIVEN_SETTINGS : the sensor settings in the subscription must be used exactly.
101 * AccelDataToken : The unique returned token for the subscription.
102 * <pre>
103 * SubscriptionSettings.nSamplePeriod = 20000;
104 * SubscriptionSettings.resultType = TYPE_RAW_ACCELERATION_3D;
105 * SubscriptionSettings.resultFormat = DSA_RESULT_TYPE_RAW_COUNTS;
106 * SubscriptionSettings.nFifoDepth = 1;
107 * SubscriptionSettings.nSettingsToUse = SM_GIVEN_SETTINGS;
108 * </pre>
109 * <pre>
110 * smApiResult = \a isf_sm_subscribe_sensor_data( SM_AFE_ACCEL_SENSOR_3D,
111 * &SubscriptionSettings,
112 * &Subscription_EventGrp,
113 * EV_ACCEL_DATA_RDY,
114 * &AccelDataToken);
115 * if ( smApiResult != ISF_SUCCESS)
116 * {
117 * // Error handling.
118 * ;
119 * }
120 * Copyright (c) 2015, Freescale Semiconductor, Inc.
121 *</pre>
122 *
123 */
124
125
126 /*! @brief This Sensor Manager API unsubscribes from
127 * receiving sensor data.
128 *
129 * @details This API allow the subscriber to unregister from a
130 * previously registered subscription to sensor data.
131 *
132 * @param[in] nTokenID This is the tokenID received from the
133 * SM after subscribing to the sensor.
134 *
135 * @return ::isf_sm_unsubscribe_sensor_data() returns a value
136 * of type ::sm_result_t indicating the result of the unsubscribe
137 * operation.
138 *
139 * @retval ::ISF_SUCCESS is returned when the unsubscribe
140 * operation completes successfully.
141 * @retval ::SM_API_ERR_TOKEN_ID is returned when the tokenID
142 * passed into the function is not valid.
143 *
144 * @Constraints If the operation is successful, the caller's
145 * subscription to sensor data associated with this tokenID
146 * is permanently removed.
147 * If the operation is unsuccessful, no change is made to the
148 * caller's subscription to this sensor.
149 *
150 * @Reentrant Yes
151 * @Libs isf_core.lib
152 **/
153 sm_result_t isf_sm_unsubscribe_sensor_data( uint32 nTokenID);
154 /*!<
155 *
156 * @Example
157 * To unsubscribe from sensor data, this API is called with the tokenID received from
158 * the Sensor Manager during subscription.
159 * ----------------------------------------------------------------------------------------
160 * isf_sm_unsubscribe_sensor_data( hostAccelDataToken);
161 * Copyright (c) 2015, Freescale Semiconductor, Inc.
162 */
163
164
165 /*! @brief This Sensor Manager API allows a subscriber to
166 * receive sensor data.
167 *
168 * @details This API allows a subscriber to request the Sensor
169 * Manager to begin sending subscribed sensor data.
170 *
171 * @param [in] nTokenID This is the tokenID received from the SM
172 * after subscribing to this sensor data.
173 *
174 * @return ::isf_sm_begin_sensor_data() returns a value of type
175 * ::sm_result_t indicating that sensor data is or is not
176 * provided.
177 *
178 * @retval ::ISF_SUCCESS is returned when the current
179 * subscriber is capable to receive notifications when data is
180 * available from the indicated sensor.
181 *
182 * @retval ::SM_API_ERR_TOKEN_ID is returned if the tokenID
183 * passed into the function is not valid.
184 *
185 * @Constraints If the operation is successful, starting from
186 * the next sensor data set, the subscriber registered with this
187 * token is notified whenever a new data set is ready to be
188 * fetched.
189 * If the operation is unsuccessful, no change is made to the
190 * caller's subscription to this sensor.
191 *
192 * @Reentrant Yes
193 * @Libs isf_core.lib
194 **/
195 sm_result_t isf_sm_begin_sensor_data( uint32 nTokenID);
196 /*!<
197 *
198 * @Example
199 * To begin receiving sensor data for this subscription, this API is called with the tokenID received from
200 * Sensor Manager during subscription.
201 * ----------------------------------------------------------------------------------------
202 * isf_sm_begin_sensor_data( hostAccelDataToken);
203 * Copyright (c) 2015, Freescale Semiconductor, Inc.
204 */
205
206
207 /*! @brief This Sensor Manager API is used by a subscriber to
208 * stop receiving sensor data
209 *
210 * @details This API enables a subscriber to request the Sensor
211 * Manager to stop sending subscribed sensor data.
212 *
213 * @param [in] nTokenID The tokenID of the sensor from which the subscriber no longer wishes to receive data.
214 *
215 * @return ::isf_sm_end_sensor_data() returns a value of type
216 * ::sm_result_t indicating whether or not the operation was
217 * successful.
218 *
219 * @retval ::ISF_SUCCESS is returned when the sensor no longer provides data to the subscriber.
220 *
221 * @retval ::SM_API_ERR_TOKEN_ID is returned when the tokenID
222 * passed into the function is not valid.
223 *
224 * @Constraints If the operation is successful, starting from
225 * the next sensor data set, the subscriber registered with this
226 * token is no longer notified when a new data set is available.
227 * If the operation is unsuccessful, no change is made to the
228 * caller's subscription to this sensor.
229 *
230 * @Reentrant Yes
231 * @Libs isf_core.lib
232 **/
233 sm_result_t isf_sm_end_sensor_data( uint32 nTokenID);
234 /*!<
235 *
236 * @Example
237 * To stop receiving sensor data for this subscription, this
238 * API is called with the tokenID received from the
239 * Sensor Manager during subscription.
240 * Note: This does not de-register the subscription. By calling isf_sm_begin_sensor_data(), the user could
241 * resume getting sensor data again at any time in the future.
242 * ----------------------------------------------------------------------------------------
243 * isf_sm_end_sensor_data( hostAccelDataToken);
244 *
245 * Copyright (c) 2015, Freescale Semiconductor, Inc.
246 */
247
248 /*! @brief This Sensor Manager API allows a subscriber to
249 * fetch a new sensor data set.
250 *
251 * @details This API allows a subscriber to
252 * fetch the next data set(s) when notified of new data
253 * availability.
254 *
255 * @param [in] nTokenID The tokenID received from the SM when
256 * the subscriber subscribed to this sensor at the given rate.
257 * @param [in,out] pSensorData On input,the parameter contains a
258 * valid pointer to the memory location to copy sensor sample
259 * set(s). \n
260 * On successful output, the parameter contains current sensor
261 * sample(s). When there is an error, the parameter is not
262 * changed.
263 *
264 * @return ::isf_sm_get_sensor_data() returns a value of type
265 * ::sm_result_t indicating whether or not the operation was
266 * successful.
267 *
268 * @retval ::ISF_SUCCESS is returned upon the sensor data set
269 * is copied successfully to the proper location.
270 * @retval ::SM_API_ERR_TOKEN_ID is returned when the tokenID
271 * passed into the function is not valid.
272 *
273 * @Constraints pSensorData must point to a properly allocated
274 * memory block large enough to hold the expected
275 * sensor sample data.
276 * If the operation is successful, current sensor data is copied
277 * to the proper memory location.
278 * If the operation is unsuccessful, no sensor data is copied.
279 * @Reentrant Yes
280 * @Libs isf_core.lib
281 **/
282 sm_result_t isf_sm_get_sensor_data(uint32 nTokenID, void *pSensorData );
283 /*!<
284 *
285 * @Example
286 \verbatim
287 The following outlines the sequence of actions occuring when a subscriber receives sensor data:
288 1. Subscriber waits for a specific event in its event group to receive sensor data from a given subscription.
289 2. The Sensor Manager signals the relevant event after depositing one or more new data sets in the shared memory area.
290 3. The subscriber, then, calls this API with the appropriate parameters as described above.
291 4. The API copies the sensor data set(s) to the passed in memory buffer with semaphore protection.
292 5. The subscriber task is free to use the sensor data as it pleases.
293 ------------------------------------------------------------
294 Notes:
295 - When notified via an event, the subscriber is able to fetch the data with the API.
296 Or, the subscriber could decide not to get the data, at its discretion.
297 - The Sensor Manager over-writes the shared memory buffer set up during its subscription whenever new data is available based upon the sampling rate of this subscription.
298 - When an event notification is made by the Sensor Manager, the sensor data available to fetch is the most recent sample set(s).
299
300 Notes on the example code:
301 - gHostNoFifoAccelData : The user buffer for receiving accelerometer data when notified by the Sensor Manager that the accelerometer data is ready.
302 - EV_HOST_ACCEL_DATA_RDY : The event flag (bit) for the Sensor Manager to notify the user when new accelerometer data is available.
303 --------------------------------------------------------------
304 AccelData_t gHostNoFifoAccelData;
305 ...
306 vuint8 *pv8MailBox;
307 uint8 *pSendData;
308 uint8 bytes2Write;
309 ...
310 switch (gCurrentEventID)
311 {
312 case EV_HOST_ACCEL_DATA_RDY:
313 isf_sm_get_sensor_data(hostAccelDataToken, (void *)&gHostNoFifoAccelData );
314 // Now the data is consumed.
315 // This data is deposited in the Slave-Port Mailbox for the host application to fetch
316 // The accelerometer data packet starts writing from MB24.
317 // MB22 - MB25 : time stamp of this data set
318 // MB26 - MB31 : xyz data [6 bytes]
319 pv8MailBox = &SP_MB22;
320 pSendData = (uint8 *)&gHostNoFifoAccelData;
321 bytes2Write = (uint8)sizeof(gHostNoFifoAccelData);
322 while (bytes2Write--)
323 {
324 *pv8MailBox++ = *pSendData++;
325 }
326 break;
327
328 Copyright (c) 2015, Freescale Semiconductor, Inc.
329 \endverbatim
330 */
331
332
333 #endif /* ISF_SM_API_H_ */
uint8
unsigned char uint8
Definition: isf_types.h:76
isf_sm_get_sensor_data
sm_result_t isf_sm_get_sensor_data(uint32 nTokenID, void *pSensorData)
This Sensor Manager API allows a subscriber to fetch a new sensor data set.
isf_dsa_adapter.h
pSensorData
void * pSensorData[]
Definition: BasicApp1.c:408
isf_sm_begin_sensor_data
sm_result_t isf_sm_begin_sensor_data(uint32 nTokenID)
This Sensor Manager API allows a subscriber to receive sensor data.
isf_SensorTypes_t
isf_SensorTypes_t
Definition: isf_sensor_types.h:14
isf_sm_unsubscribe_sensor_data
sm_result_t isf_sm_unsubscribe_sensor_data(uint32 nTokenID)
This Sensor Manager API unsubscribes from receiving sensor data.
isf_sm_subscribe_sensor_data
sm_result_t isf_sm_subscribe_sensor_data(uint8 nSensorID, isf_SubscriptionSettings_t *pRequiredSettings, event_t *pEventGroup, uint32 nEventFieldIndex, uint32 *pTokenAssigned)
This is the Sensor Manager API used to subscribe to sensor data.
isf_SensorDataTypes_t
isf_SensorDataTypes_t
Definition: isf_sensor_types.h:61
isf.h
Main ISF header file. Contains code common to all ISF components.
isf_SubscriptionSettings_t
Definition: isf_dsa_direct_types.h:22
isf_sm_end_sensor_data
sm_result_t isf_sm_end_sensor_data(uint32 nTokenID)
This Sensor Manager API is used by a subscriber to stop receiving sensor data.
sm_result_t
int32 sm_result_t
Sensor Manager API return type.
Definition: isf_sm_types.h:37
isf_sm_find_sensor_by_type
uint8 isf_sm_find_sensor_by_type(isf_SensorTypes_t typeToFind, isf_SensorDataTypes_t dataTypeToFind, uint8 *sensorList, uint8 sensorListSize)
This is the Sensor Manager API used to find a sensor of the requested type.
uint32
unsigned long int uint32
Definition: isf_types.h:78
isf_sm_types.h
The isf_sm_types.h contains the collection of type definitions used in the Sensor Manager Interface a...
- © Freescale Semiconductor, Inc. 2016. All Rights Reserved.