 | Technical Support |  |
|
|
Technical Support Support Resources Product Information | C51: USING NON-REENTRANT FUNCTION IN MAIN AND INTERRUPTS
Information in this article applies to:
QUESTIONI use the atof function in an interrupt service routine and in the main program loop. Since atof is not reentrant, I receive the following linker warning:
*** WARNING L15: MULTIPLE CALL TO SEGMENT
SEGMENT: ?PR??C?ATOF??C?ATOF
CALLER1: ?PR?SERIAL_INT?D
CALLER2: ?C_C51STARTUP
Is there a way to use atof from both the interrupt and the main routine? ANSWERYes. It is possible to use non-reentrant functions in both interrupt and main routines. - Make sure that the interrupt cannot occur during the execution of a non-reentrant function. You may disable the interrupt service routine in the main function as follows:
void main (void) {
.
.
.
ES1 = 0; // disable serial interrupt
fval = atof (buffer); // call the non-reentrant function
ES1 = 1; // enable serial interrupt
.
.
.
}
- Data overlaying must be adjusted using the linker OVERLAY directive (which will remove linker warning 15). For the above, you would use the following on the linker command line:
OVERLAY (atof ! *)
In µVision, enter atof ! * in the Overlay field on the Linker Misc Tab of the Project Options dialog. This command removes the atof function from overlay analysis. The memory used by atof for local variables is not overlaid with that of other functions. - A similar method also works for RTX51 Tiny when you want to use non-reentrant functions in several tasks. You can ensure that no task switch occurs by disabling the Timer 0 interrupt that performs round robin task switching. You must apply the OVERLAY directive to avoid the linker warning. For example:
void job0 (void) _task_ 0 {
.
.
.
ET0 = 0; // disable serial interrupt
fval = atof (buffer); // call the non-reentrant function
ET0 = 1; // enable serial interrupt
.
.
.
}
void job1 (void) _task_ 1 {
.
.
.
ET0 = 0; // disable serial interrupt
fval = atof (buffer); // call the non-reentrant function
ET0 = 1; // enable serial interrupt
.
.
.
}
SEE ALSOFORUM THREADSThe following Discussion Forum threads may provide information related to this topic. Last Reviewed: Saturday, July 09, 2005
|
|