更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_init.c 文件参考

浏览源代码.

函数

 OS_INIT_LEVEL_REG (kernel, 10, g_kernInitLevelList)
 
STATIC SPIN_LOCK_INIT (g_initLock)
 
STATIC VOID InitLevelCall (const CHAR *name, const UINT32 level, struct ModuleInitInfo *initLevelList[])
 
VOID OsInitCall (const UINT32 level)
 初始化调用日志打印,这个函数的功能主要是为了记录某个步骤的耗时.在一个函数前后各调用一次就知道函数的执行情况. 这为开机调试提供了很重要的日志依据. 更多...
 

变量

STATIC volatile UINT32 g_initCurrentLevel = OS_INVALID_VALUE
 
STATIC volatile struct ModuleInitInfog_initCurrentModule = 0
 
STATIC Atomic g_initCount = 0
 

函数说明

◆ InitLevelCall()

STATIC VOID InitLevelCall ( const CHAR name,
const UINT32  level,
struct ModuleInitInfo initLevelList[] 
)

It is recommended that each startup framework encapsulate a layer of its own calling interface. 建议每个启动框架都封装一层自己的调用接口

在文件 los_init.c59 行定义.

60{
61 struct ModuleInitInfo *module = NULL;
62#ifdef LOS_INIT_DEBUG
63 UINT64 startNsec, endNsec;
64 UINT64 totalTime = 0;
65 UINT64 singleTime;
66 UINT32 ret = LOS_OK;
67#endif
68
69 if (ArchCurrCpuid() == 0) {//主CPU
70#ifdef LOS_INIT_DEBUG
71 PRINTK("-------- %s Module Init... level = %u --------\n", name, level);
72#endif
73 g_initCurrentLevel = level;
74 g_initCurrentModule = initLevelList[level];
75 } else {
76 while (g_initCurrentLevel < level) {
77 }
78 }
79
80 do {
81 LOS_SpinLock(&g_initLock);
82 if (g_initCurrentModule >= initLevelList[level + 1]) {
83 LOS_SpinUnlock(&g_initLock);
84 break;
85 }
86 module = (struct ModuleInitInfo *)g_initCurrentModule;
88 LOS_SpinUnlock(&g_initLock);
89 if (module->hook != NULL) {
90#ifdef LOS_INIT_DEBUG
91 ret = LOS_OK;
92 startNsec = LOS_CurrNanosec();
93 ret = (UINT32)module->hook();
94 endNsec = LOS_CurrNanosec();
95 singleTime = endNsec - startNsec;
96 totalTime += singleTime;
97 PRINTK("Starting %s module consumes %llu ns. Run on cpu %u\n", module->name, singleTime, ArchCurrCpuid());
98#else
99 module->hook();
100#endif
101 }
102#ifdef LOS_INIT_DEBUG
103 if (ret != LOS_OK) {
104 PRINT_ERR("%s initialization failed at module %s, function addr at 0x%x, ret code is %u\n",
105 name, module->name, module->hook, ret);
106 }
107#endif
108 } while (1);
109
110 if (level >= LOS_INIT_LEVEL_KMOD_TASK) {
112 while ((LOS_AtomicRead(&g_initCount) % LOSCFG_KERNEL_CORE_NUM) != 0) {
113 }
114 }
115
116#ifdef LOS_INIT_DEBUG
117 PRINTK("%s initialization at level %u consumes %lluns on cpu %u.\n", name, level, totalTime, ArchCurrCpuid());
118#endif
119}
STATIC INLINE VOID LOS_AtomicInc(Atomic *v)
Atomic addSelf.
Definition: los_atomic.h:253
STATIC INLINE INT32 LOS_AtomicRead(const Atomic *v)
Atomic read. | 读取32bit原子数据
Definition: los_atomic.h:123
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_CurrNanosec(VOID)
获取自系统启动以来的纳秒数
Definition: los_hw_tick.c:62
STATIC INLINE UINT32 ArchCurrCpuid(VOID)
Definition: los_hw_cpu.h:168
STATIC volatile UINT32 g_initCurrentLevel
Definition: los_init.c:50
STATIC volatile struct ModuleInitInfo * g_initCurrentModule
Definition: los_init.c:51
STATIC Atomic g_initCount
Definition: los_init.c:52
VOID LOS_SpinLock(SPIN_LOCK_S *lock)
Definition: los_spinlock.c:50
VOID LOS_SpinUnlock(SPIN_LOCK_S *lock)
Definition: los_spinlock.c:84
long unsigned int UINT64
Definition: los_typedef.h:66
unsigned int UINT32
Definition: los_typedef.h:57
OsInitHook hook
函数指针,钩子函数
Definition: los_init_info.h:65
const CHAR * name
Definition: los_init_info.h:67
函数调用图:
这是这个函数的调用关系图:

◆ OS_INIT_LEVEL_REG()

OS_INIT_LEVEL_REG ( kernel  ,
10  ,
g_kernInitLevelList   
)

Register kernel init level labels. | 内核初始化等级

◆ OsInitCall()

VOID OsInitCall ( const UINT32  level)

初始化调用日志打印,这个函数的功能主要是为了记录某个步骤的耗时.在一个函数前后各调用一次就知道函数的执行情况. 这为开机调试提供了很重要的日志依据.

参数
level
返回
VOID

在文件 los_init.c127 行定义.

128{
129 if (level >= LOS_INIT_LEVEL_FINISH) {
130 return;
131 }
132
133 InitLevelCall("Kernel", level, g_kernInitLevelList);
134}
STATIC VOID InitLevelCall(const CHAR *name, const UINT32 level, struct ModuleInitInfo *initLevelList[])
Definition: los_init.c:59
函数调用图:
这是这个函数的调用关系图:

◆ SPIN_LOCK_INIT()

STATIC SPIN_LOCK_INIT ( g_initLock  )

变量说明

◆ g_initCount

STATIC Atomic g_initCount = 0

在文件 los_init.c52 行定义.

◆ g_initCurrentLevel

STATIC volatile UINT32 g_initCurrentLevel = OS_INVALID_VALUE

在文件 los_init.c50 行定义.

◆ g_initCurrentModule

STATIC volatile struct ModuleInitInfo* g_initCurrentModule = 0

在文件 los_init.c51 行定义.