public static void testFn() { uint hEvent; uint dwEdge = 0, dwGpio = 0; uint dwIrq = 0, dwSysIntr = 0; uint dwOutBuf = 0; uint dwBytesReturned = 0; int err; bool ret; String retText; // Get the IRQ # for this GPIO dwGpio = 36; ret = CoreDll.KernelIoControl(CoreDll.IOCTL_HAL_GPIO2IRQ, ref dwGpio, sizeof(uint), ref dwIrq, sizeof(uint), ref dwBytesReturned); // Configure for an interrupt on the rising edge dwEdge = CoreDll.GPIO_EDGE_RISING; if (!CoreDll.KernelIoControl(CoreDll.IOCTL_HAL_IRQEDGE, ref dwIrq, 1, ref dwEdge, 1, ref dwBytesReturned)) { throw new Win32Exception(err = Marshal.GetLastWin32Error()); } // Create an event associated with this interrupt hEvent = CoreDll.CreateEvent(0, false, false, null); retText = hEvent.ToString(); // Register the event ret = CoreDll.KernelIoControl(CoreDll.IOCTL_HAL_REQUEST_SYSINTR, ref dwIrq, sizeof(uint), ref dwSysIntr, sizeof(uint), ref dwBytesReturned); // Initialize the interrupt ret = CoreDll.InterruptInitialize(dwSysIntr, hEvent, 0, 0); // Clear the interrupt if there was one pending CoreDll.InterruptDone(dwSysIntr); // Wait for something to happen! bool Exit = false; while (!Exit) { if (CoreDll.WaitForSingleObject(hEvent, CoreDll.INFINITE) == CoreDll.WAIT_OBJECT_0) { CoreDll.InterruptDone(dwSysIntr); if (MessageBox.Show("Interrupt!", "Wait again", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No) //If( DialogResult.No == MessageBox.Show("Interrupt!","Wait again",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1)) { Exit = true; } } } // Disable any previously registered event CoreDll.InterruptDisable(dwSysIntr); CoreDll.KernelIoControl(CoreDll.IOCTL_HAL_RELEASE_SYSINTR, ref dwSysIntr, sizeof(uint), System.IntPtr.Zero, 0, ref dwBytesReturned); //if (!CoreDllWrapper.KernelIoControl(CoreDllWrapper.IOCTL_HAL_RELEASE_SYSINTR, ref dwSysIntr, sizeof(uint), System.IntPtr.Zero, 0, ref dwBytesReturned)) throw new Win32Exception(err = Marshal.GetLastWin32Error()); }
/// <summary> /// Releases power requirement. /// </summary> /// <exception cref="System.InvalidOperationException">Cannot close device.</exception> public void Release() { if (mHandle != IntPtr.Zero) { if (CoreDll.ReleasePowerRequirement(mHandle) != CoreDll.SUCCESS) { throw new InvalidOperationException("Cannot close device."); } mHandle = IntPtr.Zero; } }
/// <summary> /// Sets power requirement. /// </summary> /// <exception cref="System.InvalidOperationException">Device already open. -or- Cannot open device.</exception> public void Set(PowerRequirementState powerState) { if (mHandle != IntPtr.Zero) { throw new System.InvalidOperationException("Device already open."); } mHandle = CoreDll.SetPowerRequirement(mDeviceName, powerState, CoreDll.POWER_NAME, IntPtr.Zero, 0); if (mHandle == IntPtr.Zero) { throw new System.InvalidOperationException("Cannot open device."); } }