g_runtime.c
· 1.9 KiB · C
Raw
/**
******************************************************************************
* @file user\global\g_runtime.c
* @author luhuaishuai
* @version v0.1
* @date 2026-1-12
* @brief Briefly describe the function of your function
******************************************************************************
*/
/* 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];
}
| 1 | /** |
| 2 | ****************************************************************************** |
| 3 | * @file user\global\g_runtime.c |
| 4 | * @author luhuaishuai |
| 5 | * @version v0.1 |
| 6 | * @date 2026-1-12 |
| 7 | * @brief Briefly describe the function of your function |
| 8 | ****************************************************************************** |
| 9 | */ |
| 10 | |
| 11 | /* Includes -------------------------------------------------------------------*/ |
| 12 | #include "g_runtime.h" |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | /* variables ------------------------------------------------------------------*/ |
| 18 | TaskRunTimeTypeDef TaskRunTimeStat; |
| 19 | |
| 20 | |
| 21 | |
| 22 | /* code -----------------------------------------------------------------------*/ |
| 23 | |
| 24 | /** |
| 25 | * @brief GetRunTime:计算线程运行间隔时间 |
| 26 | * |
| 27 | * @note none |
| 28 | * |
| 29 | * @param taskID : 任务ID |
| 30 | * |
| 31 | * @retval runtime : 任务周期 |
| 32 | */ |
| 33 | |
| 34 | uint32_t GetTask_RunTime(uint8_t taskID) |
| 35 | { |
| 36 | static uint32_t lasttime[Task_combined] = {0}; |
| 37 | |
| 38 | uint32_t runtime = 0; |
| 39 | uint32_t curtime = HAL_GetTick(); |
| 40 | |
| 41 | runtime = curtime - lasttime[taskID]; //计算线程运行间隔时间 runtime运行一次 |
| 42 | |
| 43 | lasttime[taskID] = curtime; |
| 44 | |
| 45 | return runtime; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @brief GetTask_Beatcnt:线程运行计数,用于判断线程是否在运行 |
| 50 | * |
| 51 | * @note none |
| 52 | * |
| 53 | * @param taskID : 任务ID |
| 54 | * |
| 55 | * @retval beatcnt[taskID] : 线程运行计数 |
| 56 | */ |
| 57 | |
| 58 | uint32_t GetTask_Beatcnt(uint8_t taskID) |
| 59 | { |
| 60 | static uint8_t beatcnt[Task_combined] = {0}; |
| 61 | |
| 62 | beatcnt[taskID]++; |
| 63 | |
| 64 | if(beatcnt[taskID] >= 10) |
| 65 | { |
| 66 | beatcnt[taskID] = 0; |
| 67 | } |
| 68 | |
| 69 | return beatcnt[taskID]; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | |
| 74 | /** |
| 75 | * @brief Get_Free_Stack:获取剩余任务栈大小 |
| 76 | * |
| 77 | * @note none |
| 78 | * |
| 79 | * @param taskID : 任务ID |
| 80 | * |
| 81 | * @retval free_stack[taskID] : 剩余任务栈大小 |
| 82 | */ |
| 83 | |
| 84 | uint32_t Get_Free_Stack(uint8_t taskID) |
| 85 | { |
| 86 | static uint32_t free_stack[Task_combined] = {0}; |
| 87 | |
| 88 | free_stack[taskID] = uxTaskGetStackHighWaterMark(NULL); |
| 89 | |
| 90 | return free_stack[taskID]; |
| 91 | } |
| 92 |
g_runtime.h
· 1.3 KiB · C
Raw
#ifndef __GRUNTIME_H
#define __GRUNTIME_H
/* includes ----------------------------------------------------------------------------------------------*/
#include "global.h"
/* macro ------------------------------------------------------------------------------------------------*/
#define Task_combined 8
/* struct ------------------------------------------------------------------------------------------------*/
typedef struct TaskRunTime
{
uint32_t threads_runtime; // 运行时间
uint32_t threads_counter; // 任务计数
uint32_t threads_freestack; // 剩余栈空间
} TaskRunTime;
enum Task_ID
{
HeartBeatTaskID = 0,
DownLinkTaskID,
UPLinkTaskID,
YkcTaskID,
};
typedef struct TaskRunTimeTypeDef
{
TaskRunTime HeartBeatTask;
TaskRunTime DownLinkTask;
TaskRunTime UPLinkTask;
TaskRunTime YkcTask;
} TaskRunTimeTypeDef;
/* Exported functions prototypes ------------------------------------------------------------------------*/
uint32_t GetTask_RunTime(uint8_t taskID);
uint32_t GetTask_Beatcnt(uint8_t taskID);
uint32_t Get_Free_Stack(uint8_t taskID);
/* Exported constants -----------------------------------------------------------------------------------*/
extern TaskRunTimeTypeDef TaskRunTimeStat;
#endif /* __GRUNTIME_H */
| 1 | |
| 2 | #ifndef __GRUNTIME_H |
| 3 | #define __GRUNTIME_H |
| 4 | |
| 5 | |
| 6 | /* includes ----------------------------------------------------------------------------------------------*/ |
| 7 | #include "global.h" |
| 8 | |
| 9 | |
| 10 | |
| 11 | /* macro ------------------------------------------------------------------------------------------------*/ |
| 12 | #define Task_combined 8 |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | /* struct ------------------------------------------------------------------------------------------------*/ |
| 18 | typedef struct TaskRunTime |
| 19 | { |
| 20 | uint32_t threads_runtime; // 运行时间 |
| 21 | uint32_t threads_counter; // 任务计数 |
| 22 | uint32_t threads_freestack; // 剩余栈空间 |
| 23 | |
| 24 | } TaskRunTime; |
| 25 | |
| 26 | |
| 27 | |
| 28 | enum Task_ID |
| 29 | { |
| 30 | HeartBeatTaskID = 0, |
| 31 | DownLinkTaskID, |
| 32 | UPLinkTaskID, |
| 33 | YkcTaskID, |
| 34 | |
| 35 | }; |
| 36 | |
| 37 | |
| 38 | |
| 39 | typedef struct TaskRunTimeTypeDef |
| 40 | { |
| 41 | TaskRunTime HeartBeatTask; |
| 42 | TaskRunTime DownLinkTask; |
| 43 | TaskRunTime UPLinkTask; |
| 44 | TaskRunTime YkcTask; |
| 45 | |
| 46 | } TaskRunTimeTypeDef; |
| 47 | |
| 48 | |
| 49 | |
| 50 | /* Exported functions prototypes ------------------------------------------------------------------------*/ |
| 51 | uint32_t GetTask_RunTime(uint8_t taskID); |
| 52 | uint32_t GetTask_Beatcnt(uint8_t taskID); |
| 53 | uint32_t Get_Free_Stack(uint8_t taskID); |
| 54 | |
| 55 | /* Exported constants -----------------------------------------------------------------------------------*/ |
| 56 | extern TaskRunTimeTypeDef TaskRunTimeStat; |
| 57 | |
| 58 | |
| 59 | #endif /* __GRUNTIME_H */ |
| 60 |