libxr 1.0
Want to be the best embedded framework
|
定时器类,实现周期性任务调度 Timer class for scheduling periodic tasks More...
#include <timer.hpp>
Data Structures | |
class | ControlBlock |
控制块类,存储任务信息 Control block class for storing task information More... | |
Public Types | |
typedef LibXR::List::Node< ControlBlock > * | TimerHandle |
定时器任务句柄 Timer task handle | |
Static Public Member Functions | |
template<typename ArgType > | |
static TimerHandle | CreateTask (void(*fun)(ArgType), ArgType arg, uint32_t cycle) |
创建定时任务 Creates a periodic task | |
static void | Start (TimerHandle handle) |
启动定时任务 Starts a periodic task | |
static void | Stop (TimerHandle handle) |
停止定时任务 Stops a periodic task | |
static void | SetCycle (TimerHandle handle, uint32_t cycle) |
设置定时任务的周期 Sets the cycle of a periodic task | |
static void | RefreshThreadFunction (void *) |
定时器管理线程函数 Timer management thread function | |
static void | Remove (TimerHandle handle) |
删除定时任务 Removes a periodic task | |
static void | Add (TimerHandle handle) |
添加定时任务 Adds a periodic task | |
static void | Refresh () |
刷新定时任务状态 Refreshes the state of periodic tasks | |
static void | RefreshTimerInIdle () |
在空闲时刷新定时器 Refreshes the timer during idle time | |
Static Public Attributes | |
static LibXR::List * | list_ = nullptr |
定时任务列表 List of registered tasks | |
static Thread | thread_handle_ |
定时器管理线程 Timer management thread | |
static LibXR::Thread::Priority | priority_ |
线程优先级 Thread priority | |
static uint32_t | stack_depth_ |
线程栈深度 Thread stack depth | |
定时器类,实现周期性任务调度 Timer class for scheduling periodic tasks
该定时器支持多任务调度,可用于执行周期性任务,如定时回调函数调用。 Timer 提供任务创建、启动、停止、删除及周期调整等功能,并使用 Thread::SleepUntil
实现精确调度。
This timer supports multi-task scheduling and can be used to execute periodic tasks, such as invoking callback functions at regular intervals. It provides task creation, start, stop, delete, and cycle adjustment functionalities, utilizing Thread::SleepUntil
for precise scheduling.
|
inlinestatic |
添加定时任务 Adds a periodic task
handle | 任务句柄 Timer handle to add |
Definition at line 169 of file timer.hpp.
|
inlinestatic |
创建定时任务 Creates a periodic task
ArgType | 任务参数类型 Type of task argument |
fun | 定时执行的任务函数 Function to execute periodically |
arg | 任务参数 Argument for the function |
cycle | 任务周期(毫秒) Task execution cycle (milliseconds) |
该方法创建一个新的周期性任务,任务将在 cycle
毫秒的周期内运行。 若 cycle
小于等于 0,则会触发 ASSERT
断言。
This method creates a new periodic task that runs in a cycle of cycle
milliseconds. If cycle
is less than or equal to 0, it triggers an ASSERT
assertion.
Definition at line 69 of file timer.hpp.
刷新定时任务状态 Refreshes the state of periodic tasks
该方法遍历任务列表,并检查任务是否应当运行。 若任务启用,并且 count_
达到 cycle_
,则执行任务并重置计数器。
This method iterates through the task list and checks whether a task should run. If a task is enabled and its count_
reaches cycle_
, the task is executed and the counter is reset.
Definition at line 197 of file timer.hpp.
定时器管理线程函数 Timer management thread function
unused | 未使用参数 Unused parameter |
该线程持续运行,定期刷新任务列表,并确保任务按时执行。 Thread::SleepUntil
方式用于精确调度。
This thread runs continuously, periodically refreshing the task list and ensuring timely task execution. Thread::SleepUntil
is used for precise scheduling.
Definition at line 135 of file timer.hpp.
|
static |
在空闲时刷新定时器 Refreshes the timer during idle time
Definition at line 16 of file libxr_system.cpp.
|
inlinestatic |
删除定时任务 Removes a periodic task
handle | 任务句柄 Timer handle to remove |
该方法删除已注册的定时任务,并确保任务列表完整性。 若 handle->next_
为空,则会触发 ASSERT
断言。
This method removes a registered periodic task while ensuring the integrity of the task list. If handle->next_
is null, it triggers an ASSERT
assertion.
Definition at line 158 of file timer.hpp.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |