|
1 | 1 | /* -------------------------------------------------------------------------- |
2 | | - * Copyright (c) 2013-2018 Arm Limited. All rights reserved. |
| 2 | + * Copyright (c) 2013-2019 Arm Limited. All rights reserved. |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | * |
@@ -97,22 +97,46 @@ typedef struct { |
97 | 97 | /* Kernel initialization state */ |
98 | 98 | static osKernelState_t KernelState; |
99 | 99 |
|
100 | | -/* Heap region definition used by heap_5 variant */ |
101 | | -#if defined(RTE_RTOS_FreeRTOS_HEAP_5) |
102 | | -#if (configAPPLICATION_ALLOCATED_HEAP == 1) |
103 | 100 | /* |
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. |
106 | 109 | */ |
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 |
108 | 133 | #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 |
110 | 139 | #endif /* configAPPLICATION_ALLOCATED_HEAP */ |
111 | | - |
112 | | -static HeapRegion_t xHeapRegions[] = { |
113 | | - { ucHeap, configTOTAL_HEAP_SIZE }, |
114 | | - { NULL, 0 } |
115 | | -}; |
116 | 140 | #endif /* RTE_RTOS_FreeRTOS_HEAP_5 */ |
117 | 141 |
|
118 | 142 | #if defined(SysTick) |
@@ -146,8 +170,8 @@ osStatus_t osKernelInitialize (void) { |
146 | 170 | else { |
147 | 171 | if (KernelState == osKernelInactive) { |
148 | 172 | 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); |
151 | 175 | #endif |
152 | 176 | KernelState = osKernelReady; |
153 | 177 | stat = osOK; |
|
0 commit comments