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

📄 ul_kdmnt.c

📁 linux下的RS485的驱动 值得一看
💻 C
📖 第 1 页 / 共 2 页
字号:
            ChipOptions=device_id->driver_data; /*0x16954000*/        }    }   #endif /*UL_WITH_PCI*/    //    // Create the device object, multi-thread access (FALSE)    //    status = IoCreateDevice(DriverObject, sizeof(ULAN_DEVICE_EXTENSION),                            &uniNtNameString, FILE_DEVICE_UNKNOWN, 0,                            /* TRUE */ FALSE, &deviceObject);    if (!NT_SUCCESS (status) ) {        uLan_DbgPrint("uLan: IoCreateDevice failed\n");        return status;    }    //    // Set the FLAGS field    //    deviceObject->Flags |= DO_BUFFERED_IO;    extension = (PULAN_DEVICE_EXTENSION) deviceObject->DeviceExtension;    extension->flag_CHIPOK=0;    //    // Claim PnP busses resources    //   #ifdef UL_WITH_PCI    if(InterfaceType!=Isa){        PCM_RESOURCE_LIST  AllocatedResources;        PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;        int PartialCount, i;        InPortAddr.LowPart=IRQLine=0;        status = HalAssignSlotResources(RegistryPath,NULL,DriverObject,                     deviceObject,InterfaceType,BusNumber,                     SlotNumber.u.AsULONG,&AllocatedResources);                if(!AllocatedResources->Count)            status = STATUS_INSUFFICIENT_RESOURCES;        if(NT_SUCCESS(status)){            PartialCount=AllocatedResources->List[0].PartialResourceList.Count;            PartialDescriptor=AllocatedResources->List[0].PartialResourceList.PartialDescriptors;            for(i=0;i<PartialCount;i++){                if((PartialDescriptor[i].Type==CmResourceTypePort)&&                  (!InPortAddr.LowPart)){                    InPortAddr=PartialDescriptor[i].u.Port.Start;                    PortRange=PartialDescriptor[i].u.Port.Length;                }                if((PartialDescriptor[i].Type==CmResourceTypeInterrupt)&&                  (!IRQLine)){                    IRQLevel=(KIRQL)PartialDescriptor[i].u.Interrupt.Level;                    IRQLine=(KIRQL)PartialDescriptor[i].u.Interrupt.Vector;                }            }        }        if(!NT_SUCCESS(status)){            uLan_DbgPrint("uLan: HalAssignSlotResources error %X\n",status);            ExFreePool(AllocatedResources);            IoDeleteDevice(deviceObject);            return status;        }        if(!InPortAddr.LowPart || !IRQLine)            status = STATUS_INSUFFICIENT_RESOURCES;        uLan_DbgPrint("uLan: Found PCI resources Port=%04X IRQLevel=%02X IRQVector=%02X\n",                       InPortAddr.LowPart,IRQLevel,IRQLine);        ExFreePool(AllocatedResources);    }   #endif /*UL_WITH_PCI*/    //    // This call will map our IRQ to a system vector. It will also fill    // in the IRQL (the kernel-defined level at which our ISR will run),    // and affinity mask (which processors our ISR can run on).    //    // We need to do this so that when we connect to the interrupt, we    // can supply the kernel with this information.    //    irql=IRQLevel;    MappedVector = HalGetInterruptVector(            InterfaceType, // Interface type            BusNumber,     // Bus number            IRQLevel,	   // BusInterruptLevel            IRQLine,       // BusInterruptVector            &irql,         // IRQ level            &Affinity      // Affinity mask            );        //    // A little known Windows NT fact,    // If MappedVector==0, then HalGetInterruptVector failed.    //        if (MappedVector == 0) {        uLan_DbgPrint("uLan: HalGetInterruptVector failed\n");        IoDeleteDevice(deviceObject);        return (STATUS_INVALID_PARAMETER);    }    //    // Save off the Irql    //    extension->Irql = irql;    uLan_DbgPrint("uLan: driver mappedvector=%d irql=%d, dispatch irql=%d\n",		   MappedVector,irql,DISPATCH_LEVEL);    if(uL_SpinLock_Irql<irql)  		uL_SpinLock_Irql=irql;    uLan_DbgPrint("uLan: spin lock irql=%d\n",uL_SpinLock_Irql);    //    // Translate the base port address to a system mapped address.    // This will be saved in the device extension after IoCreateDevice,    // because we use the translated port address to access the ports.    //    if (!HalTranslateBusAddress(InterfaceType, BusNumber, InPortAddr,                                &AddressSpace, &OutPortAddr)) {        uLan_DbgPrint("uLan: HalTranslateBusAddress failed\n");        return STATUS_SOME_NOT_MAPPED;    }     if ( NT_SUCCESS(status) ) {	//        // Create dispatch points for create/open, close, unload, and ioctl        //        DriverObject->MajorFunction[IRP_MJ_CREATE] = DispatchRoutine;        DriverObject->MajorFunction[IRP_MJ_CLOSE] = DispatchRoutine;        DriverObject->MajorFunction[IRP_MJ_READ] = DispatchRoutine;        DriverObject->MajorFunction[IRP_MJ_WRITE] = DispatchRoutine;        DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DispatchRoutine;        DriverObject->MajorFunction[IRP_MJ_CLEANUP] = DispatchRoutine;        DriverObject->DriverUnload = UnloadDriver;        //        // check if resources (ports and interrupt) are available        //		       #ifdef UL_WITH_PCI        if(InterfaceType==Isa)       #endif /*UL_WITH_PCI*/        {	    ReportUsage(DriverObject,deviceObject,InterfaceType,BusNumber,                        InPortAddr,PortRange,IRQLine,&ResourceConflict);            if (ResourceConflict) {                uLan_DbgPrint("uLan: Couldn't get resources\n");                IoDeleteDevice(deviceObject);                return STATUS_INSUFFICIENT_RESOURCES;            }        }		        //        // fill in the device extension        //        extension = (PULAN_DEVICE_EXTENSION) deviceObject->DeviceExtension;        extension->DeviceObject = deviceObject;        extension->port = OutPortAddr.LowPart;		        status=ul_drv_init_ext(extension,OutPortAddr.LowPart,IRQLine,BaudRate,				BaudBase,ChipOptions,BufferSize,MyAddr);        if ( !NT_SUCCESS (status) ) {            uLan_DbgPrint("uLan: Initialization failed\n");            IoDeleteDevice(deviceObject);            return status;        }        KeInitializeDpc(&extension->bottom_dpc,ulan_bottom_dpc,extension);        KeInitializeDpc(&extension->wd_timer_dpc,ulan_wd_dpc,extension);	KeInitializeTimer(&extension->wd_timer);		//        // connect the device driver to the IRQ        //        ioConnectStatus = IoConnectInterrupt(&extension->InterruptObject,                                             uld_irq_handler,	// ServiceRoutine                                              extension,		// ServiceContext                                             NULL,		// SpinLock                                             MappedVector,	// Vector                                             irql,		// Irql                                              irql,		// SynchronizeIrql                                             InterfaceType==Isa? Latched:					       LevelSensitive,	// InterruptMode					     InterfaceType==Isa? FALSE:                                               TRUE,		// ShareVector                                              Affinity,		// ProcessorEnableMask                                              FALSE);		// FloatingSave         if ( !NT_SUCCESS (ioConnectStatus) ) {            uLan_DbgPrint("uLan: Couldn't connect interrupt\n");            IoDeleteDevice(deviceObject);            return ioConnectStatus;        }        uLan_DbgPrint("uLan: just about ready!\n");        //        // Create counted string version of our Win32 device name.        //        RtlInitUnicodeString( &uniWin32NameString, DOS_DEVICE_NAME);            //        // Create a link from our device name to a name in the Win32 namespace.        //                /* IoDeleteSymbolicLink (&uniWin32NameString); */        status = IoCreateSymbolicLink( &uniWin32NameString, &uniNtNameString );        if (!NT_SUCCESS(status)) {            uLan_DbgPrint("uLan: Couldn't create the symbolic link\n");            IoDeleteDevice (DriverObject->DeviceObject);        } else {            //            // Setup the Dpc for ISR routine            //			/*            IoInitializeDpcRequest (DriverObject->DeviceObject, uLan_Dpc_Routine);            //            // Initialize the device (enable IRQ's, hit the hardware)            //            Initialize_uLan (extension);		    */            uLan_DbgPrint("uLan: All initialized!\n");                        #ifdef UL_INT_TST			geninfoblk(extension);            printudrvbll(extension);			extension->flag_NACTIV=1;			KeRaiseIrql(DISPATCH_LEVEL,&OldIrql);            uld_timeout(extension);			KeLowerIrql(OldIrql);            #endif  /* UL_INT_TST */        }    } else {        uLan_DbgPrint("uLan: Couldn't create the device\n");    }    return status;	}//---------------------------------------------------------------------------// UnloadDriver//// Description://     Free all the allocated resources, etc.//// Arguments://     DriverObject - pointer to a driver object// // Return Value://      None// VOID UnloadDriver (IN PDRIVER_OBJECT DriverObject){    WCHAR                  deviceLinkBuffer[]  = DOS_DEVICE_NAME;    UNICODE_STRING         deviceLinkUnicodeString;    PULAN_DEVICE_EXTENSION extension;    extension = DriverObject->DeviceObject->DeviceExtension;    #ifdef UL_INT_TST    if(extension->flag_CHIPOK);      printudrvbll(extension);    #endif  /* UL_INT_TST */    //    // Deactivate uLan     //    ul_drv_done_ext(extension);    //    // Disconnect IRQ and DPC sources    //	    IoDisconnectInterrupt (extension->InterruptObject);          KeCancelTimer(&extension->wd_timer);    KeRemoveQueueDpc(&extension->wd_timer_dpc);    KeRemoveQueueDpc(&extension->bottom_dpc);		    //    // Delete the symbolic link    //	    RtlInitUnicodeString (&deviceLinkUnicodeString, deviceLinkBuffer);    IoDeleteSymbolicLink (&deviceLinkUnicodeString);    //    // Delete the device object    //    IoDeleteDevice (DriverObject->DeviceObject);   #ifdef ENABLE_UL_MEM_CHECK    UL_PRINTF("MEM_CHECK: malloc-free=%d\n",		 (int)atomic_read(&ul_mem_check_counter));   #endif /* ENABLE_UL_MEM_CHECK */    uLan_DbgPrint ("uLan: Unloaded\n");    return;}

⌨️ 快捷键说明

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