# soft_timer **Repository Path**: wei513723/soft_timer ## Basic Information - **Project Name**: soft_timer - **Description**: 用于嵌入式中扩展系统的定时器资源。 - **Primary Language**: C - **License**: AGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 8 - **Forks**: 5 - **Created**: 2020-12-27 - **Last Updated**: 2025-06-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # soft_timer #### 介绍 用于嵌入式中扩展系统的定时器资源。 #### 软件架构 采用纯C语言编写,使用双链表以解决创建的定时器过多时遍历时间过长的问题。 理论支持任意个定时器的扩展。 暂时没有考虑多线程使用场景,所以使用时尽量不要产生调用冲突。 #### 使用说明 1. 为软件定时器提供tick,在任意能够提供1ms周期定时(非绝对,但推荐)的函数中调用sft_tmr_inc_tick函数,例如: ```c void hardware_timer_irq(void) { sft_tmr_inc_tick(); } ``` 2. 在任意线程或裸机主循环中调用sft_tmr_loop函数,例如: ```c int main(int argc, char *argv[]) { for(;;) { sft_tmr_loop(); /* do something */ } } ``` 3. 创建定时器并启动,例如: ```c static struct sft_tmr_t *tmr; static uint32_t para; static void sft_tmr_callback(void *para) { printf("%d\r\n", *((uint32_t *)para)); } int main(int argc, char *argv[]) { para = 1; sft_tmr_create(&tmr, 1000, 1, sft_tmr_callback, ¶); sft_tmr_start(tmr, 0); /* do something */ } ``` 3. 可选的内存管理函数重定义,默认使用系统堆内存。 #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request