1 /*
2 * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3 */
4
5 #include "amp_platform.h"
6 #include "amp_defines.h"
7 #include "amp_config.h"
8 #include "aos_system.h"
9 #include "aos_network.h"
10 #ifdef AMP_KV_ENABLE
11 #include "aos/kv.h"
12 #endif
13 #include "aos_fs.h"
14 #include "amp_boot_recovery.h"
15 #include "amp_boot.h"
16
17 #ifdef JSE_ADVANCED_ADDON_UI
18 #include "render_public.h"
19 #include "../../../../littlevgl/lv_conf.h"
20 #include "view_model.h"
21 extern volatile int app_run_flag;
22
23 volatile int g_ui_run_flag = 1;
24 #endif
25
26 #define MOD_STR "AMP_MAIN"
27
28 extern void jsengine_main(void);
29 extern int aos_network_status_registercb(void (*cb)(int status, void *), void *arg);
30
31 #ifdef AMP_NETWORK_ENABLE
network_func(void * argv)32 void network_func(void *argv)
33 {
34 aos_network_status_registercb(NULL, NULL);
35
36 while(!aos_get_network_status()) {
37 aos_msleep(1000);
38 }
39 app_management_center_init();
40 aos_task_exit(0);
41
42 return;
43 }
44 #endif
45
jsengine_func(void * argv)46 void jsengine_func(void *argv)
47 {
48 jsengine_main();
49
50 aos_task_exit(0);
51
52 return;
53 }
54
amp_main(void)55 int amp_main(void)
56 {
57 int ret = -1;
58
59 /* add memory init */
60 amp_memory_init();
61
62 /* system init */
63 aos_system_init();
64
65 /* printf amp system info */
66 aos_printf("=================amp info=================\r\n");
67 aos_printf("amp version: amp-v%s-%s\r\n", AMP_VERSION_NUMBER, AMP_GIT_COMMIT);
68 aos_printf("amp build time: %s, %s\r\n", __DATE__, __TIME__);
69 aos_printf("amp device name: %s\r\n", aos_get_device_name());
70 aos_printf("==========================================\r\n");
71
72 /* system init */
73 aos_system_init();
74
75 /* file system init */
76 aos_fs_init();
77
78 /* ulog module init */
79 ulog_init();
80
81 /* set ulog level, make all the level of log is not lower than this value could be logged */
82 aos_set_log_level(AOS_LL_ERROR);
83
84 #ifndef HAASUI_AMP_BUILD
85 /* amp recovery service init */
86 amp_boot_main();
87
88 aos_task_t jsengine_task;
89
90 #ifdef AMP_NETWORK_ENABLE
91 aos_task_t network_task;
92 #endif
93
94 #ifdef AMP_KV_ENABLE
95 ret = kv_init();
96 if (ret != 0) {
97 amp_warn(MOD_STR, "kv init failed!");
98 }
99 #endif
100
101 /* amp main start */
102 ret = aos_task_new_ext(&jsengine_task, "amp_jsengine", jsengine_func, NULL, 1024 * 8, AOS_DEFAULT_APP_PRI);
103 if (ret != 0) {
104 amp_debug(MOD_STR, "jsengine task creat failed!");
105 return ret;
106 }
107
108 #ifdef AMP_NETWORK_ENABLE
109 /* network start */
110 ret = aos_task_new_ext(&network_task, "amp_network", network_func, NULL, 1024 * 4, AOS_DEFAULT_APP_PRI);
111 if (ret != 0) {
112 amp_debug(MOD_STR, "network task creat failed!");
113 return ret;
114 }
115 #endif
116
117 #ifdef JSE_ADVANCED_ADDON_UI
118 while(!app_run_flag){
119 aos_msleep(50);
120 }
121
122 if (g_ui_run_flag) {
123 amp_view_model_init();
124 render_init();
125 }
126 #endif
127 while(1) {
128 aos_msleep(5000);
129 }
130
131 #else /* HAASUI_AMP_BUILD defined */
132
133 ret = kv_init();
134 if (ret != 0) {
135 amp_warn(MOD_STR, "kv init failed!");
136 }
137
138 jsengine_main();
139 #endif
140
141 return 0;
142 }
143
amp_sysdep_init(void)144 int amp_sysdep_init(void)
145 {
146 return amp_main();
147 }
148
149