1 /*
2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., 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 /**
16 ****************************************************************************************
17 *
18 * @file rtos.c
19 *
20 * @brief Entry point for WiFi stack integration within an RTOS.
21 *
22 ****************************************************************************************
23 */
24 #include "al_rtos.h"
25 #include "dbg.h"
26
27 #if PLF_CONSOLE
28 #include "console_task.h"
29 #endif /* PLF_CONSOLE */
30
31 #if PLF_LETTER_SHELL
32 #include "shell_port.h"
33 #endif /* PLF_LETTER_SHELL */
34
35 #if PLF_ASIO
36 #include "asio.h"
37 #endif /* PLF_ASIO */
38
39 #if PLF_AUDIO
40 #include "app_audio.h"
41 #include "audio_eq.h"
42 #include "audio_drc.h"
43 #endif /* PLF_AUDIO */
44
45 #if PLF_TEST
46 #include "test_main.h"
47 #endif /* PLF_TEST */
48
49 #if PLF_BT_STACK
50 #ifndef CFG_BLE_ONLY
51 #include "bt_task.h"
52 #else
53 #include "ble_task.h"
54 #endif
55 #ifdef CFG_AON
56 #include "cs_bt_aon_sram.h"
57 #endif
58 #endif /* PLF_BT_STACK */
59
60 #if PLF_WIFI_STACK
61 #ifdef CFG_HOSTIF
62 #include "hostif.h"
63 #endif
64 #ifdef CONFIG_RWNX_LWIP
65 #include "porting_net_al.h"
66 #include "wifi_host.h"
67 #include "wifi_host_wpa.h"
68 #ifdef CFG_HOSTIF
69 #include "rwnx_defs.h"
70 struct rwnx_hw hw_env;
71 #endif /* CFG_HOSTIF */
72 #endif /* CONFIG_RWNX_LWIP */
73 #if !defined(CFG_HOSTIF) || defined(CFG_DEVICE_IPC)
74 #include "rwnx_defs.h"
75 struct rwnx_hw hw_env;
76 #endif
77 #endif /* PLF_WIFI_STACK */
78
79 #include "co_main.h"
80
81 #if PLF_DSP
82 #include "dsp_task.h"
83 #endif /* PLF_DSP */
84
85 #if PLF_KEY_MODULE
86 #include "key.h"
87 #endif
88 #if PLF_LED_MODULE
89 #include "led.h"
90 #endif
91 #if PLF_LS_MODULE
92 #include "light_sensor.h"
93 #endif
94
95 #include "sysctrl_api.h"
96 #include "sleep_api.h"
97 #include "cmsis_os2.h"
98
99 extern int fhost_application_smartconfig_init(void);
get_task_cfg(uint8_t task_id)100 rtos_task_cfg_st get_task_cfg(uint8_t task_id)
101 {
102 rtos_task_cfg_st cfg = {0, 0};
103
104 switch (task_id) {
105 case IPC_CNTRL_TASK:
106 cfg.priority = TASK_PRIORITY_WIFI_IPC;
107 cfg.stack_size = TASK_STACK_SIZE_WIFI_IPC;
108 break;
109 case SUPPLICANT_TASK:
110 cfg.priority = TASK_PRIORITY_WIFI_WPA;
111 cfg.stack_size = TASK_STACK_SIZE_WIFI_WPA;
112 break;
113 case CONTROL_TASK:
114 cfg.priority = TASK_PRIORITY_WIFI_CNTRL;
115 cfg.stack_size = TASK_STACK_SIZE_WIFI_CNTRL;
116 break;
117 case APP_FHOST_TX_TASK:
118 cfg.priority = TASK_PRIORITY_WIFI_TX;
119 cfg.stack_size = TASK_STACK_SIZE_WIFI_TX;
120 break;
121 default:
122 break;
123 }
124
125 return cfg;
126 }
127
128 /**
129 * Save user data that declared with PRIVATE_HOST_*(G3USER)
130 */
user_data_save(void)131 __WEAK void user_data_save(void)
132 {
133 // VOID
134 }
135
136 /**
137 * Restore user data that declared with PRIVATE_HOST_*(G3USER)
138 */
user_data_restore(void)139 __WEAK void user_data_restore(void)
140 {
141 // VOID
142 }
143
timer_callback(void * arg)144 void timer_callback(void *arg) {
145 printf("%s: begin\n", __func__);
146 OHOS_SystemInit();
147 }
148
rtos_main(void)149 void rtos_main(void)
150 {
151 dbg("Enter rtos_main ok\r\n");
152 //uart_puts("M\r\n");
153 if(LOS_KernelInit())
154 {
155 dbg("LOS_KernelInit\r\n");
156 }
157 #if (PLF_HW_PXP == 1)
158 dbg("RUNNING IN SIMULATION MODE\r\n");
159 #endif
160
161 #if DBG_MUTEX_ENABLED
162 dbg_rtos_init();
163 #endif
164
165 co_main_init();
166
167 #if PLF_KEY_MODULE
168 key_open();
169 #endif
170
171 #if PLF_LED_MODULE
172 led_init();
173 #endif
174
175 #if PLF_LS_MODULE
176 ls_init();
177 #endif
178
179 #if PLF_WIFI_STACK
180 #if defined(CONFIG_RWNX_LWIP)
181 #ifndef CFG_WIFI_RAM_VER
182 wifi_patch_prepare();
183 #endif
184 rwnx_ipc_init(&hw_env, &ipc_shared_env);
185 #endif /* CONFIG_RWNX_LWIP */
186 #if defined(CFG_DEVICE_IPC)
187 rwnx_ipc_init(&hw_env, &ipc_shared_env);
188 #endif
189 #endif /* PLF_WIFI_STACK */
190
191 #if (PLF_CONSOLE && !(PLF_WIFI_STACK && (defined(CFG_APP_CONSOLEWIFI) || defined(CFG_APP_UARTWIFI))))
192 console_task_init();
193 #endif /* PLF_CONSOLE && !PLF_WIFI_STACK */
194
195 #if PLF_LETTER_SHELL
196 userShellInit();
197 #endif
198
199 #if PLF_AUD_USED
200 #if PLF_ASIO
201 asio_init();
202 #endif
203
204 #if PLF_AUDIO
205 app_audio_open();
206 audio_eq_init();
207 audio_drc_init();
208 #if PLF_CONSOLE
209 audio_eq_cmd_init();
210 audio_drc_cmd_init();
211 #endif
212 #endif
213 #endif
214
215 #if PLF_TEST
216 test_task_init();
217 #endif /* PLF_TEST */
218
219 #if PLF_BT_STACK
220 #if !(defined(CFG_TEST_AF) || defined(CFG_TEST_SBC) || defined(CFG_TEST_AAC) || defined(CFG_TEST_SDCARD_AUDIO) || defined(CFG_TEST_HCI))
221 #ifdef CFG_AON
222 host_aon_interface_init();
223 #endif
224 #ifndef CFG_BLE_ONLY
225 // bt_task_init();
226 #else
227 ble_task_init();
228 #endif
229 #ifdef CFG_AON
230 cpup_ready_set(true);
231 #endif
232 #endif
233 #endif /* PLF_BT_STACK */
234
235 #ifdef CFG_HOSTIF
236 init_host(0);
237 #endif
238 #if PLF_WIFI_STACK
239 #ifdef CONFIG_RWNX_LWIP
240 net_init();
241 // Initialize the FHOST module
242 fhost_init(NULL);
243 #endif /* CONFIG_RWNX_LWIP */
244 #endif /* PLF_WIFI_STACK */
245 // if (pwrctrl_pwrmd_cpusys_sw_record_getf() >= CPU_SYS_POWER_DOWN) {
246 // // restore data
247 // sleep_data_restore();
248 // #if PLF_WIFI_STACK
249 // #ifdef CONFIG_RWNX_LWIP
250 // fhost_data_restore();
251 // lwip_data_restore();
252 // if (wlan_connected) {
253 // fhost_sta_ipc_rxbuf_recover();
254 // }
255 // //wpas_data_restore();
256 // #endif /* CONFIG_RWNX_LWIP */
257 // #endif /* PLF_WIFI_STACK */
258 // // user_data_restore();
259 // sys_wakeup_indicate();
260 // }
261
262 #if PLF_DSP
263 dsp_task_init();
264 #endif
265
266 /*chipsea_ohos start device manager and init system , begin*/
267 init_trace_system();
268 DeviceManagerStart();
269
270 osTimerId_t timerId;
271 unsigned int timerExec = 5000;
272 osStatus_t status;
273 timerId = osTimerNew((osTimerFunc_t)timer_callback, osTimerOnce, &timerExec, NULL );
274 if (timerId != NULL) {
275 status = osTimerStart(timerId, 5000U);
276 if (status != osOK) {
277 printf("Failed to start timer!\n");
278 }
279 } else {
280 printf("Failed to create timer!\n");
281 }
282 #ifdef CONFIG_FS_LITTLEFS
283 //hal_vfs_init();
284 #endif
285 /*chipsea_ohos start device manager and init system , end*/
286
287 // Start the scheduler
288
289 dbg("\r\n start task \r\n");
290 LOS_Start();
291
292
293 // Should never reach here
294 for( ;; );
295 }
296