Help with InterruptPort

I have a need for a better understanding of the InterruptPort class and interrupt ports in general.

I have a Cobra III board using the G120 SoM. I have progressed through the document NETMF_for_Beginners.pdf to section 7.2 Interrupt Port. With minor modifications needed for the Cobra III board, I’ve completed the two examples for using interrupt capabilities, one when the main thread is sleeping, and the other example when the main thread exists in a forever loop. Both examples work as advertised with the code in the document.

The InterruptPort I created in my code consisted of:

InterruptPort(FEZCobraIII.Gpio.Ldr0, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

I used Ldr0 as input port because it has a populated switch button on my board, and because it appears unused except at bootup of the board.

I then started to look deeper into the InterruptPort class. I became confused with some things of which I’m hoping to gain a better understanding.

I wanted to catch a single interrupt whilst blocking all other interrupts (on the Ldr0 pin) until the pending interrupt got handled. I read about the ClearInterrupt method. The information about ClearInterrupt indicates that its use must have the InterruptPort configured with InterruptMode.InterruptEdgeLevelHigh or an InterruptMode.InterruptEdgeLevelLow. I wanted to catch a single interrupt condition, handle it, and then wait for the next interrupt on the Ldr0 pin.

I wanted to test the InterruptEdgeLevelLow option (and to use the ClearInterrupt method) but when I modified the code to do that, including changing the last parameter of the InterruptPort constructor to Port.InterruptMode.InterruptEdgeLevelLow, I got the following exception when executing the following code:

SelectButton.OnInterrupt += SelectButton_OnInterrupt;

Exception System.ArgumentException - 0xfd000000 (1)


Microsoft.SPOT.Hardware.InterruptPort::EnableInterrupt [IP: 0000]

Microsoft.SPOT.Hardware.NativeEventDispatcher::add_OnInterrupt [IP: 0027]

NETMFBook.Program::Main [IP: 001c]

Now I have a concern about the selection of an “interrupt capable” port. However; something I read in search for information about interrupt capable ports indicated that “almost all GPIO pins are interrupt capable”. In further looking into this problem, I noted that the Microsoft.SPOT.Hardware namespace contains a Cpu.PinValidInterruptMode enumeration. The Cpu.PinValidInterruptMode consists of the same members as the Cpu.Port.InterruptMode enumeration, except that the Cpu.PinValidInterruptMode enumeration has a Flags attribute to allow a variable for that type to contain a set of individual values representing the total capability of a pin to respond to interrupts of various modes. Because this enumeration exists, I think pins exist on a G120 (or any other NETMF supported module) that have [em]varying[/em] interrupt capabilities. I cannot find a method or property that returns a Cpu.PinValidInterruptMode enumeration for a Pin class object that would indicate, programmatically, whether any G120 pin would support any specific type of interrupt (and not support other types).

Can anyone tell me how I might query a specific object to obtain a Cpu.PinValidInterruptMode enumeration value for a designated GPIO? If so, that might shed light on how I can find GPIO I can use to create an InterruptPort that would support an InterruptMode.InterruptEdgeLevelLow and would allow the use of the ClearInterrupt method.

See page 37 of the G120 manual.