TI BLE-Stack for Bluetooth 4.2 API Documentation  3.01.00.07
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 
35 #include "comdef.h"
36 #include "osal_memory.h"
37 #include "osal_timers.h"
38 
39 #ifdef USE_ICALL
40 #include <icall.h>
41 #endif /* USE_ICALL */
42 
43 /*********************************************************************
44  * MACROS
45  */
47 #if ( UINT_MAX == 65535 ) /* 8-bit and 16-bit devices */
48  #define osal_offsetof(type, member) ((uint16) &(((type *) 0)->member))
49 #else /* 32-bit devices */
50  #define osal_offsetof(type, member) ((uint32) &(((type *) 0)->member))
51 #endif
52 
53 #define OSAL_MSG_NEXT(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->next
54 
55 #define OSAL_MSG_Q_INIT(q_ptr) *(q_ptr) = NULL
56 
57 #define OSAL_MSG_Q_EMPTY(q_ptr) (*(q_ptr) == NULL)
58 
59 #define OSAL_MSG_Q_HEAD(q_ptr) (*(q_ptr))
60 
61 #define OSAL_MSG_LEN(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->len
62 
63 #define OSAL_MSG_ID(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->dest_id
64 /*********************************************************************
66  * CONSTANTS
67  */
68 
69 /*** Interrupts ***/
70 #define INTS_ALL 0xFF
71 
72 /*********************************************************************
73  * TYPEDEFS
74  */
75 #ifdef USE_ICALL
76 typedef ICall_MsgHdr osal_msg_hdr_t;
77 #else /* USE_ICALL */
78 typedef struct
79 {
80  void *next;
81 #ifdef OSAL_PORT2TIRTOS
82  /* Limited OSAL port to TI-RTOS requires compatibility with ROM
83  * code compiled with USE_ICALL compile flag. */
84  uint32 reserved;
85 #endif /* OSAL_PORT2TIRTOS */
86  uint16 len;
87  uint8 dest_id;
88 } osal_msg_hdr_t;
89 #endif /* USE_ICALL */
90 
92 typedef struct
93 {
94  uint8 event;
95  uint8 status;
97 
98 typedef void * osal_msg_q_t;
99 
100 #ifdef USE_ICALL
101 
102 typedef void (*osal_highres_timer_cback_t)(void *arg);
103 #endif /* USE_ICALL */
104 
105 #ifdef ICALL_LITE
106 
107 typedef void (*osal_icallMsg_hook_t)(void * param);
108 #endif /* ICALL_LITE */
109 
110 /*********************************************************************
111  * GLOBAL VARIABLES
112  */
113 #ifdef USE_ICALL
114 #ifdef ICALL_EVENTS
115 extern ICall_SyncHandle osal_syncHandle;
116 #else /* !ICALL_EVENTS */
117 extern ICall_Semaphore osal_semaphore;
118 #endif /* ICALL_EVENTS */
119 extern ICall_EntityID osal_entity;
120 extern uint_least32_t osal_tickperiod;
121 extern void (*osal_eventloop_hook)(void);
122 #endif /* USE_ICALL */
123 
124 
125 /*********************************************************************
126  * FUNCTIONS
127  */
128 
130 /*** Message Management ***/
131 
151  extern uint8 * osal_msg_allocate(uint16 len );
152 
165  extern uint8 osal_msg_deallocate( uint8 *msg_ptr );
166 
184  extern uint8 osal_msg_send( uint8 destination_task, uint8 *msg_ptr );
185 
204  extern uint8 osal_service_complete( uint8 destination_task, uint8 *msg_ptr );
205 
222  extern uint8 osal_msg_push_front( uint8 destination_task, uint8 *msg_ptr );
223 
236  extern uint8 *osal_msg_receive( uint8 task_id );
237 
247  extern osal_event_hdr_t *osal_msg_find(uint8 task_id, uint8 event);
248 
259  extern uint8 osal_msg_count(uint8 task_id, uint8 event);
260 
267  extern void osal_msg_enqueue( osal_msg_q_t *q_ptr, void *msg_ptr );
268 
280  extern uint8 osal_msg_enqueue_max( osal_msg_q_t *q_ptr, void *msg_ptr, uint8 max );
281 
290  extern void *osal_msg_dequeue( osal_msg_q_t *q_ptr );
291 
298  extern void osal_msg_push( osal_msg_q_t *q_ptr, void *msg_ptr );
299 
308  extern void osal_msg_extract( osal_msg_q_t *q_ptr, void *msg_ptr, void *prev_ptr );
309 
310 #ifdef USE_ICALL
311 
318  extern ICall_Errno osal_service_entry(ICall_FuncArgsHdr *args);
319 #endif /* USE_ICALL */
320 
321 
322 /*** Task Synchronization ***/
323 
337  extern uint8 osal_set_event( uint8 task_id, uint16 event_flag );
338 
339 
351  extern uint8 osal_clear_event( uint8 task_id, uint16 event_flag );
352 
353 
354 /*** Interrupt Management ***/
355 
367  extern uint8 osal_isr_register( uint8 interrupt_id, void (*isr_ptr)( uint8* ) );
368 
384  extern uint8 osal_int_enable( uint8 interrupt_id );
385 
400  extern uint8 osal_int_disable( uint8 interrupt_id );
401 
402 
403 /*** Task Management ***/
404 
405 #ifdef USE_ICALL
406 
413  extern void osal_enroll_dispatchid(uint8 taskid,
414  ICall_EntityID dispatchid);
415 
429  extern void osal_enroll_senderid(uint8 taskid, ICall_EntityID dispatchid);
430 
439  extern void osal_enroll_notasksender(ICall_EntityID dispatchid);
440 
441 #ifdef ICALL_JT
442 
448  void osal_timer_init(uint_least32_t tickPeriod, uint_least32_t osalMaxMsecs);
449 #endif /* ICALL_JT */
450 
451 #endif /* USE_ICALL */
452 
459  extern uint8 osal_init_system( void );
460 
461  /*
462  * System Processing Loop
463  */
470 #if defined (ZBIT)
471  extern __declspec(dllexport) void osal_start_system( void );
472 #else
473  extern void osal_start_system( void );
474 #endif
475 
484  extern void osal_run_system( void );
485 
492  extern uint8 osal_self( void );
493 
495 
496 /*** Helper Functions ***/
497 
507  extern int osal_strlen( char *pString );
508 
522  extern void *osal_memcpy( void *dst, const void GENERIC *src, unsigned int len);
523 
536  extern void *osal_memdup( const void GENERIC *src, unsigned int len );
537 
555  extern void *osal_revmemcpy( void *dst, const void GENERIC *src, unsigned int len);
556 
567  extern uint8 osal_memcmp( const void GENERIC *src1, const void GENERIC *src2, unsigned int len );
568 
578  extern void *osal_memset( void *dest, uint8 value, int size );
579 
587  extern uint16 osal_build_uint16( uint8 *swapped );
588 
597  extern uint32 osal_build_uint32( uint8 *swapped, uint8 len );
598 
608  #if !defined ( ZBIT ) && !defined ( ZBIT2 ) && !defined (UBIT)
609  extern uint8 *_ltoa( uint32 l, uint8 * buf, uint8 radix );
610  #endif
611 
617  extern uint16 osal_rand( void );
618 
627  extern uint8* osal_buffer_uint32( uint8 *buf, uint32 val );
628 
639  extern uint8* osal_buffer_uint24( uint8 *buf, uint24 val );
640 
651  extern uint8 osal_isbufset( uint8 *buf, uint8 val, uint8 len );
652 
653 #ifdef ICALL_LITE
654 
660  extern void osal_set_icall_hook( osal_icallMsg_hook_t param );
661 
669  extern uint8 osal_alien2proxy(ICall_EntityID entity);
670 
671 #endif /* ICALL_LITE */
672 
673 /*********************************************************************
674 *********************************************************************/
675 
676 #ifdef __cplusplus
677 }
678 #endif
679 
680 #endif /* OSAL_H */
int osal_strlen(char *pString)
Calculates the length of a string.
void * ICall_SyncHandle
Synchronization object data type.
Definition: icall.h:438
int_fast16_t ICall_Errno
Error code data type.
Definition: icall.h:426
uint8 * osal_buffer_uint24(uint8 *buf, uint24 val)
Buffer an uint24 value - LSB first.
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:94
Common service function arguments.
Definition: icall.h:479
uint8 * _ltoa(uint32 l, uint8 *buf, uint8 radix)
Convert a long unsigned int to a string.
uint16 osal_build_uint16(uint8 *swapped)
Build a uint16 out of 2 bytes (0 then 1).
uint8 status
event status
Definition: osal.h:95
void * osal_msg_q_t
osal message queue
Definition: osal.h:98
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.
OSAL Event Header.
Definition: osal.h:92
ICall layer interface.
uint32 osal_build_uint32(uint8 *swapped, uint8 len)
Build a uint32 out of sequential bytes.
void * ICall_Semaphore
Semaphore used for ICall.
Definition: icall.h:441
void(* osal_icallMsg_hook_t)(void *param)
ICall Message hook.
Definition: osal.h:107
uint16 osal_rand(void)
Random number generator.
uint_least8_t ICall_EntityID
Entity id data type.
Definition: icall.h:449
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 2017, Texas Instruments Incorporated