File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change 7272 static int totalBytesProvidedBySBRK = 0 ;
7373#endif
7474extern char _end ; // Defined in the linker script
75- static int heapBytesRemaining = configTOTAL_HEAP_SIZE ; // that's (&__HeapLimit)-(&__HeapBase)
75+ static int heapBytesRemaining = -1 ; // configTOTAL_HEAP_SIZE is not constant will be init later
7676
7777//! sbrk/_sbrk version supporting reentrant newlib (depends upon above symbols defined by linker control file).
7878char * sbrk (int incr ) {
7979 static char * currentHeapEnd = & _end ;
8080 vTaskSuspendAll (); // Note: safe to use before FreeRTOS scheduler started
81+ if (heapBytesRemaining == -1 ) {
82+ heapBytesRemaining = configTOTAL_HEAP_SIZE ;
83+ }
8184 char * previousHeapEnd = currentHeapEnd ;
8285 if (currentHeapEnd + incr > & _end + configTOTAL_HEAP_SIZE ) {
8386 #if ( configUSE_MALLOC_FAILED_HOOK == 1 )
@@ -145,6 +148,9 @@ void vPortFree( void *pv ) PRIVILEGED_FUNCTION {
145148
146149size_t xPortGetFreeHeapSize ( void ) PRIVILEGED_FUNCTION {
147150 struct mallinfo mi = mallinfo ();
151+ if (heapBytesRemaining == -1 ) {
152+ heapBytesRemaining = configTOTAL_HEAP_SIZE ;
153+ }
148154 return mi .fordblks + heapBytesRemaining ;
149155}
150156
You can’t perform that action at this time.
0 commit comments