Skip to content

Commit d973c5a

Browse files
committed
fix(HardRT): fix HARDRT_MAX_TASKS, where an additional task is added to the default / user selected number of tasks in the cmake, where last task id is taken by idle task.
1 parent 7ac2b27 commit d973c5a

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ message("-- HARDRT_BUILD_EXAMPLES : ${HARDRT_BUILD_EXAMPLES}")
3131
message("-- HARDRT_BUILD_TESTS : ${HARDRT_BUILD_TESTS}")
3232
message("-- HARDRT_STALL_ON_ERROR : ${HARDRT_STALL_ON_ERROR}")
3333
message("-- HARDRT_DEBUG : ${HARDRT_DEBUG}")
34-
message("-- HARDRT_CFG_MAX_TASKS : ${HARDRT_CFG_MAX_TASKS}")
34+
message("-- HARDRT_CFG_MAX_TASKS : ${HARDRT_CFG_MAX_TASKS} + 1 for IDLE task")
3535
message("-- HARDRT_CFG_MAX_PRIO : ${HARDRT_CFG_MAX_PRIO}")
3636

3737
# Validate sizing knobs at configure time (no kernel source changes needed)
@@ -48,6 +48,8 @@ endif()
4848
if(_HRT_CFG_TASKS LESS 1)
4949
message(FATAL_ERROR "HARDRT_CFG_MAX_TASKS must be >= 1. Got ${HARDRT_CFG_MAX_TASKS}.")
5050
endif()
51+
52+
# this is not actually fatal, but makes no sense to have priority to whom no available task is associated.
5153
if(_HRT_CFG_TASKS LESS _HRT_CFG_PRIO)
5254
message(FATAL_ERROR "Invalid configuration: HARDRT_CFG_MAX_TASKS (${HARDRT_CFG_MAX_TASKS}) must be >= HARDRT_CFG_MAX_PRIO (${HARDRT_CFG_MAX_PRIO}).")
5355
endif()
@@ -117,9 +119,11 @@ add_library(${LIB_NAME} STATIC ${LIBRARY_SOURCES})
117119

118120
# Propagate sizing knobs to all consumers (library PUBLIC interface)
119121
# so examples/tests and downstream apps see consistent limits.
122+
# HARDRT_CFG_MAX_TASKS + 1 as the extra task is taken by the idle task.
123+
math(EXPR HARDRT_MAX_TASKS_VALUE "${HARDRT_CFG_MAX_TASKS} + 1")
120124
target_compile_definitions(${LIB_NAME}
121125
PUBLIC
122-
HARDRT_MAX_TASKS=${HARDRT_CFG_MAX_TASKS}
126+
HARDRT_MAX_TASKS=${HARDRT_MAX_TASKS_VALUE}
123127
HARDRT_MAX_PRIO=${HARDRT_CFG_MAX_PRIO}
124128
HARDRT_STALL_ON_ERROR=${HARDRT_STALL_ON_ERROR}
125129
HARDRT_DEBUG=${HARDRT_DEBUG}

src/port/cortex_m/hrt_pendsv_handler.s

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,8 @@
1010
* PendSV_Handler - Cortex-M context switch handler for HeartOS
1111
*
1212
* Contract with C side:
13-
* - hrt__save_current_sp(uint32_t *sp):
14-
* Saves the updated PSP (after pushing r4-r11) into the current TCB.
15-
*
16-
* - int hrt__pick_next_ready(void):
17-
* Returns the next task id to run.
18-
*
19-
* - uint32_t *hrt__load_next_sp_and_set_current(int id):
20-
* Sets the current task id and returns that task's saved SP.
13+
* - uint32_t hrt__schedule(uint32_t old_sp):
14+
* Saves the updated PSP (after pushing r4-r11) into the current TCB ,returns next sp.
2115
*
2216
* Stack layout expected when switching OUT of a running task:
2317
* [high addr]

0 commit comments

Comments
 (0)