|
In lugnet.robotics.rcx.pbforth, Richard Lucock writes:
> Is there any way of ABORTing the current program from the ISR ? I
> want to attach a routine to 'UserISR and have it ABORT and then execute
> POWER_OFF when the off/on button is pressed.
To remove your program from the UserISR just set 'UserISR to ['] NoOp -
or even better: to the previously stored old value.
> I would also like to know whether a user program or the idle loop
> is running, so that the code could do different things depending on whether
> it was powered down while idling or while executing a program (obviously, the
> program could set a flag, but I would like this to be general). Does pbForth
> supply any way of getting this info ?
Yes, you just have to read the current value of 'UserISR.
If no other program is hooked to the ISR this is the same as the
execution address of NoOp.
For example
: IsISRFree? 'UserISR ['] NoOp = IF ;
IsISRFree? IF
\ no other program is hooked
ELSE
\ there is another prog. running in the ISR
THEN
Have a look at the following sample script; it demonstrates how to save and
restore a previously running ISR program.
Greetings,
Alex
----- begin sample script -----
\ UserISR-Test
\
\ TEST_1 starts a common-style UserISR hook
\ TEST_2 starts a more sophisticated hook which
\ saves and optionally calls the old hook
\ and restores it when finished.
BASE @
HEX
' NoOp VALUE 'OldUsrISR
0 VALUE myisr_oldval
: MyISR
0 TIMER_GET
DUP myisr_oldval = IF
ELSE
DUP 3002 SWAP 301F LCD_NUMBER LCD_REFRESH
THEN
DUP TO myisr_oldval
C8 > IF \ terminate if timer > 200 (= 0xC8)
2 4004 SOUND_PLAY \ downward tone
'OldUsrISR TO 'UserISR \ restore old vector
['] NoOp TO 'OldUsrISR
THEN
'OldUsrISR EXECUTE \ [optional] call old hook
;
: INIT_ISR ( exec_address -- ) \ call like: ' MyISR INIT_ISR
'UserISR TO 'OldUsrISR \ save old vector
TO 'UserISR \ and activate new
;
0 VALUE testoldhook_cnt
: TEST_OLDHOOK \ click-sound every second (every 1000'th) call
testoldhook_cnt 1+ TO testoldhook_cnt
testoldhook_cnt 3E8 > IF \ dec.1000 = 0x3E8
0 4004 SOUND_PLAY
0 TO testoldhook_cnt
THEN
;
: TEST_1 ['] TEST_OLDHOOK TO 'UserISR ;
: TEST_2
0 0 TIMER_SET
['] MyISR INIT_ISR
;
: CLEARISR ['] NoOp TO 'UserISR ;
BASE !
----- end sample script -----
|
|
Message has 2 Replies: | | Re: Aborting from ISR
|
| Hi, (...) My questions were a bit ambiguous. I don't want to abort the routine running on the ISR; I want (from the ISR routine) to abort a currently running user routine - eg abort something started from the console. So, for example, if a program (...) (22 years ago, 15-Jul-02, to lugnet.robotics.rcx.pbforth)
|
Message is in Reply To:
| | Aborting from ISR
|
| Hi, Is there any way of ABORTing the current program from the ISR ? I want to attach a routine to 'UserISR and have it ABORT and then execute POWER_OFF when the off/on button is pressed. I would also like to know whether a user program or the idle (...) (22 years ago, 14-Jul-02, to lugnet.robotics.rcx.pbforth)
|
10 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|