阅读:1367回复:0
答应大家做出中断后给大家一个结果
首先,应用程序创建一个事件,然后在子线程里,无限等待事件被Set()
然后,逻辑里使用了一个FIFO,当其半满时候提出中断 最后,驱动程序获得中断后,将获得的事件Set() 代码如下: // Test_dma_2_p.cpp // // Generated by DriverWizard version DriverStudio 2.7.0 (Build 562) // // This console application demonstrates how to open a handle // to a device in your driver, and communicate with the driver // using Read, Write, and DeviceIoControl calls, as appropriate. // // This test program attempts to open the device using the // GUID defined in "..\Dma_2_pDeviceinterface.h" #include <conio.h> #include <stdlib.h> #include <stdio.h> #include <windows.h> #include <winioctl.h> #include "..\dma_2_pioctl.h" #include "..\Dma_2_pDeviceinterface.h" // Has class GUID definition // This function is found in module OpenByIntf.cpp HANDLE OpenByInterface(GUID* pClassGuid, DWORD instance, PDWORD pError); void Test_READ_DATA(void); // Global data // Handle to device opened in driver. HANDLE hDevice = INVALID_HANDLE_VALUE; HANDLE hEvent = INVALID_HANDLE_VALUE; // Class GUID used to open device // GUID ClassGuid = Dma_2_pDevice_CLASS_GUID; DWORD WINAPI ThreadProc(LPVOID junkola) { // ThreadProc while(TRUE) { WaitForSingleObject(hEvent, INFINITE); puts("Event happened"); Test_READ_DATA(); } return 0; } //////////////////////////////////////////////////////////////////////// // Main entry point // // int __cdecl main(int argc, char *argv[]) { // int nArgIndex; // Walk through command line arguments int nArgIncrement = 0; // int val; DWORD Error; printf("Test application Test_dma_2_p starting...\n"); hDevice = OpenByInterface( &ClassGuid, 0, &Error); if (hDevice == INVALID_HANDLE_VALUE) { printf("ERROR opening device: (%0x) returned from CreateFile\n", GetLastError()); //Exit(1); } else { printf("Device found, handle open.\n"); } //add by clb on MARCH THE THIRD 15:23 DWORD junk; hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); if (!DeviceIoControl(hDevice, DMA_2_P_IOCTL_write, &hEvent, sizeof(hEvent), NULL, 0, &junk, NULL)) { printf("Error %d in EVENT_REGISTER call\n", GetLastError()); CloseHandle(hEvent); CloseHandle(hDevice); exit(1); } HANDLE hThread = CreateThread(NULL, 0, ThreadProc, NULL, 0, &junk); printf("press any key to exit . . .\n"); getch(); CloseHandle(hEvent); CloseHandle(hDevice); return 0; } #define IOCTL_INBUF_SIZE 512 #define IOCTL_OUTBUF_SIZE 512 void Test_READ_DATA(void) { CHAR bufInput[IOCTL_INBUF_SIZE]; // Input to device CHAR bufOutput[IOCTL_OUTBUF_SIZE]; // Output from device ULONG nOutput; // Count written to bufOutput // Call device IO Control interface (READ_DATA) in driver bufOutput[0]='w'; bufOutput[1]='a'; bufOutput[2]='h'; printf("Received data : "); if (!DeviceIoControl(hDevice, DMA_2_P_IOCTL_read, bufInput, IOCTL_INBUF_SIZE, bufOutput, IOCTL_OUTBUF_SIZE, &nOutput, NULL) ) { printf("ERROR: DeviceIoControl returns %0x.", GetLastError()); exit(1); } printf("%s\n", bufOutput); } 希望上面的东西对大家有用! |
|