Skip to end of banner
Go to start of banner

FreeRTOS Porting Description

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Port

The current version of FreeRTOS can be downloaded from www.freertos.org. For porting, we need the folder <FreeRTOS/Source> and one of the portables ARM_CM3, ARM_CM3_MPU, ARM_CM4FP, ARM_CM4_MPU. The following table shows the supported features of each portable.

PortableFPUMPU
ARM_CM3(error)

(error)

ARM_CM3_MPU(error)(tick)
ARM_CM4FP(tick)(error)
ARM_CM4_MPU(tick)(tick)

Simply copy the required port.c/ portmacro.h file into the folders Source/ Include.

FreeRTOS Config

The FreeRTOSConfig file customizes your FreeRTOS port and must be defined according to your needs. FreeRTOS already provides a lot of information here.

Heap

FreeRTOS provides the mentioned five heap implementations. Since none of those support newlib c, we also included Dave Nadlers newlib heap implementation.

PendSV and SVC Hanlder

To perform a task switch, FreeRTOS utilizes the CMSIS Pendable Service (PendSV) and the supervisor call (SVC) handlers.

They must not be implemented somewhere else!

FreeRTOSCommonHooks

The following Hook Functions are required:

FreeRTOSCommonHooks.h
/**
 * @brief Delay for the specified number of milliSeconds
 * @param ms: Delay in milliSeconds
 * @return Nothing
 * @note Delays the specified number of milliSeoconds using a task delay
 */
void FreeRTOSDelay(uint32_t ms);

/**
 * @brief FreeRTOS malloc fail hook
 * @return Nothing
 * @note This function is alled when a malloc fails to allocate data.
 */
void vApplicationMallocFailedHook(void);

/**
 * @brief FreeRTOS remalloc fail hook
 * @return  Nothing
 * @note This function is alled when a malloc fails to allocate data.
 */
void vApplicationReallocFailedHook(void);

/**
 * @brief FreeRTOS application idle hook
 * @return Nothing
 * @note Calls ARM Wait for Interrupt function to idle core
 */
void vApplicationIdleHook(void);
FreeRTOSCommonHooks.c
/* Delay for the specified number of milliSeconds */
void FreeRTOSDelay(uint32_t ms)
{
  portTickType xDelayTime;

  xDelayTime = xTaskGetTickCount();
  vTaskDelayUntil(&xDelayTime, ms);
}
/*-----------------------------------------------------------*/

/* FreeRTOS malloc fail hook */
void vApplicationMallocFailedHook(void)
{
  /* vApplicationMallocFailedHook() will only be called if
    configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
    function that will get called if a call to pvPortMalloc() fails.
    pvPortMalloc() is called internally by the kernel whenever a task, queue,
    timer or semaphore is created.  It is also called by various parts of the
    demo application.  If heap_1.c or heap_2.c are used, then the size of the
    heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
    FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
    to query the size of free heap space that remains (although it does not
    provide information on how the remaining heap might be fragmented). */

  taskDISABLE_INTERRUPTS();
  for (;; ) {}
}
/*-----------------------------------------------------------*/

/* FreeRTOS malloc fail hook */
void vApplicationReallocFailedHook(void)
{
  /* vApplicationMallocFailedHook() will only be called if
    configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
    function that will get called if a call to pvPortMalloc() fails.
    pvPortMalloc() is called internally by the kernel whenever a task, queue,
    timer or semaphore is created.  It is also called by various parts of the
    demo application.  If heap_1.c or heap_2.c are used, then the size of the
    heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
    FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
    to query the size of free heap space that remains (although it does not
    provide information on how the remaining heap might be fragmented). */

  taskDISABLE_INTERRUPTS();
  for (;; ) {}
}
/*-----------------------------------------------------------*/

/* FreeRTOS application idle hook */
void vApplicationIdleHook(void)
{
  /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
  to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle
  task.  It is essential that code added to this hook function never attempts
  to block in any way (for example, call xQueueReceive() with a block time
  specified, or call vTaskDelay()).  If the application makes use of the
  vTaskDelete() API function (as this demo application does) then it is also
  important that vApplicationIdleHook() is permitted to return to its calling
  function, because it is the responsibility of the idle task to clean up
  memory allocated by the kernel to any task that has since been deleted. */

  /* Best to sleep here until next systick */
  __WFI();
}

/* FreeRTOS stack overflow hook */
void vApplicationStackOverflowHook(xTaskHandle pxTask, char * pcTaskName)
{
  (void) pxTask;
  (void) pcTaskName;

  //DEBUGOUT("DIE:ERROR:FreeRTOS: Stack overflow in task %s\r\n", pcTaskName);

  /* Run time stack overflow checking is performed if
     configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
     function is called if a stack overflow is detected. */
  taskDISABLE_INTERRUPTS();
  for (;; ) {}
}

/* FreeRTOS application tick hook */
void vApplicationTickHook(void)
{
  /* This function will be called by each tick interrupt if
  configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be
  added here, but the tick hook is called from an interrupt context, so
  code must not attempt to block, and only the interrupt safe FreeRTOS API
  functions can be used (those that end in FromISR()). */
#ifdef DRV_TIM_MODULE_ENABLED
  DRVSysTick_Handler();
#endif

Note that the vApplicationTickHook() calls the netX Driver Systick Handler in case the timer module is enabled!

This is required since the timer implementation of the netX driver might need the systick!

  • No labels