代码拉取完成,页面将自动刷新
#include <stdio.h>
#include <unistd.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
static int times = 0;
void cb_timeout_periodic(void *arg) {
(void)arg;
times++;
}
void timer_periodic(void) {
osTimerId_t periodic_tid = osTimerNew(cb_timeout_periodic, osTimerPeriodic, NULL, NULL);
if (periodic_tid == NULL) {
printf("[Timer Test] osTimerNew(periodic timer) failed.\r\n");
return;
} else {
printf("[Timer Test] osTimerNew(periodic timer) success, tid: %p.\r\n",periodic_tid);
}
osStatus_t status = osTimerStart(periodic_tid, 100);
if (status != osOK) {
printf("[Timer Test] osTimerStart(periodic timer) failed.\r\n");
return;
} else {
printf("[Timer Test] osTimerStart(periodic timer) success, wait a while and stop.\r\n");
}
while(times < 3) {
printf("[Timer Test] times:%d.\r\n",times);
osDelay(100);
}
status = osTimerStop(periodic_tid);
printf("[Timer Test] stop periodic timer, status :%d.\r\n", status);
status = osTimerDelete(periodic_tid);
printf("[Timer Test] kill periodic timer, status :%d.\r\n", status);
}
static void TimerTestTask(void)
{
osThreadAttr_t attr;
attr.name = "timer_periodic";
attr.attr_bits = 0U;
attr.cb_mem = NULL;
attr.cb_size = 0U;
attr.stack_mem = NULL;
attr.stack_size = 1024;
attr.priority = osPriorityNormal;
if (osThreadNew((osThreadFunc_t)timer_periodic, NULL, &attr) == NULL) {
printf("[TimerTestTask] Falied to create timer_periodic!\n");
}
}
APP_FEATURE_INIT(TimerTestTask);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。