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

📄 txc_os_sem.c

📁 TranSwitch Envoy CE2 & Envoy CE4 设备驱动及编程指南
💻 C
📖 第 1 页 / 共 2 页
字号:
            flags = SM_WAIT;
            msPerTick = 1000 / KC_TICKS2SEC;
            milliSecondsWait += (msPerTick / 2);
            timeoutTicks = milliSecondsWait / msPerTick;
            break;
    }
    
    /* Call the psos function */
    psosError = sm_p (semId, flags, timeoutTicks);
    
    /* process the psos return */
    switch (psosError)
    {
        case 0: /* no error */
            txcError = TXC_NO_ERR;
            break;

        /* general time out */
        case ERR_TIMEOUT:
            txcError =  TXC_OS_TIMEOUT_STAT;
            break;

        /* que empty, applies only to ms time = 0 */
        case ERR_NOSEM:
            txcError = TXC_OS_RESOURCE_EMPTY_STAT;
            break;

        default:
            txcError = TXC_OS_RESOURCE_ERR;
    }

#elif defined (TXC_VXWORKS)          /* end of TXC_PSOS */ 

    /* Create a full Binary VxWorks Semaphore. */

    int timeoutTicks, semError, msPerTick;
 
    /* if the semaphore ID = 0, semaphores are not used */
    if (semId == TXC_NULL)
        return TXC_NO_ERR;

    /* first, determine the wait ticks and flags, as a function of the 
        OS ticks, rounding up to the nearest tick */ 
    switch (milliSecondsWait) 
    { 
        case TXC_OS_SEM_WAIT_NEVER: /* no wait, this is the only type que emtpy error can be returned */ 
            timeoutTicks = NO_WAIT; 
            break; 
        case TXC_OS_SEM_WAIT_FOREVER: /* just wait */
            timeoutTicks = WAIT_FOREVER;
            break; 
        default: /* wait a period of time */ 
            msPerTick = 1000 / CLOCKS_PER_SEC;
            milliSecondsWait += (msPerTick / 2);
            timeoutTicks = (int)milliSecondsWait / msPerTick;
    } 
     
    /* Call the vxworks function */ 
    semError = semTake ((SEM_ID)semId, timeoutTicks); 

    /* process the vxworks return */ 
    if (semError==ERROR) 
    {
        switch(errno)
        {
            /* invalid semaphore ID */
            case S_objLib_OBJ_ID_ERROR:
                txcError = TXC_OS_RESOURCE_ERR;
                break;
            /***general timeout***/
            case S_objLib_OBJ_TIMEOUT: 
                txcError =  TXC_OS_TIMEOUT_STAT;
                break;
            /***semaphore unavailable when timeout set to NO_WAIT***/
            case S_objLib_OBJ_UNAVAILABLE: 
                txcError = TXC_OS_RESOURCE_EMPTY_STAT;
                break;
            default:
                txcError = TXC_OS_RESOURCE_ERR;
        }
    }
    else
    {
        txcError = TXC_NO_ERR; 
    }

#elif defined (TXC_NO_RTOS)          /* end of TXC_VXWORKS */

    return TXC_NO_ERR;

#else                       /* end of TXC_NO_RTOS */                
 
    txcError = TXC_OS_RESOURCE_ERR; 
 
#endif                      /* end of default */
 
    /* return the error code */
    return txcError;

}

/************************************************************************
 *                                                                      *
 *  FUNCTION:TXC_SemPost()                                              *
 *                                                                      *
 *  DESCRIPTION: This will call the rtos function that will release the *
 *               semaphore.                                             *
 *                                                                      *
 *  INPUTS: TXC_SEM_ID semId                                            *
 *                                                                      *
 *  RETURNS: TXC_OS_RESOURCE_ERR,TXC_NO_ERR                             *
 *                                                                      *
 *  CAVEATS:                                                            *
 *                                                                      *
 *  REVISION HISTORY:                                                   *
 *      Date    Author          Description                             *
 *  ------------------------------------------------------------------- *
 *  20-Mar-01   R. Ruchandani   Initial Revision                        *
 *  25-Apr-02   B. Hawthorne    Restoring VxWorks RTOS support.         *
 *                                                                      *
 ************************************************************************/
TXC_U16BIT TXC_SemPost(TXC_SEM_ID semId)
{

#ifdef TXC_PSOS

    TXC_SEM_ID psosError;

    /* if the semaphore ID = 0, semaphores are not used */
    if (semId == TXC_NULL)
        return TXC_NO_ERR;

    /* Call the psos function */
    psosError = sm_v(semId);
    
    /* Check to see if error */
    if(psosError)
        return TXC_OS_RESOURCE_ERR;
    else
        return TXC_NO_ERR;

#elif defined (TXC_VXWORKS)             /* end of TXC_PSOS */ 
 
    int semError; 
 
    /* if the semaphore ID = 0, semaphores are not used */
    if (semId == TXC_NULL)
        return TXC_NO_ERR;

    /* Call the vxworks function */ 
    semError = semGive((SEM_ID)semId); 
     
    /* Check to see if error */ 
    if(semError==ERROR) 
        return TXC_OS_RESOURCE_ERR; 
    else 
        return TXC_NO_ERR; 

#elif defined (TXC_NO_RTOS)          /* end of TXC_VXWORKS */

    return TXC_NO_ERR;

#else                       /* end of TXC_NO_RTOS */ 

    return TXC_OS_RESOURCE_ERR; 
 
#endif                      /* end of default */

}

/************************************************************************
 *                                                                      *
 *  FUNCTION:TXC_SemDelete ()                                           *
 *                                                                      *
 *  DESCRIPTION: Delete the semaphore created.                          *
 *                                                                      *
 *  INPUTS: TXC_SEM_ID semId                                            *
 *                                                                      *
 *  RETURNS: TXC_OS_RESOURCE_ERR,TXC_NO_ERR                             *
 *                                                                      *
 *  CAVEATS:                                                            *
 *                                                                      *
 *  REVISION HISTORY:                                                   *
 *      Date    Author          Description                             *
 *  ------------------------------------------------------------------- *
 *  20-Mar-01   R. Ruchandani   Initial Revision                        *
 *  25-Apr-02   B. Hawthorne    Restoring VxWorks RTOS support.         *
 *                                                                      *
 ************************************************************************/
TXC_U16BIT TXC_SemDelete (TXC_SEM_ID semId)
{

#ifdef TXC_PSOS

    TXC_SEM_ID psosError;

    /* if the semaphore ID = 0, semaphores are not used */
    if (semId == TXC_NULL)
        return TXC_NO_ERR;

    /* Call the psos function */
    psosError = sm_delete(semId);
    
    /* Check to see if error */
    if(psosError)
        return TXC_OS_RESOURCE_ERR;
    else
        return TXC_NO_ERR;

#elif defined (TXC_VXWORKS)          /* end of TXC_PSOS */ 
 
    int semError; 
 
    /* if the semaphore ID = 0, semaphores are not used */
    if (semId == TXC_NULL)
        return TXC_NO_ERR;

    /* Call the vxworks function */ 
    semError = semDelete((SEM_ID)semId); 
     
    /* Check to see if error */ 
    if(semError==ERROR) 
        return TXC_OS_RESOURCE_ERR; 
    else 
        return TXC_NO_ERR; 

#elif defined (TXC_NO_RTOS)          /* end of TXC_VXWORKS */

    return TXC_NO_ERR;

#else                       /* end of TXC_NO_RTOS */ 

    return TXC_OS_RESOURCE_ERR; 
 
#endif                      /* end of default */

}


⌨️ 快捷键说明

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