• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
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 <components/log.h>
16 #include <modules/wifi.h>
17 #include <components/netif.h>
18 #include <components/event.h>
19 #include <driver/uart.h>
20 #include <string.h>
21 #include "boot.h"
22 #if CONFIG_BLE
23 #include "modules/ble.h"
24 #include "ble_api_5_x.h"
25 #include "legacy_include/bluetooth_legacy_include.h"
26 #endif
27 
28 #if ((CONFIG_FREERTOS) || (CONFIG_LITEOS_M) || (CONFIG_LITEOS_M_V3) || (CONFIG_LITEOS_M_MST)) && (CONFIG_CLI)
29 #include "bk_api_cli.h"
30 #endif
31 
32 #define TAG "app_init"
33 
34 #ifdef CONFIG_VND_CAL
35 #include "vnd_cal.h"
36 #endif
37 
38 #ifdef CONFIG_MEDIA
39 #include "media_core.h"
40 #endif
41 
42 #include "sdk_version.h"
43 
44 void rtos_user_app_launch_over(void);
45 
46 volatile const uint8_t build_version[] = __DATE__ " " __TIME__;
47 
app_wifi_init(void)48 static int app_wifi_init(void)
49 {
50 #if (CONFIG_WIFI_ENABLE)
51 	wifi_init_config_t wifi_config = WIFI_DEFAULT_INIT_CONFIG();
52 	BK_LOG_ON_ERR(bk_event_init());
53 	BK_LOG_ON_ERR(bk_netif_init());
54 	BK_LOG_ON_ERR(bk_wifi_init(&wifi_config));
55 #endif
56 	return BK_OK;
57 }
58 
app_ble_init(void)59 static int app_ble_init(void)
60 {
61 #if CONFIG_BLE
62     BK_LOG_ON_ERR(bk_ble_init_ext(NULL));
63 #endif
64 	return BK_OK;
65 }
66 
app_bt_init(void)67 static int app_bt_init(void)
68 {
69 #if (CONFIG_SOC_BK7271)
70 #if (CONFIG_BT)
71 	BK_LOGI(TAG, "BT active\r\n");
72 #if 0//TODO
73 	if (!ate_is_enabled())
74 		bt_activate(NULL);
75 #endif
76 #endif
77 #endif
78 	return BK_OK;
79 }
80 
app_key_init(void)81 static int app_key_init(void)
82 {
83 #if CONFIG_BUTTON
84 	key_initialization();
85 #endif
86 	return BK_OK;
87 }
88 
app_mp3_player_init(void)89 static int app_mp3_player_init(void)
90 {
91 #if (CONFIG_MP3PLAYER)
92 	key_init();
93 	media_thread_init();
94 #endif
95 	return BK_OK;
96 }
97 
app_sdio_init(void)98 int app_sdio_init(void)
99 {
100 #if (defined CONFIG_SDIO && defined CONFIG_SDIO_V1P0)
101 	BK_LOGI(TAG, "sdio intf init\r\n");
102 	sdio_intf_init();
103 #endif
104 
105 #if CONFIG_SDIO_TRANS
106 	BK_LOGI(TAG, "sdio trans init\r\n");
107 	sdio_trans_init();
108 #endif
109 	return BK_OK;
110 }
111 
app_usb_init(void)112 int app_usb_init(void)
113 {
114 #if CONFIG_USB
115 	BK_LOGI(TAG, "fusb init\r\n");
116 #if 0//TODO
117 	if (!ate_is_enabled())
118 		fusb_init();
119 #endif
120 #endif
121 	return BK_OK;
122 }
123 
app_cli_init(void)124 static int app_cli_init(void)
125 {
126 #if ((CONFIG_FREERTOS) || (CONFIG_LITEOS_M) || (CONFIG_LITEOS_M_V3) || (CONFIG_LITEOS_M_MST)) && (CONFIG_CLI)
127 #if !CONFIG_FULLY_HOSTED
128 	bk_cli_init();
129 #endif
130 #endif
131 	return BK_OK;
132 }
133 
app_usb_charge_init(void)134 static int app_usb_charge_init(void)
135 {
136 #if (CONFIG_SOC_BK7251)
137 #if CONFIG_USB_CHARGE
138 	extern void usb_plug_func_open(void);
139 	usb_plug_func_open();
140 #endif
141 #endif
142 	return BK_OK;
143 }
144 
app_uart_debug_init_todo(void)145 static int app_uart_debug_init_todo(void)
146 {
147 #if CONFIG_UART_DEBUG
148 #ifndef KEIL_SIMULATOR
149 	BK_LOGI(TAG, "uart debug init\r\n");
150 	uart_debug_init();
151 #endif
152 #endif
153 	return BK_OK;
154 }
legacy_init1(void)155 int legacy_init1(void)
156 {
157 	BK_LOGI(TAG, "bk378 test init!!!!\r\n");
158 	app_sdio_init();
159 	app_key_init();
160 	app_usb_charge_init();
161 	app_wifi_init();
162 	app_bt_init();
163 	app_ble_init();
164 	app_mp3_player_init();
165 	app_uart_debug_init_todo();
166 	app_cli_init();
167 
168 #if (CONFIG_FREERTOS)
169 #if CONFIG_SEMI_HOSTED
170 	semi_host_init();
171 #endif
172 #endif
173 
174 #if CONFIG_UDISK_MP3
175 	um_init();
176 #endif
177 	return 0;
178 }
179 
180 #if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT
181 extern void demo_wifi_fast_connect(void);
182 #endif
legacy_init(void)183 int legacy_init(void)
184 {
185 	BK_LOGI(TAG, "armino app init: %s\n", build_version);
186     BK_LOGI(TAG, "ARMINO Version: %s\n", ARMINO_TAG_VERSION);
187 
188 #ifdef LIB_HASH
189     #define HASH_VERSION(soc) soc##_HASH_VERSION
190     #define HASH_VERSION_STR(soc) #soc"_HASH_VERSION"
191     #define PRINTF(soc) BK_LOGI(TAG, HASH_VERSION_STR(soc)" IS : %s\n", HASH_VERSION(soc));
192 	#define MEMCMP(soc, lib_hash) memcmp(lib_hash, HASH_VERSION(soc), sizeof(lib_hash))
193     BK_LOGI(TAG, "LIB_HASH: %s\n", LIB_HASH);
194     PRINTF(ARMINO_SOC);
195     if(MEMCMP(ARMINO_SOC, LIB_HASH))
196 	{
197         BK_LOGI(TAG, "The current version is not the release version\n");
198 	}
199 #endif
200 
201 #ifdef APP_VERSION
202 	BK_LOGI(TAG, "APP Version: %s\n", APP_VERSION);
203 #endif
204 
205 
206 #ifdef CONFIG_VND_CAL
207 	vnd_cal_overlay();
208 #endif
209 
210 #if (CONFIG_SOC_BK7256XX && !CONFIG_SLAVE_CORE)
211 
212 	#if CONFIG_SAVE_BOOT_TIME_POINT
213 	save_mtime_point(CPU_START_WIFI_INIT_TIME);
214 	#endif
215 	app_wifi_init();
216 	#if CONFIG_SAVE_BOOT_TIME_POINT
217 	save_mtime_point(CPU_FINISH_WIFI_INIT_TIME);
218 	#endif
219 
220 	rtos_user_app_launch_over();
221 
222 #ifdef CONFIG_MEDIA
223 	media_major_init();
224 #endif
225 
226 
227 #if (CONFIG_BLUETOOTH)
228 	app_ble_init();
229 #endif
230 
231 #elif (CONFIG_SLAVE_CORE)
232 
233 #else
234 	app_sdio_init();
235 	app_key_init();
236 	app_usb_charge_init();
237 	app_wifi_init();
238 #if (CONFIG_BLUETOOTH)
239 	app_bt_init();
240 	app_ble_init();
241 #endif
242 	app_mp3_player_init();
243 	app_uart_debug_init_todo();
244 #endif
245 
246 	app_cli_init();
247 
248 #if defined(CONFIG_MEDIA) && defined(CONFIG_SLAVE_CORE)
249 	media_minor_init();
250 #endif
251 
252 #if (CONFIG_FREERTOS)
253 #if CONFIG_SEMI_HOSTED
254 	semi_host_init();
255 #endif
256 #endif
257 
258 #if CONFIG_UDISK_MP3
259 	um_init();
260 #endif
261 #if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT
262 	demo_wifi_fast_connect();
263 #endif
264 	return 0;
265 }
266