OSAL.h 7.8 KB

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