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 "E53_IS1.h"
21 #include "cmsis_os2.h"
22 #include "ohos_init.h"
23
24 #define TASK_STACK_SIZE (1024 * 8)
25 #define TASK_PRIO 25
26 #define TASK_DELAY_3S 300
27 #define FLAGS_MSK1 0x00000001U
28
29 osEventFlagsId_t g_eventFlagsId;
30
BeepAlarm(char * arg)31 static void BeepAlarm(char *arg)
32 {
33 (void)arg;
34 osEventFlagsSet(g_eventFlagsId, FLAGS_MSK1);
35 }
36
ExampleTask(void)37 static void ExampleTask(void)
38 {
39 int ret;
40 E53IS1Init();
41 ret = E53IS1ReadData(BeepAlarm);
42 if (ret != 0) {
43 printf("E53_IS1 Read Data failed!\r\n");
44 return;
45 }
46 while (1) {
47 osEventFlagsWait(g_eventFlagsId, FLAGS_MSK1, osFlagsWaitAny, osWaitForever);
48 BeepStatusSet(ON);
49 osDelay(TASK_DELAY_3S);
50 BeepStatusSet(OFF);
51 }
52 }
53
ExampleEntry(void)54 static void ExampleEntry(void)
55 {
56 g_eventFlagsId = osEventFlagsNew(NULL);
57 if (g_eventFlagsId == NULL) {
58 printf("Failed to create EventFlags!\n");
59 }
60 osThreadAttr_t attr;
61
62 attr.name = "ExampleTask";
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_SIZE;
68 attr.priority = TASK_PRIO;
69
70 if (osThreadNew((osThreadFunc_t)ExampleTask, NULL, &attr) == NULL) {
71 printf("Failed to create Example_Task!\n");
72 }
73 }
74
75 APP_FEATURE_INIT(ExampleEntry);