modify timer by wangweigen
This commit is contained in:
+14
-27
@@ -53,14 +53,14 @@ xs_uint32 xs_CurrentTicksGain(void);
|
||||
|
||||
<span id="tmr_mechanism"></span>
|
||||
|
||||
## 定时器机制
|
||||
软件定时器模块根据系统的节拍心跳(tick)提供软件定时服务,用户可以设定固定的超时时间,
|
||||
## 内核定时器机制
|
||||
内核软件定时器模块根据系统的节拍心跳(tick)提供软件定时服务,用户可以设定固定的超时时间,
|
||||
当系统运行的节拍数到达用户设定的超时时间时,便执行用户定义的超时回调函数进行业务处理。
|
||||
软件定时器的存在可以解决硬件定时器数量不足的问题。
|
||||
|
||||
<span id="structure"></span>
|
||||
|
||||
### 软件定时器结构定义
|
||||
### 内核软件定时器结构定义
|
||||
```c
|
||||
#define TRIGGE_WAY_ONCE (1 << 0)
|
||||
#define TRIGGE_WAY_PERIODIC (1 << 1)
|
||||
@@ -74,7 +74,7 @@ struct xs_Timer
|
||||
xs_tick_x origin_timeslice; ///< 超时时间
|
||||
xs_tick_x deadline_timeslice; ///< 截止时间
|
||||
XS_DOUBLE_LINKLIST link; ///< 管理链表
|
||||
XS_DOUBLE_LINKLIST Sortlist; ///< 查询链表
|
||||
XS_DOUBLE_LINKLIST Sortlist; ///< 查询链表
|
||||
};
|
||||
typedef struct xs_Timer *xs_timer_x;
|
||||
```
|
||||
@@ -91,23 +91,19 @@ typedef struct xs_Timer *xs_timer_x;
|
||||
|
||||
<span id="timer_api"></span>
|
||||
|
||||
### 软件定时器接口
|
||||
### 内核软件定时器接口
|
||||
定时器用户操作结构体定义如下:
|
||||
|
||||
```c
|
||||
#define TRIGGE_WAY_ONCE (1 << 0)
|
||||
#define TRIGGE_WAY_PERIODIC (1 << 1)
|
||||
|
||||
struct xs_utimer
|
||||
{
|
||||
xs_uint8 trigge_way; ///< 触发方式,包括单次触发和周期触发方式
|
||||
void (*func_callback)(void *param); ///< 超时回调函数
|
||||
void *func_param; ///< 回调函数的参数
|
||||
xs_tick_x ticks; ///< 定时时间,单位为 tick
|
||||
};
|
||||
typedef struct xs_utimer xs_utimer_x;
|
||||
```c
|
||||
xs_int32 xs_KTimerCreate(xs_uint8 trigge_way,void (*func_callback)(void *param),void *func_param, xs_tick_x ticks);
|
||||
```
|
||||
| 成员 | 描述 |
|
||||
该函数用于创建一个内核软件定时器,并返回创建成功的软件定时器的ID,ID默认范围0-255,可配置。
|
||||
|
||||
| 参数 | 描述 |
|
||||
| --- | --- |
|
||||
| trigge_way | 触发方式,可以配置为宏TRIGGE_WAY_ONCE和TRIGGE_WAY_PERIODIC |
|
||||
| func_callback | 软件定时器回调函数 |
|
||||
@@ -115,16 +111,7 @@ typedef struct xs_utimer xs_utimer_x;
|
||||
| ticks | 配置需要等待的超时时间 |
|
||||
|
||||
```c
|
||||
xs_int32 xs_UserTimerCreate(xs_utimer_x* timer);
|
||||
```
|
||||
该函数用于创建一个软件定时器,并返回创建成功的软件定时器的ID,ID默认范围0-255,可配置。
|
||||
|
||||
| 参数 | 描述 |
|
||||
| --- | --- |
|
||||
| timer | 软件定时器初始化结构体 |
|
||||
|
||||
```c
|
||||
void xs_UserTimerDelete(xs_uint16 id);
|
||||
void xs_KTimerDelete(xs_uint16 id);
|
||||
```
|
||||
该函数用于删除一个软件定时器。
|
||||
|
||||
@@ -133,7 +120,7 @@ void xs_UserTimerDelete(xs_uint16 id);
|
||||
| id | 待删除的软件定时器ID |
|
||||
|
||||
```c
|
||||
xs_int32 xs_UserTimerStartRun(xs_uint16 id);
|
||||
xs_int32 xs_KTimerStartRun(xs_uint16 id);
|
||||
```
|
||||
该函数用于启动一个软件定时器。
|
||||
|
||||
@@ -142,7 +129,7 @@ xs_int32 xs_UserTimerStartRun(xs_uint16 id);
|
||||
| id | 已创建且待运行的软件定时器ID |
|
||||
|
||||
```c
|
||||
xs_int32 xs_UserTimerQuitRun(xs_uint16 id);
|
||||
xs_int32 xs_KTimerQuitRun(xs_uint16 id);
|
||||
```
|
||||
该函数用于停止一个软件定时器。
|
||||
|
||||
@@ -151,7 +138,7 @@ xs_int32 xs_UserTimerQuitRun(xs_uint16 id);
|
||||
| id | 待停止运行的软件定时器ID |
|
||||
|
||||
```c
|
||||
xs_int32 xs_UserTimerModify(xs_uint16 id, xs_tick_x ticks);
|
||||
xs_int32 xs_KTimerModify(xs_uint16 id, xs_tick_x ticks);
|
||||
```
|
||||
该函数用于修改一个软件定时器的超时时间。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user