当前使用情况需要手动判断,最大使用情况,使用这个函数即可
osThreadGetStackSpace最终是调用的函数svcRtxThreadGetStackSpace
[C] 纯文本查看 复制代码 /// Get available stack space of a thread based on stack watermark recording during execution.
/// \note API identical to osThreadGetStackSpace
static uint32_t svcRtxThreadGetStackSpace (osThreadId_t thread_id) {
os_thread_t *thread = osRtxThreadId(thread_id);
const uint32_t *stack;
uint32_t space;
// Check parameters
if ((thread == NULL) || (thread->id != osRtxIdThread)) {
EvrRtxThreadGetStackSpace(thread, 0U);
//lint -e{904} "Return statement before end of function" [MISRA Note 1]
return 0U;
}
// Check if stack watermark is not enabled
if ((osRtxConfig.flags & osRtxConfigStackWatermark) == 0U) {
EvrRtxThreadGetStackSpace(thread, 0U);
//lint -e{904} "Return statement before end of function" [MISRA Note 1]
return 0U;
}
//lint -e{9079} "conversion from pointer to void to pointer to other type"
stack = thread->stack_mem;
if (*stack++ == osRtxStackMagicWord) {
for (space = 4U; space < thread->stack_size; space += 4U) {
if (*stack++ != osRtxStackFillPattern) {
break;
}
}
} else {
space = 0U;
}
EvrRtxThreadGetStackSpace(thread, space);
return space;
}
|