| |||||||||||
On-Line Manuals C166 User's Guide | Register BankThe C16x/ST10/XC16x microcontroller families support multiple register banks that must be located in on-chip RAM. The C166 Compiler allows you to define up to 128 register banks of 16 registers (R0-R15). The base address of the currently active register bank is specified in the context pointer (CP) SFR. If a function is declared with the using attribute, a new register bank is selected on entry to the function and the previous register bank is restored when the function exits. The compiler generates the code necessary to change and restore the register bank. There are several advantages to using more than one register bank. Using multiple register banks enhances the performance of interrupt procedures and real-time programs. If the active register bank is exchanged when an interrupt or context switch occurs, only the Context Pointer must be saved. Otherwise, the whole register bank must be saved before the interrupt procedure or task can execute. The using function attribute is used to specify which register bank a function uses. For example: « type » funcname (« args ») using bankname Where
You may use the same register bank in more than one function. It is common practice to use the same register bank name for interrupt procedures defined with the same interrupt priority level. It is possible to use the same name because interrupt functions with the same priority level cannot interrupt each other. Therefore, the register bank is not in use when the interrupt occurs. For example:
void rb_func (void) using my_rbank {
.
.
.
}
In the above example, using my_rbank specifies that my_rbank is the name of the active register bank during the execution of the function rb_func. There are no restrictions or required naming conventions for the register bank name. Memory for the register bank is automatically allocated and located by the linker. The using attribute affects the generated object code as follows:
The following listing shows the code generated for the using attribute:
stmt level source
1
2 extern bit alarm;
3 int alarm_count;
4 extern void alfunc (bit b0);
5
6 void falarm (void) using f_registers {
7 1 alarm_count++;
8 1 alfunc (alarm = 1);
9 1 }
ASSEMBLY LISTING OF GENERATED OBJECT CODE
; FUNCTION falarm (BEGIN RMASK = @0x3FFF)
0000 F6F00000 R MOV f_registers,R0
0004 C6090000 R SCXT CP,#f_registers
0008 CC00 NOP
; SOURCE LINE # 6
; SOURCE LINE # 7
000A 248F0000 R SUB alarm_count,ONES
; SOURCE LINE # 8
000E 0F00 E BSET alarm
0010 CA000000 E CALLA cc_UC,alfunc
; SOURCE LINE # 9
0014 FC09 POP CP
0016 CB00 RET
; FUNCTION falarm (END RMASK = @0x3FFF)
Note
| ||||||||||
| |||||||||||