TI BLE5-Stack API Documentation  3.02.04.00
util.h
Go to the documentation of this file.
1 /******************************************************************************
2 
3  @file util.h
4 
5  @brief This file contains function declarations common to CC26xx
6  TIRTOS Applications.
7 
8  Group: WCS, BTS
9  $Target Device: DEVICES $
10 
11  ******************************************************************************
12  $License: BSD3 2014 $
13  ******************************************************************************
14  $Release Name: PACKAGE NAME $
15  $Release Date: PACKAGE RELEASE DATE $
16  *****************************************************************************/
17 
26 #ifndef UTIL_H
27 #define UTIL_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /*********************************************************************
34  * INCLUDES
35  */
36 #include <stdbool.h>
37 #ifdef FREERTOS
38 #include <mqueue.h>
39 #include <pthread.h>
40  #ifndef Event_Handle
41  #define Event_Handle void*
42  #endif
43 #else
44 #include <ti/sysbios/knl/Queue.h>
45 #include <ti/sysbios/knl/Clock.h>
46 #include <ti/sysbios/knl/Event.h>
47 #endif
48 
49 /*********************************************************************
50 * EXTERNAL VARIABLES
51 */
52 
53 /*********************************************************************
54  * CONSTANTS
55  */
56 
64 #ifdef FREERTOS
65 #define UTIL_EVENT_ID_NONE (0) // Event_Id_NONE
66 #define UTIL_EVENT_ID_00 (0x1) // Event_Id_00
67 #define UTIL_EVENT_ID_01 (0x2) // Event_Id_01
68 #define UTIL_EVENT_ID_02 (0x4) // Event_Id_02
69 #define UTIL_EVENT_ID_03 (0x8) // Event_Id_03
70 #define UTIL_EVENT_ID_04 (0x10)// Event_Id_04
71 #define UTIL_EVENT_ID_05 (0x20)// Event_Id_05
72 #define UTIL_EVENT_ID_06 (0x40)// Event_Id_06
73 #define UTIL_QUEUE_EVENT_ID (0x00100000)//Event_Id_30
74 #define UTIL_TL_CB_EVENT UTIL_EVENT_ID_00 // Event_Id_00
75 #else
76 #define UTIL_QUEUE_EVENT_ID Event_Id_30
77 #endif
78 /*********************************************************************
79  * TYPEDEFS
80  */
81 
82 #ifdef FREERTOS
83 typedef void (*UtilTimerCback)(uint32_t arg);
84 
85 typedef struct Clock_Struct
86 {
87  timer_t clock;
88  UtilTimerCback cback;
89  uint32_t arg;
90  sigevent evnt;
91  pthread_attr_t timerThrdAttr;
92  struct itimerspec timeVal;
93  uint8_t isActive;
94 }Clock_Struct;
95 #endif
96 
97 typedef struct
98 {
99  uint16_t event; // Event type.
100  uint8_t state; // Event state;
101 }appEvtHdr_t;
102 
103 /*********************************************************************
104  * MACROS
105  */
106 
107 /*********************************************************************
108  * API FUNCTIONS
109  */
110 
124 #ifdef FREERTOS
125 void* Util_constructClock(Clock_Struct *entry, UtilTimerCback clockCB,
126  uint32_t clockDuration, uint32_t clockPeriod,
127  uint8_t startFlag, uint32_t arg);
128 
129 void Clock_destruct(Clock_Struct *structP);
130 #else
131 extern Clock_Handle Util_constructClock(Clock_Struct *pClock,
132  Clock_FuncPtr clockCB,
133  uint32_t clockDuration,
134  uint32_t clockPeriod,
135  uint8_t startFlag,
136  UArg arg);
137 #endif
138 
146 extern void Util_startClock(Clock_Struct *pClock);
147 
156 extern void Util_restartClock(Clock_Struct *pClock, uint32_t clockTimeout);
157 
165 extern bool Util_isActive(Clock_Struct *pClock);
166 
174 extern void Util_stopClock(Clock_Struct *pClock);
175 
183 extern void Util_rescheduleClock(Clock_Struct *pClock, uint32_t clockPeriod);
184 
193 #ifdef FREERTOS
194 extern void Util_constructQueue(mqd_t *pQueue);
195 #else
196 extern Queue_Handle Util_constructQueue(Queue_Struct *pQueue);
197 #endif
198 
211 #ifdef FREERTOS
212 uint8_t Util_enqueueMsg(mqd_t msgQueue,
213  Event_Handle event,
214  uint8_t *pMsg);
215 #else
216 
217 extern uint8_t Util_enqueueMsg(Queue_Handle msgQueue,
218  Event_Handle event,
219  uint8_t *pMsg);
220 #endif
221 
229 #ifdef FREERTOS
230 uint8_t *Util_dequeueMsg(mqd_t msgQueue);
231 #else
232 extern uint8_t *Util_dequeueMsg(Queue_Handle msgQueue);
233 #endif
234 
243 extern char *Util_convertBdAddr2Str(uint8_t *pAddr);
244 
254 extern uint8_t Util_isBufSet(uint8_t *pBuf, uint8_t pattern, uint16_t len);
255 
256 #ifdef FREERTOS
257 /*********************************************************************
258  * @fn Event_post
259  *
260  * @brief DPL that is used to signal events. If a task is waiting
261  * for the event and the event conditions are met, post()
262  * unblocks the task. If no tasks are waiting, post() simply
263  * registers the event with the event object and returns.
264  *
265  * @param eventQueue - handle of a event queue
266  * @param msg - mask of eventIds to post (must be non-zero)
267  */
268 extern void Event_post(mqd_t eventQueue, uint32_t msg);
269 #endif
270 
271 /*********************************************************************
272 *********************************************************************/
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 
278 #endif /* UTIL_H */
279 
uint8_t * Util_dequeueMsg(Queue_Handle msgQueue)
Dequeues the message from the RTOS queue.
uint8_t Util_isBufSet(uint8_t *pBuf, uint8_t pattern, uint16_t len)
Check if contents of buffer matches byte pattern.
uint8_t Util_enqueueMsg(Queue_Handle msgQueue, Event_Handle event, uint8_t *pMsg)
Creates a queue node and puts the node in RTOS queue.
void Util_rescheduleClock(Clock_Struct *pClock, uint32_t clockPeriod)
Reschedule a clock by changing the timeout and period values.
void Util_startClock(Clock_Struct *pClock)
Start a clock.
char * Util_convertBdAddr2Str(uint8_t *pAddr)
Convert Bluetooth address to string. Only needed when LCD display is used.
void Util_stopClock(Clock_Struct *pClock)
Stop a clock.
void Util_restartClock(Clock_Struct *pClock, uint32_t clockTimeout)
Restart a clock by changing the timeout.
Clock_Handle Util_constructClock(Clock_Struct *pClock, Clock_FuncPtr clockCB, uint32_t clockDuration, uint32_t clockPeriod, uint8_t startFlag, UArg arg)
Initialize a TIRTOS Clock instance.
Queue_Handle Util_constructQueue(Queue_Struct *pQueue)
Initialize an RTOS queue to hold messages from profile to be processed.
bool Util_isActive(Clock_Struct *pClock)
Determine if a clock is currently active.
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale