ARM Technical Support Knowledge Articles

USING NON-REENTRANT FUNCTION IN MAIN AND INTERRUPTS

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

I 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?

ANSWER

Yes. It is possible to use non-reentrant functions in both interrupt and main routines.

  1. 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
    .
    .
    .
    }
    
  2. 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 uVision, 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.

  3. 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 ALSO

Article last edited on: 2005-07-09 10:49:59

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential