TI BLE5-Stack API Documentation  9.11.01
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 
37 #include "ti/ble/stack_util/osal/osal_timers.h"
38 
40 
41 /*********************************************************************
42  * MACROS
43  */
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 /*********************************************************************
64  * CONSTANTS
65  */
66 
67 
68 // LL Events
69 #define LL_EVT_NONE 0x00000000u
70 #define LL_EVT_POST_PROCESS_RF 0x00000001u
71 #define LL_EVT_INIT_LAST_CMD_DONE 0x00000002u
72 #define LL_EVT_INIT_LAST_CMD_DONE_RX_ERR 0x00000004u
73 #define LL_EVT_CENTRAL_CONN_CREATED 0x00000008u
74 #define LL_EVT_CENTRAL_CONN_CANCELLED 0x00000010u
75 #define LL_EVT_EXT_SCAN_TIMEOUT 0x00000020u
76 #define LL_EVT_EXT_ADV_TIMEOUT 0x00000040u
77 #define LL_EVT_INIT_LAST_CMD_DONE_CONNECT 0x00000080u
78 #define LL_EVT_PERIODIC_SCAN_CANCELLED 0x00000100u
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 #define LL_EVT_PERIODIC_SCAN_LAST_CMD_DONE 0x00100000u
91 #define LL_EVT_PERIODIC_SCAN_RX_AVAIL 0x00200000u
92 #define LL_EVT_RESCHEDULE 0x00400000u
93 #define LL_EVT_CMD_STARTED 0x00800000u
94 #define LL_EVT_PERIODIC_ADV_LAST_CMD_DONE 0x01000000u
95 #define LL_EVT_PERIODIC_ADV_TX_BUFF_FINISHED 0x02000000u
96 #define LL_EVT_CONN_TX_BUFF_FINISHED 0x04000000u
97 #define LL_EVT_ADV_RX_AVAIL 0x08000000u
98 #define LL_EVT_ADV_TX_BUFF_FINISHED 0x10000000u
99 #define LL_EVT_INIT_RX_ENTRY_DONE 0x20000000u
100 // CS Events Family. It is assumed that those events can be received ONLY when CS is active,
101 // and all the LL events were already processed.
102 #define LL_EVT_CS 0x40000000u
103 #define LL_EVT_CS_ERROR_POST_PROCESS (LL_EVT_CS | 1 << 0)
104 #define LL_EVT_CS_SUBEVENT_POST_PROCESS (LL_EVT_CS | 1 << 1)
105 #define LL_EVT_CS_STEPS_POST_PROCESS (LL_EVT_CS | 1 << 2)
106 #define LL_EVT_CS_RESULTS_POST_PROCESS (LL_EVT_CS | 1 << 3)
107 #define LL_EVT_CS_PRECAL_POST_PROCESS (LL_EVT_CS | 1 << 4)
108 #define LL_EVT_CS_NEXT_SUBEVENT_PROCESS (LL_EVT_CS | 1 << 5)
109 #define LL_EVT_CS_CURRENT_SUBEVENT_CONT_PROCESS (LL_EVT_CS | 1 << 6)
110 
111 #define SYS_EVENT_MSG 0x80000000u
112 
113 #define SYS_RESERVED SYS_EVENT_MSG
114 
115 /*** Interrupts ***/
116 #define INTS_ALL 0xFF
117 
118 /*********************************************************************
119  * TYPEDEFS
120  */
121 typedef ICall_MsgHdr osal_msg_hdr_t;
122 
124 typedef struct
125 {
126  uint8 event;
127  uint8 status;
129 
130 typedef void * osal_msg_q_t;
131 
133 typedef void (*osal_highres_timer_cback_t)(void *arg);
134 
136 typedef void (*osal_icallMsg_hook_t)(void * param);
137 
138 /*********************************************************************
139  * GLOBAL VARIABLES
140  */
141 #ifdef ICALL_EVENTS
143 #else /* !ICALL_EVENTS */
144 extern ICall_Semaphore osal_semaphore;
145 #endif /* ICALL_EVENTS */
147 extern uint_least32_t osal_tickperiod;
148 extern void (*osal_eventloop_hook)(void);
149 
150 
151 /*********************************************************************
152  * FUNCTIONS
153  */
154 
156 /*** Message Management ***/
157 
177  extern uint8 * osal_msg_allocate(uint16 len );
178 
200  extern uint8 * osal_msg_allocateLimited(uint16 len );
201 
214  extern uint8 osal_msg_deallocate( uint8 *msg_ptr );
215 
233  extern uint8 osal_msg_send( uint8 destination_task, uint8 *msg_ptr );
234 
253  extern uint8 osal_service_complete( uint8 destination_task, uint8 *msg_ptr );
254 
271  extern uint8 osal_msg_push_front( uint8 destination_task, uint8 *msg_ptr );
272 
285  extern uint8 *osal_msg_receive( uint8 task_id );
286 
296  extern osal_event_hdr_t *osal_msg_find(uint8 task_id, uint8 event);
297 
308  extern uint8 osal_msg_count(uint8 task_id, uint8 event);
309 
316  extern void osal_msg_enqueue( osal_msg_q_t *q_ptr, void *msg_ptr );
317 
329  extern uint8 osal_msg_enqueue_max( osal_msg_q_t *q_ptr, void *msg_ptr, uint8 max );
330 
339  extern void *osal_msg_dequeue( osal_msg_q_t *q_ptr );
340 
347  extern void osal_msg_push( osal_msg_q_t *q_ptr, void *msg_ptr );
348 
357  extern void osal_msg_extract( osal_msg_q_t *q_ptr, void *msg_ptr, void *prev_ptr );
358 
366  extern ICall_Errno osal_service_entry(ICall_FuncArgsHdr *args);
367 
368 
369 /*** Task Synchronization ***/
370 
384  extern uint8 osal_set_event( uint8 task_id, uint32 event_flag );
385 
386 
398  extern uint8 osal_clear_event( uint8 task_id, uint32 event_flag );
399 
400 /*** Task Management ***/
401 
409  extern void osal_enroll_dispatchid(uint8 taskid,
410  ICall_EntityID dispatchid);
411 
425  extern void osal_enroll_senderid(uint8 taskid, ICall_EntityID dispatchid);
426 
435  extern void osal_enroll_notasksender(ICall_EntityID dispatchid);
436 
443  void osal_timer_init(uint_least32_t tickPeriod, uint_least32_t osalMaxMsecs);
444 
451  extern uint8 osal_init_system( void );
452 
453  /*
454  * System Processing Loop
455  */
461  extern void osal_start_system( void );
462 
471  extern void osal_run_system( void );
472 
479  extern uint8 osal_self( void );
480 
482 
483 /*** Helper Functions ***/
484 
494  extern int osal_strlen( char *pString );
495 
509  extern void *osal_memcpy( void *dst, const void GENERIC *src, unsigned int len);
510 
523  extern void *osal_memdup( const void GENERIC *src, unsigned int len );
524 
542  extern void *osal_revmemcpy( void *dst, const void GENERIC *src, unsigned int len);
543 
554  extern uint8 osal_memcmp( const void GENERIC *src1, const void GENERIC *src2, unsigned int len );
555 
565  extern void *osal_memset( void *dest, uint8 value, int size );
566 
574  extern uint16 osal_build_uint16( uint8 *swapped );
575 
584  extern uint32_t osal_build_uint32( uint8 *swapped, uint8 len );
585 
591  extern uint16 osal_rand( void );
592 
601  extern uint8* osal_buffer_uint32( uint8 *buf, uint32 val );
602 
613  extern uint8 osal_isbufset( uint8 *buf, uint8 val, uint8 len );
614 
621  extern void osal_set_icall_hook( osal_icallMsg_hook_t param );
622 
630  extern uint8 osal_alien2proxy(ICall_EntityID entity);
631 
632 #define BLE_LOG_INT_INT(handle, type, format, param1, param2)
633 #define BLE_LOG_INT_STR(handle, type, format, param1, param2)
634 #define BLE_LOG_INT_TIME(handle, type, start_str, param1)
635 
636 
637 /*********************************************************************
638 *********************************************************************/
639 
640 #ifdef __cplusplus
641 }
642 #endif
643 
644 #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.
uint8 event
OSAL event.
Definition: osal.h:126
ICall_MsgHdr osal_msg_hdr_t
ICall Message header.
Definition: osal.h:121
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).
uint8 status
event status
Definition: osal.h:127
void * osal_msg_q_t
osal message queue
Definition: osal.h:130
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.
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:133
OSAL Event Header.
Definition: osal.h:124
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:136
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