OSAL.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /**************************************************************************************************
  2. Filename: OSAL.h
  3. Revised: $Date: 2008-10-07 14:47:15 -0700 (Tue, 07 Oct 2008) $
  4. Revision: $Revision: 18212 $
  5. Description: This API allows the software components in the Z-stack to be written
  6. independently of the specifics of the operating system, kernel or tasking
  7. environment (including control loops or connect-to-interrupt systems).
  8. Copyright 2004-2007 Texas Instruments Incorporated. All rights reserved.
  9. IMPORTANT: Your use of this Software is limited to those specific rights
  10. granted under the terms of a software license agreement between the user
  11. who downloaded the software, his/her employer (which must be your employer)
  12. and Texas Instruments Incorporated (the "License"). You may not use this
  13. Software unless you agree to abide by the terms of the License. The License
  14. limits your use, and you acknowledge, that the Software may not be modified,
  15. copied or distributed unless embedded on a Texas Instruments microcontroller
  16. or used solely and exclusively in conjunction with a Texas Instruments radio
  17. frequency transceiver, which is integrated into your product. Other than for
  18. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  19. works of, modify, distribute, perform, display or sell this Software and/or
  20. its documentation for any purpose.
  21. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  22. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  23. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  24. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  25. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  26. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  27. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  28. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  29. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  30. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  31. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  32. Should you have any questions regarding your right to use this Software,
  33. contact Texas Instruments Incorporated at www.TI.com.
  34. **************************************************************************************************/
  35. #ifndef OSAL_H
  36. #define OSAL_H
  37. #ifdef __cplusplus
  38. extern "C"
  39. {
  40. #endif
  41. /*********************************************************************
  42. * INCLUDES
  43. */
  44. #include "comdef.h"
  45. #include "OSAL_Memory.h"
  46. #include "OSAL_Timers.h"
  47. /*********************************************************************
  48. * MACROS
  49. */
  50. #define osal_offsetof(type, member) ((uint16) &(((type *) 0)->member))
  51. #define OSAL_MSG_NEXT(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->next
  52. #define OSAL_MSG_Q_INIT(q_ptr) *(q_ptr) = NULL
  53. #define OSAL_MSG_Q_EMPTY(q_ptr) (*(q_ptr) == NULL)
  54. #define OSAL_MSG_Q_HEAD(q_ptr) (*(q_ptr))
  55. /*********************************************************************
  56. * CONSTANTS
  57. */
  58. /*** Interrupts ***/
  59. #define INTS_ALL 0xFF
  60. /*********************************************************************
  61. * TYPEDEFS
  62. */
  63. typedef struct
  64. {
  65. void *next;
  66. uint16 len;
  67. uint8 dest_id;
  68. } osal_msg_hdr_t;
  69. typedef struct
  70. {
  71. uint8 event;
  72. uint8 status;
  73. } osal_event_hdr_t;
  74. typedef void * osal_msg_q_t;
  75. /*********************************************************************
  76. * GLOBAL VARIABLES
  77. */
  78. /*********************************************************************
  79. * FUNCTIONS
  80. */
  81. /*** Message Management ***/
  82. /*
  83. * Task Message Allocation
  84. */
  85. extern uint8 * osal_msg_allocate(uint16 len );
  86. /*
  87. * Task Message Deallocation
  88. */
  89. extern uint8 osal_msg_deallocate( uint8 *msg_ptr );
  90. /*
  91. * Task Messages Count
  92. */
  93. extern uint16 osal_num_msgs( void );
  94. /*
  95. * Send a Task Message
  96. */
  97. extern uint8 osal_msg_send( uint8 destination_task, uint8 *msg_ptr );
  98. /*
  99. * Receive a Task Message
  100. */
  101. extern uint8 *osal_msg_receive( uint8 task_id );
  102. /*
  103. * Enqueue a Task Message
  104. */
  105. extern void osal_msg_enqueue( osal_msg_q_t *q_ptr, void *msg_ptr );
  106. /*
  107. * Enqueue a Task Message Up to Max
  108. */
  109. extern uint8 osal_msg_enqueue_max( osal_msg_q_t *q_ptr, void *msg_ptr, uint8 max );
  110. /*
  111. * Dequeue a Task Message
  112. */
  113. extern void *osal_msg_dequeue( osal_msg_q_t *q_ptr );
  114. /*
  115. * Push a Task Message to head of queue
  116. */
  117. extern void osal_msg_push( osal_msg_q_t *q_ptr, void *msg_ptr );
  118. /*
  119. * Extract and remove a Task Message from queue
  120. */
  121. extern void osal_msg_extract( osal_msg_q_t *q_ptr, void *msg_ptr, void *prev_ptr );
  122. /*** Task Synchronization ***/
  123. /*
  124. * Set a Task Event
  125. */
  126. extern uint8 osal_set_event( uint8 task_id, uint16 event_flag );
  127. /*** Interrupt Management ***/
  128. /*
  129. * Register Interrupt Service Routine (ISR)
  130. */
  131. extern uint8 osal_isr_register( uint8 interrupt_id, void (*isr_ptr)( uint8* ) );
  132. /*
  133. * Enable Interrupt
  134. */
  135. extern uint8 osal_int_enable( uint8 interrupt_id );
  136. /*
  137. * Disable Interrupt
  138. */
  139. extern uint8 osal_int_disable( uint8 interrupt_id );
  140. /*** Task Management ***/
  141. /*
  142. * Initialize the Task System
  143. */
  144. extern uint8 osal_init_system( void );
  145. /*
  146. * System Processing Loop
  147. */
  148. #if defined (ZBIT)
  149. extern __declspec(dllexport) void osal_start_system( void );
  150. #else
  151. extern void osal_start_system( void );
  152. #endif
  153. /*
  154. * Get the active task ID
  155. */
  156. extern uint8 osal_self( void );
  157. /*** Helper Functions ***/
  158. /*
  159. * String Length
  160. */
  161. extern int osal_strlen( char *pString );
  162. /*
  163. * Memory copy
  164. */
  165. extern void* osal_memcpy( void*, const void GENERIC *, unsigned int );
  166. /*
  167. * Memory compare
  168. */
  169. extern uint8 osal_memcmp( const void GENERIC *src1, const void GENERIC *src2, unsigned int len );
  170. /*
  171. * Memory set
  172. */
  173. extern void *osal_memset( void *dest, uint8 value, int len );
  174. /*
  175. * Build a uint16 out of 2 bytes (0 then 1).
  176. */
  177. extern uint16 osal_build_uint16( uint8 *swapped );
  178. /*
  179. * Build a uint32 out of sequential bytes.
  180. */
  181. extern uint32 osal_build_uint32( uint8 *swapped, uint8 len );
  182. /*
  183. * Convert long to ascii string
  184. */
  185. #if !defined ( ZBIT ) && !defined ( ZBIT2 ) && !defined (UBIT)
  186. extern uint8 *_ltoa( uint32 l, uint8 * buf, uint8 radix );
  187. #endif
  188. /*
  189. * Random number generator
  190. */
  191. extern uint16 osal_rand( void );
  192. /*
  193. * Buffer an uint32 value - LSB first.
  194. */
  195. extern uint8* osal_buffer_uint32( uint8 *buf, uint32 val );
  196. /*
  197. * Buffer an uint24 value - LSB first
  198. */
  199. extern uint8* osal_buffer_uint24( uint8 *buf, uint24 val );
  200. /*********************************************************************
  201. *********************************************************************/
  202. #ifdef __cplusplus
  203. }
  204. #endif
  205. #endif /* OSAL_H */