Avoiding Corrupting Register Values - Texas Instruments TMS320C2x User Manual

Optimizing c compiler digital signal processor
Hide thumbs Also See for TMS320C2x:
Table of Contents

Advertisement

5.6.2 Avoiding Corrupting Register Values

5.6.3 Disabling the Compiler From Using AR6 and AR7
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.
The −rregister shell option and the corresponding −gregister 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
Creating Global Register Variables
TMS320C2x/C2xx/C5x C Language
5-11

Advertisement

Table of Contents
loading

This manual is also suitable for:

Tms320c2xxTms320c5x

Table of Contents