![]() | ||
| Home | SwiftX Archive | SwiftForth Archive | |

I've embedded comments below....
On Sunday 10 August 2003 05:49 am, you wrote:
> Hi,
>
> It seems to me the fundamental problem is
> a task can't be halted once it is activated,
> at least not from within itself.
A task could execute the top instruction within itself to stop.
>
> If I change my sequentail leds flashing program
> as suggested by E. Rather then the vectored execution
> problem is solved, but this doesn't solve my problem which
> is to halt the task when pressing a button.
When pressing the button? Does this mean it should resume when the button
is released?
> Further whether TASK BUILD is in START or not doesn't make
> any difference. From outside the task a task can always
> be halted with TASK HALT but not from within the task itself.
>
> New code:
>
> TARGET
>
> |U| |S| |R| BACKGROUND TESTER
> |
> : MYSTART TESTER BUILD ;
> : MYSTOP TESTER HALT ;
>
> CREATE BUTTONS 8 CELLS ALLOT
> ' MYSTOP BUTTONS ! \ in cell 0
>
> : SEQBITFLASH ( -- )
>
> 1
> BEGIN
> PORTB C@ 2DUP SWAP - AND
> PORTB C! 100 MS 2*
> PORTB C@ 127 = IF DROP 1
> THEN
> 255 PORTB C! 100 MS
> AGAIN ; \ For in task
>
>
> ' SEQBITFLASH BUTTONS CELL + ! \ in cell 1
>
> : nothing ;
>
>
>
>
> : /TESTER ( -- ) MYSTART
>
> $FF DDRB C! \ Set PORTB as OUTPUT
> $FF PORTB C! \ set leds off at start up
> TESTER ACTIVATE
>
> BEGIN PAUSE
> PIND C@ 127 = IF MYSTOP ELSE
> SEQBITFLASH
> THEN
> AGAIN ;
>
In this routine, you are starting seqbitflash but never returning to your
loop. You may want to try:
: /TESTER ( -- ) MYSTART
$FF DDRB C! \ Set PORTB as OUTPUT
$FF PORTB C! \ set leds off at start up
BEGIN PAUSE
PIND C@ 127 = IF MYSTOP THEN
PIND C@ 191 = IF TESTER ACTIVATE SEQBITFLASH THEN
AGAIN ;
But this still has problems. You could enhance it with WAITNOKEY to
prevent repeatedly starting/restarting SEQBITFLASH:
: WAITNOKEY ( -- )
BEGIN PIND C@ 255 = UNTIL ;
: /TESTER ( -- ) MYSTART
$FF DDRB C! \ Set PORTB as OUTPUT
$FF PORTB C! \ set leds off at start up
BEGIN PAUSE
PIND C@ 127 = IF MYSTOP WAITNOKEY THEN
PIND C@ 191 = IF TESTER ACTIVATE SEQBITFLASH WAITNOKEY THEN
AGAIN ;
>
>
> { ---- ALTERNATIVE and assuming MYSTART is in GO in App.f
> ---------------------
>
> : /TESTER ( -- )
>
> $FF DDRB C! \ Set PORTB as OUTPUT
> $FF PORTB C! \ set leds off at start up
> TESTER ACTIVATE
>
> BEGIN PAUSE
> PIND C@
> CASE
> 127 OF BUTTONS + @EXECUTE ENDOF
> 191 OF 1 CELLS BUTTONS + @EXECUTE ENDOF
> nothing ENDCASE
> AGAIN ;
> ---------------------------------------------- }
>
>
I would actually do something like this:
127 CONSTANT STOP-BUTTON
191 CONSTANT START-BUTTON
255 CONSTANT NO-BUTTON
FALSE VALUE RUNFLASHER?
: SEQBITFLASH ( -- )
1
BEGIN
RUNFLASHER? IF
PORTB C@ 2DUP SWAP - AND
PORTB C! 100 MS 2*
PORTB C@ 127 = IF DROP 1
THEN
255 PORTB C!
THEN
100 MS
AGAIN ; \ For in task
: WAITNOKEY ( -- )
BEGIN PIND C@ NOBUTTON = UNTIL ;
: /TESTER ( -- ) MYSTART
$FF DDRB C! \ Set PORTB as OUTPUT
$FF PORTB C! \ set leds off at start up
TESTER ACTIVATE SEQBITFLASH
BEGIN PAUSE
PIND C@ STOPBUTTON = IF FALSE TO RUNFLASHER? WAITNOKEY THEN
PIND C@ STARTBUTTON = IF TRUE TO RUNFLASHER? WAITNOKEY THEN
AGAIN ;
Personally, I think the above reads more easily. I also believe that using
a value to indicate whether or not the LEDs are sequencing makes it easier
for another task to determine if they are or not by simply testing
RUNFLASHER?. I'm sure Elizabeth Rather or any of the Forth, Inc. staff
would have deeper insights and better techniques.
Cheers,
Noel
>
> Thanks in advance for any info,
> Viviane Beullens
> ----------------------------------------------------------------------
> swiftx_at_forth.com The SwiftX programming discussion email list
> To unsubscribe, send subject "unsubscribe" to swiftx-request_at_forth.com
> For list command help, send subject "help" to swiftx-request_at_forth.com
> Message archives are located at http://www.forth.com/archive/swiftx
> ----------------------------------------------------------------------
> This list is a forum for SwiftX users. For product support and bug
> reports, please send email to support_at_forth.com
> ----------------------------------------------------------------------
----------------------------------------------------------------------
swiftx_at_forth.com The SwiftX programming discussion email list
To unsubscribe, send subject "unsubscribe" to swiftx-request_at_forth.com
For list command help, send subject "help" to swiftx-request_at_forth.com
Message archives are located at http://www.forth.com/archive/swiftx
----------------------------------------------------------------------
This list is a forum for SwiftX users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Sun Aug 10 2003 - 07:30:03 PDT
This archive was generated by hypermail 2.2.0 : Fri Dec 05 2008 - 03:04:21 PST