Keil Logo

C51: Using Non-reentrant Function in Main and Interrupts


Information in this article applies to:

  • C51 Version 6.20 and later

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 µ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.

  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


Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.