With the MPLAB® XC8 compiler, this pragma is used to indicate that the function duplication that would normally take place when a function is called from main-line and interrupt code should not be performed, again due to the fact that the programmer must have taken steps to ensure that reentrancy issues have been dealt with.
The duplication of the function can be inhibited by the use of a special pragma. The #pragma interrupt_level directive can be used to prevent function duplication of functions called from main-line and interrupt code.
Let’s assume that the function main calls a function called input. This function is also called by an interrupt function.
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 function will be i1_input.
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.
Note: Never re-enable interrupts inside the interrupt function itself. Interrupts are automatically re-enabled by hardware on execution of the RETFIE instruction. Re-enabling interrupts inside an interrupt function can result in code failure.
The pragma should be placed before the definition of the function that is not to be duplicated.
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.
In main-line code, this function would typically be called as follows:
The value 1 specified to the pragma "interrupt_level" 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.
Microchip Technology acquires Atmel