Low level Int

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
GTBecker
Posts: 616
Joined: 17 January 2006, 19:59 PM
Location: Cape Coral

Low level Int

Post by GTBecker »

If an interrupt handler invokes LockTask immediately after a WaitForInterrupt(zxPinLow), and does not UnlockTask before reinvoking the WaitForInterrupt with a still-low pin, will the WaitForInterrupt be immediately satisfied before another task might get a tick?

Tom
Tom
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

I'm not sure I understand what you're trying to do. When you say "interrupt handler" are you referring to an Interrupt Service Routine in a native mode application or are you referring to a task that waits for an interrupt via WaitForInterrupt()?
- Don Kinzer
GTBecker
Posts: 616
Joined: 17 January 2006, 19:59 PM
Location: Cape Coral

Post by GTBecker »

Sorry. It is a task on a ZX-24a that watches two axes in quadrature at ~2kHz combined edge rate. The interrupt line is the output of a four-bit comparator, four from the quadrature sensors, four from the processor. At each interrupt, code determines the appropriate axis counts, and acks the quadrature changes by matching them on the comparator, which would then normally raise the Int line (to inactive).

If another quadrature change occurs during the processing of one interrupt, the Int line will remain active (low). Will there be a potential task switch at the next WaitForInterrupt if LockTask is still in effect for that task?
Tom
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

GTBecker wrote:Will there be a potential task switch at the next WaitForInterrupt if LockTask is still in effect for that task?
After reviewing the code, I'm convinced that the task awaiting the interrupt would remain in control.

I believe that the test code below proves that task1 remains in control with the Int0 input grounded, effectively starving out Main. When run, the red LED remains illuminated as long as task1 remains in complete control.

Code: Select all

Dim ts1(1 to 200) as Byte
Dim state as Byte

Sub Main()
  state = 0
  Call PutPin(Pin.RedLED, zxOutputHigh)
  Call PutPin(Pin.GreenLED, zxOutputHigh)
  CallTask task1, ts1
  Do While &#40;state <= 1&#41;
    Call Sleep&#40;0.1&#41;
    state = 1
  Loop
  Call PutPin&#40;Pin.GreenLED, zxOutputLow&#41;
End Sub

Sub task1&#40;&#41;
  Call PutPin&#40;Pin.RedLED, zxOutputLow&#41;
  Do While &#40;state = 0&#41;
    Call WaitForInterrupt&#40;zxPinLow, 0&#41;
    Call LockTask&#40;&#41;
  Loop
  Call PutPin&#40;Pin.RedLED, zxOutputHigh&#41;
  state = 2
End Sub
- Don Kinzer
Post Reply