• 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: System base function implementation
14  */
15 #include "prt_idle.h"
16 #include "prt_sys_external.h"
17 #include "prt_kexc_external.h"
18 #include "prt_hook_external.h"
19 
20 /* 系统主频 */
21 OS_SEC_BSS U32 g_systemClock;
22 
23 /* cpup */
24 OS_SEC_BSS TickEntryFunc g_tickTaskEntry;
25 
26 OS_SEC_BSS TickDispFunc g_tickDispatcher;
27 /* tick中软件定时器扫描钩子 */
28 OS_SEC_BSS TaskScanFunc g_taskScanHook;
29 OS_SEC_BSS struct TickModInfo g_tickModInfo;
30 
31 OS_SEC_L4_BSS U32 g_threadNum;
32 /* Tick计数 */
33 OS_SEC_BSS U64 g_uniTicks;
34 
35 /* 系统状态标志位 */
36 OS_SEC_DATA U32 g_uniFlag = 0;
37 OS_SEC_BSS U32 g_tickNoRespondCnt;
38 OS_SEC_DATA struct TagTskCb *g_runningTask = NULL;
39 
OsCurThreadTypeNoIntLock(void)40 OS_SEC_ALW_INLINE INLINE enum SysThreadType OsCurThreadTypeNoIntLock(void)
41 {
42     U32 uniFlag = UNI_FLAG;
43 
44     if (LIKELY(OS_SYS_TASK_STATUS(uniFlag))) {
45         return SYS_TASK;
46     } else if (OS_SYS_HWI_STATUS(uniFlag)) {
47         return SYS_HWI;
48     }
49 
50     return SYS_KERNEL; // 异常、tick、sys、初始化
51 }
52 
53 /*
54  * 描述:获取系统当前线程类型。
55  */
OsCurThreadType(void)56 OS_SEC_TEXT enum SysThreadType OsCurThreadType(void)
57 {
58     enum SysThreadType type;
59     uintptr_t intSave = OsIntLock();
60 
61     /* 异常模块打开而且目前系统有异常产生 */
62     if (CUR_NEST_COUNT > 0) {
63         OsIntRestore(intSave);
64         return SYS_KERNEL;
65     }
66 
67     type = OsCurThreadTypeNoIntLock();
68 
69     OsIntRestore(intSave);
70     return type;
71 }
72 
PRT_IdleAddHook(IdleHook hook)73 OS_SEC_L4_TEXT U32 PRT_IdleAddHook(IdleHook hook)
74 {
75     return OsHookAdd(OS_HOOK_IDLE_PERIOD, (OsVoidFunc)hook);
76 }
PRT_IdleDelHook(IdleHook hook)77 OS_SEC_L4_TEXT U32 PRT_IdleDelHook(IdleHook hook)
78 {
79     return OsHookDel(OS_HOOK_IDLE_PERIOD, (OsVoidFunc)hook);
80 }