[apps/tidep0084.git] / tutorials / generic_sensor_tutorial / tutorial / SensorToCloud / example / collector / csf.h
1 /******************************************************************************
3 @file csf.h
5 @brief Collector Specific Functions API
7 Group: WCS LPC
8 $Target Devices: Linux: AM335x, Embedded Devices: CC1310, CC1350$
10 ******************************************************************************
11 $License: BSD3 2016 $
13 Copyright (c) 2015, Texas Instruments Incorporated
14 All rights reserved.
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions
18 are met:
20 * Redistributions of source code must retain the above copyright
21 notice, this list of conditions and the following disclaimer.
23 * Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
27 * Neither the name of Texas Instruments Incorporated nor the names of
28 its contributors may be used to endorse or promote products derived
29 from this software without specific prior written permission.
31 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 ******************************************************************************
43 $Release Name: TI-15.4Stack Linux x64 SDK$
44 $Release Date: Jun 28, 2017 (2.02.00.03)$
45 *****************************************************************************/
46 #ifndef CSF_H
47 #define CSF_H
49 /******************************************************************************
50 Includes
51 *****************************************************************************/
53 #include <stdbool.h>
54 #include <stdint.h>
56 #include "llc.h"
57 #include "cllc.h"
58 #include "smsgs.h"
60 #ifdef __cplusplus
61 extern "C"
62 {
63 #endif
65 /******************************************************************************
66 Constants
67 *****************************************************************************/
69 /*! CSF Events - Key Event */
70 #define CSF_KEY_EVENT 0x0001
72 #define CSF_INVALID_SHORT_ADDR 0xFFFF
74 /******************************************************************************
75 Typedefs
76 *****************************************************************************/
79 /******************************************************************************
80 Function Prototypes
81 *****************************************************************************/
83 /*!
84 * @brief The application calls this function during initialization.
85 *
86 * @param sem - pointer to semaphore used by MAC API
87 */
88 extern void Csf_init(void *sem);
90 /*!
91 * @brief The application must call this function periodically to
92 * process any events that this module needs to process.
93 */
94 extern void Csf_processEvents(void);
96 /*!
97 * @brief The application calls this function to retrieve the stored
98 * network information. The stored network information was saved
99 * after starting a network.
100 * <BR>
101 * NOTE: If the "fh" is true you will need to free the
102 * pInfo->info.fhNetInfo.fhInfo.bcNumChans and
103 * pInfo->info.fhNetInfo.fhInfo.pUnicastChans buffers through
104 * Csf_free().
105 *
106 * @param pInfo - pointer to network information structure
107 *
108 * @return True if the network information is available
109 */
110 extern bool Csf_getNetworkInformation(Llc_netInfo_t *pInfo);
112 /*!
113 * @brief The application calls this function to indicate that it has
114 * started or restored the device in a network.
115 *
116 * The information will be saved and used to determine if a
117 * network was already started and should be restored instead
118 * of started.
119 *
120 * @param restored - true if restored in network
121 * @param pNetworkInfo - network information structure
122 */
123 extern void Csf_networkUpdate(bool restored, Llc_netInfo_t *pNetworkInfo);
125 /*!
126 * @brief The application calls this function to indicate that a device
127 * has joined the network.
128 *
129 * The information will be saved.
130 *
131 * @param pDevInfo - pointer to the device information
132 * @param capInfo - capability information of the joining device.
133 *
134 * @return ApiMac_assocStatus_success, ApiMac_assocStatus_panAtCapacity,
135 * or ApiMac_assocStatus_panAccessDenied
136 */
137 extern ApiMac_assocStatus_t Csf_deviceUpdate(
138 ApiMac_deviceDescriptor_t *pDevInfo,
139 ApiMac_capabilityInfo_t *pCapInfo);
141 /*!
142 * @brief The application calls this function to indicate that a device
143 * disassociated.
144 *
145 * @param pSrcAddr - short address of the device that disassociated
146 */
147 extern void Csf_deviceDisassocUpdate( ApiMac_sAddr_t *pSrcAddr );
149 /*!
150 * @brief The application calls this function to indicate that a device
151 * is no longer active in the network. This function will be
152 * called when the device doesn't respond to the tracking request.
153 *
154 * The information will be saved.
155 *
156 * @param pDevInfo - pointer to the device information
157 * @param timeout - true if not active because of tracking timeout.
158 * meaning that the device didn't respond to the tracking request
159 * within the timeout period.
160 */
161 extern void Csf_deviceNotActiveUpdate(ApiMac_deviceDescriptor_t *pDevInfo,
162 bool timeout);
164 /*!
165 * @brief The application calls this function to indicate that a device
166 * has responded to a Config Request.
167 *
168 * The information will be saved.
169 *
170 * @param pSrcAddr - short address of the device that sent the message
171 * @param rssi - the received packet's signal strength
172 * @param pMsg - pointer to the Config Response message
173 */
174 extern void Csf_deviceConfigUpdate(ApiMac_sAddr_t *pSrcAddr, int8_t rssi,
175 Smsgs_configRspMsg_t *pMsg);
177 /*!
178 * @brief The application calls this function to indicate that a device
179 * has reported sensor data.
180 *
181 * The information will be saved.
182 *
183 * @param pSrcAddr - short address of the device that sent the message
184 * @param rssi - the received packet's signal strength
185 * @param pMsg - pointer to the Sensor Data message
186 */
187 extern void Csf_deviceSensorDataUpdate(ApiMac_sAddr_t *pSrcAddr, int8_t rssi,
188 Smsgs_sensorMsg_t *pMsg);
190 /*!
191 The application calls this function to indicate that a device
192 has reported its FW version.
194 Public function defined in csf.h
195 */
196 /*!
197 * @brief The application calls this function to indicate that a device
198 * has reported its FW version.
199 *
200 * @param pSrcAddr - short address of the device that sent the message
201 * @param fwVerStr - the FW version string
202 */
203 extern void Csf_deviceSensorFwVerUpdate(uint16_t srcAddr, char *fwVerStr);
205 /*!
206 The application calls this function to indicate that a device
207 has requested an OAD block.
209 Public function defined in csf.h
210 */
211 /*!
212 * @brief The application calls this function to indicate that a device
213 * has reported its FW version.
214 *
215 * @param pSrcAddr - short address of the device that sent the message
216 * @param blockNum - block requested
217 * @param NumBlocks - Total number of block
218 */
219 extern void Csf_deviceSensorOadUpdate( uint16_t srcAddr, uint16_t imgId, uint16_t blockNum, uint16_t NumBlocks);
221 /*!
222 * @brief The application calls this function to indicate that a device
223 * set a Toggle LED Response message.
224 *
225 * @param pSrcAddr - short address of the device that sent the message
226 * @param ledState - 0 is off, 1 is on
227 */
228 extern void Csf_toggleResponseReceived(ApiMac_sAddr_t *pSrcAddr, bool ledState);
230 /*!
231 * @brief The application calls this function to indicate that the
232 * Coordinator's state has changed.
233 *
234 * @param state - new state
235 */
236 extern void Csf_stateChangeUpdate(Cllc_states_t state);
238 /*!
239 * @brief Initialize the tracking clock.
240 */
241 extern void Csf_initializeTrackingClock(void);
243 /*!
244 * @brief set the tracking clock.
245 *
246 * @param trackingTime - set timer this value (in msec)
247 */
248 extern void Csf_setTrackingClock(uint32_t trackingTime);
250 /*!
251 * @brief Initialize the trickle timer clock
252 */
253 extern void Csf_initializeTrickleClock(void);
255 /*!
256 * @brief Initialize the clock setting join permit duration
257 */
258 extern void Csf_initializeJoinPermitClock(void);
260 /*!
261 * @brief Initialize the clock setting config request delay
262 */
263 extern void Csf_initializeConfigClock(void);
265 /*!
266 * @brief Set trickle clock
267 *
268 * @param trickleTime - duration of trickle timer( in msec)
269 * @param frameType - type of Async frame
270 */
271 extern void Csf_setTrickleClock(uint32_t trickleTime, uint8_t frameType);
273 /*!
274 * @brief Set Join Permit clock
275 *
276 * @param joinDuration - duration for which join permit is TRUE( in msec)
277 */
278 extern void Csf_setJoinPermitClock(uint32_t joinDuration);
280 /*!
281 * @brief Set Config request delay clock
282 *
283 * @param delay - duration config request event is set( in msec)
284 */
285 extern void Csf_setConfigClock(uint32_t delay);
287 /*!
288 * @brief Read the number of device list items stored
289 *
290 * @return number of entries in the device list
291 */
292 extern uint16_t Csf_getNumDeviceListEntries(void);
294 /*!
295 * @brief Find the short address from a given extended address
296 *
297 * @param pExtAddr - extended address
298 *
299 * @return CSF_INVALID_SHORT_ADDR if not found, otherwise the short address
300 */
301 extern uint16_t Csf_getDeviceShort(ApiMac_sAddrExt_t *pExtAddr);
303 /*!
304 * @brief Find entry in device list from an address
305 *
306 * @param pDevAddr - device address
307 * @param pItem - place to put the device information
308 *
309 * @return true if found, false if not
310 */
311 extern bool Csf_getDevice(ApiMac_sAddr_t *pDevAddr, Llc_deviceListItem_t *pItem);
313 /*!
314 * @brief Find entry in device list
315 *
316 * @param devIndex - Device number (not address)
317 * @param pItem - place to put the device information
318 *
319 * @return true if found, false if not
320 */
321 extern bool Csf_getDeviceItem(uint16_t devIndex, Llc_deviceListItem_t *pItem);
323 /*!
324 * @brief Find entry in device list
325 *
326 * @param size - number of bytes to allocate from heap
327 *
328 * @return true if found, false if not
329 */
330 extern void *Csf_malloc(uint16_t size);
332 /*!
333 * @brief Csf implementation for memory de-allocation
334 *
335 * @param ptr - a valid pointer to the memory to free
336 */
337 extern void Csf_free(void *ptr);
339 /*!
340 * @brief Update the Frame Counter
341 *
342 * @param pDevAddr - pointer to device's address. If this pointer
343 * is NULL, it means that this is the frame counter
344 * for this device.
345 * @param frameCntr - valur of frame counter
346 */
347 extern void Csf_updateFrameCounter(ApiMac_sAddr_t *pDevAddr,
348 uint32_t frameCntr);
350 /*!
351 * @brief Get the Frame Counter
352 *
353 * @param pDevAddr - pointer to device's address. If this pointer
354 * is NULL, it means that this is the frame counter
355 * for this device.
356 * @param pFrameCntr - pointer to place to put the frame counter
357 *
358 * @return true if the frame counter existed, false if not.
359 */
360 extern bool Csf_getFrameCounter(ApiMac_sAddr_t *pDevAddr,
361 uint32_t *pFrameCntr);
363 /*!
364 * @brief Delete an entry from the device list
365 *
366 * @param pAddr - address to remove from device list.
367 */
368 extern void Csf_removeDeviceListItem(ApiMac_sAddrExt_t *pAddr);
370 /*!
371 * @brief Assert Indication
372 *
373 * @param reason - Reason for Assert
374 * 2 - HAL/ICALL
375 * 3 - MAC
376 * 4 - TIRTOS
377 */
378 extern void Csf_assertInd(uint8_t reason);
380 /*!
381 * @brief Clear all the NV Items
382 */
383 extern void Csf_clearAllNVItems(void);
385 /*!
386 * @brief Add an entry into the black list
387 *
388 * @param pAddr - address to add into the black list. The address
389 * can be either short or extended.
390 *
391 * @return true if added or already existed, false if problem
392 */
393 extern bool Csf_addBlackListItem(ApiMac_sAddr_t *pAddr);
395 /*!
396 * @brief Check if config timer is active
397 *
398 * @return true if active, false if not active
399 */
400 extern bool Csf_isConfigTimerActive(void);
402 /*!
403 * @brief Check if tracking timer is active
404 *
405 * @return true if active, false if not active
406 */
407 extern bool Csf_isTrackingTimerActive(void);
409 #ifdef __cplusplus
410 }
411 #endif
413 #endif /* CSF_H */
415 /*
416 * ========================================
417 * Texas Instruments Micro Controller Style
418 * ========================================
419 * Local Variables:
420 * mode: c
421 * c-file-style: "bsd"
422 * tab-width: 4
423 * c-basic-offset: 4
424 * indent-tabs-mode: nil
425 * End:
426 * vim:set filetype=c tabstop=4 shiftwidth=4 expandtab=true
427 */