⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osslib.c

📁 T2.0 USB driver.rar T2.0 USB driver.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
    UINT32 maxCount,		    /* Max count allowed for semaphore */    UINT32 curCount,		    /* initial count for semaphore */    pSEM_HANDLE pSemHandle	    /* newly created semaphore handle */    )    {    /* Validate parameters */    if (pSemHandle == NULL) 	return ossStatus (S_ossLib_BAD_PARAMETER);    if ((*pSemHandle = (SEM_HANDLE) semCCreate (SEM_Q_FIFO, curCount)) == NULL)	return ossStatus (S_ossLib_GENERAL_FAULT);    return OK;    }/***************************************************************************** ossSemDestroy - Destroys a semaphore** Destroys the semaphore <semHandle> created by ossSemCreate().** RETURNS: OK or ERROR** ERRNO:*  S_ossLib_GENERAL_FAULT*/STATUS ossSemDestroy     (    SEM_HANDLE semHandle	    /* Handle of semaphore to destroy */    )    {    if (semDelete ((SEM_ID) semHandle) != OK)	return ossStatus (S_ossLib_GENERAL_FAULT);    return OK;    }/***************************************************************************** ossSemGive - Signals a semaphore** This function signals the sepcified semaphore.  A semaphore may have more* than one outstanding signal, as specified by the maxCount parameter when* the semaphore was created by ossSemCreate().	While the semaphore is at its* maximum count, additional calls to ossSemSignal for that semaphore have no* effect.** RETURNS: OK or ERROR** ERRNO:*  S_ossLib_BAD_HANDLE*/STATUS ossSemGive    (    SEM_HANDLE semHandle	    /* semaphore to signal */    )    {    if (semGive ((SEM_ID) semHandle) != OK)	return ossStatus (S_ossLib_BAD_HANDLE);    return OK;    }/***************************************************************************** ossSemTake - Attempts to take a semaphore** ossSemTake() attempts to "take" the semaphore specified by <semHandle>.* <blockFlag> specifies the blocking behavior.	OSS_BLOCK blocks indefinitely* waiting for the semaphore to be signalled.  OSS_DONT_BLOCK does not block* and returns an error if the semaphore is not in the signalled state.	Other* values of <blockFlag> are interpreted as a count of milliseconds to wait* for the semaphore to enter the signalled state before declaring an error.** RETURNS: OK or ERROR*/STATUS ossSemTake     (    SEM_HANDLE semHandle,	    /* semaphore to take */    UINT32 blockFlag		    /* specifies blocking action */    )    {    if (semTake ((SEM_ID) semHandle, TIMEOUT (blockFlag)) != OK)	return ossStatus (translateError ());    return OK;    }/***************************************************************************** ossMutexCreate - Creates a new mutex** This function creates a new mutex and returns the handle of that* mutex in <pMutexHandle>.  The mutex is created in the "untaken" state.** RETURNS: OK or STATUS** ERRNO:*  S_ossLib_BAD_PARAMETER*  S_ossLib_GENERAL_FAULT*/STATUS ossMutexCreate     (    pMUTEX_HANDLE pMutexHandle	    /* Handle of newly created mutex */    )    {        /* Validate parameters */    if (pMutexHandle == NULL) 	return ossStatus (S_ossLib_BAD_PARAMETER);    if ((*pMutexHandle = (MUTEX_HANDLE) semMCreate (SEM_Q_FIFO)) == NULL)	return ossStatus (S_ossLib_GENERAL_FAULT);    return OK;    }/***************************************************************************** ossMutexDestroy - Destroys a mutex** Destroys the mutex <mutexHandle> created by ossMutexCreate().** RETURNS: OK or ERROR** ERRNO:*  S_ossLib_GENERAL_FAULT*/STATUS ossMutexDestroy     (    MUTEX_HANDLE mutexHandle	    /* Handle of mutex to destroy */    )    {    if (semDelete ((SEM_ID) mutexHandle) != OK)	return ossStatus (S_ossLib_GENERAL_FAULT);    return OK;    }/***************************************************************************** ossMutexTake - Attempts to take a mutex** ossMutexTake() attempts to "take" the specified mutex.  The attempt will* succeed if the mutex is not owned by any other threads.  If a thread* attempts to take a mutex which it already owns, the attempt will succeed.* <blockFlag> specifies the blocking behavior.	OSS_BLOCK blocks indefinitely* waiting for the mutex to be released.  OSS_DONT_BLOCK does not block and* returns an error if the mutex is not in the released state.  Other values* of <blockFlag> are interpreted as a count of milliseconds to wait for the* mutex to be released before declaring an error.** RETURNS: OK or ERROR*/STATUS ossMutexTake     (    MUTEX_HANDLE mutexHandle,	    /* Mutex to take */    UINT32 blockFlag		    /* specifies blocking action */    )    {    if (semTake ((SEM_ID) mutexHandle, TIMEOUT (blockFlag)) != OK)	return ossStatus (translateError ());    return OK;    }/***************************************************************************** ossMutexRelease - Releases (gives) a mutex** Release the mutex specified by <mutexHandle>.  This function will fail* if the calling thread is not the owner of the mutex.** RETURNS: OK or ERROR** ERRNO:*  S_ossLib_BAD_HANDLE*/STATUS ossMutexRelease     (    MUTEX_HANDLE mutexHandle	    /* Mutex to be released */    )    {    if (semGive ((SEM_ID) mutexHandle) != OK)	return ossStatus (S_ossLib_BAD_HANDLE);    return OK;    }/***************************************************************************** ossMalloc - Global memory allocation** ossMalloc() allocates a buffer of <numBytes> in length and returns a * pointer to the allocated buffer.  The buffer i allocated from a global* pool which can be made visible to all processes or drivers in the * system.  Memory allocated by this function must be freed by calling* ossFree().** RETURNS: Pointer to allocated buffer, or NULL **/pVOID ossMalloc     (    UINT32 numBytes		    /* Size of buffer to allocate */    )    {#ifdef	FILL_MEMORY    pVOID pBfr = malloc (numBytes);    memset (pBfr, 0xdd, numBytes);    return pBfr;#else    return malloc (numBytes);#endif    }/***************************************************************************** ossCalloc - Allocates memory initialized to zeros** ossCalloc() uses ossMalloc() to allocate a block of memory and then* initializes it to zeros.  Memory allocated using this function should* be freed using ossFree().** RETURNS: Pointer to allocated buffer, or NULL. **/pVOID ossCalloc    (    UINT32 numBytes		    /* size of buffer to allocate */    )    {    pVOID mem;    if ((mem = ossMalloc (numBytes)) == NULL)	return NULL;    memset (mem, 0, numBytes);    return mem;    }/***************************************************************************** ossMallocAlign - allocates memory aligned to boundary** ossMallocAlign() allocates memory which is aligned to an address evenly* divisible by <alignment>.  If <zero> is TRUE, then the memory will be* initialized to zeros.  Memory should be freed using ossFree().** RETURNS: Pointer to allocated buffer, or NULL. **/pVOID ossMallocAlign    (    UINT32 numBytes,		    /* size of buffer to allocate */    UINT32 alignment,		    /* alignment, must be power of 2 */    BOOL zero			    /* indicates if memory to be zeroed */    )    {    pVOID mem;    if ((mem = memalign (alignment, numBytes)) == NULL)	return NULL;    if (zero)	memset (mem, 0, numBytes);#ifdef	FILL_MEMORY    else	memset (mem, 0xdd, numBytes);#endif    return mem;    }/***************************************************************************** ossFree - Frees globally allocated memory** ossFree() frees memory allocated by ossMalloc().** RETURNS: N/A*/VOID ossFree     (    pVOID bfr    )    {    if (bfr != NULL)	free (bfr);    }/***************************************************************************** ossTime - Returns relative system time in msec** Returns a count of milliseconds relative to the time the system was* started.** NOTE: The time will wrap approximately every 49 days, so time calucations* should always be based on the difference between two time values.*/UINT32 ossTime (void)    {    return tickGet () * msecsPerTick;    }/* End of file. */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -