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

📄 txc_os_queue.c

📁 TranSwitch Envoy CE2 & Envoy CE4 设备驱动及编程指南
💻 C
📖 第 1 页 / 共 2 页
字号:
    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_Dequeue                                             *
 *                                                                      *
 *  DESCRIPTION: Dequeue a message from the specified queue.            *
 *                                                                      *
 *  INPUTS: TXC_QUEUE_ID queueId, TXC_VOID_PTR *bufferPtrPtr            *
 *          TXC_U32BIT milliSecondWait                                  *
 *  RETURNS:                                                            *
 *      TXC_NO_ERR, TXC_OS_RESOURCE_ERR                                 *
 *                                                                      *
 *                                                                      *
 *  CAVEATS:                                                            *
 *          None at this time.                                          *
 *                                                                      *
 *                                                                      *
 *  REVISION HISTORY:                                                   *
 *          Date        Author          Description                     *
 *  ------------------------------------------------------------------- *
 *  1.0     13-Mar-01   R. Ruchandani   Initial Revision                *
 *  1.1     10-May-01   B. Hawthorne    Restored VxWorks, changed to    *
 *                                      return ptr2ptr to word.         *
 *  1.2     28-Jun-02   R. Kuhnen       When in VXWORKS mode, changed   *
 *                                      message data ptr de-reference   *
 *                                                                      *
 ************************************************************************/

TXC_U16BIT TXC_Dequeue(TXC_QUEUE_ID queueId, TXC_VOID_PTR * bufferPtrPtr, 
                       TXC_U32BIT milliSecondWait)
{

    TXC_U16BIT txcError;

#ifdef TXC_PSOS

    unsigned long flags, timeoutTicks, messageBuffer[4], psosError, msPerTick;

    /* first, determine the wait ticks and flags, as a function of the
        OS ticks, rounding up to the nearest tick */
    switch (milliSecondWait)
    {
        case TXC_OS_QUEUE_WAIT_NEVER: /* no wait */
            flags = Q_NOWAIT;
            timeoutTicks = 0;
            break;

        case TXC_OS_QUEUE_WAIT_FOREVER: /* just wait */
            flags = Q_WAIT;
            timeoutTicks = 0;
            break;

        default: /* wait a period of time, converting mS to Sec*/
            flags = Q_WAIT;
            msPerTick = 1000 / KC_TICKS2SEC;
            milliSecondWait += (msPerTick / 2);
            timeoutTicks = milliSecondWait / msPerTick;

    }

    /* Call pSOS to get the message */
    psosError= q_receive (queueId, flags, timeoutTicks, messageBuffer);

    /* process the psos return */
    switch (psosError)
    {
        case 0: /* no error */
            *bufferPtrPtr = (TXC_U8BIT *) messageBuffer[0];
            txcError = TXC_NO_ERR;
            break;

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

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

        default:
            txcError = TXC_OS_RESOURCE_ERR;
            *bufferPtrPtr = TXC_NULL;
    }

#elif defined (TXC_VXWORKS)              /* end of TXC_PSOS */ 
 
    int timeoutTicks,  msgQError, msPerTick; 
    char rcvBuf[TXC_VXWORKS_MSG_LEN];
    unsigned long * bufAddrPtr;
    
 
    /* first, determine the wait ticks and flags, as a function of the 
        OS ticks, rounding up to the nearest tick */ 
    switch (milliSecondWait) 
    { 
        case TXC_OS_QUEUE_WAIT_NEVER: /* no wait */ 
            timeoutTicks = NO_WAIT; 
            break; 

        case TXC_OS_QUEUE_WAIT_FOREVER: /* just wait */
            timeoutTicks = WAIT_FOREVER;
            break;
 
        default: /* wait a period of time */ 
            msPerTick = 1000 / CLOCKS_PER_SEC;
            milliSecondWait += (msPerTick / 2);
            timeoutTicks = (int)milliSecondWait / msPerTick;
    } 
     
    /* Call vxworks to get the message */ 
    msgQError= msgQReceive ((MSG_Q_ID)queueId,  
        (char *) rcvBuf,  
        TXC_VXWORKS_MSG_LEN,           /*length of buffer*/
        timeoutTicks 
        ); 
 
    /* process the vxworks return */ 
    if (msgQError == ERROR) 
    {
        switch(errno)
        {
            /***general timeout***/
            case S_objLib_OBJ_TIMEOUT: 
                txcError =  TXC_OS_TIMEOUT_STAT;
                break;
            /***queue empty when timeout set to NO_WAIT***/
            case S_objLib_OBJ_UNAVAILABLE: 
                txcError = TXC_OS_RESOURCE_EMPTY_STAT;
                break;
            default:
                txcError = TXC_OS_RESOURCE_ERR;
        }

        *bufferPtrPtr = TXC_NULL;
    }
    else
    {
        bufAddrPtr = (unsigned long *)&rcvBuf[0];
/*         (unsigned long *) *bufferPtrPtr = *bufAddrPtr; */
        *bufferPtrPtr = (TXC_VOID_PTR *)*bufAddrPtr;
        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_DeleteQueue                                         *
 *                                                                      *
 *  DESCRIPTION: Remove the queue.                                      *
 *                                                                      *
 *  INPUTS: TXC_QUEUE_ID queueId                                        *
 *                                                                      *
 *  RETURNS:                                                            *
 *          TXC_NO_ERR, TXC_OS_RESOURCE_ERR                             *
 *                                                                      *
 *                                                                      *
 *  CAVEATS:                                                            *
 *          None at this time.                                          *
 *                                                                      *
 *                                                                      *
 *  REVISION HISTORY:                                                   *
 *          Date        Author          Description                     *
 *  ------------------------------------------------------------------- *
 *  1.0     13-Mar-01   R. Ruchandani   Initial Revision                *
 *                                                                      *
 ************************************************************************/

TXC_U16BIT TXC_DeleteQueue(TXC_QUEUE_ID queueId)
{

#ifdef TXC_PSOS

    unsigned long psosError;
    
    /* call the psos function */
    psosError= q_delete (queueId);

    /* process the psos return */
    if(psosError)
        return TXC_OS_RESOURCE_ERR;
    else
        return TXC_NO_ERR;

#elif defined (TXC_VXWORKS)          /* end of TXC_PSOS */ 
 
    int msgQError; 
     
    /* call the vxworks function */ 
    msgQError= msgQDelete ((MSG_Q_ID)queueId); 
 
    /* process the vxworks return */ 
    if(msgQError ==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 + -