FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [January 2014 Threads]
IAR Embedded Workbench for MSP430 (and, I would guess, other IAR products) has an option "Enable thread support in library". If this is ticked, the library puts locks around calls to malloc() and free() to give thread safety. The developer is responsible for implementing four functions to implement the locking (see http://supp.iar.com/FilesPublic/UPDINFO/005691/arm/doc/infocenter/DLIBThreadSupport.html). When using this with FreeRTOS, it seems to be sufficient that locking calls vTaskSuspendAll() and unlocking calls xTaskResumeAll() (similar to what heap_3.c does).
However, that means that FreeRTOS's pvPortMalloc() and vPortFree() in heap3.c do the lock and unlock twice - once in heap3.c and once in the IAR library. I'm not sure what the overhead of this is, or if there are any adverse effects (I doubt that there are). But it's fairly trivial to avoid.
I've modified FreeRTOS.h to add a new config option configLOCKMALLOCFREE which causes the duplicate calls to be omitted. I then set that in FreeRTOSConfig.h to 1. Then I wrapped the calls in heap_3.c in #if's so that they get omitted.
The attached files are diffs against FreeRTOS 7.6.0 to implement this, together with a sample file locking.c that can be added to the project to implement the locking.
Graham
The vTaskSuspend/Resume functions are designed to nest, and have very little overhead when called with a nest bigger than 0.
What advantage does using the IAR locks have over just using heap_3?
If the developer calls directly to malloc()/free() as opposed to pvPortMalloc()/vPortFree(), they'll bypass the locks in heap_3.c. So they're needed for anything that doesn't know about FreeRTOS e.g. any third party libraries, or any calls from inside the IAR libraries. They're used for C++ new/delete too.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.