Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


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.


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 ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists