TI BLE5-Stack API Documentation  9.14.00
osal.h
Go to the documentation of this file.
1 /******************************************************************************
2 
3  Group: WCS, LPC, BTS
4  $Target Device: DEVICES $
5 
6  ******************************************************************************
7  $License: BSD3 2004 $
8  ******************************************************************************
9  $Release Name: PACKAGE NAME $
10  $Release Date: PACKAGE RELEASE DATE $
11  *****************************************************************************/
12 
21 #ifndef OSAL_H
22 #define OSAL_H
23 
24 #ifdef __cplusplus
25 extern "C"
26 {
27 #endif
28 
29 /*********************************************************************
30  * INCLUDES
31  */
32 
33 #include <limits.h>
34 
38 #include "ti/ble/stack_util/osal/osal_timers.h"
39 
41 
42 /*********************************************************************
43  * MACROS
44  */
46 #if ( UINT_MAX == 65535 ) /* 8-bit and 16-bit devices */
47  #define osal_offsetof(type, member) ((uint16) &(((type *) 0)->member))
48 #else /* 32-bit devices */
49  #define osal_offsetof(type, member) ((uint32) &(((type *) 0)->member))
50 #endif
51 
52 #define OSAL_MSG_NEXT(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->next
53 
54 #define OSAL_MSG_Q_INIT(q_ptr) *(q_ptr) = NULL
55 
56 #define OSAL_MSG_Q_EMPTY(q_ptr) (*(q_ptr) == NULL)
57 
58 #define OSAL_MSG_Q_HEAD(q_ptr) (*(q_ptr))
59 
60 #define OSAL_MSG_LEN(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->len
61 
62 #define OSAL_MSG_ID(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->dest_id
63 /*********************************************************************
65  * CONSTANTS
66  */
67 
68 
69 // LL Events
70 #define LL_EVT_NONE 0x00000000u
71 #define LL_EVT_POST_PROCESS_RF 0x00000001u
72 #define LL_EVT_INIT_LAST_CMD_DONE 0x00000002u
73 #define LL_EVT_INIT_LAST_CMD_DONE_RX_ERR 0x00000004u
74 #define LL_EVT_CENTRAL_CONN_CREATED 0x00000008u
75 #define LL_EVT_CENTRAL_CONN_CANCELLED 0x00000010u
76 #define LL_EVT_EXT_SCAN_TIMEOUT 0x00000020u
77 #define LL_EVT_EXT_ADV_TIMEOUT 0x00000040u
78 #define LL_EVT_INIT_LAST_CMD_DONE_CONNECT 0x00000080u
79 #define LL_EVT_RESET_SYSTEM_HARD 0x00000200u
80 #define LL_EVT_RESET_SYSTEM_SOFT 0x00000400u
81 #define LL_EVT_CONN_DISCONNECTED_IMMED 0x00000800u
82 #define LL_EVT_ADDRESS_RESOLUTION_TIMEOUT 0x00001000u
83 #define LL_EVT_INIT_DONE 0x00002000u
84 #define LL_EVT_OUT_OF_MEMORY 0x00004000u
85 #define LL_EVT_CONN_RX_AVAIL 0x00008000u
86 #define LL_EVT_ADV_LAST_CMD_DONE 0x00010000u
87 #define LL_EVT_SCAN_LAST_CMD_DONE 0x00020000u
88 #define LL_EVT_CONNECTION_LAST_CMD_DONE 0x00040000u
89 #define LL_EVT_SCAN_RX_AVAIL 0x00080000u
90 
91 // Periodic Scanner + PAwR events family
92 #define LL_EVT_PERIODIC_SCANNER 0x00100000u
93 #define LL_EVT_PERIODIC_SCAN_LAST_CMD_DONE (LL_EVT_PERIODIC_SCANNER | 1 << 0)
94 #define LL_EVT_PERIODIC_SCAN_RX_AVAIL (LL_EVT_PERIODIC_SCANNER | 1 << 1)
95 #define LL_EVT_PAWR_RSP_DATA_LAST_CMD_DONE (LL_EVT_PERIODIC_SCANNER | 1 << 2)
96 #define LL_EVT_PERIODIC_SCAN_CANCELLED (LL_EVT_PERIODIC_SCANNER | 1 << 3)
97 
98 #define LL_EVT_RESCHEDULE 0x00400000u
99 #define LL_EVT_CMD_STARTED 0x00800000u
100 #define LL_EVT_PERIODIC_ADV_LAST_CMD_DONE 0x01000000u
101 #define LL_EVT_PERIODIC_ADV_TX_BUFF_FINISHED 0x02000000u
102 #define LL_EVT_CONN_TX_BUFF_FINISHED 0x04000000u
103 #define LL_EVT_ADV_RX_AVAIL 0x08000000u
104 #define LL_EVT_ADV_TX_BUFF_FINISHED 0x10000000u
105 #define LL_EVT_INIT_RX_ENTRY_DONE 0x20000000u
106 
107 // CS Events Family. It is assumed that those events can be received ONLY when CS is active,
108 // and all the LL events were already processed.
109 #define LL_EVT_CS 0x40000000u
110 #define LL_EVT_CS_ERROR_POST_PROCESS (LL_EVT_CS | 1 << 0)
111 #define LL_EVT_CS_SUBEVENT_POST_PROCESS (LL_EVT_CS | 1 << 1)
112 #define LL_EVT_CS_STEPS_POST_PROCESS (LL_EVT_CS | 1 << 2)
113 #define LL_EVT_CS_RESULTS_POST_PROCESS (LL_EVT_CS | 1 << 3)
114 #define LL_EVT_CS_PRECAL_POST_PROCESS (LL_EVT_CS | 1 << 4)
115 #define LL_EVT_CS_NEXT_SUBEVENT_PROCESS (LL_EVT_CS | 1 << 5)
116 #define LL_EVT_CS_CURRENT_SUBEVENT_CONT_PROCESS (LL_EVT_CS | 1 << 6)
117 
118 #define SYS_EVENT_MSG 0x80000000u
119 
120 #define SYS_RESERVED SYS_EVENT_MSG
121 
122 /*** Interrupts ***/
123 #define INTS_ALL 0xFF
124 
125 /*********************************************************************
126  * TYPEDEFS
127  */
128 typedef ICall_MsgHdr osal_msg_hdr_t;
130 
131 typedef void * osal_msg_q_t;
132 
134 typedef void (*osal_highres_timer_cback_t)(void *arg);
135 
137 typedef void (*osal_icallMsg_hook_t)(void * param);
138 
139 /*********************************************************************
140  * GLOBAL VARIABLES
141  */
142 #ifdef ICALL_EVENTS
144 #else /* !ICALL_EVENTS */
145 extern ICall_Semaphore osal_semaphore;
146 #endif /* ICALL_EVENTS */
148 extern uint_least32_t osal_tickperiod;
149 extern void (*osal_eventloop_hook)(void);
150 
151 
152 /*********************************************************************
153  * FUNCTIONS
154  */
155 
157 /*** Message Management ***/
158 
178  extern uint8 * osal_msg_allocate(uint16 len );
179 
201  extern uint8 * osal_msg_allocateLimited(uint16 len );
202 
215  extern uint8 osal_msg_deallocate( uint8 *msg_ptr );
216 
234  extern uint8 osal_msg_send( uint8 destination_task, uint8 *msg_ptr );
235 
254  extern uint8 osal_service_complete( uint8 destination_task, uint8 *msg_ptr );
255 
272  extern uint8 osal_msg_push_front( uint8 destination_task, uint8 *msg_ptr );
273 
286  extern uint8 *osal_msg_receive( uint8 task_id );
287 
297  extern osal_event_hdr_t *osal_msg_find(uint8 task_id, uint8 event);
298 
309  extern uint8 osal_msg_count(uint8 task_id, uint8 event);
310 
317  extern void osal_msg_enqueue( osal_msg_q_t *q_ptr, void *msg_ptr );
318 
330  extern uint8 osal_msg_enqueue_max( osal_msg_q_t *q_ptr, void *msg_ptr, uint8 max );
331 
340  extern void *osal_msg_dequeue( osal_msg_q_t *q_ptr );
341 
348  extern void osal_msg_push( osal_msg_q_t *q_ptr, void *msg_ptr );
349 
358  extern void osal_msg_extract( osal_msg_q_t *q_ptr, void *msg_ptr, void *prev_ptr );
359 
367  extern ICall_Errno osal_service_entry(ICall_FuncArgsHdr *args);
368 
369 
370 /*** Task Synchronization ***/
371 
385  extern uint8 osal_set_event( uint8 task_id, uint32 event_flag );
386 
387 
399  extern uint8 osal_clear_event( uint8 task_id, uint32 event_flag );
400 
401 /*** Task Management ***/
402 
410  extern void osal_enroll_dispatchid(uint8 taskid,
411  ICall_EntityID dispatchid);
412 
426  extern void osal_enroll_senderid(uint8 taskid, ICall_EntityID dispatchid);
427 
436  extern void osal_enroll_notasksender(ICall_EntityID dispatchid);
437 
444  void osal_timer_init(uint_least32_t tickPeriod, uint_least32_t osalMaxMsecs);
445 
452  extern uint8 osal_init_system( void );
453 
454  /*
455  * System Processing Loop
456  */
462  extern void osal_start_system( void );
463 
472  extern void osal_run_system( void );
473 
480  extern uint8 osal_self( void );
481 
483 
484 /*** Helper Functions ***/
485 
495  extern int osal_strlen( char *pString );
496 
510  extern void *osal_memcpy( void *dst, const void GENERIC *src, unsigned int len);
511 
524  extern void *osal_memdup( const void GENERIC *src, unsigned int len );
525 
543  extern void *osal_revmemcpy( void *dst, const void GENERIC *src, unsigned int len);
544 
555  extern uint8 osal_memcmp( const void GENERIC *src1, const void GENERIC *src2, unsigned int len );
556 
566  extern void *osal_memset( void *dest, uint8 value, int size );
567 
575  extern uint16 osal_build_uint16( uint8 *swapped );
576 
585  extern uint32_t osal_build_uint32( uint8 *swapped, uint8 len );
586 
592  extern uint16 osal_rand( void );
593 
602  extern uint8* osal_buffer_uint32( uint8 *buf, uint32 val );
603 
614  extern uint8 osal_isbufset( uint8 *buf, uint8 val, uint8 len );
615 
622  extern void osal_set_icall_hook( osal_icallMsg_hook_t param );
623 
631  extern uint8 osal_alien2proxy(ICall_EntityID entity);
632 
633 /*********************************************************************
634 *********************************************************************/
635 
636 #ifdef __cplusplus
637 }
638 #endif
639 
640 #endif /* OSAL_H */
int osal_strlen(char *pString)
Calculates the length of a string.
void * ICall_SyncHandle
Synchronization object data type.
Definition: icall.h:431
int_fast16_t ICall_Errno
Error code data type.
Definition: icall.h:419
Common Defines.
void * osal_memset(void *dest, uint8 value, int size)
Set memory buffer to value.
uint8 * osal_buffer_uint32(uint8 *buf, uint32 val)
Buffer an uint32 value - LSB first.
uint8 osal_memcmp(const void GENERIC *src1, const void GENERIC *src2, unsigned int len)
Generic memory compare.
ICall_MsgHdr osal_msg_hdr_t
ICall Message header.
Definition: osal.h:128
void(* osal_eventloop_hook)(void)
OSAL event loop hook.
Common service function arguments.
Definition: icall.h:475
uint16 osal_build_uint16(uint8 *swapped)
Build a uint16 out of 2 bytes (0 then 1).
void * osal_msg_q_t
osal message queue
Definition: osal.h:131
uint8 osal_isbufset(uint8 *buf, uint8 val, uint8 len)
Check if all of the array elements are set to a value.
uint8 osal_alien2proxy(ICall_EntityID entity)
Assign or retrieve a proxy OSAL task id for an external ICall entity.
void osal_set_icall_hook(osal_icallMsg_hook_t param)
Set the hook used to parse icall message.
event_hdr_t osal_event_hdr_t
OSAL Event header.
Definition: osal.h:129
Type definitions and macros for BLE stack.
his module defines the OSAL memory control functions.
ICall_EntityID osal_entity
OSAL entity.
void(* osal_highres_timer_cback_t)(void *arg)
High resolution timer callback function type.
Definition: osal.h:134
Generic Event Header.
Definition: bcomdef.h:223
ICall_SyncHandle osal_syncHandle
OSAL synchronization handle.
ICall layer interface.
uint_least32_t osal_tickperiod
OSAL ticket period.
void * ICall_Semaphore
Semaphore used for ICall.
Definition: icall.h:437
uint32_t osal_build_uint32(uint8 *swapped, uint8 len)
Build a uint32 out of sequential bytes.
void(* osal_icallMsg_hook_t)(void *param)
ICall Message hook.
Definition: osal.h:137
uint16 osal_rand(void)
Random number generator.
uint_least8_t ICall_EntityID
Entity id data type.
Definition: icall.h:445
void * osal_memcpy(void *dst, const void GENERIC *src, unsigned int len)
Generic memory copy.
void * osal_revmemcpy(void *dst, const void GENERIC *src, unsigned int len)
Generic reverse memory copy.
void * osal_memdup(const void GENERIC *src, unsigned int len)
Allocates a buffer and copies the src buffer into the newly allocated space.
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale