• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 GOODIX.
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 "main.h"
17 #include "los_arch_interrupt.h"
18 #include "stdint.h"
19 #include "gr55xx_sys.h"
20 #include "custom_config.h"
21 #include "uart.h"
22 #include "app_rng.h"
23 #include "app_log.h"
24 #include "los_task.h"
25 #include "cmsis_os2.h"
26 
27 #define CN_MINISECONDS_IN_SECOND    1000
28 #define CN_MAINBOOT_TASK_STACKSIZE  0X1000
29 #define CN_MAINBOOT_TASK_PRIOR      2
30 #define CN_MAINBOOT_TASK_NAME       "MainBoot"
31 
32 #define RNG_PARAM   {APP_RNG_TYPE_POLLING, {RNG_SEED_FR0_S0, RNG_LFSR_MODE_59BIT, RNG_OUTPUT_LFSR, RNG_POST_PRO_NOT}}
33 
34 static const uint8_t  s_bd_addr[SYS_BD_ADDR_LEN] = {0x08, 0x08, 0x08, 0xea, 0xea, 0xea};
35 static uint16_t g_random_seed[8] = {0x1234, 0x5678, 0x90AB, 0xCDEF, 0x1468, 0x2345, 0x5329, 0x2411};
36 
37 /* Initialize system peripherals. */
SystemPeripheralsInit(void)38 void SystemPeripheralsInit(void)
39 {
40     uint8_t   addr[6];
41     uint16_t  lenght = 6;
42 
43     if (NVDS_TAG_NOT_EXISTED == nvds_get(0xC001, &lenght, (uint8_t*)addr)) {
44         SYS_SET_BD_ADDR(s_bd_addr);
45     }
46 
47     bsp_log_init();
48     APP_LOG_INFO("GR551x system start!!!");
49 }
50 
51 /* Initialize Hardware RNG peripherals. */
HardwareRandomInit(void)52 void HardwareRandomInit(void)
53 {
54     app_rng_params_t params_t = RNG_PARAM;
55     app_rng_init(&params_t, NULL);
56 }
57 
HardwareRandomGet(uint32_t * p_random)58 int HardwareRandomGet(uint32_t *p_random)
59 {
60     int ret = 0;
61 
62     ret = app_rng_gen_sync(g_random_seed, p_random);
63     if (ret != 0) {
64         return -1;
65     }
66 
67     return 0;
68 }
69 
OSVectorInit(void)70 void OSVectorInit(void)
71 {
72     uint32_t *p_vector = (uint32_t *)SCB->VTOR;
73     p_vector[SVCall_IRQn + OS_SYS_VECTOR_CNT]  = SVC_Handler;
74 
75     OsSetVector(WDT_IRQn, (HWI_PROC_FUNC)WDT_IRQHandler);
76     OsSetVector(BLE_SDK_IRQn, (HWI_PROC_FUNC)BLE_SDK_Handler);
77     OsSetVector(BLE_IRQn, (HWI_PROC_FUNC)BLE_IRQHandler);
78     OsSetVector(DMA_IRQn, (HWI_PROC_FUNC)DMA_IRQHandler);
79     OsSetVector(SPI_M_IRQn, (HWI_PROC_FUNC)SPI_M_IRQHandler);
80     OsSetVector(SPI_S_IRQn, (HWI_PROC_FUNC)SPI_S_IRQHandler);
81     OsSetVector(EXT0_IRQn, (HWI_PROC_FUNC)EXT0_IRQHandler);
82     OsSetVector(EXT1_IRQn, (HWI_PROC_FUNC)EXT1_IRQHandler);
83     OsSetVector(TIMER0_IRQn, (HWI_PROC_FUNC)TIMER0_IRQHandler);
84     OsSetVector(TIMER1_IRQn, (HWI_PROC_FUNC)TIMER1_IRQHandler);
85     OsSetVector(DUAL_TIMER_IRQn, (HWI_PROC_FUNC)DUAL_TIMER_IRQHandler);
86     OsSetVector(QSPI0_IRQn, (HWI_PROC_FUNC)QSPI0_IRQHandler);
87     OsSetVector(UART0_IRQn, (HWI_PROC_FUNC)UART0_IRQHandler);
88     OsSetVector(UART1_IRQn, (HWI_PROC_FUNC)UART1_IRQHandler);
89     OsSetVector(I2C0_IRQn, (HWI_PROC_FUNC)I2C0_IRQHandler);
90     OsSetVector(I2C1_IRQn, (HWI_PROC_FUNC)I2C1_IRQHandler);
91     OsSetVector(AES_IRQn, (HWI_PROC_FUNC)AES_IRQHandler);
92     OsSetVector(HMAC_IRQn, (HWI_PROC_FUNC)HMAC_IRQHandler);
93     OsSetVector(EXT2_IRQn, (HWI_PROC_FUNC)EXT2_IRQHandler);
94     OsSetVector(RNG_IRQn, (HWI_PROC_FUNC)RNG_IRQHandler);
95     OsSetVector(PMU_IRQn, (HWI_PROC_FUNC)PMU_IRQHandler);
96     OsSetVector(PKC_IRQn, (HWI_PROC_FUNC)PKC_IRQHandler);
97     OsSetVector(XQSPI_IRQn, (HWI_PROC_FUNC)XQSPI_IRQHandler);
98     OsSetVector(QSPI1_IRQn, (HWI_PROC_FUNC)QSPI1_IRQHandler);
99     OsSetVector(PWR_CMD_IRQn, (HWI_PROC_FUNC)PWR_CMD_IRQHandler);
100     OsSetVector(BLESLP_IRQn, (HWI_PROC_FUNC)BLESLP_IRQHandler);
101     OsSetVector(SLPTIMER_IRQn, (HWI_PROC_FUNC)SLPTIMER_IRQHandler);
102     OsSetVector(COMP_EXT_IRQn, (HWI_PROC_FUNC)COMP_IRQHandler);
103     OsSetVector(AON_WDT_IRQn, (HWI_PROC_FUNC)AON_WDT_IRQHandler);
104     OsSetVector(I2S_M_IRQn, (HWI_PROC_FUNC)I2S_M_IRQHandler);
105     OsSetVector(I2S_S_IRQn, (HWI_PROC_FUNC)I2S_S_IRQHandler);
106     OsSetVector(ISO7816_IRQn, (HWI_PROC_FUNC)ISO7816_IRQHandler);
107     OsSetVector(PRESENT_IRQn, (HWI_PROC_FUNC)PRESENT_IRQHandler);
108     OsSetVector(CALENDAR_IRQn, (HWI_PROC_FUNC)CALENDAR_IRQHandler);
109 
110     NVIC_SetPriorityGrouping(0x3);
111 }
112 
MainBoot(void)113 static void MainBoot(void)
114 {
115     UINT32 uwRet;
116     UINT32 taskID;
117     TSK_INIT_PARAM_S stTask = {0};
118 
119     stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)OHOS_SystemInit;
120     stTask.uwStackSize = CN_MAINBOOT_TASK_STACKSIZE;
121     stTask.pcName = CN_MAINBOOT_TASK_NAME;
122     stTask.usTaskPrio = CN_MAINBOOT_TASK_PRIOR;
123     uwRet = LOS_TaskCreate(&taskID, &stTask);
124     if (uwRet != LOS_OK) {
125         APP_LOG_ERROR("MainBoot task create failed!!!");
126     }
127 }
128 
129 /**
130   * @brief  The application entry point.
131   * @retval int
132   */
main(void)133 int main(void)
134 {
135     UINT32 ret;
136 
137     ret = LOS_KernelInit();
138     if (ret == LOS_OK) {
139         OSVectorInit();
140 #if (LOSCFG_USE_SHELL == 1)
141         LosShellInit();
142         OsShellInit();
143 #endif
144         SystemPeripheralsInit();
145         HardwareRandomInit();
146         DeviceManagerStart();
147         MainBoot();
148         LOS_Start();
149     }
150     return 0;
151 }
152 
153