1
This commit is contained in:
parent
bf2310bf6f
commit
4a78121aa7
19
a8/xtimer.cc
19
a8/xtimer.cc
@ -119,7 +119,6 @@ namespace a8
|
|||||||
{
|
{
|
||||||
base_ = new xtvec_base();
|
base_ = new xtvec_base();
|
||||||
base_->running_timer = nullptr;
|
base_->running_timer = nullptr;
|
||||||
base_->timer_tick = get_tick_count_func_(context_);
|
|
||||||
INIT_LIST_HEAD(&base_->free_timer);
|
INIT_LIST_HEAD(&base_->free_timer);
|
||||||
base_->free_timer_num = 0;
|
base_->free_timer_num = 0;
|
||||||
for (int j = 0; j < TVN_SIZE; j++) {
|
for (int j = 0; j < TVN_SIZE; j++) {
|
||||||
@ -143,9 +142,12 @@ namespace a8
|
|||||||
void XTimer::Init(XGetTickCountFunc func, void* context, int gc_time, int cache_timer_num)
|
void XTimer::Init(XGetTickCountFunc func, void* context, int gc_time, int cache_timer_num)
|
||||||
{
|
{
|
||||||
get_tick_count_func_ = func;
|
get_tick_count_func_ = func;
|
||||||
context_ = context_;
|
context_ = context;
|
||||||
gc_time_ = gc_time;
|
gc_time_ = gc_time;
|
||||||
cache_timer_num_ = cache_timer_num;
|
cache_timer_num_ = cache_timer_num;
|
||||||
|
#if 1
|
||||||
|
base_->timer_tick = get_tick_count_func_(context_);
|
||||||
|
#endif
|
||||||
AddRepeatTimer(gc_time_,
|
AddRepeatTimer(gc_time_,
|
||||||
a8::XParams().SetSender(this),
|
a8::XParams().SetSender(this),
|
||||||
&XTimer::GC_XTimerFunc);
|
&XTimer::GC_XTimerFunc);
|
||||||
@ -197,6 +199,14 @@ namespace a8
|
|||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xtimer_list* XTimer::AddRepeatTimerAndAttach(int expire_time, a8::XParams param, a8::XTimerFunc timer_func,
|
||||||
|
list_head* attach_list)
|
||||||
|
{
|
||||||
|
xtimer_list* timer = AddRepeatTimer(expire_time, param, timer_func);
|
||||||
|
list_add_tail(&timer->attach_entry, attach_list);
|
||||||
|
return timer;
|
||||||
|
}
|
||||||
|
|
||||||
void XTimer::ModifyTimer(xtimer_list* timer, int expire_time)
|
void XTimer::ModifyTimer(xtimer_list* timer, int expire_time)
|
||||||
{
|
{
|
||||||
DetachTimer(timer);
|
DetachTimer(timer);
|
||||||
@ -218,6 +228,9 @@ namespace a8
|
|||||||
|
|
||||||
void XTimer::DeleteTimer(xtimer_list* timer)
|
void XTimer::DeleteTimer(xtimer_list* timer)
|
||||||
{
|
{
|
||||||
|
if (base_->running_timer == timer) {
|
||||||
|
base_->running_timer = nullptr;
|
||||||
|
}
|
||||||
if (timer->timer_after_func) {
|
if (timer->timer_after_func) {
|
||||||
timer->timer_after_func(timer->param);
|
timer->timer_after_func(timer->param);
|
||||||
}
|
}
|
||||||
@ -264,6 +277,7 @@ namespace a8
|
|||||||
if (timer->timer_after_func) {
|
if (timer->timer_after_func) {
|
||||||
timer->timer_after_func(timer->param);
|
timer->timer_after_func(timer->param);
|
||||||
}
|
}
|
||||||
|
if (base_->running_timer) {
|
||||||
switch (timer->timer_type) {
|
switch (timer->timer_type) {
|
||||||
case 1:
|
case 1:
|
||||||
case 2: //循环类定时 fixed timer也是循环定时器
|
case 2: //循环类定时 fixed timer也是循环定时器
|
||||||
@ -286,6 +300,7 @@ namespace a8
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
base->running_timer = nullptr;
|
base->running_timer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,11 +15,10 @@ namespace a8
|
|||||||
|
|
||||||
class XTimer
|
class XTimer
|
||||||
{
|
{
|
||||||
private:
|
public:
|
||||||
XTimer();
|
XTimer();
|
||||||
~XTimer();
|
~XTimer();
|
||||||
|
|
||||||
public:
|
|
||||||
void Init(XGetTickCountFunc func, void* context, int gc_time, int cache_timer_num);
|
void Init(XGetTickCountFunc func, void* context, int gc_time, int cache_timer_num);
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
@ -33,6 +32,8 @@ namespace a8
|
|||||||
a8::XTimerAfterFunc timer_after_func = nullptr);
|
a8::XTimerAfterFunc timer_after_func = nullptr);
|
||||||
//添加重复执行定时器(周期性定时器)
|
//添加重复执行定时器(周期性定时器)
|
||||||
xtimer_list* AddRepeatTimer(int expire_time, a8::XParams param, a8::XTimerFunc timer_func);
|
xtimer_list* AddRepeatTimer(int expire_time, a8::XParams param, a8::XTimerFunc timer_func);
|
||||||
|
xtimer_list* AddRepeatTimerAndAttach(int expire_time, a8::XParams param, a8::XTimerFunc timer_func,
|
||||||
|
list_head* attach_list);
|
||||||
//修改定时器参数
|
//修改定时器参数
|
||||||
void ModifyTimer(xtimer_list* timer, int expire_time);
|
void ModifyTimer(xtimer_list* timer, int expire_time);
|
||||||
//删除定时器
|
//删除定时器
|
||||||
|
Loading…
x
Reference in New Issue
Block a user