Recent change for disabled interrupts during INKEY
Andrew Rawnsley (492) 1445 posts |
Hi folks, just saw the recent change in the git history to disable interrupts during INKEY. Not sure what prompted this, and my fears may be unfounded – haven’t been able to try a ROM to see it yet. However, in various cases I’ve found INKEY to be a very useful way of inserting small pauses to allow things to complete initialisation before triggering the next step. For example, USB and Ethernet drivers may return before being completely “up”, and if you have things running at startup (eg. predesk) that are dependant, INKEY is a useful one-line solution. It may be that I’ve got the wrong end of the stick, but it certainly concerned me that INKEY would now “block” completely… |
Jeffrey Lee (213) 6048 posts |
The changes should be safe. The commit message doesn’t make it particularly clear, but interrupts will only be disabled for part of the wait loop, not all of it. Specifically, interrupts are disabled for the critical section of "IF NOT FNkey_available() THEN SYS "Portable_Idle"". Portable_Idle puts the CPU to sleep until the next interrupt. Keeping interrupts disabled for the entire sequence avoids the problem where the CPU could sleep for longer than necessary if a key interrupt arrives inbetween the buffer being checked and the CPU going to sleep. Once the CPU comes back from sleep, interrupts are re-enabled, to allow the pending interrupt (and any callbacks) to be triggered. |
Andrew Rawnsley (492) 1445 posts |
Thanks for that, Jeffrey – much appreciated. |