• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "stdarg.h"
33 #include "los_arch.h"
34 #include "los_config.h"
35 #include "los_debug.h"
36 #include "los_memory.h"
37 #include "los_mux.h"
38 #include "los_queue.h"
39 #include "los_sem.h"
40 
41 #if (LOSCFG_PLATFORM_HWI == 1)
42 #include "los_interrupt.h"
43 #endif
44 
45 #if (LOSCFG_BASE_CORE_SWTMR == 1)
46 #include "los_swtmr.h"
47 #endif
48 
49 #if (LOSCFG_BASE_CORE_CPUP == 1)
50 #include "los_cpup.h"
51 #endif
52 
53 #if (LOSCFG_PLATFORM_EXC == 1)
54 #include "los_exc_info.h"
55 #endif
56 
57 #if (LOSCFG_BACKTRACE_TYPE != 0)
58 #include "los_backtrace.h"
59 #endif
60 
61 #if (LOSCFG_KERNEL_PM == 1)
62 #include "los_pm.h"
63 #endif
64 
65 #if (LOSCFG_DYNLINK == 1)
66 #include "los_dynlink.h"
67 #endif
68 
69 #ifdef LOSCFG_KERNEL_LMS
70 #include "los_lms_pri.h"
71 #endif
72 
73 #if (LOSCFG_KERNEL_LMK == 1)
74 #include "los_lmk.h"
75 #endif
76 
77 #if (LOSCFG_POSIX_PIPE_API == 1)
78 #include "pipe_impl.h"
79 #endif
80 
81 #if (LOSCFG_KERNEL_SIGNAL == 1)
82 #include "los_signal.h"
83 #endif
84 
85 /*****************************************************************************
86  Function    : LOS_Reboot
87  Description : system exception, die in here, wait for watchdog.
88  Input       : None
89  Output      : None
90  Return      : None
91  *****************************************************************************/
LOS_Reboot(VOID)92 LITE_OS_SEC_TEXT_INIT VOID LOS_Reboot(VOID)
93 {
94     OsDoExcHook(EXC_REBOOT);
95     ArchSysExit();
96 }
97 
LOS_Panic(const CHAR * fmt,...)98 LITE_OS_SEC_TEXT_INIT VOID LOS_Panic(const CHAR *fmt, ...)
99 {
100     va_list ap;
101     va_start(ap, fmt);
102     PRINT_ERR(fmt, ap);
103     va_end(ap);
104 #if (LOSCFG_BACKTRACE_TYPE != 0)
105     LOS_BackTrace();
106 #endif
107     ArchSysExit();
108 }
109 
110 
111 /*****************************************************************************
112  Function    : OsRegister
113  Description : Configuring the maximum number of tasks
114  Input       : None
115  Output      : None
116  Return      : None
117  *****************************************************************************/
OsRegister(VOID)118 LITE_OS_SEC_TEXT_INIT static VOID OsRegister(VOID)
119 {
120     g_taskMaxNum = LOSCFG_BASE_CORE_TSK_LIMIT + 1; /* Reserved 1 for IDLE */
121 
122     return;
123 }
124 
LOS_Start(VOID)125 LITE_OS_SEC_TEXT_INIT UINT32 LOS_Start(VOID)
126 {
127     return ArchStartSchedule();
128 }
129 
130 /*****************************************************************************
131  Function    : LOS_KernelInit
132  Description : System kernel initialization function, configure all system modules
133  Input       : None
134  Output      : None
135  Return      : LOS_OK on success or error code on failure
136  *****************************************************************************/
LOS_KernelInit(VOID)137 LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID)
138 {
139     UINT32 ret;
140     PRINTK("entering kernel init...\n");
141 
142 #if (LOSCFG_BACKTRACE_TYPE != 0)
143     OsBackTraceInit();
144 #endif
145 
146     OsRegister();
147 
148 #ifdef LOSCFG_KERNEL_LMS
149     OsLmsInit();
150 #endif
151     ret = OsMemSystemInit();
152     if (ret != LOS_OK) {
153         PRINT_ERR("OsMemSystemInit error %d\n", ret);
154         return ret;
155     }
156 
157     ArchInit();
158 
159     ret = OsTickTimerInit();
160     if (ret != LOS_OK) {
161         PRINT_ERR("OsTickTimerInit error! 0x%x\n", ret);
162         return ret;
163     }
164 
165     ret = OsTaskInit();
166     if (ret != LOS_OK) {
167         PRINT_ERR("OsTaskInit error\n");
168         return ret;
169     }
170 
171 #if (LOSCFG_BASE_CORE_TSK_MONITOR == 1)
172     OsTaskMonInit();
173 #endif
174 
175 #if (LOSCFG_BASE_CORE_CPUP == 1)
176     ret = OsCpupInit();
177     if (ret != LOS_OK) {
178         PRINT_ERR("OsCpupInit error\n");
179         return ret;
180     }
181 #endif
182 
183 #if (LOSCFG_BASE_IPC_SEM == 1)
184     ret = OsSemInit();
185     if (ret != LOS_OK) {
186         return ret;
187     }
188 #endif
189 
190 #if (LOSCFG_BASE_IPC_MUX == 1)
191     ret = OsMuxInit();
192     if (ret != LOS_OK) {
193         return ret;
194     }
195 #endif
196 
197 #if (LOSCFG_BASE_IPC_QUEUE == 1)
198     ret = OsQueueInit();
199     if (ret != LOS_OK) {
200         PRINT_ERR("OsQueueInit error\n");
201         return ret;
202     }
203 #endif
204 
205 #if (LOSCFG_BASE_CORE_SWTMR == 1)
206     ret = OsSwtmrInit();
207     if (ret != LOS_OK) {
208         PRINT_ERR("OsSwtmrInit error\n");
209         return ret;
210     }
211 #endif
212 
213     ret = OsIdleTaskCreate();
214     if (ret != LOS_OK) {
215         return ret;
216     }
217 
218 #if (LOSCFG_KERNEL_TRACE == 1)
219     ret = OsTraceInit(LOSCFG_TRACE_BUFFER_SIZE);
220     if (ret != LOS_OK) {
221         PRINT_ERR("OsTraceInit error\n");
222         return ret;
223     }
224 #endif
225 
226 #if (LOSCFG_KERNEL_PM == 1)
227     ret = OsPmInit();
228     if (ret != LOS_OK) {
229         PRINT_ERR("Pm init failed!\n");
230         return ret;
231     }
232 #endif
233 
234 #if (LOSCFG_KERNEL_LMK == 1)
235     OsLmkInit();
236 #endif
237 
238 #if (LOSCFG_PLATFORM_EXC == 1)
239     OsExcMsgDumpInit();
240 #endif
241 
242 #if (LOSCFG_DYNLINK == 1)
243     ret = LOS_DynlinkInit();
244     if (ret != LOS_OK) {
245         return ret;
246     }
247 #endif
248 
249 #if (LOSCFG_POSIX_PIPE_API == 1)
250     ret = OsPipeInit();
251     if (ret != LOS_OK) {
252         PRINT_ERR("Pipe init failed!\n");
253         return ret;
254     }
255 #endif
256 
257 #if (LOSCFG_KERNEL_SIGNAL == 1)
258     ret = OsSignalInit();
259     if (ret != LOS_OK) {
260         PRINT_ERR("Signal init failed!\n");
261         return ret;
262     }
263 #endif
264 
265     return LOS_OK;
266 }
267 
268