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

📄 net_nic.c

📁 从Luminary官方网站下载的LM3S6000系列的UCos+Tcp/IP的源码, 经本人稍微修改后可直接在IAR6.2下编译通过,里面包括了LM3S6000系列的所有外设UART, PWn....
💻 C
📖 第 1 页 / 共 4 页
字号:
*********************************************************************************************************
*                                            NetNIC_IntEn()
*
* Description : Enable NIC interrupts.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : Net_Init().
*********************************************************************************************************
*/

void  NetNIC_IntEn (NET_ERR  *perr)
{
    MACIM   = MACIM_RXINTM                                              /* Enable RX packet interrupt                               */
            | MACIM_TXEMPM                                              /* Enable TX packet interrupt                               */
            | MACIM_PHY;

    IntEnable(INT_ETH);                                                 /* Enable interrupt in NVIC                                 */

   *perr = NET_NIC_ERR_NONE;                                            /* Assign error                                             */
}

/*
*********************************************************************************************************
*                                        NetNIC_ConnStatusGet()
*
* Description : Get NIC's network connection status.
*
*               (1) Obtaining the NIC's network connection status is encapsulated in this function for the
*                   possibility that obtaining a NIC's connection status requires a non-trivial procedure.
*
*
* Argument(s) : none.
*
* Return(s)   : NIC network connection status :
*
*                   DEF_OFF     Network connection DOWN.
*                   DEF_ON      Network connection UP.
*
* Caller(s)   : NetIF_Pkt_Tx().
*********************************************************************************************************
*/

CPU_BOOLEAN  NetNIC_ConnStatusGet (void)
{
    return (NetNIC_ConnStatus);
}

/*
*********************************************************************************************************
*                                         NetNIC_ISR_Handler()
*
* Description : (1) Decode ISR :
*
*                   (a) Packet transmitted    (MACIS_TXEMP)
*                   (b) Packet received       (MACIS_RXINT)
*                   (c) Receive FIFO overflow (MACIS_FOV)
*                   (d) Receive error         (MACIS_RXER)
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : This is an ISR
*********************************************************************************************************
*/

void  NetNIC_ISR_Handler (void)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR      cpu_sr;
#endif
    CPU_INT32U  status;
    NET_ERR     err;


    CPU_CRITICAL_ENTER();                                               /* Tell uC/OS-II that we are starting an ISR                */
    OSIntNesting++;
    CPU_CRITICAL_EXIT();

    status  = MACIS;                                                    /* Read the interrupt status                                */
    MACIS   = status;                                                   /* Clear the interrupt status                               */

    if ((status & MACIS_TXEMP) > 0) {                                   /* A packet was sent                                        */
        NetOS_NIC_TxRdySignal();                                        /*  ... Signal the stack that it may transmit another frame */
    }

    if ((status & MACIS_RXINT) > 0) {                                   /* A packet was received                                    */
        EMAC_RxIntDis();                                                /*  ... Disable receive interrupts                          */
        NetOS_IF_RxTaskSignal(&err);                                    /*  ... Signal Net IF Rx Task of NIC rx pkt.                */
    }

    if ((status & MACIS_PHY) > 0) {
        NetNIC_PhyISR_Handler();
    }

    OSIntExit();                                                        /* Tell uC/OS-II that we are leaving the ISR                */
}

/*
*********************************************************************************************************
*                                         NetNIC_RxPktGetSize()
*
* Description : Get network packet size from NIC.
*
* Argument(s) : none.
*
* Return(s)   : Size, in octets, of next frame to be read from the EMAC receive FIFO.
*
* Caller(s)   : NetIF_RxTaskHandler()
*
* Notes       : (1) The first two bytes of the FIFO are the packet length (which includes the FCS).  The
*                   next two bytes of the FIFO contain the first two bytes of the packet, which must be
*                   stored.
*********************************************************************************************************
*/

CPU_INT16U  NetNIC_RxPktGetSize (void)
{
    CPU_INT32U  temp;
    CPU_INT32U  size;


    if ((MACNP & MACNP_NPR) == 0) {                                     /* There is no packet in the FIFO                           */
        return (0);                                                     /*  ... Return 0                                            */
    }

    temp = MACDATA;                                                     /* Read word from FIFO                                      */

    if ((temp & 0x0000FFFF) < 6) {                                      /* If sufficient data was not received                      */
        size = 0;                                                       /*  ... Return size of zero                                 */
    } else {                                                            /* If sufficient data was     received                      */
        size = (temp & 0x0000FFFF) - 6;                                 /*  ... Subtract 6 = 4 (for FCS) + 2 (for size)             */
        if (size >= 2028) {
            size = 0;
        } else {
            EMAC_DataTemp = temp >> 16;                                 /*  ... Store first two bytes of packet                     */
        }
    }

    return (size);                                                      /* Return the size of the current frame                     */
}

/*
*********************************************************************************************************
*                                            NetNIC_RxPkt()
*
* Description : Read network packet from NIC into buffer.
*
* Argument(s) : ppkt        Pointer to memory buffer to receive NIC packet.
*
*               size        Number of packet frame octets to read into buffer.
*
*               perr        Pointer to variable that will hold the return error code from this function :
*
*                               NET_NIC_ERR_NONE            Packet successfully read.
*                               NET_ERR_INIT_INCOMPLETE     Network initialization NOT complete.
*                               NET_NIC_ERR_NULL_PTR        Argument 'ppkt' passed a NULL pointer.
*                               NET_NIC_ERR_INVALID_SIZE    Invalid size.
*
* Return(s)   : none.
*
* Caller(s)   : NetIF_RxTaskHandler().
*
* Note(s)     : 1) NetNIC_RxPkt() blocked until network initialization completes; perform NO action.
*********************************************************************************************************
*/

void  NetNIC_RxPkt (void        *ppkt,
                    CPU_INT16U   size,
                    NET_ERR     *perr)
{
#if ((NET_CTR_CFG_STAT_EN     == DEF_ENABLED)                    && \
     (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL))
    CPU_SR  cpu_sr;
#endif


    if (Net_InitDone != DEF_YES) {                                      /* If init NOT complete, exit rx (see Note #2).         */
       *perr = NET_ERR_INIT_INCOMPLETE;
        return;
    }

#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)                         /* ------------------- VALIDATE PTR ------------------  */
    if (ppkt == (void *)0) {
       *perr = NET_NIC_ERR_NULL_PTR;
        return;
    }

                                                                        /* ------------------- VALIDATE SIZE -----------------  */
    if (size < NET_IF_FRAME_MIN_SIZE) {
       *perr = NET_NIC_ERR_INVALID_SIZE;
        return;
    }
#endif

    EMAC_RxPkt(ppkt, size, perr);                                       /* Read the received Frame from the EMAC buffers        */
    if (*perr != NET_NIC_ERR_NONE) {
        return;
    }

    NET_CTR_STAT_INC(NetNIC_StatRxPktCtr);

    *perr = NET_NIC_ERR_NONE;
}

/*
*********************************************************************************************************
*                                         NetNIC_RxPktDiscard()
*
* Description : Discard network packet from NIC to free NIC packet frames for new receive packets.
*
* Argument(s) : size        Number of packet frame octets.
*
*               perr        Pointer to variable that will hold the return error code from this function :
*
*                               NET_NIC_ERR_NONE            Packet successfully discarded.
*                               NET_ERR_INIT_INCOMPLETE     Network initialization NOT complete.
*
* Return(s)   : none.
*
* Caller(s)   : NetIF_RxTaskHandler().
*
* Note(s)     : (1) NetNIC_RxPktDiscard() blocked until network initialization completes; perform NO action.
*
*               (2) #### 'perr' may NOT be necessary (remove before product release if unnecessary).
*********************************************************************************************************
*/

void  NetNIC_RxPktDiscard (CPU_INT16U   size,
                           NET_ERR     *perr)
{
#if ((NET_CTR_CFG_ERR_EN      == DEF_ENABLED)                    && \
     (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL))
    CPU_SR  cpu_sr;
#endif

    if (Net_InitDone != DEF_YES) {                                      /* If init NOT complete, exit discard (see Note #1).    */
       *perr = NET_ERR_INIT_INCOMPLETE;
        return;
    }

    EMAC_RxPktDiscard(size);

    NET_CTR_ERR_INC(NetNIC_ErrRxPktDiscardedCtr);

   *perr = NET_NIC_ERR_NONE;
}

/*
*********************************************************************************************************
*                                             NetNIC_TxPkt()
*
* Description : Transmit data packets from network driver layer to network interface card.
*
* Argument(s) : ppkt        Pointer to memory buffer to transmit NIC packet.
*
*               size        Number of packet frame octets to write to frame.
*

⌨️ 快捷键说明

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