Skip to content

Commit

Permalink
实现3.06版本中新增的OSTmrSet函数
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterywolf committed Aug 23, 2020
1 parent 9b83a9a commit e994051
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 17 deletions.
5 changes: 3 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
### 2020-8-23

- 修改`OS_TMR`结构体`.Remain``.Match`成员变量赋值的bug
- 实现3.06版本中新增的`OSTmrSet`函数



Expand Down Expand Up @@ -387,6 +388,8 @@

**[bug fix]** 修改`OS_TMR`结构体`.Remain``.Match`成员变量赋值的bug

**[add 3.08]** 实现3.06版本中新增的`OSTmrSet`函数



# TODO
Expand All @@ -399,5 +402,3 @@
OS_OPT FlagsOpt; /* Options (See OS_OPT_FLAG_xxx) */
```

2. 3.08版本中多出一个`OSTmrSet`函数
3. 调整注释排版
4 changes: 2 additions & 2 deletions uCOS-III_Wrapper/examples/timer_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ static void AppTask1 (void *param)
(void *)0,/*参数为0*/
(OS_ERR *)&err);/*返回的错误码*/

OSTmrStart(&CPUUsageTimer,&err);/*开启定时器*/
OSTmrStart(&CPUUsageTimer,&err);/*开启定时器*/

while(1)
{
OSTaskStkChk(RT_NULL,&free,&used,&err);/*获取当前任务堆栈信息*/
Expand Down
63 changes: 50 additions & 13 deletions uCOS-III_Wrapper/uCOS-III/os_tmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,12 @@ void OS_TmrCallback(void *p_ara)
{
OS_TMR *p_tmr;
OS_ERR err;
char* nameptr;
OS_TMR_CALLBACK_PTR callback;
void * arg;
OS_OPT opt;
OS_TICK dly;
OS_TICK period;

CPU_SR_ALLOC();

Expand All @@ -1135,31 +1141,62 @@ void OS_TmrCallback(void *p_ara)
p_tmr->Tmr.init_tick = p_tmr->Period * (1000 / OS_CFG_TMR_TASK_RATE_HZ);
p_tmr->Tmr.timeout_tick = rt_tick_get() + p_tmr->Tmr.init_tick;
p_tmr->Tmr.parent.flag |= RT_TIMER_FLAG_PERIODIC;/*定时器设置为周期模式*/
p_tmr->Remain = p_tmr->Period;
CPU_CRITICAL_EXIT();
rt_timer_start(&(p_tmr->Tmr));/*开启定时器*/
}
else if(p_tmr->Opt==OS_OPT_TMR_PERIODIC)

if(p_tmr->Opt == OS_OPT_TMR_ONE_SHOT)
{
/*若不是带有延迟的周期模式模式,而仅仅是周期模式*/
CPU_CRITICAL_ENTER();
p_tmr->Remain = p_tmr->Period;
p_tmr->State = OS_TMR_STATE_COMPLETED;
p_tmr->Remain = 0;
CPU_CRITICAL_EXIT();
}

CPU_CRITICAL_ENTER();
if(p_tmr->Opt == OS_OPT_TMR_ONE_SHOT)
else if (p_tmr->Opt == OS_OPT_TMR_PERIODIC)
{
p_tmr->State = OS_TMR_STATE_COMPLETED;
CPU_CRITICAL_ENTER();
/*重新设定下一次定时器的参数*/
p_tmr->Match = rt_tick_get() + p_tmr->Tmr.init_tick;
p_tmr->Remain = p_tmr->Period;
CPU_CRITICAL_EXIT();
}
/*重新设定下一次定时器的.Match变量*/
p_tmr->Match = rt_tick_get() + p_tmr->Tmr.init_tick;
CPU_CRITICAL_EXIT();


/*调用真正uCOS-III的软件定时器回调函数*/
OSSchedLock(&err);
p_tmr->CallbackPtr((void *)p_tmr, p_tmr->CallbackPtrArg);
OSSchedUnlock(&err);
OSSchedUnlock(&err);

/*-----处理OSTmrSet函数------*/
if(p_tmr->_set_dly || p_tmr->_set_period) /* 检查是否调用OSTmrSet函数 */
{
OSTmrStop(p_tmr,OS_OPT_TMR_NONE,0,&err); /* 删除当前定时器 */
/*将老定时器的参数保存*/
nameptr = p_tmr->NamePtr;
callback = p_tmr->CallbackPtr;
arg = p_tmr->CallbackPtrArg;
opt = p_tmr->Opt;
dly = p_tmr->_set_dly;
period = p_tmr->_set_period;
OSTmrDel(p_tmr,&err);
if(err!=OS_ERR_NONE)
{
return;
}

if(dly && period)
{
OSTmrCreate(p_tmr, nameptr, dly, period, opt, callback, arg, &err);
}
else if(dly)
{
OSTmrCreate(p_tmr, nameptr, dly, period, opt, callback, arg, &err);
}
else if(period)
{
OSTmrCreate(p_tmr, nameptr, dly, period, opt, callback, arg, &err);
}
OSTmrStart(p_tmr, &err); /* 启动装填新参数的定时器 */
}
}

#endif

0 comments on commit e994051

Please sign in to comment.