Windows CE驱动N枪拍案惊奇系列 之 基于Wince5.0的DM9000A的驱动分析和移植步骤

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/niuniumenghua/article/details/6490076

基于Wince5.0DM9000A的驱动分析和移植步骤

华清远见非著名讲师  O(_)O  牛牛猛

点击链接加我好友!

http://student.csdn.net/invite.php?u=111047&c=758a60d66d3a92d1

欢迎大家去我CSDN博客上踩踩

http://blog.csdn.net/mistyeyed

 

首先要找到驱动程的入口点,从dm9000.def文件中可以看到dm9000的驱动程序(dm9000.dllexports的函数只有DriverEntry。可以确定这里便是DM9000 驱动入口函数。

 

详细查看这个位于driver.cpp文件中的入口函数会发现这个函数中主要有一个函数NdisMInitializeWrapper(

              &hwrapper,

              pDriverObject,

              pRegistryPath,

              NULL);

查看微软的帮助文档可知这个函数作用是This function notifies NDIS that a new miniport is initializing,翻译一下,函数的功能是通知NDIS这个函数是一个初始化函数,NDIS(网络驱动器标准接口),NdisMInitializeWrapper()函数是内核提供给我们的,可以直接调用。

接下来就是给

NDIS30_MINIPORT_CHARACTERISTICS这个结构体变量初始化,主要是设置一些回调函数,这是Windows程序的常见风格:

ndischar.Ndis30Chars.InitializeHandler  =  MiniportInitialize;

   ndischar.Ndis30Chars.ResetHandler      = MiniportReset;

   ndischar.Ndis30Chars.CheckForHangHandler = MiniportCheckForHang;

   ndischar.Ndis30Chars.HaltHandler         = MiniportHalt;

   ndischar.Ndis30Chars.HandleInterruptHandler = MiniportInterruptHandler;

   ndischar.Ndis30Chars.ISRHandler           = MiniportISRHandler;

   ndischar.Ndis30Chars.QueryInformationHandler=MiniportQueryInformation;

   ndischar.Ndis30Chars.SetInformationHandler            = MiniportSetInformation;

ndischar.Ndis30Chars.SendHandler              = MiniportSend;

       

很明显上面提到的通常要自己实现的。再下来就是NdisMRegisterMiniport()函数了,【F1】查看帮助文档,

This function registers an NIC or intermediate driver's Miniport_* entry points and name with the NDIS library when the driver initializes

顾名思义这是一个注册函数,想wince内核注册驱动程序,注册刚才初始化的结构体就是用刚才初始化的那个结构体NDIS30_MINIPORT_CHARACTERISTICS注册。搞过Linux驱动的兄弟一定对这种思路一定不陌生。

函数中只有一个函数NdisTerminateWrapper,接着查看帮助文档,

This function releases system resources allocated when the NIC driver called the NdisMInitializeWrapper function意思是说函数调用后获得系统资源。

帮助文档里有这样的描述:A miniport calls this function during initialization if it cannot find an NIC that it supports in the current platform or if it cannot successfully initialize at least one NIC or virtual NIC.那么后面将是从成功注册的结构体的第一个函数执行了即:NDIS_STATUS

 

 

MiniportInitialize(

        OUT PNDIS_STATUS OpenErrorStatus,

        OUT PUINT SelectedMediaIndex,

        IN PNDIS_MEDIUM MediaArray,

        IN UINT MediaArraySize,

    IN NDIS_HANDLE MiniportHandle,

        IN NDIS_HANDLE WrapperConfigHandle)

This function is a required function that sets up a network adapter, or virtual network adapter, for network I/O operations, claims all hardware resources necessary to the network adapter in the registry, and allocates resources the driver needs to carry out network I/O operations

意思是说,开启所有网口资源。我们看看MiniportInitialize函数中做了那些工作。

NIC_DRIVER_OBJECT *pnic;意思是实例化NIC_DRIVER_OBJECT

 

其中有NIC_DRIVER_OBJECT类的初始化,以及该类的EDriverInitialize函数调用,在此函数中全面展开了dm9000的所有初始化操作。

 

pnic->EDriverInitialize(

                    OpenErrorStatus,

                    SelectedMediaIndex,

                    MediaArray,

                    MediaArraySize);

 

pnic->DriverStart();      

 

 

我们跟踪到EDriverInitialize中,发现这样一句话:

       m_pLower = DeviceEntry(this,NULL);

主要是通过DeviceEntry()这个函数来实现(这个函数实现在dm9isa.cpp文件中),

extern "C" NIC_DEVICE_OBJECT    *DeviceEntry(

       NIC_DRIVER_OBJECT *pDriverObject,

       PVOID                         pVoid)

{

      

       return new C_DM9000(pDriverObject,pVoid);

}

 

DeviceEntry这个函数中只做了一件事:new了一个C_DM9000类的实例并return

接下来就该C_DM9000的实例了,真正进入DM9000的初始化阶段

 

 

 

m_pLower->DeviceSetDefaultSettings();

                   m_pLower->DeviceSetEepromFormat();        

                   m_pLower->DeviceRetriveConfigurations(hconfig);

                   m_pLower->EDeviceValidateConfigurations();

 

 

完成若干初始化工作后, NIC_DRIVER_OBJECT又出现了,

pnic->DriverStart();函数将被调用,

驱动程序进入DriverStart()函数,

函数很简单但是比较重要,它在此DeviceEnableInterrupt()启动了中断,至此正常的话可以看到DM9:--MiniportInitialize的提示。

 

DriverStart函数中有个EDeviceValidateConfigurations函数会获得g_szDm9ConfigParams结构体中的中断号和片选地址:

{ CID_IO_BASE_ADDRESS, 0x20000000, NDIS_STRING_CONST("IoAddress")},

{ CID_IRQ_NUMBER, 16, NDIS_STRING_CONST("IrqNumber")},

Step-by-step移植:

1、获得dm9000的基于wince的驱动包,复制

%_winceroot%/ PLATFORM/SMDK2440A/Src/Drivers/目录下;

2、打开在driver目录下dirs文件,在该文件里将dm9000加入到dirs中;

3、打开driver/dm9000目录,在该目录下将dirssource等文件改了

4、中断和片选参考上面的提示即可。

 

附上我的注册表信息供大家参考哦!

IF BSP_DM9000 !

       [HKEY_LOCAL_MACHINE/Comm/DM9CE]

              "DisplayName"="DM9000A/9010 ISA Fast Ethernet Adapter"

              "Group"="NDIS"

              "ImagePath"="dm9isa.dll"

 

       [HKEY_LOCAL_MACHINE/Comm/DM9CE/Linkage]

              "Route"=multi_sz:"dm9ce1"

 

       [HKEY_LOCAL_MACHINE/Comm/DM9CE1]

              "DisplayName"="DM9000A/9010 ISA Fast Ethernet Adapter"

              "Group"="NDIS"

              "ImagePath"="dm9isa.dll"

 

       [HKEY_LOCAL_MACHINE/Comm/Tcpip/Linkage]

              "Bind"="dm9ce1"

 

       [HKEY_LOCAL_MACHINE/Comm/DM9CE1/Parms]

              "BusNumber"=dword:0

              "BusType"=dword:0

              "XmitBuffer"=dword:20

              "RecvBuffer"=dword:20

              "IrqNumber"=dword:10

              "MACAddress" =hex:00,0A,EB,FD,7A,00

 

       [HKEY_LOCAL_MACHINE/Comm/DM9CE1/Parms/TcpIp]

              "EnableDHCP"=dword:0

              "UseZeroBroadcast"=dword:0

              "DefaultGateway"="192.168.4.1"

              "IpAddress"="192.168.4.215"

              "Subnetmask"="255.255.255.0"

              "DNS"="202.106.0.20"

ENDIF BSP_DM9000 !

 

 

本文参考:

bluefish博客,出处http://bluefish.blog.51cto.com/214870/58106

感谢bluefish的分享。

 

展开阅读全文

求助:linux-2.6.32.2 dm9000a驱动问题

02-17

In: serialrnOut: serialrnErr: serialrnUSB slave is enable!rnNet: dm9000rnHit any key to stop autoboot: 0rnrnNAND read: device 0 offset 0x50000, size 0x280000rnrnplease waiting......rn2621440 bytes read: OKrn## Booting kernel from Legacy Image at 30008000 ...rn Image Name: linux-2.6.32.2rn Created: 2012-02-16 8:10:36 UTCrn Image Type: ARM Linux Kernel Image (uncompressed)rn Data Size: 2287060 Bytes = 2.2 MiBrn Load Address: 30008000rn Entry Point: 30008040rn Verifying Checksum ... OKrn XIP Kernel Image ... OKrnOKrnrnStarting kernel ...rnrnUncompressing Linux.............................................................rn................................................................................rn........ done, booting the kernel.rnLinux version 2.6.32.2-FriendlyARM (root@localhost.localdomain) (gcc version 4.3rn.2 (Sourcery G++ Lite 2008q3-72) ) #16 Thu Feb 16 16:10:06 CST 2012rnCPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177rnCPU: VIVT data cache, VIVT instruction cachernMachine: FriendlyARM Mini2440 development boardrnMemory policy: ECC disabled, Data cache writebackrnCPU S3C2440A (id 0x32440001)rnS3C24XX Clocks, (c) 2004 Simtec ElectronicsrnS3C244X: core 405.600 MHz, memory 101.400 MHz, peripheral 50.700 MHzrnCLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL onrnBuilt 1 zonelists in Zone order, mobility grouping on. Total pages: 16256rnKernel command line: noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0,rn115200 rootfstype=yaffs2 rw mem=64MrnPID hash table entries: 256 (order: -2, 1024 bytes)rnDentry cache hash table entries: 8192 (order: 3, 32768 bytes)rnInode-cache hash table entries: 4096 (order: 2, 16384 bytes)rnMemory: 64MB = 64MB totalrnMemory: 60024KB available (4236K code, 452K data, 160K init, 0K highmem)rnSLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1rnHierarchical RCU implementation.rnNR_IRQS:85rnirq: clearing subpending status 00000002rnConsole: colour dummy device 80x30rnconsole [ttySAC0] enabledrnCalibrating delay loop... 202.34 BogoMIPS (lpj=505856)rnMount-cache hash table entries: 512rnCPU: Testing write buffer coherency: okrnNET: Registered protocol family 16rnS3C2440: Initialising architecturernS3C2440: IRQ SupportrnS3C24XX DMA Driver, (c) 2003-2004,2006 Simtec ElectronicsrnDMA channel 0 at c4808000, irq 33rnDMA channel 1 at c4808040, irq 34rnDMA channel 2 at c4808080, irq 35rnDMA channel 3 at c48080c0, irq 36rnS3C244X: Clock Support, DVS offrnbio: create slab at 0rnSCSI subsystem initializedrnusbcore: registered new interface driver usbfsrnusbcore: registered new interface driver hubrnusbcore: registered new device driver usbrns3c-i2c s3c2440-i2c: slave address 0x10rns3c-i2c s3c2440-i2c: bus frequency set to 99 KHzrns3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapterrnNET: Registered protocol family 2rnIP route cache hash table entries: 1024 (order: 0, 4096 bytes)rnTCP established hash table entries: 2048 (order: 2, 16384 bytes)rnTCP bind hash table entries: 2048 (order: 1, 8192 bytes)rnTCP: Hash tables configured (established 2048 bind 2048)rnTCP reno registeredrnNET: Registered protocol family 1rnRPC: Registered udp transport module.rnRPC: Registered tcp transport module.rnRPC: Registered tcp NFSv4.1 backchannel transport module.rnNetWinder Floating Point Emulator V0.97 (double precision)rnyaffs Feb 15 2012 09:24:45 Installing.rnmsgmni has been set to 117rnalg: No test for stdrng (krng)rnio scheduler noop registered (default)rnConsole: switching to colour frame buffer device 30x20rnfb0: s3c2410fb frame buffer devicernbacklight initializedrnleds initializedrnbuttons initializedrnpwm initializedrnadc initializedrns3c2440-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440rns3c2440-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440rns3c2440-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440rnloop: module loadedrnS3C24XX NAND Driver, (c) 2004 Simtec Electronicsrns3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29nsrns3c24xx-nand s3c2440-nand: NAND soft ECCrnNAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bitrn)rnScanning device for bad blocksrnCreating 3 MTD partitions on "NAND 64MiB 3,3V 8-bit":rn0x000000000000-0x000000050000 : "boot"rn0x000000050000-0x0000002d0000 : "kernel"rn0x000000330000-0x000004000000 : "root"rndm9000 Ethernet Driver, V1.31linux[color=#FF0000]启动停在此次不动了,发现是第一次dm9000_reset(db);的时候挂掉了,具体是执行writeb(DM9000_NCR, db->io_addr);挂掉,打印io_addr的值为c4814300,请大大指点啊[/color] 论坛

没有更多推荐了,返回首页