• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
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 <stdio.h>
17 #include <string.h>
18 #include <unistd.h>
19 
20 #include "cmsis_os2.h"
21 #include "ohos_init.h"
22 
23 /**
24  * @brief Callback for Timer1 triggering
25  *
26  */
Timer1Callback(void)27 void Timer1Callback(void)
28 {
29     printf("This is BearPi Timer1Callback!\n");
30 }
31 
32 /**
33  * @brief Callback for Timer2 triggering
34  *
35  */
Timer2Callback(void)36 void Timer2Callback(void)
37 {
38     printf("This is BearPi Timer2Callback!\n");
39 }
40 
41 /**
42  * @brief Main Entry of the Timer Example
43  *
44  */
TimerExample(void)45 static void TimerExample(void)
46 {
47     osTimerId_t id1, id2;
48     uint32_t timerDelay;
49     osStatus_t status;
50 
51     id1 = osTimerNew(Timer1Callback, osTimerPeriodic, NULL, NULL);
52     if (id1 != NULL) {
53         // Hi3861 1U=10ms,100U=1S
54         timerDelay = 100U;
55 
56         status = osTimerStart(id1, timerDelay);
57         if (status != osOK) {
58             printf("Failed to start Timer1!\n");
59         }
60     }
61 
62     id2 = osTimerNew(Timer2Callback, osTimerPeriodic, NULL, NULL);
63     if (id2 != NULL) {
64         // Hi3861 1U=10ms,300U=3S
65         timerDelay = 300U;
66 
67         status = osTimerStart(id2, timerDelay);
68         if (status != osOK) {
69             printf("Failed to start Timer2!\n");
70         }
71     }
72 }
73 
74 APP_FEATURE_INIT(TimerExample);
75