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

📄 net_os.c

📁 AT91SAM7X256微处理器
💻 C
📖 第 1 页 / 共 5 页
字号:
                                                            /* Initialize net transmit suspend signal timeout value.    */
    NetOS_TxSuspendTimeoutSet(NET_CFG_TX_SUSPEND_TIMEOUT_MS, &net_err);
    if (net_err != NET_ERR_NONE) {
       *perr = NET_OS_ERR_INIT_TX_SUSPEND_TIMEOUT;
        return;
    }

#if (OS_EVENT_NAME_SIZE >= NET_OBJ_NAME_SIZE_MAX)
    OSEventNameSet((OS_EVENT *) NetOS_TxSuspendSignalPtr,
                   (INT8U    *) NET_TX_SUSPEND_NAME,
                   (INT8U    *)&os_err);
    if (os_err != OS_NO_ERR) {
       *perr = NET_OS_ERR_INIT_TX_SUSPEND_NAME;
        return;
    }
#endif
#endif


   *perr = NET_OS_ERR_NONE;
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                          NetOS_InitWait()
*
* Description : Wait on signal indicating network initialization is complete.
*
* Argument(s) : perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_OS_ERR_NONE                 Initialization signal     received.
*                               NET_OS_ERR_INIT                 Initialization signal NOT received.
*
* Return(s)   : none.
*
* Caller(s)   : NetIF_RxTaskHandler(),
*               NetTmr_TaskHandler().
*
* Note(s)     : (1) Network initialization signal MUST be acquired--i.e. MUST wait for access; do NOT timeout.
*
*                   Failure to acquire signal will prevent network task(s) from running.
*********************************************************************************************************
*/

void  NetOS_InitWait (NET_ERR  *perr)
{
    INT8U  os_err;


    OSSemPend(NetOS_InitSignalPtr, (INT16U)0, &os_err);         /* Wait until network initialization complete.          */

    switch (os_err) {
        case OS_NO_ERR:
            *perr = NET_OS_ERR_NONE;
             break;


        case OS_TIMEOUT:
        case OS_ERR_EVENT_TYPE:
        case OS_ERR_PEVENT_NULL:
        case OS_ERR_PEND_ISR:
        default:
            *perr = NET_OS_ERR_INIT;
             break;
    }
}


/*
*********************************************************************************************************
*                                         NetOS_InitSignal()
*
* Description : Signal that network initialization is complete.
*
* Argument(s) : perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_OS_ERR_NONE                 Network initialization     successfully signaled.
*                               NET_OS_ERR_INIT_SIGNALD         Network initialization NOT successfully signaled.
*
* Return(s)   : none.
*
* Caller(s)   : Net_Init().
*
* Note(s)     : (1) Network initialization MUST be signaled--i.e. MUST signal without failure.
*
*                   Failure to signal will prevent network task(s) from running.
*********************************************************************************************************
*/

void  NetOS_InitSignal (NET_ERR  *perr)
{
    INT8U  os_err;


    os_err = OSSemPost(NetOS_InitSignalPtr);                    /* Signal network initialization complete.              */
    if (os_err != OS_NO_ERR) {
       *perr = NET_OS_ERR_INIT_SIGNALD;
    }

    *perr = NET_OS_ERR_NONE;
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                            NetOS_Lock()
*
* Description : Acquire mutually exclusive access to network protocol suite.
*
* Argument(s) : perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_OS_ERR_NONE                 Network access     acquired.
*                               NET_OS_ERR_LOCK                 Network access NOT acquired.
*
* Return(s)   : none.
*
* Caller(s)   : NetIF_RxTaskHandler(),
*               NetTmr_TaskHandler().
*
* Note(s)     : (1) Network access MUST be acquired--i.e. MUST wait for access; do NOT timeout.
*
*                   Failure to acquire network access will prevent network task(s)/operation(s)
*                   from functioning.
*********************************************************************************************************
*/

void  NetOS_Lock (NET_ERR  *perr)
{
    INT8U  os_err;


    OSSemPend(NetOS_LockPtr, (INT16U)0, &os_err);               /* Acquire network access.                              */

    switch (os_err) {
        case OS_NO_ERR:
            *perr = NET_OS_ERR_NONE;
             break;


        case OS_TIMEOUT:
        case OS_ERR_EVENT_TYPE:
        case OS_ERR_PEVENT_NULL:
        case OS_ERR_PEND_ISR:
        default:
            *perr = NET_OS_ERR_LOCK;
             break;
    }
}


/*
*********************************************************************************************************
*                                           NetOS_Unlock()
*
* Description : Release mutually exclusive access to network protocol suite.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : NetIF_RxTaskHandler(),
*               NetTmr_TaskHandler().
*
* Note(s)     : (1) Network access MUST be released--i.e. MUST unlock access without failure.
*
*                   Failure to release network access will prevent network task(s)/operation(s)
*                   from functioning.
*********************************************************************************************************
*/

void  NetOS_Unlock (void)
{
   (void)OSSemPost(NetOS_LockPtr);                              /* Release network access.                              */
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                        NetOS_TxSuspendWait()
*
* Description : Wait on network transmit suspend signal.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : Net_TxSuspend().
*
* Note(s)     : (1) Network transmit suspend waits until :
*
*                   (a) Signaled
*                   (b) Timed out
*                   (c) Any OS fault occurs
*
*               (2) Implement timeout with OS-dependent function.
*********************************************************************************************************
*/

#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
void  NetOS_TxSuspendWait (void)
{
    INT8U  os_err;

                                                                /* Wait on network transmit suspend signal.               */
    OSSemPend(NetOS_TxSuspendSignalPtr, NetOS_TxSuspendTimeout_tick, &os_err);

   (void)os_err;
}
#endif


/*$PAGE*/
/*
*********************************************************************************************************
*                                       NetOS_TxSuspendSignal()
*
* Description : Signal network transmit suspend.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : Net_TxSuspendSignal().
*
* Note(s)     : (1) Failure to signal network transmit suspend signal will cause network transmit suspends
*                   to timeout.
*
*                   See also 'NetOS_TxSuspendWait()  Note #1b'.
*********************************************************************************************************
*/

#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
void  NetOS_TxSuspendSignal (void)
{
   (void)OSSemPost(NetOS_TxSuspendSignalPtr);                   /* Signal network transmit suspend.                     */
}
#endif


/*$PAGE*/
/*
*********************************************************************************************************
*                                     NetOS_TxSuspendTimeoutSet()
*
* Description : Set network transmit suspend timeout value.
*
* Argument(s) : timeout_ms      Timeout value (in milliseconds).
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_ERR_NONE                    Network transmit suspend timeout successfully set.
*
*                                                               --- RETURNED BY NetOS_TimeoutCalc_OS_tick() : ----
*                               NET_OS_ERR_INVALID_TIME         Invalid time value.
*
* Return(s)   : none.
*
* Caller(s)   : NetOS_Init(),
*               Application.
*
* Note(s)     : none.
*********************************************************************************************************
*/

#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
void  NetOS_TxSuspendTimeoutSet (CPU_INT32U   timeout_ms,
                                 NET_ERR     *perr)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR  cpu_sr;
#endif
    INT16U  os_tick;


    os_tick = NetOS_TimeoutCalc_OS_tick(timeout_ms, perr);      /* Calculate timeout value (in OS ticks).               */
    if (*perr != NET_OS_ERR_NONE) {
         return;
    }

    CPU_CRITICAL_ENTER();
    NetOS_TxSuspendTimeout_tick = os_tick;                      /* Set OS tick timeout value.                           */
    CPU_CRITICAL_EXIT();
    

   *perr = NET_ERR_NONE;
}
#endif


/*$PAGE*/
/*
*********************************************************************************************************
*                                   NetOS_TxSuspendTimeoutGet_ms()
*
* Description : Get network transmit suspend timeout value.
*
* Argument(s) : perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_ERR_NONE                    Network transmit suspend timeout 
*                                                                   successfully returned.
*
* Return(s)   : Network transmit suspend timeout value (in milliseconds).
*
* Caller(s)   : Application.
*
* Note(s)     : none.
*********************************************************************************************************
*/

#if (NET_CFG_LOAD_BAL_EN == DEF_ENABLED)
CPU_INT32U  NetOS_TxSuspendTimeoutGet_ms (NET_ERR  *perr)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR      cpu_sr;
#endif
    INT16U      os_tick;
    CPU_INT16U  timeout_ms;


    CPU_CRITICAL_ENTER();
    os_tick    =  NetOS_TxSuspendTimeout_tick;                  /* Get OS tick timeout value.                           */
    CPU_CRITICAL_EXIT();

⌨️ 快捷键说明

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