• 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 #include <stdio.h>
16 #include <stdint.h>
17 #include <string.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <fcntl.h>
21 #include <unistd.h>
22 
23 #include "los_tick.h"
24 #include "los_task.h"
25 #include "los_config.h"
26 #include "los_interrupt.h"
27 #include "los_debug.h"
28 #include "los_compiler.h"
29 #include "los_arch_interrupt.h"
30 #include "los_task.h"
31 
32 #include "lz_hardware.h"
33 #include "uart_debug.h"
34 #include "config_network.h"
35 
36 #define MAIN_TAG                    "MAIN"
37 
38 #define IOTPROCESS_TASK_STACKSIZE   0x1000
39 #define IOTPROCESS_TASK_PRIO        6
40 #define IOTPROCESS_TASK_NAME        "IotProcess"
41 
42 #define MASKLED_ON                  LZGPIO_LEVEL_HIGH
43 #define MASKLED_OFF                 LZGPIO_LEVEL_LOW
44 
45 void OHOS_SystemInit(void);
46 
IotProcess(void * arg)47 static void IotProcess(void *arg)
48 {
49     static const unsigned int SLEEP_MAX_SECOND = 5;
50     static const unsigned int SECOND_TO_MSECOND = 1000;
51 
52     while (1) {
53         printf("%s: sleep %d sec!\n", __func__, SLEEP_MAX_SECOND);
54 
55         LOS_Msleep(SLEEP_MAX_SECOND * SECOND_TO_MSECOND);
56     }
57 }
58 
IotInit(void)59 static void IotInit(void)
60 {
61     UINT32 uwRet;
62     UINT32 taskID;
63     TSK_INIT_PARAM_S stTask = {0};
64 
65     stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)IotProcess;
66     stTask.uwStackSize = IOTPROCESS_TASK_STACKSIZE;
67     stTask.pcName = IOTPROCESS_TASK_NAME;
68     stTask.uwArg = (UINT32)(0);
69     stTask.usTaskPrio = IOTPROCESS_TASK_PRIO;
70     uwRet = LOS_TaskCreate(&taskID, &stTask);
71     if (uwRet != LOS_OK) {
72         LZ_HARDWARE_LOGD(MAIN_TAG, "MainBoot task create failed!!!");
73     }
74 }
75 
Main(void)76 int Main(void)
77 {
78     UINT32 ret;
79 
80     HalInit();
81 
82     LZ_HARDWARE_LOGD(MAIN_TAG, "%s: OpenHarmony enter...", __func__);
83 
84     ret = LOS_KernelInit();
85     if (ret == LOS_OK) {
86         OHOS_SystemInit();
87         DeviceManagerStart(); // HDF Drivers Init
88         IotInit();
89         LZ_HARDWARE_LOGD(MAIN_TAG, "%s: OpenHarmony start schedule...", __func__);
90         LOS_Start();
91     }
92 
93     while (1) {
94         __asm volatile("wfi");
95     }
96 
97     return 0;
98 }
99