Another gotcha- @ and ! can break interrupts
Alex Holden <[email protected]> Sun, 14 Nov 2004 18:42:38 +0000
| Newsgroups | gmane.comp.lang.forth.picforth |
|---|---|
| Message-ID | <[email protected]> |
Here's another gotcha which took me a couple of hours to get to the bottom of. Sometimes when you do '@' and '!' picforth will ask you to include libfetch.fs / libstore.fs. These files define words called any-@ and any-! which are sometimes called when you use '@' and '!'. any-@ and any-! use suspend-interrupts and restore-interrupts to prevent interrupts from occuring in the middle of a fetch or store. I also used suspend-interrupts and restore-interrupts to protect a critical section of my own, which happened to call '@' a couple of times. If suspend-interrupts is called twice without a restore inbetween, the next restore-interrupts will restore the state after the first suspend-interrupts (ie. interrupts-off). So what was happening was that every time my word with the critical section in it was called, the interrupt system on the PIC froze solid. I can think of a few possible solutions: * Make suspend/restore-interrupts take an argument which is a number between 0 and 7 that points to which bit in the isr-enabled variable to use (so system-type stuff could use a different bit in isr-enabled to user-type stuff). * Make suspend/restore-interrupts nestable by creating a new variable which is used to automatically keep track of which bit in the isr-enabled variable was used by the last save-interrupts. * Have two versions of suspend/restore-interrupts which use different bits in isr-enabled - one intended for 'system' type words with critical sections in them, and one intended for user defined words. * Simply revise the documentation to warn against using suspend/restore-interrupts unless you're absolutely certain none of the words in your critical section also use them (pointing out that even @ and ! aren't safe). -- ------------ Alex Holden - http://www.linuxhacker.org ------------ If it doesn't work, you're not hitting it with a big enough hammer