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

📄 net_nic.c

📁 从Luminary官方网站下载的LM3S6000系列的UCos+Tcp/IP的源码, 经本人稍微修改后可直接在IAR6.2下编译通过,里面包括了LM3S6000系列的所有外设UART, PWn....
💻 C
📖 第 1 页 / 共 4 页
字号:
/*
*********************************************************************************************************
*                                              uC/TCP-IP
*                                      The Embedded TCP/IP Suite
*
*                          (c) Copyright 2003-2007; Micrium, Inc.; Weston, FL
*
*               All rights reserved.  Protected by international copyright laws.
*
*               uC/TCP-IP is provided in source form for FREE evaluation, for educational
*               use or peaceful research.  If you plan on using uC/TCP-IP in a commercial
*               product you need to contact Micrium to properly license its use in your
*               product.  We provide ALL the source code for your convenience and to help
*               you experience uC/TCP-IP.  The fact that the source code is provided does
*               NOT mean that you can use it without paying a licensing fee.
*
*               Network Interface Card (NIC) port files provided, as is, for FREE and do
*               NOT require any additional licensing or licensing fee.
*
*               Knowledge of the source code may NOT be used to develop a similar product.
*
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                        NETWORK INTERFACE CARD
*
*                                      LuminaryMicro LM3Snnnn EMAC
*
* Filename      : net_nic.c
* Version       : V1.90
* Programmer(s) : BAN
*********************************************************************************************************
* Note(s)       : (1) Supports EMAC section of LuminaryMicro's LM3Snnnn microcontroller.
*
*                 (2) REQUIREs Ethernet Network Interface Layer located in the following network directory :
*
*                         \<Network Protocol Suite>\IF\Ether\
*
*                              where
*                                      <Network Protocol Suite>    directory path for network protocol suite
*
*                 (3) Since the LM3Snnnn EMAC (NIC) module is integrated into the LM3Snnnn microcontroller,
*                     the endianness of the registers is the same as the CPU, which is little-endian by default.
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                            INCLUDE FILES
*********************************************************************************************************
*/

#define   NET_NIC_MODULE
#include  <net.h>
#include  <net_phy.h>
#include  <net_phy_def.h>

#include  <hw_ints.h>
#include  <hw_memmap.h>
#include  <hw_types.h>
#include  <interrupt.h>
#include  <sysctl.h>


/*
*********************************************************************************************************
*                                    LM3SNNNN REGISTER DEFINITIONS
*********************************************************************************************************
*/

                                                                        /* --------------- LM3Sxxx EMAC Registers ----------------- */
#define  MACIS          (*(volatile CPU_INT32U *)0x40048000)         	/* Interrupt status/acknowledgement register                */
#define  MACIM          (*(volatile CPU_INT32U *)0x40048004)         	/* Interrupt mask register                                  */
#define  MACRCTL        (*(volatile CPU_INT32U *)0x40048008)           	/* Receive  control register                                */
#define  MACTCTL        (*(volatile CPU_INT32U *)0x4004800C)          	/* Transmit control register                                */
#define  MACDATA        (*(volatile CPU_INT32U *)0x40048010)         	/* FIFO data access                                         */
#define  MACIA0         (*(volatile CPU_INT32U *)0x40048014)           	/* MAC address register 0                                   */
#define  MACIA1         (*(volatile CPU_INT32U *)0x40048018)           	/* MAC address register 1                                   */
#define  MACTHR         (*(volatile CPU_INT32U *)0x4004801C)        	/* MAC transmit threshold register                          */
#define  MACMCTL        (*(volatile CPU_INT32U *)0x40048020)        	/* MAC management control register                          */
#define  MACMDV         (*(volatile CPU_INT32U *)0x40048024)          	/* MAC management divider register                          */
#define  MACMADD        (*(volatile CPU_INT32U *)0x40048028)         	/* MAC management address register                          */
#define  MACMTXD        (*(volatile CPU_INT32U *)0x4004802C)         	/* MAC management transmit data                             */
#define  MACMRXD        (*(volatile CPU_INT32U *)0x40048030)           	/* MAC management receive  data                             */
#define  MACNP          (*(volatile CPU_INT32U *)0x40048034)          	/* Number of packets                                        */
#define  MACTR          (*(volatile CPU_INT32U *)0x40048038)           	/* Transmission request register                            */
#define  MACTS          (*(volatile CPU_INT32U *)0x4004803C)          	/* Timer support register                                   */


/*
*********************************************************************************************************
*                                LM3SNNNN REGISTER BIT DEFINITIONS
*********************************************************************************************************
*/

                                                                        /* -------- LM3Sxxx EMAC Registers Bit Defintions --------- */
#define  MACIS_RXINT                    DEF_BIT_00
#define  MACIS_TXER                     DEF_BIT_01
#define  MACIS_TXEMP                    DEF_BIT_02
#define  MACIS_FOV                      DEF_BIT_03
#define  MACIS_RXER                     DEF_BIT_04
#define  MACIS_MDINT                    DEF_BIT_05
#define  MACIS_PHY                      DEF_BIT_06

#define  MACIM_RXINTM                   DEF_BIT_00
#define  MACIM_TXERM                    DEF_BIT_01
#define  MACIM_TXEMPM                   DEF_BIT_02
#define  MACIM_FOVM                     DEF_BIT_03
#define  MACIM_RXERM                    DEF_BIT_04
#define  MACIM_MDINTM                   DEF_BIT_05
#define  MACIM_PHY                      DEF_BIT_06

#define  MACRCTL_RSTFIFO                DEF_BIT_04
#define  MACRCTL_BADCRC                 DEF_BIT_03
#define  MACRCTL_PRMS                   DEF_BIT_02
#define  MACRCTL_AMUL                   DEF_BIT_01
#define  MACRCTL_RXEN                   DEF_BIT_00

#define  MACTCTL_DUPLEX                 DEF_BIT_04
#define  MACTCTL_CRC                    DEF_BIT_02
#define  MACTCTL_PADEN                  DEF_BIT_01
#define  MACTCTL_TXEN                   DEF_BIT_00

#define  MACIA0_MACOCT4                 0xFF000000
#define  MACIA0_MACOCT3                 0x00FF0000
#define  MACIA0_MACOCT2                 0x0000FF00
#define  MACIA0_MACOCT1                 0x000000FF

#define  MACIA1_MACOCT6                 0x0000FF00
#define  MACIA1_MACOCT5                 0x000000FF

#define  MACTHR_THRESH                  0x0000003F

#define  MACMCTL_REGADR                 0x000000F8
#define  MACMCTL_WRITE                  DEF_BIT_01
#define  MACMCTL_START                  DEF_BIT_00

#define  MACMDV_DIV                     0x000000FF

#define  MACMTXD_MDTX                   0x0000FFFF

#define  MACMRXD_MDRX                   0x0000FFFF

#define  MACNP_NPR                      0x0000003F

#define  MACTR_NEWTX                    DEF_BIT_00

#define  MACTS_TSEN                     DEF_BIT_00


/*
*********************************************************************************************************
*                                          DATA TYPES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                      GLOBAL VARIABLES
*********************************************************************************************************
*/

static  CPU_INT32U  EMAC_DataTemp;                                      /* First two bytes of packet, saved in RxPktGetSize()       */


/*
*********************************************************************************************************
*                                 LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/

                                                                        /* ------------------- LM3Sxxx FNCTS ---------------------- */

static  void        EMAC_Init                (NET_ERR      *perr);


                                                                        /* ------------------ LM3Sxxx RX FNCTS -------------------- */

static  void        EMAC_RxIntDis            (void);
static  void        EMAC_RxIntEn             (void);

static  void        EMAC_RxPkt               (void         *ppkt,
                                              CPU_INT16U    size,
                                              NET_ERR      *perr);

static  void        EMAC_RxPktDiscard        (CPU_INT16U    size);

                                                                        /* ------------------ LM3Sxxx TX FNCTS -------------------- */

static  void        EMAC_TxPkt               (void         *ppkt,
                                              CPU_INT16U    size,
                                              NET_ERR      *perr);


/*
*********************************************************************************************************
*********************************************************************************************************
*                                          GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                            NetNIC_Init()
*
* Description : (1) Initialize Network Interface Card :
*
*                   (a) Perform NIC Layer OS initialization
*                   (b) Initialize NIC status
*                   (c) Initialize NIC statistics & error counters
*                   (d) Initialize LM3Snnnn
*
*
* Argument(s) : perr        Pointer to variable that will hold the return error code from this function :
*
*                               NET_NIC_ERR_NONE                    Network interface card successfully initialized.
*
*                                                                   -------- RETURNED BY NetOS_NIC_Init() : --------
*                               NET_OS_ERR_INIT_NIC_TX_RDY          NIC transmit ready signal NOT successfully
*                                                                       initialized.
*                               NET_OS_ERR_INIT_NIC_TX_RDY_NAME     NIC transmit ready name   NOT successfully
*                                                                       configured.
* Return(s)   : none.
*
* Caller(s)   : Net_Init().
*
* Note(s)     : 1) This function calls EMAC_Init() which initializes the LM3Snnnn hardware.
*********************************************************************************************************
*/

void  NetNIC_Init (NET_ERR  *perr)
{                                                                       /* --------------- PERFORM NIC/OS INIT -------------------- */
    NetOS_NIC_Init(perr);                                               /* Create NIC objs.                                         */
    if (*perr != NET_OS_ERR_NONE) {
         return;
    }
                                                                        /* ----------------- INIT NIC STATUS ---------------------- */
    NetNIC_ConnStatus           =  DEF_OFF;
                                                                        /* ------------- INIT NIC STAT & ERR CTRS ----------------- */
#if (NET_CTR_CFG_STAT_EN        == DEF_ENABLED)
    NetNIC_StatRxPktCtr         =  0;
    NetNIC_StatTxPktCtr         =  0;
#endif

#if (NET_CTR_CFG_ERR_EN         == DEF_ENABLED)
    NetNIC_ErrRxPktDiscardedCtr =  0;
    NetNIC_ErrTxPktDiscardedCtr =  0;
#endif
                                                                        /* ----------------- INIT LPC2378 EMAC -------------------- */
    EMAC_Init(perr);
}

/*

⌨️ 快捷键说明

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