Post Go back to editing

Using sprintf, strstr and memset functions in the UART ISR Callback

Hi Team,

In the UART TX & RX Completion, we have a requirement to use sprintf, memset and strstr functions in the callback function.

Are they safe to use in the ISR Context. 

Thank You & Regards,

Sudheer

Parents
  • Hi,

    Only a limited number of the runtime library functions are available to call from within ISRs. Not all C run-time library functions are interrupt-safe (and can therefore be called from an interrupt service routine). For a run-time function to be classified as interrupt-safe:
         • It must not update any global data, such as errno
         • It must not write to (or maintain) any private static data
     
    It is recommended that none of the functions defined in the math.h header file, nor the string conversion functions defined in the stdlib.h header file, be called from an ISR as these functions are commonly defined to update the global variable errno. Similarly, the functions defined in the stdio.h header file maintain static tables for currently opened streams and should not be called from an ISR. The memory allocation routines (such as malloc, calloc, realloc, and free), the C++ operators new and delete, and any variants, read and update global tables and are not interrupt-safe; they should not be called from an ISR.
     
    The following library functions are not interrupt-safe because they use private static data.
    asctime      gmtime      localtime
    rand         srand       strtok
     
    Please refer the chapter "Calling a Library Function From an ISR" from the below C/C++ Compiler and Library Manual for Blackfin Processors in the below link:
    http://www.analog.com/media/en/dsp-documentation/software-manuals/cces-BlackfinCompiler-library-manual.pdf

    Regards,

    Kader

Reply
  • Hi,

    Only a limited number of the runtime library functions are available to call from within ISRs. Not all C run-time library functions are interrupt-safe (and can therefore be called from an interrupt service routine). For a run-time function to be classified as interrupt-safe:
         • It must not update any global data, such as errno
         • It must not write to (or maintain) any private static data
     
    It is recommended that none of the functions defined in the math.h header file, nor the string conversion functions defined in the stdlib.h header file, be called from an ISR as these functions are commonly defined to update the global variable errno. Similarly, the functions defined in the stdio.h header file maintain static tables for currently opened streams and should not be called from an ISR. The memory allocation routines (such as malloc, calloc, realloc, and free), the C++ operators new and delete, and any variants, read and update global tables and are not interrupt-safe; they should not be called from an ISR.
     
    The following library functions are not interrupt-safe because they use private static data.
    asctime      gmtime      localtime
    rand         srand       strtok
     
    Please refer the chapter "Calling a Library Function From an ISR" from the below C/C++ Compiler and Library Manual for Blackfin Processors in the below link:
    http://www.analog.com/media/en/dsp-documentation/software-manuals/cces-BlackfinCompiler-library-manual.pdf

    Regards,

    Kader

Children
No Data