Files
BR_YKC/Core/User/Global/g_runtime.c
2026-05-21 12:19:01 +08:00

92 lines
1.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
******************************************************************************
* @file User\Global\g_runtime.c
* @author 路淮
* @version v0.1
* @date 2026-05-21
* @brief 运行时统计
******************************************************************************
*/
/* Includes -------------------------------------------------------------------*/
#include "g_runtime.h"
/* variables ------------------------------------------------------------------*/
TaskRunTimeTypeDef TaskRunTimeStat;
/* code -----------------------------------------------------------------------*/
/**
* @brief GetRunTime计算线程运行间隔时间
*
* @note none
*
* @param taskID : 任务ID
*
* @retval runtime : 任务周期
*/
uint32_t GetTask_RunTime(uint8_t taskID)
{
static uint32_t lasttime[Task_combined] = {0};
uint32_t runtime = 0;
uint32_t curtime = HAL_GetTick();
runtime = curtime - lasttime[taskID]; //计算线程运行间隔时间 runtime运行一次
lasttime[taskID] = curtime;
return runtime;
}
/**
* @brief GetTask_Beatcnt线程运行计数,用于判断线程是否在运行
*
* @note none
*
* @param taskID : 任务ID
*
* @retval beatcnt[taskID] : 线程运行计数
*/
uint32_t GetTask_Beatcnt(uint8_t taskID)
{
static uint8_t beatcnt[Task_combined] = {0};
beatcnt[taskID]++;
if(beatcnt[taskID] >= 10)
{
beatcnt[taskID] = 0;
}
return beatcnt[taskID];
}
/**
* @brief Get_Free_Stack获取剩余任务栈大小
*
* @note none
*
* @param taskID : 任务ID
*
* @retval free_stack[taskID] : 剩余任务栈大小
*/
uint32_t Get_Free_Stack(uint8_t taskID)
{
static uint32_t free_stack[Task_combined] = {0};
free_stack[taskID] = uxTaskGetStackHighWaterMark(NULL);
return free_stack[taskID];
}