![Texas Instruments TMS320C2x User Manual Download Page 116](http://html1.mh-extra.com/html/texas-instruments/tms320c2x/tms320c2x_user-manual_1097073116.webp)
Creating Global Register Variables
5-11
TMS320C2x/C2xx/C5x C Language
5.6.2 Avoiding Corrupting Register Values
Because the two registers you are allowed to use for global register variables
are normally save-on-entry registers, a normal function call and return does
not affect the value in the register and neither does a normal interrupt. How-
ever, when you mix code that has a globally declared register variable with
code that does not have the register reserved, it is possible for the value in the
register to become corrupted. To avoid corrupting the register values, you
must follow these rules:
-
You cannot access a global register variable in an interrupt service routine
unless you recompile all code, including all libraries, to reserve the
register.
-
Functions that alter global register variables cannot be called by functions
that are not aware of the global register. You must be careful if you pass
a pointer to a function as an argument. If the passed function alters the
global register variable and the called function saves the register, the
value in the register is corrupted.
-
You must save the global register on entry into a module that uses it, and
you must restore the register at exit.
-
The longjmp() function restores global register variables to the values
they had at the setjmp() location. If this presents a problem in your code,
you must unarchive the source for longjmp from rts.src and modify it.
5.6.3 Disabling the Compiler From Using AR6 and AR7
The
−
r
register
shell option and the corresponding
−
g
register
option for the
optimizer and code generator (if you are invoking the tools individually) pre-
vent the compiler from using the named
register
. This lets you reserve the
named register in modules (such as the run-time-support libraries) that do not
have the global register variable declaration if you need to compile the
modules to prevent some of the above occurrences.
You can disable the compiler’s use of AR6 and AR7 completely so that you
can use AR6 and/or AR7 in your interrupt functions without preserving them.
If you disable the compiler from using AR6 and AR7, you must compile all code
with the
−
r option(s) and rebuild the run-time-support library. For example, the
following command rebuilds the rts25.lib library to not use AR6 and AR7:
dspmk −rAR6 −rAR7 −o −v25 rts.src −l rts25.lib
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...