|
|
| Author |
Message |
GTBecker
Joined: 18 Jan 2006
Posts: 457
Location: Cape Coral
|
|
Posted: 10 January 2010, 1:15 AM Post subject: StatusTask() TaskWaitInputCapture |
|
|
I'm trying to terminate an overtime InputCapture. If an InputCapture hasn't completed within about 17mS, I want to end it and move on; available timebase divisors make the natural 16-bit timeout ~35mS, so 50% is wasted if I rely on that. StatusTask() never seems to indicate that Main() is TaskWaitInputCapture.
I've tried to demonstrate that with the following code, which puts ~60Hz on pin 11 (ZX-24 Int1), uses WaitForInterrupt to trigger on that, testing Main's task status, which should be waiting on InputCaptureEx. LEDs show no activity at their current positions, but just outside of their respective tests, they show activity.
What am I doing wrong here, Don?
In my first post I left out the important step, the ExitTask() and Yield(). The corrected test code is: | Code: | ' ZX-24 task mode change test
const pinInt1Not as byte = 11 ' /vsync
const pinICPNot as byte = 12 ' /vsync-/vpeak delay
const pinRLED as byte = 25
const pinGLED as byte = 26
const LEDOn as byte = 0
const LEDOff as byte = 1
dim RLED as byte, GLED as byte
dim uiICP as unsignedinteger, InputCaptureCancelled as boolean
dim SyncTaskStack(1 to 40) as byte
dim TestSignalTaskStack(1 to 40) as byte
Sub Main()
call Sleep(1.0)
call putpin(pinICPNot, zxInputPullup)
register.TimerSpeed1 = 2 ' Timer1= 1.843200e6, ICP max period ~=35mS
RLED = LEDOff
GLED = LEDOff
calltask "TestSignalTask", TestSignalTaskStack
calltask "SyncTask", SyncTaskStack
do
' measure delay
InputCaptureCancelled = False
do
call InputCaptureEx(pinICPNot, uiICP, 1, 0, 1)
loop until InputCaptureCancelled
GLED = 1 and not GLED
call putpin(pinGLED, GLED)
loop
end sub
sub SyncTask()
do
waitforinterrupt(zxPinFallingEdge) ' wait for 60Hz fall
' problem seems here:
' StatusTask() of Main is never TaskWaitInputCapture
' despite Main loop around InputCaptureEx
if StatusTask() = TaskWaitInputCapture then
InputCaptureCancelled = True
call ResumeTask()
call Yield()
RLED = 1 and not RLED
call putpin(pinRLED, RLED)
end if
loop
end sub
sub TestSignalTask() ' puts ~60Hz on pin 11 (int1)
do
call putpin(pinInt1Not, zxOutputHigh)
call sleep(0.008)
call putpin(pinInt1Not, zxOutputLow)
call sleep(0.008)
loop
end sub
|
Last edited by GTBecker on 11 January 2010, 1:32 AM; edited 1 time in total |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 10 January 2010, 21:34 PM Post subject: Re: StatusTask() TaskWaitInputCapture |
|
|
| GTBecker wrote: | | What am I doing wrong here, Don? |
Nothing, I think. There is a latent error that prevents the task status from being updated correctly. Which ZX device are you using? |
|
| Back to top |
|
 |
GTBecker
Joined: 18 Jan 2006
Posts: 457
Location: Cape Coral
|
|
Posted: 10 January 2010, 21:44 PM Post subject: |
|
|
> ... Which ZX device...
ZX-24. I can try an -a, or -n, if you like.
I changed the test code again, BTW, replacing an improper ExitTask() with ResumeTask(), but the result is unchanged. I'd used ExitTask() in another attempt that used a one-shot task to run InputCapture. |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 11 January 2010, 3:15 AM Post subject: |
|
|
| GTBecker wrote: | | I can try an -a, or -n, if you like. | Thanks, but that's not necessary. My research indicates that it is a problem in all ZX devices. We'll have to update the VM and release a ZX Library update to correct the issue.
In the mean time, you may be able to utilize a bit in the 'taskFlags' member of the Task Control Block. Bit 7 of the taskFlags member indicates that the task is awaiting InputCapture. The example code shows how to access the taskFlags member for VM device. The code is written to test both the Main() task and an alternate task, controlled by a #define.
| Code: | Dim ts1(1 to 100) as Byte
Dim captData(1 to 20) as UnsignedInteger
#define INPUT_CAPTURE_IN_MAIN
Structure TCB_VM
Dim status as Byte
Dim sleepTime as UnsignedInteger
Dim nextTCB as UnsignedInteger
Dim context1 as UnsignedInteger
Dim context3 as UnsignedInteger
Dim context2 as UnsignedInteger
Dim flags as Byte
End Structure
Sub Main()
CallTask task1, ts1
#if defined(INPUT_CAPTURE_IN_MAIN)
Call InputCapture(captData, UBound(captData), 1)
#else
Call Sleep(0.5)
Debug.Print "Status of task1() is "; StatusTask(ts1)
Call dspTaskFlags(ts1.DataAddress)
#endif
Do
Loop
End Sub
Sub task1()
#if defined(INPUT_CAPTURE_IN_MAIN)
Call Sleep(0.5)
Debug.Print "Status of Main() is "; StatusTask()
Call dspTaskFlags(Register.TaskMain)
#else
Call InputCapture(captData, UBound(captData), 1)
Debug.Print "After InputCapture() in task1()"
#endif
Do
Loop
End Sub
Sub dspTaskFlags(ByVal tcbAddr as UnsignedInteger)
Dim taskControlBlock as TCB_VM Based tcbAddr
Debug.Print "taskFlags = 0x"; CStrHex(taskControlBlock.flags)
End Sub
|
|
|
| Back to top |
|
 |
GTBecker
Joined: 18 Jan 2006
Posts: 457
Location: Cape Coral
|
|
Posted: 11 January 2010, 22:44 PM Post subject: |
|
|
Thanks, Don. That appears to work.
Does the StatusTask issue also affect native devices? |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 11 January 2010, 23:14 PM Post subject: |
|
|
| GTBecker wrote: | | Does the StatusTask issue also affect native devices? | Yes, it does. We're working on an update of the VM and the ZX Library that corrects the problem for both VM-based and native mode devices. |
|
| Back to top |
|
 |
|