ossLib.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:7k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* ossLib.h - O/S-independent services */
  2. /* Copyright 2000 Wind River Systems, Inc. */
  3. /*
  4. Modification history
  5. --------------------
  6. 01g,18sep01,wef  merge from wrs.tor2_0.usb1_1-f for veloce
  7. 01f,07may01,wef  changed module number to be (module sub num << 8) | 
  8.  M_usbHostLib
  9. 01e,02may01,wef  changed module number to be M_<module> + M_usbHostLib
  10. 01d,16mar01,wef  changed priority levels of OSS_PRIORITY_HIGH and 
  11.  OSS_PRIORITY_INTERRUPT to be 5 and 10 respectivly
  12. 01d,05dec00,wef  moved Module number defs to vwModNum.h - add this
  13.                  to #includes
  14. 01c,07mar00,rcb  Change MUTEX_HANDLE, SEM_HANDLE, and THREAD_HANDLE from
  15.  UINT32 to pVOID to allow comparison with NULL.
  16. 01b,13jul99,rcb  Removed queue functions to usbQueueLib.h.
  17. 01a,07jun99,rcb  First.
  18. */
  19. /*
  20. DESCRIPTION
  21. Defines constants, structures, and functions provided by the ossLib.
  22. These functions include:
  23. o   Multithreading services (thread management and thread synchronization).
  24. o   Shared memory allocation (for passing memory globally).
  25. o   Time services.
  26. Other system-unique services may be provided in the future.
  27. IMPORTANT: Code using ossLib may be ported to preemptive and
  28. non-preemptive multitasking environments.  Therefore, code must observe the
  29. following rules:
  30. 1. Code must not assume that the scheduler is preemptive.  Therefore, no
  31. task is permitted to "hog" the processor indefinitely. All threads should 
  32. regularly relinquish the processor, either through calls which may block in 
  33. ossLib functions - which automatically relinquish, or through explicit 
  34. calls to the threadSleep() function.
  35. 2. Code must not assume that the scheduler is NOT preemptive.  Therefore,
  36. critical sections must be protected from reentrancy.  This protection is 
  37. typically managed through the use of mutexes.
  38. */
  39. #ifndef __INCossLibh
  40. #define __INCossLibh
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /* includes */
  45. #include "vwModNum.h"  /* USB Module Number Def's */
  46. /* Defines */
  47. /* ossLib return codes. */
  48. /* 
  49.  * USB errnos are defined as being part of the USB host Module, as are all
  50.  * vxWorks module numbers, but the USB Module number is further divided into 
  51.  * sub-modules.  Each sub-module has upto 255 values for its own error codes
  52.  */
  53.  
  54. #define USB_OSS_SUB_MODULE  1
  55. #define M_ossLib    ( (USB_OSS_SUB_MODULE  << 8) | M_usbHostLib )
  56. #define ossErr(x)   (M_ossLib | (x))
  57. #define S_ossLib_BAD_HANDLE     ossErr (1)
  58. #define S_ossLib_BAD_PARAMETER     ossErr (2)
  59. #define S_ossLib_OUT_OF_MEMORY     ossErr (3)
  60. #define S_ossLib_OUT_OF_RESOURCES   ossErr (4)
  61. #define S_ossLib_INTERNAL_FAULT     ossErr (5)
  62. #define S_ossLib_TIMEOUT     ossErr (6)
  63. #define S_ossLib_GENERAL_FAULT     ossErr (7)
  64. #define S_ossLib_DESTROY_FAILED     ossErr (8)
  65. #define S_ossLib_QUEUE_FULL     ossErr (9)
  66. #define S_ossLib_QUEUE_EMPTY     ossErr (10)
  67. #define S_ossLib_NO_SIGNAL     ossErr (11)
  68. #define S_ossLib_TAKE_MUTEX     ossErr (12)
  69. #define S_ossLib_RELEASE_MUTEX     ossErr (13)
  70. #define S_ossLib_NOT_IMPLEMENTED    ossErr (14)
  71. /* Blocking/non-blocking parameters for functions which can block. */
  72. #define OSS_BLOCK 0xffffffff  /* Function will block indefinitely */
  73. #define OSS_DONT_BLOCK 0x0     /* Function will not block */
  74.     /* NOTE: All other values are interpreted */
  75.     /* as a count of milliseconds to block */
  76. /* Thread priority parameters for ossThreadCreate */
  77. #define OSS_PRIORITY_INHERIT 0xffff /* inherit caller's priority */
  78. #define OSS_PRIORITY_LOW 255
  79. #define OSS_PRIORITY_TYPICAL 127
  80. #define OSS_PRIORITY_HIGH 10
  81. #define OSS_PRIORITY_INTERRUPT 5
  82. /* Maximum length of a thread name string. */
  83. #define MAX_OSS_NAME_LEN 32
  84. /* Structure definitions. */
  85. /* Handles. */
  86. typedef pVOID THREAD_HANDLE;     /* Thread handle */
  87. typedef THREAD_HANDLE *pTHREAD_HANDLE;
  88. typedef pVOID SEM_HANDLE;     /* Semaphore handle */
  89. typedef SEM_HANDLE *pSEM_HANDLE;    
  90. typedef pVOID MUTEX_HANDLE;     /* Mutex handle */
  91. typedef MUTEX_HANDLE *pMUTEX_HANDLE;
  92. /* Structure of a thread entry point */
  93. typedef VOID (*THREAD_PROTOTYPE) (pVOID param);
  94. /* function prototypes */
  95. STATUS ossStatus 
  96.     (
  97.     int status
  98.     );
  99. STATUS ossInitialize (void);
  100. STATUS ossShutdown (void);
  101. STATUS ossThreadCreate 
  102.     (
  103.     THREAD_PROTOTYPE func,     /* function to spawn as new thread */
  104.     pVOID param,     /* Parameter to be passed to new thread */
  105.     UINT16 priority,     /* OSS_PRIORITY_xxxx */
  106.     pCHAR name,      /* thread name or NULL */
  107.     pTHREAD_HANDLE pThreadHandle    /* Handle of newly spawned thread */
  108.     );
  109. #define OSS_THREAD_CREATE(func, param, priority, name, pThreadHandle) 
  110.     ossThreadCreate (func, param, priority, name, pThreadHandle)
  111. STATUS ossThreadDestroy 
  112.     (
  113.     THREAD_HANDLE threadHandle     /* handle of thread to be destroyed */
  114.     );
  115. #define OSS_THREAD_DESTROY(threadHandle) ossThreadDestroy (threadHandle)
  116. STATUS ossThreadSleep
  117.     (
  118.     UINT32 msec      /* Number of msec to sleep */
  119.     );
  120. #define OSS_THREAD_SLEEP(msec) ossThreadSleep (msec)
  121. STATUS ossSemCreate 
  122.     (
  123.     UINT32 maxCount,     /* Max count allowed for semaphore */
  124.     UINT32 curCount,     /* initial count for semaphore */
  125.     pSEM_HANDLE pSemHandle     /* newly created semaphore handle */
  126.     );
  127. #define OSS_SEM_CREATE(maxCount, curCount, pSemHandle) 
  128.     ossSemCreate (maxCount, curCount, pSemHandle)
  129. STATUS ossSemDestroy 
  130.     (
  131.     SEM_HANDLE semHandle     /* Handle of semaphore to destroy */
  132.     );
  133. #define OSS_SEM_DESTROY(semHandle) ossSemDestroy (semHandle)
  134. STATUS ossSemGive 
  135.     (
  136.     SEM_HANDLE semHandle     /* semaphore to signal */
  137.     );
  138. #define OSS_SEM_GIVE(semHandle) ossSemGive (semHandle)
  139. STATUS ossSemTake 
  140.     (
  141.     SEM_HANDLE semHandle,     /* semaphore to take */
  142.     UINT32 blockFlag     /* specifies blocking action */
  143.     );
  144. #define OSS_SEM_TAKE(semHandle, blockFlag) ossSemTake (semHandle, blockFlag)
  145. STATUS ossMutexCreate 
  146.     (
  147.     pMUTEX_HANDLE pMutexHandle     /* Handle of newly created mutex */
  148.     );
  149. #define OSS_MUTEX_CREATE(pMutexHandle) ossMutexCreate (pMutexHandle)
  150. STATUS ossMutexDestroy 
  151.     (
  152.     MUTEX_HANDLE mutexHandle     /* Handle of mutex to destroy */
  153.     );
  154. #define OSS_MUTEX_DESTROY(mutexHandle) ossMutexDestroy (mutexHandle)
  155. STATUS ossMutexTake 
  156.     (
  157.     MUTEX_HANDLE mutexHandle,     /* Mutex to take */
  158.     UINT32 blockFlag     /* specifies blocking action */
  159.     );
  160. #define OSS_MUTEX_TAKE(mutexHandle, blockFlag) 
  161.     ossMutexTake (mutexHandle, blockFlag)
  162. STATUS ossMutexRelease 
  163.     (
  164.     MUTEX_HANDLE mutexHandle     /* Mutex to be released */
  165.     );
  166. #define OSS_MUTEX_RELEASE(mutexHandle) ossMutexRelease(mutexHandle)
  167. pVOID ossMalloc 
  168.     (
  169.     UINT32 numBytes     /* Size of buffer to allocate */
  170.     );
  171. #define OSS_MALLOC(numBytes) ossMalloc(numBytes)
  172. pVOID ossCalloc
  173.     (
  174.     UINT32 numBytes     /* size of buffer to allocate */
  175.     );
  176. #define OSS_CALLOC(numBytes) ossCalloc(numBytes)
  177. pVOID ossMallocAlign
  178.     (
  179.     UINT32 numBytes,     /* size of buffer to allocate */
  180.     UINT32 alignment,     /* alignment, must be power of 2 */
  181.     BOOL zero     /* indicates if memory to be zeroed */
  182.     );
  183. #define OSS_MALLOC_ALIGN(numBytes, alignment, zero) 
  184.     ossMallocAlign (numBytes, alignment, zero)
  185. VOID ossFree 
  186.     (
  187.     pVOID bfr
  188.     );
  189. #define OSS_FREE(bfr) ossFree (bfr)
  190. UINT32 ossTime (void);
  191. #define OSS_TIME() ossTime ()
  192. #ifdef __cplusplus
  193. }
  194. #endif
  195. #endif /* __INCossLibh */
  196. /* End of file. */