硬汉嵌入式论坛

 找回密码
 立即注册
查看: 155|回复: 0
收起左侧

[RTOS] RTX5的任务栈最大使用情况使用函数osThreadGetStackSpace获取

[复制链接]

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
119430
QQ
发表于 2025-10-12 10:19:56 | 显示全部楼层 |阅读模式



当前使用情况需要手动判断,最大使用情况,使用这个函数即可

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;
}



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-11-22 02:05 , Processed in 0.035481 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表