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

📄 txc_os_task.c

📁 TranSwitch Envoy CE2 & Envoy CE4 设备驱动及编程指南
💻 C
📖 第 1 页 / 共 2 页
字号:
#else                       /* end of TXC_NO_RTOS */ 
 
    return TXC_OS_RESOURCE_ERR; 
 
#endif                      /* end of default */

}

/************************************************************************
 *                                                                      *
 *  FUNCTION:   TXC_GetTaskId                                           *
 *                                                                      *
 *  DESCRIPTION: Get the id of a task.                                  *
 *                                                                      *
 *  INPUTS:const char name, TXC_TASK_ID * taskIdPtr                     *
 *                                                                      *
 *  RETURNS:                                                            *
 *      TXC_U16BIT error code                                           *
 *          TXC_NO_ERR, TXC_OS_RESOURCE_ERR                             *
 *                                                                      *
 *  CAVEATS:                                                            *
 *      Non Blocking function.                                          *
 *                                                                      *
 *                                                                      *
 *  REVISION HISTORY:                                                   *
 *          Date        Author          Description                     *
 *  ------------------------------------------------------------------- *
 *  1.0     20-Mar-01   R. Ruchandani   Initial Revision                *
 *  1.1     25-Apr-02   B. Hawthorne    Adding VxWorks RTOS support.    *
 *  1.2     28-Jun-02   R. Kuhnen       When in VXWORKS mode, added     *
 *                                      test for name = NULL and if so  *
 *                                      call a different function       *
 *                                                                      *
 ************************************************************************/

TXC_U16BIT TXC_GetTaskId(const char * name, TXC_TASK_ID * taskIdPtr)
{

#ifdef TXC_PSOS

    unsigned long psosError;

    /* call the psos function */
    psosError = t_ident(name, 0, taskIdPtr);
    
    /* process the error */
    if (psosError)
        return TXC_OS_RESOURCE_ERR;
    else 
        return TXC_NO_ERR;

#elif defined (TXC_VXWORKS)      /* end of TXC_PSOS */ 
 
    int taskError; 
 
    /* if name = NULL then it will be implied that it is desired to get the
       calling task's ID therefore different function is called */ 
    if (name == TXC_NULL)
    {
        *taskIdPtr = (TXC_TASK_ID)taskIdSelf(); 
        return TXC_NO_ERR; 
    }
    else
    {
        taskError = taskNameToId((char *)name); 
         
        /* process the error */ 
        if (taskError == ERROR) 
            return TXC_OS_RESOURCE_ERR; 
        else  
        { 
            *taskIdPtr = (TXC_TASK_ID)taskError; 
            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_SignalTask                                          *
 *                                                                      *
 *  DESCRIPTION: This function will signal a task to happen.            *
 *                                                                      *
 *  INPUTS:TXC_TASK_ID taskId, TXC_TASK_ID events                       *
 *                                                                      *
 *  RETURNS:                                                            *
 *      TXC_U16BIT error code                                           *
 *          TXC_NO_ERR, TXC_OS_RESOURCE_ERR                             *
 *                                                                      *
 *  CAVEATS:                                                            *
 *      Non Blocking function.                                          *
 *                                                                      *
 *                                                                      *
 *  REVISION HISTORY:                                                   *
 *          Date        Author          Description                     *
 *  ------------------------------------------------------------------- *
 *  1.0     20-Mar-01   R. Ruchandani   Initial Revision                *
 *  1.1     25-Apr-02   B. Hawthorne    Adding VxWorks RTOS support.    *
 *  1.2     02-Oct-02   R. Kuhnen       Added check if input taskId is  *
 *                                      equal to current task id then   *
 *                                      exit with TXC_NO_ERR            *
 *  1.3     10-Dec-02   R. Kuhnen       Removed GetTaskId. This will be *
 *                                      done by calling function        *
 *                                                                      *
 ************************************************************************/

TXC_U16BIT TXC_SignalTask(TXC_TASK_ID taskId, TXC_U32BIT signalMask)
{

#ifdef TXC_PSOS

    unsigned long psosError;
    
    /* send the signal */
    psosError = ev_send (taskId, signalMask);

    /* process the error code */
    if (psosError == 0)
        return TXC_NO_ERR;
    else
        return TXC_OS_RESOURCE_ERR;

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

    int sigError;
    union sigval mySigval;
    mySigval.sival_int = 0;

    sigError = sigqueue((int)taskId, (int)signalMask, mySigval);

    if(sigError == 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_WaitOnSignal                                        *
 *                                                                      *
 *  DESCRIPTION: This function will wait for signal from a task.        *
 *                                                                      *
 *  INPUTS:TXC_U32BIT signalMask, TXC_U32BIT milliSecondsWait           *
 *                                                                      *
 *  RETURNS:                                                            *
 *      TXC_U16BIT error code                                           *
 *          TXC_NO_ERR, TXC_OS_RESOURCE_ERR,                            *
 *          TXC_OS_TIMEOUT_STAT, TXC_OS_RESOURCE_EMPTY_STAT             *
 *                                                                      *
 *  CAVEATS:                                                            *
 *                                                                      *
 *                                                                      *
 *                                                                      *
 *  REVISION HISTORY:                                                   *
 *          Date        Author          Description                     *
 *  ------------------------------------------------------------------- *
 *  1.0     20-Mar-01   R. Ruchandani   Initial Revision                *
 *  1.1     25-Apr-02   B. Hawthorne    Adding VxWorks RTOS support.    *
 *  1.2     02-Oct-02   R. Kuhnen       1) Added check if parameter     *
 *                                         milliSecondsWait = 0 then    *
 *                                         exit with TXC_NO_ERR         *
 *                                      2) Removed sigfillset           *
 *                                      3) Changed timeOut.tv_nsec      *
 *                                         computation                  *
 *                                                                      *
 ************************************************************************/

TXC_U16BIT TXC_WaitOnSignal (TXC_U32BIT signalMask, TXC_U32BIT milliSecondsWait)
{
    TXC_U16BIT txcError;

#ifdef TXC_PSOS

    unsigned long flags, timeoutTicks, msPerTick, psosError, eventsReceived;

    if (milliSecondsWait == 0)
        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_TASK_WAIT_NEVER : /* no wait */
            flags = EV_NOWAIT | EV_ALL;
            timeoutTicks = 0;
            break;

        case TXC_OS_TASK_WAIT_FOREVER: /* just wait */
            flags = EV_WAIT | EV_ALL;
            timeoutTicks = 0;
            break;

        default: /* wait a period of time.  Determine how many ticks, rounded to the nearest tick */
            flags = EV_WAIT | EV_ALL;
            msPerTick = 1000 / KC_TICKS2SEC;
            milliSecondsWait += (msPerTick / 2);
            timeoutTicks = milliSecondsWait / msPerTick;
            break;
    }
    
    /* Call the psos function */
    psosError = ev_receive (signalMask, flags, timeoutTicks, &eventsReceived);

    /* 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;

        /* signal pending, applies only to ms time = 0 */
        case ERR_NOEVS:
            txcError = TXC_OS_RESOURCE_EMPTY_STAT;
            break;

        default:
            txcError = TXC_OS_RESOURCE_ERR;
    }

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

    struct siginfo eventsReceived;
    struct timespec timeOut;
    int sigError, osErrno;
    sigset_t sigSet;

    if (milliSecondsWait == 0)
        return TXC_NO_ERR;

    txcError = TXC_NO_ERR;

    sigError = sigemptyset(&sigSet);
    if (sigError == ERROR)
        txcError = TXC_OS_RESOURCE_ERR;
    else
        txcError = TXC_NO_ERR;

    if (txcError == TXC_NO_ERR)
    sigError = sigaddset(&sigSet, (int)signalMask);
    if (sigError == ERROR)
        txcError = TXC_OS_RESOURCE_ERR;
    else
        txcError = TXC_NO_ERR;

    if (txcError == TXC_NO_ERR)
    sigError = sigismember(&sigSet, (int)signalMask);
    if ( (sigError == ERROR) || (sigError == TXC_FALSE) )
        txcError = TXC_OS_RESOURCE_ERR;
    else
        txcError = TXC_NO_ERR;

    if (txcError == TXC_NO_ERR)
    {
        if (milliSecondsWait == TXC_OS_TASK_WAIT_FOREVER)
        {
            sigError = sigtimedwait(&sigSet, &eventsReceived, TXC_NULL);
            if (sigError == ERROR)
                txcError = TXC_OS_RESOURCE_ERR;
            else
                txcError = TXC_NO_ERR;
        }
        else 
        /***wait for a specified time***/
        {
            timeOut.tv_sec  = milliSecondsWait/1000;
            timeOut.tv_nsec = (milliSecondsWait % 1000) * 1000000;
            sigError = sigtimedwait(&sigSet, &eventsReceived, &timeOut);
            if (sigError == ERROR)
            {
                osErrno = errnoGet();
                switch(osErrno)
                {
                    /***general timeout***/
                    case EAGAIN: 
                        if(milliSecondsWait == 0)
                            txcError = TXC_OS_RESOURCE_EMPTY_STAT;
                        else
                            txcError = TXC_OS_TIMEOUT_STAT;
                        break;
                    default:
                        txcError = TXC_OS_RESOURCE_ERR;
                        break;
                }
            }
            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;

}


⌨️ 快捷键说明

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