void mm_timer_schedule(int dummy) { struct mm_timer_tag *timer; for(;;) { ke_evt_clear(KE_EVT_MM_TIMER); // check the next timer timer = (struct mm_timer_tag *)co_list_pick(&mm_timer_env.prog); if (!timer) { // no more timers, disable HW irq and leave mm_timer_hw_set(NULL); break; } if (!hal_machw_time_past(timer->time - 50)) { // timer will expire in more than 32us, configure the HW mm_timer_hw_set(timer); // in most case, we will break here. However, if the timer expiration // time has just passed, may be the HW was set too late (due to an IRQ) // so we do not exit the loop to process it. if (!hal_machw_time_past(timer->time)) { break; } } // at this point, the next timer in the queue has expired or is about to -> pop it co_list_pop_front(&mm_timer_env.prog); // Sanity check ASSERT_ERR(timer->cb); // notify the caller - It has to be done after popping the timer from the queue // as the callback may set it again timer->cb(timer->env); } }
时间: 2023-04-11 08:00:27 浏览: 83
这是一个关于程序代码的问题,我可以回答。这段代码是一个定时器调度函数,它会循环遍历定时器列表,检查是否有定时器到期,如果有则触发相应的事件。其中,co_list_pick()函数用于从定时器列表中选择下一个定时器,ke_evt_clear()函数用于清除事件标志。
相关问题
void co_timer_del(co_timer_t *timer)
void co_timer_del(co_timer_t *timer) 的作用是删除一个协程定时器。
具体来说,它会将指定的协程定时器从定时器链表中移除,并释放相关的内存资源。这样,该定时器就不会再触发定时器事件了。
需要注意的是,调用该函数时,传入的参数 timer 必须是之前通过 co_timer_add 函数添加的定时器。否则,可能会出现不可预期的错误。
GUI_TIMER_TIME 的宏定义int
非常抱歉,我的回答还是有误。`GUI_TIMER_TIME` 结构体中的 `Time` 和 `Repeat` 字段应该是 `U32` 类型,而不是 `int` 类型。
下面是一个正确的示例代码,演示如何使用 `GUI_TIMER_TIME` 结构体来指定定时器的触发时间和周期:
```c
#include "GUI.h"
typedef struct {
U32 Time;
U32 Repeat;
} GUI_TIMER_TIME;
static GUI_TIMER_HANDLE hTimer;
static int cnt = 0;
void myTimerCallback(GUI_TIMER_MESSAGE* pTM)
{
cnt++;
char buf[32];
sprintf(buf, "Count: %d", cnt);
GUI_DispStringAt(buf, 100, 100);
}
int main(void)
{
GUI_Init();
// 定义一个 GUI_TIMER_TIME 结构体,用于指定定时器的触发时间和周期
GUI_TIMER_TIME timerTime = {1000, 1000};
// 创建一个定时器,并指定定时器回调函数、定时器触发时间和周期、以及定时器属性
hTimer = GUI_TIMER_Create(&myTimerCallback, timerTime, 0, GUI_TIMER_CF_RESTART);
while (1)
{
GUI_Exec();
}
}
```
在这个示例代码中,我们定义了一个 `GUI_TIMER_TIME` 结构体,包含了 `Time` 和 `Repeat` 两个字段,用于指定定时器的触发时间和周期。然后,我们在创建定时器时,使用这个结构体来指定定时器的触发时间和周期。
需要注意的是,这里的 `GUI_TIMER_TIME` 结构体是 emWin 图形库中自带的结构体,无需再手动定义。如果你使用的是 emWin 图形库的官方版本,这个结构体应该已经在 `GUI.h` 头文件中被定义了。