亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? rs485nt.c

?? RS485設備驅動源代碼
?? C
?? 第 1 頁 / 共 3 頁
字號:
//---------------------------------------------------------------------------
//
// RS485NT.C
//
// Author:  Anthony A. Kempka
//          Device Drivers International, LLC
//
//          Tel: 218-587-3120
//          Tel: 513-984-4491
//          Web: www.ddiusa.com
//
//---------------------------------------------------------------------------
// 
// For:     Integrity Instruments (a division of Cogito Software, Inc.)
//
//          Tel: 800-450-2001
//          Web: www.integrityusa.com
//
//
// Last Modified:       
//      A. A. Kempka    08/20/97        Original.
//  
//---------------------------------------------------------------------------
//
// Description:
// ------------
// This file was developed for Integrity Instruments as a Generic
// Windows NT RS485 driver. This is a Kernel-Mode driver.
//
//
// Application Interface:
// ----------------------
// CreateFile () - Establishes an open channel to this driver
// WriteFile ()  - Transmits a buffer of Data via RS485 by asserting
//                 RTS during trasnmit and deasserting RTS upon
//                 transmitt complete of the final character
//
//                 *CAUTION* WriteFile discards unread receive buffer contents!
//
// ReadFile ()   - Returns the current received character buffer
//
// See the sample User mode API in Q_TEST.C
//
//
// Distribution Notice:
// --------------------
// 
//
//
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
//
// Include files 
//
#include "NTDDK.H"
#include "COM8250.H"
#include "RS485NT.H"
#include "RS485IOC.H"

//---------------------------------------------------------------------------
//
// Define the driver names
// 
#define NT_DEVICE_NAME	    L"\\Device\\RS485NT"
#define DOS_DEVICE_NAME     L"\\DosDevices\\RS485NT"

#define RS_DbgPrint(a) DbgPrint(a)


//---------------------------------------------------------------------------
//
// Declare forward function references
//

NTSTATUS DispatchRoutine (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);

VOID UnloadDriver (IN PDRIVER_OBJECT DriverObject);

BOOLEAN ReportUsage (IN PDRIVER_OBJECT DriverObject,
                     IN PDEVICE_OBJECT DeviceObject,
                     IN PHYSICAL_ADDRESS PortAddress,
                     IN BOOLEAN *ConflictDetected);

BOOLEAN RS485_Isr (IN PKINTERRUPT Interrupt, IN OUT PVOID Context);

VOID RS485_Dpc_Routine (IN PKDPC Dpc, IN PDEVICE_OBJECT DeviceObject, 
                        IN PIRP Irp, IN PVOID Context);

NTSTATUS GetConfiguration (IN PRS485NT_DEVICE_EXTENSION DeviceExtension,
                           IN PUNICODE_STRING RegistryPath);

NTSTATUS Initialize_RS485 (IN PRS485NT_DEVICE_EXTENSION DeviceExtension);

NTSTATUS RS485_Write (IN PRS485NT_DEVICE_EXTENSION  deviceExtension, IN PIRP Irp);
NTSTATUS RS485_Read (IN PRS485NT_DEVICE_EXTENSION  deviceExtension, IN PIRP Irp);


//---------------------------------------------------------------------------
//
//  Begin FUNCTIONS
//

//---------------------------------------------------------------------------
// DriverEntry
//
// 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;
    KIRQL irql = DEF_IRQ_LINE;
    KAFFINITY Affinity;
    ULONG MappedVector, AddressSpace = 1;
    PRS485NT_DEVICE_EXTENSION extension;
    BOOLEAN ResourceConflict;
    PHYSICAL_ADDRESS InPortAddr, OutPortAddr;

    RS_DbgPrint ("RS485NT: Enter the driver!\n");

    //
    // Create counted string version of our device name.
    //

    RtlInitUnicodeString(&uniNtNameString, NT_DEVICE_NAME);

    //
    // Create the device object, single-thread access (TRUE)
    //

    status = IoCreateDevice(DriverObject, sizeof(RS485NT_DEVICE_EXTENSION),
                            &uniNtNameString, FILE_DEVICE_UNKNOWN, 0,
                            TRUE, &deviceObject);

    if (!NT_SUCCESS (status) ) {
        RS_DbgPrint("RS485NT: IoCreateDevice failed\n");
        return status;
    }
    //
    // Set the FLAGS field
    //

    deviceObject->Flags |= DO_BUFFERED_IO;

    //
    // Get the configuration information from the Registry
    //

    status = GetConfiguration (deviceObject->DeviceExtension, RegistryPath);

    if (!NT_SUCCESS (status) ) {
        RS_DbgPrint("RS485NT: GetConfiguration failed\n");
        return status;
    }

    extension = (PRS485NT_DEVICE_EXTENSION) deviceObject->DeviceExtension;

    //
    // 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.
    //
    MappedVector = HalGetInterruptVector(
            Isa,        // Interface type
            0,          // Bus number
            extension->IRQLine,
            extension->IRQLine,
            &irql,      // IRQ level
            &Affinity   // Affinity mask
            );

    //
    // A little known Windows NT fact,
    // If MappedVector==0, then HalGetInterruptVector failed.
    //

    if (MappedVector == 0) {
        RS_DbgPrint("RS485NT: HalGetInterruptVector failed\n");
        return (STATUS_INVALID_PARAMETER);
    }

    //
    // Save off the Irql
    //

    extension->Irql = 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.
    //

    InPortAddr.LowPart = (ULONG)extension->PortAddress;
    InPortAddr.HighPart = 0;
    if (!HalTranslateBusAddress(Isa, 0, InPortAddr, &AddressSpace, 
                                &OutPortAddr)) {
        RS_DbgPrint("RS485NT: 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->DriverUnload = UnloadDriver;

        //
        // check if resources (ports and interrupt) are available
        //
        ReportUsage (DriverObject, deviceObject, OutPortAddr, &ResourceConflict);

        if (ResourceConflict) {
            RS_DbgPrint("RS485NT: Couldn't get resources\n");
            IoDeleteDevice(deviceObject);
            return STATUS_INSUFFICIENT_RESOURCES;
        }

        //
        // fill in the device extension
        //
        extension = (PRS485NT_DEVICE_EXTENSION) deviceObject->DeviceExtension;
        extension->DeviceObject = deviceObject;
        extension->PortAddress = (PVOID)OutPortAddr.LowPart;

        //
        // connect the device driver to the IRQ
        //
        ioConnectStatus = IoConnectInterrupt(&extension->InterruptObject,
                                             RS485_Isr,
                                             extension->DeviceObject,
                                             NULL,
                                             MappedVector,
                                             irql,
                                             irql,
                                             Latched,
                                             FALSE,
                                             Affinity,
                                             FALSE);

        if ( !NT_SUCCESS (ioConnectStatus) ) {
            RS_DbgPrint("RS485NT: Couldn't connect interrupt\n");
            IoDeleteDevice(deviceObject);
            return ioConnectStatus;
        }

        RS_DbgPrint("RS485NT: 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.
        //
        
        status = IoCreateSymbolicLink( &uniWin32NameString, &uniNtNameString );

        if (!NT_SUCCESS(status)) {
            RS_DbgPrint("RS485NT: Couldn't create the symbolic link\n");
            IoDeleteDevice (DriverObject->DeviceObject);
        } else {

            //
            // Setup the Dpc for ISR routine
            //

            IoInitializeDpcRequest (DriverObject->DeviceObject, RS485_Dpc_Routine);

            //
            // Initialize the device (enable IRQ's, hit the hardware)
            //

            Initialize_RS485 (extension);

            RS_DbgPrint("RS485NT: All initialized!\n");
        }

    } else {
        RS_DbgPrint("RS485NT: Couldn't create the device\n");
    }
    return status;
}


//---------------------------------------------------------------------------
// RS485_Isr
//
// Description:
//  This is our 'C' Isr routine to handle RS485 transmit and recieve
//
// Arguments:
//      Interrupt   - Pointer to our interrupt object
//      Context     - Pointer to our device object
//
// Return Value:
//      TRUE        - If this was our ISR (assumed)
//
BOOLEAN RS485_Isr (IN PKINTERRUPT Interrupt, IN OUT PVOID Context)
{
    PDEVICE_OBJECT DeviceObject;
    PRS485NT_DEVICE_EXTENSION DeviceExtension;
    UCHAR   ch;

    //
    // Get the Device Object and obtain our Extension
    //

    DeviceObject = Context;
    DeviceExtension = DeviceObject->DeviceExtension;

    //
    // Bump the interrupt count
    //

    DeviceExtension->InterruptCount++;
    
    RS_DbgPrint ("RS485NT: ISR!\n");

    //
    // For the 8250 series UART, we must spin and handle ALL interrupts
    // before returning
    //

    ch = READ_PORT_UCHAR (DeviceExtension->ComPort.IIR);

    while ((ch & IIR_INTERRUPT_MASK) != IIR_NO_INTERRUPT_PENDING) {
        switch (ch & IIR_INTERRUPT_MASK) {

            case IIR_RX_ERROR_IRQ_PENDING:      // 1st priority interrupt
                RS_DbgPrint ("RS485NT: ISR RX Error!\n");
                ch = READ_PORT_UCHAR (DeviceExtension->ComPort.LSR);
                DeviceExtension->RcvError++;
                break;

            case IIR_RX_DATA_READY_IRQ_PENDING: // 2nd priority int

                RS_DbgPrint ("RS485NT: ISR RX Data!\n");

                //
                // Read the UART receive register and stuff byte into buffer
                //

                ch = READ_PORT_UCHAR (DeviceExtension->ComPort.RBR);

                //
                // Check for end of buffer
                //

                if (DeviceExtension->RcvBufferPosition+1 < 
                    DeviceExtension->RcvBufferEnd) {

                   *DeviceExtension->RcvBufferPosition = ch;
                    DeviceExtension->RcvBufferPosition++;
                    DeviceExtension->RcvBufferCount++;
                }

                //
                // Get the current system time
                //

                KeQuerySystemTime (&DeviceExtension->LastQuerySystemTime);

                break;
            
            case IIR_TX_HBE_IRQ_PENDING:        // 3rd priority interrupt

                RS_DbgPrint ("RS485NT: ISR TX Data!\n");

                //
                // Is this the last byte sent?
                //

                if (DeviceExtension->XmitBufferCount == 0) {

                    //
                    // Wait for the entire character to be sent out the UART
                    //

                    ch = READ_PORT_UCHAR (DeviceExtension->ComPort.LSR);

                    while ( (ch & LSR_TX_BOTH_EMPTY) != LSR_TX_BOTH_EMPTY) {
                        ch = READ_PORT_UCHAR (DeviceExtension->ComPort.LSR);
                    }

                    //
                    // De-assert RTS
                    //

                    ch = READ_PORT_UCHAR (DeviceExtension->ComPort.MCR) & 
                         MCR_DEACTIVATE_RTS;
                    WRITE_PORT_UCHAR (DeviceExtension->ComPort.MCR, ch);

                    //
                    // Clear the Rcv buffer info, a reply is emminent
                    //

                    DeviceExtension->RcvBufferCount = 0;
                    DeviceExtension->RcvBufferPosition = DeviceExtension->RcvBuffer;

                    //
                    // Schedule the DPC (where the Xmit done event is set)
                    //

                    IoRequestDpc (DeviceObject, DeviceObject->CurrentIrp, NULL);

                } else {

                    //
                    // Send the next byte
                    //

                    WRITE_PORT_UCHAR (DeviceExtension->ComPort.TBR,
                                      *DeviceExtension->XmitBufferPosition);

                    DeviceExtension->XmitBufferPosition++;
                    DeviceExtension->XmitBufferCount--;
                }

                //
                // Get the current system time
                //

                KeQuerySystemTime (&DeviceExtension->LastQuerySystemTime);

                break;

            case IIR_MODEM_STATUS_IRQ_PENDING:  // 4th priority interrupt
                RS_DbgPrint ("RS485NT: ISR Modem Status!\n");

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品国产乱码久久久久久1区2区| 午夜精品久久久久久| 亚洲美女精品一区| 久久精品999| 欧洲视频一区二区| 中文字幕乱码久久午夜不卡 | 天天综合天天综合色| 国产精品自拍在线| 69精品人人人人| 亚洲人成在线播放网站岛国| 精品一区二区三区的国产在线播放| 色哟哟亚洲精品| 国产欧美一区二区精品秋霞影院| 奇米影视一区二区三区| 91蜜桃免费观看视频| 国产女同互慰高潮91漫画| 美国精品在线观看| 欧美日韩一区在线| 亚洲女人小视频在线观看| 成人激情动漫在线观看| 欧美大片在线观看一区| 日韩有码一区二区三区| 欧美伊人久久久久久午夜久久久久| 中文字幕中文字幕在线一区 | 99久久久国产精品| 久久久欧美精品sm网站| 久久精品噜噜噜成人av农村| 欧美日本不卡视频| 亚洲成人tv网| 欧美在线三级电影| 亚洲一区在线免费观看| 欧美亚男人的天堂| 亚洲福利一二三区| 欧美三级电影一区| 视频一区视频二区中文| 欧美日韩综合在线免费观看| 一区二区在线观看免费视频播放 | 国产一区不卡精品| 久久综合九色欧美综合狠狠| 蜜桃传媒麻豆第一区在线观看| 欧美日本在线看| 亚洲一区二区三区中文字幕在线| 欧美亚洲国产一区在线观看网站| 亚洲九九爱视频| 欧美色偷偷大香| 亚洲成人综合网站| 91精品国产91久久久久久最新毛片 | 伊人一区二区三区| 欧美日韩视频在线观看一区二区三区| 亚洲一线二线三线视频| 91精品国模一区二区三区| 日本中文字幕一区二区视频| 日韩免费高清电影| 韩国理伦片一区二区三区在线播放| 精品国产三级电影在线观看| 国产露脸91国语对白| 国产精品久久久久久久久久免费看 | 欧美成人官网二区| 国产乱码精品一区二区三区忘忧草| 国产欧美1区2区3区| 91亚洲国产成人精品一区二区三| 亚洲综合丝袜美腿| 精品区一区二区| 成人免费毛片片v| 亚洲国产精品麻豆| 26uuu精品一区二区三区四区在线 26uuu精品一区二区在线观看 | 中文字幕乱码亚洲精品一区| 色呦呦一区二区三区| 奇米四色…亚洲| 国产精品热久久久久夜色精品三区 | 日韩视频免费直播| 成人精品免费看| 视频一区在线视频| 中文字幕一区二区在线观看| 欧美精品v国产精品v日韩精品| 国产麻豆视频精品| 午夜精品久久久久影视| 亚洲丝袜美腿综合| 欧美人牲a欧美精品| 成人18视频在线播放| 天天影视涩香欲综合网| 久久精品一区二区| 欧美精品丝袜中出| av不卡免费在线观看| 久久精品国产99国产| 亚洲免费高清视频在线| 欧美精品一区二区三区在线| 91久久一区二区| 成人黄色在线看| 精品综合久久久久久8888| 一区二区三区鲁丝不卡| 国产日产精品一区| 欧美一区欧美二区| 欧美在线视频日韩| 97久久精品人人爽人人爽蜜臀| 久久97超碰色| 日韩国产精品久久| 亚洲一区二区三区中文字幕| 国产精品福利一区二区三区| www激情久久| 91精品国产色综合久久| 欧美三级午夜理伦三级中视频| 99久久99久久精品国产片果冻| 精品一区二区三区日韩| 亚洲成av人片在线| 樱桃视频在线观看一区| **性色生活片久久毛片| 日本一区二区免费在线| 精品久久国产字幕高潮| 欧美一卡二卡在线观看| 91精品久久久久久久久99蜜臂| 日本电影欧美片| 一本高清dvd不卡在线观看| www.爱久久.com| 国产 欧美在线| www.日本不卡| 99视频精品在线| 99久久精品一区二区| 91视频www| 91激情在线视频| 欧美在线看片a免费观看| 在线观看日韩一区| 在线免费亚洲电影| 欧美日韩一区二区在线视频| 欧美三级乱人伦电影| 56国语精品自产拍在线观看| 欧美日韩免费观看一区三区| 7777精品伊人久久久大香线蕉完整版| 欧美色区777第一页| 欧美一区二区性放荡片| 日韩一区二区三区高清免费看看| 欧美一区二区三区色| 日韩精品中文字幕在线一区| 久久综合九色综合欧美就去吻| 国产人成亚洲第一网站在线播放| 欧美国产在线观看| 亚洲男人天堂av| 爽好久久久欧美精品| 国产一区999| 精品国产99国产精品| 久久午夜免费电影| 中文字幕亚洲一区二区va在线| 亚洲美女一区二区三区| 亚洲成年人网站在线观看| 精品一区二区三区免费| 成人激情黄色小说| 欧美人与性动xxxx| 国产日韩欧美精品在线| 一区二区三区在线视频免费| 爽好多水快深点欧美视频| 国产一区二区免费看| 色综合一个色综合亚洲| 欧美精品v日韩精品v韩国精品v| 精品福利视频一区二区三区| 自拍偷拍亚洲综合| 美腿丝袜亚洲综合| 成人激情文学综合网| 在线成人小视频| 亚洲国产岛国毛片在线| 偷窥国产亚洲免费视频| 丰满少妇久久久久久久| 欧美亚男人的天堂| 中文字幕国产一区| 日韩成人午夜精品| 99久精品国产| 欧美videos大乳护士334| 亚洲精品视频在线看| 国产一区在线看| 欧美日韩国产成人在线91| 中文一区二区在线观看| 手机精品视频在线观看| 日本道精品一区二区三区| 国产三级欧美三级日产三级99| 偷拍一区二区三区| 97精品国产97久久久久久久久久久久| 日韩欧美中文一区| 亚洲精品精品亚洲| 成人免费高清视频| 久久综合色8888| 日韩不卡在线观看日韩不卡视频| 91在线一区二区三区| 国产蜜臀av在线一区二区三区| 视频一区二区三区中文字幕| 色综合天天天天做夜夜夜夜做| 久久亚洲精精品中文字幕早川悠里| 亚洲午夜激情网页| 色88888久久久久久影院野外| 久久精品男人的天堂| 国内精品在线播放| 日韩欧美国产一区二区在线播放| 亚洲va国产va欧美va观看| 91成人免费电影| 亚洲综合图片区| 欧美影院一区二区三区| 亚洲国产精品视频| 欧美三级日本三级少妇99| 亚洲成人在线免费| 欧美日韩国产精品成人| 视频在线观看一区| 91精品国产91久久综合桃花|