136 lines
2.7 KiB
C
136 lines
2.7 KiB
C
#include <stdio.h>
|
|
#include "time.h"
|
|
#include "los_swtmr.h"
|
|
#include "los_sys.h"
|
|
|
|
|
|
|
|
#include "ohos_init.h"
|
|
// #include "iot_gpio.h"
|
|
// #include "iot_gpio_ex.h"
|
|
|
|
// #include "iot_i2c.h"
|
|
|
|
// #include "cmsis_os2.h"
|
|
|
|
|
|
// #include "ohos_init.h"
|
|
// #include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
// #include <cmsis_os2.h>
|
|
#include <stdbool.h>
|
|
|
|
|
|
// #ifdef __cplusplus
|
|
// #if __cplusplus
|
|
// extern "C" {
|
|
// #endif /* __cplusplus */
|
|
// #endif /* __cplusplus */
|
|
|
|
UINT32 g_timerCount1 = 0;
|
|
UINT32 g_timerCount2 = 0;
|
|
|
|
VOID Timer1_CallBack(UINT32 arg)
|
|
{
|
|
UINT64 lastTick;
|
|
|
|
g_timerCount1++;
|
|
lastTick=(UINT32)LOS_TickCountGet();
|
|
dprintf("g_timerCount1=%d\n", g_timerCount1);
|
|
dprintf("tick_last1=%d\n", lastTick);
|
|
}
|
|
|
|
VOID Timer2_CallBack(UINT32 arg)
|
|
{
|
|
UINT64 lastTick;
|
|
|
|
lastTick=(UINT32)LOS_TickCountGet();
|
|
g_timerCount2++;
|
|
dprintf("g_timerCount2=%d\n", g_timerCount2);
|
|
dprintf("tick_last2=%d\n", lastTick);
|
|
}
|
|
|
|
// VOID Timer_example(VOID)
|
|
// {
|
|
// UINT16 id1; // Timer1 id
|
|
// UINT16 id2; // Timer2 id
|
|
// UINT32 tick;
|
|
|
|
// LOS_SwtmrCreate(1000, LOS_SWTMR_MODE_ONCE, Timer1_CallBack, &id1, 1);
|
|
// LOS_SwtmrCreate(100, LOS_SWTMR_MODE_PERIOD, Timer2_CallBack, &id2, 1);
|
|
// dprintf("create Timer1 success\n");
|
|
|
|
// LOS_SwtmrStart(id1);
|
|
// dprintf("start Timer1 sucess\n");
|
|
// LOS_TaskDelay(200);
|
|
// LOS_SwtmrTimeGet(id1, &tick);
|
|
// dprintf("tick =%d\n", tick);
|
|
// LOS_SwtmrStop(id1);
|
|
// dprintf("stop Timer1 sucess\n");
|
|
|
|
// LOS_SwtmrStart(id1);
|
|
// LOS_TaskDelay(1000);
|
|
// LOS_SwtmrDelete(id1);
|
|
// dprintf("delete Timer1 sucess\n");
|
|
|
|
// LOS_SwtmrStart(id2);
|
|
// dprintf("start Timer2\n");
|
|
// LOS_TaskDelay(1000);
|
|
// LOS_SwtmrStop(id2);
|
|
// LOS_SwtmrDelete(id2);
|
|
// }
|
|
|
|
// #ifdef __cplusplus
|
|
// #if __cplusplus
|
|
// }
|
|
// #endif /* __cplusplus */
|
|
// #endif /* __cplusplus */
|
|
|
|
|
|
|
|
/***** 定时器创建 *****/
|
|
static void Timer_example(void)
|
|
{
|
|
UINT16 id1; // Timer1 id
|
|
UINT16 id2; // Timer2 id
|
|
UINT32 tick;
|
|
|
|
LOS_SwtmrCreate(1000, LOS_SWTMR_MODE_ONCE, Timer1_CallBack, &id1, 1);
|
|
LOS_SwtmrCreate(100, LOS_SWTMR_MODE_PERIOD, Timer2_CallBack, &id2, 1);
|
|
dprintf("create Timer1 success\n");
|
|
|
|
LOS_SwtmrStart(id1);
|
|
dprintf("start Timer1 sucess\n");
|
|
LOS_TaskDelay(200);
|
|
LOS_SwtmrTimeGet(id1, &tick);
|
|
dprintf("tick =%d\n", tick);
|
|
LOS_SwtmrStop(id1);
|
|
dprintf("stop Timer1 sucess\n");
|
|
|
|
LOS_SwtmrStart(id1);
|
|
LOS_TaskDelay(1000);
|
|
LOS_SwtmrDelete(id1);
|
|
dprintf("delete Timer1 sucess\n");
|
|
|
|
LOS_SwtmrStart(id2);
|
|
dprintf("start Timer2\n");
|
|
LOS_TaskDelay(1000);
|
|
LOS_SwtmrStop(id2);
|
|
LOS_SwtmrDelete(id2);
|
|
|
|
}
|
|
|
|
APP_FEATURE_INIT(Timer_example);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|