TI BLE5-Stack API Documentation  3.02.01.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 (0x40000000)//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 struct Clock_Struct
84 {
85  timer_t clock;
86  void *cback;
87  uint32_t arg;
88  sigevent evnt;
89  pthread_attr_t timerThrdAttr;
90  struct itimerspec timeVal;
91  uint8_t isActive;
92 }Clock_Struct;
93 #endif
94 
95 typedef struct
96 {
97  uint16_t event; // Event type.
98  uint8_t state; // Event state;
99 }appEvtHdr_t;
100 
101 /*********************************************************************
102  * MACROS
103  */
104 
105 /*********************************************************************
106  * API FUNCTIONS
107  */
108 
122 #ifdef FREERTOS
123 void* Util_constructClock(Clock_Struct *entry, void *clockCB,
124  uint32_t clockDuration, uint32_t clockPeriod,
125  uint8_t startFlag, uint32_t arg);
126 
127 void Clock_destruct(Clock_Struct *structP);
128 #else
129 extern Clock_Handle Util_constructClock(Clock_Struct *pClock,
130  Clock_FuncPtr clockCB,
131  uint32_t clockDuration,
132  uint32_t clockPeriod,
133  uint8_t startFlag,
134  UArg arg);
135 #endif
136 
144 extern void Util_startClock(Clock_Struct *pClock);
145 
154 extern void Util_restartClock(Clock_Struct *pClock, uint32_t clockTimeout);
155 
163 extern bool Util_isActive(Clock_Struct *pClock);
164 
172 extern void Util_stopClock(Clock_Struct *pClock);
173 
181 extern void Util_rescheduleClock(Clock_Struct *pClock, uint32_t clockPeriod);
182 
191 #ifdef FREERTOS
192 extern void Util_constructQueue(mqd_t *pQueue);
193 #else
194 extern Queue_Handle Util_constructQueue(Queue_Struct *pQueue);
195 #endif
196 
209 #ifdef FREERTOS
210 uint8_t Util_enqueueMsg(mqd_t msgQueue,
211  Event_Handle event,
212  uint8_t *pMsg);
213 #else
214 
215 extern uint8_t Util_enqueueMsg(Queue_Handle msgQueue,
216  Event_Handle event,
217  uint8_t *pMsg);
218 #endif
219 
227 #ifdef FREERTOS
228 uint8_t *Util_dequeueMsg(mqd_t msgQueue);
229 #else
230 extern uint8_t *Util_dequeueMsg(Queue_Handle msgQueue);
231 #endif
232 
241 extern char *Util_convertBdAddr2Str(uint8_t *pAddr);
242 
252 extern uint8_t Util_isBufSet(uint8_t *pBuf, uint8_t pattern, uint16_t len);
253 
254 #ifdef FREERTOS
255 /*********************************************************************
256  * @fn Event_post
257  *
258  * @brief DPL that is used to signal events. If a task is waiting
259  * for the event and the event conditions are met, post()
260  * unblocks the task. If no tasks are waiting, post() simply
261  * registers the event with the event object and returns.
262  *
263  * @param eventQueue - handle of a event queue
264  * @param msg - mask of eventIds to post (must be non-zero)
265  */
266 extern void Event_post(mqd_t eventQueue, uint32_t msg);
267 #endif
268 
269 /*********************************************************************
270 *********************************************************************/
271 
272 #ifdef __cplusplus
273 }
274 #endif
275 
276 #endif /* UTIL_H */
277 
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