亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
欧美sm美女调教| 懂色av一区二区三区免费看| 成人国产精品免费网站| 91精品国产91久久久久久最新毛片| 国产农村妇女毛片精品久久麻豆 | 欧美精品一区二区三区高清aⅴ| 亚洲日本丝袜连裤袜办公室| 国产一本一道久久香蕉| 67194成人在线观看| 亚洲一区视频在线观看视频| 成人综合激情网| 精品国产制服丝袜高跟| 日本sm残虐另类| 欧美麻豆精品久久久久久| 亚洲精品午夜久久久| 成人午夜视频福利| 国产午夜精品一区二区三区视频| 久久综合综合久久综合| 99精品视频在线观看免费| 日韩区在线观看| 精品一二线国产| 91蝌蚪porny| 国产精品成人一区二区三区夜夜夜| 五月天激情小说综合| 欧美日韩视频一区二区| 日本女优在线视频一区二区| 精品剧情在线观看| 国产成a人亚洲| 综合网在线视频| 国产成人免费视频网站| 欧美一区二区美女| 国产视频911| 国产精品一区2区| 国产精品久久看| 日韩欧美中文一区| 欧美成人官网二区| 97se亚洲国产综合在线| 日韩电影网1区2区| 欧美午夜一区二区三区| 亚洲成av人片www| 国产精品久久久久毛片软件| 91在线视频播放地址| 亚洲电影中文字幕在线观看| 884aa四虎影成人精品一区| 国产在线播放一区三区四| 国产精品久久夜| 91精品国产福利| 国产1区2区3区精品美女| 亚洲一区中文日韩| 久久久亚洲精华液精华液精华液| 99国产精品久久久| 极品尤物av久久免费看| 亚洲日本丝袜连裤袜办公室| 日韩一区二区在线看| 99视频有精品| 成人av集中营| 久久激情综合网| 国产在线精品一区二区| 国产精品天美传媒| 91日韩精品一区| 亚洲一二三四久久| 久久午夜羞羞影院免费观看| 91成人免费在线视频| 国产精品亚洲а∨天堂免在线| 五月婷婷激情综合网| 成人免费一区二区三区在线观看| 亚洲精品在线电影| 91麻豆123| k8久久久一区二区三区| 成人亚洲一区二区一| 亚洲一区二区3| 亚洲综合一区二区精品导航| 久久久五月婷婷| 欧美大片拔萝卜| 91精品一区二区三区在线观看| 欧美日韩在线播放| 国产凹凸在线观看一区二区| 欧美中文字幕亚洲一区二区va在线| 一区二区三区精品久久久| 91 com成人网| 国产精品1024| 亚洲乱码国产乱码精品精的特点| 欧美日韩国产在线观看| 国产高清视频一区| 亚洲国产视频一区二区| 精品久久久久久亚洲综合网| 91丨porny丨首页| 蜜桃传媒麻豆第一区在线观看| 日本一区二区免费在线| 欧美日韩视频第一区| 高清国产午夜精品久久久久久| 在线观看亚洲a| 一本到三区不卡视频| 精品欧美一区二区三区精品久久| 国产精品午夜电影| 亚洲欧美在线视频| 亚洲一区二区三区免费视频| 亚洲成人在线网站| 久久国产三级精品| 国产不卡视频一区二区三区| 成人亚洲精品久久久久软件| www.日韩精品| 日韩视频一区二区三区在线播放 | 久久久久久久久久电影| 1024成人网色www| 成人av综合在线| 日韩国产欧美在线观看| 欧美国产1区2区| 一区二区三区日韩| 日韩精品一区二区三区在线观看| a亚洲天堂av| 极品少妇一区二区| 亚洲地区一二三色| 国产精品网站在线| 精品美女一区二区三区| 91国模大尺度私拍在线视频| 国产一区二区伦理| 日韩精品成人一区二区三区| 亚洲欧洲制服丝袜| 国产欧美一区二区三区鸳鸯浴 | 91在线观看一区二区| 激情五月婷婷综合网| 亚洲国产精品久久不卡毛片| 国产精品欧美精品| 久久久久久久久久久电影| 欧美一区二区成人6969| 欧美三级视频在线| 91在线精品一区二区| 成人av网址在线观看| 国产一区二区美女| 精品在线一区二区三区| 日本 国产 欧美色综合| 亚洲综合图片区| 亚洲女人的天堂| 亚洲视频在线一区观看| 国产欧美日韩另类一区| 久久精品免费在线观看| 精品国产乱码久久久久久老虎| 日韩一区二区三区视频在线观看| 欧美中文字幕一区二区三区 | 色综合亚洲欧洲| 成人免费观看视频| 国产精品99久久久久久有的能看| 另类综合日韩欧美亚洲| 日本在线播放一区二区三区| 亚洲超碰97人人做人人爱| 欧美三级日韩三级| 午夜伊人狠狠久久| 欧美tickle裸体挠脚心vk| 日本伦理一区二区| 亚洲视频在线观看三级| 99re在线视频这里只有精品| 国产精品美女久久久久久2018| 成人国产精品免费网站| 久久久精品2019中文字幕之3| 国产成人在线视频免费播放| 国产区在线观看成人精品| 国产成人丝袜美腿| 国产精品久久久久一区二区三区共 | 精品国产不卡一区二区三区| 欧美一级国产精品| 制服视频三区第一页精品| 在线成人免费观看| 欧美日韩免费观看一区三区| 欧美日韩精品综合在线| 91.com视频| 精品欧美乱码久久久久久1区2区| 精品成人在线观看| 久久久精品国产免费观看同学| 国产亚洲成av人在线观看导航| 久久精品一级爱片| 中文字幕精品一区二区精品绿巨人 | 色拍拍在线精品视频8848| 色天天综合色天天久久| 777午夜精品免费视频| 日韩视频不卡中文| 久久久精品国产99久久精品芒果| 欧美—级在线免费片| 亚洲美女视频一区| 午夜精品123| 久久黄色级2电影| 国产东北露脸精品视频| 91在线高清观看| 欧美视频中文字幕| 欧美成人在线直播| 欧美极品aⅴ影院| 一二三区精品福利视频| 日本美女一区二区三区视频| 国模一区二区三区白浆| 成人免费福利片| 91久久精品国产91性色tv | 不卡的电视剧免费网站有什么| 99精品视频在线免费观看| 欧美日韩精品免费观看视频| 日韩免费看网站| 日韩理论在线观看| 视频精品一区二区| 国产成人精品aa毛片| 欧美色视频一区| 欧美精品一区在线观看|