Files
BR_YKC/Core/User/App/task_sys.h
2026-05-21 12:19:01 +08:00

33 lines
1.0 KiB
C

/**
******************************************************************************
* @file User\App\task_sys.h
* @author 路淮
* @version v0.1
* @date 2026-05-21
* @brief 系统任务头文件
******************************************************************************
*/
#ifndef __TASK_SYS_H
#define __TASK_SYS_H
/* includes ------------------------------------------------------------------*/
#include "global.h"
#include "cmsis_os.h" // 或使用 HAL_GetTick() 等
// 获取当前系统时间(毫秒)
//#define GET_TICK() (osKernelSysTick()) // FreeRTOS/CMSIS-RTOS
#define GET_TICK() (HAL_GetTick()) // STM32 HAL 用户可换这行
// 非阻塞延时宏:每 interval_ms 执行一次 {code}
#define RUN_EVERY(interval_ms, static_tick_var, code) \
do { \
static uint32_t static_tick_var = 0; \
if ((GET_TICK() - static_tick_var) >= (interval_ms)) { \
static_tick_var = GET_TICK(); \
code; \
} \
} while(0)
#endif /* __TASK_SYS_H */