Skip to content

Commit 8c9b032

Browse files
committed
Wrap the heap based parts of portable.h in if dynamic allocation is supported. Update the CMakeLists.txt to account for this
1 parent f22169d commit 8c9b032

File tree

2 files changed

+70
-72
lines changed

2 files changed

+70
-72
lines changed

CMakeLists.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,12 @@ target_sources(freertos_kernel PRIVATE
284284
stream_buffer.c
285285
tasks.c
286286
timers.c
287-
)
288287

289-
# Check if user requested to not include a heap implementation
290-
if(NOT DEFINED FREERTOS_DO_NOT_INCLUDE_HEAP)
291-
list(APPEND FREERTOS_KERNEL_SOURCES
288+
# Check if user requested to not include a heap implementation
289+
if(NOT DEFINED FREERTOS_DO_NOT_INCLUDE_HEAP)
292290
# If FREERTOS_HEAP is digit between 1 .. 5 - it is heap number, otherwise - it is path to custom heap source file
293291
$<IF:$<BOOL:$<FILTER:${FREERTOS_HEAP},EXCLUDE,^[1-5]$>>,${FREERTOS_HEAP},portable/MemMang/heap_${FREERTOS_HEAP}.c>
294-
)
295-
endif()
296-
297-
add_library(freertos_kernel STATIC
298-
${FREERTOS_KERNEL_SOURCES}
292+
endif()
299293
)
300294

301295

include/portable.h

Lines changed: 67 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -132,76 +132,80 @@
132132
#endif
133133
#endif /* if ( portUSING_MPU_WRAPPERS == 1 ) */
134134

135-
/* Used by heap_5.c to define the start address and size of each memory region
136-
* that together comprise the total FreeRTOS heap space. */
137-
typedef struct HeapRegion
138-
{
139-
uint8_t * pucStartAddress;
140-
size_t xSizeInBytes;
141-
} HeapRegion_t;
135+
/* Only include heap related functions and structs if using dynamic allocation */
136+
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
142137

143-
/* Used to pass information about the heap out of vPortGetHeapStats(). */
144-
typedef struct xHeapStats
145-
{
146-
size_t xAvailableHeapSpaceInBytes; /* The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated. */
147-
size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
148-
size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
149-
size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */
150-
size_t xMinimumEverFreeBytesRemaining; /* The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted. */
151-
size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */
152-
size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */
153-
} HeapStats_t;
138+
/* Used by heap_5.c to define the start address and size of each memory region
139+
* that together comprise the total FreeRTOS heap space. */
140+
typedef struct HeapRegion
141+
{
142+
uint8_t * pucStartAddress;
143+
size_t xSizeInBytes;
144+
} HeapRegion_t;
154145

155-
/*
156-
* Used to define multiple heap regions for use by heap_5.c. This function
157-
* must be called before any calls to pvPortMalloc() - not creating a task,
158-
* queue, semaphore, mutex, software timer, event group, etc. will result in
159-
* pvPortMalloc being called.
160-
*
161-
* pxHeapRegions passes in an array of HeapRegion_t structures - each of which
162-
* defines a region of memory that can be used as the heap. The array is
163-
* terminated by a HeapRegions_t structure that has a size of 0. The region
164-
* with the lowest start address must appear first in the array.
165-
*/
166-
void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION;
146+
/* Used to pass information about the heap out of vPortGetHeapStats(). */
147+
typedef struct xHeapStats
148+
{
149+
size_t xAvailableHeapSpaceInBytes; /* The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated. */
150+
size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
151+
size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
152+
size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */
153+
size_t xMinimumEverFreeBytesRemaining; /* The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted. */
154+
size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */
155+
size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */
156+
} HeapStats_t;
167157

168-
/*
169-
* Returns a HeapStats_t structure filled with information about the current
170-
* heap state.
171-
*/
172-
void vPortGetHeapStats( HeapStats_t * pxHeapStats );
158+
/*
159+
* Used to define multiple heap regions for use by heap_5.c. This function
160+
* must be called before any calls to pvPortMalloc() - not creating a task,
161+
* queue, semaphore, mutex, software timer, event group, etc. will result in
162+
* pvPortMalloc being called.
163+
*
164+
* pxHeapRegions passes in an array of HeapRegion_t structures - each of which
165+
* defines a region of memory that can be used as the heap. The array is
166+
* terminated by a HeapRegions_t structure that has a size of 0. The region
167+
* with the lowest start address must appear first in the array.
168+
*/
169+
void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION;
173170

174-
/*
175-
* Map to the memory management routines required for the port.
176-
*/
177-
void * pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION;
178-
void * pvPortCalloc( size_t xNum,
179-
size_t xSize ) PRIVILEGED_FUNCTION;
180-
void vPortFree( void * pv ) PRIVILEGED_FUNCTION;
181-
void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION;
182-
size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION;
183-
size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION;
171+
/*
172+
* Returns a HeapStats_t structure filled with information about the current
173+
* heap state.
174+
*/
175+
void vPortGetHeapStats( HeapStats_t * pxHeapStats );
184176

185-
#if ( configSTACK_ALLOCATION_FROM_SEPARATE_HEAP == 1 )
186-
void * pvPortMallocStack( size_t xSize ) PRIVILEGED_FUNCTION;
187-
void vPortFreeStack( void * pv ) PRIVILEGED_FUNCTION;
188-
#else
189-
#define pvPortMallocStack pvPortMalloc
190-
#define vPortFreeStack vPortFree
191-
#endif
177+
/*
178+
* Map to the memory management routines required for the port.
179+
*/
180+
void * pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION;
181+
void * pvPortCalloc( size_t xNum,
182+
size_t xSize ) PRIVILEGED_FUNCTION;
183+
void vPortFree( void * pv ) PRIVILEGED_FUNCTION;
184+
void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION;
185+
size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION;
186+
size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION;
192187

193-
#if ( configUSE_MALLOC_FAILED_HOOK == 1 )
188+
#if ( configSTACK_ALLOCATION_FROM_SEPARATE_HEAP == 1 )
189+
void * pvPortMallocStack( size_t xSize ) PRIVILEGED_FUNCTION;
190+
void vPortFreeStack( void * pv ) PRIVILEGED_FUNCTION;
191+
#else
192+
#define pvPortMallocStack pvPortMalloc
193+
#define vPortFreeStack vPortFree
194+
#endif
194195

195-
/**
196-
* task.h
197-
* @code{c}
198-
* void vApplicationMallocFailedHook( void )
199-
* @endcode
200-
*
201-
* This hook function is called when allocation failed.
202-
*/
203-
void vApplicationMallocFailedHook( void ); /*lint !e526 Symbol not defined as it is an application callback. */
204-
#endif
196+
#if ( configUSE_MALLOC_FAILED_HOOK == 1 )
197+
/**
198+
* task.h
199+
* @code{c}
200+
* void vApplicationMallocFailedHook( void )
201+
* @endcode
202+
*
203+
* This hook function is called when allocation failed.
204+
*/
205+
void vApplicationMallocFailedHook( void ); /*lint !e526 Symbol not defined as it is an application callback. */
206+
#endif /* ( configUSE_MALLOC_FAILED_HOOK == 1 ) */
207+
208+
#endif /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */
205209

206210
/*
207211
* Setup the hardware ready for the scheduler to take control. This generally

0 commit comments

Comments
 (0)