Memory manager for IAR, KEIL and others ...

fojtik wrote on Sunday, 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 <stdlib.h>
#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);
}

rtel wrote on Monday, 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.

fojtik wrote on Monday, 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/