1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 
5 #include "aos/init.h"
6 #include "board.h"
7 #include <aos/kernel.h>
8 #include <k_api.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include "build_version.h"
12 
13 #ifndef AOS_BINS
14 extern int application_start(int argc, char *argv[]);
15 #endif
16 
17 /*
18 If board have no component for example board_xx_init, it indicates that this app
19 does not support this board. Set the correspondence in file
20 platform\board\aaboard_demo\ucube.py.
21 */
22 extern void board_tick_init(void);
23 extern void board_stduart_init(void);
24 extern void board_detect();
25 extern void board_dma_init(void);
26 extern void board_gpio_init(void);
27 extern void board_kinit_init(kinit_t *init_args);
28 
29 /*  For user config
30     kinit.argc = 0;
31     kinit.argv = NULL;
32     kinit.cli_enable = 1;
33 */
34 static kinit_t kinit = {0, NULL, 1};
35 
36 /**
37  * @brief Board Initialization Function
38  * @param None
39  * @retval None
40  */
board_init(void)41 void board_init(void)
42 {
43     board_tick_init();
44     board_stduart_init();
45     board_dma_init();
46     board_gpio_init();
47 }
48 
aos_maintask(void * arg)49 void aos_maintask(void *arg)
50 {
51     board_init();
52     board_kinit_init(&kinit);
53     aos_components_init(&kinit);
54     board_detect();
55 #if (ENABLE_FACTORY_TEST == 1)
56     uint8_t image_version[22];
57     sprintf(image_version, "VER: %s", BUILD_VERSION);
58     printf("\r\n Enter HaaSEDUk1 factorytest model, Version : %s \r\n", image_version);
59     int value = 0;
60     int re_value = 0;
61     int len = 32;
62     if (0 != aos_kv_get("factory_test", &value, &len)) {
63         if (0 == aos_kv_get("reboot_times", &re_value, &len)) {
64             if (re_value++ < 3) {
65                 aos_kv_set("reboot_times", &re_value, len, 1);
66                 printf("reboot_times is avild, add it %d!\r\n", re_value);
67             } else {
68                 goto normal_mode;
69             }
70         } else {
71             re_value++;
72             printf("reboot_times is not avild, create it %d!\r\n", re_value);
73             aos_kv_set("reboot_times", &re_value, len, 1);
74         }
75     }
76 factorytest_mode:
77         printf("board_test entry here!\r\n");
78         board_test();
79 normal_mode:
80 #endif
81 #ifndef AOS_BINS
82     application_start(kinit.argc, kinit.argv); /* jump to app entry */
83 #endif
84 }
85