1 #include "stdio.h"
2 #include "aos/init.h"
3 #include "board.h"
4 #include <k_api.h>
5 #include "k_config.h"
6 #include <stdio.h>
7 #include <stdlib.h>
8 //#include "aos/yloop.h"
9 #ifdef AOS_COMP_YUNIT
10 #include "yts.h"
11 #endif
12 #include "ota_port.h"
13 
14 //#include "apps.h"
15 #include "hal_trace.h"
16 #include "led.h"
17 
18 /*
19  * If enable this macro for local test, we don't use wifi service to trigger connection,
20  * remember to mask -DALIOS_WIFI_SERVICE and set -DLWIP_SUPPORT=1 in SDK.
21  */
22 #if LWIP_SUPPORT
23 #define ALIOS_BES_APP
24 #endif
25 
26 #define BES_SDK 0
27 #define BES_WIFI_ONLY 1
28 #define BES_WIFI_BT 2
29 #define BES_WIFI_BT_MINI 3 // cut off nouse tasks
30 
31 /*
32  * main task stask size(byte)
33 */
34 #define OS_MAIN_TASK_STACK (32*1024)
35 #define OS_MAIN_TASK_PRI 32
36 
37 /*  For user config
38     kinit.argc = 0;
39     kinit.argv = NULL;
40     kinit.cli_enable = 0;
41 */
42 static kinit_t kinit = {0, NULL, 1};
43 static ktask_t *g_main_task;
44 static ktask_t *g_speech_task = NULL;
45 static ktask_t *g_dsp_task = NULL;
46 uint8_t mesh_open_enalbe = 1;
47 uint32_t g_wifi_factory_test = 0;
48 
49 extern void soc_peripheral_init();
50 extern void aos_init_done_hook(void);
51 extern void ble_nosignal_uart_bridge_loop(void);
52 extern uint8_t ble_nosignal_start_flag;
53 extern int32_t tg_bt_hal_vendor_hci_set_epta(int32_t state);
54 extern uint8_t epta_hci_set_flag;
55 extern void a7_heartbeat_reboot_enable(int enable);
56 extern uint32_t __aos_lastword_start[];
57 
58 #ifndef AOS_BINS
59 extern int application_start(int argc, char **argv);
60 #endif
61 
62 #ifdef ENABLE_LATTICE
63 #include "ali_led.h"
64 #include "ali_sensor.h"
65 void ali_lattice_cli_init();
66 #endif
67 
68 #ifdef CONFIG_ALI_DISPLAY
69 void disp_init(void);
70 #endif
71 
haas_board_init(void)72 static void haas_board_init(void)
73 {
74 #if CONFIG_A7_DSP_ENABLE
75     int init = BES_WIFI_BT;
76 #else
77     int init = BES_WIFI_BT_MINI;
78 #endif
79 	int release_version = 1;
80     int ret = 0;
81 
82 #if 1//def CONFIG_GENIE_DEBUG // disable watchdog
83 	release_version = 0;
84 #endif
85 
86     platform_init_step0(release_version);
87     printf("%s platform_init_step0 done\n", __FUNCTION__);
88 #if CONFIG_A7_DSP_ENABLE
89     /*disable it, since output stereo as default*/
90     // analog_aud_codec_set_dev(1); // haas use spk-L
91 #endif
92     platform_init_step1(init);
93     printf("%s platform_init_step1 done\n", __FUNCTION__);
94 
95     ASSERT(DEBUG_LASTWORD_RAM_ADDR == (uint32_t)__aos_lastword_start,
96         "DEBUG_LASTWORD_RAM_ADDR(0x%x) is not equel to __aos_lastword_start(0x%x)",
97         DEBUG_LASTWORD_RAM_ADDR, (uint32_t)__aos_lastword_start)
98 
99     led_switch(1, LED_ON);
100     led_switch(2, LED_ON);
101     led_switch(3, LED_ON);
102     led_switch(4, LED_ON);
103     led_switch(5, LED_ON);
104 
105 #if CONFIG_A7_DSP_ENABLE
106 #ifndef CONFIG_GENIE_DEBUG
107     a7_heartbeat_reboot_enable(1);
108 #endif
109 #endif
110 }
111 
a7_dsp_init(void)112 static void a7_dsp_init(void)
113 {
114     if (!app_enter_factory_wifi_test()) {
115         printf("now a7_dsp_boot\n");
116         a7_dsp_boot();
117     } else {
118         printf("app_enter_factory_wifi_test, no a7_dsp_boot\n");
119     }
120 }
121 
factory_rf_test(void)122 static void factory_rf_test(void)
123 {
124     kinit_t kinit = {0, NULL, 1};
125     printf("wait factory test now...\n");
126     board_stduart_init();
127     aos_components_init(&kinit);
128 #ifdef AOS_VENDOR_CLI
129     vendor_cli_register_init();
130 #endif
131     while(1) {
132         aos_msleep(1000);
133     }
134 }
135 
aos_main_task_entry(void)136 static void aos_main_task_entry(void)
137 {
138     int ret = 0;
139 #ifdef AOS_COMP_YUNIT
140     char *parm[4] = {"yts", "kv", "ramfs", "vfs"};
141 #endif
142 
143     /* user code start */
144     soc_peripheral_init();
145 
146     if (app_enter_factory_wifi_test()) {
147         printf("********************************************************************\n");
148         printf("Begin wifi factory test ...\n");
149         printf("********************************************************************\n");
150         g_wifi_factory_test = 1;
151     }
152 
153     ch395_device_dereset();
154 #ifdef AOS_COMP_CPLUSPLUS
155     cpp_init();
156 #endif
157 
158 #ifdef AOS_COMP_YUNIT
159     yts_run(sizeof(parm) / sizeof(parm[0]), &parm[0]);
160 #endif
161 
162 #ifdef ENABLE_LATTICE
163     ali_lattice_cli_init();
164 #endif
165 
166 #ifdef CONFIG_ALI_DISPLAY
167     disp_init();
168 #endif
169 
170     aos_init_done_hook();
171 
172     ret = bwifi_init();
173     if (ret) {
174         printf("bwifi init fail\n");
175     }
176 
177     ret = eth_lwip_tcpip_init();
178     if (ret) {
179         printf("haas100 ethernet init fail\n");
180     }
181 
182 #if (RHINO_CONFIG_HW_COUNT > 0)
183     soc_hw_timer_init();
184 #endif
185 
186 #ifndef AOS_BINS
187     if (app_enter_factory_wifi_test() == false) {
188         aos_maintask();
189 	} else {
190         factory_rf_test();
191     }
192 #endif
193 
194 }
195 
main(void)196 int main(void)
197 {
198     int times = 0;
199     /*irq initialized is approved here.But irq triggering is forbidden, which will enter CPU scheduling.
200     Put them in sys_init which will be called after aos_start.
201     Irq for task schedule should be enabled here, such as PendSV for cortex-M4.
202     */
203     haas_board_init();   //including aos_heap_set();  flash_partition_init();
204 
205     /*kernel init, malloc can use after this!*/
206     //krhino_init();
207 
208     /*main task to run */
209     krhino_task_dyn_create(&g_main_task, "main_task", 0, OS_MAIN_TASK_PRI, 0, OS_MAIN_TASK_STACK, (task_entry_t)aos_main_task_entry, 1);
210 
211     /*kernel start schedule!*/
212     //krhino_start();
213 
214     while (1) {
215         krhino_task_sleep(100);
216 
217         if (times == 10) {
218             led_switch(1, LED_OFF);
219             led_switch(2, LED_OFF);
220             led_switch(3, LED_OFF);
221             led_switch(4, LED_OFF);
222             led_switch(5, LED_OFF);
223             times ++;
224         } else {
225             if(times < 11) {
226                 times ++;
227             }
228         }
229 #ifdef AOS_VENDOR_CLI
230         /*only work when enter ble nosignal*/
231         if(ble_nosignal_start_flag)
232         {
233             ble_nosignal_uart_bridge_loop();
234         }
235 #endif
236         if(epta_hci_set_flag)
237         {
238             printf("%d epta_hci_set_flag \n", epta_hci_set_flag);
239             tg_bt_hal_vendor_hci_set_epta(epta_hci_set_flag);
240             epta_hci_set_flag = 0;
241         }
242     }
243 
244     /*never run here*/
245     return 0;
246 }
247 
248