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




Loading

porting newlib to FreeRTOS

Posted by Markus B. on June 21, 2007
I want to port the newlib malloc function to FreeRTOS. To ensure that the malloc functions are thread-safe, following function should be provided:

__malloc_lock
__malloc_unlock

following hint is inside the newlib documentation:
A call to <<malloc>> may call <<__malloc_lock>> recursively; that is,
the sequence of calls may go <<__malloc_lock>>, <<__malloc_lock>>,
<<__malloc_unlock>>, <<__malloc_unlock>>. Any implementation of these
routines must be careful to avoid causing a thread to wait for a lock
that it already holds.

To avoid locking out themself, i need an information which task is currently executed. Is there an easy way to implement a function like GetCurrentTCB()?


If different threads works in the library at the same time, it can creates reentrancy problems. Newlib avoid this with the _impure_ptr to a _reent struct. Every task should have his own _reent structure and the _impure_ptr is moving between these structures during context switches.
How can i implement this? Is it possible to implement a callback function inside the scheduler?

regards
markus


RE: porting newlib to FreeRTOS

Posted by Richard on June 21, 2007
To answer the first part of your question - look at the function xTaskGetCurrentTaskHandle() in task.c.

For the second part of your question - I'm not sure your intention. Is it to add another item into the task control block and save and restore this item automatically in the context switch? Or is it to have the 'callback' called each time there is a context switch?

Regards.

RE: porting newlib to FreeRTOS

Posted by Markus B. on June 21, 2007
Hi Richard,
thanks for your answer.
Yes, that´s what i want. But the function xTaskGetCurrentTaskHandle() is not listed in the online documentation. Most of the sample FreeRTOSConfig.h have no define INCLUDE_xTaskGetCurrentTaskHandle. I have added this.

For the second part of my question:
My idea is to have a way to manipulate some global vars while the scheduler is inside the "critical section" and a context switch occurs. It can be implemented like vApplicationTickHook() or vApplicationIdleHook().
As a consequence the developer has a way to do some stuff while a context switch occur.

For details see http://www.embedded.com/shared/printableArticle.jhtml?articleID=15201696
subsection reentrancy

regards
markus


RE: porting newlib to FreeRTOS

Posted by Glen B. on June 21, 2007
For ARM port...

I have a C++ class that supplies a recursive locking mechanism based on FreeRTOS queues (semaphore-like usage where 1 item of size 0 is used). It is not as straight-forward as you might think. The code is not directly usable in C, but could easily be modified. It is the algorithm that is important.

I have modified the portRESTORE_CONTEXT() and portSAVE_CONTEXT() macros of portmacro.h to stack/unstack _impure_ptr.

Later this evening I can get the code out. I can send both directly to you if you email me at 'glen @ EmbeddedClarity.com' (elide spaces around @).


[ 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