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

📄 net_os.c

📁 从Luminary官方网站下载的LM3S6000系列的UCos+Tcp/IP的源码, 经本人稍微修改后可直接在IAR6.2下编译通过,里面包括了LM3S6000系列的所有外设UART, PWn....
💻 C
📖 第 1 页 / 共 5 页
字号:
/*$PAGE*/
/*
*********************************************************************************************************
*                                        NetOS_NIC_TxRdyWait()
*
* Description : Wait on NIC transmit ready signal.
*
* Argument(s) : perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_NIC_ERR_NONE                        NIC transmit ready signal     received.
*                               NET_NIC_ERR_TX_RDY_SIGNAL_TIMEOUT       NIC transmit ready signal NOT received
*                                                                           by timeout.
*                               NET_NIC_ERR_TX_RDY_SIGNAL_FAULT         NIC transmit ready signal fault.
*
* Return(s)   : none.
*
* Caller(s)   : NetIF_Pkt_Tx(),
*               NetIF_Char_Tx().
*
*               This function is a network interface (IF) to network interface controller (NIC) function 
*               & SHOULD be called only by appropriate network interface function(s).
*
* Note(s)     : (1) (a) If timeouts NOT desired, wait on NIC transmit ready signal forever (i.e. do NOT exit).
*
*                   (b) If timeout      desired, return NET_NIC_ERR_TX_RDY_SIGNAL_TIMEOUT error on transmit 
*                       ready timeout.  Implement timeout with OS-dependent functionality.
*********************************************************************************************************
*/

void  NetOS_NIC_TxRdyWait (NET_ERR  *perr)
{
    INT8U  os_err;


    OSSemPend((OS_EVENT *) NetOS_NIC_TxRdySignalPtr,            /* Wait on NIC transmit ready signal ...                */
              (INT16U    ) 0,                                   /* ... preferably without timeout (see Note #1a).       */
              (INT8U    *)&os_err);

    switch (os_err) {
        case OS_ERR_NONE:
            *perr = NET_NIC_ERR_NONE;
             break;


        case OS_ERR_TIMEOUT:
            *perr = NET_NIC_ERR_TX_RDY_SIGNAL_TIMEOUT;          /* See Note #1b.                                        */
             break;


        case OS_ERR_PEVENT_NULL:
        case OS_ERR_EVENT_TYPE:
        case OS_ERR_PEND_ISR:
        case OS_ERR_PEND_ABORT:
        default:
            *perr = NET_NIC_ERR_TX_RDY_SIGNAL_FAULT;
             break;
    }
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                       NetOS_NIC_TxRdySignal()
*
* Description : Signal NIC transmit that NIC transmit buffer is ready.
*
* Argument(s) : psignal     Pointer to value that signals NIC transmit.
*
* Return(s)   : none.
*
* Caller(s)   : NetNIC_TxISR_Handler().
*
*               This function is a network protocol suite to network interface controller (NIC) function
*               & SHOULD be called only by appropriate network interface controller function(s).
*
* Note(s)     : (1) #### NIC transmit ready MUST be signaled--i.e. MUST signal without failure.
*
*                   Failure to signal NIC transmit ready will prevent NIC from transmitting packets.
*********************************************************************************************************
*/

void  NetOS_NIC_TxRdySignal (void)
{
    INT8U  os_err;

                                                                /* Signal NIC transmit that transmit ready.             */
    os_err = OSSemPost(NetOS_NIC_TxRdySignalPtr);

   (void)&os_err;                                               /* See Note #1.                                         */
}


/*$PAGE*/
/*
*********************************************************************************************************
*********************************************************************************************************
*                                  NETWORK INTERFACE LAYER FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                           NetOS_IF_Init()
*
* Description : (1) Perform network interface/OS initialization :
*
*                   (a) Implement network interface queue by creating a counting semaphore.
*
*                       Initialize network interface queue with no received packets by setting the semaphore
*                       count to 0 to block the network interface queue semaphore.
*
*                   (b) Create network IF Receive Task.
*
*
* Argument(s) : perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_OS_ERR_NONE                     Network interface/OS initialization
*                                                                           successful.
*                               NET_OS_ERR_INIT_IF_RX_Q             Network interface receive queue signal
*                                                                       NOT successfully initialized.
*                               NET_OS_ERR_INIT_IF_RX_Q_NAME        Network interface receive queue name
*                                                                       NOT successfully configured.
*                               NET_OS_ERR_INIT_IF_RX_TASK          Network interface receive task
*                                                                       NOT successfully initialized.
*                               NET_OS_ERR_INIT_IF_RX_TASK_NAME     Network interface receive task  name
*                                                                       NOT successfully configured.
*
* Return(s)   : none.
*
* Caller(s)   : NetIF_Pkt_Init(),
*               NetIF_Char_Init().
*
*               This function is an INTERNAL network protocol suite function & MUST NOT be called by 
*               application function(s).
*
* Note(s)     : none.
*********************************************************************************************************
*/
/*$PAGE*/
void  NetOS_IF_Init (NET_ERR  *perr)
{
    INT8U  os_err;


                                                                            /* Create receive queue     (see Note #1a). */
    NetOS_IF_RxQ_SignalPtr = OSSemCreate((INT16U)0);
    if (NetOS_IF_RxQ_SignalPtr == (OS_EVENT *)0) {
       *perr = NET_OS_ERR_INIT_IF_RX_Q;
        return;
    }

#if (OS_EVENT_NAME_SIZE >= NET_OBJ_NAME_SIZE_MAX)
    OSEventNameSet((OS_EVENT *) NetOS_IF_RxQ_SignalPtr,
                   (INT8U    *) NET_IF_RX_Q_NAME,
                   (INT8U    *)&os_err);
    if (os_err !=  OS_ERR_NONE) {
       *perr = NET_OS_ERR_INIT_IF_RX_Q_NAME;
        return;
    }
#endif


                                                                            /* Create NetOS_IF_RxTask() [see Note #1b]. */
#if (OS_TASK_CREATE_EXT_EN == 1)

#if (OS_STK_GROWTH == 1)
    os_err = OSTaskCreateExt((void (*)(void *)) NetOS_IF_RxTask,
                             (void          * ) 0,
                             (OS_STK        * )&NetOS_IF_RxTaskStk[NET_OS_CFG_IF_RX_TASK_STK_SIZE - 1],
                             (INT8U           ) NET_OS_CFG_IF_RX_TASK_PRIO,
                             (INT16U          ) NET_OS_CFG_IF_RX_TASK_PRIO, /* Set task id same as task prio.           */
                             (OS_STK        * )&NetOS_IF_RxTaskStk[0],
                             (INT32U          ) NET_OS_CFG_IF_RX_TASK_STK_SIZE,
                             (void          * ) 0,
                             (INT16U          )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK));
#else
    os_err = OSTaskCreateExt((void (*)(void *)) NetOS_IF_RxTask,
                             (void          * ) 0,
                             (OS_STK        * )&NetOS_IF_RxTaskStk[0],
                             (INT8U           ) NET_OS_CFG_IF_RX_TASK_PRIO,
                             (INT16U          ) NET_OS_CFG_IF_RX_TASK_PRIO, /* Set task id same as task prio.           */
                             (OS_STK        * )&NetOS_IF_RxTaskStk[NET_OS_CFG_IF_RX_TASK_STK_SIZE - 1],
                             (INT32U          ) NET_OS_CFG_IF_RX_TASK_STK_SIZE,
                             (void          * ) 0,
                             (INT16U          )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK));
#endif

#else

#if (OS_STK_GROWTH == 1)
    os_err = OSTaskCreate((void (*)(void *)) NetOS_IF_RxTask,
                          (void          * ) 0,
                          (OS_STK        * )&NetOS_IF_RxTaskStk[NET_OS_CFG_IF_RX_TASK_STK_SIZE - 1],
                          (INT8U           ) NET_OS_CFG_IF_RX_TASK_PRIO);
#else
    os_err = OSTaskCreate((void (*)(void *)) NetOS_IF_RxTask,
                          (void          * ) 0,
                          (OS_STK        * )&NetOS_IF_RxTaskStk[0],
                          (INT8U           ) NET_OS_CFG_IF_RX_TASK_PRIO);
#endif

#endif
    if (os_err !=  OS_ERR_NONE) {
       *perr = NET_OS_ERR_INIT_IF_RX_TASK;
        return;
    }


#if (OS_TASK_NAME_SIZE >= NET_TASK_NAME_SIZE_MAX)
    OSTaskNameSet((INT8U  ) NET_OS_CFG_IF_RX_TASK_PRIO,
                  (INT8U *) NET_IF_RX_TASK_NAME,
                  (INT8U *)&os_err);
    if (os_err !=  OS_ERR_NONE) {
       *perr = NET_OS_ERR_INIT_IF_RX_TASK_NAME;
        return;
    }
#endif


   *perr = NET_OS_ERR_NONE;
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                        NetOS_IF_RxTask()
*
* Description : OS-dependent shell task to schedule & run Network Interface Receive Task Handler.
*
*               (1) Shell task's primary purpose is to schedule & run NetIF_RxTaskHandler() forever;
*                   (i.e. shell task should NEVER exit).
*
*
* Argument(s) : p_data      Pointer to task initialization data (required by uC/OS-II).
*
* Return(s)   : none.
*
* Created by  : NetOS_IF_Init().
*
* Note(s)     : none.
*********************************************************************************************************
*/

static  void  NetOS_IF_RxTask (void  *p_data)
{
   (void)&p_data;                                               /* Prevent compiler warning.                            */

    NetIF_RxTaskHandlerInit();
    while (DEF_ON) {
        NetIF_RxTaskHandler();
    }
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                        NetOS_IF_RxTaskWait()
*
* Description : Wait on network interface receive queue for NIC receive signal.
*
* Argument(s) : perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_IF_ERR_NONE                 Signal received from NIC receive ISR.
*                               NET_IF_ERR_RX_Q_EMPTY           Network interface receive queue empty.
*                               NET_IF_ERR_RX_Q_SIGNAL_FAULT    Network interface receive queue signal fault.
*
* Return(s)   : none.
*
* Caller(s)   : NetIF_RxTaskHandler().
*
*               This function is an INTERNAL network protocol suite function & MUST NOT be called by 
*               application function(s).
*
* Note(s)     : (1) (a) If timeouts NOT desired, wait on network interface receive queue until signaled
*                       (i.e. do NOT exit).
*
*                   (b) If timeout      desired, return NET_IF_ERR_RX_Q_EMPTY error on receive queue 
*                       timeout.  Implement timeout with OS-dependent functionality.
*********************************************************************************************************
*/

void  NetOS_IF_RxTaskWait (NET_ERR  *perr)
{
    INT8U  os_err;


    OSSemPend((OS_EVENT *) NetOS_IF_RxQ_SignalPtr,              /* Wait on network interface receive queue ...          */
              (INT16U    ) 0,                                   /* ... preferably without timeout (see Note #1a).       */
              (INT8U    *)&os_err);

    switch (os_err) {
        case OS_ERR_NONE:
            *perr = NET_IF_ERR_NONE;
             break;


        case OS_ERR_TIMEOUT:
            *perr = NET_IF_ERR_RX_Q_EMPTY;                      /* See Note #1b.                                        */
             break;


        case OS_ERR_PEVENT_NULL:
        case OS_ERR_EVENT_TYPE:
        case OS_ERR_PEND_ISR:
        case OS_ERR_PEND_ABORT:
        default:
            *perr = NET_IF_ERR_RX_Q_SIGNAL_FAULT;
             break;
    }
}

⌨️ 快捷键说明

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