• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
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 <unistd.h>
18 #include "ohos_init.h"
19 #include "cmsis_os2.h"
20 #include "iot_watchdog.h"
21 #include "app_demo_multi_sample.h"
22 
23 #define TASK_STACK  (1024 * 4)
24 #define INTERRUPT_TASK_PRIO (26)
25 #define TRAFFIC_TASK_PRIO   (25)
KeyInterruptScan(const char * arg)26 void KeyInterruptScan(const char *arg)
27 {
28     (void)arg;
29     AppMultiSampleDemo();
30 }
31 
TrafficLightDemo(const char * arg)32 void TrafficLightDemo(const char *arg)
33 {
34     printf("traffic light open ok\r\n");
35     TrafficLightFunc();
36 }
37 
InterruptTask(void)38 static void InterruptTask(void)
39 {
40     osThreadAttr_t attr;
41 
42     attr.name = "Interrupt";
43     attr.attr_bits = 0U;
44     attr.cb_mem = NULL;
45     attr.cb_size = 0U;
46     attr.stack_mem = NULL;
47     attr.stack_size = TASK_STACK;
48     attr.priority = INTERRUPT_TASK_PRIO;
49 
50     if (osThreadNew((osThreadFunc_t)KeyInterruptScan, NULL, &attr) == NULL) {
51         printf("[TrafficLight] Failed to create TrafficLightDemo!\n");
52     }
53 }
54 
55 SYS_RUN(InterruptTask);
56 
StartTask(void)57 static void StartTask(void)
58 {
59     osThreadAttr_t attr;
60     IoTWatchDogDisable();
61 
62     attr.name = "TrafficLightDemo";
63     attr.attr_bits = 0U;
64     attr.cb_mem = NULL;
65     attr.cb_size = 0U;
66     attr.stack_mem = NULL;
67     attr.stack_size = TASK_STACK;
68     attr.priority = osPriorityNormal;
69 
70     if (osThreadNew((osThreadFunc_t)TrafficLightDemo, NULL, &attr) == NULL) {
71         printf("[TrafficLight] Failed to create TrafficLightDemo!\n");
72     }
73 }
74 
75 SYS_RUN(StartTask);
76