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

Questions on size_t data type usage and data alignment in heap_2.c in MemMang folder

Posted by diptopal on August 14, 2015

I was going through heap2.c in the MemMang folder in FreeRTOS V7.4.2 source to understand it. I have compared heap2.c with the latest vesrion too, this file remains more of less the same, so I did not move over to the newest version of FreeRTOS to get a newer version of heap_2.c. After going through the code, I have a few doubts.

  1. Why is configTOTALHEAPSIZE defined with a** sizet** type e.g. "**#define configTOTALHEAPSIZE ( ( sizet ) ( 19 * 1024 ) )**" and sizet is used in a few other places as well in heap2.c? What is the benefit of it ?

  2. Why does size of** xBlockLink, **blocks and** xWantedSize** need to be aligned or adjusted to the nearest word (4 bytes in case of Cortex M4), is it because some controllers are not capable of unaligned access ?

  3. To save stack depth prvInsertBlockIntoFreeList macro is defined in heap_2.c, whereas** prvHeapInit** is an independent function in the same file even though prvHeapInit is a static function as well. What are the considerations for using macros or functions here?


Questions on size_t data type usage and data alignment in heap_2.c in MemMang folder

Posted by rtel on August 14, 2015

In recent versios of FreeRTOS, heap4.c is normally used in favour of heap2.c.

1) size_t is used for its portability - FreeRTOS runs on 8-bit up to 64-bit hardware.

2) Alignment is a requirement of many processors, especially the alignment of the stack. Each port has the required alignment defined - breaching the alignment can result in mis-calculations, or complete crashes.

3) prvHeapInit is only called once, whereas prvInsertBlockIntoFreeList is called on each allocation, hence the latter is written as a macro to make it faster and use less stack. More important on small processors than large processors.

Regards.


Questions on size_t data type usage and data alignment in heap_2.c in MemMang folder

Posted by diptopal on August 15, 2015

Thank you very much. I am planning to make a Youtube video on memory allocation for deeply embedded systems. I want to explain it using the heap_x.c files from FreeRTOS. I will maintain the copyrights as is. I will be using the evaluation version of the IAR compiler for this.

Please let me know if there is anything specific that I need to abide by if I use your code for the training.


[ 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