Skip to content

Commit 2b794ed

Browse files
committed
Added heap override and customization options when using heap_5 variant.
1 parent d1aea9a commit 2b794ed

1 file changed

Lines changed: 39 additions & 15 deletions

File tree

CMSIS/RTOS2/FreeRTOS/Source/cmsis_os2.c

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* --------------------------------------------------------------------------
2-
* Copyright (c) 2013-2018 Arm Limited. All rights reserved.
2+
* Copyright (c) 2013-2019 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -97,22 +97,46 @@ typedef struct {
9797
/* Kernel initialization state */
9898
static osKernelState_t KernelState;
9999

100-
/* Heap region definition used by heap_5 variant */
101-
#if defined(RTE_RTOS_FreeRTOS_HEAP_5)
102-
#if (configAPPLICATION_ALLOCATED_HEAP == 1)
103100
/*
104-
The application writer has already defined the array used for the RTOS
105-
heap - probably so it can be placed in a special segment or address.
101+
Heap region definition used by heap_5 variant
102+
103+
Define configAPPLICATION_ALLOCATED_HEAP as nonzero value in FreeRTOSConfig.h if
104+
heap regions are already defined and vPortDefineHeapRegions is called in application.
105+
106+
Otherwise vPortDefineHeapRegions will be called by osKernelInitialize using
107+
definition configHEAP_5_REGIONS as parameter. Overriding configHEAP_5_REGIONS
108+
is possible by defining it globally or in FreeRTOSConfig.h.
106109
*/
107-
extern uint8_t ucHeap[configTOTAL_HEAP_SIZE];
110+
#if defined(RTE_RTOS_FreeRTOS_HEAP_5)
111+
#if (configAPPLICATION_ALLOCATED_HEAP == 0)
112+
/*
113+
FreeRTOS heap is not defined by the application.
114+
Single region of size configTOTAL_HEAP_SIZE (defined in FreeRTOSConfig.h)
115+
is provided by default. Define configHEAP_5_REGIONS to provide custom
116+
HeapRegion_t array.
117+
*/
118+
#define HEAP_5_REGION_SETUP 1
119+
120+
#ifndef configHEAP_5_REGIONS
121+
#define configHEAP_5_REGIONS xHeapRegions
122+
123+
static uint8_t ucHeap[configTOTAL_HEAP_SIZE];
124+
125+
static HeapRegion_t xHeapRegions[] = {
126+
{ ucHeap, configTOTAL_HEAP_SIZE },
127+
{ NULL, 0 }
128+
};
129+
#else
130+
/* Global definition is provided to override default heap array */
131+
extern HeapRegion_t configHEAP_5_REGIONS[];
132+
#endif
108133
#else
109-
static uint8_t ucHeap[configTOTAL_HEAP_SIZE];
134+
/*
135+
The application already defined the array used for the FreeRTOS heap and
136+
called vPortDefineHeapRegions to initialize heap.
137+
*/
138+
#define HEAP_5_REGION_SETUP 0
110139
#endif /* configAPPLICATION_ALLOCATED_HEAP */
111-
112-
static HeapRegion_t xHeapRegions[] = {
113-
{ ucHeap, configTOTAL_HEAP_SIZE },
114-
{ NULL, 0 }
115-
};
116140
#endif /* RTE_RTOS_FreeRTOS_HEAP_5 */
117141

118142
#if defined(SysTick)
@@ -146,8 +170,8 @@ osStatus_t osKernelInitialize (void) {
146170
else {
147171
if (KernelState == osKernelInactive) {
148172
EvrFreeRTOSSetup();
149-
#if defined(RTE_RTOS_FreeRTOS_HEAP_5)
150-
vPortDefineHeapRegions (xHeapRegions);
173+
#if defined(RTE_RTOS_FreeRTOS_HEAP_5) && (HEAP_5_REGION_SETUP == 1)
174+
vPortDefineHeapRegions (configHEAP_5_REGIONS);
151175
#endif
152176
KernelState = osKernelReady;
153177
stat = osOK;

0 commit comments

Comments
 (0)