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

📄 net_os.c

📁 AT91SAM7X256微处理器
💻 C
📖 第 1 页 / 共 5 页
字号:
*               (4) #### ICMP Receive Error/Reply Messages NOT yet implemented.
*
*                   See also 'net_icmp.c  NetICMP_Rx()  Note #4'.
*********************************************************************************************************
*/
/*$PAGE*/
NET_ICMP_REQ_ID_SEQ  NetOS_ICMP_TxMsgReq (CPU_INT08U    type,
                                          CPU_INT08U    code,
                                          NET_IP_TOS    TOS,
                                          NET_IP_TTL    TTL,
                                          NET_IP_ADDR   addr_dest,
                                          CPU_INT16U    flags,
                                          void         *popts,
                                          void         *p_data,
                                          CPU_INT16U    data_len,
                                          NET_ERR      *perr)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR               cpu_sr;
#endif
    CPU_INT16U           id;
    NET_ICMP_REQ_ID_SEQ  id_seq;


    CPU_CRITICAL_ENTER();
    id     = (CPU_INT16U)OSTCBCur->OSTCBPrio;                   /* Set task prio as ICMP Req Msg id (see Note #3b).     */
    CPU_CRITICAL_EXIT();

    id_seq =  NetICMP_TxMsgReq(type, code, id, TOS, TTL, addr_dest, flags, popts, p_data, data_len, perr);

    return (id_seq);
}


/*$PAGE*/
/*
*********************************************************************************************************
*********************************************************************************************************
*                            TRANSMISSION CONTROL PROTOCOL LAYER FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                          NetOS_TCP_Init()
*
* Description : (1) Perform TCP/OS initialization :
*
*                   (a) Create TCP connection receive  queue binary semaphores :
*
*                       (1) Initialize TCP connection receive queue binary semaphores with no received 
*                           packets  by setting the semaphore count to 0.
*                       (2) Initialize TCP connection receive queue timeout values.
*
*                   (b) Create TCP connection transmit queue binary semaphores :
*
*                       (1) Initialize TCP connection transmit queue binary semaphores with no transmit
*                           permissions by setting the semaphore count to 0.
*                       (2) Initialize TCP connection transmit queue timeout values.
*
*
* Argument(s) : perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_OS_ERR_NONE                     TCP/OS initialization successful.
*                               NET_OS_ERR_INIT_TCP_RX_Q            TCP receive  queue(s)         NOT 
*                                                                       successfully initialized.
*                               NET_OS_ERR_INIT_TCP_RX_Q_TIMEOUT    TCP receive  queue timeout(s) NOT 
*                                                                       successfully configured.
*                               NET_OS_ERR_INIT_TCP_TX_Q            TCP transmit queue(s)         NOT 
*                                                                       successfully initialized.
*                               NET_OS_ERR_INIT_TCP_TX_Q_TIMEOUT    TCP transmit queue timeout(s) NOT 
*                                                                       successfully configured.
*
* Return(s)   : none.
*
* Caller(s)   : NetTCP_Init().
*
* Note(s)     : none.
*********************************************************************************************************
*/
/*$PAGE*/
#ifdef  NET_TCP_MODULE_PRESENT
void  NetOS_TCP_Init (NET_ERR  *perr)
{
    OS_EVENT          **psignal;
    CPU_INT32U          timeout_ms;
    NET_TCP_CONN_QTY    i;
    NET_ERR             net_err;

                                                            /* Initialize TCP connection queues (see Note #1).          */

    psignal    = &NetOS_TCP_RxQ_SemPtr[0];
    timeout_ms = (NET_TCP_CFG_TIMEOUT_CONN_RX_Q_SEC != NET_TMR_TIME_INFINITE  ) ?
                 (NET_TCP_CFG_TIMEOUT_CONN_RX_Q_SEC *  DEF_TIME_NBR_mS_PER_SEC) :
                                                       NET_TMR_TIME_INFINITE;
    for (i = 0; i < NET_TCP_CFG_NBR_CONN; i++) {               
       *psignal = OSSemCreate((INT16U)0);                   /* Create     TCP connection receive queue semaphores.      */
        if (*psignal == (OS_EVENT *)0) {
            *perr = NET_OS_ERR_INIT_TCP_RX_Q;
             return;
        }
        psignal++;
                                                            /* Initialize TCP connection receive queue timeout values.  */
        NetOS_TCP_RxQ_TimeoutSet(i, timeout_ms, &net_err);
        if (net_err != NET_TCP_ERR_NONE) {
           *perr = NET_OS_ERR_INIT_TCP_RX_Q_TIMEOUT;
            return;
        }
    }


    psignal    = &NetOS_TCP_TxQ_SemPtr[0];
    timeout_ms = (NET_TCP_CFG_TIMEOUT_CONN_TX_Q_SEC != NET_TMR_TIME_INFINITE  ) ?
                 (NET_TCP_CFG_TIMEOUT_CONN_TX_Q_SEC *  DEF_TIME_NBR_mS_PER_SEC) :
                                                       NET_TMR_TIME_INFINITE;
    for (i = 0; i < NET_TCP_CFG_NBR_CONN; i++) {               
       *psignal = OSSemCreate((INT16U)0);                   /* Create     TCP connection transmit queue semaphores.     */
        if (*psignal == (OS_EVENT *)0) {
            *perr = NET_OS_ERR_INIT_TCP_TX_Q;
             return;
        }
        psignal++;
                                                            /* Initialize TCP connection transmit queue timeout values. */
        NetOS_TCP_TxQ_TimeoutSet(i, timeout_ms, &net_err);
        if (net_err != NET_TCP_ERR_NONE) {
           *perr = NET_OS_ERR_INIT_TCP_TX_Q_TIMEOUT;
             return;
        }
    }


   *perr = NET_OS_ERR_NONE;
}
#endif


/*$PAGE*/
/*
*********************************************************************************************************
*                                         NetOS_TCP_RxQ_Clr()
*
* Description : Clear TCP connection receive queue.
*
* Argument(s) : conn_id_tcp     Handle identifier of TCP connection to clear receive queue.
*               -----------     Argument validated in NetTCP_RxPktConnHandlerRxQ_AppData(),
*                                                     NetTCP_CloseHandler().
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_TCP_ERR_NONE                TCP connection receive queue successfully cleared.
*                               NET_TCP_ERR_RX_Q_CLR            TCP connection receive queue NOT          cleared.
*
* Return(s)   : none.
*
* Caller(s)   : NetTCP_RxPktConnHandlerRxQ_AppData(),
*               NetTCP_CloseHandler().
*
* Note(s)     : none.
*********************************************************************************************************
*/

#ifdef  NET_TCP_MODULE_PRESENT
void  NetOS_TCP_RxQ_Clr (NET_TCP_CONN_ID   conn_id_tcp,
                         NET_ERR          *perr)
{
    OS_EVENT  *psignal;
    INT16U     sem_cnt;
    INT8U      os_err;


    psignal = NetOS_TCP_RxQ_SemPtr[conn_id_tcp];
    sem_cnt = 0;
    OSSemSet(psignal, sem_cnt, &os_err);                        /* Clear TCP connection receive queue.                  */

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


        case OS_ERR_TASK_WAITING:                               /* If OS task waiting on semaphore          ...         */
             if (sem_cnt == 0) {                                /* ... but semaphore count cleared to zero, ...         */
                *perr = NET_TCP_ERR_NONE;                       /* ... return NO error.                                 */
             } else {
                *perr = NET_TCP_ERR_RX_Q_CLR;
             }
             break;


        case OS_ERR_EVENT_TYPE:
        case OS_ERR_PEVENT_NULL:
        default:
            *perr = NET_TCP_ERR_RX_Q_CLR;
             break;
    }
}
#endif


/*$PAGE*/
/*
*********************************************************************************************************
*                                         NetOS_TCP_RxQ_Wait()
*
* Description : Wait on TCP connection receive queue.
*
* Argument(s) : conn_id_tcp     Handle identifier of TCP connection to wait on receive queue.
*               -----------     Argument checked in NetTCP_RxAppData().
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_TCP_ERR_NONE                TCP connection receive queue non-empty.
*                               NET_TCP_ERR_RX_Q_EMPTY          TCP connection receive queue still empty by
*                                                                   timeout.
*
* Return(s)   : none.
*
* Caller(s)   : NetTCP_RxAppData().
*
* Note(s)     : (1) If timeouts NOT desired, wait on TCP connection receive queue forever (i.e. do NOT exit).
*
*               (2) If timeout desired, return NET_TCP_ERR_RX_Q_EMPTY error on TCP connection receive queue 
*                   timeout.  Implement timeout with OS-dependent function.
*********************************************************************************************************
*/

#ifdef  NET_TCP_MODULE_PRESENT
void  NetOS_TCP_RxQ_Wait (NET_TCP_CONN_ID   conn_id_tcp,
                          NET_ERR          *perr)
{
    OS_EVENT  *psignal;
    INT16U     os_tick;
    INT8U      os_err;


    psignal = NetOS_TCP_RxQ_SemPtr[conn_id_tcp];
    os_tick = NetOS_TCP_RxQ_TimeoutTbl_tick[conn_id_tcp];
    OSSemPend(psignal, os_tick, &os_err);                       /* Wait on TCP connection receive queue.                */

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


        case OS_TIMEOUT:
        case OS_ERR_EVENT_TYPE:
        case OS_ERR_PEVENT_NULL:
        case OS_ERR_PEND_ISR:
        default:
            *perr = NET_TCP_ERR_RX_Q_EMPTY;
             break;
    }
}
#endif


/*$PAGE*/
/*
*********************************************************************************************************
*                                       NetOS_TCP_RxQ_Signal()
*
* Description : Signal TCP connection receive queue.
*
* Argument(s) : conn_id_tcp     Handle identifier of TCP connection to signal receive queue.
*               -----------     Argument validated in NetTCP_RxAppData(),
*                                                     NetTCP_RxPktConnHandlerRxQ_AppData().
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_TCP_ERR_NONE                TCP connection receive queue successfully
*                                                                   signaled.
*                               NET_TCP_ERR_RX_Q_FULL           TCP connection receive queue full.
*                               NET_TCP_ERR_RX_Q_SIGNAL         TCP connection receive queue signal failed.
*
* Return(s)   : none.
*
* Caller(s)   : NetTCP_RxAppData(),
*               NetTCP_RxPktConnHandlerRxQ_AppData().
*
* Note(s)     : none.
*********************************************************************************************************
*/

#ifdef  NET_TCP_MODULE_PRESENT
void  NetOS_TCP_RxQ_Signal (NET_TCP_CONN_ID   conn_id_tcp,
                            NET_ERR          *perr)
{
    OS_EVENT  *psignal;
    INT8U      os_err;


    psignal = NetOS_TCP_RxQ_SemPtr[conn_id_tcp];
    os_err  = OSSemPost(psignal);                               /* Signal TCP connection receive queue.                 */

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


        case OS_SEM_OVF:
            *perr = NET_TCP_ERR_RX_Q_FULL;
             break;


        case OS_ERR_EVENT_TYPE:
        case OS_ERR_PEVENT_NULL:
        default:
            *perr = NET_TCP_ERR_RX_Q_SIGNAL;
             break;
    }
}
#endif


/*$PAGE*/
/*
*********************************************************************************************************
*                                     NetOS_TCP_RxQ_TimeoutSet()
*
* Description : Set TCP connection receive queue timeout value.
*
* Argument(s)

⌨️ 快捷键说明

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