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

📄 rtl8019.c

📁 rtl8019网卡在uclinux下的驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                     graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:           rtl8019.c
** Last modified Date:  2005-05-12
** Last Version:        1.0
** Descriptions:        This is a Kernel module for uClinux 2.4.x .**                      This module let uClinux 2.4.x can use rtl8019. 
**------------------------------------------------------------------------------------------------------
** Created by:          Chenmingji
** Created date:        2005-05-12
** Version:             1.0
** Descriptions:        The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**

********************************************************************************************************/
#define IN_RTL8019#include "config.h"#include "rtl8019.h"/********************************************************************************************************
              function announce********************************************************************************************************/
static int net_init(struct net_device *dev);static int net_open(struct net_device *dev);static int net_release(struct net_device *dev); static int net_config(struct net_device *dev, struct ifmap *map);static int net_tx(struct sk_buff *skb, struct net_device *dev);static void net_irq_handle(int irq, void *dev_id, struct pt_regs *regs);
static int net_set_mac_address(struct net_device *dev, void *addr);int  net_init_module(void);void net_cleanup(void);static void net_tasklet(unsigned long);/********************************************************************************************************
              define announce********************************************************************************************************/
static struct net_device *RTL8019Dev;
module_init(net_init_module);module_exit(net_cleanup);DECLARE_TASKLET(ZLG_net_tasklet, net_tasklet, (unsigned long)(&RTL8019Dev));
MODULE_LICENSE("Proprietary");MODULE_DESCRIPTION("Guangzou ZLG-MCU Development Co.,LTD.\ngraduate school\nhttp://www.zlgmcu.com");MODULE_SUPPORTED_DEVICE("uClinux2.4.x LPC2200 rtl8019");MODULE_AUTHOR("chenmingji");/*********************************************************************************************************
**                  "全局和静态变量在这里定义"         
**        global variables and static variables define here
********************************************************************************************************/
static unsigned int usage;static u32 PinSel0Save;
/********************************************************************************************************/
static struct net_device net_net ={    name:           "eth0",    init:           net_init,    base_addr:      IOaddress,    irq:            NET_IRQ,    watchdog_timeo: NET_TIMEOUT,};/*********************************************************************************************************
** Function name: SetMacID
** Descriptions:  set MacID
** Input: dev:    information of device
**        
** Output: 0:     OK
**         other: errno
** Created by:    Chenmingji
** Created Date:  2005-05-12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void SetMacID(struct net_device *dev)   
{    u8 *mac_ptr;        mac_ptr = (u8 *)dev->dev_addr;
    //把MAC地址写入MY——MAC——ID中
    page(1);
    
    WriteToNet(1 , *mac_ptr++);
    WriteToNet(2 , *mac_ptr++);
    WriteToNet(3 , *mac_ptr++);
    WriteToNet(4 , *mac_ptr++);
    WriteToNet(5 , *mac_ptr++);
    WriteToNet(6 , *mac_ptr);
    page(0);
}/*********************************************************************************************************
** Function name: device_init
** Descriptions:  device init
** Input: dev:    information of device
**        
** Output: 0:     OK
**         other: errno
** Created by:    Chenmingji
** Created Date:  2005-05-12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int device_init(struct net_device *dev){    unsigned long flag;    local_irq_save(flag);
    /* 硬件复位复位 */
    outl(1 << 8, IOSET);    mdelay(7);
    outl(1 << 8, IOCLR);    /* 软件复位 */    WriteToNet(0x1f, 0x00);  
    mdelay(11);
        WriteToNet(0x00, 0x21);      //使芯片处于停止模式,这时进行寄存器设置
    mdelay(11);
    page(0);
    
    WriteToNet(0x0a, 0x00);     //清rbcr0
    WriteToNet(0x0b, 0x00);     //清rbcr1
    WriteToNet(0x0c, 0xe0);     //RCR,监视模式,不接收数据包
    WriteToNet(0x0d, 0xe2);     //TCR,loop back模式
    page(0);
    WriteToNet(0x01, 0x4c);     //PSTART=0X4C
    WriteToNet(0x02, 0x80);     //PSTOP=0X80
    WriteToNet(0x03, 0x4c);     //bnry=0x4c;
    page(0);
    WriteToNet(0x04, 0x40);     //TPSR,发送起始页寄存器
    WriteToNet(0x07, 0xff);     //清除所有中断标志位,中断状态寄存器
    WriteToNet(0x0f, 0x13);     //允许相关的中断
    
    WriteToNet(0x0e, 0xcb);     //数据配置寄存器,16位dma方式
    page(1);
    WriteToNet(0x07, 0x4d);     //curr = 0x4d
    WriteToNet(0x08, 0x00);
    WriteToNet(0x09, 0x00);
    WriteToNet(0x0a, 0x00);
    WriteToNet(0x0b, 0x00);
    WriteToNet(0x0c, 0x00);
    WriteToNet(0x0d, 0x00);
    WriteToNet(0x0e, 0x00);
    WriteToNet(0x0f, 0x00);
    WriteToNet(0x00, 0x22);         //这时让芯片开始工作
    
    SetMacID(dev);                  //将芯片物理地址写入到MAR寄存器
    
    page(0);
    WriteToNet(0x0c, 0xc4);         //将芯片设置成正常模式,跟外部网络连接
    WriteToNet(0x0d, 0xe0);
    WriteToNet(0x00, 0x22);         //启动芯片开始工作
    WriteToNet(0x07, 0xff);         //清除所有中断标志位                local_irq_restore(flag);
    return 0;}
/*********************************************************************************************************
** Function name: net_init
** Descriptions:  net device init
** Input: dev:    information of device
**        
** Output: 0:     OK
**         other: errno
** Created by:    Chenmingji
** Created Date:  2005-05-12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int net_init(struct net_device *dev){    ether_setup(dev); /* assign some of the fields */    dev->open            = net_open;    dev->stop            = net_release;    dev->set_config      = net_config;    dev->hard_start_xmit = net_tx;
    dev->set_mac_address = net_set_mac_address;    dev->flags           &= ~(IFF_LOOPBACK | IFF_MULTICAST);
    dev->priv            = NULL;    memcpy(dev->dev_addr, MyMacID, dev->addr_len);    SET_MODULE_OWNER(dev);    return 0;}/*********************************************************************************************************
** Function name: net_config
** Descriptions:  config device
** Input: dev:    information of device
**        map:    config data
** Output: 0:     OK
**         other: errno
** Created by:    Chenmingji
** Created Date:  2005-05-12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int net_config(struct net_device *dev, struct ifmap *map){    return -EBUSY;}
/*********************************************************************************************************
** Function name: net_set_mac_address
** Descriptions:  set mac address
** Input: dev:    information of device
**        addr:   config data
** Output: 0:     OK
**         other: errno
** Created by:    Chenmingji
** Created Date:  2005-05-12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int net_set_mac_address(struct net_device *dev, void *addr)
{
    struct sockaddr *mac_addr;
    mac_addr = addr;    if (netif_running(dev))
    {        return -EBUSY;
    }    /* Set the device copy of the Ethernet address */
        memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);    
    SetMacID(dev);      return 0;    
}

                           /*********************************************************************************************************
** Function name: net_tx
** Descriptions:  send data to other machine
** Input: skb:    save data for send
**        dev:    information of device
** Output: 0:     OK
**         other: not OK
** Created by:    Chenmingji
** Created Date:  2005-05-12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int net_tx(struct sk_buff *skb, struct net_device *dev){    unsigned long flag;    int len;
    u16 *data;

    netif_stop_queue(dev);

    len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len;
    data = (u16 *)skb->data;    len = (len + 1) & (~1);

    local_irq_save(flag);
        page(0);
    WriteToNet(0x09, 0x40);             //设置发送页地址
    WriteToNet(0x08, 0x00);             //写入RSAR0 DMA起始地址低位read page address low
    WriteToNet(0x0b, len >> 8);         //写入RSCR1 DMA 计数器高位read count high
    WriteToNet(0x0a, len & 0x00ff);     //写入RSCR0 DMA 计数器低位read count low;
    WriteToNet(0, 0x12);                //启动DMA写write dma, page0
        outsw(RTL8019_REG(0x10), data, len >> 1);

    WriteToNet(0x0b, 0x00); 
    WriteToNet(0x0a, 0x00);
    WriteToNet(0x00, 0x22);             //结束或放弃DMA操作

    WriteToNet(0x06, len >> 8);         //high byte counter
    WriteToNet(0x05, len & 0x00ff);     //low byte counter
    WriteToNet(0x07, 0xff);
    WriteToNet(0x00, 0x3e);             //to sendpacket;
            dev->trans_start = jiffies;
    local_irq_restore(flag);
    dev_kfree_skb(skb);

    return 0; /* Our simple device can not fail */}/*********************************************************************************************************
** Function name: net_open
** Descriptions:  open device
** Input: dev:    information of device
**       
** Output: 0:     OK
**         other: not OK
** Created by:    Chenmingji
** Created Date:  2005-05-12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int  net_open(struct net_device *dev){    unsigned long flag;    u32 temp;
    if (usage == 0)
    {
        local_irq_save(flag);        temp = inl(PINSEL0);        PinSel0Save = temp & (0x0f << (8 * 2));        temp |= (3 << (9 * 2));        temp &= ~(3 << (8 * 2));        outl(temp, PINSEL0);
        temp = inl(IO0DIR);        temp |= 1 << 8;

⌨️ 快捷键说明

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