Skip to content

Commit

Permalink
[freertos] Allow use static allocations
Browse files Browse the repository at this point in the history
Signed-off-by: andryblack <[email protected]>
  • Loading branch information
andryblack committed Oct 18, 2021
1 parent af0d1c8 commit 3e4d461
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ext/aws/FreeRTOSConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ your application. */
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ ( {{ frequency }} )
/* Memory allocation related definitions. */
%% if with_heap
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
%% else
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 0
%% endif
// used by modm:platform:clock for modm::Clock::increment(): vApplicationTickHook()
#define configUSE_TICK_HOOK 1

Expand Down
3 changes: 2 additions & 1 deletion ext/aws/freertos.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ these settings:
- `configASSERT(x)` implemented with `modm_assert(x, "freertos")`.
- `configCPU_CLOCK_HZ` implemented with CMSIS `SystemCoreClock`.
- `configTICK_RATE_HZ` set to `modm:freertos:frequency` or 1kHz on Cortex-M0.
- `configSUPPORT_DYNAMIC_ALLOCATION = 1` as implemented by `modm:platform:heap`.
- `configSUPPORT_DYNAMIC_ALLOCATION = 1` if used with `modm:platform:heap`.
- `configSUPPORT_STATIC_ALLOCATION = 1` if used without `modm:platform:heap`.
- `configUSE_TICK_HOOK = 1` used by `modm:platform:clock` to provide `modm::Clock`.

In addition we define these overwritable default settings:
Expand Down
25 changes: 25 additions & 0 deletions ext/aws/modm_port.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void vApplicationStackOverflowHook(TaskHandle_t /*pxTask*/, char *pcTaskName)
modm_assert(false, "freertos.stack", "FreeRTOS detected a stack overflow!", pcTaskName);
}

%% if with_heap
// ----------------------------------------------------------------------------
// Make the Newlib heap thread-safe with FreeRTOS

Expand Down Expand Up @@ -64,6 +65,30 @@ void vPortFree(void *pv)
traceFREE(pv, 0);
}
}
%% else
#if ( configUSE_TIMERS == 1 )
static StaticTask_t timers_task_storage;
static StackType_t timers_task_stack_storage[configTIMER_TASK_STACK_DEPTH];
extern "C"
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t ** ppxTimerTaskStackBuffer,
uint32_t * pulTimerTaskStackSize ) {
*ppxTimerTaskTCBBuffer = &timers_task_storage;
*ppxTimerTaskStackBuffer = timers_task_stack_storage;
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}
#endif
static StaticTask_t idle_task_storage;
static StackType_t idle_task_stack_storage[configMINIMAL_STACK_SIZE];
extern "C"
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
uint32_t * pulIdleTaskStackSize ) {
*ppxIdleTaskTCBBuffer = &idle_task_storage;
*ppxIdleTaskStackBuffer = idle_task_stack_storage;
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
}
%% endif

%% if with_debug
#include <modm/debug.hpp>
Expand Down
6 changes: 3 additions & 3 deletions ext/aws/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def prepare(module, options):
module.depends(
":architecture:assert",
":cmsis:device",
":platform:clock",
":platform:heap")
":platform:clock")

module.add_submodule(FreeRTOS_TCP())

Expand All @@ -95,7 +94,8 @@ def build(env):
env.substitutions = {
"core": core,
"frequency": env.get("frequency", 1000),
"with_debug": env.has_module(":debug")
"with_debug": env.has_module(":debug"),
"with_heap": env.has_module(":platform:heap"),
}
path = core.replace("cortex-m", "ARM_CM").replace("+", "").replace("fd", "f").upper()
path = path.replace("CM7F", "CM7/r0p1") # use subfolder for M7
Expand Down
2 changes: 1 addition & 1 deletion src/modm/processing/rtos/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def prepare(module, options):
return False

if options[":target"].identifier["platform"] not in ["hosted"]:
module.depends(":freertos")
module.depends(":freertos",":platform:heap")

return True

Expand Down

0 comments on commit 3e4d461

Please sign in to comment.