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

📄 ul_kdmnt.c

📁 linux下的RS485的驱动 值得一看
💻 C
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************  uLan Communication - uL_DRV - multiplatform uLan driver  ul_kdmnt.c	- Windows NT KMD specific support  (C) Copyright 1996-2004 by Pavel Pisa - project originator        http://cmp.felk.cvut.cz/~pisa  (C) Copyright 1996-2004 PiKRON Ltd.        http://www.pikron.com  (C) Copyright 2002-2004 Petr Smolik    The uLan driver project can be used and distributed   in compliance with any of next licenses   - GPL - GNU Public License     See file COPYING for details.   - LGPL - Lesser GNU Public License   - MPL - Mozilla Public License   - and other licenses added by project originator  Code can be modified and re-distributed under any combination  of the above listed licenses. If contributor does not agree with  some of the licenses, he/she can delete appropriate line.  WARNING: if you delete all lines, you are not allowed to  distribute code or sources in any form. *******************************************************************///-------------------------------------------------------------------//// Declare forward function references//VOID UnloadDriver (IN PDRIVER_OBJECT DriverObject);BOOLEAN ReportUsage(IN PDRIVER_OBJECT DriverObject,	            IN PDEVICE_OBJECT DeviceObject,                    IN INTERFACE_TYPE InterfaceType,                    IN ULONG BusNumber,                    IN PHYSICAL_ADDRESS PortAddress,		    IN LONG PortRange,		    IN KIRQL IRQLine,                    IN BOOLEAN *ConflictDetected);//---------------------------------------------------------------------------// ReportUsage//// Description://  This routine registers (reports) the I/O and IRQ usage for this driver.//// Arguments://      DriverObject    - Pointer to the driver object//      DeviceObject    - Pointer to the Device object//      PortAddress     - Address of I/O port used//      ConflictDetected - TRUE if a resource conflict was detected.//// Return Value://      TRUE    - If a Resource conflict was detected//      FALSE   - If no conflict was detected//BOOLEAN ReportUsage(IN PDRIVER_OBJECT DriverObject,		    IN PDEVICE_OBJECT DeviceObject,		    IN INTERFACE_TYPE InterfaceType,                    IN ULONG BusNumber,                    IN PHYSICAL_ADDRESS PortAddress,		    IN LONG PortRange,		    IN KIRQL IRQLine,                    IN BOOLEAN *ConflictDetected){  ULONG sizeOfResourceList;  PCM_RESOURCE_LIST resourceList;  PCM_FULL_RESOURCE_DESCRIPTOR nextFrd;  PCM_PARTIAL_RESOURCE_DESCRIPTOR partial;  //  // The size of the resource list is going to be one full descriptor  // which already has one partial descriptor included, plus another  // partial descriptor. One partial descriptor will be for the  // interrupt, and the other for the port addresses.  //  sizeOfResourceList = sizeof(CM_FULL_RESOURCE_DESCRIPTOR);  //  // The full resource descriptor already contains one  // partial.	Make room for one more.  //  // It will hold the irq "prd", and the port "prd".  //	  ("prd" = partial resource descriptor)  //  sizeOfResourceList += sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);  //  // Now we increment the length of the resource list by field offset  // of the first frd.   This will give us the length of what preceeds  // the first frd in the resource list.  //	 (frd = full resource descriptor)  //  sizeOfResourceList += FIELD_OFFSET(CM_RESOURCE_LIST, List[0]);  resourceList = ExAllocatePool(PagedPool, sizeOfResourceList);  if (!resourceList) {    return FALSE;  }  //  // Zero out the list  //  RtlZeroMemory(resourceList, sizeOfResourceList);  resourceList->Count = 1;  nextFrd = &resourceList->List[0];  nextFrd->InterfaceType = InterfaceType;  nextFrd->BusNumber = BusNumber;  //  // We are going to report port addresses and interrupt  //  nextFrd->PartialResourceList.Count = 2;  //  // Now fill in the port data.  We don't wish to share  // this port range with anyone.  //  // Note: the port address we pass in is the one we got  // back from HalTranslateBusAddress.  //  // CmResourceShareDriverExclusive  // CmResourceShareDeviceExclusive  // CmResourceShareShared  partial = &nextFrd->PartialResourceList.PartialDescriptors[0];  partial->Type = CmResourceTypePort;  partial->ShareDisposition = CmResourceShareDeviceExclusive;  partial->Flags = CM_RESOURCE_PORT_IO;  partial->u.Port.Start = PortAddress;  partial->u.Port.Length = PortRange;  partial++;  //  // Now fill in the irq stuff.  //  // Note: for IoReportResourceUsage, the Interrupt.Level and  // Interrupt.Vector are bus-specific level and vector, just  // as we passed in to HalGetInterruptVector, not the mapped  // system vector we got back from HalGetInterruptVector.  //  partial->Type = CmResourceTypeInterrupt;  partial->u.Interrupt.Level = IRQLine;  partial->u.Interrupt.Vector = IRQLine;  partial->ShareDisposition = InterfaceType==Isa?                                  CmResourceShareDeviceExclusive:                                 CmResourceShareShared;  partial->Flags = InterfaceType==Isa?                     CM_RESOURCE_INTERRUPT_LATCHED:		     CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;  /* Claim resources for Driver */  /*IoReportResourceUsage(      NULL,      DriverObject,      resourceList,      sizeOfResourceList,      NULL,      NULL,      0,      FALSE,      ConflictDetected);*/  /* Claim resources for individual DeviceObject */  IoReportResourceUsage(      NULL,      DriverObject,      NULL,      0,      DeviceObject,      resourceList,      sizeOfResourceList,      FALSE,      ConflictDetected);  //  // The above routine sets the BOOLEAN parameter ConflictDetected  // to TRUE if a conflict was detected.  //  ExFreePool(resourceList);  return (*ConflictDetected);}//-------------------------------------------------------------------// DriverEntry for WinNT style KMD//// Description://  NT device Driver Entry point//// Arguments://      DriverObject    - Pointer to this device's driver object//      RegistryPath    - Pointer to the Unicode regsitry path name//// Return Value://      NTSTATUS//NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath){    PDEVICE_OBJECT deviceObject = NULL;    NTSTATUS status, ioConnectStatus;    UNICODE_STRING uniNtNameString;    UNICODE_STRING uniWin32NameString;    UNICODE_STRING uniRegPath;    INTERFACE_TYPE InterfaceType;    ULONG BusNumber;    PCI_SLOT_NUMBER SlotNumber;    KIRQL irql;    KIRQL IRQLine;    KIRQL IRQLevel;    KIRQL OldIrql;    KAFFINITY Affinity;    LONG TmpLong;    LONG PortRange;    LONG BaudRate;    LONG BaudBase;    LONG MyAddr;    LONG BufferSize;    LONG ScanForPCI;    ULONG MappedVector=0, AddressSpace = 1;    PULAN_DEVICE_EXTENSION extension;    BOOLEAN ResourceConflict;    PHYSICAL_ADDRESS InPortAddr, OutPortAddr;    int ChipOptions=0;    ULD_LARGE_INTEGER_0=RtlConvertLongToLargeInteger(0);    uLan_DbgPrint("uLan v" UL_DRV_VERSION " Enter the driver!\n");    uLan_DbgPrint("uLan: " __DATE__ " " __TIME__ "\n");    //    // Create counted string version of our device name.    //    RtlInitUnicodeString(&uniNtNameString, NT_DEVICE_NAME);    //    // Default configuration    //    ScanForPCI=0;    InterfaceType = Isa;    BusNumber = 0;    InPortAddr.LowPart = DEF_PORT_ADDRESS;    InPortAddr.HighPart = 0;    PortRange = DEF_PORT_RANGE;    IRQLine = DEF_IRQ_LINE;    BaudRate = DEF_BAUD_RATE;    BaudBase = 0;    BufferSize=0x8000;    MyAddr = DEF_MY_ADDR;    //    // Get the configuration information from the Registry    //    /* RtlInitUnicodeString(&uniRegPath,RegistryPath->Buffer); */    /* RtlCopyUnicodeString(&uniRegPath,RegistryPath); */    status=STATUS_SUCCESS;    RtlInitUnicodeString(&uniRegPath, NULL);    uniRegPath.MaximumLength = RegistryPath->Length + sizeof(L"\\Parameters")+1;    uniRegPath.Buffer = ExAllocatePool(PagedPool, uniRegPath.MaximumLength*sizeof(WCHAR));    if (!uniRegPath.Buffer) {        uLan_DbgPrint("uLan: ExAllocatePool failed for Path in DriverEntry\n");        status = STATUS_UNSUCCESSFUL;    }    else    {        RtlZeroMemory(uniRegPath.Buffer,uniRegPath.MaximumLength*sizeof(WCHAR));        RtlAppendUnicodeStringToString(&uniRegPath, RegistryPath);        RtlAppendUnicodeToString(&uniRegPath, L"\\Parameters");    }    if (NT_SUCCESS(status))        status=ulan_GetRegistryDword(uniRegPath.Buffer,L"ScanForPCI",&ScanForPCI);    if (NT_SUCCESS(status))	status=ulan_GetRegistryDword(uniRegPath.Buffer,L"Port Address",&InPortAddr.LowPart);    if (NT_SUCCESS(status))	status=ulan_GetRegistryDword(uniRegPath.Buffer,L"Port Range",&PortRange);    TmpLong=IRQLine;    if (NT_SUCCESS(status))	status=ulan_GetRegistryDword(uniRegPath.Buffer,L"IRQ Line",&TmpLong);    IRQLine=(KIRQL)TmpLong;    IRQLevel=(KIRQL)TmpLong;    if (NT_SUCCESS(status))        status=ulan_GetRegistryDword(uniRegPath.Buffer,L"Baud Rate",&BaudRate);    if (NT_SUCCESS(status))        status=ulan_GetRegistryDword(uniRegPath.Buffer,L"Baud Base",&BaudBase);    if (NT_SUCCESS(status))        status=ulan_GetRegistryDword(uniRegPath.Buffer,L"My Addr",&MyAddr);    if (NT_SUCCESS(status))        status=ulan_GetRegistryDword(uniRegPath.Buffer,L"Buffer Size",&BufferSize);    TmpLong=uld_debug_flg;    if (NT_SUCCESS(status))        status=ulan_GetRegistryDword(uniRegPath.Buffer,L"Debug",&TmpLong);    uld_debug_flg=TmpLong;    if(uniRegPath.Buffer)	ExFreePool(uniRegPath.Buffer);    if (!NT_SUCCESS(status)) {        uLan_DbgPrint("uLan: GetConfiguration failed\n");        return status;    }   #ifdef UL_WITH_PCI    if(ScanForPCI){        pci_device_id_t *device_id;        uLan_DbgPrint("uLan: Calling ScanForPCICard\n");        if(ScanForPCICard(&BusNumber,&SlotNumber,TRUE,&device_id)){	    /*PCI_COMMON_CONFIG PCIConfig;*/            /*HalGetBusData(PCIConfiguration,BusNumber,SlotNumber.u.AsULONG,                             PCIConfig,sizeof(PCIConfig));*/            uLan_DbgPrint("uLan: ScanForPCICard found slot %02X:%02X.%1X\n",                (int)BusNumber,(int)SlotNumber.u.bits.DeviceNumber,                (int)SlotNumber.u.bits.FunctionNumber);            InterfaceType=PCIBus;

⌨️ 快捷键说明

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