Microchip Technology SW006021-2 Manual De Usuario
C Language Features
2012 Microchip Technology Inc.
DS52053B-page 193
Examination of the assembly list file will show assembly code for both the original and
duplicate function outputs. The output corresponding to the C function input() will
use the assembly label _input. The corresponding label used by the duplicate func-
tion will be i1_input. If the original function makes reference to a temporary variable,
the generated output will use the symbol ??_input, compared to ??i1_input for the
duplicate output. Even local labels within the function output will be duplicated in the
same way. The call graph, in the assembly list file, will show the calls made to both of
these functions as if they were independently written. These symbols will also be seen
in the map file symbol table.
duplicate function outputs. The output corresponding to the C function input() will
use the assembly label _input. The corresponding label used by the duplicate func-
tion will be i1_input. If the original function makes reference to a temporary variable,
the generated output will use the symbol ??_input, compared to ??i1_input for the
duplicate output. Even local labels within the function output will be duplicated in the
same way. The call graph, in the assembly list file, will show the calls made to both of
these functions as if they were independently written. These symbols will also be seen
in the map file symbol table.
This feature allows the programmer to use the same source code with compilers that
use either reentrant or non-reentrant models. It does not handle cases where functions
are called recursively.
use either reentrant or non-reentrant models. It does not handle cases where functions
are called recursively.
Code associated with library functions are duplicated in the same way. This also
applies to implicitly called library routines, such as those that perform division or
floating-point operations associated with C operators.
applies to implicitly called library routines, such as those that perform division or
floating-point operations associated with C operators.
5.9.5.1
DISABLING DUPLICATION
The automatic duplication of the function may be inhibited by the use of a special
pragma.
pragma.
This should only be done if the source code guarantees that an interrupt cannot occur
while the function is being called from any main-line code. Typically this would be
achieved by disabling interrupts before calling the function. It is not sufficient to disable
the interrupts inside the function after it has been called; if an interrupt occurs when
executing the function, the code may fail. See Section 5.9.4 “Enabling Interrupts” for
more information on how interrupts may be disabled.
while the function is being called from any main-line code. Typically this would be
achieved by disabling interrupts before calling the function. It is not sufficient to disable
the interrupts inside the function after it has been called; if an interrupt occurs when
executing the function, the code may fail. See Section 5.9.4 “Enabling Interrupts” for
more information on how interrupts may be disabled.
The pragma is:
#pragma interrupt_level 1
The pragma should be placed before the definition of the function that is not to be dupli-
cated. The pragma will only affect the first function whose definition follows.
cated. The pragma will only affect the first function whose definition follows.
For example, if the function read is only ever called from main-line code when the
interrupts are disabled, then duplication of the function can be prevented if it is also
called from an interrupt function as follows.
interrupts are disabled, then duplication of the function can be prevented if it is also
called from an interrupt function as follows.
#pragma interrupt_level 1
int read(char device)
{
// ...
}
In main-line code, this function would typically be called as follows:
di(); // turn off interrupts
read(IN_CH1);
ei(); // re-enable interrupts
The level value specified indicates for which interrupt the function will not be duplicated.
For mid-range devices, the level should always be 1; for PIC18 devices it can be 1 or
2 for the low- or high-priority interrupt functions, respectively. To disable duplication for
both interrupt priorities, use the pragma twice to specify both levels 1 and 2. The fol-
lowing function will not be duplicated if it is also called from the low- and high-priority
interrupt functions.
For mid-range devices, the level should always be 1; for PIC18 devices it can be 1 or
2 for the low- or high-priority interrupt functions, respectively. To disable duplication for
both interrupt priorities, use the pragma twice to specify both levels 1 and 2. The fol-
lowing function will not be duplicated if it is also called from the low- and high-priority
interrupt functions.
#pragma interrupt_level 1
#pragma interrupt_level 2
int timestwo(int a) {
return a * 2;
}