-
Notifications
You must be signed in to change notification settings - Fork 94
Integrate the new heap implementation from InfiniTime #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8ae5ba7
Integrate the new heap implementation from InfiniTime (https://github…
JF002 7c2ea61
sim: mark header that need to be as C header
NeroBurner 310dc02
main: access minimumEverFreeHeap only when needed
NeroBurner c2488a2
FreeRTOS: use unordered_map as it has better runtime for access
NeroBurner d67a74d
FreeRTOS: use more specific std::algorithm instead of std::foreach
NeroBurner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,45 @@ | ||
| #include "FreeRTOS.h" | ||
| #include <numeric> | ||
| #include <unordered_map> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| void NVIC_SystemReset(void) {} | ||
|
|
||
| void APP_ERROR_HANDLER(int err) { | ||
| fprintf(stderr, "APP_ERROR_HANDLER: %d", err); | ||
| } | ||
|
|
||
| namespace { | ||
| std::unordered_map<void *, size_t> allocatedMemory; | ||
| size_t currentFreeHeap = configTOTAL_HEAP_SIZE; | ||
| size_t minimumEverFreeHeap = configTOTAL_HEAP_SIZE; | ||
| } | ||
|
|
||
| void *pvPortMalloc( size_t xWantedSize ) { | ||
| void* ptr = malloc(xWantedSize); | ||
| allocatedMemory[ptr] = xWantedSize; | ||
|
|
||
| const size_t currentSize = std::accumulate( | ||
| allocatedMemory.begin(), allocatedMemory.end(), 0, | ||
| [](const size_t lhs, const std::pair<void*, size_t>& item){ | ||
| return lhs + item.second; | ||
| }); | ||
|
|
||
| currentFreeHeap = configTOTAL_HEAP_SIZE - currentSize; | ||
| minimumEverFreeHeap = std::min(currentFreeHeap, minimumEverFreeHeap); | ||
|
|
||
| return ptr; | ||
| } | ||
| void vPortFree( void *pv ) { | ||
| allocatedMemory.erase(pv); | ||
| return free(pv); | ||
| } | ||
|
|
||
| size_t xPortGetFreeHeapSize(void) { | ||
| return currentFreeHeap; | ||
| } | ||
|
|
||
| size_t xPortGetMinimumEverFreeHeapSize(void) { | ||
| return minimumEverFreeHeap; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,9 +30,14 @@ | |||||
| #ifndef INC_TASK_H | ||||||
| #define INC_TASK_H | ||||||
|
|
||||||
| #ifdef __cplusplus | ||||||
| extern "C" { | ||||||
| #endif | ||||||
|
|
||||||
| #include "portmacro_cmsis.h" | ||||||
|
|
||||||
| #include <cstdint> | ||||||
| #include <stdint.h> | ||||||
| #include <stddef.h> | ||||||
| // copied from InfiniTime/src/FreeRTOSConfig.h | ||||||
| #define configTICK_RATE_HZ 1024 | ||||||
| #define configSTACK_DEPTH_TYPE uint16_t | ||||||
|
|
@@ -65,11 +70,11 @@ typedef void (*TaskFunction_t)(void *instance); | |||||
| * \ingroup Tasks | ||||||
| */ | ||||||
| //typedef void * TaskHandle_t; | ||||||
| struct TaskHandle_t { | ||||||
| void *thread_handle = nullptr; | ||||||
| typedef struct TaskHandle_t { | ||||||
| void *thread_handle; | ||||||
| TaskFunction_t task_fn; | ||||||
| void *instance = nullptr; | ||||||
| }; | ||||||
| void *instance; | ||||||
| }TaskHandle_t; | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: space before name
Suggested change
|
||||||
|
|
||||||
| /* Task states returned by eTaskGetState. */ | ||||||
| enum eTaskState | ||||||
|
|
@@ -101,7 +106,7 @@ is used in assert() statements. */ | |||||
|
|
||||||
| /* Used with the uxTaskGetSystemState() function to return the state of each task | ||||||
| in the system. */ | ||||||
| struct TaskStatus_t { | ||||||
| typedef struct TaskStatus_t { | ||||||
| TaskHandle_t xHandle; /* The handle of the task to which the rest of the information in the structure relates. */ | ||||||
| const char *pcTaskName; /* A pointer to the task's name. This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ | ||||||
| UBaseType_t xTaskNumber; /* A number unique to the task. */ | ||||||
|
|
@@ -111,7 +116,7 @@ struct TaskStatus_t { | |||||
| uint32_t ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See http://www.freertos.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */ | ||||||
| //StackType_t *pxStackBase; /* Points to the lowest address of the task's stack area. */ | ||||||
| uint16_t usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */ | ||||||
| }; | ||||||
| }TaskStatus_t; | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: space before name
Suggested change
|
||||||
|
|
||||||
| /** | ||||||
| * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for | ||||||
|
|
@@ -323,4 +328,8 @@ TaskHandle_t xTaskGetCurrentTaskHandle(); | |||||
| */ | ||||||
| BaseType_t xTaskGetSchedulerState(); | ||||||
|
|
||||||
| #ifdef __cplusplus | ||||||
| } | ||||||
| #endif | ||||||
|
|
||||||
| #endif /* INC_TASK_H */ | ||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we still default initialize in
Ccode? I actually don't knowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhm I don't think we can do that in
C, but this file should be compiled by the C++ compiler so it should work, I guess (and it builds).