RE: "using" attribute
pls make it clear the following statement
The register bank number currently in use (0..3) is stored on the
stack, so that it can be restored later. This is a value separate
from the contents of the registers themselves.
main (using 0)
---> interrupt (using 1)
---> push reg bank 0
---> set register bank = 1
---> push other values
---> handle interrupt
---> restore values
---> set register bank = 0
There are four register banks, each with 8 registers (R0..R7). The
idea is that it can be faster to devote a register bank to an
interrupt so that it does not have to save all 8 registers on entry.
It simply changes the bank instead. The old registers are safe,
because they're in another bank. The idea is similar to the
hard-wired way an ARM works, with some registers replaced with
duplicated during an ISR.
The feature assumes a fairly simple system, with few contexts
(ISRs or tasks). If you have more contexts than you have register
banks, then some of them must share. If the ones that share can
interrupt each other, then they have to save values on the stack.
Once you put in the code (and time) to save values on the stack into
all your contexts, then you might just as well use one register bank.
So, "using" is useful mostly for a very few (three or less) special
interrupts that need very fast execution at the cost of permanently
dedicated system resources.
For a system complicated enough to need an RTOS, you probably have
too many contexts. I'd expect all the RTOS tasks to use one bank (0)
and ignore the others, which might be given to ISRs.
Note that the registers are the first 32 bytes of data space, and
that the 128 bytes of data space are usually a precious resource.
Giving up 8 bytes for a register bank means that the other contexts
are more likely to need xdata, and thus get bigger and slower.
"Using" is best used for a couple of highly important special
interrupts. If you don't have a particular need for this sort of
speed, then don't even bother with the feature.