1、UBOOT DM9000驱动完全注释UBOOT DM9000驱动完全注释UBOOT DM9000驱动完全注释#include ./include/dm9000x.h/* Board/System/Debug information/definition - */#define DM9801_NOISE_FLOOR 0x08#define DM9802_NOISE_FLOOR 0x05/* #define CONFIG_DM9000_DEBUG */#define DM9000_DBG(fmt,args.)/*=/DM9000芯片的PHY层模式/*=enum DM9000_PHY_mode DM
2、9000_10MHD = 0, DM9000_100MHD = 1, DM9000_10MFD = 4, DM9000_100MFD = 5, DM9000_AUTO = 8, DM9000_1M_HPNA = 0x10;/*=/DM9000芯片的网卡类型。NIC=network interface card/*=enum DM9000_NIC_TYPE FASTETHER_NIC = 0, HOMERUN_NIC = 1, LONGRUN_NIC = 2;/*=/DM9000芯片的数据结构/*=typedef struct board_info u32 runt_length_counter
3、; /接收报文长度小于64byte的计数器 u32 long_length_counter; / 接收报文长度大于1514byte 的计数器 u32 reset_counter; /复位计数 u32 reset_tx_timeout; / 由发送超时引起的复位 u32 reset_rx_status; /由接收状态引起的复位 u16 tx_pkt_cnt; /接收包计数 u16 queue_start_addr; /序列起始地址 u16 dbug_cnt; u8 phy_addr; /MAC地址 u8 device_wait_reset; / 设备状态 u8 nic_type; /网卡类型 u
4、nsigned char srom128; board_info_t;board_info_t dmfe_info;/*=/DM9000芯片的设置参数/*=static int media_mode = DM9000_AUTO;static u8 nfloor = 0;/*=/DM9000芯片的函数声明/*=int eth_init(bd_t * bd); /DM9000网卡初始化int eth_send(volatile void *, int); /将来自上层的数据包发送到媒介上int eth_rx(void); /接收数据包并且发送到上层去void eth_halt(void); /关闭
5、网卡static int dm9000_probe(void); /探测网卡芯片static u16 phy_read(int); /从物理层上读取一个字(16位)static void phy_write(int, u16); /往物理层上写一个字(16位)static u16 read_srom_word(int); /读取SROM中的一个字static u8 DM9000_ior(int); /从IO口上读取一个字节static void DM9000_iow(int reg, u8 value); /写一个字节到IO口上/*=/DM9000芯片的的寄存器操作宏,分为byte,word,
6、Dword三种/*=#define DM9000_outb(d,r) ( *(volatile u8 *)r = d )#define DM9000_outw(d,r) ( *(volatile u16 *)r = d )#define DM9000_outl(d,r) ( *(volatile u32 *)r = d )#define DM9000_inb(r) (*(volatile u8 *)r)#define DM9000_inw(r) (*(volatile u16 *)r)#define DM9000_inl(r) (*(volatile u32 *)r)/*=/函数名称:dm90
7、00_probe/函数功能:寻找DM9000芯片,分配内存空间,注册。/ 复位结束后到网卡的vendor ID寄存器和product ID寄存器读取id,/ 检测此网卡是否是dm9000。 /出口参数:无/入口参数:无/*=intdm9000_probe(void) u32 id_val; /32bit变量 id_val = DM9000_ior(DM9000_VIDL);/首先读VIDL vendor ID low byte id_val |= DM9000_ior(DM9000_VIDH) 8;/然后读VIDH vendor ID high byte id_val |= DM9000_io
8、r(DM9000_PIDL) 16;/再读PIDL Product ID low byte id_val |= DM9000_ior(DM9000_PIDH) nic_type = HOMERUN_NIC; program_dm9801(phy_reg3); DM9000_DBG(found homerun NICn); else db-nic_type = LONGRUN_NIC; DM9000_DBG(found longrun NICn); program_dm9802(); break; default: db-nic_type = FASTETHER_NIC; break; DM90
9、00_iow(DM9000_NCR, 0);/*=/函数名称:dm9000_reset/函数功能:DM9000的复位。/出口参数:无/入口参数:无/*=static voiddm9000_reset(void) DM9000_iow(DM9000_NCR, NCR_RST); OSTimeDly(1); /* delay 50ms */*=/函数名称:eth_init/函数功能:网卡的初始化/出口参数:无/入口参数:bd/*=inteth_init(bd_t * bd) int i, oft, lnk; /* RESET device */ dm9000_reset(); dm9000_pro
10、be(); /* NIC Type: FASTETHER, HOMERUN, LONGRUN */ identify_nic(); /* GPIO0 on pre-activate PHY */ DM9000_iow(DM9000_GPR, 0x00); /*REG_1F bit0 activate phyxcer */ /* Set PHY */ set_PHY_mode(); /* Program operating register */ DM9000_iow(DM9000_NCR, 0x0); /* only intern phy supported by now */ DM9000_
11、iow(DM9000_TCR, 0); /* TX Polling clear */ DM9000_iow(DM9000_BPTR, 0x3f); /* Less 3Kb, 200us */ DM9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8); /* Flow Control : High/Low Water */ DM9000_iow(DM9000_FCR, 0x0); /* SH FIXME: This looks strange! Flow Control */ DM9000_iow(DM9000_SMCR, 0); /* Specia
12、l Mode */ DM9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END); /* clear TX status */ DM9000_iow(DM9000_ISR, 0x0f); /* Clear interrupt status */ /* 下面这段代码是设置dm9000的MAC地址, 选是通过read_srom_word(i)到srom中读取MAC地址值, 再分别写入板子信息数据结构bd和dm9000的MAC寄存器中, 再将Multicast Address Register寄存器全部置1。*/ for (i = 0; i bi_enetaddr)i = read_srom_word(i); printf(MAC: %02x:%02x:%02x:%02x:%02x:%02xn, bd-bi_enetaddr0, bd-bi_enetaddr1, bd-bi_enetaddr2, bd-bi_enetadd
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1