Zephyr Project RTOS Tutorial (6) 教學 : Kernel API – Timers Test

文章作者: 盧宜良

主要funtion:
k_timer_expiry_t function pointer

k_timer_init 初始化

k_timer_start 開始

k_timer_stop_t 停止,呼叫後執行 STOP k_timer_expiry_t

測試CODE:

 

static struct k_timer timer;
static int count = 0;

static void timer_expire(struct k_timer *timer)
{
	count++;
	printk("timer_expire [%d]:%u\n", count, timer->status);

	if (count == 10) // run 10 time
		k_timer_stop(timer); // call timer_stop
}

static void timer_stop(struct k_timer *timer)
{
	printk("timer_stop\n");
}

void main(void)
{
	console_init();
	printk("Hello World! %s\n", CONFIG_ARCH);

	k_timer_init(&timer, timer_expire, timer_stop);
	k_timer_start(&timer, 10000, 1000); // wait 10 sec , period 1 sec

	while (1) {
		k_sleep(1000); // nothing
	}
}

 

未經允許不得轉載:GoMCU » Zephyr Project RTOS Tutorial (6) 教學 : Kernel API – Timers Test