TI BLE Stack API Documentation  2.03.09
osal.h
1 /******************************************************************************
2 
3  @file osal.h
4 
5  @brief This API allows the software components in the Z-Stack to be written
6  independently of the specifics of the operating system, kernel, or
7  tasking environment (including control loops or connect-to-interrupt
8  systems).
9 
10  Group: WCS, LPC, BTS
11  $Target Device: DEVICES $
12 
13  ******************************************************************************
14  $License: BSD3 2004 $
15  ******************************************************************************
16  $Release Name: PACKAGE NAME $
17  $Release Date: PACKAGE RELEASE DATE $
18  *****************************************************************************/
19 
20 #ifndef OSAL_H
21 #define OSAL_H
22 
23 #ifdef __cplusplus
24 extern "C"
25 {
26 #endif
27 
28 /*********************************************************************
29  * INCLUDES
30  */
31 
32 #include <limits.h>
33 
34 #include "comdef.h"
35 #include "osal_memory.h"
36 #include "osal_timers.h"
37 
38 #ifdef USE_ICALL
39 #include <icall.h>
40 #endif /* USE_ICALL */
41 
42 /*********************************************************************
43  * MACROS
44  */
45 #if ( UINT_MAX == 65535 ) /* 8-bit and 16-bit devices */
46  #define osal_offsetof(type, member) ((uint16) &(((type *) 0)->member))
47 #else /* 32-bit devices */
48  #define osal_offsetof(type, member) ((uint32) &(((type *) 0)->member))
49 #endif
50 
51 #define OSAL_MSG_NEXT(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->next
52 
53 #define OSAL_MSG_Q_INIT(q_ptr) *(q_ptr) = NULL
54 
55 #define OSAL_MSG_Q_EMPTY(q_ptr) (*(q_ptr) == NULL)
56 
57 #define OSAL_MSG_Q_HEAD(q_ptr) (*(q_ptr))
58 
59 #define OSAL_MSG_LEN(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->len
60 
61 #define OSAL_MSG_ID(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->dest_id
62 
63 /*********************************************************************
64  * CONSTANTS
65  */
66 
67 /*** Interrupts ***/
68 #define INTS_ALL 0xFF
69 
70 /*********************************************************************
71  * TYPEDEFS
72  */
73 #ifdef USE_ICALL
75 #else /* USE_ICALL */
76 typedef struct
77 {
78  void *next;
79 #ifdef OSAL_PORT2TIRTOS
80  /* Limited OSAL port to TI-RTOS requires compatibility with ROM
81  * code compiled with USE_ICALL compile flag. */
82  uint32 reserved;
83 #endif /* OSAL_PORT2TIRTOS */
84  uint16 len;
85  uint8 dest_id;
86 } osal_msg_hdr_t;
87 #endif /* USE_ICALL */
88 
89 typedef struct
90 {
91  uint8 event;
92  uint8 status;
94 
95 typedef void * osal_msg_q_t;
96 
97 #ifdef USE_ICALL
98 /* High resolution timer callback function type */
99 typedef void (*osal_highres_timer_cback_t)(void *arg);
100 #endif /* USE_ICALL */
101 
102 #ifdef ICALL_SLIM
103 typedef void (*osal_icallMsg_hook_t)(void * param);
104 #endif /* ICALL_SLIM */
105 
106 /*********************************************************************
107  * GLOBAL VARIABLES
108  */
109 #ifdef USE_ICALL
110 #ifdef ICALL_EVENTS
111 extern ICall_SyncHandle osal_syncHandle;
112 #else /* !ICALL_EVENTS */
113 extern ICall_Semaphore osal_semaphore;
114 #endif /* ICALL_EVENTS */
115 extern ICall_EntityID osal_entity;
116 extern uint_least32_t osal_tickperiod;
117 extern void (*osal_eventloop_hook)(void);
118 #endif /* USE_ICALL */
119 
120 
121 /*********************************************************************
122  * FUNCTIONS
123  */
124 
125 /*** Message Management ***/
126 
127  /*
128  * Task Message Allocation
129  */
130  extern uint8 * osal_msg_allocate(uint16 len );
131 
132  /*
133  * Task Message Deallocation
134  */
135  extern uint8 osal_msg_deallocate( uint8 *msg_ptr );
136 
137  /*
138  * Send a Task Message
139  */
140  extern uint8 osal_msg_send( uint8 destination_task, uint8 *msg_ptr );
141 
142  /*
143  * Push a Task Message to head of queue
144  */
145  extern uint8 osal_msg_push_front( uint8 destination_task, uint8 *msg_ptr );
146 
147  /*
148  * Receive a Task Message
149  */
150  extern uint8 *osal_msg_receive( uint8 task_id );
151 
152  /*
153  * Find in place a matching Task Message / Event.
154  */
155  extern osal_event_hdr_t *osal_msg_find(uint8 task_id, uint8 event);
156 
157  /*
158  * Count the number of queued OSAL messages matching Task ID / Event.
159  */
160  extern uint8 osal_msg_count(uint8 task_id, uint8 event);
161 
162  /*
163  * Enqueue a Task Message
164  */
165  extern void osal_msg_enqueue( osal_msg_q_t *q_ptr, void *msg_ptr );
166 
167  /*
168  * Enqueue a Task Message Up to Max
169  */
170  extern uint8 osal_msg_enqueue_max( osal_msg_q_t *q_ptr, void *msg_ptr, uint8 max );
171 
172  /*
173  * Dequeue a Task Message
174  */
175  extern void *osal_msg_dequeue( osal_msg_q_t *q_ptr );
176 
177  /*
178  * Push a Task Message to head of queue
179  */
180  extern void osal_msg_push( osal_msg_q_t *q_ptr, void *msg_ptr );
181 
182  /*
183  * Extract and remove a Task Message from queue
184  */
185  extern void osal_msg_extract( osal_msg_q_t *q_ptr, void *msg_ptr, void *prev_ptr );
186 
187 #ifdef USE_ICALL
188  extern ICall_Errno osal_service_entry(ICall_FuncArgsHdr *args);
189 #endif /* USE_ICALL */
190 
191 
192 /*** Task Synchronization ***/
193 
194  /*
195  * Set a Task Event
196  */
197  extern uint8 osal_set_event( uint8 task_id, uint16 event_flag );
198 
199 
200  /*
201  * Clear a Task Event
202  */
203  extern uint8 osal_clear_event( uint8 task_id, uint16 event_flag );
204 
205 
206 /*** Interrupt Management ***/
207 
208  /*
209  * Register Interrupt Service Routine (ISR)
210  */
211  extern uint8 osal_isr_register( uint8 interrupt_id, void (*isr_ptr)( uint8* ) );
212 
213  /*
214  * Enable Interrupt
215  */
216  extern uint8 osal_int_enable( uint8 interrupt_id );
217 
218  /*
219  * Disable Interrupt
220  */
221  extern uint8 osal_int_disable( uint8 interrupt_id );
222 
223 
224 /*** Task Management ***/
225 
226 #ifdef USE_ICALL
227  /*
228  * Enroll dispatcher registered entity ID
229  */
230  extern void osal_enroll_dispatchid(uint8 taskid,
231  ICall_EntityID dispatchid);
232 
233  /*
234  * Enroll an OSAL task to use another OSAL task's enrolled entity ID
235  * when sending a message.
236  */
237  extern void osal_enroll_senderid(uint8 taskid, ICall_EntityID dispatchid);
238 
239  /*
240  * Enroll entity ID to be used as sender entity ID for non OSAL task
241  */
242  extern void osal_enroll_notasksender(ICall_EntityID dispatchid);
243 
244 #ifdef ICALL_JT
245  /*
246  * Initialize osal timer module variable at init,
247  * based on parameter send by the application.
248  */
249  void osal_timer_init(uint_least32_t tickPeriod, uint_least32_t osalMaxMsecs);
250 #endif /* ICALL_JT */
251 
252 #endif /* USE_ICALL */
253 
254  /*
255  * Initialize the Task System
256  */
257  extern uint8 osal_init_system( void );
258 
259  /*
260  * System Processing Loop
261  */
262 #if defined (ZBIT)
263  extern __declspec(dllexport) void osal_start_system( void );
264 #else
265  extern void osal_start_system( void );
266 #endif
267 
268  /*
269  * One Pass Through the OSAL Processing Loop
270  */
271  extern void osal_run_system( void );
272 
273  /*
274  * Get the active task ID
275  */
276  extern uint8 osal_self( void );
277 
278 
279 /*** Helper Functions ***/
280 
281  /*
282  * String Length
283  */
284  extern int osal_strlen( char *pString );
285 
286  /*
287  * Memory copy
288  */
289  extern void *osal_memcpy( void*, const void GENERIC *, unsigned int );
290 
291  /*
292  * Memory Duplicate - allocates and copies
293  */
294  extern void *osal_memdup( const void GENERIC *src, unsigned int len );
295 
296  /*
297  * Reverse Memory copy
298  */
299  extern void *osal_revmemcpy( void*, const void GENERIC *, unsigned int );
300 
301  /*
302  * Memory compare
303  */
304  extern uint8 osal_memcmp( const void GENERIC *src1, const void GENERIC *src2, unsigned int len );
305 
306  /*
307  * Memory set
308  */
309  extern void *osal_memset( void *dest, uint8 value, int len );
310 
311  /*
312  * Build a uint16 out of 2 bytes (0 then 1).
313  */
314  extern uint16 osal_build_uint16( uint8 *swapped );
315 
316  /*
317  * Build a uint32 out of sequential bytes.
318  */
319  extern uint32 osal_build_uint32( uint8 *swapped, uint8 len );
320 
321  /*
322  * Convert long to ascii string
323  */
324  #if !defined ( ZBIT ) && !defined ( ZBIT2 ) && !defined (UBIT)
325  extern uint8 *_ltoa( uint32 l, uint8 * buf, uint8 radix );
326  #endif
327 
328  /*
329  * Random number generator
330  */
331  extern uint16 osal_rand( void );
332 
333  /*
334  * Buffer an uint32 value - LSB first.
335  */
336  extern uint8* osal_buffer_uint32( uint8 *buf, uint32 val );
337 
338  /*
339  * Buffer an uint24 value - LSB first
340  */
341  extern uint8* osal_buffer_uint24( uint8 *buf, uint24 val );
342 
343  /*
344  * Is all of the array elements set to a value?
345  */
346  extern uint8 osal_isbufset( uint8 *buf, uint8 val, uint8 len );
347 
348 #ifdef ICALL_SLIM
349  /*
350  * set teh callback to parse icall slim message.
351  */
352  extern void osal_set_icall_hook( osal_icallMsg_hook_t *param );
353 
354  /*
355  * translate alien task Id to osal task id.
356  */
357  extern uint8 osal_alien2proxy(ICall_EntityID entity);
358 
359 #endif /* ICALL_SLIM */
360 
361 /*********************************************************************
362 *********************************************************************/
363 
364 #ifdef __cplusplus
365 }
366 #endif
367 
368 #endif /* OSAL_H */
Definition: icall.h:759
Definition: icall.h:429
Definition: osal.h:76
Definition: osal.h:89