3 Star 17 Fork 6

hihopeorg/HiSpark-HM-Pegasus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
timer.c 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
宋倩倩 提交于 2021-03-05 15:36 +08:00 . add readme
#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);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/hihopeorg/hispark-hm-pegasus.git
git@gitee.com:hihopeorg/hispark-hm-pegasus.git
hihopeorg
hispark-hm-pegasus
HiSpark-HM-Pegasus
1.0.1

搜索帮助