OSAL.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /******************************************************************************
  2. Filename: OSAL.h
  3. Revised:
  4. Revision:
  5. ******************************************************************************/
  6. #ifndef OSAL_H
  7. #define OSAL_H
  8. #ifdef __cplusplus
  9. extern "C"
  10. {
  11. #endif
  12. /*********************************************************************
  13. * INCLUDES
  14. */
  15. #include "comdef.h"
  16. #include "OSAL_Memory.h"
  17. #include "OSAL_Timers.h"
  18. /*********************************************************************
  19. * MACROS
  20. */
  21. #if ( UINT_MAX == 65535 ) /* 8-bit and 16-bit devices */
  22. #define osal_offsetof(type, member) ((uint16) &(((type *) 0)->member))
  23. #else /* 32-bit devices */
  24. #define osal_offsetof(type, member) ((uint32) &(((type *) 0)->member))
  25. #endif
  26. #define OSAL_MSG_NEXT(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->next
  27. #define OSAL_MSG_Q_INIT(q_ptr) *(q_ptr) = NULL
  28. #define OSAL_MSG_Q_EMPTY(q_ptr) (*(q_ptr) == NULL)
  29. #define OSAL_MSG_Q_HEAD(q_ptr) (*(q_ptr))
  30. #define OSAL_MSG_LEN(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->len
  31. #define OSAL_MSG_ID(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->dest_id
  32. /*********************************************************************
  33. * CONSTANTS
  34. */
  35. /*** Interrupts ***/
  36. #define INTS_ALL 0xFF
  37. /*********************************************************************
  38. * TYPEDEFS
  39. */
  40. typedef struct
  41. {
  42. void *next;
  43. uint16 len;
  44. uint8 dest_id;
  45. } osal_msg_hdr_t;
  46. typedef struct
  47. {
  48. uint8 event;
  49. uint8 status;
  50. } osal_event_hdr_t;
  51. typedef void * osal_msg_q_t;
  52. /*********************************************************************
  53. * GLOBAL VARIABLES
  54. */
  55. /*********************************************************************
  56. * FUNCTIONS
  57. */
  58. /*** Message Management ***/
  59. /*
  60. * Task Message Allocation
  61. */
  62. extern uint8 * osal_msg_allocate(uint16 len );
  63. /*
  64. * Task Message Deallocation
  65. */
  66. extern uint8 osal_msg_deallocate( uint8 *msg_ptr );
  67. /*
  68. * Send a Task Message
  69. */
  70. extern uint8 osal_msg_send( uint8 destination_task, uint8 *msg_ptr );
  71. /*
  72. * Push a Task Message to head of queue
  73. */
  74. extern uint8 osal_msg_push_front( uint8 destination_task, uint8 *msg_ptr );
  75. /*
  76. * Receive a Task Message
  77. */
  78. extern uint8 *osal_msg_receive( uint8 task_id );
  79. /*
  80. * Find in place a matching Task Message / Event.
  81. */
  82. extern osal_event_hdr_t *osal_msg_find(uint8 task_id, uint8 event);
  83. /*
  84. * Enqueue a Task Message
  85. */
  86. extern void osal_msg_enqueue( osal_msg_q_t *q_ptr, void *msg_ptr );
  87. /*
  88. * Enqueue a Task Message Up to Max
  89. */
  90. extern uint8 osal_msg_enqueue_max( osal_msg_q_t *q_ptr, void *msg_ptr, uint8 max );
  91. /*
  92. * Dequeue a Task Message
  93. */
  94. extern void *osal_msg_dequeue( osal_msg_q_t *q_ptr );
  95. /*
  96. * Push a Task Message to head of queue
  97. */
  98. extern void osal_msg_push( osal_msg_q_t *q_ptr, void *msg_ptr );
  99. /*
  100. * Extract and remove a Task Message from queue
  101. */
  102. extern void osal_msg_extract( osal_msg_q_t *q_ptr, void *msg_ptr, void *prev_ptr );
  103. /*** Task Synchronization ***/
  104. /*
  105. * Set a Task Event
  106. */
  107. extern uint8 osal_set_event( uint8 task_id, uint16 event_flag );
  108. /*
  109. * Clear a Task Event
  110. */
  111. extern uint8 osal_clear_event( uint8 task_id, uint16 event_flag );
  112. /*** Interrupt Management ***/
  113. /*
  114. * Register Interrupt Service Routine (ISR)
  115. */
  116. extern uint8 osal_isr_register( uint8 interrupt_id, void (*isr_ptr)( uint8* ) );
  117. /*
  118. * Enable Interrupt
  119. */
  120. extern uint8 osal_int_enable( uint8 interrupt_id );
  121. /*
  122. * Disable Interrupt
  123. */
  124. extern uint8 osal_int_disable( uint8 interrupt_id );
  125. /*** Task Management ***/
  126. /*
  127. * Initialize the Task System
  128. */
  129. extern uint8 osal_init_system( void );
  130. /*
  131. * System Processing Loop
  132. */
  133. #if defined (ZBIT)
  134. extern __declspec(dllexport) void osal_start_system( void );
  135. #else
  136. extern void osal_start_system( void );
  137. #endif
  138. /*
  139. * One Pass Throu the OSAL Processing Loop
  140. */
  141. extern void osal_run_system( void );
  142. /*
  143. * Get the active task ID
  144. */
  145. extern uint8 osal_self( void );
  146. /*** Helper Functions ***/
  147. /*
  148. * String Length
  149. */
  150. extern int osal_strlen( char *pString );
  151. /*
  152. * Memory copy
  153. */
  154. extern void *osal_memcpy( void*, const void GENERIC *, unsigned int );
  155. /*
  156. * Memory Duplicate - allocates and copies
  157. */
  158. extern void *osal_memdup( const void GENERIC *src, unsigned int len );
  159. /*
  160. * Reverse Memory copy
  161. */
  162. extern void *osal_revmemcpy( void*, const void GENERIC *, unsigned int );
  163. /*
  164. * Memory compare
  165. */
  166. extern uint8 osal_memcmp( const void GENERIC *src1, const void GENERIC *src2, unsigned int len );
  167. /*
  168. * Memory set
  169. */
  170. extern void *osal_memset( void *dest, uint8 value, int len );
  171. /*
  172. * Build a uint16 out of 2 bytes (0 then 1).
  173. */
  174. extern uint16 osal_build_uint16( uint8 *swapped );
  175. /*
  176. * Build a uint32 out of sequential bytes.
  177. */
  178. extern uint32 osal_build_uint32( uint8 *swapped, uint8 len );
  179. /*
  180. * Convert long to ascii string
  181. */
  182. #if !defined ( ZBIT ) && !defined ( ZBIT2 ) && !defined (UBIT)
  183. extern uint8 *_ltoa( uint32 l, uint8 * buf, uint8 radix );
  184. #endif
  185. /*
  186. * Random number generator
  187. */
  188. extern uint16 osal_rand( void );
  189. /*
  190. * Buffer an uint32 value - LSB first.
  191. */
  192. extern uint8* osal_buffer_uint32( uint8 *buf, uint32 val );
  193. /*
  194. * Buffer an uint24 value - LSB first
  195. */
  196. extern uint8* osal_buffer_uint24( uint8 *buf, uint24 val );
  197. /*
  198. * Is all of the array elements set to a value?
  199. */
  200. extern uint8 osal_isbufset( uint8 *buf, uint8 val, uint8 len );
  201. /*********************************************************************
  202. *********************************************************************/
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206. #endif /* OSAL_H */