• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Hunan OpenValley Digital Industry Development 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 <unistd.h>
18 #include "los_compiler.h"
19 #include "los_task.h"
20 #include "los_debug.h"
21 #include "samgr_lite.h"
22 #include "ohos_init.h"
23 #include "ohos_types.h"
24 #include "nvs.h"
25 #include "cmsis_os2.h"
26 
27 #include "hiview_def.h"
28 #include "hiview_output_log.h"
29 
30 #define SYSTEM_INIT_TASK_PRIO (LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO + 1)
31 #define SYSTEM_INIT_TASK_STACK_SIZE (LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE * 2)
32 #define DEALY_10_TICKS 10
33 #define MIN_STACK_SIZE 2048
34 
35 void* __attribute__((weak)) OHOS_APP_FUNC_ENTRY = NULL;
36 void* __attribute__((weak)) BEFORE_OHOS_RUN_FUNC_ENTRY = NULL;
37 
DeviceManagerStart(void)38 int __attribute__((weak)) DeviceManagerStart(void)
39 {
40     return 0;
41 }
42 
DeviceWifiStart(void)43 int __attribute__((weak)) DeviceWifiStart(void)
44 {
45     return 0;
46 }
47 
ohos_app_main()48 void ohos_app_main()
49 {
50     LOS_TaskDelay(DEALY_10_TICKS);
51     if (OHOS_APP_FUNC_ENTRY) {
52         printf("\n\033[1;32m<--------------- OHOS Application Start Here --------------->\033[0m\n");
53         ((void (*)(void))OHOS_APP_FUNC_ENTRY)();
54     } else {
55         printf("\n\033[1;31m<--------------- OHOS_APP_FUNC_ENTRY is NULL --------------->\033[0m\n");
56     }
57     while (1) {
58         LOS_TaskDelay(DEALY_10_TICKS * DEALY_10_TICKS);
59         IoTWatchDogKick();
60     }
61 }
62 
before_ohos_run()63 void before_ohos_run()
64 {
65     if (BEFORE_OHOS_RUN_FUNC_ENTRY) {
66         ((void (*)(void))BEFORE_OHOS_RUN_FUNC_ENTRY)();
67     }
68 }
69 
70 #ifdef CONFIG_BUILD_TYPE_TEST
71 
lwip_ifconfig(INT32 argc,const CHAR ** argv)72 __attribute__((weak)) UINT32 lwip_ifconfig(INT32 argc, const CHAR** argv)
73 {
74     return 0;
75 }
76 
OsShellPing(INT32 argc,const CHAR ** argv)77 __attribute__((weak)) UINT32 OsShellPing(INT32 argc, const CHAR** argv)
78 {
79     return 0;
80 }
81 
TaskCreateExtensionHook(VOID * taskCB)82 void TaskCreateExtensionHook(VOID* taskCB)
83 {
84     LosTaskCB* p = (LosTaskCB*)taskCB;
85     UINTPTR topOfStack;
86     if (!p) {
87         return;
88     }
89     if ((p->stackSize <= 0) || (p->stackSize >= MIN_STACK_SIZE)) {
90         return;
91     }
92     p->stackSize = MIN_STACK_SIZE;
93     topOfStack = (UINTPTR)LOS_MemAllocAlign(OS_TASK_STACK_ADDR, p->stackSize,
94         LOSCFG_STACK_POINT_ALIGN_SIZE);
95     p->stackPointer = ArchTskStackInit(p->taskID, p->stackSize, (VOID*)topOfStack);
96     LOS_MemFree(OS_TASK_STACK_ADDR, (void*)p->topOfStack);
97     p->topOfStack = topOfStack;
98 }
99 #else
TaskCreateExtensionHook(VOID * taskCB)100 void TaskCreateExtensionHook(VOID* taskCB)
101 {
102     (void)taskCB;
103 }
104 #endif
105 
OHOS_SystemInitEntry(VOID)106 VOID* OHOS_SystemInitEntry(VOID)
107 {
108     int err;
109     printf("Code Build Time:%s %s\n", __DATE__, __TIME__);
110     before_ohos_run();
111     esp_err_t ret = nvs_flash_init();
112     if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
113         nvs_flash_erase();
114         ret = nvs_flash_init();
115     }
116     DeviceWifiStart();
117     init_trace_system();
118     err = DeviceManagerStart();
119     if (err) {
120         printf("DeviceManagerStart.ret=0x%X\n", err);
121     }
122     OHOS_SystemInit();
123     ohos_app_main();
124     return NULL;
125 }
126 
app_main(void)127 void app_main(void)
128 {
129     UINT32 ret;
130     UINT32 taskID;
131     TSK_INIT_PARAM_S stTask = { 0 };
132     stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)OHOS_SystemInitEntry;
133     stTask.uwStackSize = SYSTEM_INIT_TASK_STACK_SIZE;
134     stTask.pcName = "OHOS";
135     stTask.usTaskPrio = SYSTEM_INIT_TASK_PRIO;
136     ret = LOS_TaskCreate(&taskID, &stTask);
137     if (ret != LOS_OK) {
138         printf("OHOS_SystemInitEntry create failed!\n");
139     }
140     LOS_Start();
141 }