singrdk/base/Applications/Runtime/Full/Singularity/Io/IoIrq.cs

84 lines
1.9 KiB
C#
Raw Normal View History

2008-03-05 09:52:00 -05:00
///////////////////////////////////////////////////////////////////////////////
//
// Microsoft Research Singularity
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
2008-11-17 18:29:00 -05:00
// Note: Process Code
2008-03-05 09:52:00 -05:00
//
using System;
using System.Threading;
using Microsoft.Singularity.V1.Threads;
namespace Microsoft.Singularity.Io
{
[CLSCompliant(false)]
public sealed class IoIrq : IoRange
{
private readonly byte irq;
private InterruptHandle handle;
internal IoIrq(byte irq)
{
this.irq = irq;
}
~IoIrq()
{
2008-11-17 18:29:00 -05:00
if (handle.id != UIntPtr.Zero) {
2008-03-05 09:52:00 -05:00
ReleaseInterrupt();
}
}
public byte Irq
{
get { return irq; }
}
public bool RegisterInterrupt()
{
InterruptHandle handleOnStack;
bool success = InterruptHandle.Create(irq, out handleOnStack);
handle = handleOnStack;
return success;
}
public bool ReleaseInterrupt()
{
bool ret = InterruptHandle.Dispose(handle);
handle = new InterruptHandle();
return ret;
}
public bool WaitForInterrupt()
{
2008-11-17 18:29:00 -05:00
if (handle.id != UIntPtr.Zero) {
2008-03-05 09:52:00 -05:00
return InterruptHandle.Wait(handle);
}
return false;
}
public void Pulse()
{
2008-11-17 18:29:00 -05:00
if (handle.id != UIntPtr.Zero) {
2008-03-05 09:52:00 -05:00
InterruptHandle.Pulse(handle);
}
}
public bool AckInterrupt()
{
2008-11-17 18:29:00 -05:00
if (handle.id != UIntPtr.Zero) {
2008-03-05 09:52:00 -05:00
return InterruptHandle.Ack(handle);
}
return false;
}
public override string ToString()
{
return String.Format("IRQ:{0,2:x2}", irq);
}
}
}