• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "los_swtmr.h"
17 #include "ohos_init.h"
18 
19 /* 定时器定时滴答数 */
20 #define TIMER1_TICK         1000
21 #define TIMER2_TICK         2000
22 
23 /***************************************************************
24 * 函数名称: timer1_timeout
25 * 说    明: 定时器1超时函数
26 * 参    数: 无
27 * 返 回 值: 无
28 ***************************************************************/
timer1_timeout(void)29 void timer1_timeout(void)
30 {
31     printf("This is Timer1 Timeout function\n");
32 }
33 
34 /***************************************************************
35 * 函数名称: timer2_timeout
36 * 说    明: 定时器2超时函数
37 * 参    数: 无
38 * 返 回 值: 无
39 ***************************************************************/
timer2_timeout(void)40 void timer2_timeout(void)
41 {
42     printf("This is Timer2 Timeout function\n");
43 }
44 
45 /***************************************************************
46 * 函数名称: timer_example
47 * 说    明: 内核定时器函数
48 * 参    数: 无
49 * 返 回 值: 无
50 ***************************************************************/
timer_example(void)51 void timer_example(void)
52 {
53     unsigned int timer_id1, timer_id2;
54     unsigned int ret;
55 
56     ret = LOS_SwtmrCreate(TIMER1_TICK, LOS_SWTMR_MODE_PERIOD, timer1_timeout, &timer_id1, NULL);
57     if (ret == LOS_OK) {
58         ret = LOS_SwtmrStart(timer_id1);
59         if (ret != LOS_OK) {
60             printf("start timer1 fail ret:0x%x\n", ret);
61             return;
62         }
63     } else {
64         printf("create timer1 fail ret:0x%x\n", ret);
65         return;
66     }
67 
68     ret = LOS_SwtmrCreate(TIMER2_TICK, LOS_SWTMR_MODE_PERIOD, timer2_timeout, &timer_id2, NULL);
69     if (ret == LOS_OK) {
70         ret = LOS_SwtmrStart(timer_id2);
71         if (ret != LOS_OK) {
72             printf("start timer2 fail ret:0x%x\n", ret);
73             return;
74         }
75     } else {
76         printf("create timer2 fail ret:0x%x\n"), ret;
77         return;
78     }
79 }
80 
81 APP_FEATURE_INIT(timer_example);
82