1 /*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
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 "los_tick.h"
17 #include "los_task.h"
18 #include "los_config.h"
19 #include "los_interrupt.h"
20 #include "los_debug.h"
21 #include "uart.h"
22
23 #ifdef LOSCFG_NET_LWIP
24
25 #define IFNAMSIZ IF_NAMESIZE
26 #include "lwip/tcpip.h"
27 #include "lwip/netif.h"
28 #include "lwip/netifapi.h"
29
30 #define SLEEP_TIME_MS 60
31 #define NETIF_SETUP_OVERTIME 100
32
net_init(void)33 void net_init(void)
34 {
35 extern void tcpip_init(tcpip_init_done_fn initfunc, void *arg);
36 extern struct netif *VirtnetInit(void);
37
38 static unsigned int overtime = 0;
39
40 printf("tcpip_init start\n");
41 tcpip_init(NULL, NULL);
42 printf("tcpip_init end\n");
43
44 printf("netif init start...\n");
45 struct netif *pnetif = VirtnetInit();
46 if (pnetif) {
47 netif_set_default(pnetif);
48 (void)netifapi_netif_set_up(pnetif);
49 do {
50 LOS_UDelay(SLEEP_TIME_MS);
51 overtime++;
52 if (overtime > NETIF_SETUP_OVERTIME) {
53 PRINT_ERR("netif_is_link_up overtime!\n");
54 break;
55 }
56 } while (netif_is_link_up(pnetif) == 0);
57 if (overtime <= NETIF_SETUP_OVERTIME) {
58 printf("netif init succeed!\n");
59 }
60 } else {
61 printf("netif init failed!\n");
62 }
63 }
64 #endif /* LOSCFG_NET_LWIP */
65
66 UINT32 LosAppInit(VOID);
67
QemuCLZ(UINT32 data)68 UINT32 QemuCLZ(UINT32 data)
69 {
70 UINT32 count = 32; /* 32-bit data length */
71 if (data == 0) {
72 return count;
73 }
74
75 if (data & 0xFFFF0000) {
76 data = data >> 16; /* 16-bit data length */
77 count -= 16; /* 16-bit data length */
78 }
79
80 if (data & 0xFF00) {
81 data = data >> 8; /* 8-bit data length */
82 count -= 8; /* 8-bit data length */
83 }
84
85 if (data & 0xF0) {
86 data = data >> 4; /* 4-bit data length */
87 count -= 4; /* 4-bit data length */
88 }
89
90 if (data & 0x8) {
91 return (count - 4); /* 4-bit data length */
92 } else if (data & 0x4) {
93 return (count - 3); /* 3-bit data length */
94 } else if (data & 0x2) {
95 return (count - 2); /* 2-bit data length */
96 } else if (data & 0x1) {
97 return (count - 1);
98 }
99
100 return 0;
101 }
102
103 /*****************************************************************************
104 Function : main
105 Description : Main function entry
106 Input : None
107 Output : None
108 Return : None
109 *****************************************************************************/
main(VOID)110 LITE_OS_SEC_TEXT_INIT INT32 main(VOID)
111 {
112 UINT32 ret;
113
114 UartInit();
115 printf("\n OHOS start \n\r");
116
117 ret = LOS_KernelInit();
118 if (ret != LOS_OK) {
119 PRINT_ERR("LiteOS kernel init failed! ERROR: 0x%x\n", ret);
120 goto START_FAILED;
121 }
122
123 HalPlicInit();
124
125 Uart0RxIrqRegister();
126
127 #if (LOSCFG_USE_SHELL == 1)
128 ret = LosShellInit();
129 if (ret != LOS_OK) {
130 printf("LosShellInit failed! ERROR: 0x%x\n", ret);
131 }
132 #endif
133
134 printf("\nFb init begin...\n");
135 if (fb_init() != LOS_OK) {
136 PRINT_ERR("Fb init failed!");
137 }
138 printf("Fb int end\n");
139
140 printf("\nDeviceManagerStart start ...\n");
141 if (DeviceManagerStart()) {
142 PRINT_ERR("No drivers need load by hdf manager!");
143 }
144 printf("DeviceManagerStart end ...\n");
145
146 #ifdef LOSCFG_NET_LWIP
147 net_init();
148 #endif /* LOSCFG_NET_LWIP */
149
150 SystemAdapterInit();
151 ret = LosAppInit();
152 if (ret != LOS_OK) {
153 PRINT_ERR("LosAppInit failed! ERROR: 0x%x\n", ret);
154 }
155
156 LOS_Start();
157
158 START_FAILED:
159 while (1) {
160 __asm volatile("wfi");
161 }
162 }
163
ioremap(uintptr_t paddr,unsigned long size)164 void *ioremap(uintptr_t paddr, unsigned long size)
165 {
166 printf("[WARN] Function to be implemented: %s\n", __FUNCTION__);
167 return (void *)paddr;
168 }
169
iounmap(void * vaddr)170 void iounmap(void *vaddr)
171 {
172 printf("[WARN] Function to be implemented: %s\n", __FUNCTION__);
173 }
174
I2cOpen(int16_t number)175 int32_t I2cOpen(int16_t number)
176 {
177 printf("[WARN] Function to be implemented: %s\n", __FUNCTION__);
178 return 0;
179 }
180
GpioRead(uint16_t gpio,uint16_t * val)181 int32_t GpioRead(uint16_t gpio, uint16_t *val)
182 {
183 printf("[WARN] Function to be implemented: %s\n", __FUNCTION__);
184 return 0;
185 }
186
GpioSetIrq(uint16_t gpio,uint16_t mode,void * func,void * arg)187 int32_t GpioSetIrq(uint16_t gpio, uint16_t mode, void *func, void *arg)
188 {
189 printf("[WARN] Function to be implemented: %s\n", __FUNCTION__);
190 return 0;
191 }
192
GpioSetDir(uint16_t gpio,uint16_t dir)193 int32_t GpioSetDir(uint16_t gpio, uint16_t dir)
194 {
195 printf("[WARN] Function to be implemented: %s\n", __FUNCTION__);
196 return 0;
197 }
198
GpioEnableIrq(uint16_t gpio)199 int32_t GpioEnableIrq(uint16_t gpio)
200 {
201 printf("[WARN] Function to be implemented: %s\n", __FUNCTION__);
202 return 0;
203 }
204
GpioDisableIrq(uint16_t gpio)205 int32_t GpioDisableIrq(uint16_t gpio)
206 {
207 printf("[WARN] Function to be implemented: %s\n", __FUNCTION__);
208 return 0;
209 }
210