1 /*
2 * Copyright (c) 2022 Talkweb 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 "ohos_run.h"
21 #include "cmsis_os2.h"
22
23 unsigned int timer1Exec = 1, timer2Exec = 100;
24
OS_Timer1_Callback(void * arg)25 void OS_Timer1_Callback(void *arg)
26 {
27 printf("This is Niobe407 Timer1_Callback:%u!\r\n", *(unsigned int*)arg);
28 }
29
OS_Timer2_Callback(void * arg)30 void OS_Timer2_Callback(void *arg)
31 {
32 printf("This is Niobe407 Timer2_Callback:%u!\r\n", *(unsigned int*)arg);
33 }
34
OS_Timer_example(void)35 static void OS_Timer_example(void)
36 {
37 osTimerId_t timerId1, timerId2;
38 unsigned int delay;
39 osStatus_t status;
40
41 timer1Exec = 1U;
42 timerId1 = osTimerNew((osTimerFunc_t)OS_Timer1_Callback, osTimerPeriodic, &timer1Exec, NULL);
43 if (timerId1 != NULL) {
44 delay = 100U;
45 status = osTimerStart(timerId1, delay);
46 if (status != osOK) {
47 printf("Failed to start timer1!\n");
48 }
49 }
50
51 timer2Exec = 100U;
52 timerId2 = osTimerNew((osTimerFunc_t)OS_Timer2_Callback, osTimerPeriodic, &timer2Exec, NULL);
53 if (timerId2 != NULL) {
54 delay = 300U;
55 status = osTimerStart(timerId2, delay);
56 if (status != osOK) {
57 printf("Failed to start timer2!\n");
58 }
59 }
60 }
61
62 OHOS_APP_RUN(OS_Timer_example);
63