1 /*
2 * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., 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 #include <stdio.h>
17 #include <stdlib.h>
18 #include "board.h"
19 #include "duet_cm4.h"
20 #include "duet_pinmux.h"
21 #include "duet_uart.h"
22 #include "printf_uart.h"
23 #if 0
24 #include "los_config.h"
25 #include "los_debug.h"
26 #include "los_interrupt.h"
27 #include "los_task.h"
28 #include "los_tick.h"
29 #else
30 #include "cmsis_os.h"
31 #include "lega_at_api.h"
32 #endif
33 #include "los_exc_info.h"
34 #include "devmgr_service_start.h"
35
36 /*
37 main task stask size(byte)
38 */
39 #define OS_MAIN_TASK_STACK (4096)
40
41 osThreadAttr_t g_main_task = {"main_task", 0, NULL, 0, NULL, OS_MAIN_TASK_STACK, 15, 0, 0};
42
43 #ifdef CFG_HARMONY_TESTS
44 osThreadAttr_t harmony_test_task = {"test_task", 0, NULL, 0, NULL, OS_MAIN_TASK_STACK, 15, 0, 0};
45 #endif
46
47 static int sys_init_done = 0;
48 extern void HalPendSV(void);
49 extern void os_post_init_hook(void);
PendSV_Handler(void)50 void PendSV_Handler(void)
51 {
52 HalPendSV();
53 }
54
sys_init(void)55 static void sys_init(void)
56 {
57 os_post_init_hook();
58
59 #ifdef MS_RELEASE_DOMAIN
60 // LOG("log_disable");
61 lega_log_disable();
62 #endif
63
64 duet_flash_kv_init();
65
66 board_after_init();
67 // debug_memory_access_err_check(0x0, 0x10000, MPU_AP_NA_NA);
68
69 #ifdef SYSTEM_COREDUMP
70 // coredump_command_register(0, NULL);
71 #endif
72
73 #ifdef CFG_DUAL_AP
74 comm_wifi_command_register(0, NULL);
75 #endif
76
77 // lega_at_init(AT_TASK_NAME,AT_TASK_PRIORITY,AT_TASK_STACK_SIZE);
78 // lega_at_cmd_register_all();
79 lega_at_user_cmd_register();
80
81 #ifdef BLE_APP_AT_CMD
82 atcmdplus_ble_register();
83 #endif
84
85 #ifdef CFG_MRFOTA_TEST
86 // extern void lega_rfota_wifi_test_at_init(void);
87 // lega_rfota_wifi_test_at_init();
88 // extern void lega_rfota_ble_test_at_init(void);
89 // lega_rfota_ble_test_at_init();
90 #endif
91 DeviceManagerStart();
92 printf("sys_init running...\n");
93 sys_init_done = 1;
94 }
95
96 #ifdef CFG_HARMONY_TESTS
harmony_test(void)97 static void harmony_test(void)
98 {
99 while (sys_init_done == 0) {
100 osDelay(500);
101 }
102 osDelay(500);
103 extern void OHOS_SystemInit(void);
104 OHOS_SystemInit();
105 }
106 #endif
107
main(void)108 int main(void)
109 {
110 osStatus_t ret;
111 osThreadId_t threadId;
112
113 board_before_init();
114
115 board_init();
116
117 NVIC_deinit();
118 ret = osKernelInitialize();
119
120 if (ret == osOK) {
121 threadId = osThreadNew((osThreadFunc_t)sys_init, NULL, &g_main_task);
122 #ifdef CFG_HARMONY_TESTS
123 osThreadNew((osThreadFunc_t)harmony_test, NULL, &harmony_test_task);
124 #endif
125 if (threadId != NULL) {
126 osKernelStart();
127 }
128 }
129
130 while (1);
131 return 0;
132 }
133