Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

C18 Reentrancy

Posted by Nobody/Anonymous on January 11, 2005
Since C18 isn't reentrant, won't the rtos cause problems if the same function is called in two different tasks?

Do I have to take care of this myself?

I'm particularly thinking about things like sprintf and the math library. I don't think the C standard guarantees reentrancy.

RE: C18 Reentrancy

Posted by Nobody/Anonymous on January 11, 2005
I have been investigating C18 re-entrancy, and I'm getting more confused by the minute :-)

From the manual:
"MPLAB C18 supports parameters and local variables allocated either on the software
stack or directly from global memory. The static keyword places a local variable or
a function parameter in global memory instead of on the software stack.1 In general,
stack-based local variables and function parameters require more code to access than
static local variables and function parameters (see Section 2.3.2 “static
Function Arguments”). Functions that use stack-based variables are more flexible in
that they can be reentrant and/or recursive."

Still searching........


RE: C18 Reentrancy

Posted by Richard on January 11, 2005
The areas of global memory used by the compiler are saved as part of the task context so you need not worry about these directly - only to ensure that the correct number of bytes are stored as per the WEB documentation.

There are some library functions that are very rarely reentrant. malloc(), free(), strtok() for example. Also anything that uses errno if that is of concern to you. You always need to take care when using these. If in doubt you can suspend and resume the scheduler around a function call - this will allow interrupts to be processed but guarantee that a context switch does not occur.

sprintf may struggle on a PIC as it normally uses a fair amount of stack.

The section from the manual you quote seems to refer to your own function parameters and the C standard use of the static modifier. The problem with the C18 is it's use of memory when performing simple routines like adding two integers.

I am going to get the latest C18 version and see how things are different.

Regards.

RE: C18 Reentrancy

Posted by Richard on January 11, 2005
Just for completion - from the other thread:

"With the new version, the MATH_DATA and .tmpdata sections are the same size, suggesting they are used in the same way. Having just compiled and run the first and third FreeRTOS.org demo applications they appear to execute correctly with V2.4."


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner