• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2009-12-22
13  * Description: UniProton的初始化C文件。
14  */
15 #include "prt_config_internal.h"
16 
OsConfigAddrSizeGet(uintptr_t addr,uintptr_t size,uintptr_t * destAddr,uintptr_t * destSize)17 OS_SEC_ALW_INLINE INLINE void OsConfigAddrSizeGet(uintptr_t addr, uintptr_t size,
18                                                   uintptr_t *destAddr, uintptr_t *destSize)
19 {
20     *destAddr = addr;
21     *destSize = size;
22 }
23 
OsMemConfigReg(void)24 U32 OsMemConfigReg(void)
25 {
26     U32 ret;
27 
28     ret = OsFscMemInit(OS_MEM_FSC_PT_ADDR, OS_MEM_FSC_PT_SIZE);
29     if (ret != OS_OK) {
30         return ret;
31     }
32 
33     return OS_OK;
34 }
35 
OsMemDefPtInit(void)36 U32 OsMemDefPtInit(void)
37 {
38     return OS_OK;
39 }
40 
OsMemConfigInit(void)41 U32 OsMemConfigInit(void)
42 {
43     /* 系统默认FSC内存分区初始化 */
44     return OsMemDefPtInit();
45 }
46 
OsSystemReg(void)47 U32 OsSystemReg(void)
48 {
49     struct SysModInfo sysModInfo;
50 
51     sysModInfo.systemClock = OS_SYS_CLOCK;
52     sysModInfo.cpuType = OS_CPU_TYPE;
53 #if defined(OS_OPTION_HWI_MAX_NUM_CONFIG)
54     sysModInfo.hwiMaxNum = OS_HWI_MAX_NUM_CONFIG;
55 #endif
56 
57     return OsSysRegister(&sysModInfo);
58 }
59 
60 #if (OS_INCLUDE_SEM == YES)
OsSemConfigReg(void)61 U32 OsSemConfigReg(void)
62 {
63     struct SemModInfo semModInfo;
64 
65     semModInfo.maxNum = OS_SEM_MAX_SUPPORT_NUM;
66     return OsSemRegister(&semModInfo);
67 
68 }
69 #endif
70 
71 #if (OS_INCLUDE_TASK == YES)
OsTaskInfoSet(struct TskModInfo * taskModInfo)72 void OsTaskInfoSet(struct TskModInfo *taskModInfo)
73 {
74     taskModInfo->maxNum = OS_TSK_MAX_SUPPORT_NUM;
75     taskModInfo->defaultSize = OS_TSK_DEFAULT_STACK_SIZE;
76     taskModInfo->idleStackSize = OS_TSK_IDLE_STACK_SIZE;
77     taskModInfo->magicWord = WORD_PACK((U32)OS_TSK_STACK_MAGIC_WORD);
78 }
79 #else
80 #error "OS_INCLUDE_TASK MUST BE YES! The SWI has been cut out,the task can not cut out."
81 #endif
82 
OsHookConfigReg(void)83 U32 OsHookConfigReg(void)
84 {
85     struct HookModInfo hookModInfo;
86 
87     hookModInfo.maxNum[OS_HOOK_HWI_ENTRY] = OS_HOOK_HWI_ENTRY_NUM;
88     hookModInfo.maxNum[OS_HOOK_HWI_EXIT] = OS_HOOK_HWI_EXIT_NUM;
89     hookModInfo.maxNum[OS_HOOK_TSK_SWITCH] = OS_HOOK_TSK_SWITCH_NUM;
90     hookModInfo.maxNum[OS_HOOK_IDLE_PERIOD] = OS_HOOK_IDLE_NUM;
91 
92     return OsHookRegister(&hookModInfo);
93 }
94 
OsSysConfigReg(void)95 U32 OsSysConfigReg(void)
96 {
97     U32 ret;
98 
99     ret = OsSystemReg();
100     if (ret != OS_OK) {
101         return ret;
102     }
103     return OS_OK;
104 }
105 
106 #if (OS_INCLUDE_TICK == YES)
OsTickConfigReg(void)107 U32 OsTickConfigReg(void)
108 {
109     struct TickModInfo tickModInfo;
110 
111     tickModInfo.tickPerSecond = OS_TICK_PER_SECOND;
112     tickModInfo.tickPriority = 0;
113 
114     return OsTickRegister(&tickModInfo);
115 }
116 #endif
117 
118 #if (OS_INCLUDE_TASK == YES)
OsTskConfigReg(void)119 U32 OsTskConfigReg(void)
120 {
121     struct TskModInfo taskModInfo;
122     OsTaskInfoSet(&taskModInfo);
123     return OsTskRegister(&taskModInfo);
124 }
125 #endif
126 
127 #if (OS_INCLUDE_QUEUE == YES)
OsQueueConfigReg(void)128 U32 OsQueueConfigReg(void)
129 {
130     return OsQueueRegister(OS_QUEUE_MAX_SUPPORT_NUM);
131 }
132 #endif
133 
134 #if (OS_INCLUDE_CPUP == YES)
OsCpupConfigReg(void)135 U32 OsCpupConfigReg(void)
136 {
137     struct CpupModInfo cpupModInfo;
138 
139     cpupModInfo.cpupWarnFlag = (bool)OS_CONFIG_CPUP_WARN;
140     cpupModInfo.sampleTime = OS_CPUP_SAMPLE_INTERVAL;
141     cpupModInfo.warn = OS_CPUP_SHORT_WARN;
142     cpupModInfo.resume = OS_CPUP_SHORT_RESUME;
143 
144     return OsCpupRegister(&cpupModInfo);
145 }
146 #endif
147 
148 #if (OS_INCLUDE_TICK_SWTMER == YES)
OsSwTmrConfigInit(void)149 U32 OsSwTmrConfigInit(void)
150 {
151     return OsSwTmrInit(OS_TICK_SWITIMER_MAX_NUM);
152 }
153 #endif
154 
155 #if (OS_INCLUDE_CPUP == YES)
156 #if (OS_INCLUDE_TICK == NO)
157 #error "OS_INCLUDE_CPUP depend on OS_INCLUDE_TICK!"
158 #endif
OsCpupConfigInit(void)159 U32 OsCpupConfigInit(void)
160 {
161     U32 ret;
162 
163     ret = OsCpupInit();
164     if (ret != OS_OK) {
165         return ret;
166     }
167 
168     if (OS_CONFIG_CPUP_WARN == YES) {
169 #if defined(OS_OPTION_CPUP_WARN)
170         OsCpupWarnInit();
171 #else
172         return OS_ERRNO_SYS_NO_CPUP_WARN;
173 #endif
174     }
175     return OS_OK;
176 }
177 #endif
178 
179 #if (OS_INCLUDE_SEM == YES)
OsSemConfigInit(void)180 U32 OsSemConfigInit(void)
181 {
182     return OsSemInit();
183 }
184 #endif
185 
186 #if (OS_INCLUDE_TASK == YES)
OsTskConfigInit(void)187 U32 OsTskConfigInit(void)
188 {
189     return OsTskInit();
190 }
191 #endif
192 
193 /* 系统初始化注册表 */
194 struct OsModuleConfigInfo g_moduleConfigTab[] = {
195     /* {模块号, 模块注册函数, 模块初始化函数} */
196     {OS_MID_SYS, {OsSysConfigReg, NULL}},
197     {OS_MID_MEM, {OsMemConfigReg, OsMemConfigInit}},
198     {OS_MID_HWI, {NULL, OsHwiConfigInit}},
199     {OS_MID_HARDDRV, {NULL, PRT_HardDrvInit}},
200     {OS_MID_HOOK, {OsHookConfigReg, OsHookConfigInit}},
201     {OS_MID_EXC, {NULL, OsExcConfigInit}},
202 #if (OS_INCLUDE_TASK == YES)
203     {OS_MID_TSK, {OsTskConfigReg, OsTskConfigInit}},
204 #endif
205 #if (OS_INCLUDE_TICK == YES)
206     {OS_MID_TICK, {OsTickConfigReg, OsTickConfigInit}},
207 #endif
208 
209 #if (OS_INCLUDE_TICK_SWTMER == YES)
210     {OS_MID_SWTMR, {NULL, OsSwTmrConfigInit}},
211 #endif
212 
213 #if (OS_INCLUDE_CPUP == YES)
214     {OS_MID_CPUP, {OsCpupConfigReg, OsCpupConfigInit}},
215 #endif
216 #if (OS_INCLUDE_SEM == YES)
217     {OS_MID_SEM, {OsSemConfigReg, OsSemConfigInit}},
218 #endif
219 #if (OS_INCLUDE_QUEUE == YES)
220     {OS_MID_QUEUE, {OsQueueConfigReg, OsQueueConfigInit}},
221 #endif
222     {OS_MID_APP, {NULL, PRT_AppInit}},
223 
224     {OS_MID_BUTT, {NULL, NULL}},
225 };
226 
227 /*
228  * 描述:OS模块注册、初始化运行函数
229  */
OsModuleConfigRun(enum OsinitPhaseId initPhaseId,U32 initPhase)230 U32 OsModuleConfigRun(enum OsinitPhaseId initPhaseId, U32 initPhase)
231 {
232     U32 idx = 0;
233     U32 ret = OS_OK;
234     while (g_moduleConfigTab[idx].moudleId != OS_MID_BUTT) {
235         if (g_moduleConfigTab[idx].moudleConfigFunc[initPhaseId] == NULL) {
236             idx++;
237             continue;
238         }
239         ret = g_moduleConfigTab[idx].moudleConfigFunc[initPhaseId]();
240         if (ret != OS_OK) {
241             break;
242         }
243         idx++;
244     }
245     return ret;
246 }
OsRegister(void)247 U32 OsRegister(void)
248 {
249     return OsModuleConfigRun(OS_REGISTER_ID, OS_REGISTER_PHASE);
250 }
251 
252 /*
253  * 描述:OsInitialize阶段
254  */
OsInitialize(void)255 U32 OsInitialize(void)
256 {
257     return OsModuleConfigRun(OS_INIT_ID, OS_INITIALIZE_PHASE);
258 }
259 
260 /*
261  * 描述:OsStart阶段
262  */
OsStart(void)263 U32 OsStart(void)
264 {
265     U32 ret;
266 
267 #if (OS_INCLUDE_TICK == YES)
268     /* 表示系统在进行启动阶段,匹配MOUDLE_ID之后,标记进入TICK模块的启动 */
269     ret = OsTickStart();
270     if (ret != OS_OK) {
271         return ret;
272     }
273 #endif
274 
275 #if (OS_INCLUDE_TASK == YES)
276     /* 表示系统在进行启动阶段,匹配MOUDLE_ID之后,标记进入任务模块的启动 */
277     ret = OsActivate();
278 #else
279     ret = OS_OK;
280 #endif
281 
282     return ret;
283 }
284 
main(void)285 S32 main(void)
286 {
287     U32 ret;
288 
289     OsHwInit();
290 
291     /* OS模块注册 */
292     ret = OsRegister();
293     if (ret != OS_OK) {
294         return (S32)ret;
295     }
296 
297     /* OS模块初始化 */
298     ret = OsInitialize();
299     if (ret != OS_OK) {
300         return (S32)ret;
301     }
302 
303     /* OS启动调度 */
304     ret = OsStart();
305     if (ret != OS_OK) {
306         return (S32)ret;
307     }
308 
309     /* Execution should not reach this point */
310     return (S32)OS_ERROR;
311 }
312