Quality RTOS & Embedded Software

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




Loading

Memory manager for IAR, KEIL and others ...

Posted by Jaroslav Fojtik on February 10, 2013
This memory manager can reuse standard C-lib functions. Sometimes the malloc, realloc and free could be optimized more precise in C lib than those proposed in RTOS..

FreeRTOS\Source\portable\MemMang\HeapClib.c:
#include 

#include "FreeRTOS.h"
#include "task.h"


void vPortFree( void *pv )
{
if(pv)
{
vTaskSuspendAll();
free(pv);
xTaskResumeAll();
}
}

void *pvPortMalloc(size_t xWantedSize)
{
void *Mem;
vTaskSuspendAll();
Mem = malloc(xWantedSize);
xTaskResumeAll();
return (Mem);
}

RE: Memory manager for IAR, KEIL and others ...

Posted by Richard on February 11, 2013
What is the difference between this and heap_3.c?

Heap_4.c is currently the preferred scheme if RAM is going to be freed as well as allocated.

Regards.

RE: Memory manager for IAR, KEIL and others ...

Posted by Jaroslav Fojtik on February 11, 2013
Sorry, I overlook that. Anyway, this memory scheme performs a little better in Keil. You can use safelly malloc and free inside your code and everything is synchronized. Keil can use in its C-lib externally provided mutex.

void vPortFree( void *pv )
{
free(pv);
}

void *pvPortMalloc(size_t xWantedSize)
{
return malloc(xWantedSize);
}


/*--------------------------- _mutex_initialize -----------------------------*/
int _mutex_initialize (_SYNC_t *mutex)
{
/* Allocate and initialize a system mutex. */
vSemaphoreCreateBinary(*mutex);/*Create semaphore*/
return (1);
}


/*--------------------------- _mutex_acquire --------------------------------*/

__attribute__((used)) void _mutex_acquire(_SYNC_t *mutex)
{
/* Acquire a system mutex, lock stdlib resources. */
if(RTOS_STATE == RTOS_RUNNING)
{ /* RTX running, acquire a mutex. */
xSemaphoreTake(*mutex, 500);
}
}


/*--------------------------- _mutex_release --------------------------------*/

__attribute__((used)) void _mutex_release (_SYNC_t *mutex)
{
/* Release a system mutex, unlock stdlib resources. */
if(RTOS_STATE == RTOS_RUNNING)
{ /* RTX runnning, release a mutex. */
xSemaphoreGive(*mutex);
}
}

//http://www.keil.com/forum/16315/


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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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