• 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_timer.h"
16 #include "prt_clk.h"
17 #include "prt_hwi.h"
18 #include "prt_attr_external.h"
19 #include "prt_sys_external.h"
20 #include "prt_lib_external.h"
21 
22 OS_SEC_BSS U8 g_cpuType;
23 
OsGetCpuType(void)24 OS_SEC_L4_TEXT U8 OsGetCpuType(void)
25 {
26     return g_cpuType;
27 }
28 
OsSysTimeHookReg(void)29 OS_SEC_L4_TEXT U32 OsSysTimeHookReg(void)
30 {
31     return OsSetSysTimeHook(PRT_ClkGetCycleCount64);
32 }
33 
OsSysRegister(struct SysModInfo * modInfo)34 OS_SEC_L4_TEXT U32 OsSysRegister(struct SysModInfo *modInfo)
35 {
36     U32 ret;
37 
38     if (modInfo->systemClock < OS_SYS_US_PER_SECOND) {
39         return OS_ERRNO_SYS_CLOCK_INVALID;
40     }
41 
42     ret = OsSysTimeHookReg();
43     if (ret != OS_OK) {
44         return ret;
45     }
46 
47     UNI_FLAG = 0;
48     g_systemClock = modInfo->systemClock;
49     g_cpuType = (U8)modInfo->cpuType;
50 #if defined(OS_OPTION_HWI_MAX_NUM_CONFIG)
51     if (OsHwiCheckMaxNum(modInfo->hwiMaxNum) == FALSE) {
52         return OS_ERRNO_SYS_HWI_MAX_NUM_CONFIG_INVALID;
53     }
54     g_hwiMaxNumConfig = modInfo->hwiMaxNum;
55 #endif
56 
57     return ret;
58 }
59 
PRT_ClkCycle2Ms(U64 cycle)60 OS_SEC_L4_TEXT U64 PRT_ClkCycle2Ms(U64 cycle)
61 {
62     return DIV64(cycle, g_systemClock / OS_SYS_MS_PER_SECOND);
63 }
64 
PRT_ClkCycle2Us(U64 cycle)65 OS_SEC_L4_TEXT U64 PRT_ClkCycle2Us(U64 cycle)
66 {
67     return DIV64(cycle, g_systemClock / OS_SYS_US_PER_SECOND);
68 }
69