From 99c01f46b7339f93a2aff7dfe342eabc04abc235 Mon Sep 17 00:00:00 2001
From: cailun <2505225681@qq.com>
Date: Fri, 3 Nov 2023 00:31:07 +0800
Subject: [PATCH 01/26] doc
---
...teOS阅读报告.docx => 蔡伦_LiteOS阅读泛读报告.docx} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename doc/{蔡伦_LiteOS阅读报告.docx => 蔡伦_LiteOS阅读泛读报告.docx} (100%)
diff --git a/doc/蔡伦_LiteOS阅读报告.docx b/doc/蔡伦_LiteOS阅读泛读报告.docx
similarity index 100%
rename from doc/蔡伦_LiteOS阅读报告.docx
rename to doc/蔡伦_LiteOS阅读泛读报告.docx
From 6412ea5ff6cabc6ca3facde053c7ca031b65fc03 Mon Sep 17 00:00:00 2001
From: he <1429721469@qq.com>
Date: Fri, 3 Nov 2023 00:43:59 +0800
Subject: [PATCH 02/26] hjc
---
hjc/hjc.txt | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 hjc/hjc.txt
diff --git a/hjc/hjc.txt b/hjc/hjc.txt
new file mode 100644
index 0000000..e69de29
From 3e0fcb461917fbbc2b6b4860a1404e7164596133 Mon Sep 17 00:00:00 2001
From: faj <1900949849@qq.com>
Date: Fri, 3 Nov 2023 20:37:13 +0800
Subject: [PATCH 03/26] fuaojia_branch
---
fuaojia_branch.txt | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 fuaojia_branch.txt
diff --git a/fuaojia_branch.txt b/fuaojia_branch.txt
new file mode 100644
index 0000000..e69de29
From a5ed7a0caafd1f6e1e2a7a1caf1e3b1fd03eaf54 Mon Sep 17 00:00:00 2001
From: tree <1913915946@qq.com>
Date: Mon, 27 Nov 2023 19:54:03 +0800
Subject: [PATCH 04/26] 11.27
---
src/kernel/base/los_bitmap.c | 12 ++++---
src/kernel/base/los_err.c | 8 +++--
src/kernel/base/los_event.c | 34 ++++++++++---------
src/kernel/base/los_exc.c | 51 ++++++++++++++++-------------
src/kernel/base/los_hwi.c | 61 +++++++++++++++++++++++------------
src/kernel/base/los_lockdep.c | 25 +++++++-------
src/kernel/base/los_misc.c | 42 ++++++++++++------------
src/kernel/base/los_mp.c | 20 ++++++------
src/kernel/base/los_mux.c | 25 +++++++-------
src/kernel/base/los_percpu.c | 2 +-
src/kernel/base/los_printf.c | 14 ++++----
11 files changed, 170 insertions(+), 124 deletions(-)
diff --git a/src/kernel/base/los_bitmap.c b/src/kernel/base/los_bitmap.c
index 84a056a..8ac0390 100644
--- a/src/kernel/base/los_bitmap.c
+++ b/src/kernel/base/los_bitmap.c
@@ -26,6 +26,10 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
+/*这是一个位图(bitmap)的实现,用于对位图进行设置、清除和获取最高/最低位的操作。
+该位图使用一个32位无符号整数(UINT32)来表示,每一位都代表一个标记
+函数通过位运算来实现对位图的操作,其中包括左移、按位与、按位或、按位取反等操作。*/
+
#include "los_bitmap.h"
#include "los_toolchain.h"
@@ -36,7 +40,7 @@ extern "C" {
#endif /* __cplusplus */
#define OS_BITMAP_MASK 0x1FU
-
+//LOS_BitmapSet:将指定位置的位设置为1
VOID LOS_BitmapSet(UINT32 *bitmap, UINT16 pos)
{
if (bitmap == NULL) {
@@ -45,7 +49,7 @@ VOID LOS_BitmapSet(UINT32 *bitmap, UINT16 pos)
*bitmap |= 1U << (pos & OS_BITMAP_MASK);
}
-
+//LOS_BitmapClr:将指定位置的位清除为0
VOID LOS_BitmapClr(UINT32 *bitmap, UINT16 pos)
{
if (bitmap == NULL) {
@@ -54,7 +58,7 @@ VOID LOS_BitmapClr(UINT32 *bitmap, UINT16 pos)
*bitmap &= ~(1U << (pos & OS_BITMAP_MASK));
}
-
+//LOS_HighBitGet:获取位图中最高位(值为1的位置)的索引
UINT16 LOS_HighBitGet(UINT32 bitmap)
{
if (bitmap == 0) {
@@ -63,7 +67,7 @@ UINT16 LOS_HighBitGet(UINT32 bitmap)
return (OS_BITMAP_MASK - CLZ(bitmap));
}
-
+//LOS_LowBitGet:获取位图中最低位(值为1的位置)的索引
UINT16 LOS_LowBitGet(UINT32 bitmap)
{
if (bitmap == 0) {
diff --git a/src/kernel/base/los_err.c b/src/kernel/base/los_err.c
index 970015d..abcc40a 100644
--- a/src/kernel/base/los_err.c
+++ b/src/kernel/base/los_err.c
@@ -25,7 +25,8 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
-
+/*这段代码是关于错误处理的相关功能,包括注册错误处理函数和执行错误处理的函数。
+通过以下接口,用户可以自定义错误处理函数,并在发生错误时进行相应的处理操作。这样可以增强系统的健壮性和容错性,更好地应对各种错误情况。*/
#include "los_err.h"
#ifdef __cplusplus
@@ -35,8 +36,9 @@ extern "C" {
#endif /* __cplusplus */
/* Hook function for error handling. */
+//g_usrErrFunc:全局变量,用于保存用户注册的错误处理函数
LITE_OS_SEC_BSS LOS_ERRORHANDLE_FUNC g_usrErrFunc;
-
+//LOS_ErrHandle:用于执行错误处理的函数,当系统出现错误时会调用该函数来处理错误信息
LITE_OS_SEC_TEXT_INIT UINT32 LOS_ErrHandle(CHAR *fileName, UINT32 lineNo, UINT32 errorNo,
UINT32 paraLen, VOID *para)
{
@@ -46,7 +48,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_ErrHandle(CHAR *fileName, UINT32 lineNo, UINT32
return LOS_OK;
}
-
+//LOS_RegErrHandle:用于注册错误处理函数的接口,用户可以通过该函数注册自定义的错误处理函数
LITE_OS_SEC_TEXT_INIT VOID LOS_RegErrHandle(LOS_ERRORHANDLE_FUNC func)
{
g_usrErrFunc = func;
diff --git a/src/kernel/base/los_event.c b/src/kernel/base/los_event.c
index b2fe8cb..3caadc8 100644
--- a/src/kernel/base/los_event.c
+++ b/src/kernel/base/los_event.c
@@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
-
+/*这段代码是关于事件管理的实现,包括事件的初始化、读取、写入、清除等操作。*/
#include "los_event_pri.h"
#include "los_task_pri.h"
#include "los_spinlock.h"
@@ -38,7 +38,7 @@
extern "C" {
#endif
#endif /* __cplusplus */
-
+//LOS_EventInit()函数用于初始化事件控制块(eventCB),并将事件ID、事件列表等属性设置为初始值
LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB)
{
UINT32 intSave;
@@ -55,7 +55,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB)
LOS_IntRestore(intSave);
return LOS_OK;
}
-
+//OsEventParamCheck()函数用于检查参数的有效性,包括事件掩码(eventMask)、模式(mode)等
LITE_OS_SEC_TEXT STATIC UINT32 OsEventParamCheck(const VOID *ptr, UINT32 eventMask, UINT32 mode)
{
if (ptr == NULL) {
@@ -75,16 +75,17 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventParamCheck(const VOID *ptr, UINT32 eventMa
!(mode & (LOS_WAITMODE_OR | LOS_WAITMODE_AND))) {
return LOS_ERRNO_EVENT_FLAGS_INVALID;
}
+ //指针非空,事件掩码非0,事件掩码不包含LOS_ERRTYPE_ERROR标志位,模式合法
return LOS_OK;
}
-
+//OsEventPoll()函数用于轮询事件,根据指定的事件掩码和模式判断是否满足条件
LITE_OS_SEC_TEXT STATIC UINT32 OsEventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode)
{
UINT32 ret = 0;
LOS_ASSERT(ArchIntLocked());
LOS_ASSERT(LOS_SpinHeld(&g_taskSpin));
-
+
if (mode & LOS_WAITMODE_OR) {
if ((*eventId & eventMask) != 0) {
ret = *eventId & eventMask;
@@ -101,7 +102,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventPoll(UINT32 *eventId, UINT32 eventMask, UI
return ret;
}
-
+//OsEventReadCheck()函数用于检查事件读取操作的参数有效性,包括事件控制块(eventCB)、事件掩码(eventMask)、模式(mode)等
LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadCheck(const PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode)
{
UINT32 ret;
@@ -122,7 +123,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadCheck(const PEVENT_CB_S eventCB, UINT3
}
return LOS_OK;
}
-
+//OsEventReadImp()函数是事件读取的实现,根据指定的事件掩码和模式进行轮询,并根据超时时间和是否只读取一次进行相应的操作
LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadImp(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode,
UINT32 timeout, BOOL once, UINT32 *intSave)
{
@@ -165,7 +166,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadImp(PEVENT_CB_S eventCB, UINT32 eventM
}
return ret;
}
-
+//OsEventRead()函数是对外提供的事件读取接口,调用OsEventReadCheck()和OsEventReadImp()实现事件的读取操作
LITE_OS_SEC_TEXT STATIC UINT32 OsEventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode,
UINT32 timeout, BOOL once)
{
@@ -184,7 +185,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventRead(PEVENT_CB_S eventCB, UINT32 eventMask
SCHEDULER_UNLOCK(intSave);
return ret;
}
-
+//OsEventWrite()函数用于向事件控制块中写入指定的事件
LITE_OS_SEC_TEXT STATIC UINT32 OsEventWrite(PEVENT_CB_S eventCB, UINT32 events, BOOL once)
{
LosTaskCB *resumedTask = NULL;
@@ -230,7 +231,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventWrite(PEVENT_CB_S eventCB, UINT32 events,
}
return LOS_OK;
}
-
+//LOS_EventPoll()函数是对外提供的事件轮询接口,调用OsEventParamCheck()和OsEventPoll()实现事件的轮询操作
LITE_OS_SEC_TEXT UINT32 LOS_EventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode)
{
UINT32 ret;
@@ -246,17 +247,17 @@ LITE_OS_SEC_TEXT UINT32 LOS_EventPoll(UINT32 *eventId, UINT32 eventMask, UINT32
SCHEDULER_UNLOCK(intSave);
return ret;
}
-
+//LOS_EventRead()函数是对外提供的事件读取接口,调用OsEventRead()实现事件的读取操作
LITE_OS_SEC_TEXT UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout)
{
return OsEventRead(eventCB, eventMask, mode, timeout, FALSE);
}
-
+//LOS_EventWrite()函数是对外提供的事件写入接口,调用OsEventWrite()实现事件的写入操作
LITE_OS_SEC_TEXT UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events)
{
return OsEventWrite(eventCB, events, FALSE);
}
-
+//LOS_EventDestroy()函数用于销毁事件控制块,将事件ID设置为0
LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB)
{
UINT32 intSave;
@@ -279,7 +280,7 @@ OUT:
LOS_TRACE(EVENT_DELETE, (UINTPTR)eventCB, ret);
return ret;
}
-
+//LOS_EventClear()函数用于清除指定的事件
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events)
{
UINT32 intSave;
@@ -296,18 +297,19 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events)
return LOS_OK;
}
-
+//OsEventWriteOnce()函数是事件写入的实现,与OsEventWrite()类似,但只写入一次
LITE_OS_SEC_TEXT_MINOR UINT32 OsEventWriteOnce(PEVENT_CB_S eventCB, UINT32 events)
{
return OsEventWrite(eventCB, events, TRUE);
}
#ifdef LOSCFG_COMPAT_POSIX
+//OsEventReadOnce()函数是事件读取的实现,与OsEventRead()类似,但只读取一次
LITE_OS_SEC_TEXT_MINOR UINT32 OsEventReadOnce(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout)
{
return OsEventRead(eventCB, eventMask, mode, timeout, TRUE);
}
-
+// /OsEventReadWithCond()函数用于根据条件读取事件,只有当条件满足时才进行事件读取操作
LITE_OS_SEC_TEXT UINT32 OsEventReadWithCond(const EventCond *cond, PEVENT_CB_S eventCB,
UINT32 eventMask, UINT32 mode, UINT32 timeout)
{
diff --git a/src/kernel/base/los_exc.c b/src/kernel/base/los_exc.c
index 71970f0..3ea59a0 100644
--- a/src/kernel/base/los_exc.c
+++ b/src/kernel/base/los_exc.c
@@ -25,7 +25,8 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
-
+/*这是关于LiteOS中异常处理的代码,其中包括记录异常信息、异常信息保存和读取等功能。
+同时还包括了一些与异常相关的函数,如打印异常信息、任务回溯等*/
#include "los_exc.h"
#include "los_printf_pri.h"
#include "los_task_pri.h"
@@ -48,7 +49,7 @@
extern "C" {
#endif
#endif /* __cplusplus */
-
+//ExcInfoDumpFormat的结构体类型,包含了用于存储异常信息的缓冲区指针、偏移量、长度和存储地址等信息
#ifdef LOSCFG_SHELL_EXCINFO_DUMP
typedef struct {
CHAR *buf; /* pointer to the buffer for storing the exception information */
@@ -56,11 +57,13 @@ typedef struct {
UINT32 len; /* the size of storing the exception information */
UINTPTR dumpAddr; /* the address of storing the exception information */
} ExcInfoDumpFormat;
-
+//全局变量g_excInfoPool,用于存储异常信息的缓冲区和相关的信息
STATIC ExcInfoDumpFormat g_excInfoPool = {0};
/* the hook of read-writing exception information */
STATIC __attribute__((section(".data"))) LogReadWriteFunc g_dumpHook = NULL;
-
+//LOS_ExcInfoRegHook:注册异常信息读写钩子函数,用于设置异常信息的存储地址、长度以及缓冲区等信息
+//"钩子函数"是指在特定事件发生时会被调用的函数
+//通过使用钩子函数,可以在异常发生时灵活地执行特定的操作,例如记录异常信息、进行特定的处理或通知其他模块进行相应的操作
VOID LOS_ExcInfoRegHook(UINTPTR startAddr, UINT32 len, CHAR *buf, LogReadWriteFunc hook)
{
if ((hook == NULL) || (buf == NULL)) {
@@ -78,57 +81,57 @@ VOID LOS_ExcInfoRegHook(UINTPTR startAddr, UINT32 len, CHAR *buf, LogReadWriteFu
g_excInfoPool.buf = buf;
g_dumpHook = hook;
}
-
+//OsSetExcInfoRW:设置异常信息读写钩子函数
VOID OsSetExcInfoRW(LogReadWriteFunc func)
{
g_dumpHook = func;
}
-
+//OsGetExcInfoRW:获取异常信息读写钩子函数
LogReadWriteFunc OsGetExcInfoRW(VOID)
{
return g_dumpHook;
}
-
+//OsSetExcInfoBuf:设置异常信息的缓冲区
VOID OsSetExcInfoBuf(CHAR *buf)
{
g_excInfoPool.buf = buf;
}
-
+//OsGetExcInfoBuf:获取异常信息的缓冲区
CHAR *OsGetExcInfoBuf(VOID)
{
return g_excInfoPool.buf;
}
-
+//OsSetExcInfoOffset:设置异常信息的偏移量
VOID OsSetExcInfoOffset(UINT32 Offset)
{
g_excInfoPool.offset = Offset;
}
-
+//OsGetExcInfoOffset:获取异常信息的偏移量
UINT32 OsGetExcInfoOffset(VOID)
{
return g_excInfoPool.offset;
}
-
+//OsSetExcInfoDumpAddr:设置异常信息的存储地址
VOID OsSetExcInfoDumpAddr(UINTPTR addr)
{
g_excInfoPool.dumpAddr = addr;
}
-
+//OsGetExcInfoDumpAddr:获取异常信息的存储地址
UINTPTR OsGetExcInfoDumpAddr(VOID)
{
return g_excInfoPool.dumpAddr;
}
-
+//OsSetExcInfoLen:设置异常信息的长度
VOID OsSetExcInfoLen(UINT32 len)
{
g_excInfoPool.len = len;
}
-
+//OsGetExcInfoLen:获取异常信息的长度
UINT32 OsGetExcInfoLen(VOID)
{
return g_excInfoPool.len;
}
-
+//WriteExcBufVa:将格式化的字符串写入异常信息缓冲区
VOID WriteExcBufVa(const CHAR *format, va_list arglist)
{
errno_t ret;
@@ -143,7 +146,7 @@ VOID WriteExcBufVa(const CHAR *format, va_list arglist)
g_excInfoPool.offset += ret;
}
}
-
+//WriteExcInfoToBuf:将格式化的字符串写入异常信息缓冲区
VOID WriteExcInfoToBuf(const CHAR *format, ...)
{
va_list arglist;
@@ -152,7 +155,7 @@ VOID WriteExcInfoToBuf(const CHAR *format, ...)
WriteExcBufVa(format, arglist);
va_end(arglist);
}
-
+//OsRecordExcInfoTime:记录异常信息的时间
VOID OsRecordExcInfoTime(VOID)
{
#define NOW_TIME_LENGTH 24
@@ -169,7 +172,7 @@ VOID OsRecordExcInfoTime(VOID)
#undef NOW_TIME_LENGTH
PrintExcInfo("%s \n", nowTime);
}
-
+//OsShellCmdReadExcInfo:读取并打印异常信息的Shell命令
#ifdef LOSCFG_SHELL
INT32 OsShellCmdReadExcInfo(INT32 argc, const CHAR **argv)
{
@@ -200,6 +203,9 @@ SHELLCMD_ENTRY(readExcInfo_shellcmd, CMD_TYPE_EX, "excInfo", 0, (CmdCallBackFunc
#endif
#ifdef LOSCFG_EXC_INTERACTION
+//OsCheckExcInteractionTask:检查任务是否为异常交互任务
+//异常交互任务通常指的是用于处理异常情况的特殊任务或线程
+//当系统发生严重的错误或异常时,需要立即采取相应的措施来处理异常情况,这就需要使用异常交互任务来处理
UINT32 OsCheckExcInteractionTask(const TSK_INIT_PARAM_S *initParam)
{
if ((initParam->pfnTaskEntry == (TSK_ENTRY_FUNC)ShellTask) ||
@@ -209,7 +215,7 @@ UINT32 OsCheckExcInteractionTask(const TSK_INIT_PARAM_S *initParam)
}
return LOS_NOK;
}
-
+//OsKeepExcInteractionTask:保留异常交互任务,删除其他任务
VOID OsKeepExcInteractionTask(VOID)
{
LosTaskCB *taskCB = NULL;
@@ -243,7 +249,7 @@ VOID OsKeepExcInteractionTask(VOID)
}
#endif
-
+//LOS_Panic:打印异常信息并停止CPU执行
VOID LOS_Panic(const CHAR *fmt, ...)
{
va_list ap;
@@ -252,7 +258,7 @@ VOID LOS_Panic(const CHAR *fmt, ...)
va_end(ap);
ArchHaltCpu();
}
-
+//LOS_BackTrace:打印当前任务的运行信息和回溯堆栈
VOID LOS_BackTrace(VOID)
{
#ifdef LOSCFG_BACKTRACE
@@ -262,7 +268,7 @@ VOID LOS_BackTrace(VOID)
ArchBackTrace();
#endif
}
-
+//LOS_TaskBackTrace:打印指定任务的运行信息和回溯堆栈
VOID LOS_TaskBackTrace(UINT32 taskID)
{
#ifdef LOSCFG_BACKTRACE
@@ -289,6 +295,7 @@ VOID LOS_TaskBackTrace(UINT32 taskID)
#ifdef __GNUC__
/* stack protector */
+//__stack_chk_fail:用于栈保护机制,当发现栈被破坏时触发异常处理
VOID __stack_chk_fail(VOID)
{
/* __builtin_return_address is a builtin function, building in gcc */
diff --git a/src/kernel/base/los_hwi.c b/src/kernel/base/los_hwi.c
index 0adc4f4..c620a44 100644
--- a/src/kernel/base/los_hwi.c
+++ b/src/kernel/base/los_hwi.c
@@ -25,7 +25,9 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
-
+/*
+关于LiteOS中硬件中断处理的部分,涉及了中断的注册、删除、触发、使能、禁止等操作
+*/
#include "los_hwi_pri.h"
#include "los_hwi.h"
#include "los_memory.h"
@@ -61,7 +63,7 @@ const HwiControllerOps *g_hwiOps = NULL;
typedef VOID (*HWI_PROC_FUNC0)(VOID);
typedef VOID (*HWI_PROC_FUNC2)(INT32, VOID *);
-
+//OsIrqNestingActive:用于在处理中断期间激活中断嵌套计数器,避免在处理时钟中断时进行抢占
STATIC INLINE VOID OsIrqNestingActive(UINT32 hwiNum)
{
#ifdef LOSCFG_ARCH_INTERRUPT_PREEMPTION
@@ -71,7 +73,7 @@ STATIC INLINE VOID OsIrqNestingActive(UINT32 hwiNum)
}
#endif
}
-
+//OsIrqNestingInactive:用于在处理中断结束后禁用中断嵌套计数器
STATIC INLINE VOID OsIrqNestingInactive(UINT32 hwiNum)
{
#ifdef LOSCFG_ARCH_INTERRUPT_PREEMPTION
@@ -80,17 +82,17 @@ STATIC INLINE VOID OsIrqNestingInactive(UINT32 hwiNum)
}
#endif
}
-
+//OsIrqNestingCntGet:获取当前CPU的中断嵌套计数值
size_t OsIrqNestingCntGet(VOID)
{
return g_intCount[ArchCurrCpuid()];
}
-
+//OsIrqNestingCntSet:设置当前CPU的中断嵌套计数值
VOID OsIrqNestingCntSet(size_t val)
{
g_intCount[ArchCurrCpuid()] = val;
}
-
+//InterruptHandle:处理中断的实际函数,根据中断号调用对应的中断处理函数
STATIC INLINE VOID InterruptHandle(HwiHandleInfo *hwiForm)
{
hwiForm->respCount++;
@@ -114,7 +116,7 @@ STATIC INLINE VOID InterruptHandle(HwiHandleInfo *hwiForm)
}
#endif
}
-
+//OsIntHandle:中断处理入口函数,负责处理中断前的一些准备工作,如调用中断处理前的钩子函数等
VOID OsIntHandle(UINT32 hwiNum, HwiHandleInfo *hwiForm)
{
size_t *intCnt = NULL;
@@ -148,7 +150,7 @@ VOID OsIntHandle(UINT32 hwiNum, HwiHandleInfo *hwiForm)
OsCpupIrqEnd(hwiNum);
#endif
}
-
+//OsIntEntry:中断向量入口函数,根据中断号调用对应的中断处理函数
VOID OsIntEntry(VOID)
{
if ((g_hwiOps != NULL) && (g_hwiOps->handleIrq != NULL)) {
@@ -156,7 +158,7 @@ VOID OsIntEntry(VOID)
}
return;
}
-
+//OsHwiCpIrqParam:根据传入的中断参数结构体分配内存,并将参数信息拷贝到新分配的内存中
STATIC HWI_ARG_T OsHwiCpIrqParam(const HWI_IRQ_PARAM_S *irqParam)
{
HWI_IRQ_PARAM_S *paramByAlloc = NULL;
@@ -169,6 +171,7 @@ STATIC HWI_ARG_T OsHwiCpIrqParam(const HWI_IRQ_PARAM_S *irqParam)
return (HWI_ARG_T)paramByAlloc;
}
#ifndef LOSCFG_SHARED_IRQ
+//OsHwiDel:删除指定的中断处理函数
STATIC UINT32 OsHwiDel(HwiHandleInfo *hwiForm, const HWI_IRQ_PARAM_S *irqParam, UINT32 irqId)
{
UINT32 intSave;
@@ -190,7 +193,7 @@ STATIC UINT32 OsHwiDel(HwiHandleInfo *hwiForm, const HWI_IRQ_PARAM_S *irqParam,
HWI_UNLOCK(intSave);
return LOS_OK;
}
-
+//OsHwiCreate:创建中断处理函数,并将其添加到中断处理链表中
STATIC UINT32 OsHwiCreate(HwiHandleInfo *hwiForm, HWI_MODE_T hwiMode, HWI_PROC_FUNC hwiHandler,
const HWI_IRQ_PARAM_S *irqParam)
{
@@ -218,6 +221,7 @@ STATIC UINT32 OsHwiCreate(HwiHandleInfo *hwiForm, HWI_MODE_T hwiMode, HWI_PROC_F
return LOS_OK;
}
#else /* LOSCFG_SHARED_IRQ */
+//函数OsFreeHwiNode:用于释放中断处理函数节点,并在需要时禁止该中断
STATIC INLINE UINT32 OsFreeHwiNode(HwiHandleInfo *head, HwiHandleInfo *hwiForm, UINT32 irqId)
{
UINT32 ret = LOS_OK;
@@ -240,7 +244,8 @@ STATIC INLINE UINT32 OsFreeHwiNode(HwiHandleInfo *head, HwiHandleInfo *hwiForm,
return ret;
}
-
+//OsHwiDel:用于删除硬件中断处理函数,它首先判断中断是否是共享中断
+//如果不是,则直接释放该中断的处理函数节点;如果是共享中断,则遍历链表找到对应的设备ID,然后释放该中断的处理函数节点
STATIC UINT32 OsHwiDel(HwiHandleInfo *head, const HWI_IRQ_PARAM_S *irqParam, UINT32 irqId)
{
HwiHandleInfo *hwiFormPrev = NULL;
@@ -290,7 +295,8 @@ STATIC UINT32 OsHwiDel(HwiHandleInfo *head, const HWI_IRQ_PARAM_S *irqParam, UIN
HWI_UNLOCK(intSave);
return ret;
}
-
+//OsHwiCreate:用于创建硬件中断处理函数,它首先判断中断是否是共享中断,并检查是否已经存在具有相同设备ID的中断处理函数节点,如果存在则返回错误
+//然后申请内存并初始化新的中断处理函数节点,将其添加到链表中
STATIC UINT32 OsHwiCreate(HwiHandleInfo *head, HWI_MODE_T hwiMode, HWI_PROC_FUNC hwiHandler,
const HWI_IRQ_PARAM_S *irqParam)
{
@@ -359,7 +365,9 @@ size_t IntActive()
LOS_IntRestore(intSave);
return intCount;
}
-
+//LOS_HwiCreate 函数:用于创建硬件中断处理函数
+//它会注册一个中断处理函数,并将其与指定的硬件中断号相关联
+//可以设置中断的优先级、硬件中断模式和处理函数
LITE_OS_SEC_TEXT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
HWI_PRIOR_T hwiPrio,
HWI_MODE_T hwiMode,
@@ -396,7 +404,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
}
return ret;
}
-
+//LOS_HwiDelete 函数:用于删除已经创建的硬件中断处理函数
+//通过指定硬件中断号,可以将之前注册的中断处理函数从系统中删除
LITE_OS_SEC_TEXT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S *irqParam)
{
UINT32 ret;
@@ -417,7 +426,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S *irqP
return ret;
}
-
+//LOS_HwiTrigger 函数:用于手动触发指定的硬件中断
+//调用该函数后,会立即触发对应的硬件中断,使得系统执行相应的中断处理函数
LITE_OS_SEC_TEXT UINT32 LOS_HwiTrigger(HWI_HANDLE_T hwiNum)
{
if ((g_hwiOps == NULL) || (g_hwiOps->triggerIrq == NULL)) {
@@ -427,7 +437,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiTrigger(HWI_HANDLE_T hwiNum)
return g_hwiOps->triggerIrq(hwiNum);
}
-
+//LOS_HwiEnable 函数:用于使能指定的硬件中断
+//调用该函数后,系统将允许对应的硬件中断产生,并执行相应的中断处理函数
LITE_OS_SEC_TEXT UINT32 LOS_HwiEnable(HWI_HANDLE_T hwiNum)
{
if ((g_hwiOps == NULL) || (g_hwiOps->enableIrq == NULL)) {
@@ -437,7 +448,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiEnable(HWI_HANDLE_T hwiNum)
return g_hwiOps->enableIrq(hwiNum);
}
-
+//LOS_HwiDisable 函数:用于禁止指定的硬件中断
+//调用该函数后,系统将阻止对应的硬件中断产生,屏蔽其影响
LITE_OS_SEC_TEXT UINT32 LOS_HwiDisable(HWI_HANDLE_T hwiNum)
{
if ((g_hwiOps == NULL) || (g_hwiOps->disableIrq == NULL)) {
@@ -447,7 +459,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiDisable(HWI_HANDLE_T hwiNum)
return g_hwiOps->disableIrq(hwiNum);
}
-
+//LOS_HwiClear 函数:用于清除指定的硬件中断
+//在某些平台上,硬件中断发生后可能需要手动清除中断标志位,以便正确处理后续的中断
LITE_OS_SEC_TEXT UINT32 LOS_HwiClear(HWI_HANDLE_T hwiNum)
{
if ((g_hwiOps == NULL) || (g_hwiOps->clearIrq == NULL)) {
@@ -457,7 +470,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiClear(HWI_HANDLE_T hwiNum)
return g_hwiOps->clearIrq(hwiNum);
}
-
+//LOS_HwiSetPriority 函数:用于设置硬件中断的优先级
+//通过指定硬件中断号和优先级,可以调整硬件中断的触发顺序
LITE_OS_SEC_TEXT UINT32 LOS_HwiSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority)
{
if ((g_hwiOps == NULL) || (g_hwiOps->setIrqPriority == NULL)) {
@@ -468,6 +482,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T prio
return g_hwiOps->setIrqPriority(hwiNum, priority);
}
#ifdef LOSCFG_KERNEL_SMP
+//LOS_HwiSetAffinity函数:用于设置硬件中断的处理CPU亲和性
+//它首先检查硬件中断操作函数指针是否为空,然后调用具体的操作函数来设置中断的处理CPU亲和性
LITE_OS_SEC_TEXT UINT32 LOS_HwiSetAffinity(HWI_HANDLE_T hwiNum, UINT32 cpuMask)
{
if ((g_hwiOps == NULL) || (g_hwiOps->setIrqCpuAffinity == NULL)) {
@@ -477,7 +493,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiSetAffinity(HWI_HANDLE_T hwiNum, UINT32 cpuMask)
return g_hwiOps->setIrqCpuAffinity(hwiNum, cpuMask);
}
-
+//LOS_HwiSendIpi函数:用于发送硬件中断处理请求给指定的CPU
+//它首先检查硬件中断操作函数指针是否为空,然后调用具体的操作函数来发送中断处理请求
LITE_OS_SEC_TEXT UINT32 LOS_HwiSendIpi(HWI_HANDLE_T hwiNum, UINT32 cpuMask)
{
if ((g_hwiOps == NULL) || (g_hwiOps->sendIpi == NULL)) {
@@ -490,6 +507,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiSendIpi(HWI_HANDLE_T hwiNum, UINT32 cpuMask)
#endif
#ifdef LOSCFG_KERNEL_LOWPOWER
+//LOS_IntWakeupHookReg函数:用于注册中断唤醒回调函数
+//它将传入的回调函数赋值给全局变量g_intWakeupHook,以便在中断唤醒时调用该回调函数
LITE_OS_SEC_TEXT_MINOR VOID LOS_IntWakeupHookReg(WAKEUPFROMINTHOOK hook)
{
g_intWakeupHook = hook;
@@ -497,6 +516,8 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_IntWakeupHookReg(WAKEUPFROMINTHOOK hook)
#endif
/* Initialization of the hardware interrupt */
+//OsHwiInit函数:用于初始化硬件中断
+//它会调用具体的平台相关函数来进行硬件中断的初始化操作
LITE_OS_SEC_TEXT_INIT VOID OsHwiInit(VOID)
{
ArchIrqInit();
diff --git a/src/kernel/base/los_lockdep.c b/src/kernel/base/los_lockdep.c
index 7c65cf1..b4826f0 100644
--- a/src/kernel/base/los_lockdep.c
+++ b/src/kernel/base/los_lockdep.c
@@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
-
+/*这段代码是关于锁依赖检查的实现。包含了一些头文件和函数的定义,用于在多核系统中检测锁的使用情况*/
#include "los_base.h"
#include "los_spinlock.h"
#include "los_task_pri.h"
@@ -47,6 +47,8 @@ extern "C" {
STATIC Atomic g_lockdepAvailable = 1;
/* atomic insurance for lockdep check */
+//OsLockDepRequire:该函数用于获取锁依赖检查的原子操作,确保在进行锁依赖检查时不会被中断
+//原子操作是指在计算机科学中,不会被中断的操作
STATIC INLINE VOID OsLockDepRequire(UINT32 *intSave)
{
*intSave = LOS_IntLock();
@@ -54,13 +56,13 @@ STATIC INLINE VOID OsLockDepRequire(UINT32 *intSave)
/* busy waiting */
}
}
-
+//OsLockDepRelease:释放锁依赖检查的原子操作,用于在完成锁依赖检查后恢复正常的中断状态
STATIC INLINE VOID OsLockDepRelease(UINT32 intSave)
{
LOS_AtomicSet(&g_lockdepAvailable, 1);
LOS_IntRestore(intSave);
}
-
+//OsLockDepGetCycles:获取当前 CPU 的周期计数器的值,用于记录锁请求和释放时的时间戳
STATIC INLINE UINT64 OsLockDepGetCycles(VOID)
{
UINT32 high, low;
@@ -69,7 +71,7 @@ STATIC INLINE UINT64 OsLockDepGetCycles(VOID)
/* combine cycleHi and cycleLo into 8 bytes cycles */
return (((UINT64)high << 32) + low);
}
-
+//OsLockDepErrorStringGet:根据错误类型返回对应的错误字符串,用于打印错误信息
STATIC INLINE CHAR *OsLockDepErrorStringGet(enum LockDepErrType type)
{
CHAR *errorString = NULL;
@@ -94,7 +96,7 @@ STATIC INLINE CHAR *OsLockDepErrorStringGet(enum LockDepErrType type)
return errorString;
}
-
+//OsLockDepPanic:当发生严重错误时触发系统的崩溃,通常在检测到死锁等无法修复的情况下调用
WEAK VOID OsLockDepPanic(enum LockDepErrType errType)
{
/* halt here */
@@ -103,7 +105,7 @@ WEAK VOID OsLockDepPanic(enum LockDepErrType errType)
OsBackTrace();
while (1) {}
}
-
+//OsLockDepDumpLock:输出锁依赖检查失败时的调试信息,包括任务名、任务 ID、CPU 号等,并最终触发崩溃
STATIC VOID OsLockDepDumpLock(const LosTaskCB *task, const SPIN_LOCK_S *lock,
const VOID *requestAddr, enum LockDepErrType errType)
{
@@ -143,7 +145,7 @@ STATIC VOID OsLockDepDumpLock(const LosTaskCB *task, const SPIN_LOCK_S *lock,
OsLockDepPanic(errType);
}
-
+//OsLockDepCheckDependancy:检查当前任务与锁的所有者之间是否存在依赖关系,以避免死锁
STATIC BOOL OsLockDepCheckDependancy(const LosTaskCB *current, const LosTaskCB *lockOwner)
{
BOOL checkResult = TRUE;
@@ -164,7 +166,7 @@ STATIC BOOL OsLockDepCheckDependancy(const LosTaskCB *current, const LosTaskCB *
return checkResult;
}
-
+//OsLockDepCheckIn:在请求锁时进行依赖检查,记录锁的请求地址和等待时间,如检查失败则触发崩溃
VOID OsLockDepCheckIn(const SPIN_LOCK_S *lock)
{
UINT32 intSave;
@@ -217,7 +219,7 @@ OUT:
OsLockDepRelease(intSave);
}
-
+//OsLockDepRecord:记录成功获取锁的时间戳和持有者信息,并更新锁的所有者和 CPU 号等信息
VOID OsLockDepRecord(SPIN_LOCK_S *lock)
{
UINT32 intSave;
@@ -250,7 +252,7 @@ VOID OsLockDepRecord(SPIN_LOCK_S *lock)
OsLockDepRelease(intSave);
}
-
+//OsLockDepCheckOut:在释放锁时进行依赖检查,记录持有时间并清除相关信息,如检查失败则触发崩溃
VOID OsLockDepCheckOut(SPIN_LOCK_S *lock)
{
UINT32 intSave;
@@ -302,7 +304,8 @@ VOID OsLockDepCheckOut(SPIN_LOCK_S *lock)
OUT:
OsLockDepRelease(intSave);
}
-
+//OsLockdepClearSpinlocks:清除当前任务持有的所有自旋锁,通常在系统处于异常状态下调用以确保解锁
+//自旋锁是一种用于多线程同步的机制。在使用自旋锁时,线程会反复检查锁是否被释放,如果锁已经被占用,线程就会一直循环等待,直到锁被释放为止
VOID OsLockdepClearSpinlocks(VOID)
{
LosTaskCB *task = OsCurrTaskGet();
diff --git a/src/kernel/base/los_misc.c b/src/kernel/base/los_misc.c
index 3cbe7fc..6e495c5 100644
--- a/src/kernel/base/los_misc.c
+++ b/src/kernel/base/los_misc.c
@@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
-
+//操作系统的基础函数
#include "los_task_pri.h"
#include "los_misc_pri.h"
#include "los_memory_pri.h"
@@ -48,23 +48,23 @@ extern "C" {
#endif /* __cplusplus */
#ifdef LOSCFG_LIB_CONFIGURABLE
-LITE_OS_SEC_BSS UINT32 g_osSysClock;
-LITE_OS_SEC_BSS UINT32 g_semLimit;
-LITE_OS_SEC_BSS UINT32 g_muxLimit;
-LITE_OS_SEC_BSS UINT32 g_queueLimit;
-
-LITE_OS_SEC_BSS UINT32 g_swtmrLimit;
-LITE_OS_SEC_BSS UINT32 g_taskLimit;
-LITE_OS_SEC_BSS UINT32 g_minusOneTickPerSecond;
-LITE_OS_SEC_BSS UINT32 g_taskMinStkSize;
-LITE_OS_SEC_BSS UINT32 g_taskIdleStkSize;
-LITE_OS_SEC_BSS UINT32 g_taskSwtmrStkSize;
-LITE_OS_SEC_BSS UINT32 g_taskDfltStkSize;
-LITE_OS_SEC_BSS UINT32 g_timeSliceTimeOut;
-
-LITE_OS_SEC_DATA BOOL g_nxEnabled = FALSE;
-LITE_OS_SEC_BSS UINTPTR g_dlNxHeapBase;
-LITE_OS_SEC_BSS UINT32 g_dlNxHeapSize;
+LITE_OS_SEC_BSS UINT32 g_osSysClock; //操作系统的系统时钟频率
+LITE_OS_SEC_BSS UINT32 g_semLimit; //信号量的最大数量限制
+LITE_OS_SEC_BSS UINT32 g_muxLimit; //互斥锁的最大数量限制
+LITE_OS_SEC_BSS UINT32 g_queueLimit; //队列最大数量限制
+
+LITE_OS_SEC_BSS UINT32 g_swtmrLimit; //软件定时器的最大数量限制
+LITE_OS_SEC_BSS UINT32 g_taskLimit; //任务的最大数量限制
+LITE_OS_SEC_BSS UINT32 g_minusOneTickPerSecond; //每秒减去的滴答数,用于时间戳计算
+LITE_OS_SEC_BSS UINT32 g_taskMinStkSize;//任务的最小堆栈大小
+LITE_OS_SEC_BSS UINT32 g_taskIdleStkSize; //空闲任务的堆栈大小
+LITE_OS_SEC_BSS UINT32 g_taskSwtmrStkSize; //软件定时器任务的堆栈大小
+LITE_OS_SEC_BSS UINT32 g_taskDfltStkSize; //默认任务的堆栈大小
+LITE_OS_SEC_BSS UINT32 g_timeSliceTimeOut; //时间片的超时时间
+
+LITE_OS_SEC_DATA BOOL g_nxEnabled = FALSE; //是否启用了内存保护机制
+LITE_OS_SEC_BSS UINTPTR g_dlNxHeapBase; //动态加载库的内存堆起始地址
+LITE_OS_SEC_BSS UINT32 g_dlNxHeapSize; //动态加载库的内存堆大小
#endif
#ifdef LOSCFG_KERNEL_TRACE
@@ -77,11 +77,12 @@ LMS_INIT_HOOK g_lmsMemInitHook = NULL;
LMS_FUNC_HOOK g_lmsMallocHook = NULL;
LMS_FUNC_HOOK g_lmsFreeHook = NULL;
#endif
+//LOS_Align:用于将给定的地址按指定的边界对齐,返回对齐后的地址
LITE_OS_SEC_TEXT UINTPTR LOS_Align(UINTPTR addr, UINT32 boundary)
{
return (addr + boundary - 1) & ~((UINTPTR)(boundary - 1));
}
-
+//OsDumpMemByte:用于以字节为单位打印内存中的数据
LITE_OS_SEC_TEXT_MINOR VOID LOS_Msleep(UINT32 msecs)
{
UINT32 interval;
@@ -97,7 +98,7 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_Msleep(UINT32 msecs)
(VOID)LOS_TaskDelay(interval);
}
-
+//OsDumpMemByte:用于以字节为单位打印内存中的数据
VOID OsDumpMemByte(size_t length, UINTPTR addr)
{
size_t dataLen;
@@ -141,6 +142,7 @@ VOID OsDumpMemByte(size_t length, UINTPTR addr)
}
#if defined(LOSCFG_DEBUG_SEMAPHORE) || defined(LOSCFG_DEBUG_MUTEX) || defined(LOSCFG_DEBUG_QUEUE)
+//OsArraySort:快速排序
VOID OsArraySort(UINT32 *sortArray, UINT32 start, UINT32 end,
const SortParam *sortParam, OsCompareFunc compareFunc)
{
diff --git a/src/kernel/base/los_mp.c b/src/kernel/base/los_mp.c
index d176a17..ba29cd8 100644
--- a/src/kernel/base/los_mp.c
+++ b/src/kernel/base/los_mp.c
@@ -25,7 +25,8 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
-
+/*针对多处理器(SMP)系统的操作系统内核部分的实现
+主要包括了多处理器调度、任务管理和中断处理等功能*/
#include "los_mp_pri.h"
#include "los_task_pri.h"
#include "los_percpu_pri.h"
@@ -45,7 +46,7 @@ LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_mpCallSpin);
#define MP_CALL_LOCK(state) LOS_SpinLockSave(&g_mpCallSpin, &(state))
#define MP_CALL_UNLOCK(state) LOS_SpinUnlockRestore(&g_mpCallSpin, (state))
#endif
-
+//LOS_MpSchedule:多处理器调度函数,用于向指定的处理器发送调度中断
VOID LOS_MpSchedule(UINT32 target)
{
UINT32 ret;
@@ -57,12 +58,12 @@ VOID LOS_MpSchedule(UINT32 target)
}
return;
}
-
+//OsMpWakeHandler:多处理器唤醒处理函数,目前为空实现,无特定操作
VOID OsMpWakeHandler(VOID)
{
/* generic wakeup ipi, do nothing */
}
-
+//OsMpScheduleHandler:多处理器调度处理函数,设置调度标志以触发调度器在中断结束时执行调度
VOID OsMpScheduleHandler(VOID)
{
/*
@@ -71,7 +72,7 @@ VOID OsMpScheduleHandler(VOID)
*/
OsPercpuGet()->schedFlag = INT_PEND_RESCH;
}
-
+//OsMpHaltHandler:多处理器停机处理函数,将当前处理器标记为已停机状态,并进入死循环
VOID OsMpHaltHandler(VOID)
{
(VOID)LOS_IntLock();
@@ -79,7 +80,7 @@ VOID OsMpHaltHandler(VOID)
while (1) {}
}
-
+//OsMpCollectTasks:多处理器任务回收函数,用于递归检查所有可用任务,并删除标记为需要销毁的任务
VOID OsMpCollectTasks(VOID)
{
LosTaskCB *taskCB = NULL;
@@ -109,6 +110,7 @@ VOID OsMpCollectTasks(VOID)
}
#ifdef LOSCFG_KERNEL_SMP_CALL
+//OsMpFuncCall:多处理器函数调用函数,用于向指定的处理器发送函数调用请求
VOID OsMpFuncCall(UINT32 target, SMP_FUNC_CALL func, VOID *args)
{
UINT32 index;
@@ -144,7 +146,7 @@ VOID OsMpFuncCall(UINT32 target, SMP_FUNC_CALL func, VOID *args)
}
return;
}
-
+//OsMpFuncCallHandler:多处理器函数调用处理函数,从本处理器的函数调用队列中取出并执行函数调用请求
VOID OsMpFuncCallHandler(VOID)
{
UINT32 intSave;
@@ -166,7 +168,7 @@ VOID OsMpFuncCallHandler(VOID)
}
MP_CALL_UNLOCK(intSave);
}
-
+//OsMpFuncCallInit:多处理器函数调用初始化函数,用于初始化每个核心的函数调用队列
VOID OsMpFuncCallInit(VOID)
{
UINT32 index;
@@ -176,7 +178,7 @@ VOID OsMpFuncCallInit(VOID)
}
}
#endif /* LOSCFG_KERNEL_SMP_CALL */
-
+//OsMpInit:多处理器初始化函数,包括创建周期性软件定时器和初始化函数调用队列等
UINT32 OsMpInit(VOID)
{
UINT16 swtmrId;
diff --git a/src/kernel/base/los_mux.c b/src/kernel/base/los_mux.c
index 25dbacc..31bb6df 100644
--- a/src/kernel/base/los_mux.c
+++ b/src/kernel/base/los_mux.c
@@ -25,7 +25,8 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
-
+/*代码实现了一个简单的互斥锁(Mutex),用于保护共享资源的访问
+互斥锁的主要功能是确保在同一时间只有一个线程可以访问被保护的代码块或共享资源,从而避免并发访问引发的数据竞争和不一致性*/
#include "los_mux_pri.h"
#include "los_mux_debug_pri.h"
#include "los_bitmap.h"
@@ -49,6 +50,7 @@ LITE_OS_SEC_DATA_INIT STATIC LOS_DL_LIST g_unusedMuxList;
* Description : Initializes the mutex
* Return : LOS_OK on success, or error code on failure
*/
+//OsMuxInit:Mutex初始化函数,用于初始化Mutex数据结构并设置初始状态
LITE_OS_SEC_TEXT UINT32 OsMuxInit(VOID)
{
LosMuxCB *muxNode = NULL;
@@ -74,7 +76,7 @@ LITE_OS_SEC_TEXT UINT32 OsMuxInit(VOID)
}
return LOS_OK;
}
-
+//LOS_MuxCreate:创建Mutex函数,用于创建一个新的Mutex对象,并返回其句柄
LITE_OS_SEC_TEXT UINT32 LOS_MuxCreate(UINT32 *muxHandle)
{
UINT32 intSave;
@@ -113,7 +115,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxCreate(UINT32 *muxHandle)
ERR_HANDLER:
OS_RETURN_ERROR_P2(errLine, errNo);
}
-
+//LOS_MuxDelete:删除Mutex函数,用于删除指定的Mutex对象及其相关资源
LITE_OS_SEC_TEXT UINT32 LOS_MuxDelete(UINT32 muxHandle)
{
UINT32 intSave;
@@ -154,7 +156,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxDelete(UINT32 muxHandle)
ERR_HANDLER:
OS_RETURN_ERROR_P2(errLine, errNo);
}
-
+//OsMuxParaCheck 函数主要用于验证互斥量操作的参数是否有效,包括互斥量是否被正确创建和传入的句柄是否有效,以及当前是否处于中断上下文
LITE_OS_SEC_TEXT STATIC UINT32 OsMuxParaCheck(const LosMuxCB *muxCB, UINT32 muxHandle)
{
if ((muxCB->muxStat == LOS_UNUSED) || (muxCB->muxId != muxHandle)) {
@@ -168,7 +170,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsMuxParaCheck(const LosMuxCB *muxCB, UINT32 muxH
}
return LOS_OK;
}
-
+//OsMuxBitmapSet 函数用于在互斥量等待队列中设置任务的优先级位图,并根据需要调整任务的优先级,以确保任务在等待互斥量时能够正确反映其优先级关系
LITE_OS_SEC_TEXT STATIC VOID OsMuxBitmapSet(const LosTaskCB *runTask, const MuxBaseCB *muxPended)
{
if (muxPended->owner->priority > runTask->priority) {
@@ -176,7 +178,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsMuxBitmapSet(const LosTaskCB *runTask, const MuxB
OsTaskPriModify(muxPended->owner, runTask->priority);
}
}
-
+//OsMuxBitmapRestore 函数用于恢复任务的优先级位图,并根据需要更新拥有者任务的优先级
LITE_OS_SEC_TEXT STATIC VOID OsMuxBitmapRestore(const LosTaskCB *runTask, LosTaskCB *owner)
{
UINT16 bitMapPri;
@@ -244,7 +246,8 @@ LITE_OS_SEC_TEXT STATIC LOS_DL_LIST *OsMuxPendFindPos(const LosTaskCB *runTask,
return node;
}
#endif
-
+//总体来说,OsMuxPostOp 函数用于处理 Mutex 的释放操作,包括唤醒等待任务、更新 Mutex 状态和持有者等
+//确保 Mutex 能够按照预期的方式被正确释放和传递给下一个任务
LITE_OS_SEC_TEXT UINT32 OsMuxPendOp(LosTaskCB *runTask, MuxBaseCB *muxPended, UINT32 timeout,
UINT32 *intSave)
{
@@ -270,7 +273,7 @@ LITE_OS_SEC_TEXT UINT32 OsMuxPendOp(LosTaskCB *runTask, MuxBaseCB *muxPended, UI
return ret;
}
-
+//LOS_MuxPend:等待Mutex函数,用于尝试获取指定Mutex的访问权限。如果Mutex已被其他任务持有,则当前任务会被挂起,直到Mutex可用
LITE_OS_SEC_TEXT UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout)
{
UINT32 ret;
@@ -332,7 +335,7 @@ OUT_UNLOCK:
}
return ret;
}
-
+//OsMuxPostOpSub:通过比较当前任务和 Mutex 等待队列中的任务的优先级,来调整当前任务的优先级位图,并将 Mutex 持有者的优先级提升
LITE_OS_SEC_TEXT STATIC VOID OsMuxPostOpSub(LosTaskCB *runTask, MuxBaseCB *muxPosted)
{
LosTaskCB *pendedTask = NULL;
@@ -350,7 +353,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsMuxPostOpSub(LosTaskCB *runTask, MuxBaseCB *muxPo
LOS_BitmapClr(&runTask->priBitMap, bitMapPri);
OsTaskPriModify(muxPosted->owner, bitMapPri);
}
-
+//
LITE_OS_SEC_TEXT UINT32 OsMuxPostOp(LosTaskCB *runTask, MuxBaseCB *muxPosted)
{
LosTaskCB *resumedTask = NULL;
@@ -386,7 +389,7 @@ LITE_OS_SEC_TEXT UINT32 OsMuxPostOp(LosTaskCB *runTask, MuxBaseCB *muxPosted)
return MUX_SCHEDULE;
}
-
+//LOS_MuxPost:释放Mutex函数,用于释放当前任务对指定Mutex的访问权限,以便其他任务可以获取该Mutex
LITE_OS_SEC_TEXT UINT32 LOS_MuxPost(UINT32 muxHandle)
{
UINT32 ret;
diff --git a/src/kernel/base/los_percpu.c b/src/kernel/base/los_percpu.c
index 7110c08..c7e0782 100644
--- a/src/kernel/base/los_percpu.c
+++ b/src/kernel/base/los_percpu.c
@@ -33,7 +33,7 @@
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-
+//定义全局变量数组,用于存储每个CPU核心的私有数据
Percpu g_percpu[LOSCFG_KERNEL_CORE_NUM];
#ifdef __cplusplus
diff --git a/src/kernel/base/los_printf.c b/src/kernel/base/los_printf.c
index 6457a4d..7974cb3 100644
--- a/src/kernel/base/los_printf.c
+++ b/src/kernel/base/los_printf.c
@@ -32,7 +32,7 @@
* It should not add OS inner invocation, which is not allowed to be accessed in user space.
* But it's allowed to invoke syscall interface.
*---------------------------------------------------------------------------- */
-
+/*这段代码是一个输出控制模块,根据不同的输出类型将字符串输出到不同的设备上*/
#ifdef LOSCFG_LIB_LIBC
#include "unistd.h"
#endif
@@ -62,13 +62,13 @@ typedef enum {
CONSOLE_OUTPUT = 2,
EXC_OUTPUT = 3
} OutputType;
-
+//ErrorMsg:用于输出错误信息,当字符串输出非法或者vsnprintf_s函数失败时调用
STATIC VOID ErrorMsg(VOID)
{
const CHAR *p = "Output illegal string! vsnprintf_s failed!\n";
UartPuts(p, (UINT32)strlen(p), UART_WITH_LOCK);
}
-
+//UartOutput:实际将字符串输出到串口的函数,根据配置可能会进行一些额外的处理
STATIC VOID UartOutput(const CHAR *str, UINT32 len, BOOL isLock)
{
#ifdef LOSCFG_SHELL_DMESG
@@ -82,7 +82,7 @@ STATIC VOID UartOutput(const CHAR *str, UINT32 len, BOOL isLock)
UartPuts(str, len, isLock);
#endif
}
-
+//OutputControl:根据输出类型选择相应的输出设备,并调用对应的输出函数
STATIC VOID OutputControl(const CHAR *str, UINT32 len, OutputType type)
{
switch (type) {
@@ -105,14 +105,14 @@ STATIC VOID OutputControl(const CHAR *str, UINT32 len, OutputType type)
}
return;
}
-
+//OsVprintfFree:释放动态分配的缓冲区内存
STATIC VOID OsVprintfFree(CHAR *buf, UINT32 bufLen)
{
if (bufLen != SIZEBUF) {
(VOID)LOS_MemFree(m_aucSysMem0, buf);
}
}
-
+//OsVprintf:核心函数,根据给定的格式化字符串和可变参数,进行字符串格式化并输出到相应的设备
STATIC VOID OsVprintf(const CHAR *fmt, va_list ap, OutputType type)
{
INT32 len;
@@ -156,7 +156,7 @@ STATIC VOID OsVprintf(const CHAR *fmt, va_list ap, OutputType type)
OutputControl(bBuf, len, type);
OsVprintfFree(bBuf, bufLen);
}
-
+//UartVprintf、ConsoleVprintf、UartPrintf、dprintf、LkDprintf、DmesgPrintf、ExcPrintf、PrintExcInfo:这些函数都是对OsVprintf的封装,提供了不同的输出接口,在不同的场景下调用OsVprintf来完成字符串的格式化和输出
VOID UartVprintf(const CHAR *fmt, va_list ap)
{
OsVprintf(fmt, ap, UART_OUTPUT);
From d4596b7503d88e09b5535f3332c67d13c89fddde Mon Sep 17 00:00:00 2001
From: faj <1900949849@qq.com>
Date: Mon, 27 Nov 2023 19:56:08 +0800
Subject: [PATCH 05/26] 1
---
src/kernel/include/arch_generic/atomic.h | 55 +++-
src/kernel/include/console.h | 132 ++++-----
src/kernel/include/los_atomic.h | 46 +--
src/kernel/include/los_base.h | 43 ++-
src/kernel/include/los_bitmap.h | 21 +-
src/kernel/include/los_builddef.h | 42 +--
src/kernel/include/los_config.h | 216 ++++++++------
src/kernel/include/los_cppsupport.h | 16 +
src/kernel/include/los_cpup.h | 41 +++
src/kernel/include/los_err.h | 20 +-
src/kernel/include/los_errno.h | 52 +++-
src/kernel/include/los_event.h | 162 ++++++++++-
src/kernel/include/los_exc.h | 75 ++++-
src/kernel/include/los_hw.h | 3 +-
src/kernel/include/los_hwi.h | 353 ++++++++++++++++++++++-
15 files changed, 1049 insertions(+), 228 deletions(-)
diff --git a/src/kernel/include/arch_generic/atomic.h b/src/kernel/include/arch_generic/atomic.h
index 2b68336..81dc858 100644
--- a/src/kernel/include/arch_generic/atomic.h
+++ b/src/kernel/include/arch_generic/atomic.h
@@ -31,6 +31,7 @@
* @ingroup kernel
*/
+//LiteOSϵͳУatomic.hͷļͨṩԭӲ֧֡ԭӲDzжϵIJȷڶ̻߳жԹԴаȫķʺġ
#ifndef _ARCH_GENERIC_ATOMIC_H
#define _ARCH_GENERIC_ATOMIC_H
@@ -44,17 +45,26 @@ extern "C" {
#endif /* __cplusplus */
#ifndef LOSCFG_KERNEL_SMP
-
+/*ArchAtomicRead ԭӶȡһֵ
+һָԭӱָ v ǿתΪ volatile INT32 ͵ָ룬
+ظֵָָ*/
STATIC INLINE INT32 ArchAtomicRead(const Atomic *v)
{
return *(volatile INT32 *)v;
}
+/*ArchAtomicSet ԭһֵ
+һָԭӱָ v ǿתΪ volatile INT32 ͵ָ룬
+ setVal ֵָָı*/
STATIC INLINE VOID ArchAtomicSet(Atomic *v, INT32 setVal)
{
*(volatile INT32 *)v = setVal;
}
+/*ArchAtomicAdd ԭһֵ
+ȱ浱ǰж״̬Ȼڹرжϵ£ addVal ӵָ v ָıϣ
+Ӻֵ
+ָ֮ǰж״̬*/
STATIC INLINE INT32 ArchAtomicAdd(Atomic *v, INT32 addVal)
{
UINT32 intSave;
@@ -66,6 +76,9 @@ STATIC INLINE INT32 ArchAtomicAdd(Atomic *v, INT32 addVal)
return *v;
}
+/*ArchAtomicSub ԭӼһֵ
+ʵ ArchAtomicAdd ƣ
+ֻǽ subVal ȥָ v ָı*/
STATIC INLINE INT32 ArchAtomicSub(Atomic *v, INT32 subVal)
{
UINT32 intSave;
@@ -77,6 +90,10 @@ STATIC INLINE INT32 ArchAtomicSub(Atomic *v, INT32 subVal)
return *v;
}
+/*ArchAtomicInc ԭһֵ
+ȱ浱ǰж״̬ intSaveȻڹرжϵ£
+ָ addr ָı 1
+ָ֮ǰж״̬*/
STATIC INLINE VOID ArchAtomicInc(Atomic *addr)
{
UINT32 intSave;
@@ -86,6 +103,7 @@ STATIC INLINE VOID ArchAtomicInc(Atomic *addr)
LOS_IntRestore(intSave);
}
+//ArchAtomicIncRet ArchAtomicInc ƣӺıֵ
STATIC INLINE INT32 ArchAtomicIncRet(Atomic *addr)
{
UINT32 intSave;
@@ -96,6 +114,7 @@ STATIC INLINE INT32 ArchAtomicIncRet(Atomic *addr)
return *addr;
}
+//ArchAtomicDec ԭӼһֵʵ ArchAtomicIncֻǽָ addr ָı 1
STATIC INLINE VOID ArchAtomicDec(Atomic *addr)
{
UINT32 intSave;
@@ -105,6 +124,7 @@ STATIC INLINE VOID ArchAtomicDec(Atomic *addr)
LOS_IntRestore(intSave);
}
+//ArchAtomicDecRet ArchAtomicDec ƣؼٺıֵ
STATIC INLINE INT32 ArchAtomicDecRet(Atomic *addr)
{
UINT32 intSave;
@@ -115,6 +135,10 @@ STATIC INLINE INT32 ArchAtomicDecRet(Atomic *addr)
return *addr;
}
+/*ArchAtomic64Read ԭӶȡһ 64 λֵ
+ȱ浱ǰж״̬ intSaveȻڹرжϵ£
+ȡָ v ָ 64 λֵ
+ָ֮ǰж״̬ضȡֵ*/
STATIC INLINE INT64 ArchAtomic64Read(const Atomic64 *v)
{
UINT32 intSave;
@@ -127,6 +151,10 @@ STATIC INLINE INT64 ArchAtomic64Read(const Atomic64 *v)
return val;
}
+/*ArchAtomic64Set ԭһ 64 λֵΪ setVal
+ȱ浱ǰж״̬ intSaveȻڹرжϵ£
+ָ v ָıΪ setVal
+ָ֮ǰж״̬*/
STATIC INLINE VOID ArchAtomic64Set(Atomic64 *v, INT64 setVal)
{
UINT32 intSave;
@@ -136,6 +164,10 @@ STATIC INLINE VOID ArchAtomic64Set(Atomic64 *v, INT64 setVal)
LOS_IntRestore(intSave);
}
+/*ArchAtomic64Add ԭһ 64 λֵ
+ȱ浱ǰж״̬ intSaveȻڹرжϵ£
+ָ v ָı addValȻӺֵ val
+ָ֮ǰж״̬ val*/
STATIC INLINE INT64 ArchAtomic64Add(Atomic64 *v, INT64 addVal)
{
UINT32 intSave;
@@ -149,6 +181,9 @@ STATIC INLINE INT64 ArchAtomic64Add(Atomic64 *v, INT64 addVal)
return val;
}
+/*ArchAtomic64Sub ԭӼһ 64 λֵ
+ʵ ArchAtomic64Add
+ֻǽָ v ָıȥ subVal*/
STATIC INLINE INT64 ArchAtomic64Sub(Atomic64 *v, INT64 subVal)
{
UINT32 intSave;
@@ -162,6 +197,8 @@ STATIC INLINE INT64 ArchAtomic64Sub(Atomic64 *v, INT64 subVal)
return val;
}
+/*ArchAtomic64Inc ԭһ 64 λֵ
+ʵ ArchAtomic64Addֻǽӵ̶ֵΪ 1*/
STATIC INLINE VOID ArchAtomic64Inc(Atomic64 *v)
{
UINT32 intSave;
@@ -171,6 +208,7 @@ STATIC INLINE VOID ArchAtomic64Inc(Atomic64 *v)
LOS_IntRestore(intSave);
}
+//ArchAtomic64IncRet ArchAtomic64Inc ƣӺıֵ
STATIC INLINE INT64 ArchAtomic64IncRet(Atomic64 *v)
{
UINT32 intSave;
@@ -184,6 +222,9 @@ STATIC INLINE INT64 ArchAtomic64IncRet(Atomic64 *v)
return val;
}
+/*ArchAtomic64Dec ԭӼһ 64 λֵ
+ȱ浱ǰж״̬ intSaveȻڹرжϵ£ָ v ָıȥ 1
+ָ֮ǰж״̬*/
STATIC INLINE VOID ArchAtomic64Dec(Atomic64 *v)
{
UINT32 intSave;
@@ -193,6 +234,7 @@ STATIC INLINE VOID ArchAtomic64Dec(Atomic64 *v)
LOS_IntRestore(intSave);
}
+//ArchAtomic64DecRet ArchAtomic64Dec ƣؼٺıֵ
STATIC INLINE INT64 ArchAtomic64DecRet(Atomic64 *v)
{
UINT32 intSave;
@@ -206,6 +248,10 @@ STATIC INLINE INT64 ArchAtomic64DecRet(Atomic64 *v)
return val;
}
+/*ArchAtomicXchg32bits ԭӽһ 32 λֵ
+ȱ浱ǰж״̬ intSaveȻڹرжϵ£
+ָ v ָıֵ prevValٽ v ֵΪ val
+ָ֮ǰж״̬ԭȵֵ prevVal*/
STATIC INLINE INT32 ArchAtomicXchg32bits(Atomic *v, INT32 val)
{
UINT32 intSave;
@@ -219,6 +265,7 @@ STATIC INLINE INT32 ArchAtomicXchg32bits(Atomic *v, INT32 val)
return prevVal;
}
+//ArchAtomicXchg64bits ArchAtomicXchg32bitsԭӽһ 64 λֵ
STATIC INLINE INT64 ArchAtomicXchg64bits(Atomic64 *v, INT64 val)
{
UINT32 intSave;
@@ -232,6 +279,11 @@ STATIC INLINE INT64 ArchAtomicXchg64bits(Atomic64 *v, INT64 val)
return prevVal;
}
+/*ArchAtomicCmpXchg32bits ԭӱȽϺͽһ 32 λֵ
+ȱ浱ǰж״̬ intSaveȻڹرжϵ£
+ָ v ָıֵ prevValж prevVal Ƿ oldVal
+ȣ v ֵΪ valָ֮ǰж״̬
+Ƿִ˽IJֵ*/
STATIC INLINE BOOL ArchAtomicCmpXchg32bits(Atomic *v, INT32 val, INT32 oldVal)
{
UINT32 intSave;
@@ -247,6 +299,7 @@ STATIC INLINE BOOL ArchAtomicCmpXchg32bits(Atomic *v, INT32 val, INT32 oldVal)
return (prevVal != oldVal);
}
+//ArchAtomicCmpXchg64bits ArchAtomicCmpXchg32bitsԭӱȽϺͽһ 64 λֵ
STATIC INLINE BOOL ArchAtomicCmpXchg64bits(Atomic64 *v, INT64 val, INT64 oldVal)
{
UINT32 intSave;
diff --git a/src/kernel/include/console.h b/src/kernel/include/console.h
index a0f102a..e57aba9 100644
--- a/src/kernel/include/console.h
+++ b/src/kernel/include/console.h
@@ -25,18 +25,18 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
-
+//LiteOSϵͳУconsoleͷļͨڶ̨صĺݽṹ
#ifndef _CONSOLE_H
#define _CONSOLE_H
-
-#include "los_config.h"
-#ifdef LOSCFG_FS_VFS
-#include "termios.h"
-#ifdef LOSCFG_NET_TELNET
-#include "telnet_dev.h"
-#endif
-#include "virtual_serial.h"
-#include "los_ringbuf.h"
+//УʹȷͷļֻһΡŶ˿̨ĴС˿̨ʼӡͶȡȺ
+#include "los_config.h"//ϵͳļڻȡϵͳһЩúԡ
+#ifdef LOSCFG_FS_VFS//ʹָжǷ˺LOSCFG_FS_VFSѾ壬Ĵ飬
+#include "termios.h"// POSIX ն˿ƶͷļڶն˽пơ
+#ifdef LOSCFG_NET_TELNET//ʹָжǷ˺,Ѿ壬Ĵ飬
+#include "telnet_dev.h"// Telnet 豸ͷļʵ Telnet ӡ
+#endif//ָ
+#include "virtual_serial.h"//ڵͷļʵڵĹܡ
+#include "los_ringbuf.h"//˻λͷļʵֻĶд
#endif
#ifdef __cplusplus
@@ -57,76 +57,76 @@ extern "C" {
#define CONSOLE "/dev/console"
#define CONSOLE_NAMELEN 16
-
-#define CONSOLE_CMD_RD_BLOCK_SERIAL 0x104
-#define CONSOLE_CMD_RD_BLOCK_TELNET 101
-#define CONSOLE_RD_BLOCK 1
-#define CONSOLE_RD_NONBLOCK 0
-#define CONSOLE_SHELL_KEY_EVENT 0x112
-#define CONSOLE_SHELL_EXITED 0x400
-#define CONSOLE_CONTROL_RIGHTS_CAPTURE 201
-#define CONSOLE_CONTROL_RIGHTS_RELEASE 202
-#define CONSOLE_CONTROL_CAPTURE_LINE 203
-#define CONSOLE_CONTROL_CAPTURE_CHAR 204
-#define CONSOLE_FIFO_SIZE 1024
-#define CONSOLE_NUM 2
+//δ붨һЩͳǵĺ£
+#define CONSOLE_CMD_RD_BLOCK_SERIAL 0x104//ʾӴڶȡݵֵΪ0x104
+#define CONSOLE_CMD_RD_BLOCK_TELNET 101//ʾTelnetӶȡݵֵΪ101
+#define CONSOLE_RD_BLOCK 1//ʾģʽֵΪ1
+#define CONSOLE_RD_NONBLOCK 0//ʾģʽֵΪ0
+#define CONSOLE_SHELL_KEY_EVENT 0x112//ʾshell¼ֵΪ0x112
+#define CONSOLE_SHELL_EXITED 0x400//ʾshell˳ֵΪ0x400
+#define CONSOLE_CONTROL_RIGHTS_CAPTURE 201//ʾȨֵΪ201
+#define CONSOLE_CONTROL_RIGHTS_RELEASE 202//ʾȨͷţֵΪ202
+#define CONSOLE_CONTROL_CAPTURE_LINE 203//ʾֵΪ203
+#define CONSOLE_CONTROL_CAPTURE_CHAR 204//ʾֵַΪ204
+#define CONSOLE_FIFO_SIZE 1024//ʾ̨FIFOFirst In First OutСֵΪ1024
+#define CONSOLE_NUM 2//ʾֵ̨Ϊ2
typedef struct {
- Ringbuf ringbuf; /* Ring buffer */
- EVENT_CB_S sendEvent; /* Inform telnet send task */
+ Ringbuf ringbuf; /* Ring buffer *///ʾλһڻݵѭл
+ EVENT_CB_S sendEvent; /* Inform telnet send task *///ʾtelnet¼Ļص
} RingbufSendCB;
typedef struct {
- UINT32 consoleID;
- UINT32 consoleType;
- UINT32 consoleSem;
- UINT32 shellEntryId;
- UINT32 consoleMask;
- struct inode *devInode;
- CHAR *name;
- INT32 fd;
- UINT32 refCount;
- BOOL isNonBlock;
+ UINT32 consoleID;//ʾ̨ID
+ UINT32 consoleType;//ʾ̨͡
+ UINT32 consoleSem;//ʾͬĿ̨ź
+ UINT32 shellEntryId;//ʾshellID
+ UINT32 consoleMask;//ʾ̨롣
+ struct inode *devInode;//ʾ豸ڵ㡣
+ CHAR *name;//ʾ̨ơ
+ INT32 fd;//ʾļ
+ UINT32 refCount;//ʾü
+ BOOL isNonBlock;//ʾǷΪģʽ
#ifdef LOSCFG_SHELL
- VOID *shellHandle;
+ VOID *shellHandle;//ʾshellľ
#endif
- UINT32 sendTaskID;
- RingbufSendCB *ringbufSendCB;
- UINT8 fifo[CONSOLE_FIFO_SIZE];
- UINT32 fifoOut;
- UINT32 fifoIn;
- UINT32 currentLen;
- struct termios consoleTermios;
+ UINT32 sendTaskID;//ʾID
+ RingbufSendCB *ringbufSendCB;//ʾλͻص
+ UINT8 fifo[CONSOLE_FIFO_SIZE];//ʾ̨FIFO
+ UINT32 fifoOut;//ʾFIFOλá
+ UINT32 fifoIn;//ʾFIFOλá
+ UINT32 currentLen;//ʾǰȡ
+ struct termios consoleTermios;//ʾ̨նԡ
} CONSOLE_CB;
-extern INT32 system_console_init(const CHAR *deviceName);
-extern INT32 system_console_deinit(const CHAR *deviceName);
-extern BOOL SetSerialNonBlock(const CONSOLE_CB *consoleCB);
-extern BOOL SetSerialBlock(const CONSOLE_CB *consoleCB);
-extern BOOL SetTelnetNonBlock(const CONSOLE_CB *consoleCB);
-extern BOOL SetTelnetBlock(const CONSOLE_CB *consoleCB);
-extern CONSOLE_CB *OsGetConsoleByID(INT32 consoleId);
-extern CONSOLE_CB *OsGetConsoleByTaskID(UINT32 taskId);
-extern UINT32 ConsoleTaskReg(INT32 consoleId, UINT32 taskId);
-extern INT32 ConsoleUpdateFd(VOID);
-extern BOOL ConsoleEnable(VOID);
-extern BOOL is_nonblock(const CONSOLE_CB *consoleCB);
-extern BOOL IsConsoleOccupied(const CONSOLE_CB *consoleCB);
-extern INT32 FilepOpen(struct file *filep, const struct file_operations_vfs *fops);
-extern INT32 FilepClose(struct file *filep, const struct file_operations_vfs *fops);
-extern INT32 FilepRead(struct file *filep, const struct file_operations_vfs *fops, CHAR *buffer, size_t bufLen);
-extern INT32 FilepWrite(struct file *filep, const struct file_operations_vfs *fops, const CHAR *buffer, size_t bufLen);
-extern INT32 FilepPoll(struct file *filep, const struct file_operations_vfs *fops, poll_table *fds);
-extern INT32 FilepIoctl(struct file *filep, const struct file_operations_vfs *fops, INT32 cmd, unsigned long arg);
-extern INT32 GetFilepOps(const struct file *filep, struct file **privFilep, const struct file_operations_vfs **fops);
+extern INT32 system_console_init(const CHAR *deviceName);//̨ʼڳʼ̨صԴ״̬
+extern INT32 system_console_deinit(const CHAR *deviceName);//̨ʼͷſ̨صԴ״̬
+extern BOOL SetSerialNonBlock(const CONSOLE_CB *consoleCB);//ôΪģʽ
+extern BOOL SetSerialBlock(const CONSOLE_CB *consoleCB);//ôΪģʽ
+extern BOOL SetTelnetNonBlock(const CONSOLE_CB *consoleCB);//TelnetΪģʽ
+extern BOOL SetTelnetBlock(const CONSOLE_CB *consoleCB);//TelnetΪģʽ
+extern CONSOLE_CB *OsGetConsoleByID(INT32 consoleId);//ݿ̨IDȡ̨Ŀƿ飨Control Block
+extern CONSOLE_CB *OsGetConsoleByTaskID(UINT32 taskId);//IDȡĿ̨Ŀƿ顣
+extern UINT32 ConsoleTaskReg(INT32 consoleId, UINT32 taskId);//ָĿ̨й
+extern INT32 ConsoleUpdateFd(VOID);//¿̨ļFile Descriptor
+extern BOOL ConsoleEnable(VOID);//ʹ̨ܿܡ
+extern BOOL is_nonblock(const CONSOLE_CB *consoleCB);//жϿ̨ǷΪģʽ
+extern BOOL IsConsoleOccupied(const CONSOLE_CB *consoleCB);//жϿ̨ǷѾռá
+extern INT32 FilepOpen(struct file *filep, const struct file_operations_vfs *fops);//ļ
+extern INT32 FilepClose(struct file *filep, const struct file_operations_vfs *fops);//رļ
+extern INT32 FilepRead(struct file *filep, const struct file_operations_vfs *fops, CHAR *buffer, size_t bufLen);//ļжȡݡ
+extern INT32 FilepWrite(struct file *filep, const struct file_operations_vfs *fops, const CHAR *buffer, size_t bufLen);//ļдݡ
+extern INT32 FilepPoll(struct file *filep, const struct file_operations_vfs *fops, poll_table *fds);//ļѯ
+extern INT32 FilepIoctl(struct file *filep, const struct file_operations_vfs *fops, INT32 cmd, unsigned long arg);//ļIOƲ
+extern INT32 GetFilepOps(const struct file *filep, struct file **privFilep, const struct file_operations_vfs **fops);//ȡļIJ
#else
-STATIC INLINE INT32 ConsoleUpdateFd(VOID)
+STATIC INLINE INT32 ConsoleUpdateFd(VOID)//һһΪConsoleUpdateFdľ̬ΪINT3232λΪաݺʵΪreturn -1;úǸ¿̨ļFile Descriptor-1
{
return -1;
}
-#endif
+#endif//ʾ֮ǰָ#if
-#ifdef __cplusplus
+#ifdef __cplusplus//һָжǷΪC++뻷C++뻷Ĵextern "C"Ա֤CC++֮ĺùһ¡
#if __cplusplus
}
#endif /* __cplusplus */
diff --git a/src/kernel/include/los_atomic.h b/src/kernel/include/los_atomic.h
index 05fff5f..eaf9204 100644
--- a/src/kernel/include/los_atomic.h
+++ b/src/kernel/include/los_atomic.h
@@ -30,12 +30,12 @@
* @defgroup los_atomic Atomic
* @ingroup kernel
*/
-
-#ifndef _LOS_ATOMIC_H
-#define _LOS_ATOMIC_H
+//los_atomic.h֧ԭӲͷļ
+#ifndef _LOS_ATOMIC_H//ʾ _LOS_ATOMIC_H ûбִ´룬δ롣
+#define _LOS_ATOMIC_H//ǶһжͷļǷѾ
#include "los_typedef.h"
-#include "arch/atomic.h"
+#include "arch/atomic.h"//ƽ̨صԭӲͷļʵڲͬӲƽ̨
#ifdef __cplusplus
#if __cplusplus
@@ -60,7 +60,7 @@ extern "C" {
* @see LOS_Atomic64Read
* @since Huawei LiteOS V200R003C00
*/
-STATIC INLINE INT32 LOS_AtomicRead(const Atomic *v)
+STATIC INLINE INT32 LOS_AtomicRead(const Atomic *v)//һAtomic͵ָvһ32λڶȡָڴλõԭӱֵ
{
return ArchAtomicRead(v);
}
@@ -84,7 +84,7 @@ STATIC INLINE INT32 LOS_AtomicRead(const Atomic *v)
* @see LOS_Atomic64Set
* @since Huawei LiteOS V200R003C00
*/
-STATIC INLINE VOID LOS_AtomicSet(Atomic *v, INT32 setVal)
+STATIC INLINE VOID LOS_AtomicSet(Atomic *v, INT32 setVal)//һAtomic͵ָvһ32λsetValûзֵΪVOID
{
ArchAtomicSet(v, setVal);
}
@@ -114,7 +114,7 @@ STATIC INLINE VOID LOS_AtomicSet(Atomic *v, INT32 setVal)
*/
STATIC INLINE INT32 LOS_AtomicAdd(Atomic *v, INT32 addVal)
{
- return ArchAtomicAdd(v, addVal);
+ return ArchAtomicAdd(v, addVal);//ڽָڴλõԭӱֵָ
}
/**
@@ -142,7 +142,7 @@ STATIC INLINE INT32 LOS_AtomicAdd(Atomic *v, INT32 addVal)
*/
STATIC INLINE INT32 LOS_AtomicSub(Atomic *v, INT32 subVal)
{
- return ArchAtomicSub(v, subVal);
+ return ArchAtomicSub(v, subVal);//ڽָڴλõԭӱֵָ
}
/**
@@ -168,7 +168,7 @@ STATIC INLINE INT32 LOS_AtomicSub(Atomic *v, INT32 subVal)
*/
STATIC INLINE VOID LOS_AtomicInc(Atomic *v)
{
- ArchAtomicInc(v);
+ ArchAtomicInc(v);//ڽָڴλõԭӱ1
}
/**
@@ -222,7 +222,7 @@ STATIC INLINE INT32 LOS_AtomicIncRet(Atomic *v)
*/
STATIC INLINE VOID LOS_AtomicDec(Atomic *v)
{
- ArchAtomicDec(v);
+ ArchAtomicDec(v);//úͨضϵṹṩԭӵݼʵ֡ͨʹͺ궨壬ڱʱδֱǶ뵽ôӶִЧʺͽʡõĿ
}
/**
@@ -248,7 +248,7 @@ STATIC INLINE VOID LOS_AtomicDec(Atomic *v)
*/
STATIC INLINE INT32 LOS_AtomicDecRet(Atomic *v)
{
- return ArchAtomicDecRet(v);
+ return ArchAtomicDecRet(v);//úͨضϵṹṩԭӵݼصݼֵĺ
}
/**
@@ -270,7 +270,7 @@ STATIC INLINE INT32 LOS_AtomicDecRet(Atomic *v)
*/
STATIC INLINE INT64 LOS_Atomic64Read(const Atomic64 *v)
{
- return ArchAtomic64Read(v);
+ return ArchAtomic64Read(v);//úͨضϵṹṩԭӶȡĺ
}
/**
@@ -294,7 +294,7 @@ STATIC INLINE INT64 LOS_Atomic64Read(const Atomic64 *v)
*/
STATIC INLINE VOID LOS_Atomic64Set(Atomic64 *v, INT64 setVal)
{
- ArchAtomic64Set(v, setVal);
+ ArchAtomic64Set(v, setVal);//úӦɵײļܹṩģʵ 64 λԭӲ
}
/**
@@ -322,7 +322,7 @@ STATIC INLINE VOID LOS_Atomic64Set(Atomic64 *v, INT64 setVal)
*/
STATIC INLINE INT64 LOS_Atomic64Add(Atomic64 *v, INT64 addVal)
{
- return ArchAtomic64Add(v, addVal);
+ return ArchAtomic64Add(v, addVal);//ԭӼӲúӦɵײļܹṩģʵ 64 λԭӲ
}
/**
@@ -350,7 +350,7 @@ STATIC INLINE INT64 LOS_Atomic64Add(Atomic64 *v, INT64 addVal)
*/
STATIC INLINE INT64 LOS_Atomic64Sub(Atomic64 *v, INT64 subVal)
{
- return ArchAtomic64Sub(v, subVal);
+ return ArchAtomic64Sub(v, subVal);//ԭӼúӦɵײļܹṩģʵ 64 λԭӲ
}
/**
@@ -376,7 +376,7 @@ STATIC INLINE INT64 LOS_Atomic64Sub(Atomic64 *v, INT64 subVal)
*/
STATIC INLINE VOID LOS_Atomic64Inc(Atomic64 *v)
{
- ArchAtomic64Inc(v);
+ ArchAtomic64Inc(v);//ԭӲúӦɵײļܹṩģʵ 64 λԭӲ
}
/**
@@ -403,7 +403,7 @@ STATIC INLINE VOID LOS_Atomic64Inc(Atomic64 *v)
*/
STATIC INLINE INT64 LOS_Atomic64IncRet(Atomic64 *v)
{
- return ArchAtomic64IncRet(v);
+ return ArchAtomic64IncRet(v);//ԭӲӺֵúӦɵײļܹṩģʵ 64 λԭӲ
}
/**
@@ -430,7 +430,7 @@ STATIC INLINE INT64 LOS_Atomic64IncRet(Atomic64 *v)
*/
STATIC INLINE VOID LOS_Atomic64Dec(Atomic64 *v)
{
- ArchAtomic64Dec(v);
+ ArchAtomic64Dec(v);//ԭӼٲúӦɵײļܹṩģʵ 64 λԭӲ
}
/**
@@ -456,7 +456,7 @@ STATIC INLINE VOID LOS_Atomic64Dec(Atomic64 *v)
*/
STATIC INLINE INT64 LOS_Atomic64DecRet(Atomic64 *v)
{
- return ArchAtomic64DecRet(v);
+ return ArchAtomic64DecRet(v);//ԭӼٲؼٺֵúӦɵײļܹṩģʵ 64 λԭӲ
}
/**
@@ -480,7 +480,7 @@ STATIC INLINE INT64 LOS_Atomic64DecRet(Atomic64 *v)
*/
STATIC INLINE INT32 LOS_AtomicXchg32bits(Atomic *v, INT32 val)
{
- return ArchAtomicXchg32bits(v, val);
+ return ArchAtomicXchg32bits(v, val);//ԭӽؽǰֵúӦɵײļܹṩģʵ 32 λԭӲ
}
/**
@@ -504,7 +504,7 @@ STATIC INLINE INT32 LOS_AtomicXchg32bits(Atomic *v, INT32 val)
*/
STATIC INLINE INT64 LOS_AtomicXchg64bits(Atomic64 *v, INT64 val)
{
- return ArchAtomicXchg64bits(v, val);
+ return ArchAtomicXchg64bits(v, val);//ԭӽؽǰֵúӦɵײļܹṩģʵ 64 λԭӲ
}
/**
@@ -531,7 +531,7 @@ STATIC INLINE INT64 LOS_AtomicXchg64bits(Atomic64 *v, INT64 val)
*/
STATIC INLINE BOOL LOS_AtomicCmpXchg32bits(Atomic *v, INT32 val, INT32 oldVal)
{
- return ArchAtomicCmpXchg32bits(v, val, oldVal);
+ return ArchAtomicCmpXchg32bits(v, val, oldVal);//ԭӱȽϺͽرȽϽúӦɵײļܹṩģʵ 32 λԭӲ
}
/**
@@ -558,7 +558,7 @@ STATIC INLINE BOOL LOS_AtomicCmpXchg32bits(Atomic *v, INT32 val, INT32 oldVal)
*/
STATIC INLINE BOOL LOS_AtomicCmpXchg64bits(Atomic64 *v, INT64 val, INT64 oldVal)
{
- return ArchAtomicCmpXchg64bits(v, val, oldVal);
+ return ArchAtomicCmpXchg64bits(v, val, oldVal);//ԭӱȽϺͽرȽϽúӦɵײļܹṩģʵ 64 λԭӲ
}
#ifdef __cplusplus
diff --git a/src/kernel/include/los_base.h b/src/kernel/include/los_base.h
index a4544a5..bf1e570 100644
--- a/src/kernel/include/los_base.h
+++ b/src/kernel/include/los_base.h
@@ -75,19 +75,19 @@ extern "C" {
* @since Huawei LiteOS V100R001C00
*/
#define LOS_ASSERT_COND(expression) LOS_ASSERT(expression)
-
+//һ꺯һʽΪñʽΪݸһΪLOS_ASSERTĺ꺯ʱִжԡ
/**
* @ingroup los_base
* Define the timeout interval as LOS_NO_WAIT.
*/
#define LOS_NO_WAIT 0
-
+//һΪ0ʾһʱʱʾȴء
/**
* @ingroup los_base
* Define the timeout interval as LOS_WAIT_FOREVER.
*/
#define LOS_WAIT_FOREVER 0xFFFFFFFF
-
+//һΪ0xFFFFFFFFʾһʱʱʾԶȴֱ߱жϡ
/**
* @ingroup los_base
* @brief Align the value (addr) by some bytes (boundary).
@@ -111,8 +111,8 @@ extern "C" {
* @see LOS_Align | TRUNCATE
* @since Huawei LiteOS V100R001C00
*/
-#ifndef ALIGN
-#define ALIGN(addr, boundary) LOS_Align(addr, boundary)
+#ifndef ALIGN//жALIGNǷѾûбִнĴ롣
+#define ALIGN(addr, boundary) LOS_Align(addr, boundary)//ֱʾҪĵַͶ߽硣ںڲLOS_Alignеַaddrַ϶뵽ӽboundaryı
#endif
/**
@@ -139,10 +139,16 @@ extern "C" {
* @since Huawei LiteOS V100R001C00
*/
#define TRUNCATE(addr, size) ((UINTPTR)(addr) & ~((size) - 1))
-
+// addr sizeһضϺĵַԣú꽫ַ addr size ĴСж룬λλΪ㡣磬 addr 0x12345678size 4ضϺĵַ 0x12345670
/**
* Read a UINT8 value from addr and stroed in value.
*/
+/*READ_UINT8(value, addr)READ_UINT16(value, addr) READ_UINT32(value, addr)
+ֱڴӵַ addr жȡ 8 λ16 λ 32 λֵ
+洢 value С⼸ʵַʽƣ
+ָͨӶȡڴеֵʹ dsb() ͬ
+ȷȡȷУdsb() һָ
+ڽֹͬݲһµ*/
#define READ_UINT8(value, addr) ({ (value) = *((volatile UINT8 *)((UINTPTR)(addr))); dsb(); })
/**
@@ -155,6 +161,9 @@ extern "C" {
*/
#define READ_UINT32(value, addr) ({ (value) = *((volatile UINT32 *)((UINTPTR)(addr))); dsb(); })
+
+//жϱ뻷ǷΪ 64 λ 64 λ READ_UINT64 WRITE_UINT64 ꡣ꽫ԡ
+//ڴӵַ addr жȡһ 64 λֵ洢 value Сʹ˺֮ǰƵIJָͨӶȡڴеֵʹ dsb() ͬ
#ifdef __LP64__
/**
* Read a UINT64 value from addr and stroed in value.
@@ -162,6 +171,11 @@ extern "C" {
#define READ_UINT64(value, addr) ({ (value) = *((volatile UINT64 *)((UINTPTR)(addr))); dsb(); })
#endif
+
+/*WRITE_UINT8(value, addr)WRITE_UINT16(value, addr) WRITE_UINT32(value, addr)
+ֱڽ 8 λ16 λ 32 λֵ value д뵽ַ addr С
+ЩҲʹ˺֮ǰƵIJʹ dsb() ͬ
+ָͨдڴеֵ*/
/**
* Write a UINT8 value to addr.
*/
@@ -177,6 +191,8 @@ extern "C" {
*/
#define WRITE_UINT32(value, addr) ({ dsb(); *((volatile UINT32 *)((UINTPTR)(addr))) = (value); })
+
+// 64 λ£ WRITE_UINT64 ꣬ڽ 64 λֵ value д뵽ַ addr С
#ifdef __LP64__
/**
* Write a UINT64 addr to addr.
@@ -187,11 +203,13 @@ extern "C" {
/**
* Get a UINT8 value from addr.
*/
+//ڴӵַ addr жȡһ 8 λֵضȡĽڶȡ֮ʹ dsb() ͬȷȡȷ
#define GET_UINT8(addr) ({ UINT8 r = *((volatile UINT8 *)((UINTPTR)(addr))); dsb(); r; })
/**
* Get a UINT16 value from addr.
*/
+//GET_UINT16(addr) GET_UINT32(addr) ֱڴӵַ addr жȡ 16 λ 32 λֵضȡĽͬأڶȡ֮Ҳͬ
#define GET_UINT16(addr) ({ UINT16 r = *((volatile UINT16 *)((UINTPTR)(addr))); dsb(); r; })
/**
@@ -199,6 +217,8 @@ extern "C" {
*/
#define GET_UINT32(addr) ({ UINT32 r = *((volatile UINT32 *)((UINTPTR)(addr))); dsb(); r; })
+
+// 64 λ£ GET_UINT64(addr) ꣬ڴӵַ addr жȡһ 64 λֵضȡĽ
#ifdef __LP64__
/**
* Get a UINT64 value from addr.
@@ -226,7 +246,7 @@ extern "C" {
* @see LOS_ASSERT_COND
* @since Huawei LiteOS V100R001C00
*/
-#ifdef LOSCFG_DEBUG_VERSION
+#ifdef LOSCFG_DEBUG_VERSION//ȣָͨ #ifdef LOSCFG_DEBUG_VERSION жǷڵ汾 LOSCFG_DEBUG_VERSION ꣬ʾڵ汾 #ifdef #endif ֮ݽЧ #else #endif ֮ݽЧ
#define LOS_ASSERT(judge) do { \
if ((UINTPTR)(judge) == 0) { \
(VOID)LOS_IntLock(); \
@@ -234,8 +254,12 @@ extern "C" {
while (1) {} \
} \
} while (0)
+//ڵ汾£궨ĴУLOS_ASSERT 걻Ϊһв judge ĺ꺯ǽжԼ飬 judge ʽĽΪ㣨٣ִϲ
+// LOS_IntLock() úһڽֹжϵIJȷڶʧʱжϴ
+//ʹ PRINT_ERR ӡһϢа˳ļкźͺ
+//һѭ while (1)һֱͣѭС
#else
-#define LOS_ASSERT(judge)
+#define LOS_ASSERT(judge)//ڷǵ汾£궨ĴУLOS_ASSERT 걻Ϊգκβ
#endif
/**
@@ -261,7 +285,8 @@ extern "C" {
* @since Huawei LiteOS V100R001C00
*/
extern UINTPTR LOS_Align(UINTPTR addr, UINT32 boundary);
-
+//ԣĹǽ addr boundary ߽ж룬ضĵַ磬 addr 12boundary 8ôĵַ 16
+//extern ؼֱʾúطģֻǶĿڵǰļʹøúʱܹȷҪṩľʵ֡
/**
* @ingroup los_base
* @brief Sleep the current task.
diff --git a/src/kernel/include/los_bitmap.h b/src/kernel/include/los_bitmap.h
index 81bfb8f..b05e472 100644
--- a/src/kernel/include/los_bitmap.h
+++ b/src/kernel/include/los_bitmap.h
@@ -31,7 +31,7 @@
* @ingroup kernel
*/
-#ifndef _LOS_BITMAP_H
+#ifndef _LOS_BITMAP_H//δһָ飬жǷ˺ _LOS_BITMAP_Hδúִ꣬ #ifndef #endif ֮Ĵ롣
#define _LOS_BITMAP_H
#include "los_typedef.h"
@@ -48,6 +48,7 @@ extern "C" {
*
* The effective bit index is from 0 to 31.
*/
+//궨ֵΪ 32ĺʹ 0 31 ʾλֵ 32 ʾЧλִֵʽڼбȽϳһڱʶijЩ״̬־
#define LOS_INVALID_BIT_INDEX 32
/**
@@ -69,6 +70,9 @@ extern "C" {
* @see LOS_BitmapClr
* @since Huawei LiteOS V100R001C00
*/
+/*bitmap һָ UINT32 ͵ָ룬ʾһλͼΪλ飩
+pos һ UINT16 ͵IJʾҪõλ
+ڸλͼнָλλΪ 1ӦλõıλΪ 1*/
VOID LOS_BitmapSet(UINT32 *bitmap, UINT16 pos);
/**
@@ -90,6 +94,9 @@ VOID LOS_BitmapSet(UINT32 *bitmap, UINT16 pos);
* @see LOS_BitmapSet.
* @since Huawei LiteOS V100R001C00
*/
+/*bitmap һָ UINT32 ͵ָ룬ʾһλͼΪλ飩
+pos һ UINT16 ͵IJʾҪλ
+ڸλͼнָλλ㣬ӦλõıλΪ 0*/
VOID LOS_BitmapClr(UINT32 *bitmap, UINT16 pos);
/**
@@ -108,6 +115,12 @@ VOID LOS_BitmapClr(UINT32 *bitmap, UINT16 pos);
* @see LOS_HighBitGet
* @since Huawei LiteOS V100R001C00
*/
+/*ڸλͼҵλҲֵСλ
+ظλͼвκλıλ
+ 32 LOS_INVALID_BIT_INDEX ֵ
+ʵֿܻ漰λ
+ҵλšںΪ UINT16
+ unsigned short ͣ˷ֵΪ 0 31 0 31 32*/
UINT16 LOS_LowBitGet(UINT32 bitmap);
/**
@@ -126,6 +139,12 @@ UINT16 LOS_LowBitGet(UINT32 bitmap);
* @see LOS_LowBitGet
* @since Huawei LiteOS V100R001C00
*/
+/*ڸλͼҵλҲֵλ
+ظλͼвκλıλ
+ 32 LOS_INVALID_BIT_INDEX ֵ
+ʵֿܻ漰λҵλš
+ںΪ UINT16 unsigned short ͣ
+˷ֵΪ 0 31 0 31 32*/
UINT16 LOS_HighBitGet(UINT32 bitmap);
#ifdef __cplusplus
diff --git a/src/kernel/include/los_builddef.h b/src/kernel/include/los_builddef.h
index 894fd80..192d90a 100644
--- a/src/kernel/include/los_builddef.h
+++ b/src/kernel/include/los_builddef.h
@@ -35,79 +35,79 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-#define OS_LITTLE_ENDIAN 0x1234 /* Little endian */
-#define OS_BIG_ENDIAN 0x4321 /* Big endian */
+#define OS_LITTLE_ENDIAN 0x1234 /* Little endian *///ʾСֵΪ 0x1234
+#define OS_BIG_ENDIAN 0x4321 /* Big endian *///ʾֵΪ 0x4321
#ifndef OS_BYTE_ORDER
-#define OS_BYTE_ORDER OS_LITTLE_ENDIAN
+#define OS_BYTE_ORDER OS_LITTLE_ENDIAN//δ OS_BYTE_ORDERΪ OS_LITTLE_ENDIAN
#endif
/* Define OS code data sections */
/* The indicator function is inline */
#ifndef LITE_OS_SEC_ALW_INLINE
-#define LITE_OS_SEC_ALW_INLINE /* __attribute__((always_inline)) */
+#define LITE_OS_SEC_ALW_INLINE /* __attribute__((always_inline)) *///һ꣬ڽΪ
#endif
#ifndef LITE_OS_SEC_TEXT
-#define LITE_OS_SEC_TEXT /* __attribute__((section(".text.sram"))) */
+#define LITE_OS_SEC_TEXT /* __attribute__((section(".text.sram"))) *///һ꣬ڽη .text.sram
#endif
#ifndef LITE_OS_SEC_TEXT_MINOR
-#define LITE_OS_SEC_TEXT_MINOR /* __attribute__((section(".text.ddr"))) */
+#define LITE_OS_SEC_TEXT_MINOR /* __attribute__((section(".text.ddr"))) *///һ꣬ڽη .text.ddr
#endif
#ifndef LITE_OS_SEC_TEXT_INIT
-#define LITE_OS_SEC_TEXT_INIT /* __attribute__((section(".text.init"))) */
+#define LITE_OS_SEC_TEXT_INIT /* __attribute__((section(".text.init"))) *///궨һΣڷóʼ룬λ .text.init С
#endif
#ifndef LITE_OS_SEC_DATA
-#define LITE_OS_SEC_DATA /* __attribute__((section(".data.sram"))) */
+#define LITE_OS_SEC_DATA /* __attribute__((section(".data.sram"))) *///궨һݶΣڷݣλ .data.sram С
#endif
#ifndef LITE_OS_SEC_DATA_MINOR
-#define LITE_OS_SEC_DATA_MINOR /* __attribute__((section(".data.ddr"))) */
+#define LITE_OS_SEC_DATA_MINOR /* __attribute__((section(".data.ddr"))) *///һҪݶΣڷôҪݣλ .data.ddr С
#endif
#ifndef LITE_OS_SEC_DATA_INIT
-#define LITE_OS_SEC_DATA_INIT /* __attribute__((section(".data.init"))) */
+#define LITE_OS_SEC_DATA_INIT /* __attribute__((section(".data.init"))) *///궨һݶΣڷóʼݣλ .data.init С
#endif
#ifndef LITE_OS_SEC_DATA_VEC
-#define LITE_OS_SEC_DATA_VEC __attribute__((section(".data.vector")))
+#define LITE_OS_SEC_DATA_VEC __attribute__((section(".data.vector")))//궨һݶΣڷݣλ .data.vector С
#endif
#ifndef LITE_OS_SEC_BSS
-#define LITE_OS_SEC_BSS /* __attribute__((section(".bss.sram"))) */
+#define LITE_OS_SEC_BSS /* __attribute__((section(".bss.sram"))) *///궨һݶΣڷδʼݣBSSΣλ .bss.sram С
#endif
#ifndef LITE_OS_SEC_BSS_MINOR
-#define LITE_OS_SEC_BSS_MINOR /* __attribute__((section(".bss.ddr"))) */
+#define LITE_OS_SEC_BSS_MINOR /* __attribute__((section(".bss.ddr"))) */// 궨һݶΣڷδʼĴҪݣBSSΣλ .bss.ddr С
#endif
#ifndef LITE_OS_SEC_BSS_INIT
-#define LITE_OS_SEC_BSS_INIT /* __attribute__((section(".bss.init"))) */
+#define LITE_OS_SEC_BSS_INIT /* __attribute__((section(".bss.init"))) *///궨һݶΣڷδʼijʼݣBSSΣλ .bss.init С
#endif
#ifndef LITE_OS_SEC_ITCM
-#define LITE_OS_SEC_ITCM /* __attribute__((section(".itcm "))) */
+#define LITE_OS_SEC_ITCM /* __attribute__((section(".itcm "))) */// 궨һΣڷô루ָֻݣ ITCM С ITCM ڴͬλ CPU ڲиٷʺ͵ӳٵơ
#endif
#ifndef LITE_OS_SEC_DTCM
-#define LITE_OS_SEC_DTCM /* __attribute__((section(".dtcm"))) */
+#define LITE_OS_SEC_DTCM /* __attribute__((section(".dtcm"))) *///궨һݶΣڷݣλ DTCM С DTCM ڴͬλ CPU ڲиٷʺ͵ӳٵơ
#endif
-#define PACK1
+#define PACK1//궨һṹԱĶ뷽ʽṹijԱܵشһ𣬲ʹÿռ롣
#ifndef LITE_OS_ATTR_SEC
-#define LITE_OS_ATTR_SEC(name) __attribute__((section(#name)))
+#define LITE_OS_ATTR_SEC(name) __attribute__((section(#name)))//궨һڵĶΣͨ #name name תΪַõָƵĶС
#endif
#ifndef LITE_OS_ATTR_ALIGN
-#define LITE_OS_ATTR_ALIGN(x) __attribute__((aligned(x)))
+#define LITE_OS_ATTR_ALIGN(x) __attribute__((aligned(x)))//궨ݵĶ뷽ʽֽڶ룬x ʾֽ
#endif
#ifndef LITE_OS_ATTR_SEC_ALIGN
-#define LITE_OS_ATTR_SEC_ALIGN(name, x) __attribute__((section(#name), aligned(x)))
+#define LITE_OS_ATTR_SEC_ALIGN(name, x) __attribute__((section(#name), aligned(x)))//궨ijݵĶ뷽ʽݷõָƵĶУָĶ뷽ʽ롣
#endif
#ifndef OS_EMBED_ASM
-#define OS_EMBED_ASM __asm__ __volatile__
+#define OS_EMBED_ASM __asm__ __volatile__//궨Ƕָķʽ asm volatile ΪǶָǰʹñԽʶΪָ
#endif
#ifdef __cplusplus
diff --git a/src/kernel/include/los_config.h b/src/kernel/include/los_config.h
index 75b9ea0..bd14843 100644
--- a/src/kernel/include/los_config.h
+++ b/src/kernel/include/los_config.h
@@ -30,6 +30,22 @@
* @defgroup los_config System configuration items
* @ingroup kernel
*/
+/*ԣlos_config.h ļͨݣ
+
+TaskãԶȼΧջСȲ㲻ͬӦó
+
+жϣInterruptãԶжϷ̵ȼΧԼжϴIJԵȡ
+
+ڴMemory ManagementãԶ嶯̬ڴ㷨ڴصĴСز
+
+ʱTimerãԶ嶨ʱȡʽȡ
+
+ȣTask Schedulingã㷨ʱƬתʱȡ
+
+ϵͳʱӣSystem ClockãԶϵͳʱӵƵʡʱʱԴȡ
+
+ͨ los_config.h ļеĺ궨ȫֱԱԸӦԲϵͳжƺŻ
+Ȼĺ los_config.h ļ LiteOS ںˣʵֶԲϵͳΪܵĶƻá*/
#ifndef _LOS_CONFIG_H
#define _LOS_CONFIG_H
@@ -45,53 +61,53 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-#ifdef LOSCFG_LIB_CONFIGURABLE
-extern UINT32 g_osSysClock;
-extern UINT32 g_tickPerSecond;
-extern UINT32 g_taskLimit;
-extern UINT32 g_taskMinStkSize;
-extern UINT32 g_taskIdleStkSize;
-extern UINT32 g_taskDfltStkSize;
-extern UINT32 g_taskSwtmrStkSize;
-extern UINT32 g_swtmrLimit;
-extern UINT32 g_semLimit;
-extern UINT32 g_muxLimit;
-extern UINT32 g_queueLimit;
-extern UINT32 g_timeSliceTimeOut;
-
-extern BOOL g_nxEnabled;
-extern UINTPTR g_dlNxHeapBase;
-extern UINT32 g_dlNxHeapSize;
-
-#define LOS_GET_NX_CFG() (g_nxEnabled)
-#define LOS_SET_NX_CFG(value) (g_nxEnabled = (value))
-#define LOS_GET_DL_NX_HEAP_BASE() (g_dlNxHeapBase)
-#define LOS_SET_DL_NX_HEAP_BASE(addr) (g_dlNxHeapBase = (addr))
-#define LOS_GET_DL_NX_HEAP_SIZE() (g_dlNxHeapSize)
-#define LOS_SET_DL_NX_HEAP_SIZE(size) (g_dlNxHeapSize = (size))
-
-#define OS_SYS_CLOCK g_osSysClock
-#define KERNEL_TICK_PER_SECOND g_tickPerSecond
-#define KERNEL_TSK_LIMIT g_taskLimit
-#define KERNEL_TSK_MIN_STACK_SIZE g_taskMinStkSize
-#define KERNEL_TSK_DEFAULT_STACK_SIZE g_taskDfltStkSize
-#define KERNEL_TSK_IDLE_STACK_SIZE g_taskIdleStkSize
-#define KERNEL_TSK_SWTMR_STACK_SIZE g_taskSwtmrStkSize
-#define KERNEL_SWTMR_LIMIT g_swtmrLimit
-#define KERNEL_SEM_LIMIT g_semLimit
-#define KERNEL_MUX_LIMIT g_muxLimit
-#define KERNEL_QUEUE_LIMIT g_queueLimit
-#define KERNEL_TIMESLICE_TIMEOUT g_timeSliceTimeOut
+#ifdef LOSCFG_LIB_CONFIGURABLE//жϺ궨 LOSCFG_LIB_CONFIGURABLE Ƿ塣ú걻壬ô±ᱻС
+extern UINT32 g_osSysClock;//ϵͳʱƵ
+extern UINT32 g_tickPerSecond;//ϵͳʱӵδ
+extern UINT32 g_taskLimit;//
+extern UINT32 g_taskMinStkSize;//СջС
+extern UINT32 g_taskIdleStkSize;//ջС
+extern UINT32 g_taskDfltStkSize;//ĬջС
+extern UINT32 g_taskSwtmrStkSize;//ʱջС
+extern UINT32 g_swtmrLimit;//ʱ
+extern UINT32 g_semLimit;//ź
+extern UINT32 g_muxLimit;//
+extern UINT32 g_queueLimit;//
+extern UINT32 g_timeSliceTimeOut;//ʱƬתʱ
+
+extern BOOL g_nxEnabled;//Ƿڴ汣
+extern UINTPTR g_dlNxHeapBase;//ڴ汣Ƶʼַ
+extern UINT32 g_dlNxHeapSize;//ڴ汣ƵĴС
+
+#define LOS_GET_NX_CFG() (g_nxEnabled)//ڻȡһΪg_nxEnabledıֵ
+#define LOS_SET_NX_CFG(value) (g_nxEnabled = (value))//һΪg_nxEnabledıֵ
+#define LOS_GET_DL_NX_HEAP_BASE() (g_dlNxHeapBase)//ڻȡһΪg_dlNxHeapBaseıֵ
+#define LOS_SET_DL_NX_HEAP_BASE(addr) (g_dlNxHeapBase = (addr))//һΪg_dlNxHeapBaseıֵ
+#define LOS_GET_DL_NX_HEAP_SIZE() (g_dlNxHeapSize)//ڻȡһΪg_dlNxHeapSizeıֵ
+#define LOS_SET_DL_NX_HEAP_SIZE(size) (g_dlNxHeapSize = (size))//һΪg_dlNxHeapSizeıֵ
+
+#define OS_SYS_CLOCK g_osSysClock//ϵͳʱƵ
+#define KERNEL_TICK_PER_SECOND g_tickPerSecond//ϵͳʱδ
+#define KERNEL_TSK_LIMIT g_taskLimit//
+#define KERNEL_TSK_MIN_STACK_SIZE g_taskMinStkSize//СջС
+#define KERNEL_TSK_DEFAULT_STACK_SIZE g_taskDfltStkSize//ĬջС
+#define KERNEL_TSK_IDLE_STACK_SIZE g_taskIdleStkSize//ĬջС
+#define KERNEL_TSK_SWTMR_STACK_SIZE g_taskSwtmrStkSize//ʱջС
+#define KERNEL_SWTMR_LIMIT g_swtmrLimit//ʱ
+#define KERNEL_SEM_LIMIT g_semLimit//ź
+#define KERNEL_MUX_LIMIT g_muxLimit//
+#define KERNEL_QUEUE_LIMIT g_queueLimit//
+#define KERNEL_TIMESLICE_TIMEOUT g_timeSliceTimeOut//ʱƬתʱ
#else /* LOSCFG_LIB_CONFIGURABLE */
#ifdef LOSCFG_KERNEL_NX
-#define LOS_GET_NX_CFG() true
-#define LOS_SET_NX_CFG(value)
-#define LOS_GET_DL_NX_HEAP_BASE() LOS_DL_HEAP_BASE
-#define LOS_SET_DL_NX_HEAP_BASE(addr)
-#define LOS_GET_DL_NX_HEAP_SIZE() LOS_DL_HEAP_SIZE
-#define LOS_SET_DL_NX_HEAP_SIZE(size)
+#define LOS_GET_NX_CFG() true//ȡڴ汣Ƿֵ LOSCFG_KERNEL_NX 걻ʱ true false
+#define LOS_SET_NX_CFG(value)//ڴ汣Ƶֵú궨Ϊհףûʵʲ
+#define LOS_GET_DL_NX_HEAP_BASE() LOS_DL_HEAP_BASE//ȡڴ汣Ƶʼַ LOSCFG_KERNEL_NX 걻ʱ LOS_DL_HEAP_BASE NULL
+#define LOS_SET_DL_NX_HEAP_BASE(addr)//ڴ汣Ƶʼַú궨Ϊհףûʵʲ
+#define LOS_GET_DL_NX_HEAP_SIZE() LOS_DL_HEAP_SIZE//ȡڴ汣ƵĴС LOSCFG_KERNEL_NX 걻ʱ LOS_DL_HEAP_SIZE 0
+#define LOS_SET_DL_NX_HEAP_SIZE(size)//ڴ汣ƵĴСú궨Ϊհףûʵʲ
#else /* LOSCFG_KERNEL_NX */
#define LOS_GET_NX_CFG() false
#define LOS_SET_NX_CFG(value)
@@ -101,7 +117,9 @@ extern UINT32 g_dlNxHeapSize;
#define LOS_SET_DL_NX_HEAP_SIZE(size)
#endif /* LOSCFG_KERNEL_NX */
-#define KERNEL_TICK_PER_SECOND LOSCFG_BASE_CORE_TICK_PER_SECOND
+//δһϵк궨壬ڽһЩòӳ䵽Ӧĺ궨塣
+//ĿǽòʹòʱֻҪӦĺ궨壬øòĴ롣ߴĿάԺͿֲԡ
+#define KERNEL_TICK_PER_SECOND LOSCFG_BASE_CORE_TICK_PER_SECOND//KERNEL_TICK_PER_SECOND궨ΪLOSCFG_BASE_CORE_TICK_PER_SECONDζڴʹKERNEL_TICK_PER_SECONDʱʵʹò
#define KERNEL_TSK_LIMIT LOSCFG_BASE_CORE_TSK_LIMIT
#define KERNEL_TSK_MIN_STACK_SIZE LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE
#define KERNEL_TSK_DEFAULT_STACK_SIZE LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE
@@ -112,27 +130,27 @@ extern UINT32 g_dlNxHeapSize;
#define KERNEL_MUX_LIMIT LOSCFG_BASE_IPC_MUX_LIMIT
#define KERNEL_QUEUE_LIMIT LOSCFG_BASE_IPC_QUEUE_LIMIT
#define KERNEL_TIMESLICE_TIMEOUT LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT
-
+//#endif /* LOSCFG_LIB_CONFIGURABLE */ʾ궨ĽLOSCFG_LIB_CONFIGURABLEʱ궨岻ãΪ¶ġ
#endif /* LOSCFG_LIB_CONFIGURABLE */
/**
* system sections start and end address
*/
-extern CHAR __int_stack_start;
-extern CHAR __int_stack_end;
-extern CHAR __rodata_start;
-extern CHAR __rodata_end;
-extern CHAR __bss_start;
-extern CHAR __bss_end;
-extern CHAR __text_start;
-extern CHAR __text_end;
-extern CHAR __ram_data_start;
-extern CHAR __ram_data_end;
-extern CHAR __exc_heap_start;
-extern CHAR __exc_heap_end;
-extern CHAR __heap_start;
-extern CHAR __init_array_start__;
-extern CHAR __init_array_end__;
+extern CHAR __int_stack_start;//ڲջʼַ
+extern CHAR __int_stack_end;//ڲջĽַ
+extern CHAR __rodata_start;//ֻݶεʼַ
+extern CHAR __rodata_end;//ֻݶεĽַ
+extern CHAR __bss_start;//δʼȫֱΣBSS Segmentʼַ
+extern CHAR __bss_end;//δʼȫֱΣBSS SegmentĽַ
+extern CHAR __text_start;//ִдΣText Segmentʼַ
+extern CHAR __text_end;//ִдΣText SegmentĽַ
+extern CHAR __ram_data_start;//RAM ݶεʼַ
+extern CHAR __ram_data_end;//RAM ݶεĽַ
+extern CHAR __exc_heap_start;//쳣ѣException Heapʼַ
+extern CHAR __exc_heap_end;//쳣ѣException HeapĽַ
+extern CHAR __heap_start;//ѣHeapʼַ
+extern CHAR __init_array_start__;//ʼʼַ
+extern CHAR __init_array_end__; //ʼĽַ
/****************************** System clock module configuration ****************************/
/**
@@ -140,24 +158,24 @@ extern CHAR __init_array_end__;
* System clock (unit: HZ)
*/
#ifndef OS_SYS_CLOCK
-#define OS_SYS_CLOCK (get_bus_clk())
+#define OS_SYS_CLOCK (get_bus_clk())//ϵͳʱƵʣĬֵΪget_bus_clk()
#endif
/**
* @ingroup los_config
* time timer clock (unit: HZ)
*/
#ifndef OS_TIME_TIMER_CLOCK
-#define OS_TIME_TIMER_CLOCK OS_SYS_CLOCK
+#define OS_TIME_TIMER_CLOCK OS_SYS_CLOCK//嶨ʱʱƵʣĬֵΪ OS_SYS_CLOCK
#endif
/**
* limit addr range when search for 'func local(frame pointer)' or 'func name'
*/
#ifndef OS_SYS_FUNC_ADDR_START
-#define OS_SYS_FUNC_ADDR_START ((UINTPTR)&__int_stack_start)
+#define OS_SYS_FUNC_ADDR_START ((UINTPTR)&__int_stack_start)//庯ʼַĬֵΪ&__int_stack_start
#endif
#ifndef OS_SYS_FUNC_ADDR_END
-#define OS_SYS_FUNC_ADDR_END g_sys_mem_addr_end
+#define OS_SYS_FUNC_ADDR_END g_sys_mem_addr_end//庯ַֹĬֵΪg_sys_mem_addr_end
#endif
/**
@@ -165,14 +183,14 @@ extern CHAR __init_array_end__;
* Microseconds of adjtime in one second
*/
#ifndef LOSCFG_BASE_CORE_ADJ_PER_SECOND
-#define LOSCFG_BASE_CORE_ADJ_PER_SECOND 500
+#define LOSCFG_BASE_CORE_ADJ_PER_SECOND 500//ÿӵʱ䡣ûжLOSCFG_BASE_CORE_ADJ_PER_SECOND䶨Ϊ500ζϵͳڽʱʱÿӿ500롣
#endif
/**
* @ingroup los_config
* Sched clck interval
*/
-#define SCHED_CLOCK_INTETRVAL_TICKS 100
+#define SCHED_CLOCK_INTETRVAL_TICKS 100//ʾʱӵļ궨ֵΪ100ʾʱӵļΪ100ʱӽġ
/****************************** Interrupt module configuration ****************************/
/**
@@ -184,7 +202,7 @@ extern CHAR __init_array_end__;
*/
#ifdef LOSCFG_ARCH_INTERRUPT_PREEMPTION
#ifndef MAX_BINARY_POINT_VALUE
-#define MAX_BINARY_POINT_VALUE 4
+#define MAX_BINARY_POINT_VALUE 4//ʹǷѾMAX_BINARY_POINT_VALUEꡣûж壬䶨Ϊ4
#endif
#endif
@@ -197,6 +215,11 @@ extern CHAR __init_array_end__;
* 0xFFFF: max number of all software timers
*/
#ifndef OS_SWTMR_MAX_TIMERID
+/*ʾʱID
+ĬֵΪ((0xFFFF / KERNEL_SWTMR_LIMIT) * KERNEL_SWTMR_LIMIT)
+KERNEL_SWTMR_LIMITʾϵͳÿԴʱ
+궨ǽõIDһʱΧڣ
+ԸõIDԴ*/
#define OS_SWTMR_MAX_TIMERID ((0xFFFF / KERNEL_SWTMR_LIMIT) * KERNEL_SWTMR_LIMIT)
#endif
/**
@@ -204,6 +227,11 @@ extern CHAR __init_array_end__;
* Maximum size of a software timer queue. The default value of LOSCFG_BASE_CORE_SWTMR_LIMIT is 16.
*/
#ifndef OS_SWTMR_HANDLE_QUEUE_SIZE
+/*ʾʱеС
+ĬֵΪKERNEL_SWTMR_LIMIT
+Ҳϵͳÿͬʱʱ
+궨ܹʱ
+ԱԴ˷Ѻ⡣*/
#define OS_SWTMR_HANDLE_QUEUE_SIZE KERNEL_SWTMR_LIMIT
#endif
#endif
@@ -214,6 +242,10 @@ extern CHAR __init_array_end__;
* Starting address of the system memory
*/
#ifndef OS_SYS_MEM_ADDR
+/*__heap_startӽűжķţ
+ʾڴصʼַ
+ˣOS_SYS_MEM_ADDRֵڴصʼַָ룬
+ͨúϵͳڴء*/
#define OS_SYS_MEM_ADDR (&__heap_start)
#endif
@@ -223,9 +255,11 @@ extern CHAR __init_array_end__;
* Starting address of dynload heap
*/
#if defined (LOSCFG_KERNEL_NX) && defined (LOSCFG_KERNEL_DYNLOAD)
-#define LOS_DL_HEAP_SIZE (LOSCFG_KERNLE_DYN_HEAPSIZE * 0x100000)
-#define LOS_DL_HEAP_BASE (SYS_MEM_END - LOS_DL_HEAP_SIZE)
+//궼ˣô̬ģѵĴСΪ
+#define LOS_DL_HEAP_SIZE (LOSCFG_KERNLE_DYN_HEAPSIZE * 0x100000)//(LOSCFG_KERNLE_DYN_HEAPSIZE * 0x100000)
+#define LOS_DL_HEAP_BASE (SYS_MEM_END - LOS_DL_HEAP_SIZE)//SYS_MEM_END - LOS_DL_HEAP_SIZESYS_MEM_ENDʾϵͳڴصĽַ
#else
+//ûжLOSCFG_KERNEL_NXLOSCFG_KERNEL_DYNLOAD̬꣬ģѵĴСʼַΪ0
#define LOS_DL_HEAP_SIZE 0
#define LOS_DL_HEAP_BASE 0
#endif
@@ -236,7 +270,7 @@ extern CHAR __init_array_end__;
*/
#ifndef OS_SYS_MEM_SIZE
#define OS_SYS_MEM_SIZE ((g_sys_mem_addr_end) - \
- ((LOS_DL_HEAP_SIZE + ((UINTPTR)&__heap_start) + (64 - 1)) & ~(64 - 1)))
+ ((LOS_DL_HEAP_SIZE + ((UINTPTR)&__heap_start) + (64 - 1)) & ~(64 - 1)))//ڴصĴС
#endif
/****************************** fw Interface configuration **************************/
@@ -245,11 +279,12 @@ extern CHAR __init_array_end__;
* The core number is one in non-SMP architecture.
*/
#ifdef LOSCFG_KERNEL_SMP
+//LOSCFG_KERNEL_CORE_NUM Ϊ LOSCFG_KERNEL_SMP_CORE_NUM ֵLOSCFG_KERNEL_CORE_NUM Ϊ 1
#define LOSCFG_KERNEL_CORE_NUM LOSCFG_KERNEL_SMP_CORE_NUM
#else
#define LOSCFG_KERNEL_CORE_NUM 1
#endif
-
+//LOSCFG_KERNEL_CPU_MASK Ϊڱʾ CPU ıʽʹλ㣬ͨ 1 LOSCFG_KERNEL_CORE_NUM λȻȥ 1һ LOSCFG_KERNEL_CORE_NUM 1 Ķͨ CPU ԣȷ߳̿Щ CPU ϡ
#define LOSCFG_KERNEL_CPU_MASK ((1 << LOSCFG_KERNEL_CORE_NUM) - 1)
/****************************** trace module configuration **************************/
@@ -259,6 +294,10 @@ extern CHAR __init_array_end__;
*/
#ifdef LOSCFG_KERNEL_TRACE
#ifdef LOSCFG_RECORDER_MODE_OFFLINE
+/*LOSCFG_KERNEL_TRACE £ôᱻ롣
+ͬʱ LOSCFG_RECORDER_MODE_OFFLINE
+ LOSTRACE_BUFFER_SIZE ᱻΪ LOSCFG_TRACE_BUFFER_SIZE ֵ
+LOSTRACE_BUFFER_SIZE ᱻΪ 0*/
#define LOS_TRACE_BUFFER_SIZE LOSCFG_TRACE_BUFFER_SIZE
#else
#define LOS_TRACE_BUFFER_SIZE 0
@@ -277,39 +316,44 @@ extern CHAR __init_array_end__;
/**
* Version number
*/
-#define _T(x) x
-#define HW_LITEOS_SYSNAME "Huawei LiteOS"
-#define HW_LITEOS_SEP " "
-#define _V(v) _T(HW_LITEOS_SYSNAME)_T(HW_LITEOS_SEP)_T(v)
+//δһ궨壬ڶϵͳİ汾źϵͳơ
+#define _T(x) x//궨彫IJ x ԭأں궨бʾַ
+#define HW_LITEOS_SYSNAME "Huawei LiteOS"//궨Ϊַ "Huawei LiteOS"ʾϵͳơ
+#define HW_LITEOS_SEP " "//궨Ϊַ " "ʾƺͰ汾֮ķָ
+#define _V(v) _T(HW_LITEOS_SYSNAME)_T(HW_LITEOS_SEP)_T(v)//궨ͨϵͳƺͰ汾һİ汾ַ
-#define HW_LITEOS_VERSION "V200R005C20B053"
-#define HW_LITEOS_VER _V(HW_LITEOS_VERSION"-SMP")
+#define HW_LITEOS_VERSION "V200R005C20B053"//궨Ϊַ "V200R005C20B053"ʾϵͳľ汾š
+#define HW_LITEOS_VER _V(HW_LITEOS_VERSION"-SMP")//궨ʹ _V ꣬ϵͳƺͰ汾γ "Huawei LiteOS V200R005C20B053-SMP" 汾ַ
/**
* The Version number of Public
*/
-#define MAJ_V 5
-#define MIN_V 1
-#define REL_V 0
+#define MAJ_V 5//궨Ϊ 5ʾϵͳҪ汾š
+#define MIN_V 1//궨Ϊ 1ʾϵͳĴҪ汾š
+#define REL_V 0//궨Ϊ 0ʾϵͳķ汾š
/**
* The release candidate version number
*/
-#define EXTRA_V 0
+//Щ궨ͺڹϵͳİ汾ţṩһֽ汾תΪַʽĻơ
+#define EXTRA_V 0//궨Ϊ 0ʾϵͳĶ汾Żѡ汾š
-#define VERSION_NUM(a, b, c) (((a) << 16) | ((b) << 8) | (c))
-#define HW_LITEOS_OPEN_VERSION_NUM VERSION_NUM(MAJ_V, MIN_V, REL_V)
+#define VERSION_NUM(a, b, c) (((a) << 16) | ((b) << 8) | (c))//궨彫汾 aΰ汾 b ͷ汾 c ϳһͨλʵ֡
+#define HW_LITEOS_OPEN_VERSION_NUM VERSION_NUM(MAJ_V, MIN_V, REL_V)// 궨ʹ VERSION_NUM ꣬汾šΰ汾źͷ汾һʾ汾ŵ
-#define STRINGIFY_1(x) #x
-#define STRINGIFY(x) STRINGIFY_1(x)
+#define STRINGIFY_1(x) #x//궨彫 x תΪַ
+#define STRINGIFY(x) STRINGIFY_1(x)//궨 STRINGIFY_1 ꣬תΪַ
-#define HW_LITEOS_OPEN_VERSION_STRING STRINGIFY(MAJ_V) "." STRINGIFY(MIN_V) "." STRINGIFY(REL_V)
+#define HW_LITEOS_OPEN_VERSION_STRING STRINGIFY(MAJ_V) "." STRINGIFY(MIN_V) "." STRINGIFY(REL_V)//궨ʹ STRINGIFY ꣬汾šΰ汾źͷ汾תΪ "5.1.0" ַʽ
#if (EXTRA_V != 0)
+/* 0 HW_LITEOS_KERNEL_VERSION_STRING 궨Ϊкѡ汾ŵİ汾ַ
+Ϊѡ汾ŵİ汾ַ*/
#define HW_LITEOS_KERNEL_VERSION_STRING HW_LITEOS_OPEN_VERSION_STRING "-rc" STRINGIFY(EXTRA_V)
#else
#define HW_LITEOS_KERNEL_VERSION_STRING HW_LITEOS_OPEN_VERSION_STRING
#endif
+// 0 HW_LITEOS_KERNEL_VERSION_STRING 궨Ϊкѡ汾ŵİ汾ַΪѡ汾ŵİ汾ַ
extern VOID OsStart(VOID);
extern UINT32 OsMain(VOID);
extern VOID *OsGetMainTask(VOID);
diff --git a/src/kernel/include/los_cppsupport.h b/src/kernel/include/los_cppsupport.h
index cdf3fd4..c02d5e4 100644
--- a/src/kernel/include/los_cppsupport.h
+++ b/src/kernel/include/los_cppsupport.h
@@ -47,6 +47,8 @@ extern "C" {
* If LOS_CppSystemInit() is called in the first stage of scatter load,
* this flag should be passed as the third parameter.
*/
+/*ɢصĵһε LOS_CppSystemInit
+˱־ӦΪݡ*/
#define BEFORE_SCATTER 0
/**
@@ -54,6 +56,8 @@ extern "C" {
* If LOS_CppSystemInit() is called in the second stage of scatter load,
* this flag should be passed as the third parameter.
*/
+/*ɢصĵڶε LOS_CppSystemInit
+˱־ӦΪݡ*/
#define AFTER_SCATTER 1
/**
@@ -61,6 +65,8 @@ extern "C" {
* If scatter load is disabled, this flag should be passed as the third
* parameter when LOS_CppSystemInit() is called.
*/
+/*˷ɢأڵ LOS_CppSystemInit ʱ
+Ӧ˱־Ϊݡ*/
#define NO_SCATTER 2
/**
@@ -87,6 +93,16 @@ extern "C" {
*
- los_cppsupport.h: the header file that contains the API declaration.
* @since Huawei LiteOS V100R001C00
*/
+//ʼϵͳC++лĺ
+/*˵LOS_CppSystemInitҪ
+ȫ־̬Ĺ캯C++У
+ȫ־̬Ĺ캯Ҫڳʼǰá
+LOS_CppSystemInitȫ־̬б
+εǵĹ캯
+ִC++ʱijʼ
+ȫ־̬Ĺ캯֮⣬
+ҪִC++ʱصijʼ
+磬ԳʼC++쳣ơ̬ڴȡ*/
extern INT32 LOS_CppSystemInit(UINTPTR initArrayStart, UINTPTR initArrayEnd, INT32 flag);
#ifdef __cplusplus
diff --git a/src/kernel/include/los_cpup.h b/src/kernel/include/los_cpup.h
index 3591a26..690cea4 100644
--- a/src/kernel/include/los_cpup.h
+++ b/src/kernel/include/los_cpup.h
@@ -53,6 +53,9 @@ extern "C" {
*
* Solution: Decrease the maximum number of tasks.
*/
+/* CPUģзڴ治Ĵ
+ҾĴ LOS_ERRNO_OS_ERROR ģIDLOS_MOD_CPUPʹ루0x00ɵġ
+ԱڳбʶʹضĴ*/
#define LOS_ERRNO_CPUP_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x00)
/**
@@ -63,6 +66,9 @@ extern "C" {
*
* Solution: Check whether the pointer to the input parameter is usable.
*/
+/* CPUģз˿ָ
+ҾĴ LOS_ERRNO_OS_ERROR ģIDLOS_MOD_CPUPʹ루0x01ɵġ
+ԱڳбʶʹضĴ*/
#define LOS_ERRNO_CPUP_TASK_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x01)
/**
@@ -73,6 +79,9 @@ extern "C" {
*
* Solution: Check whether the CPU usage is initialized.
*/
+/* CPUģзδʼĴ
+Ĵ LOS_ERRNO_OS_ERROR ģIDLOS_MOD_CPUPʹ루0x02ɵġ
+ԱڳбʶʹضĴ*/
#define LOS_ERRNO_CPUP_NO_INIT LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x02)
/**
@@ -83,6 +92,9 @@ extern "C" {
*
* Solution: Check whether the number of threads is applicable for the current operation.
*/
+/* CPUģзЧ
+Ĵ LOS_ERRNO_OS_ERROR ģIDLOS_MOD_CPUPʹ루0x03ɵġ
+ԱڳбʶʹضĴ*/
#define LOS_ERRNO_CPUP_MAXNUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x03)
/**
@@ -93,6 +105,9 @@ extern "C" {
*
* Solution: Check whether the target thread is created.
*/
+/* CPUģз߳δĴ
+Ĵ LOS_ERRNO_OS_ERROR ģIDLOS_MOD_CPUPʹ루0x04ɵġ
+ԱڳбʶʹضĴ*/
#define LOS_ERRNO_CPUP_THREAD_NO_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x04)
/**
@@ -103,12 +118,22 @@ extern "C" {
*
* Solution: Check whether the target task ID is applicable for the current operation.
*/
+/*CPUģзЧID
+Ĵ LOS_ERRNO_OS_ERROR ģIDLOS_MOD_CPUPʹ루0x05ɵġ
+ԱڳбʶʹضĴ*/
#define LOS_ERRNO_CPUP_TSK_ID_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x05)
/**
* @ingroup los_cpup
* The structure of the CPU usage information of all tasks.
*/
+/*CPUϢ
+ṹԱ
+usStatusʾ״̬һ 16 λ
+uwUsageʾ CPU ʹʣһ 32 λλΪ permillageǧ֮һ
+ڲϵͳУCPU ḺϵͳиִС
+CPUP_INFO_S ṹṩһַʽ
+˽״̬ϵͳ CPU ʹϢ*/
typedef struct tagCpupInfo {
UINT16 usStatus; /**< The task status. */
UINT32 uwUsage; /**< CPU usage of all tasks. It is a permillage. And the value range is [0,1000]. */
@@ -118,9 +143,13 @@ typedef struct tagCpupInfo {
* @ingroup los_cpup
* The time period which the CPU usage collects in.
*/
+//ڱʾ CPU ʹʵʱ䷶Χ
enum {
+ //ʾʾ 10 ӵ CPU ʹʣֵΪ0
CPUP_LAST_TEN_SECONDS = 0, /**< Display CPU usage in the last ten seconds, the value is 0. */
+ //ʾʾ 1 ӵ CPU ʹʣֵΪ1
CPUP_LAST_ONE_SECONDS = 1, /**< Display CPU usage in the last one second, the value is 1. */
+ //ʾʾϵͳڵ CPU ʹʣֵΪ 0xffff
CPUP_ALL_TIME = 0xffff /**< Display CPU usage from system startup to now, the value is 0xffff. */
};
@@ -149,6 +178,7 @@ enum {
* @see LOS_HistoryTaskCpuUsage | LOS_AllCpuUsage
* @since Huawei LiteOS V100R001C00
*/
+//ȡʷϵͳCPUʹʡ mode ָȡ CPU ʹʵʱ䷶Χá
extern UINT32 LOS_HistorySysCpuUsage(UINT32 mode);
/**
@@ -182,6 +212,9 @@ extern UINT32 LOS_HistorySysCpuUsage(UINT32 mode);
* @see LOS_HistorySysCpuUsage
* @since Huawei LiteOS V100R001C00
*/
+/*ڻȡʷCPUʹʡ
+ taskId ʾIDʶ
+mode ܱʾȡCPUʹʵģʽѡ*/
extern UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskId, UINT32 mode);
/**
@@ -224,6 +257,10 @@ extern UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskId, UINT32 mode);
* - los_cpup.h: the header file that contains the API declaration.
* @since Huawei LiteOS V100R001C00
*/
+/*ڻȡϵͳCPUʹϢ
+ maxNum ʾCPUcpupInfo ʾڴ洢CPUʹϢĽṹָ룬
+mode ܱʾȡCPUʹʵģʽѡ
+flag ܱʾĿƱ־λ*/
extern UINT32 LOS_AllCpuUsage(UINT16 maxNum, CPUP_INFO_S *cpupInfo, UINT32 mode, UINT16 flag);
/**
@@ -244,6 +281,10 @@ extern UINT32 LOS_AllCpuUsage(UINT16 maxNum, CPUP_INFO_S *cpupInfo, UINT32 mode,
* - los_cpup.h: the header file that contains the API declaration.
* @since Huawei LiteOS V100R001C00
*/
+/*LOS_CpupReset ϵͳжϣ
+ǵ CPU ʹͳϢ㡣
+һжִʱ
+ϵͳͻ¿ʼ¼ǵ CPU ʹʡ*/
extern VOID LOS_CpupReset(VOID);
#ifdef __cplusplus
diff --git a/src/kernel/include/los_err.h b/src/kernel/include/los_err.h
index ff84c03..ef1f1dc 100644
--- a/src/kernel/include/los_err.h
+++ b/src/kernel/include/los_err.h
@@ -62,11 +62,12 @@ extern "C" {
* - los_err.h: the header file that contains the API declaration.
* @since Huawei LiteOS V100R001C00
*/
-typedef VOID (*LOS_ERRORHANDLE_FUNC)(CHAR *fileName,
- UINT32 lineNo,
- UINT32 errorNo,
- UINT32 paraLen,
- VOID *para);
+//LOS_ERRORHANDLE_FUNC һָָͣһú
+typedef VOID (*LOS_ERRORHANDLE_FUNC)(CHAR *fileName,//ʾļ
+ UINT32 lineNo,//ʾкš
+ UINT32 errorNo,//ʾš
+ UINT32 paraLen,//ʾӲijȡ
+ VOID *para);//ʾӲָ롣
/**
* @ingroup los_err
@@ -88,6 +89,15 @@ typedef VOID (*LOS_ERRORHANDLE_FUNC)(CHAR *fileName,
* - los_err.h: the header file that contains the API declaration.
* @since Huawei LiteOS V100R001C00
*/
+/*Ǵйзʱ
+Եд¼Ϣ־Ȳ
+IJڶλľϢ
+ӶõؽдŲ顣
+CHAR *fileNameʾļ
+UINT32 lineNoʾкš
+UINT32 errorNoʾ͡
+UINT32 paraLenʾݵIJȡ
+VOID *paraʾݵIJ*/
extern UINT32 LOS_ErrHandle(CHAR *fileName, UINT32 lineNo,
UINT32 errorNo, UINT32 paraLen,
VOID *para);
diff --git a/src/kernel/include/los_errno.h b/src/kernel/include/los_errno.h
index 9d05458..106b7ef 100644
--- a/src/kernel/include/los_errno.h
+++ b/src/kernel/include/los_errno.h
@@ -46,31 +46,31 @@ extern "C" {
* @ingroup los_errno
* OS error code flag. It is a 24-bit unsigned integer. Its value is 0x000000U.
*/
-#define LOS_ERRNO_OS_ID (0x00U << 16)
+#define LOS_ERRNO_OS_ID (0x00U << 16)//궨Ϊ 0x00U << 16ʾϵͳصĴ롣
/**
* @ingroup los_errno
* Define the error level as informative. It is a 32-bit unsigned integer. Its value is 0x00000000U.
*/
-#define LOS_ERRTYPE_NORMAL (0x00U << 24)
+#define LOS_ERRTYPE_NORMAL (0x00U << 24)//궨ʾΪ "informative"Ϣ𣩣ֵΪ 0x00U << 24
/**
* @ingroup los_errno
* Define the error level as warning. It is a 32-bit unsigned integer. Its value is 0x01000000U.
*/
-#define LOS_ERRTYPE_WARN (0x01U << 24)
+#define LOS_ERRTYPE_WARN (0x01U << 24)//궨ʾΪ "warning"漶𣩣ֵΪ 0x01U << 24
/**
* @ingroup los_errno
* Define the error level as critical. It is a 32-bit unsigned integer. Its value is 0x02000000U.
*/
-#define LOS_ERRTYPE_ERROR (0x02U << 24)
+#define LOS_ERRTYPE_ERROR (0x02U << 24)//궨ʾΪ "critical"ؼ𣩣ֵΪ 0x02U << 24
/**
* @ingroup los_errno
* Define the error level as fatal. It is a 32-bit unsigned integer. Its value is 0x03000000U.
*/
-#define LOS_ERRTYPE_FATAL (0x03U << 24)
+#define LOS_ERRTYPE_FATAL (0x03U << 24)//궨ʾΪ "fatal"𣩣ֵΪ 0x03U << 24
/**
* @ingroup los_errno
@@ -82,6 +82,14 @@ extern "C" {
* 0-7 bits indicate the error code number. It is specified by ERRNO.
*
*/
+/*ɲϵͳ롣
+LOS_ERRTYPE_FATAL ʾΪ "fatal"𣩣ֵΪ 0x03U << 24
+LOS_ERRNO_OS_ID ʾϵͳصĴ룬ֵΪ 0x00U << 16
+(UINT32)(MID) << 8 MID 8 λڱʾģʶ
+(UINT32)(ERRNO) ʾĴ롣
+λLOS_ERRNO_OS_FATAL һϵͳ룬
+ʽΪLOS_ERRTYPE_FATAL+ ԴLOS_ERRNO_OS_ID+ ģʶMID+ 루ERRNO
+ͨĺ꣬Էɲͬ͵Ĵ룬ݴIJͬԽзʹ*/
#define LOS_ERRNO_OS_FATAL(MID, ERRNO) \
(LOS_ERRTYPE_FATAL | LOS_ERRNO_OS_ID | ((UINT32)(MID) << 8) | ((UINT32)(ERRNO)))
@@ -95,6 +103,15 @@ extern "C" {
* 0-7 bits indicate the error code number. It is specified by ERRNO.
*
*/
+/*δ붨һ LOS_ERRNO_OS_ERRORɲϵͳش롣
+úʹ¼λ
+LOS_ERRTYPE_ERROR ʾΪ "critical"ؼ𣩣ֵΪ 0x02U << 24
+LOS_ERRNO_OS_ID ʾϵͳصĴ룬ֵΪ 0x00U << 16
+(UINT32)(MID) << 8 MID 8 λڱʾģʶ
+(UINT32)(ERRNO) ʾĴ롣
+λLOS_ERRNO_OS_ERROR һϵͳش룬
+ʽΪLOS_ERRTYPE_ERROR+ ԴLOS_ERRNO_OS_ID+ ģʶMID+ 루ERRNO
+ͨĺ꣬Էɲͬ͵Ĵ룬ݴIJͬԽзʹ*/
#define LOS_ERRNO_OS_ERROR(MID, ERRNO) \
(LOS_ERRTYPE_ERROR | LOS_ERRNO_OS_ID | ((UINT32)(MID) << 8) | ((UINT32)(ERRNO)))
@@ -108,6 +125,15 @@ extern "C" {
* 0-7 bits indicate the error code number. It is specified by ERRNO.
*
*/
+/*δ붨һ LOS_ERRNO_OS_WARNɲϵͳ롣
+úʹ¼λ
+LOS_ERRTYPE_WARN ʾΪ "warning"漶𣩣ֵΪ 0x01U << 24
+LOS_ERRNO_OS_ID ʾϵͳصĴ룬ֵΪ 0x00U << 16
+(UINT32)(MID) << 8 MID 8 λڱʾģʶ
+(UINT32)(ERRNO) ʾĴ롣
+λLOS_ERRNO_OS_WARN һϵͳ룬
+ʽΪLOS_ERRTYPE_WARN+ ԴLOS_ERRNO_OS_ID+ ģʶMID+ 루ERRNO
+ͨĺ꣬Էɲͬ͵Ĵ룬ݴIJͬԽзʹڷ漶ĴʱԲȡӦĴʩԱDZķ*/
#define LOS_ERRNO_OS_WARN(MID, ERRNO) \
(LOS_ERRTYPE_WARN | LOS_ERRNO_OS_ID | ((UINT32)(MID) << 8) | ((UINT32)(ERRNO)))
@@ -121,13 +147,29 @@ extern "C" {
* 0-7 bits indicate the error code number. It is specified by ERRNO.
*
*/
+/*δ붨һ LOS_ERRNO_OS_NORMALɲϵͳͨ롣
+úʹ¼λ
+LOS_ERRTYPE_NORMAL ʾΪ "normal"ͨ𣩣ֵΪ 0x00U << 24
+LOS_ERRNO_OS_ID ʾϵͳصĴ룬ֵΪ 0x00U << 16
+(UINT32)(MID) << 8 MID 8 λڱʾģʶ
+(UINT32)(ERRNO) ʾĴ롣
+λLOS_ERRNO_OS_NORMAL һϵͳͨ룬
+ʽΪLOS_ERRTYPE_NORMAL+ ԴLOS_ERRNO_OS_ID+ ģʶMID+ 루ERRNO
+ͨĺ꣬Էɲͬ͵Ĵ룬ݴIJͬԽзʹڷͨĴʱԸҪӦĴ¼*/
#define LOS_ERRNO_OS_NORMAL(MID, ERRNO) \
(LOS_ERRTYPE_NORMAL | LOS_ERRNO_OS_ID | ((UINT32)(MID) << 8) | ((UINT32)(ERRNO)))
/**
* @ingroup los_errno
* Define the ID of each module in kernel. The ID is used in error code.
+ * ںжÿģ ID ID ڴ롣
*/
+/*δ붨һö LOS_MODULE_IDһϵеģʶӦֵ
+ÿģ鶼һΨһıʶڴнʶáЩʶֵʮƱʾģ LOS_MOD_SYS ֵ 0x0LOS_MOD_MEM ֵ 0x1Դơ
+öУһʶ LOS_MOD_BUTT һ־ʾöٵĽ
+ͨʹöͣԷʹЩģʶʾʹݲͬģ顣
+磬ʹ LOS_MOD_SYS ʾϵͳģ飬ڴнصIJжϡ
+֮öṩһּķʽʹøģıʶ*/
enum LOS_MOUDLE_ID {
LOS_MOD_SYS = 0x0, /**< System ID. Its value is 0x0. */
LOS_MOD_MEM = 0x1, /**< Dynamic memory module ID. Its value is 0x1. */
diff --git a/src/kernel/include/los_event.h b/src/kernel/include/los_event.h
index 7f1f653..47abca9 100644
--- a/src/kernel/include/los_event.h
+++ b/src/kernel/include/los_event.h
@@ -47,19 +47,19 @@ extern "C" {
* @ingroup los_event
* Event reading mode: The task waits for all its expected events to occur.
*/
-#define LOS_WAITMODE_AND 4U
+#define LOS_WAITMODE_AND 4U//ģʽʾȴ¼Ҳ˵ֻее¼ʱŻִС
/**
* @ingroup los_event
* Event reading mode: The task waits for any of its expected events to occur.
*/
-#define LOS_WAITMODE_OR 2U
+#define LOS_WAITMODE_OR 2U//ģʽʾȴκһ¼Ҳ˵ֻҪκһ¼ͻִС
/**
* @ingroup los_event
* Event reading mode: The event flag is immediately cleared after the event is read.
*/
-#define LOS_WAITMODE_CLR 1U
+#define LOS_WAITMODE_CLR 1U//ģʽʾ¼ȡ¼־Ҳ˵һȡ¼¼־ͻᱻ
/**
* @ingroup los_event
@@ -69,6 +69,14 @@ extern "C" {
* Value: 0x02001c00.
*
* Solution: Set bits excluding bit 25 of the event mask to events.
+ * δ붨һ LOS_ERRNO_EVENT_SETBIT_INVALID
+ ʾ¼λЧ궨ʹ LOS_ERRNO_OS_ERROR ꣬
+ úͨڶϵͳصĴ롣
+ LOS_MOD_EVENT ʾģ¼ģ飬
+ 0x00 Ǹô¼ģڲľš
+ ͨʹĺ궨壬Էڴúʹ룬
+ ͬʱҲڶԴзͶλij¼λЧʱ
+ Է룬Ӷõ֪ʲôⲢӦĴ
*/
#define LOS_ERRNO_EVENT_SETBIT_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x00)
@@ -81,6 +89,13 @@ extern "C" {
* Solution: Increase the waiting time for event reading, or make another task write a
* mask for the event.
*/
+/*δ붨һ LOS_ERRNO_EVENT_READ_TIMEOUTʾ¼ȡʱͬأú궨Ҳʹ LOS_ERRNO_OS_ERROR ꣬ʾôڲϵͳĴ룬¼ģڲľ 0x01
+
+ijȴ¼ʱ趨˳ʱʱ䣬
+ڸʱûеȵ¼ôͻ᷵룬
+֪¼ȡʱ
+ĶԱõжϺʹʱ
+ӶϵͳȶԺͿɿԡ*/
#define LOS_ERRNO_EVENT_READ_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x01)
/**
@@ -92,6 +107,13 @@ extern "C" {
*
* Solution: Pass in a valid EVENTMASK value.
*/
+/*δ붨һ LOS_ERRNO_EVENT_EVENTMASK_INVALIDʾ¼Ч
+ͬأú궨Ҳʹ LOS_ERRNO_OS_ERROR ꣬
+ʾôڲϵͳĴ룬¼ģڲľ 0x02
+¼ڱʶȴ¼¼Ч
+ʾָ¼벻Ϲ淶ʶ𡣵ʱ
+Է룬֪¼ЧͨĶ壬
+ԱԸõؼʹ¼صĴӶϵͳĽ׳ԺͿάԡ*/
#define LOS_ERRNO_EVENT_EVENTMASK_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x02)
/**
@@ -102,6 +124,15 @@ extern "C" {
*
* Solution: Read the event in a task.
*/
+/*δ붨һ LOS_ERRNO_EVENT_READ_IN_INTERRUPTʾжн¼ȡ
+ͬأú궨Ҳʹ LOS_ERRNO_OS_ERROR ꣬
+ʾôڲϵͳĴ룬¼ģڲľ 0x03
+ͨ£¼ȡӦнУжϴִС
+Ϊжϴиȼܻȵľͳͻ
+¼ȡжʱͻ᷵룬
+֪жн¼ȡDzֵ֧ġ
+ͨĶ壬Աʱֲжִ¼ȡ⣬
+ȷϵͳȷкͿɿԡ*/
#define LOS_ERRNO_EVENT_READ_IN_INTERRUPT LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x03)
/**
@@ -115,6 +146,15 @@ extern "C" {
*
* Solution: Pass in a valid flag value.
*/
+/*δ붨һ LOS_ERRNO_EVENT_FLAGS_INVALIDʾ¼־Ч
+ͬأú궨Ҳʹ LOS_ERRNO_OS_ERROR ꣬
+ʾôڲϵͳĴ룬¼ģڲľ 0x04
+¼־ڱʶض¼״̬ڽ¼ʱҪʹЧ¼־
+¼־ЧʱΪ˴ı־߱־Ԥڡ
+ʱԷ룬֪¼־Ч
+ͨĶ壬Աõؼʹ¼־صĴ
+ӶϵͳȶԺͿάԡԱԸݴλ¼־Ч⣬
+ȷ¼ȷԺͿɿԡ*/
#define LOS_ERRNO_EVENT_FLAGS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x04)
/**
@@ -125,6 +165,15 @@ extern "C" {
*
* Solution: Unlock the task and read the event.
*/
+/*δ붨һ LOS_ERRNO_EVENT_READ_IN_LOCKʾ״̬½¼ȡ
+ͬأú궨Ҳʹ LOS_ERRNO_OS_ERROR ꣬
+ʾôڲϵͳĴ룬¼ģڲľ 0x05
+ͨ£¼ȡӦڷ״̬½У
+Ϊ״̬½¼ȡܵԴ⡣
+״̬½¼ȡʱԷ룬
+֪¼ȡڲʵ״̬¡
+ͨĶ壬ԱԼʱֲ״ִ̬¼ȡ⣬
+ȷϵͳȷкͿɿԡϵͳIJԺͱDZڵ⡣*/
#define LOS_ERRNO_EVENT_READ_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x05)
/**
@@ -135,6 +184,14 @@ extern "C" {
*
* Solution: Check whether the input parameter is null.
*/
+/*δ붨һ LOS_ERRNO_EVENT_PTR_NULLʾָΪָ롣
+ͬأú궨Ҳʹ LOS_ERRNO_OS_ERROR ꣬
+ʾôڲϵͳĴ룬¼ģڲľ 0x06
+ڽ¼ʱͨҪһЩ¼롢¼־¼ȡ
+ݵָΪָ룬ܻᵼ·ʷǷڴ桢⡣ʱ
+Է룬֪ߴָΪָ롣
+ͨĶ壬ԱԼʱֲָ⣬
+ȷϵͳȷкͿɿԡϵͳȶԺͿάԡ*/
#define LOS_ERRNO_EVENT_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x06)
/**
@@ -147,6 +204,15 @@ extern "C" {
* Solution: Read the event in a vailid task.
* @deprecated This error code is obsolete since LiteOS 5.0.0.
*/
+/*δ붨һ LOS_ERRNO_EVENT_READ_IN_SYSTEM_TASK
+ʾϵͳн¼ȡͬأú궨Ҳʹ LOS_ERRNO_OS_ERROR ꣬
+ʾôڲϵͳĴ룬¼ģڲľ 0x07
+һ˵ϵͳнϸߵȨ𣬲ڲϵͳڲĹؼ
+ͨӦóˣϵͳн¼ȡܻԤڵΪ
+ƻϵͳȶԺͿɿԡϵͳн¼ȡʱ
+Է룬֪߲Ӧϵͳִ¼ȡ
+ͨĶ壬Աϵͳִ¼ȡ
+ӶȷϵͳкͰȫԡϵͳȶԺͿάԡ*/
#define LOS_ERRNO_EVENT_READ_IN_SYSTEM_TASK LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x07)
/**
@@ -157,12 +223,29 @@ extern "C" {
*
* Solution: Check whether the event list is not empty.
*/
+/*δ붨һ LOS_ERRNO_EVENT_SHOULD_NOT_DESTORY
+ʾͼٲӦñٵ¼ͬأú궨Ҳʹ LOS_ERRNO_OS_ERROR ꣬
+ʾôڲϵͳĴ룬¼ģڲľ 0x08
+¼УЩ¼ܲӦñ٣Ϊǿڱ߳ʹá
+ͼЩ¼ܻᵼ´ΪԴй©⡣ʱԷ룬֪߲ӦЩ¼
+ͨĶ壬ԱٲӦñٵ¼
+ӶȷϵͳкͿɿԡϵͳȶԺͿάԡ*/
#define LOS_ERRNO_EVENT_SHOULD_NOT_DESTORY LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x08)
/**
* @ingroup los_event
* Event control structure
*/
+/*δ붨һΪ tagEvent Ľṹ壬аԱ
+uwEventIDʾ¼룬¼ƿָʾѾ¼
+ͨڱʶ¼ͻԡ
+stEventListһڵ㣬ڽ¼ƿӣֶ֧¼Ĺ
+⣬ͨ typedef ؼֽ struct tagEvent ¶Ϊ EVENT_CB_S ͣ
+ͬʱָ EVENT_CB_S ṹָ PEVENT_CB_S
+ֽṹͨ¼ģ飬ڴ洢¼صϢ
+¼ıʶ¼ƿϵ
+ԱʹĽṹʵ¼Ĵɾȴʹȹܣ
+Ӷõعϵͳе첽¼ϵͳIJ*/
typedef struct tagEvent {
UINT32 uwEventID; /**< Event mask in the event control block,
indicating the event that has been logically processed. */
@@ -187,6 +270,15 @@ typedef struct tagEvent {
* @see LOS_EventClear
* @since Huawei LiteOS V100R001C00
*/
+/*UINT32 LOS_EventInit(PEVENT_CB_S eventCB) LiteOS ϵͳеһ
+ڳʼ¼ƿ顣
+ eventCB ָ¼ƿṹ EVENT_CB_S ָ룬
+ýṹڴ洢¼صϢ
+ķֵ UINT32 һʾִеĽ롣
+ͨɹִУ LOS_OK ʾɹضӦĴ롣
+ LOS_EventInit ʹ¼֮ǰ¼ƿгʼ
+ͨ˺ȷ¼ƿijʼ״̬ȷ
+ҿȫʹ¼ƿ¼ĵȴʹȲ*/
extern UINT32 LOS_EventInit(PEVENT_CB_S eventCB);
/**
@@ -223,6 +315,25 @@ extern UINT32 LOS_EventInit(PEVENT_CB_S eventCB);
* @see LOS_EventRead | LOS_EventWrite
* @since Huawei LiteOS V100R001C00
*/
+/*UINT32 LOS_EventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode) LiteOS ϵͳеһѯ¼
+
+˵:
+
+eventId һָָ룬ڴ洢ѯ¼ID
+eventMask һʾϣѯ¼롣
+mode һʾѯģʽ¼ֵ֮һ
+OS_EVENT_ORѯһ¼õ¼
+OS_EVENT_ANDѯ¼õ¼
+ķֵ UINT32 һ
+ʾִеĽ롣ͨɹִУ LOS_OK ʾɹ
+ضӦĴ롣
+ LOS_EventPoll ѯָ¼ָģʽ¼ǷѾ
+¼
+Ὣ¼IDд eventId ָĵַ LOS_OKû¼
+ѯģʽӦĴ루 LOS_ERRNO_EVENT_UNAVAILABLE
+˺ͨ¼ʹãʵĵȴ¼Ļơ
+ͨѯ¼Ըݲͬ¼״̬IJ
+ʵ첽¼ȵĹܡ*/
extern UINT32 LOS_EventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode);
/**
@@ -263,6 +374,24 @@ extern UINT32 LOS_EventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode);
* @see LOS_EventPoll | LOS_EventWrite
* @since Huawei LiteOS V100R001C00
*/
+/*UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout)
+ LiteOS ϵͳеһڶȡ¼
+˵:
+eventCB һָ¼ƿṹ EVENT_CB_S ָ룬ʾҪȡ¼ƿ顣
+eventMask һʾϣȡ¼롣
+mode һʾȡģʽ¼ֵ֮һ
+OS_EVENT_ORȴһ¼õ¼
+OS_EVENT_ANDȴ¼õ¼
+timeout һʾʱʱ䣬λΪϵͳʱӽ
+ָʱδȡسʱ롣
+ķֵ UINT32 һʾִеĽ롣
+ͨɹִУ LOS_OK ʾɹʱضӦĴ롣
+ LOS_EventRead Եȴָ¼ָģʽ¼ǷѾ
+¼᷵ LOS_OKû¼
+ݶȡģʽȴ¼Ĵֱʱڵȴڼ䣬ܻᱻ
+ֱ¼ȡ
+˺ͨ¼ʹãʵĵȴ¼Ļơͨȡ¼
+Ըݲͬ¼״̬IJʵ첽¼ȵĹܡ*/
extern UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout);
/**
@@ -311,6 +440,17 @@ extern UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events);
* @see LOS_EventPoll | LOS_EventRead | LOS_EventWrite
* @since Huawei LiteOS V100R001C00
*/
+/*UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events) LiteOS ϵͳеһд¼
+˵:
+eventCB һָ¼ƿṹ EVENT_CB_S ָ룬ʾҪд¼¼ƿ顣
+events һʾҪд¼롣
+ķֵ UINT32 һʾִеĽ롣
+ͨɹִУ LOS_OK ʾɹضӦĴ롣
+ LOS_EventWrite ָ¼ƿд¼
+¼ʾһ¼״̬ͨӦ¼λΪ 1 ʾ¼Ѿ
+¼дȴ¼ܻᱻѣ¼״̬IJ
+˺ͨ¼ʹãʵ֮ͬͨš
+ͨд¼ԴִУʵЭͬĹܡ*/
extern UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events);
/**
@@ -333,6 +473,22 @@ extern UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events);
* @see LOS_EventPoll | LOS_EventRead | LOS_EventWrite
* @since Huawei LiteOS V100R001C00
*/
+/*UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB) LiteOS ϵͳеһ¼ƿ顣
+˵:
+
+eventCB һָ¼ƿṹ EVENT_CB_S ָ룬ʾҪٵ¼ƿ顣
+ķֵ UINT32 һʾִеĽ롣
+ͨɹִУ LOS_OK ʾɹضӦĴ롣
+
+ LOS_EventDestroy һ¼ƿ飬ͷŸ¼ƿռõԴ
+һ¼ƿ鱻٣ʹø¼ƿ¼
+
+ʵӦУҪij¼ƿʱ
+ͨ LOS_EventDestroy ͷԴֹԴй©ϵͳԴ˷ѡ
+
+Ҫעǣ¼ƿ֮ǰ
+Ҫȷûڵȴ¼ʹø¼ͬ
+ܻᵼϵͳΪ쳣*/
extern UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB);
#ifdef __cplusplus
diff --git a/src/kernel/include/los_exc.h b/src/kernel/include/los_exc.h
index 07c38e9..56ec150 100644
--- a/src/kernel/include/los_exc.h
+++ b/src/kernel/include/los_exc.h
@@ -61,6 +61,23 @@ extern "C" {
* los_exc.h: the header file that contains the API declaration.
* @since Huawei LiteOS V100R001C00
*/
+/*LOS_Panic(const CHAR *fmt, ...) LiteOS ϵͳеһڴϵͳ
+˵:
+fmt һʽַʾϢĸʽ
+... ǿɱбݸʽַ fmt ҪӦIJ
+úûзֵ
+
+ LOS_Panic ᵼϵͳ״̬ϵͳִȥ
+ͨ£úڴشɻָ쳣
+Էֹϵͳִпܵ¸Ĵ롣
+
+úͨʽַһЩϢ
+ӶṩڱԭλûϢ
+ЩϢܶڵԺŲdzá
+
+ҪעǣLOS_Panic ӦýʹãڱҪʱʹá
+ڸúϵͳᵼϵͳֹͣвָ
+ӦñҵеøúɲҪϵͳжϡ*/
VOID LOS_Panic(const CHAR *fmt, ...);
/**
@@ -79,8 +96,22 @@ VOID LOS_Panic(const CHAR *fmt, ...);
* los_exc.h: the header file that contains the API declaration.
* @since Huawei LiteOS V200R005C10
*/
+/*VOID LOS_BackTrace(VOID) LiteOS ϵͳеĺڻȡǰ̵߳ĺջϢ
+úûвҲûзֵ
+ LOS_BackTrace ȡǰ̵߳ĺջϢ
+ÿĵõַԼӦĺЩϢڵԺŲdzã
+Ա˽ִʱḷ́λڡ
+
+ͨ£LOS_BackTrace ڵĿģڳ쳣ʱ
+ͨӡջϢԭ
+ڶλ쳣dzа
+
+ҪעǣLOS_BackTrace ʵֿھӲƽ̨ͱ
+ͬƽ̨ͱܻвͬʵַʽơ
+ˣʹøúʱҪ˽صƽ̨ͱԣȷȡȷĺջϢ*/
extern VOID LOS_BackTrace(VOID);
#define OsBackTrace LOS_BackTrace
+//궨彫 OsBackTrace 滻Ϊ LOS_BackTraceζڴʹ OsBackTrace ʱʵǵ LOS_BackTrace
/**
* @ingroup los_exc
@@ -99,9 +130,28 @@ extern VOID LOS_BackTrace(VOID);
* los_exc.h: the header file that contains the API declaration.
* @since Huawei LiteOS V100R001C00
*/
+/*VOID LOS_TaskBackTrace(UINT32 taskID) LiteOS ϵͳеĺڻȡָĺջϢ
+˵:
+taskID һʾҪȡջϢĿID
+úûзֵ
+
+ LOS_TaskBackTrace ԻȡָĺջϢ
+ÿĵõַԼӦĺЩϢڵԺŲdzã
+Ա˽ִָʱḷ́λڡ
+
+ͨ£LOS_TaskBackTrace ڵĿģض쳣ʱ
+ͨӡĺջϢԭ
+ڶλ쳣dzа
+
+ҪעǣLOS_TaskBackTrace ʵֿھӲƽ̨ͱ
+ͬƽ̨ͱܻвͬʵַʽơ
+ˣʹøúʱҪ˽صƽ̨ͱԣȷȡȷĺջϢ
+
+⣬ҪȷָIDЧġڵID
+ܵ»ȡȷĺջϢ*/
extern VOID LOS_TaskBackTrace(UINT32 taskID);
#define OsTaskBackTrace LOS_TaskBackTrace
-
+//궨彫 OsTaskBackTrace 滻Ϊ LOS_TaskBackTraceζڴʹ OsTaskBackTrace ʱʵǵ LOS_TaskBackTrace
#ifdef LOSCFG_SHELL_EXCINFO_DUMP
/**
* @ingroup los_exc
@@ -122,7 +172,14 @@ extern VOID LOS_TaskBackTrace(UINT32 taskID);
* - los_exc.h: the header file that contains the type definition.
* @since Huawei LiteOS V200R005C10
*/
+/*һָ͵Ķ塣һΪ LogReadWriteFunc ĺָͣ
+úָָһΪ VOID ĺ
+Ϊ UINTPTR startAddrUINT32 spaceUINT32 rwFlag CHAR *buf
+ֶ巽ʽضǩĺָͣԱڴʹá*/
typedef VOID (*LogReadWriteFunc)(UINTPTR startAddr, UINT32 space, UINT32 rwFlag, CHAR *buf);
+/*һ궨壬 log_read_write_fn 滻Ϊ LogReadWriteFunc
+עָһɵAPIʹͨ궨壬
+Խ log_read_write_fn 滻Ϊ LogReadWriteFuncԴﵽͳһĿġ*/
#define log_read_write_fn LogReadWriteFunc /* old API since V200R002C00, please avoid use of it */
/**
@@ -146,6 +203,22 @@ typedef VOID (*LogReadWriteFunc)(UINTPTR startAddr, UINT32 space, UINT32 rwFlag,
* - los_exc.h: the header file that contains the API declaration.
* @since Huawei LiteOS V200R002C00
*/
+/* LOS_ExcInfoRegHook LiteOS ϵͳеһ쳣ϢĴĻصӺ
+
+úĸ
+
+startAddr쳣ϢĴʼַ
+space쳣ϢĴĴСֽΪλ
+bufڴ洢쳣ϢĴݵĻ
+hookصӺΪ LogReadWriteFuncָ͡
+˵쳣ʱLiteOS LOS_ExcInfoRegHook
+쳣ϢĴʼַСͻΪݸ
+Ȼ LOS_ExcInfoRegHook ڲ
+ͨصӺ hook 쳣ϢĴݡ
+
+ܿԶ쳣쳣Ϣ¼ͨûصӺ
+쳣ʱȡ쳣ϢĴݣ
+Աнһķ¼*/
VOID LOS_ExcInfoRegHook(UINTPTR startAddr, UINT32 space, CHAR *buf, LogReadWriteFunc hook);
#endif
diff --git a/src/kernel/include/los_hw.h b/src/kernel/include/los_hw.h
index db1cf00..2105a21 100644
--- a/src/kernel/include/los_hw.h
+++ b/src/kernel/include/los_hw.h
@@ -59,9 +59,10 @@ extern "C" {
* los_hw.h: the header file that contains the API declaration.
* @since Huawei LiteOS V200R003C00
*/
+/*δ붨һ̬ LOS_CpuInfoúһַָָ롣*/
STATIC INLINE const CHAR *LOS_CpuInfo(VOID)
{
- return ArchCpuInfo();
+ return ArchCpuInfo();//ݵǰӲƽ̨öӦĵײ㺯ԻȡCPUϢͺšƵʡȵȡʵͨӲƽ̨صģҿҪһЩײļĴȡضƽ̨صIJ
}
#ifdef __cplusplus
diff --git a/src/kernel/include/los_hwi.h b/src/kernel/include/los_hwi.h
index 95233f2..4603103 100644
--- a/src/kernel/include/los_hwi.h
+++ b/src/kernel/include/los_hwi.h
@@ -48,12 +48,16 @@ extern "C" {
* @ingroup los_hwi
* Count of interrupts.
*/
+/*дһΪg_intCount飬Ķ岢ڵǰԴļС
+ؼ"extern"߱طģͨζԴļС
+ӽΣȥҵʵʵg_intCountĶ壬Ȼ뵱ǰĴӡ*/
extern size_t g_intCount[];
/**
* An interrupt is active.
*/
-extern size_t IntActive(VOID);
+
+extern size_t IntActive(VOID);//IntActive(VOID)ڻȡǰжĺúûвΪͣsize_t
/**
* @ingroup los_hwi
@@ -61,6 +65,16 @@ extern size_t IntActive(VOID);
*
* @see OS_INT_INACTIVE
*/
+
+ /*LiteOSϵͳУ#define OS_INT_ACTIVE IntActive() һԤָһꡣOS_INT_ACTIVE Ϊ IntActive() Ľ
+
+ 궨һڴʹõı滻ơ£
+ г OS_INT_ACTIVE ʱԤὫ滻Ϊ IntActive() ĵã
+ ʵϾǽΪһʹá
+
+ ֺ궨ĿĿΪ˼дߴĿɶԡ
+ ͨ꣬ͨƣOS_INT_ACTIVEʾӵĺãIntActive()
+ ӶʹӼ⡣*/
#define OS_INT_ACTIVE IntActive()
/**
@@ -71,6 +85,21 @@ extern size_t IntActive(VOID);
*
* @see OS_INT_ACTIVE
*/
+/*LiteOSϵͳУ#define OS_INT_INACTIVE (!(OS_INT_ACTIVE)) һԤָ
+һꡣOS_INT_INACTIVE Ϊ OS_INT_ACTIVE ȡĽ
+
+˵OS_INT_ACTIVE һ꣬ʾ IntActive() Ľ
+ OS_INT_INACTIVE һ꣬ʾ OS_INT_ACTIVE ȡĽ
+£ʹ ! OS_INT_ACTIVE Ľȡ
+
+궨ĿĿڱʾǰжǷڷǻ״̬
+ OS_INT_ACTIVE Ϊ棨㣩ʾжϴڻ״̬
+ OS_INT_INACTIVE Ϊ٣㣩ʾжϴڷǻ״̬
+
+ַͨʽ꣬Էڴжж״̬ӦĴ
+ʹ OS_INT_INACTIVE Ըֱ۵رʾжǷڷǻ״̬
+ߴĿɶԺͿάԡ
+*/
#define OS_INT_INACTIVE (!(OS_INT_ACTIVE))
/**
@@ -78,6 +107,18 @@ extern size_t IntActive(VOID);
* Highest priority of a hardware interrupt.This is an external parameter.
* The priority range is [OS_HWI_PRIO_HIGHEST, OS_HWI_PRIO_HIGHEST + LOSCFG_HWI_PRIO_LIMIT - 1].
*/
+/*LiteOSϵͳУ#define OS_HWI_PRIO_HIGHEST 0 һԤָ
+һꡣ OS_HWI_PRIO_HIGHEST Ϊ 0
+
+LiteOSϵͳУжϣInterruptҲΪӲжϣHardware Interrupt
+Ϊ HWIHWIвͬȼPriorityȼԽߣжӦʱԽ̡
+OS_HWI_PRIO_HIGHEST һʾжȼĺֵ꣬Ϊ 0
+
+LiteOSϵͳУжϵȼֱʾģԽСʾȼԽߡ
+ˣOS_HWI_PRIO_HIGHEST ʾжȼҲСжȼ
+һЩض£Ҫʹжȼ
+ʱʹ OS_HWI_PRIO_HIGHEST ʾжȼֵ 0
+Ӷؽдд*/
#define OS_HWI_PRIO_HIGHEST 0
/**
@@ -85,12 +126,36 @@ extern size_t IntActive(VOID);
* This represents the interrupt priority range, the larger number, the lower priority, the interrupt processor is
* modified uniformly.
*/
+/*LiteOSϵͳУ
+#define OS_HWI_PRIO_LOWEST (LOSCFG_HWI_PRIO_LIMIT - 1) һԤָ
+һꡣ OS_HWI_PRIO_LOWEST Ϊ LOSCFG_HWI_PRIO_LIMIT ȥ 1 Ľ
+
+LiteOSϵͳУжϣInterruptҲΪӲжϣHardware Interrupt
+Ϊ HWIHWIвͬȼPriorityȼԽߣжӦʱԽ̡OS_HWI_PRIO_LOWEST һʾжȼĺֵ꣬Ϊ LOSCFG_HWI_PRIO_LIMIT - 1
+
+LOSCFG_HWI_PRIO_LIMIT һòڱʾϵͳֵ֧жȼ
+ˣOS_HWI_PRIO_LOWEST ʾжȼҲжȼ
+ֵжȼȥ 1
+һЩض£Ҫʹжȼ
+ʱʹ OS_HWI_PRIO_LOWEST ʾжȼֵӶؽдд*/
#define OS_HWI_PRIO_LOWEST (LOSCFG_HWI_PRIO_LIMIT - 1)
/**
* @ingroup los_hwi
* The lower priority number, the higher priority, so OS_HWI_PRIO_LOWEST big than OS_HWI_PRIO_HIGHEST.
*/
+/*úһ priʾҪжϵжȼֵ
+Ķʹ && ͱȽ >=<=
+£
+
+((pri) >= OS_HWI_PRIO_HIGHEST) ʾж pri ǷڵжȼOS_HWI_PRIO_HIGHEST pri ڵжȼΪ棨㣩Ϊ٣㣩
+((pri) <= OS_HWI_PRIO_LOWEST) ʾж pri ǷСڵжȼOS_HWI_PRIO_LOWEST pri СڵжȼΪ棨㣩Ϊ٣㣩
+궨彫ʹ &&
+ (((pri) >= OS_HWI_PRIO_HIGHEST) && ((pri) <= OS_HWI_PRIO_LOWEST))
+ֻе pri ͬʱڵжȼСڵжȼʱ
+Ϊ棨㣩ʾжȼЧΪ٣㣩ʾжȼЧ
+ڽжȼжϺʱ
+ȷʹõжȼֵЧΧڣִжȼá*/
#define HWI_PRI_VALID(pri) (((pri) >= OS_HWI_PRIO_HIGHEST) && ((pri) <= OS_HWI_PRIO_LOWEST))
/**
@@ -105,6 +170,23 @@ extern size_t IntActive(VOID);
* Please use macros starting with LOS, and macros starting with OS will not be supported.
*
*/
+/*Ԥָ롣
+
+ЩڱʾڲϵͳӲжϣHWIģзĴ
+ͨʹLiteOSṩĴġ
+£
+
+LOS_ERRNO_HWI_NUM_INVALID һʾЧжϺŵĴ롣
+ôֵ LOS_ERRNO_OS_ERROR ɣ
+ģźʹֵ
+УLOS_MOD_HWI ʾHWIģģţ0x00 ʾֵ
+ˣLOS_ERRNO_HWI_NUM_INVALID ֵǸģźʹֵóġ
+OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_HWI_NUM_INVALID ı
+ͨ䶨ΪֵͬڴʹøʾЧжϺŵĴ롣
+Щڱ̹жϺʹHWIģصĴ
+磬úʹжʱЧжϺţ
+ͨ鷵صĴǷ LOS_ERRNO_HWI_NUM_INVALID OS_ERRNO_HWI_NUM_INVALID
+жжϺǷЧӦĴ*/
#define LOS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_HWI_NUM_INVALID
@@ -120,6 +202,22 @@ extern size_t IntActive(VOID);
* Please use macros starting with LOS, and macros starting with OS will not be supported.
*
*/
+/*Ԥָ롣
+
+ЩڱʾڲϵͳӲжϣHWIģзĴ
+ͨʹLiteOSṩĴġ
+£
+
+LOS_ERRNO_HWI_PROC_FUNC_NULL һʾжϴΪյĴ롣ôֵ LOS_ERRNO_OS_ERROR ɣ
+ģźʹֵ
+УLOS_MOD_HWI ʾHWIģģţ0x01 ʾֵ
+ˣLOS_ERRNO_HWI_PROC_FUNC_NULL ֵǸģźʹֵóġ
+OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_HWI_PROC_FUNC_NULL ı
+ͨ䶨ΪֵͬڴʹøʾжϴΪյĴ롣
+Щڱ̹жϺʹHWIģصĴ
+磬úʹжʱжϴΪգ
+ͨ鷵صĴǷ LOS_ERRNO_HWI_PROC_FUNC_NULL OS_ERRNO_HWI_PROC_FUNC_NULLжжϴǷȷã
+ӦĴ*/
#define LOS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
#define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_HWI_PROC_FUNC_NULL
@@ -132,6 +230,18 @@ extern size_t IntActive(VOID);
* Solution: This error code is not in use temporarily.
* @deprecated This error code is obsolete since LiteOS 5.0.0.
*/
+/**/
+/*һ룬ʾӲжϣHWIصõ
+£
+
+OS_ERRNO_HWI_CB_UNAVAILABLE ʾӲжϣHWIصõĴ롣
+ LOS_ERRNO_OS_ERROR ɣúģźʹֵ
+LOS_MOD_HWI ʾHWIģģţ0x02 ʾֵ
+ˣOS_ERRNO_HWI_CB_UNAVAILABLE ֵǸģźʹֵóġ
+ڱ̹жϺʹHWIģصĴ
+磬úעжϻصʱصã
+ͨ鷵صĴǷ OS_ERRNO_HWI_CB_UNAVAILABLEжϻصĿԣ
+ӶӦĴ*/
#define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
/**
@@ -146,6 +256,21 @@ extern size_t IntActive(VOID);
* Please use macros starting with LOS, and macros starting with OS will not be supported.
*
*/
+/*Ԥָ롣
+
+ЩڱʾڲϵͳӲжϣHWIģзĴͨʹLiteOSṩĴġ
+£
+
+LOS_ERRNO_HWI_NO_MEMORY һʾڴĴ롣
+ôֵ LOS_ERRNO_OS_ERROR ɣģźʹֵ
+УLOS_MOD_HWI ʾHWIģģţ0x03 ʾֵ
+ˣLOS_ERRNO_HWI_NO_MEMORY ֵǸģźʹֵóġ
+OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_HWI_NO_MEMORY ıͨ䶨Ϊֵͬ
+ڴʹøʾڴĴ롣
+Щڱ̹жϺʹHWIģصĴ
+磬úעжϴʱڴ
+ͨ鷵صĴǷ LOS_ERRNO_HWI_NO_MEMORY OS_ERRNO_HWI_NO_MEMORY
+жڴǷɹӦĴ*/
#define LOS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
#define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_HWI_NO_MEMORY
@@ -162,6 +287,22 @@ extern size_t IntActive(VOID);
* Please use macros starting with LOS, and macros starting with OS will not be supported.
*
*/
+/*Ԥָڶ롣
+
+ЩڱʾڲϵͳӲжϣHWIģзĴ
+ͨʹLiteOSṩĴġ
+£
+
+LOS_ERRNO_HWI_ALREADY_CREATED һʾжѾĴ롣
+ôֵ LOS_ERRNO_OS_ERROR ɣģźʹֵ
+LOS_MOD_HWI ʾHWIģģţ0x04 ʾֵ
+ˣLOS_ERRNO_HWI_ALREADY_CREATED ֵǸģźʹֵóġ
+OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_HWI_ALREADY_CREATED ı
+ͨ䶨ΪֵͬڴʹøʾжѾĴ롣
+Щڱ̹жϺʹHWIģصĴ
+磬ڴжʱжѾ
+ͨ鷵صĴǷ LOS_ERRNO_HWI_ALREADY_CREATED OS_ERRNO_HWI_ALREADY_CREATED
+жжǷѾڣӶӦĴ*/
#define LOS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
#define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_HWI_ALREADY_CREATED
@@ -177,6 +318,22 @@ extern size_t IntActive(VOID);
* Please use macros starting with LOS, and macros starting with OS will not be supported.
*
*/
+/*Ԥָڶ롣
+
+ЩڱʾڲϵͳӲжϣHWIģзĴ
+ͨʹLiteOSṩĴġ
+£
+
+LOS_ERRNO_HWI_PRIO_INVALID һʾжȼЧĴ롣
+ôֵ LOS_ERRNO_OS_ERROR ɣģźʹֵ
+LOS_MOD_HWI ʾHWIģģţ0x05 ʾֵ
+ˣLOS_ERRNO_HWI_PRIO_INVALID ֵǸģźʹֵóġ
+OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_HWI_PRIO_INVALID ı
+ͨ䶨ΪֵͬڴʹøʾжȼЧĴ롣
+Щڱ̹жϺʹHWIģصĴ
+磬жȼʱṩЧȼֵ
+ͨ鷵صĴǷ LOS_ERRNO_HWI_PRIO_INVALID OS_ERRNO_HWI_PRIO_INVALIDжȼǷЧ
+ӦĴ*/
#define LOS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_HWI_PRIO_INVALID
@@ -189,6 +346,18 @@ extern size_t IntActive(VOID);
* Solution: This error code is not in use temporarily.
* @deprecated This error code is obsolete since LiteOS 5.0.0.
*/
+/*һԤָڶ롣
+
+ôڱʾڲϵͳӲжϣHWIģзĴ
+˵жģʽЧĴ
+ͨʹLiteOSṩĴ LOS_ERRNO_OS_ERROR ġ
+úģźʹֵ
+LOS_MOD_HWI ʾHWIģģţ0x06 ʾֵ
+ˣOS_ERRNO_HWI_MODE_INVALID ֵǸģźʹֵóġ
+ڱ̹жϺʹHWIģصĴ
+磬жģʽʱṩЧģʽֵ
+ͨ鷵صĴǷ OS_ERRNO_HWI_MODE_INVALID
+жģʽǷЧӦĴ*/
#define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
/**
@@ -200,6 +369,19 @@ extern size_t IntActive(VOID);
* Solution: This error code is not in use temporarily.
* @deprecated This error code is obsolete since LiteOS 5.0.0.
*/
+/*һԤָڶ롣
+
+ôڱʾڲϵͳӲжϣHWIģзĴ
+˵ǿжģʽѾĴ
+ͨʹLiteOSṩĴ LOS_ERRNO_OS_ERROR ġ
+úģźʹֵ
+LOS_MOD_HWI ʾHWIģģţ0x07 ʾֵ
+ˣOS_ERRNO_HWI_FASTMODE_ALREADY_CREATED ֵǸģźʹֵóġ
+
+ڱ̹жϺʹHWIģصĴ
+磬ڴжģʽʱģʽѾ
+ͨ鷵صĴǷ OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED
+жϿжģʽǷѾڣӶӦĴ*/
#define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
/**
@@ -214,6 +396,23 @@ extern size_t IntActive(VOID);
* Please use macros starting with LOS, and macros starting with OS will not be supported.
*
*/
+/*Ԥָڶ롣
+
+ЩڱʾڲϵͳӲжϣHWIģзĴ˵ӲжϷĴ
+ͨʹLiteOSṩĴġ
+£
+
+LOS_ERRNO_HWI_INTERR һʾӲжϷĴ롣
+ôֵ LOS_ERRNO_OS_ERROR ɣ
+ģźʹֵ
+LOS_MOD_HWI ʾHWIģģţ0x08 ʾֵ
+ˣLOS_ERRNO_HWI_INTERR ֵǸģźʹֵóġ
+OS_ERRNO_HWI_INTERR LOS_ERRNO_HWI_INTERR ı
+ͨ䶨ΪֵͬڴʹøʾӲжϷĴ롣
+Щڱ̹жϺʹHWIģصĴ
+磬жϴУӲжϷ
+ͨ鷵صĴǷ LOS_ERRNO_HWI_INTERR OS_ERRNO_HWI_INTERR
+жжǷ˴ӦĴ*/
#define LOS_ERRNO_HWI_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08)
#define OS_ERRNO_HWI_INTERR LOS_ERRNO_HWI_INTERR
@@ -230,6 +429,22 @@ extern size_t IntActive(VOID);
* Please use macros starting with LOS, and macros starting with OS will not be supported.
*
*/
+/*Ԥָڶ롣
+
+ЩڱʾڲϵͳӲжϣHWIģзĴ˵ǹжϴĴ
+ͨʹLiteOSṩĴġ
+£
+
+LOS_ERRNO_HWI_SHARED_ERROR һʾжϴĴ롣
+ôֵ LOS_ERRNO_OS_ERROR ɣģźʹֵ
+LOS_MOD_HWI ʾHWIģģţ0x09 ʾֵ
+ˣLOS_ERRNO_HWI_SHARED_ERROR ֵǸģźʹֵóġ
+OS_ERRNO_HWI_SHARED_ERROR LOS_ERRNO_HWI_SHARED_ERROR ı
+ͨ䶨ΪֵͬڴʹøʾжϴĴ롣
+Щڱ̹жϺʹHWIģصĴ
+磬ùжʱ˴
+ͨ鷵صĴǷ LOS_ERRNO_HWI_SHARED_ERROR OS_ERRNO_HWI_SHARED_ERROR
+жϹжǷóɹӦĴ*/
#define LOS_ERRNO_HWI_SHARED_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x09)
#define OS_ERRNO_HWI_SHARED_ERROR LOS_ERRNO_HWI_SHARED_ERROR
@@ -242,6 +457,20 @@ extern size_t IntActive(VOID);
* Solution: This error code is not in use temporarily.
* @deprecated This error code is obsolete since LiteOS 5.0.0.
*/
+/*һԤָڶ롣
+
+ڱʾڲϵͳӲжϣHWIģзĴ˵ӲжϲЧĴ
+ͨʹLiteOSṩĴġ
+£
+
+OS_ERRNO_HWI_ARG_INVALID һʾӲжϲЧĴ롣
+ôֵ LOS_ERRNO_OS_ERROR ɣģźʹֵ
+LOS_MOD_HWI ʾHWIģģţ0x0a ʾֵ
+ˣOS_ERRNO_HWI_ARG_INVALID ֵǸģźʹֵóġ
+ڱ̹жϺʹHWIģصĴ
+磬עӲжϴʱݸIJЧ
+ͨ鷵صĴǷ OS_ERRNO_HWI_ARG_INVALIDжϲǷЧ
+ӦĴ*/
#define OS_ERRNO_HWI_ARG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0a)
/**
@@ -257,6 +486,22 @@ extern size_t IntActive(VOID);
* Please use macros starting with LOS, and macros starting with OS will not be supported.
*
*/
+/*Ԥָڶ롣
+
+ЩڱʾڲϵͳӲжϣHWIģзĴ˵ӲжϺδĴ
+ͨʹLiteOSṩĴġ
+£
+
+LOS_ERRNO_HWI_HWINUM_UNCREATE һʾӲжϺδĴ롣
+ôֵ LOS_ERRNO_OS_ERROR ɣģźʹֵ
+LOS_MOD_HWI ʾHWIģģţ0x0b ʾֵ
+ˣLOS_ERRNO_HWI_HWINUM_UNCREATE ֵǸģźʹֵóġ
+OS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_HWI_HWINUM_UNCREATE ı
+ͨ䶨ΪֵͬڴʹøʾӲжϺδĴ롣
+ڱ̹жϺʹHWIģصĴ
+磬ijӲжʱָжϺδ
+ͨ鷵صĴǷ LOS_ERRNO_HWI_HWINUM_UNCREATE OS_ERRNO_HWI_HWINUM_UNCREATE
+жжϺǷЧӦĴ*/
#define LOS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0b)
#define OS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_HWI_HWINUM_UNCREATE
@@ -264,18 +509,21 @@ extern size_t IntActive(VOID);
* @ingroup los_hwi
* Define the type HWI_HANDLE_T for a hardware interrupt number, the type is an unsigned int.
*/
+//д붨һµ HWI_HANDLE_TΪ UINT3232λHWI_HANDLE_T ʾӲжϵľʶ
typedef UINT32 HWI_HANDLE_T;
/**
* @ingroup los_hwi
* Define the type HWI_PRIOR_T for a hardware interrupt priority, the type is an unsigned short.
*/
+//д붨һµ HWI_PRIOR_TΪ UINT1616λHWI_PRIOR_T ʾӲжϵȼ
typedef UINT16 HWI_PRIOR_T;
/**
* @ingroup los_hwi
* Define the type HWI_MODE_T for hardware interrupt mode configurations, the type is an unsigned short.
*/
+//д붨һµ HWI_MODE_TΪ UINT1616λHWI_MODE_T ʾӲжϵģʽá
typedef UINT16 HWI_MODE_T;
/**
@@ -283,6 +531,9 @@ typedef UINT16 HWI_MODE_T;
* Define the type HWI_ARG_T for the parameter used for the hardware interrupt creation function.
* The function of this parameter varies among platforms.
*/
+/*д붨һµ HWI_ARG_TΪ UINTPTR
+һСָСͬ
+HWI_ARG_T ʾӲжϴIJ庬ƽ̨졣*/
typedef UINTPTR HWI_ARG_T;
/**
@@ -303,6 +554,8 @@ typedef UINTPTR HWI_ARG_T;
* @see LOS_HwiCreate
* @since Huawei LiteOS V100R001C00
*/
+/*д붨һָ HWI_PROC_FUNCָһûвͷֵĺ
+HWI_PROC_FUNC ʾӲжϴ͡*/
typedef VOID (*HWI_PROC_FUNC)(VOID);
/**
@@ -311,12 +564,22 @@ typedef VOID (*HWI_PROC_FUNC)(VOID);
*
* The flag only used by the kernel as part of the IRQ handling routines.
*/
+/*궨һ IRQF_SHAREDֵΪ 0x8000U
+IRQF_SHARED ڱʾһӲжϡ*/
#define IRQF_SHARED 0x8000U
/**
* @ingroup los_hwi
* The hardware interrupt parameter for #LOS_HwiDelete and interrupt handler in #LOS_HwiCreate.
*/
+/*붨һΪ HWI_IRQ_PARAM_S Ľṹͣṹڰ³Ա
+int swIrq: ʾжϺŵ
+VOID *pDevId: ʾжϵ豸IDָ
+const CHAR *pName: ʾжƵָ
+
+ṹ HWI_IRQ_PARAM_S LOS_HwiDelete LOS_HwiCreate еӲжϲ
+ͨʹṹ壬
+ԴжϺš豸IDжƵϢԽӦIJ*/
typedef struct tagIrqParam {
int swIrq; /**< The interrupt number */
VOID *pDevId; /**< The pointer to the device ID that launches the interrupt */
@@ -340,6 +603,27 @@ typedef struct tagIrqParam {
* @see LOS_IntRestore
* @since Huawei LiteOS V100R001C00
*/
+/*δ붨һ̬ LOS_IntLock()£
+
+STATIC INLINE
+
+STATIC ؼָʾúΪǰļļвɼ
+INLINE ؼָ߱úĴ뵽ôɺá
+UINT32
+
+UINT32 ʾֵΪ32λ
+LOS_IntLock(VOID)
+
+LOS_IntLock Ǻƣһ VOID ʾû
+return ArchIntLock();
+
+д ArchIntLock() ䷵ֵΪ LOS_IntLock() ķֵ
+ArchIntLock() һӲصĺڽжϣ֮ǰж״̬
+ΪΪҺdz
+ԱڵôֱӲ ArchIntLock() Ĵ룬ִЧʡ
+ܽLOS_IntLock() һ
+õײ ArchIntLock() жϣ֮ǰж״̬
+ĿΪ˱ؼֹжϴϣȷݵһԺͿɿԡ*/
STATIC INLINE UINT32 LOS_IntLock(VOID)
{
return ArchIntLock();
@@ -361,6 +645,13 @@ STATIC INLINE UINT32 LOS_IntLock(VOID)
* - los_hwi.h: the header file that contains the API declaration.
* @see LOS_IntLock
*/
+/*return ArchIntUnlock();
+
+д ArchIntUnlock() ䷵ֵΪ LOS_IntUnLock() ķֵ
+ArchIntUnlock() һӲصĺڻָ֮ǰõж״̬
+ܽLOS_IntUnLock() һ
+õײ ArchIntUnlock() ָ֮ǰõж״̬
+ĿΪٽִϺָжϣж¼*/
STATIC INLINE UINT32 LOS_IntUnLock(VOID)
{
return ArchIntUnlock();
@@ -384,6 +675,14 @@ STATIC INLINE UINT32 LOS_IntUnLock(VOID)
* @see LOS_IntLock
* @since Huawei LiteOS V100R001C00
*/
+/*ArchIntRestore(intSave);
+
+д ArchIntRestore() ֮ǰж״̬Ϊݸ
+ArchIntRestore() һӲصĺڸݴж״ֵָ̬жϡ
+ܽLOS_IntRestore() һ
+õײ ArchIntRestore() ֮ǰж״ָ̬жϡ
+ĿһαжϵĴִϺָж״̬ж¼
+ںûзֵԲ᷵κν*/
STATIC INLINE VOID LOS_IntRestore(UINT32 intSave)
{
ArchIntRestore(intSave);
@@ -430,11 +729,11 @@ STATIC INLINE VOID LOS_IntRestore(UINT32 intSave)
* @see LOS_HwiDelete
* @since Huawei LiteOS V100R001C00
*/
-extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
- HWI_PRIOR_T hwiPrio,
- HWI_MODE_T hwiMode,
- HWI_PROC_FUNC hwiHandler,
- HWI_IRQ_PARAM_S *irqParam);
+extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,//ʾжϺŻжıʶ
+ HWI_PRIOR_T hwiPrio,//ʾжϵȼ
+ HWI_MODE_T hwiMode,//ʾжϵģʽشƽȣ
+ HWI_PROC_FUNC hwiHandler,//ʾжϴָ롣
+ HWI_IRQ_PARAM_S *irqParam);//ʾжϲĽṹָ롣
/**
* @ingroup los_hwi
@@ -470,6 +769,9 @@ extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
* @see LOS_HwiCreate
* @since Huawei LiteOS V100R001C00
*/
+//һ LiteOS ϵͳɾһжϴ
+/*HWI_HANDLE_T hwiNum ǺĵһʾҪɾжϺŻжıʶ
+HWI_IRQ_PARAM_S *irqParam ǺĵڶʾжϲĽṹָ롣*/
extern UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S *irqParam);
/**
@@ -492,6 +794,8 @@ extern UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S *irqParam);
* - los_hwi.h: the header file that contains the API declaration.
* @since Huawei LiteOS V200R005C00
*/
+//һ LiteOS ϵͳдһָжϡ
+//HWI_HANDLE_T hwiNum ǺIJʾҪжϺŻжıʶ
extern UINT32 LOS_HwiTrigger(HWI_HANDLE_T hwiNum);
/**
@@ -513,6 +817,10 @@ extern UINT32 LOS_HwiTrigger(HWI_HANDLE_T hwiNum);
* - los_hwi.h: the header file that contains the API declaration.
* @since Huawei LiteOS V200R005C00
*/
+//һ LiteOS ϵͳλһָжϡ
+/*HWI_HANDLE_T hwiNum ǺIJʾҪжϺŻжıʶ
+ǸָжϺţӦжϱ־λж״̬λ
+ͨøúжϴ״̬Աһжϴ*/
extern UINT32 LOS_HwiClear(HWI_HANDLE_T hwiNum);
/**
@@ -536,6 +844,10 @@ extern UINT32 LOS_HwiClear(HWI_HANDLE_T hwiNum);
* @see LOS_HwiDisable
* @since Huawei LiteOS V200R005C00
*/
+//һ LiteOS ϵͳʹܣãһָжϡ
+/*HWI_HANDLE_T hwiNum ǺIJʾҪʹܵжϺŻжıʶ
+ǸָжϺţӦжʹλΪЧøжϡ
+жϺжϴʱϵͳתִжӦжϴ*/
extern UINT32 LOS_HwiEnable(HWI_HANDLE_T hwiNum);
/**
@@ -558,6 +870,10 @@ extern UINT32 LOS_HwiEnable(HWI_HANDLE_T hwiNum);
* @see LOS_HwiEnable
* @since Huawei LiteOS V200R005C00
*/
+//һ LiteOS ϵͳнãرգһָжϡ
+/*HWI_HANDLE_T hwiNum ǺIJʾҪõжϺŻжıʶ
+ǸָжϺţӦжʹλΪЧøжϡ
+жϺʹжϴϵͳҲתִжӦжϴ*/
extern UINT32 LOS_HwiDisable(HWI_HANDLE_T hwiNum);
#ifdef LOSCFG_KERNEL_SMP
@@ -582,6 +898,11 @@ extern UINT32 LOS_HwiDisable(HWI_HANDLE_T hwiNum);
* - los_hwi.h: the header file that contains the API declaration.
* @since Huawei LiteOS V200R005C00
*/
+//һ LiteOS ϵͳָĴж
+/*HWI_HANDLE_T hwiNum ǺĵһʾҪ͵жϺŻжıʶ
+UINT32 cpuMask ǺĵڶʾжϷ͵Ŀ괦룬ָжϷ͵Щϡ
+ָĴж
+ͨжϿĿ괦жźţӦжϴ*/
extern UINT32 LOS_HwiSendIpi(HWI_HANDLE_T hwiNum, UINT32 cpuMask);
/**
@@ -605,6 +926,12 @@ extern UINT32 LOS_HwiSendIpi(HWI_HANDLE_T hwiNum, UINT32 cpuMask);
* - los_hwi.h: the header file that contains the API declaration.
* @since Huawei LiteOS V200R005C00
*/
+//һ LiteOS ϵͳָжϵԣAffinity
+/*HWI_HANDLE_T hwiNum ǺĵһʾҪԵжϺŻжıʶ
+UINT32 cpuMask ǺĵڶʾҪõж룬ָжϿЩִС
+ָжϵԣжضĴжϱʱ
+ֻжصĴŻ᳢ִжϴ
+Ӷ˲Ҫжϴݺʹ*/
extern UINT32 LOS_HwiSetAffinity(HWI_HANDLE_T hwiNum, UINT32 cpuMask);
#endif /* LOSCFG_KERNEL_SMP */
@@ -632,6 +959,11 @@ extern UINT32 LOS_HwiSetAffinity(HWI_HANDLE_T hwiNum, UINT32 cpuMask);
* @see None
* @since Huawei LiteOS V200R005C00
*/
+//һ LiteOS ϵͳָжϵȼPriority
+/*HWI_HANDLE_T hwiNum ǺĵһʾҪȼжϺŻжıʶ
+HWI_PRIOR_T priority ǺĵڶʾҪõжȼ
+ָжϵȼȷжϵͳеִȼ
+ϸȼжϽȻôԴж֮ǰõӦִС*/
extern UINT32 LOS_HwiSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority);
#ifdef LOSCFG_KERNEL_LOWPOWER
@@ -652,6 +984,10 @@ extern UINT32 LOS_HwiSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority);
* @see None.
* @since Huawei LiteOS V200R005C10
*/
+//һָ͵Ķ塣
+/*ⲿֶ˺ָָĺIJбаһΪ hwiNum IJΪ HWI_HANDLE_T
+ˣ˵typedef VOID (*WAKEUPFROMINTHOOK)(HWI_HANDLE_T hwiNum) һָ WAKEUPFROMINTHOOK
+ָһֵĺҸúһ HWI_HANDLE_T ͵IJ hwiNum*/
typedef VOID (*WAKEUPFROMINTHOOK)(HWI_HANDLE_T hwiNum);
/**
@@ -671,6 +1007,11 @@ typedef VOID (*WAKEUPFROMINTHOOK)(HWI_HANDLE_T hwiNum);
* @see None.
* @since Huawei LiteOS V200R005C10
*/
+//עжϻѹӺⲿ
+/*WAKEUPFROMINTHOOK hook ǺIJһָжϻѹӺָ롣
+עжϻѹӺ
+ָĺָ루ָжϻѴָ룩עᵽϵͳУ
+Աضж¼ʱִӦĴ*/
extern VOID LOS_IntWakeupHookReg(WAKEUPFROMINTHOOK hook);
#endif
From 4e5ee91f58e1cdca3fd6e256e1490b2a3c8cabf5 Mon Sep 17 00:00:00 2001
From: tree <1913915946@qq.com>
Date: Mon, 27 Nov 2023 20:05:17 +0800
Subject: [PATCH 06/26] test
---
src/kernel/base/los_queue.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/kernel/base/los_queue.c b/src/kernel/base/los_queue.c
index f6804c0..3b217ed 100644
--- a/src/kernel/base/los_queue.c
+++ b/src/kernel/base/los_queue.c
@@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
-
+//队列
#include "los_queue_pri.h"
#include "los_queue_debug_pri.h"
#include "los_task_pri.h"
From 2178a790e5eacec1853b8102ca3e47cb7ba9e383 Mon Sep 17 00:00:00 2001
From: he <1429721469@qq.com>
Date: Sun, 3 Dec 2023 23:28:01 +0800
Subject: [PATCH 07/26] =?UTF-8?q?=E4=BD=95=E4=BD=B3=E8=81=AA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../extended/.vscode/c_cpp_properties.json | 18 ++
src/kernel/extended/.vscode/launch.json | 24 ++
src/kernel/extended/.vscode/settings.json | 59 +++++
src/kernel/extended/lowpower/los_lowpower.c | 38 +--
.../lowpower/powermgr/los_lowpower_impl.c | 222 ++++++++++--------
.../lowpower/runstop/src/los_runstop.c | 141 +++++++----
.../extended/lowpower/tickless/los_tickless.c | 31 ++-
src/kernel/extended/perf/los_perf.c | 101 ++++----
src/kernel/extended/perf/perf_output.c | 22 +-
src/kernel/extended/perf/perf_output_pri.h | 14 +-
src/kernel/extended/perf/perf_pmu.c | 13 +-
src/kernel/extended/perf/perf_pmu_pri.h | 38 +--
src/kernel/extended/perf/pmu/perf_hw_pmu.c | 50 ++--
src/kernel/extended/perf/pmu/perf_sw_pmu.c | 20 +-
src/kernel/extended/perf/pmu/perf_timed_pmu.c | 40 ++--
...代码阅读(初稿)-何佳聪-.docx | Bin 0 -> 14017 bytes
16 files changed, 505 insertions(+), 326 deletions(-)
create mode 100644 src/kernel/extended/.vscode/c_cpp_properties.json
create mode 100644 src/kernel/extended/.vscode/launch.json
create mode 100644 src/kernel/extended/.vscode/settings.json
create mode 100644 src/kernel/extended/软件工程代码阅读(初稿)-何佳聪-.docx
diff --git a/src/kernel/extended/.vscode/c_cpp_properties.json b/src/kernel/extended/.vscode/c_cpp_properties.json
new file mode 100644
index 0000000..b1880ec
--- /dev/null
+++ b/src/kernel/extended/.vscode/c_cpp_properties.json
@@ -0,0 +1,18 @@
+{
+ "configurations": [
+ {
+ "name": "windows-gcc-x64",
+ "includePath": [
+ "${workspaceFolder}/**"
+ ],
+ "compilerPath": "D:/mingw64/bin/gcc.exe",
+ "cStandard": "${default}",
+ "cppStandard": "${default}",
+ "intelliSenseMode": "windows-gcc-x64",
+ "compilerArgs": [
+ ""
+ ]
+ }
+ ],
+ "version": 4
+}
\ No newline at end of file
diff --git a/src/kernel/extended/.vscode/launch.json b/src/kernel/extended/.vscode/launch.json
new file mode 100644
index 0000000..f78275c
--- /dev/null
+++ b/src/kernel/extended/.vscode/launch.json
@@ -0,0 +1,24 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "C/C++ Runner: Debug Session",
+ "type": "cppdbg",
+ "request": "launch",
+ "args": [],
+ "stopAtEntry": false,
+ "externalConsole": true,
+ "cwd": "h:/ruanjian/LiteOS-Reading/src/kernel/extended/perf/pmu",
+ "program": "h:/ruanjian/LiteOS-Reading/src/kernel/extended/perf/pmu/build/Debug/outDebug",
+ "MIMode": "gdb",
+ "miDebuggerPath": "gdb",
+ "setupCommands": [
+ {
+ "description": "Enable pretty-printing for gdb",
+ "text": "-enable-pretty-printing",
+ "ignoreFailures": true
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/kernel/extended/.vscode/settings.json b/src/kernel/extended/.vscode/settings.json
new file mode 100644
index 0000000..3e5eb95
--- /dev/null
+++ b/src/kernel/extended/.vscode/settings.json
@@ -0,0 +1,59 @@
+{
+ "C_Cpp_Runner.cCompilerPath": "gcc",
+ "C_Cpp_Runner.cppCompilerPath": "g++",
+ "C_Cpp_Runner.debuggerPath": "gdb",
+ "C_Cpp_Runner.cStandard": "",
+ "C_Cpp_Runner.cppStandard": "",
+ "C_Cpp_Runner.msvcBatchPath": "",
+ "C_Cpp_Runner.useMsvc": false,
+ "C_Cpp_Runner.warnings": [
+ "-Wall",
+ "-Wextra",
+ "-Wpedantic",
+ "-Wshadow",
+ "-Wformat=2",
+ "-Wcast-align",
+ "-Wconversion",
+ "-Wsign-conversion",
+ "-Wnull-dereference"
+ ],
+ "C_Cpp_Runner.msvcWarnings": [
+ "/W4",
+ "/permissive-",
+ "/w14242",
+ "/w14287",
+ "/w14296",
+ "/w14311",
+ "/w14826",
+ "/w44062",
+ "/w44242",
+ "/w14905",
+ "/w14906",
+ "/w14263",
+ "/w44265",
+ "/w14928"
+ ],
+ "C_Cpp_Runner.enableWarnings": true,
+ "C_Cpp_Runner.warningsAsError": false,
+ "C_Cpp_Runner.compilerArgs": [],
+ "C_Cpp_Runner.linkerArgs": [],
+ "C_Cpp_Runner.includePaths": [],
+ "C_Cpp_Runner.includeSearch": [
+ "*",
+ "**/*"
+ ],
+ "C_Cpp_Runner.excludeSearch": [
+ "**/build",
+ "**/build/**",
+ "**/.*",
+ "**/.*/**",
+ "**/.vscode",
+ "**/.vscode/**"
+ ],
+ "C_Cpp_Runner.useAddressSanitizer": false,
+ "C_Cpp_Runner.useUndefinedSanitizer": false,
+ "C_Cpp_Runner.useLeakSanitizer": false,
+ "C_Cpp_Runner.showCompilationTime": false,
+ "C_Cpp_Runner.useLinkTimeOptimization": false,
+ "C_Cpp_Runner.msvcSecureNoWarnings": false
+}
\ No newline at end of file
diff --git a/src/kernel/extended/lowpower/los_lowpower.c b/src/kernel/extended/lowpower/los_lowpower.c
index bd9dde0..2a19c3e 100644
--- a/src/kernel/extended/lowpower/los_lowpower.c
+++ b/src/kernel/extended/lowpower/los_lowpower.c
@@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
-
+ /*低功耗管理*/
#include "los_lowpower_pri.h"
#ifdef LOSCFG_KERNEL_TICKLESS
#include "los_tickless_pri.h"
@@ -36,10 +36,10 @@
__attribute__((section(".data"))) STATIC const PowerMgrOps *g_pmOps = NULL;
-VOID OsLowpowerInit(const PowerMgrOps *pmOps)
+VOID OsLowpowerInit(const PowerMgrOps *pmOps) /*初始化低功耗管理*/
{
if (pmOps == NULL) {
-#ifdef LOSCFG_KERNEL_POWER_MGR
+#ifdef LOSCFG_KERNEL_POWER_MGR/*是否配置了低功耗内核管理*/
PRINT_ERR("\r\n [PM] PowerMgrOps must be non-null.\n");
return;
#endif
@@ -48,34 +48,34 @@ VOID OsLowpowerInit(const PowerMgrOps *pmOps)
return;
}
- if (g_pmOps != NULL) {
+ if (g_pmOps != NULL) {
PRINT_ERR("\r\n [PM] Reassignment of PowerMgrOps is forbidden.\n");
return;
}
g_pmOps = pmOps;
LOS_LowpowerHookReg(OsPowerMgrProcess);
-
+ /*注册低功耗处理函数和终端唤醒处理函数*/
LOS_IntWakeupHookReg(OsPowerMgrWakeUpFromInterrupt);
}
-VOID OsPowerMgrProcess(VOID)
+VOID OsPowerMgrProcess(VOID) /*执行低功耗管理的处理过程*/
{
-#ifdef LOSCFG_KERNEL_POWER_MGR
+#ifdef LOSCFG_KERNEL_POWER_MGR/*判断是否配置了内核低功耗管理*/
CALL_PMOPS_FUNC_VOID(process);
#else
- if (g_pmOps == NULL) {
+ if (g_pmOps == NULL) {
#ifdef LOSCFG_KERNEL_TICKLESS
OsTicklessOpen();
- wfi();
+ wfi(); /*管理进程进入睡眠状态*/
#endif
} else {
- CALL_PMOPS_FUNC_VOID(process);
+ CALL_PMOPS_FUNC_VOID(process);/*执行低功耗管理*/
}
#endif
}
-VOID OsPowerMgrWakeUpFromInterrupt(UINT32 intNum)
+VOID OsPowerMgrWakeUpFromInterrupt(UINT32 intNum) /*从中断唤醒处理*/
{
#ifdef LOSCFG_KERNEL_POWER_MGR
CALL_PMOPS_FUNC_VOID(resumeFromInterrupt, intNum);
@@ -90,44 +90,44 @@ VOID OsPowerMgrWakeUpFromInterrupt(UINT32 intNum)
#endif
}
-VOID OsPowerMgrWakeupFromReset(VOID)
+VOID OsPowerMgrWakeupFromReset(VOID) /*从复位唤醒处理*/
{
CALL_PMOPS_FUNC_VOID(wakeupFromReset);
}
-VOID LOS_PowerMgrChangeFreq(LosFreqMode freq)
+VOID LOS_PowerMgrChangeFreq(LosFreqMode freq)/*改变系统频率*/
{
CALL_PMOPS_FUNC_VOID(changeFreq, freq);
}
-VOID LOS_PowerMgrDeepSleepVoteBegin(VOID)
+VOID LOS_PowerMgrDeepSleepVoteBegin(VOID)/*开始深度睡眠设置*/
{
CALL_PMOPS_FUNC_VOID(deepSleepVoteBegin);
}
-VOID LOS_PowerMgrDeepSleepVoteEnd(VOID)
+VOID LOS_PowerMgrDeepSleepVoteEnd(VOID)/*结束深度睡眠状态*/
{
CALL_PMOPS_FUNC_VOID(deepSleepVoteEnd);
}
-VOID LOS_PowerMgrSleepDelay(UINT32 tick)
+VOID LOS_PowerMgrSleepDelay(UINT32 tick)/*延迟进入睡眠状态*/
{
CALL_PMOPS_FUNC_VOID(deepSleepVoteDelay, tick);
}
-VOID LOS_PowerMgrRegisterExtVoter(UINT32 (*callback)(VOID))
+VOID LOS_PowerMgrRegisterExtVoter(UINT32 (*callback)(VOID))/*注册外部投票者*/
{
CALL_PMOPS_FUNC_VOID(registerExternalVoter, callback);
}
-UINT32 LOS_PowerMgrGetSleepMode(VOID)
+UINT32 LOS_PowerMgrGetSleepMode(VOID)/*获取睡眠模式*/
{
UINT32 ret = 0;
CALL_PMOPS_FUNC_RET(getSleepMode, ret);
return ret;
}
-UINT32 LOS_PowerMgrGetDeepSleepVoteCount(VOID)
+UINT32 LOS_PowerMgrGetDeepSleepVoteCount(VOID)/*获取深度睡眠的投票计数*/
{
UINT32 ret = 0;
CALL_PMOPS_FUNC_RET(getDeepSleepVoteCount, ret);
diff --git a/src/kernel/extended/lowpower/powermgr/los_lowpower_impl.c b/src/kernel/extended/lowpower/powermgr/los_lowpower_impl.c
index 0f8cc28..78f5f94 100644
--- a/src/kernel/extended/lowpower/powermgr/los_lowpower_impl.c
+++ b/src/kernel/extended/lowpower/powermgr/los_lowpower_impl.c
@@ -44,7 +44,7 @@
#endif
#if defined(LOSCFG_KERNEL_RUNSTOP) || defined(LOSCFG_KERNEL_DEEPSLEEP)
-/* Is system is up from the memory image, then this flag should be 1; else 0 */
+/* 如果系统是从内存映像中启动的,则该标志应为1;否则为0。*/
#ifdef LOSCFG_AARCH64
__attribute__((section(".data"))) INT64 g_resumeFromImg = LOS_COLD_RESET;
__attribute__((section(".data"))) STATIC INT64 g_otherCoreResume = 0;
@@ -55,8 +55,8 @@ __attribute__((section(".data"))) INT32 g_otherCoreResume = 0;
#ifdef LOSCFG_AARCH64
/*
- * 16: The number of aligned memory,
- * 34: The number of task context registers(X0~X30, SP, DAIF, NZCV)
+ * 16: 对齐内存的数量,
+ * 34: 任务上下文寄存器的数量,指寄存器的集合(X0~X30, SP, DAIF, NZCV)
*/
LITE_OS_SEC_DATA_MINOR __attribute__((aligned(16))) UINT64 g_saveSRContext[34];
/* 3: The number of available universal registers(X0, X1, X2) temporarily saved */
@@ -161,24 +161,24 @@ STATIC PowerMgrRunOps g_pmRunOps = {
.postConfig = OsPostConfigDefault,
};
-STATIC VOID OsLightSleepDefault(VOID)
+STATIC VOID OsLightSleepDefault(VOID)/*轻量级睡眠函数,执行wfi指令,让处理器进入睡眠状态*/
{
TRACE_FUNC_CALL();
wfi();
}
-STATIC VOID OsSetWakeUpTimerDefault(UINT32 sleepTick)
+STATIC VOID OsSetWakeUpTimerDefault(UINT32 sleepTick)/*设置唤醒定时器,默认实现为空函数*/
{
TRACE_FUNC_CALL();
}
-STATIC UINT32 OsWithrawWakeUpTimerDefault(VOID)
+STATIC UINT32 OsWithrawWakeUpTimerDefault(VOID)/*撤销唤醒定时器,默认实现返回0*/
{
TRACE_FUNC_CALL();
return 0;
}
-STATIC UINT32 OsGetSleepTimeDefault(VOID)
+STATIC UINT32 OsGetSleepTimeDefault(VOID)/*获取当前任务休眠时间*/
{
#ifdef LOSCFG_KERNEL_TICKLESS
return OsSleepTicksGet();
@@ -187,12 +187,12 @@ STATIC UINT32 OsGetSleepTimeDefault(VOID)
#endif
}
-STATIC UINT32 OsSelectSleepModeDefault(UINT32 sleepTicks)
+STATIC UINT32 OsSelectSleepModeDefault(UINT32 sleepTicks)/*选择合适的休眠模式*/
{
if (sleepTicks < g_pmMgr.minSleepTicks) {
return LOS_INTERMIT_NONE;
}
-
+ /*默认实现根据休眠时间和当前系统状态选择轻量级睡眠或者深度睡眠模式*/
if (g_pmMgr.deepSleepOps != NULL && sleepTicks >= g_pmMgr.minDeepSleepTicks &&
g_pmRunOps.getDeepSleepVoteCount() == 0) {
return LOS_INTERMIT_DEEP_SLEEP;
@@ -201,73 +201,73 @@ STATIC UINT32 OsSelectSleepModeDefault(UINT32 sleepTicks)
return LOS_INTERMIT_LIGHT_SLEEP;
}
-STATIC VOID OsChangeFreqDefault(UINT8 freq)
+STATIC VOID OsChangeFreqDefault(UINT8 freq)/*改变处理器频率*/
{
(VOID)freq;
TRACE_FUNC_CALL();
}
-STATIC VOID OsEnterDeepSleepDefault(VOID)
+STATIC VOID OsEnterDeepSleepDefault(VOID)// 进入深度睡眠模式函数
{
TRACE_FUNC_CALL();
wfi();
}
-STATIC UINT32 OsPreConfigDefault(VOID)
+STATIC UINT32 OsPreConfigDefault(VOID)//电源管理模块预配置函数
{
TRACE_FUNC_CALL();
return 1;
}
-STATIC VOID OsPostConfigDefault(VOID)
+STATIC VOID OsPostConfigDefault(VOID)//电源管理模块后配置函数
{
}
#ifdef LOSCFG_KERNEL_DEEPSLEEP
-STATIC BOOL OsCouldDeepSleepDefault(VOID)
+STATIC BOOL OsCouldDeepSleepDefault(VOID)// 判断是否可以进入深度睡眠模式
{
TRACE_FUNC_CALL();
return true;
}
-STATIC BOOL OsSuspendPreConfigDefault(VOID)
+STATIC BOOL OsSuspendPreConfigDefault(VOID)// 休眠前的预配置函数
{
TRACE_FUNC_CALL();
return true;
}
-STATIC VOID OsSuspendDeviceDefault(VOID)
+STATIC VOID OsSuspendDeviceDefault(VOID)//休眠时设备挂起函数
{
TRACE_FUNC_CALL();
}
-STATIC VOID OsRollBackDefault(VOID)
+STATIC VOID OsRollBackDefault(VOID)//唤醒后的回滚函数
{
TRACE_FUNC_CALL();
}
-STATIC VOID OsResumeDeviceDefault(VOID)
+STATIC VOID OsResumeDeviceDefault(VOID)//唤醒后的设备恢复函数
{
TRACE_FUNC_CALL();
}
-STATIC VOID OsResumePostConfigDefault(VOID)
+STATIC VOID OsResumePostConfigDefault(VOID)//唤醒后电源管理模块后配置函数
{
TRACE_FUNC_CALL();
}
-STATIC VOID OsSystemWakeupDefault(VOID)
+STATIC VOID OsSystemWakeupDefault(VOID)//系统唤醒函数
{
TRACE_FUNC_CALL();
}
-STATIC VOID OsResumeCallBackDefault(VOID)
+STATIC VOID OsResumeCallBackDefault(VOID)//唤醒后回调函数
{
TRACE_FUNC_CALL();
}
-STATIC VOID OsOtherCoreResumeDefault(VOID)
+STATIC VOID OsOtherCoreResumeDefault(VOID)//其他核心唤醒函数
{
TRACE_FUNC_CALL();
}
@@ -275,18 +275,18 @@ STATIC VOID OsOtherCoreResumeDefault(VOID)
STATIC VOID OsDeepSleepResume(VOID);
STATIC PowerMgrDeepSleepOps g_deepSleepOps = {
- .couldDeepSleep = OsCouldDeepSleepDefault,
- .systemWakeup = OsSystemWakeupDefault,
- .suspendPreConfig = OsSuspendPreConfigDefault,
- .suspendDevice = OsSuspendDeviceDefault,
- .rollback = OsRollBackDefault,
- .resumeDevice = OsResumeDeviceDefault,
- .resumePostConfig = OsResumePostConfigDefault,
- .resumeCallBack = OsResumeCallBackDefault,
- .otherCoreResume = OsOtherCoreResumeDefault
+ .couldDeepSleep = OsCouldDeepSleepDefault, //判断是否可以进入深度睡眠模式的函数指针
+ .systemWakeup = OsSystemWakeupDefault,//唤醒函数的函数指针
+ .suspendPreConfig = OsSuspendPreConfigDefault,//修面前的预配置函数的函数指针
+ .suspendDevice = OsSuspendDeviceDefault,//设备挂起函数的函数指针
+ .rollback = OsRollBackDefault,//唤醒后的回滚函数的函数指针
+ .resumeDevice = OsResumeDeviceDefault,//设备回复函数的函数指针
+ .resumePostConfig = OsResumePostConfigDefault,//唤醒后电源管理模块后配置函数的函数指针
+ .resumeCallBack = OsResumeCallBackDefault,//唤醒后回调函数的函数指针
+ .otherCoreResume = OsOtherCoreResumeDefault//其他核心唤醒函数的函数指针
};
-STATIC INLINE VOID OsTickResume(UINT32 sleepTicks)
+STATIC INLINE VOID OsTickResume(UINT32 sleepTicks)//用于更新系统始终,根据休眠时间调整系统时钟
{
UINT32 cpuid = ArchCurrCpuid();
if (sleepTicks > g_pmMgr.sleepTime[cpuid]) {
@@ -297,7 +297,7 @@ STATIC INLINE VOID OsTickResume(UINT32 sleepTicks)
OsSysTimeUpdate(sleepTicks);
}
-STATIC VOID OsDeepSleepResume(VOID)
+STATIC VOID OsDeepSleepResume(VOID)//深度睡眠唤醒后的处理函数
{
DEEPOPS_CALL_FUNC_VOID(resumeFromReset);
LOS_AtomicSet(&g_pmMgr.resumeSleepCores, OS_MP_CPU_ALL);
@@ -305,30 +305,32 @@ STATIC VOID OsDeepSleepResume(VOID)
#ifdef LOSCFG_KERNEL_CPUP
OsSetCpuCycle(0);
#endif
-
+//恢复设置,恢复其他核心进程
#if (LOSCFG_KERNEL_SMP == YES)
release_secondary_cores();
#endif
OsSRRestoreRegister();
}
-STATIC INLINE VOID OsEnterDeepSleepMainCore(VOID)
+STATIC INLINE VOID OsEnterDeepSleepMainCore(VOID)//用于主核心进入深度睡眠
{
+ //挂起预配置
LOS_AtomicAdd(&g_pmMgr.deepSleepCores, 1);
g_deepSleepOps.suspendPreConfig();
-
+ //是否可以进入神对睡眠判断
if (g_pmMgr.deepSleepCores == LOSCFG_KERNEL_CORE_NUM && g_deepSleepOps.couldDeepSleep()) {
g_deepSleepOps.suspendDevice();
g_pmRunOps.setWakeUpTimer(g_pmMgr.sleepTime[0]);
g_resumeFromImg = LOS_COLD_RESET;
OsSRSaveRegister();
-
+ //进入深度睡眠,进行回滚操作,保存上下文
if (g_resumeFromImg == LOS_COLD_RESET) {
g_resumeFromImg = LOS_DEEP_SLEEP_RESET;
CALL_RUN_OPS_FUNC_NO_RETURN(contextSave);
g_pmRunOps.enterDeepSleep();
g_deepSleepOps.rollback();
}
+ //设置唤醒定时器
g_deepSleepOps.resumeDevice();
UINT32 sleepTicks = g_pmRunOps.withdrawWakeUpTimer();
OsSysTimeUpdate(sleepTicks);
@@ -342,42 +344,43 @@ STATIC INLINE VOID OsEnterDeepSleepMainCore(VOID)
LOS_AtomicSub(&g_pmMgr.deepSleepCores, 1);
}
-STATIC INLINE VOID OsEnterSleepMode(VOID)
+STATIC INLINE VOID OsEnterSleepMode(VOID)//进入睡眠模式,包括主核心和其他核心的不同处理
{
#ifdef LOSCFG_KERNEL_SMP
UINT32 currCpuid = ArchCurrCpuid();
- if (currCpuid == 0) {
+ if (currCpuid == 0) { //如果是0则进入主核心深度睡眠
#endif
OsEnterDeepSleepMainCore();
-#ifdef LOSCFG_KERNEL_SMP
+#ifdef LOSCFG_KERNEL_SMP //如果当前核心不是主核心,则直接返回,因为其他核心的睡眠处理逻辑不在此函数中处理
return;
}
UINT32 cpuMask = 1 << currCpuid;
LOS_AtomicAdd(&g_pmMgr.deepSleepCores, 1);
- OsSRSaveRegister();
+ OsSRSaveRegister();//保存相关寄存器状态并判断是否需要唤醒当前核心。
if (g_pmMgr.resumeSleepCores & cpuMask) {
INT32 val;
- do {
+ do { //,将 g_pmMgr.resumeSleepCores 的值中当前核心的位清零,表示该核心已被唤醒。
val = LOS_AtomicRead(&g_pmMgr.resumeSleepCores);
} while (LOS_AtomicCmpXchg32bits(&g_pmMgr.resumeSleepCores, val & (~cpuMask), val));
g_deepSleepOps.otherCoreResume();
UINT32 sleepTicks = g_pmRunOps.withdrawWakeUpTimer();
OsTickResume(sleepTicks);
+ //执行其他核心的恢复操作,并从唤醒定时器中获取休眠时间,然后调用 OsTickResume 函数更新系统时钟。
} else {
- if (g_pmMgr.deepSleepCores == LOSCFG_KERNEL_CORE_NUM) {
- LOS_MpSchedule(1 << 0);
+ if (g_pmMgr.deepSleepCores == LOSCFG_KERNEL_CORE_NUM) {//如果不需要唤醒,则判断是否所有核心都进入了深度睡眠
+ LOS_MpSchedule(1 << 0);//调用函数选择一个核心唤醒系统
}
#ifdef LOSCFG_KERNEL_TICKLESS
- OsTicklessOpen();
+ OsTicklessOpen();//开启节能模式
#endif
g_pmRunOps.enterLightSleep();
}
- LOS_AtomicSub(&g_pmMgr.deepSleepCores, 1);
+ LOS_AtomicSub(&g_pmMgr.deepSleepCores, 1);//将 g_pmMgr.deepSleepCores 的值减1,表示当前核心已经处理完睡眠状态
#endif // LOSCFG_KERNEL_SMP
}
-STATIC INLINE VOID OsSystemSuspend(LosIntermitMode *mode)
+STATIC INLINE VOID OsSystemSuspend(LosIntermitMode *mode)//选择合适的低功耗模式(深度,轻度
{
// If enterShutdownMode is not defined, will fall through to standby mode
// If enterStandbyMode is not defined, will fall through to stop mode
@@ -402,10 +405,10 @@ STATIC INLINE VOID OsSystemSuspend(LosIntermitMode *mode)
}
#endif
-STATIC VOID OsLowpowerLightSleep(UINT32 mode, UINT32 cpuid, UINT32 sleepTicks)
+STATIC VOID OsLowpowerLightSleep(UINT32 mode, UINT32 cpuid, UINT32 sleepTicks)//轻度睡眠中的模式调整
{
if (g_pmRunOps.preConfig != NULL) {
- sleepTicks = g_pmRunOps.getSleepTime();
+ sleepTicks = g_pmRunOps.getSleepTime();//获取休眠时间
}
if (sleepTicks > 1) {
g_pmMgr.sleepMode[cpuid] = (mode & 0x0FF);
@@ -414,18 +417,19 @@ STATIC VOID OsLowpowerLightSleep(UINT32 mode, UINT32 cpuid, UINT32 sleepTicks)
OsTicklessOpen();
#endif
if (mode == LOS_INTERMIT_LIGHT_SLEEP && g_pmRunOps.enterLightSleep != NULL) {
- g_pmRunOps.enterLightSleep();
+ g_pmRunOps.enterLightSleep();//进入轻度睡眠
} else {
wfi();
}
} else {
- g_pmMgr.sleepMode[cpuid] = LOS_INTERMIT_NONE;
+ g_pmMgr.sleepMode[cpuid] = LOS_INTERMIT_NONE;//等待中断事件
g_pmMgr.sleepTime[cpuid] = 0;
wfi();
}
}
STATIC VOID OsLowpowerDeepSleep(LosIntermitMode *mode, UINT32 cpuid, UINT32 sleepTicks)
+//深度睡眠设置
{
#ifdef LOSCFG_KERNEL_DEEPSLEEP
if (g_pmRunOps.enterDeepSleep == NULL) {
@@ -438,27 +442,31 @@ STATIC VOID OsLowpowerDeepSleep(LosIntermitMode *mode, UINT32 cpuid, UINT32 slee
OsSystemSuspend(mode);
}
#else
- *mode = LOS_INTERMIT_LIGHT_SLEEP;
+ *mode = LOS_INTERMIT_LIGHT_SLEEP;//若不支持深度睡眠则强制进入轻度睡眠
#endif
}
-STATIC VOID OsLowpowerProcess(VOID)
+STATIC VOID OsLowpowerProcess(VOID)//处理系统进入低功耗模式的过程
{
-#ifdef LOSCFG_KERNEL_RUNSTOP
+#ifdef LOSCFG_KERNEL_RUNSTOP//检查系统是否需要在进入低功耗模式前保存系统消息
if (OsWowSysDoneFlagGet() == OS_STORE_SYSTEM) {
OsStoreSystemInfoBeforeSuspend();
}
#endif
/* Change frequency is pended, need to change the freq here. */
- if ((g_pmRunOps.changeFreq != NULL)) {
+ if ((g_pmRunOps.changeFreq != NULL)) {//如果需要改变频率则调整切换
OsChangeFreq();
}
-
+ //禁止中断,锁住任务调度,并获取当前CPUID和休眠时间
UINT32 intSave = LOS_IntLock();
LOS_TaskLock();
RUNOPS_CALL_FUNC_VOID(preConfig);
UINT32 cpuid = ArchCurrCpuid();
UINT32 sleepTicks = g_pmRunOps.getSleepTime();
+ /*如果休眠时间小于等于最小休眠时间(g_pmMgr.minSleepTicks)
+ 或者有任务请求不进入深度睡眠(LOS_PowerMgrGetDeepSleepVoteCount 返回值不为0),
+ 则将当前 CPU 设置为不进入任何中断模式,清零休眠时间,
+ 并调用 postConfig 函数。*/
if (sleepTicks <= g_pmMgr.minSleepTicks || LOS_PowerMgrGetDeepSleepVoteCount() != 0) {
g_pmMgr.sleepMode[cpuid] = LOS_INTERMIT_NONE;
g_pmMgr.sleepTime[cpuid] = 0;
@@ -477,23 +485,23 @@ STATIC VOID OsLowpowerProcess(VOID)
sleepTicks = g_pmMgr.maxSleepCount;
}
UINT32 mode = g_pmRunOps.selectSleepMode(sleepTicks);
- if (mode >= LOS_INTERMIT_DEEP_SLEEP) {
+ if (mode >= LOS_INTERMIT_DEEP_SLEEP) {//如果支持深度睡眠
g_pmMgr.sleepTime[cpuid] = g_pmRunOps.withdrawWakeUpTimer();
OsLowpowerDeepSleep(&mode, cpuid, sleepTicks);
}
RUNOPS_CALL_FUNC_VOID(postConfig);
- if (mode < LOS_INTERMIT_DEEP_SLEEP) {
+ if (mode < LOS_INTERMIT_DEEP_SLEEP) {//进入轻度睡眠
OsLowpowerLightSleep(mode, cpuid, sleepTicks);
}
}
LOS_TaskUnlock();
- LOS_IntRestore(intSave);
+ LOS_IntRestore(intSave);//解锁任务调度并恢复中断
}
-STATIC VOID OsLowpowerWakeupFromReset(VOID)
+STATIC VOID OsLowpowerWakeupFromReset(VOID)//处理系统从重置状态唤醒的情况
{
#ifdef LOSCFG_KERNEL_RUNSTOP
if (g_resumeFromImg == LOS_RUN_STOP_RESET) {
@@ -508,7 +516,7 @@ STATIC VOID OsLowpowerWakeupFromReset(VOID)
#endif
}
-STATIC VOID OsLowpowerWakeupFromInterrupt(UINT32 intNum)
+STATIC VOID OsLowpowerWakeupFromInterrupt(UINT32 intNum)//用于处理系统从重置状态唤醒的情况
{
#ifdef LOSCFG_KERNEL_TICKLESS
OsTicklessUpdate(intNum);
@@ -517,26 +525,27 @@ STATIC VOID OsLowpowerWakeupFromInterrupt(UINT32 intNum)
#endif
}
-STATIC VOID OsChangeFreq(VOID)
+STATIC VOID OsChangeFreq(VOID)//处理改变系统频率的操作
{
UINT32 freq;
BOOL ret;
- do {
+ do {//尝试获取频率切换的自旋锁(通过原子操作实现)
+ //如果成功获取锁,则说明没有其他线程正在频率切换过程中,可以继续执行
ret = LOS_AtomicCmpXchg32bits(&g_pmMgr.freeLock, LOCK_ON, LOCK_OFF);
if (ret) {
return;
}
- freq = (UINT32)g_pmMgr.freqPending;
+ freq = (UINT32)g_pmMgr.freqPending;//获取频率切换的目标频率,并进行频率切换
if (freq != (UINT32)g_pmMgr.freq) {
- g_pmRunOps.changeFreq(freq);
+ g_pmRunOps.changeFreq(freq);//更新频率
LOS_AtomicSet(&g_pmMgr.freq, (INT32)freq);
}
- LOS_AtomicSet(&g_pmMgr.freeLock, LOCK_OFF);
+ LOS_AtomicSet(&g_pmMgr.freeLock, LOCK_OFF);//释放自旋锁
} while (FreqHigher(g_pmMgr.freqPending, freq));
}
-STATIC VOID OsLowpowerChangeFreq(LosFreqMode freq)
+STATIC VOID OsLowpowerChangeFreq(LosFreqMode freq)//改变系统频率
{
TRACE_FUNC_CALL();
if (g_pmRunOps.changeFreq == NULL) {
@@ -554,36 +563,36 @@ STATIC VOID OsLowpowerChangeFreq(LosFreqMode freq)
// We get a high frequency request, then change it
if (FreqHigher(g_pmMgr.freqPending, g_pmMgr.freq) && g_pmRunOps.changeFreq != NULL) {
- OsChangeFreq();
+ OsChangeFreq();//如果目标频率高于当前频率,并且 g_pmRunOps.changeFreq 不为空,则调用 OsChangeFreq 函数进行频率切换。
}
}
-STATIC VOID OsLowpowerDeepSleepVoteBegin(VOID)
+STATIC VOID OsLowpowerDeepSleepVoteBegin(VOID)//开始深度睡眠投票
{
TRACE_FUNC_CALL();
- LOS_AtomicInc(&g_pmMgr.sleepVoteCount);
+ LOS_AtomicInc(&g_pmMgr.sleepVoteCount);//用原子操作将 g_pmMgr.sleepVoteCount 加一,并断言 g_pmMgr.sleepVoteCount 大于零。
LOS_ASSERT(g_pmMgr.sleepVoteCount > 0);
}
-STATIC VOID OsLowpowerDeepSleepVoteEnd(VOID)
+STATIC VOID OsLowpowerDeepSleepVoteEnd(VOID)//结束深度睡眠投票
{
TRACE_FUNC_CALL();
- LOS_AtomicDec(&g_pmMgr.sleepVoteCount);
+ LOS_AtomicDec(&g_pmMgr.sleepVoteCount);//原子操作将 g_pmMgr.sleepVoteCount 减一,并断言 g_pmMgr.sleepVoteCount 大于等于零。
LOS_ASSERT(g_pmMgr.sleepVoteCount >= 0);
}
-STATIC VOID OsLowpowerDeepSleepVoteDelay(UINT32 delayTicks)
+STATIC VOID OsLowpowerDeepSleepVoteDelay(UINT32 delayTicks)//延迟深度睡眠投票
{
TRACE_FUNC_CALL();
}
-STATIC VOID OsLowpowerRegisterExternalVoter(LowpowerExternalVoterHandle callback)
+STATIC VOID OsLowpowerRegisterExternalVoter(LowpowerExternalVoterHandle callback)//注册外部投票者
{
TRACE_FUNC_CALL();
g_pmMgr.exVoterHandle = callback;
}
-STATIC UINT32 OsLowpowerGetDeepSleepVoteCount(VOID)
+STATIC UINT32 OsLowpowerGetDeepSleepVoteCount(VOID)//获取深度睡眠投票数
{
if (g_pmMgr.exVoterHandle == NULL) {
return (UINT32)g_pmMgr.sleepVoteCount;
@@ -593,22 +602,26 @@ STATIC UINT32 OsLowpowerGetDeepSleepVoteCount(VOID)
}
STATIC PowerMgrOps g_pmOps = {
- .process = OsLowpowerProcess,
- .wakeupFromReset = OsLowpowerWakeupFromReset,
- .resumeFromInterrupt = OsLowpowerWakeupFromInterrupt,
- .changeFreq = OsLowpowerChangeFreq,
- .deepSleepVoteBegin = OsLowpowerDeepSleepVoteBegin,
- .deepSleepVoteEnd = OsLowpowerDeepSleepVoteEnd,
- .deepSleepVoteDelay = OsLowpowerDeepSleepVoteDelay,
- .registerExternalVoter = OsLowpowerRegisterExternalVoter,
- .getDeepSleepVoteCount = OsLowpowerGetDeepSleepVoteCount,
- .getSleepMode = NULL,
- .setSleepMode = NULL,
+ .process = OsLowpowerProcess, //该函数指针用于处理低功耗过程,即在进入低功耗模式前需要执行的操作
+ .wakeupFromReset = OsLowpowerWakeupFromReset,//该函数指针用于处理从复位状态唤醒时的操作
+ .resumeFromInterrupt = OsLowpowerWakeupFromInterrupt,//该函数指针用于处理从中断状态恢复时的操作。
+ .changeFreq = OsLowpowerChangeFreq,//该函数指针用于改变系统频率的操作,可以根据需要调整系统的工作频率
+ .deepSleepVoteBegin = OsLowpowerDeepSleepVoteBegin,//该函数指针用于开始深度休眠投票,即在进入深度休眠模式前需要执行的操作
+ .deepSleepVoteEnd = OsLowpowerDeepSleepVoteEnd,//该函数指针用于结束深度休眠投票,即在退出深度休眠模式后需要执行的操作
+ .deepSleepVoteDelay = OsLowpowerDeepSleepVoteDelay,//该函数指针用于处理深度休眠投票延迟的操作,可以根据需要延迟深度休眠的投票
+ .registerExternalVoter = OsLowpowerRegisterExternalVoter,//该函数指针用于注册外部投票者,即在系统中存在其他模块也需要参与低功耗投票时的操作
+ .getDeepSleepVoteCount = OsLowpowerGetDeepSleepVoteCount,//该函数指针用于获取当前深度休眠投票的数量,可以用来监控系统中参与休眠投票的模块数量
+ .getSleepMode = NULL,//该函数指针用于获取当前的睡眠模式,即获取系统当前是否处于睡眠状态
+ .setSleepMode = NULL,//该函数指针用于设置睡眠模式,即将系统设置为指定的睡眠模式
+ //以上提及的函数均为函数指针
};
#define FORCE_NULL_CALLBACK (void *)0x3f3f3f3f
-
-#define ASSIGN_MEMBER(lhs, rhs, member) \
+//以下定义是用于给结构体成员赋值,如果某个回调函数指针为特殊空值,则将相应的成员置为空,否则进行赋值
+#define ASSIGN_MEMBER(lhs, rhs, member)
+//lhs 是左操作数,表示要赋值的结构体指针;
+//rhs 是右操作数,表示要赋给成员的值;
+//member 是要赋值的结构体成员
do { \
if ((rhs)->member == FORCE_NULL_CALLBACK) { \
(lhs)->member = NULL; \
@@ -631,16 +644,16 @@ VOID LOS_PowerMgrInit(const PowerMgrParameter *para)
const PowerMgrRunOps *runOps = NULL;
const PowerMgrDeepSleepOps *deepSleepOps = NULL;
(void)deepSleepOps;
- if (para != NULL) {
+ if (para != NULL) { //如果para为空,则运行操作和深度睡眠操作都为空指针
runOps = ¶->runOps;
#ifdef LOSCFG_KERNEL_DEEPSLEEP
deepSleepOps = ¶->deepSleepOps;
#endif
- g_pmMgr.minSleepTicks = para->config.minLightSleepTicks;
- g_pmMgr.maxSleepCount = para->config.maxDeepSleepTicks;
- g_pmMgr.minDeepSleepTicks = para->config.minDeepSleepTicks;
+ g_pmMgr.minSleepTicks = para->config.minLightSleepTicks;//记录了系统中需要从睡眠状态唤醒的 CPU 核心数
+ g_pmMgr.maxSleepCount = para->config.maxDeepSleepTicks;//用于保护电源管理模块在多线程环境下的并发访问
+ g_pmMgr.minDeepSleepTicks = para->config.minDeepSleepTicks;//记录自旋锁是否被释放
}
-
+ //将传入的运行操作和深度睡眠操作分别赋值给全局变量 g_pmRunOps 和 g_deepSleepOps
LOS_AtomicSet(&g_pmMgr.resumeSleepCores, 0);
LOS_SpinInit(&g_pmMgr.lock);
@@ -648,25 +661,25 @@ VOID LOS_PowerMgrInit(const PowerMgrParameter *para)
// verify and assign input operators.
if (runOps != NULL) {
- ASSIGN_MEMBER(&g_pmRunOps, runOps, changeFreq);
- ASSIGN_MEMBER(&g_pmRunOps, runOps, enterLightSleep);
+ ASSIGN_MEMBER(&g_pmRunOps, runOps, changeFreq);//改变CPU频率
+ ASSIGN_MEMBER(&g_pmRunOps, runOps, enterLightSleep);//进入浅度睡眠
#ifdef LOSCFG_KERNEL_DEEPSLEEP
- ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, enterDeepSleep);
- ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, setWakeUpTimer);
- ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, withdrawWakeUpTimer);
+ ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, enterDeepSleep);//进入深度睡眠
+ ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, setWakeUpTimer);//设置唤醒定时器
+ ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, withdrawWakeUpTimer);//撤销定时器
#else
ASSIGN_MEMBER(&g_pmRunOps, runOps, enterDeepSleep);
ASSIGN_MEMBER(&g_pmRunOps, runOps, setWakeUpTimer);
ASSIGN_MEMBER(&g_pmRunOps, runOps, withdrawWakeUpTimer);
#endif
- ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, getSleepTime);
- ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, selectSleepMode);
- ASSIGN_MEMBER(&g_pmRunOps, runOps, preConfig);
- ASSIGN_MEMBER(&g_pmRunOps, runOps, postConfig);
+ ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, getSleepTime);//货的睡眠时间
+ ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, selectSleepMode);//选择不同的睡眠模式
+ ASSIGN_MEMBER(&g_pmRunOps, runOps, preConfig);//预配置
+ ASSIGN_MEMBER(&g_pmRunOps, runOps, postConfig);//后配置
}
#ifdef LOSCFG_KERNEL_DEEPSLEEP
- if (deepSleepOps != NULL) {
+ if (deepSleepOps != NULL) {//进入深度睡眠
ASSIGN_MEMBER(&g_deepSleepOps, deepSleepOps, couldDeepSleep);
ASSIGN_MEMBER(&g_deepSleepOps, deepSleepOps, systemWakeup);
ASSIGN_MEMBER(&g_deepSleepOps, deepSleepOps, suspendPreConfig);
@@ -680,4 +693,7 @@ VOID LOS_PowerMgrInit(const PowerMgrParameter *para)
#endif
// Register PowerMgr to Low-Power Framework.
LOS_LowpowerInit(&g_pmOps);
+ //将电源管理模块注册到低功耗框架中。
+ //低功耗框架是一个用于管理处理器和设备进入低功耗模式的软件框架,
+ //它能够最大限度地降低系统能耗,提高系统的电池寿命
}
diff --git a/src/kernel/extended/lowpower/runstop/src/los_runstop.c b/src/kernel/extended/lowpower/runstop/src/los_runstop.c
index 0da74e3..f529d6a 100644
--- a/src/kernel/extended/lowpower/runstop/src/los_runstop.c
+++ b/src/kernel/extended/lowpower/runstop/src/los_runstop.c
@@ -51,22 +51,28 @@ extern "C" {
/* If core is ready for imaging */
LITE_OS_SEC_DATA_MINOR STATIC UINT32 g_sysDoneFlag[LOSCFG_KERNEL_CORE_NUM] = {
[0 ... (LOSCFG_KERNEL_CORE_NUM - 1)] = OS_NO_STORE_SYSTEM
-};
+}; /*标记数组状态,用来表示系统是否加载完成*/
/* Start position of flash to write image */
LITE_OS_SEC_DATA_MINOR STATIC UINTPTR g_flashImgAddr;
+/*flash图像地址和大小,用于存储flash相关信息。*/
/* Start position of heap memory after carry the image from flash to memory */
LITE_OS_SEC_DATA_MINOR STATIC const VOID *g_heapMemStart = NULL;
+/*初始化图像地址*/
/* Size of heap memory in image */
LITE_OS_SEC_DATA_MINOR STATIC size_t g_heapMemSize = 0;
+/*初始化定义图像大小*/
+
#ifdef LOSCFG_EXC_INTERACTION
/* Start position of exc interaction heap memory after carry the image from flash to memory */
LITE_OS_SEC_DATA_MINOR STATIC const VOID *g_excInteractionMemStart = NULL;
+/*在存储器映像从闪存复制到内存之后异常交互堆的起始位置变量*/
/* Size of exc interaction heap memory in image */
LITE_OS_SEC_DATA_MINOR STATIC size_t g_excInteractionMemSize = 0;
+/*异常交互堆内存在储存器映像中的大小*/
#endif
/* Size of wow image */
LITE_OS_SEC_DATA_MINOR STATIC size_t g_wowImgSize = 0;
@@ -76,15 +82,17 @@ LITE_OS_SEC_DATA_MINOR STATIC EVENT_CB_S g_suspendResumeEvent;
LITE_OS_SEC_DATA_MINOR STATIC EVENT_CB_S g_writeFlashEvent;
typedef struct {
- UINTPTR memStart;
- UINTPTR flashStart;
- size_t memSize;
+ UINTPTR memStart; /*内存起始地址*/
+ UINTPTR flashStart; /*闪存起始地址*/
+ size_t memSize; /*存储空间大小*/
} FlashWriteParam;
BOOL IsImageResume(VOID)
{
return (g_resumeFromImg != LOS_COLD_RESET);
}
+/*判断系统是否从存储器映像中恢复的,功能是当系统异常启动或者需要重启的时候就会从内存将其数据保存到闪存中
+此函数就是判断系统是否是从存储器映像回复的,从而确定是否需要对系统状态进行恢复*/
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsDoWriteWow2Flash(FLASH_WRITE_FUNC flashWriteFunc,
const FlashWriteParam *wowSection,
@@ -109,29 +117,32 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsDoWriteWow2Flash(FLASH_WRITE_FUNC flashWrit
return;
}
}
-
-LITE_OS_SEC_TEXT_MINOR VOID OsWriteWow2Flash(VOID)
+/*首先检查内存中的大小是否为0
+若不为0则将wowsection、excheapsection、heapmemsection中的静态数据和代码存储在系统启动的时候将其从闪存加入到内存中*/
+LITE_OS_SEC_TEXT_MINOR VOID OsWriteWow2Flash(VOID) /*根据指定的内存区域,在闪存中写入相应的数据,完成写入操作*/
{
FlashWriteParam wowSection;
FlashWriteParam excHeapSection = {0};
- FlashWriteParam heapMemSection;
- size_t eraseAlignSize;
- size_t writeAlignSize;
+ FlashWriteParam heapMemSection; /*这是三种闪存内部独立的堆专用的内存区域对应的闪存写入参数*/
+ size_t eraseAlignSize; /*表示闪存擦除时的对齐大小*/
+ size_t writeAlignSize; /*闪存写入时的对齐大小*/
FLASH_WRITE_FUNC flashWriteFunc = g_runstopParam.pfFlashWriteFunc;
- eraseAlignSize = g_runstopParam.uwFlashEraseAlignSize;
- writeAlignSize = g_runstopParam.uwFlashWriteAlignSize;
+ eraseAlignSize = g_runstopParam.uwFlashEraseAlignSize; /*用来指定擦除和写入时的对齐大小,通常设置为扇区大小的整数倍*/
+ writeAlignSize = g_runstopParam.uwFlashWriteAlignSize; /*为了避免出现擦除或写入不规则数据的情况,
+ 需要将操作的地址向下或向上舍入到扇区大小的整数倍
+ 从而避免因为不规则的操作而导致数据的错误或损坏。*/
writeAlignSize = (writeAlignSize >= eraseAlignSize) ? writeAlignSize : eraseAlignSize;
if (flashWriteFunc == NULL) {
PRINT_ERR("%s, %d\n", __FUNCTION__, __LINE__);
return;
}
- wowSection.memStart = (UINTPTR)&__ram_vectors_vma;
- wowSection.flashStart = g_flashImgAddr;
+ wowSection.memStart = (UINTPTR)&__ram_vectors_vma;/*初始化wowSection,为内存中起始地址*/
+ wowSection.flashStart = g_flashImgAddr; /*为闪存中起始地址*/
wowSection.memSize = ((UINTPTR)&__wow_end) - ((UINTPTR)&__ram_vectors_vma);
wowSection.memSize = (wowSection.memSize + writeAlignSize - 1) & ~(writeAlignSize - 1);
-
+ /*计算了wowSection大小,通过与运算保证每次写入的数据都是整个扇区的倍数*/
#ifdef LOSCFG_EXC_INTERACTION
excHeapSection.memStart = (UINTPTR)m_aucSysMem0;
excHeapSection.flashStart = g_flashImgAddr + wowSection.memSize;
@@ -152,39 +163,41 @@ LITE_OS_SEC_TEXT_MINOR VOID OsWriteWow2Flash(VOID)
g_wowImgSize = wowSection.memSize + heapMemSection.memSize + excHeapSection.memSize;
OsDoWriteWow2Flash(flashWriteFunc, &wowSection, &excHeapSection, &heapMemSection);
+ /*将变量传输给函数,由其实现相应的写入操作*/
}
-LITE_OS_SEC_TEXT_MINOR VOID OsSystemSuspend(VOID)
+LITE_OS_SEC_TEXT_MINOR VOID OsSystemSuspend(VOID) /*实现系统的挂起操作*/
{
- UINT32 cpuid;
+ UINT32 cpuid; /*获取当前CPU的ID*/
- (VOID)LOS_IntLock();
+ (VOID)LOS_IntLock();
LOS_TaskLock();
cpuid = ArchCurrCpuid();
+ /*禁止中断并锁定任务调度器,确保在执行挂起操作期间不会被打断*/
+ g_sysDoneFlag[cpuid] = OS_NO_STORE_SYSTEM; /*将当前CPU的系统挂起标志设置为不需要保存系统状态*/
+ g_saveTsk[cpuid] = OsCurrTaskGet(); /*保存当前任务指针到savetask变量中*/
- g_sysDoneFlag[cpuid] = OS_NO_STORE_SYSTEM;
- g_saveTsk[cpuid] = OsCurrTaskGet();
-
- OsSRSaveRegister();
+ OsSRSaveRegister(); /*保存当前CPU的寄存器状态,以便在恢复系统时能够正确恢复到挂起前的状态*/
/* If 1 core, only to save registers */
- if (cpuid != 0) {
- if (g_otherCoreResume != 0) {
+ if (cpuid != 0) { /*若此CPU部位0号内核*/
+ if (g_otherCoreResume != 0) { /*说明其他多核核心需要恢复运行*/
HalIrqInitPercpu();
OsTickStart();
LOS_TaskUnlock();
(VOID)LOS_IntUnLock();
- return;
+ return;
}
- g_sysDoneFlag[cpuid - 1] = OS_STORE_SYSTEM;
+ g_sysDoneFlag[cpuid - 1] = OS_STORE_SYSTEM; /*需要初始化中断并启动系统时钟,并最终解锁任务调度器并恢复中断*/
while (1) {}
}
- if (g_resumeFromImg) {
+ if (g_resumeFromImg) { /*如果是 0 号 CPU,且系统需要从镜像中恢复(g_resumeFromImg 为真)*/
OsWriteWow2Flash();
LOS_TaskUnlock();
(VOID)LOS_IntUnLock();
(VOID)LOS_EventWrite(&g_suspendResumeEvent, FLASH_IMG_SUCCESS);
- } else {
+ /*调用 OsWriteWow2Flash 函数将数据写入闪存,并发送 FLASH_IMG_SUCCESS 事件信号,表示成功从镜像中恢复*/
+ } else { /*不需要从镜像中恢复*/
OsTickStart();
LOS_TaskUnlock();
(VOID)LOS_IntUnLock();
@@ -194,9 +207,15 @@ LITE_OS_SEC_TEXT_MINOR VOID OsSystemSuspend(VOID)
}
(VOID)LOS_EventWrite(&g_suspendResumeEvent, WAKEUP_FROM_SUSPEND);
}
+ /*启动系统时钟,解锁任务调度器和中断,并根据是否设置了空闲唤醒回调函数来执行相应的操作,
+ 最后发送 WAKEUP_FROM_SUSPEND 事件信号,表示从挂起状态唤醒*/
}
LITE_OS_SEC_TEXT VOID OsWriteToFlashTask(VOID)
+/*初始化了一个事件对象 g_writeFlashEvent
+并且在循环中调用 LOS_EventRead 函数等待事件的发生,
+并以 OR 模式和清除模式等待事件的标志位为 0x01。
+一旦事件发生,它调用 OsSystemSuspend 函数将系统挂起。*/
{
(VOID)LOS_EventInit(&g_writeFlashEvent);
@@ -207,6 +226,10 @@ LITE_OS_SEC_TEXT VOID OsWriteToFlashTask(VOID)
}
LITE_OS_SEC_TEXT VOID OsStoreSystemInfoBeforeSuspend(VOID)
+/*根据当前 CPU 的 ID 判断是否需要挂起系统。
+如果当前 CPU 不是 0 号 CPU,直接调用 OsSystemSuspend 函数挂起系统。
+如果是 0 号 CPU,则调用 LOS_EventWrite 函数向事件对象 g_writeFlashEvent 发送一个事件,
+唤醒 OsWriteToFlashTask 任务来执行挂起操作。*/
{
UINT32 cpuid = ArchCurrCpuid();
if (cpuid != 0) {
@@ -218,6 +241,9 @@ LITE_OS_SEC_TEXT VOID OsStoreSystemInfoBeforeSuspend(VOID)
}
LITE_OS_SEC_TEXT_MINOR VOID OsSystemWakeup(VOID)
+/*是系统从挂起状态唤醒后的处理函数。*/
+
+
{
UINT32 cpuid;
errno_t err;
@@ -225,7 +251,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsSystemWakeup(VOID)
if (!g_resumeFromImg) {
return;
}
-
+/*进行一些内存数据的复制操作,然后设置当前 CPU 的任务指针,*/
#ifdef LOSCFG_EXC_INTERACTION
err = memmove_s(m_aucSysMem0, g_excInteractMemSize, g_excInteractionMemStart, g_excInteractionMemSize);
if (err != EOK) {
@@ -243,6 +269,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsSystemWakeup(VOID)
cpuid = ArchCurrCpuid();
OsCurrTaskSet(g_saveTsk[cpuid]);
+/*设置系统计数器频率。接着,它重置内存池的末尾节点,清零 BSS 区域的数据,重新初始化中断*/
/* Set system counter freq */
HalClockFreqWrite(OS_SYS_CLOCK);
dsb();
@@ -270,7 +297,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsSystemWakeup(VOID)
#ifdef LOSCFG_KERNEL_CPUP
OsSetCpuCycle(0);
#endif
-
+/*并调用 OsSRRestoreRegister 函数恢复寄存器状态*/
#if (LOSCFG_KERNEL_SMP == YES)
release_secondary_cores();
#endif
@@ -281,32 +308,33 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsWaitImagingDone(UINTPTR wowFlashAddr, size_t *wo
{
UINT32 ret;
- g_flashImgAddr = wowFlashAddr;
- (VOID)LOS_EventInit(&g_suspendResumeEvent);
+ g_flashImgAddr = wowFlashAddr; /*烧录的flash地址*/
+ (VOID)LOS_EventInit(&g_suspendResumeEvent); /*指向用于存储烧录镜像大小的变量的指针*/
- // This flag will be stored into flash, and will affect the wakeup procedure when cpu is rebooting.
+ // 这个标志将被存储到闪存中,当 CPU 重新启动时,它将影响唤醒流程。
g_resumeFromImg = LOS_RUN_STOP_RESET;
- // This flag affects the suspending procedure later,
- // and will be reset depending on 'g_resumeFromImg' when cpu is rebooting.
+ // 这个标志会影响之后的挂起过程,并且在 CPU 重新启动时根据 'g_resumeFromImg' 的值进行重置
g_otherCoreResume = 0;
- g_sysDoneFlag[LOSCFG_KERNEL_CORE_NUM - 1] = OS_STORE_SYSTEM;
+ g_sysDoneFlag[LOSCFG_KERNEL_CORE_NUM - 1] = OS_STORE_SYSTEM; /*表示系统状态需要被保存*/
ret = LOS_EventRead(&g_suspendResumeEvent, 0xFF, LOS_WAITMODE_OR | LOS_WAITMODE_CLR, LOS_WAIT_FOREVER);
+ /*等待事件发生*/
if (wowImgSize != NULL) {
*wowImgSize = g_wowImgSize;
- }
+ }/*保证能够在烧录完成之后正确的保存和恢复状态*/
return ret;
}
-LITE_OS_SEC_TEXT_MINOR VOID OsCarryLeftScatter(VOID)
+LITE_OS_SEC_TEXT_MINOR VOID OsCarryLeftScatter(VOID) /*将位于RAM的数据从指定位置复制到Flash存储器中*/
{
size_t size;
UINTPTR memAddr;
- size_t wowSize;
- size_t readAlignSize;
- size_t eraseAlignSize;
- size_t writeAlignSize;
+ size_t wowSize;/*等待复制数据的大小*/
+ size_t readAlignSize;/*读取对齐大小*/
+ size_t eraseAlignSize;/*擦除对齐大小*/
+ size_t writeAlignSize;/*写入对齐大小*/
+ /*读取所有参数的初始状态*/
UINTPTR imageFlashAddr;
FLASH_READ_FUNC flashReadFunc = g_runstopParam.pfFlashReadFunc;
@@ -315,18 +343,19 @@ LITE_OS_SEC_TEXT_MINOR VOID OsCarryLeftScatter(VOID)
eraseAlignSize = g_runstopParam.uwFlashEraseAlignSize;
writeAlignSize = g_runstopParam.uwFlashWriteAlignSize;
writeAlignSize = (writeAlignSize >= eraseAlignSize) ? writeAlignSize : eraseAlignSize;
-
+ /*计算wowsize的大小,根据对齐大小调整值*/
wowSize = ((UINTPTR)&__wow_end) - ((UINTPTR)&__ram_vectors_vma);
wowSize = (wowSize + writeAlignSize - 1) & ~(writeAlignSize - 1);
imageFlashAddr += wowSize;
-
+ /*检查memaddr是否超出了BSS段的起始地址*/
memAddr = ((UINTPTR)&__ram_vectors_vma) + wowSize;
if (memAddr >= ((UINTPTR)&__bss_start)) {
return;
}
+ /*计算了要复制的数据大小,在磁盘中根据对齐大小调整size*/
size = ((UINTPTR)&__int_stack_start) - memAddr;
size = (size + readAlignSize - 1) & ~(readAlignSize - 1);
-
+ /*将RAM中的数据从memaddr复制到flash存储器的imageflashaddr,进行缓存和同步操作*/
if ((flashReadFunc != NULL) && (flashReadFunc((VOID *)memAddr, imageFlashAddr, size) != 0)) {
PRINT_ERR("%s, %d\n", __FUNCTION__, __LINE__);
}
@@ -336,6 +365,8 @@ LITE_OS_SEC_TEXT_MINOR VOID OsCarryLeftScatter(VOID)
}
LITE_OS_SEC_TEXT_MINOR VOID OsRunstopParamInit(const RUNSTOP_PARAM_S *runstopParam)
+/*初始化运行暂停功能所需的参数,保存在全局变量g_中,以便告诉计算机目前的系统转台
+包含了运行暂停功能所需的各个回调函数和对齐大小等参数*/
{
g_runstopParam.pfIdleWakeupCallback = runstopParam->pfIdleWakeupCallback;
g_runstopParam.pfWakeupCallback = runstopParam->pfWakeupCallback;
@@ -350,28 +381,31 @@ LITE_OS_SEC_TEXT_MINOR VOID OsRunstopParamInit(const RUNSTOP_PARAM_S *runstopPar
}
LITE_OS_SEC_TEXT_MINOR VOID LOS_MakeImage(RUNSTOP_PARAM_S *runstopParam)
+/*用于除法运行暂停功能的操作,并根据返回值进行相应处理*/
{
UINT32 ret;
size_t imgSize;
-
+ /*检查是否需要暂停*/
if (runstopParam == NULL) {
return;
}
+ /*调用函数,将传入的runstopparam转换为全局变量*/
OsRunstopParamInit(runstopParam);
ret = OsWaitImagingDone(g_runstopParam.uwWowFlashAddr, &imgSize);
- if (ret == WAKEUP_FROM_SUSPEND) {
+ /*用于等待图像转移完成,范围相应的状态码ret和图像大小imgsize*/
+ if (ret == WAKEUP_FROM_SUSPEND) { /*从暂停状态唤醒,并查看系统是否需要空闲唤醒回调*/
if (g_runstopParam.pfWakeupCallback != NULL) {
g_runstopParam.pfWakeupCallback();
}
- OsCarryLeftScatter();
+ OsCarryLeftScatter(); /*将RAM中的数据复制到Flash存储器*/
PRINT_INFO("Resume ok!\n");
- } else if (ret == FLASH_IMG_SUCCESS) {
+ } else if (ret == FLASH_IMG_SUCCESS) { /*闪存图像成功*/
if (g_runstopParam.pfImageDoneCallback != NULL) {
g_runstopParam.pfImageDoneCallback();
}
- PRINT_INFO("Flash ok! Image length 0x%x\n", imgSize);
+ PRINT_INFO("Flash ok! Image length 0x%x\n", imgSize);/*图像转移成功,并打印图像大小*/
}
}
@@ -380,8 +414,9 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsWowWriteFlashTaskCreate(VOID)
UINT32 ret;
UINT32 writeFlashTaskId;
TSK_INIT_PARAM_S taskInitParam;
-
+ /*首先对任务初始化参数进行了清零操作*/
(VOID)memset_s((VOID *)(&taskInitParam), sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S));
+ /*设置了任务入口函数,并且制定了任务的堆栈大小,任务名和优先级*/
taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)OsWriteToFlashTask;
taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
taskInitParam.pcName = "WowWriteFlashTask";
@@ -389,24 +424,28 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsWowWriteFlashTaskCreate(VOID)
#ifdef LOSCFG_KERNEL_SMP
taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(0);
#endif
+ /*创建任务,返回结果*/
ret = LOS_TaskCreate(&writeFlashTaskId, &taskInitParam);
return ret;
}
LITE_OS_SEC_TEXT_MINOR size_t OsWowImageSizeGet(VOID)
+/*获取wow图像的大小,返回全局变量*/
{
return g_wowImgSize;
}
LITE_OS_SEC_TEXT_MINOR UINT32 OsWowSysDoneFlagGet(VOID)
+/*获取wow系统完成的标志*/
{
UINT32 cpuid = ArchCurrCpuid();
return g_sysDoneFlag[cpuid];
}
LITE_OS_SEC_TEXT_MINOR VOID OsWowOtherCoreResume(UINT32 cpuid)
+/*唤醒其他的核心*/
{
- if (g_otherCoreResume == 1) {
+ if (g_otherCoreResume == 1) { /*全局变量的值为1则表示需要唤醒其他核心*/
OsCurrTaskSet(g_saveTsk[cpuid]);
OsSRRestoreRegister();
}
diff --git a/src/kernel/extended/lowpower/tickless/los_tickless.c b/src/kernel/extended/lowpower/tickless/los_tickless.c
index fdeb5b8..d609b1e 100644
--- a/src/kernel/extended/lowpower/tickless/los_tickless.c
+++ b/src/kernel/extended/lowpower/tickless/los_tickless.c
@@ -46,42 +46,46 @@ STATIC volatile UINT32 g_sleepTicks[LOSCFG_KERNEL_CORE_NUM] = {0};
(((GET_SYS_CLOCK()) / (g_tickPerSecond)) - (cyclesCur)) : \
((((GET_SYS_CLOCK()) / (g_tickPerSecond)) << 1) - (cyclesCur)))
-LITE_OS_SEC_TEXT VOID LOS_TicklessEnable(VOID)
+LITE_OS_SEC_TEXT VOID LOS_TicklessEnable(VOID) /*开启Tickless功能*/
{
g_ticklessFlag = TRUE;
+ /*变量表示Tickless功能的开启状态,为TRUE表示已开启,为FALSE表示已关闭。*/
}
-LITE_OS_SEC_TEXT VOID LOS_TicklessDisable(VOID)
+LITE_OS_SEC_TEXT VOID LOS_TicklessDisable(VOID) /*开启Tickless功能*/
{
g_ticklessFlag = FALSE;
}
-LITE_OS_SEC_TEXT BOOL OsTicklessFlagGet(VOID)
+LITE_OS_SEC_TEXT BOOL OsTicklessFlagGet(VOID) /*用于获取Tickless标志的状态*/
{
return g_ticklessFlag;
}
-LITE_OS_SEC_TEXT BOOL OsTickIrqFlagGet(VOID)
+LITE_OS_SEC_TEXT BOOL OsTickIrqFlagGet(VOID)
{
return g_tickIrqFlag[ArchCurrCpuid()];
+ /*数组表示每个核心的Tick中断标志的状态,
+ 为TRUE表示中断正在处理中,为FALSE表示中断未处理。*/
}
-LITE_OS_SEC_TEXT VOID OsTickIrqFlagSet(BOOL tickIrqFlag)
+LITE_OS_SEC_TEXT VOID OsTickIrqFlagSet(BOOL tickIrqFlag) /*用于设置当前核心的时钟中断标志*/
{
g_tickIrqFlag[ArchCurrCpuid()] = tickIrqFlag;
}
-LITE_OS_SEC_TEXT UINT32 OsTicklessSleepTickGet(VOID)
+LITE_OS_SEC_TEXT UINT32 OsTicklessSleepTickGet(VOID) /*用于获取当前系统的睡眠计时器的数值*/
{
return g_sleepTicks[ArchCurrCpuid()];
}
-LITE_OS_SEC_TEXT VOID OsTicklessSleepTickSet(UINT32 sleeptick)
+LITE_OS_SEC_TEXT VOID OsTicklessSleepTickSet(UINT32 sleeptick) /*设置当前核心得到睡眠计时器的数值*/
{
g_sleepTicks[ArchCurrCpuid()] = sleeptick;
}
-LITE_OS_SEC_TEXT UINT32 OsSleepTicksGet(VOID)
+LITE_OS_SEC_TEXT UINT32 OsSleepTicksGet(VOID) /*函数用于获取当前需要休眠的ticks数,通过查询任务链表和软件定时器链表,
+ 找到最小的定时器到期时间,作为休眠时长。*/
{
UINT32 tskSortLinkTicks, sleepTicks;
@@ -104,7 +108,8 @@ LITE_OS_SEC_TEXT UINT32 OsSleepTicksGet(VOID)
return sleepTicks;
}
-LITE_OS_SEC_TEXT VOID OsSysTimeUpdate(UINT32 sleepTicks)
+LITE_OS_SEC_TEXT VOID OsSysTimeUpdate(UINT32 sleepTicks) /*用于更新系统时间,
+ 根据休眠时长更新全局计数器和任务链表、软件定时器链表的到期时间*/
{
UINT32 intSave;
@@ -127,7 +132,7 @@ LITE_OS_SEC_TEXT VOID OsSysTimeUpdate(UINT32 sleepTicks)
LOS_IntRestore(intSave);
}
-VOID OsTicklessUpdate(UINT32 irqnum)
+VOID OsTicklessUpdate(UINT32 irqnum) /*OsTicklessUpdate函数用于在发生中断时更新系统时间*/
{
UINT32 cycles, ticks;
UINT32 cyclesPertick;
@@ -165,7 +170,8 @@ VOID OsTicklessUpdate(UINT32 irqnum)
LOS_IntRestore(intSave);
}
-VOID OsTicklessStart(VOID)
+VOID OsTicklessStart(VOID) /*Tickless模式的入口函数,根据休眠时长计算需要延迟的周期数,
+ 并设置定时器的重载值,启动Tickless模式。*/
{
UINT32 intSave;
/*
@@ -202,7 +208,8 @@ VOID OsTicklessStart(VOID)
return;
}
-VOID OsTicklessOpen(VOID)
+VOID OsTicklessOpen(VOID) /*在Tick中断处理函数中开启Tickless模式。
+ 当Tick中断处理函数检测到Tickless标志为1时,调用该函数启动Tickless模式。*/
{
if (OsTickIrqFlagGet()) {
OsTickIrqFlagSet(0);
diff --git a/src/kernel/extended/perf/los_perf.c b/src/kernel/extended/perf/los_perf.c
index ecb0c2e..e8b84f6 100644
--- a/src/kernel/extended/perf/los_perf.c
+++ b/src/kernel/extended/perf/los_perf.c
@@ -37,10 +37,11 @@ extern "C" {
#endif /* __cplusplus */
#ifdef LOSCFG_KERNEL_PERF
-STATIC Pmu *g_pmu = NULL;
-STATIC PerfCB g_perfCb = {0};
+STATIC Pmu *g_pmu = NULL;//用于保存当前系统中所使用的硬件性能计数器
+STATIC PerfCB g_perfCb = {0};//保存了性能测量回调函数和一些测量结果数据
LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_perfSpin);
+//定义了一个自旋锁 g_perfSpin,用于保护性能测量模块在多线程环境下的并发访问
#define PERF_LOCK(state) LOS_SpinLockSave(&g_perfSpin, &(state))
#define PERF_UNLOCK(state) LOS_SpinUnlockRestore(&g_perfSpin, (state))
@@ -55,8 +56,9 @@ STATIC INLINE UINT64 OsPerfGetCurrTime(VOID)
#endif
}
-STATIC UINT32 OsPmuInit(VOID)
+STATIC UINT32 OsPmuInit(VOID)//初始化性能计数器
{
+ //判断是否开启了计数器
#ifdef LOSCFG_PERF_HW_PMU
if (OsHwPmuInit() != LOS_OK) {
return LOS_ERRNO_PERF_HW_INIT_ERROR;
@@ -77,13 +79,13 @@ STATIC UINT32 OsPmuInit(VOID)
return LOS_OK;
}
-STATIC UINT32 OsPerfConfig(PerfEventConfig *eventsCfg)
+STATIC UINT32 OsPerfConfig(PerfEventConfig *eventsCfg)//配置性能计数器
{
UINT32 i;
UINT32 ret;
g_pmu = OsPerfPmuGet(eventsCfg->type);
- if (g_pmu == NULL) {
+ if (g_pmu == NULL) {//根据配置的类型获取对应的性能计数器对象
PRINT_ERR("perf config type error %u!\n", eventsCfg->type);
return LOS_ERRNO_PERF_INVALID_PMU;
}
@@ -92,6 +94,7 @@ STATIC UINT32 OsPerfConfig(PerfEventConfig *eventsCfg)
(VOID)memset_s(&g_pmu->events, sizeof(PerfEvent), 0, sizeof(PerfEvent));
+//根据配置信息设置各性能事件的参数,调用性能计数器对象的配置函数进行配置
for (i = 0; i < eventNum; i++) {
g_pmu->events.per[i].eventId = eventsCfg->events[i].eventId;
g_pmu->events.per[i].period = eventsCfg->events[i].period;
@@ -109,13 +112,13 @@ STATIC UINT32 OsPerfConfig(PerfEventConfig *eventsCfg)
return LOS_OK;
}
-STATIC VOID OsPerfPrintCount(VOID)
+STATIC VOID OsPerfPrintCount(VOID)//用于打印性能计数器的统计信息
{
UINT32 index;
UINT32 intSave;
UINT32 cpuid = ArchCurrCpuid();
- PerfEvent *events = &g_pmu->events;
+ PerfEvent *events = &g_pmu->events;//获取性能计数器对象的性能时间数组和事件数量
UINT32 eventNum = events->nr;
PERF_LOCK(intSave);
@@ -123,7 +126,7 @@ STATIC VOID OsPerfPrintCount(VOID)
Event *event = &(events->per[index]);
/* filter out event counter with no event binded. */
- if (event->period == 0) {
+ if (event->period == 0) { //事件周期
continue;
}
PRINT_EMG("[%s] eventType: 0x%x [core %u]: %llu\n", g_pmu->getName(event), event->eventId, cpuid,
@@ -132,7 +135,7 @@ STATIC VOID OsPerfPrintCount(VOID)
PERF_UNLOCK(intSave);
}
-STATIC INLINE VOID OsPerfPrintTs(VOID)
+STATIC INLINE VOID OsPerfPrintTs(VOID)//打印时间信息
{
#ifdef LOSCFG_PERF_CALC_TIME_BY_TICK
DOUBLE time = (g_perfCb.endTime - g_perfCb.startTime) * 1.0 / LOSCFG_BASE_CORE_TICK_PER_SECOND;
@@ -142,7 +145,7 @@ STATIC INLINE VOID OsPerfPrintTs(VOID)
PRINT_EMG("time used: %.6f(s)\r\n", time);
}
-STATIC VOID OsPerfStart(VOID)
+STATIC VOID OsPerfStart(VOID)//启动及更新CPU和计数器状态
{
UINT32 cpuid = ArchCurrCpuid();
@@ -152,7 +155,7 @@ STATIC VOID OsPerfStart(VOID)
}
if (g_perfCb.pmuStatusPerCpu[cpuid] != PERF_PMU_STARTED) {
- UINT32 ret = g_pmu->start();
+ UINT32 ret = g_pmu->start();//若计数器未启动则启动
if (ret != LOS_OK) {
PRINT_ERR("perf start on core:%u failed, ret = 0x%x\n", cpuid, ret);
return;
@@ -164,7 +167,7 @@ STATIC VOID OsPerfStart(VOID)
}
}
-STATIC VOID OsPerfStop(VOID)
+STATIC VOID OsPerfStop(VOID)//停止性能计数器
{
UINT32 cpuid = ArchCurrCpuid();
@@ -191,19 +194,21 @@ STATIC VOID OsPerfStop(VOID)
}
STATIC UINT32 OsPerfBackTrace(UINTPTR *callChain, UINT32 maxDepth, PerfRegs *regs)
+//获取当前函数调用链的信息,并将结果存储在 callChain 数组中
{
UINT32 i;
- UINT32 count = ArchBackTraceGet(regs->fp, callChain, maxDepth);
+ UINT32 count = ArchBackTraceGet(regs->fp, callChain, maxDepth);//获取当前状态的帧指针值
PRINT_DEBUG("backtrace depth = %u, fp = 0x%x\n", count, regs->fp);
for (i = 0; i < count; i++) {
- PRINT_DEBUG("ip[%u]: 0x%x\n", i, callChain[i]);
+ PRINT_DEBUG("ip[%u]: 0x%x\n", i, callChain[i]);//打印调用链中每个函数的指令地址
}
- return count;
+ return count;//返回用链的深度
}
STATIC UINT32 OsPerfCollectData(Event *event, PerfSampleData *data, PerfRegs *regs)
+//收集性能计数器的数据,并将其存储在 data 结构体中
{
UINT32 size = 0;
UINT32 depth;
@@ -211,12 +216,12 @@ STATIC UINT32 OsPerfCollectData(Event *event, PerfSampleData *data, PerfRegs *re
CHAR *p = (CHAR *)data;
if (sampleType & PERF_RECORD_CPU) {
- *(UINT32 *)(p + size) = ArchCurrCpuid();
+ *(UINT32 *)(p + size) = ArchCurrCpuid();//函数获取当前CPU的ID,并存储在 data->cpuid 字段中
size += sizeof(data->cpuid);
}
if (sampleType & PERF_RECORD_TID) {
- *(UINT32 *)(p + size) = LOS_CurTaskIDGet();
+ *(UINT32 *)(p + size) = LOS_CurTaskIDGet();// 函数获取当前任务的ID,并存储在 data->taskId 字段中
size += sizeof(data->taskId);
}
@@ -231,7 +236,7 @@ STATIC UINT32 OsPerfCollectData(Event *event, PerfSampleData *data, PerfRegs *re
}
if (sampleType & PERF_RECORD_TIMESTAMP) {
- *(UINT64 *)(p + size) = OsPerfGetCurrTime();
+ *(UINT64 *)(p + size) = OsPerfGetCurrTime();//获取当前时间戳,并存储在 data->time 字段中
size += sizeof(data->time);
}
@@ -254,7 +259,7 @@ STATIC UINT32 OsPerfCollectData(Event *event, PerfSampleData *data, PerfRegs *re
* return TRUE if user haven't specified any taskId(which is supposed
* to instrument the whole system)
*/
-STATIC BOOL OsPerfTaskFilter(UINT32 taskId)
+STATIC BOOL OsPerfTaskFilter(UINT32 taskId)//过滤任务ID,判断一个给定的任务ID是否需要进行性能优化
{
UINT32 i;
@@ -262,7 +267,7 @@ STATIC BOOL OsPerfTaskFilter(UINT32 taskId)
return TRUE;
}
- for (i = 0; i < g_perfCb.taskIdsNr; i++) {
+ for (i = 0; i < g_perfCb.taskIdsNr; i++) { //储存允许过滤任务ID的列表
if (g_perfCb.taskIds[i] == taskId) {
return TRUE;
}
@@ -270,7 +275,7 @@ STATIC BOOL OsPerfTaskFilter(UINT32 taskId)
return FALSE;
}
-STATIC INLINE UINT32 OsPerfParamValid(VOID)
+STATIC INLINE UINT32 OsPerfParamValid(VOID)//检查性能函数的有效性
{
UINT32 index;
UINT32 res = 0;
@@ -287,7 +292,7 @@ STATIC INLINE UINT32 OsPerfParamValid(VOID)
return res;
}
-STATIC UINT32 OsPerfHdrInit(UINT32 id)
+STATIC UINT32 OsPerfHdrInit(UINT32 id)//初始化性能数据的头部信息
{
PerfDataHdr head = {
.magic = PERF_DATA_MAGIC_WORD,
@@ -299,7 +304,7 @@ STATIC UINT32 OsPerfHdrInit(UINT32 id)
return OsPerfOutPutWrite((CHAR *)&head, head.len);
}
-VOID OsPerfUpdateEventCount(Event *event, UINT32 value)
+VOID OsPerfUpdateEventCount(Event *event, UINT32 value)//更新上传事件的技术
{
if (event == NULL) {
return;
@@ -307,46 +312,46 @@ VOID OsPerfUpdateEventCount(Event *event, UINT32 value)
event->count[ArchCurrCpuid()] += (value & 0xFFFFFFFF); /* event->count is UINT64 */
}
-VOID OsPerfHandleOverFlow(Event *event, PerfRegs *regs)
+VOID OsPerfHandleOverFlow(Event *event, PerfRegs *regs)//处理性能计数器溢出的情况
{
PerfSampleData data;
UINT32 len;
(VOID)memset_s(&data, sizeof(PerfSampleData), 0, sizeof(PerfSampleData));
- if ((g_perfCb.needSample) && OsPerfTaskFilter(LOS_CurTaskIDGet())) {
+ if ((g_perfCb.needSample) && OsPerfTaskFilter(LOS_CurTaskIDGet())) {//判断是否优化
len = OsPerfCollectData(event, &data, regs);
OsPerfOutPutWrite((CHAR *)&data, len);
}
}
-UINT32 LOS_PerfInit(VOID *buf, UINT32 size)
+UINT32 LOS_PerfInit(VOID *buf, UINT32 size)//初始化性能统计模块
{
UINT32 ret;
UINT32 intSave;
- PERF_LOCK(intSave);
+ PERF_LOCK(intSave);//保存中断状态
if (g_perfCb.status != PERF_UNINIT) {
ret = LOS_ERRNO_PERF_STATUS_INVALID;
goto PERF_INIT_ERROR;
}
- ret = OsPmuInit();
+ ret = OsPmuInit();//函数性能计数器初始化
if (ret != LOS_OK) {
goto PERF_INIT_ERROR;
}
- ret = OsPerfOutPutInit(buf, size);
+ ret = OsPerfOutPutInit(buf, size);//性能输出缓冲区进行初始化
if (ret != LOS_OK) {
ret = LOS_ERRNO_PERF_BUF_ERROR;
goto PERF_INIT_ERROR;
}
g_perfCb.status = PERF_STOPED;
PERF_INIT_ERROR:
- PERF_UNLOCK(intSave);
+ PERF_UNLOCK(intSave);//解锁中断处理
return ret;
}
-UINT32 LOS_PerfConfig(PerfConfigAttr *attr)
+UINT32 LOS_PerfConfig(PerfConfigAttr *attr)//配置性能统计模块的属性
{
UINT32 ret;
UINT32 intSave;
@@ -355,20 +360,20 @@ UINT32 LOS_PerfConfig(PerfConfigAttr *attr)
return LOS_ERRNO_PERF_CONFIG_NULL;
}
- PERF_LOCK(intSave);
+ PERF_LOCK(intSave);//保存中断状态
if (g_perfCb.status != PERF_STOPED) {
ret = LOS_ERRNO_PERF_STATUS_INVALID;
PRINT_ERR("perf config status error : 0x%x\n", g_perfCb.status);
goto PERF_CONFIG_ERROR;
}
- g_pmu = NULL;
+ g_pmu = NULL;//将全局标量PMU计数器置零
g_perfCb.needSample = attr->needSample;
g_perfCb.taskFilterEnable = attr->taskFilterEnable;
g_perfCb.sampleType = attr->sampleType;
- if (attr->taskFilterEnable) {
+ if (attr->taskFilterEnable) {//开启任务过滤功能
ret = memcpy_s(g_perfCb.taskIds, PERF_MAX_FILTER_TSKS * sizeof(UINT32), attr->taskIds,
g_perfCb.taskIdsNr * sizeof(UINT32));
if (ret != EOK) {
@@ -377,29 +382,29 @@ UINT32 LOS_PerfConfig(PerfConfigAttr *attr)
}
g_perfCb.taskIdsNr = MIN(attr->taskIdsNr, PERF_MAX_FILTER_TSKS);
}
- ret = OsPerfConfig(&attr->eventsCfg);
+ ret = OsPerfConfig(&attr->eventsCfg);//对事件配置进行处理
PERF_CONFIG_ERROR:
PERF_UNLOCK(intSave);
return ret;
}
-VOID LOS_PerfStart(UINT32 sectionId)
+VOID LOS_PerfStart(UINT32 sectionId)//启动性能统计模块
{
UINT32 intSave;
UINT32 ret;
PERF_LOCK(intSave);
- if (g_perfCb.status != PERF_STOPED) {
+ if (g_perfCb.status != PERF_STOPED) {//判断统计模块是否打开
PRINT_ERR("perf start status error : 0x%x\n", g_perfCb.status);
goto PERF_START_ERROR;
}
- if (!OsPerfParamValid()) {
+ if (!OsPerfParamValid()) {//检车行呢个统计模块的参数是否有效
PRINT_ERR("forgot call `LOS_Config(...)` before instrumenting?\n");
goto PERF_START_ERROR;
}
- if (g_perfCb.needSample) {
+ if (g_perfCb.needSample) {//判断是否需要抽样
ret = OsPerfHdrInit(sectionId); /* section header init */
if (ret != LOS_OK) {
PRINT_ERR("perf hdr init error 0x%x\n", ret);
@@ -407,7 +412,7 @@ VOID LOS_PerfStart(UINT32 sectionId)
}
}
- SMP_CALL_PERF_FUNC(OsPerfStart); /* send to all cpu to start pmu */
+ SMP_CALL_PERF_FUNC(OsPerfStart); /* 所有CPU开始PMU计数器,启动性能统计模块i奥 */
g_perfCb.status = PERF_STARTED;
g_perfCb.startTime = OsPerfGetCurrTime();
PERF_START_ERROR:
@@ -415,7 +420,7 @@ PERF_START_ERROR:
return;
}
-VOID LOS_PerfStop(VOID)
+VOID LOS_PerfStop(VOID)//停止性能统计模块的运行,进行一些清理操作
{
UINT32 intSave;
@@ -427,12 +432,12 @@ VOID LOS_PerfStop(VOID)
SMP_CALL_PERF_FUNC(OsPerfStop); /* send to all cpu to stop pmu */
- OsPerfOutPutFlush();
+ OsPerfOutPutFlush();//刷新输出操作
if (g_perfCb.needSample) {
OsPerfOutPutInfo();
}
-
+ //更新了两个全局变量的值,表示性能统计模块已经在状态上和时间上停止了
g_perfCb.status = PERF_STOPED;
g_perfCb.endTime = OsPerfGetCurrTime();
@@ -442,21 +447,21 @@ PERF_STOP_ERROR:
return;
}
-UINT32 LOS_PerfDataRead(CHAR *dest, UINT32 size)
+UINT32 LOS_PerfDataRead(CHAR *dest, UINT32 size)//从性能统计门票快的输出缓冲区中读取数据到指定的内存
{
return OsPerfOutPutRead(dest, size);
}
-VOID LOS_PerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func)
+VOID LOS_PerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func)//注册型那个统计模块的通知hook函数
{
UINT32 intSave;
-
+ //保存中断状态,恢复中断状态
PERF_LOCK(intSave);
OsPerfNotifyHookReg(func);
PERF_UNLOCK(intSave);
}
-VOID LOS_PerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func)
+VOID LOS_PerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func)//刷新hook
{
UINT32 intSave;
@@ -465,7 +470,7 @@ VOID LOS_PerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func)
PERF_UNLOCK(intSave);
}
-VOID OsPerfSetIrqRegs(UINTPTR pc, UINTPTR fp)
+VOID OsPerfSetIrqRegs(UINTPTR pc, UINTPTR fp)//设置中断相关的寄存器,用于中断时的性能统计
{
LosTaskCB *runTask = (LosTaskCB *)ArchCurrTaskGet();
runTask->pc = pc;
diff --git a/src/kernel/extended/perf/perf_output.c b/src/kernel/extended/perf/perf_output.c
index 20bea3a..a83d806 100644
--- a/src/kernel/extended/perf/perf_output.c
+++ b/src/kernel/extended/perf/perf_output.c
@@ -39,11 +39,14 @@ STATIC PERF_BUF_FLUSH_HOOK g_perfBufFlushHook = NULL;
STATIC PerfOutputCB g_perfOutputCb;
STATIC VOID OsPerfDefaultNotify(VOID)
+//默认的性能缓冲区通知回调函数,在性能缓冲区的水位线达到一定值时打印一条信息
{
PRINT_INFO("perf buf waterline notify!\n");
}
UINT32 OsPerfOutPutInit(VOID *buf, UINT32 size)
+//初始化性能输出模块。如果传入的缓冲区指针为空,则使用LOS_MemAlloc函数动态分配内存。
+//然后初始化环形缓冲区,设置水位线,并注册默认的性能缓冲区通知回调函数
{
UINT32 ret;
BOOL releaseFlag = FALSE;
@@ -69,21 +72,22 @@ RELEASE:
return ret;
}
-VOID OsPerfOutPutFlush(VOID)
+VOID OsPerfOutPutFlush(VOID)//刷新性能输出缓冲区
{
if (g_perfBufFlushHook != NULL) {
g_perfBufFlushHook(g_perfOutputCb.ringbuf.fifo, g_perfOutputCb.ringbuf.size);
}
}
-UINT32 OsPerfOutPutRead(CHAR *dest, UINT32 size)
+UINT32 OsPerfOutPutRead(CHAR *dest, UINT32 size)//从性能输出缓冲区中读取数据
{
OsPerfOutPutFlush();
return LOS_RingbufRead(&g_perfOutputCb.ringbuf, dest, size);
}
-STATIC BOOL OsPerfOutPutBegin(UINT32 size)
+STATIC BOOL OsPerfOutPutBegin(UINT32 size)//开始写入性能输出缓冲区
{
+ //检查是否有足够空间
if (g_perfOutputCb.ringbuf.remain < size) {
PRINT_INFO("perf buf has no enough space for 0x%x\n", size);
return FALSE;
@@ -91,9 +95,9 @@ STATIC BOOL OsPerfOutPutBegin(UINT32 size)
return TRUE;
}
-STATIC VOID OsPerfOutPutEnd(VOID)
+STATIC VOID OsPerfOutPutEnd(VOID)//结束性能输出
{
- OsPerfOutPutFlush();
+ OsPerfOutPutFlush();//刷新缓冲区
if (LOS_RingbufUsedSize(&g_perfOutputCb.ringbuf) >= g_perfOutputCb.waterMark) {
if (g_perfBufNotifyHook != NULL) {
g_perfBufNotifyHook();
@@ -101,7 +105,7 @@ STATIC VOID OsPerfOutPutEnd(VOID)
}
}
-UINT32 OsPerfOutPutWrite(CHAR *data, UINT32 size)
+UINT32 OsPerfOutPutWrite(CHAR *data, UINT32 size)//将数据写入性能输入缓冲区
{
if (!OsPerfOutPutBegin(size)) {
return LOS_NOK;
@@ -113,17 +117,17 @@ UINT32 OsPerfOutPutWrite(CHAR *data, UINT32 size)
return LOS_OK;
}
-VOID OsPerfOutPutInfo(VOID)
+VOID OsPerfOutPutInfo(VOID)//打印性能输出缓冲区的信息,包括地址和长度
{
PRINT_EMG("dump section data, addr: %p length: %#x \r\n", g_perfOutputCb.ringbuf.fifo, g_perfOutputCb.ringbuf.size);
}
-VOID OsPerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func)
+VOID OsPerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func)//注册性能缓冲区通知
{
g_perfBufNotifyHook = func;
}
-VOID OsPerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func)
+VOID OsPerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func)//注册性能缓冲区刷新的函数
{
g_perfBufFlushHook = func;
}
diff --git a/src/kernel/extended/perf/perf_output_pri.h b/src/kernel/extended/perf/perf_output_pri.h
index 382f2a9..603e64d 100644
--- a/src/kernel/extended/perf/perf_output_pri.h
+++ b/src/kernel/extended/perf/perf_output_pri.h
@@ -43,13 +43,13 @@ typedef struct {
UINT32 waterMark; /* notify water mark */
} PerfOutputCB;
-extern UINT32 OsPerfOutPutInit(VOID *buf, UINT32 size);
-extern UINT32 OsPerfOutPutRead(CHAR *dest, UINT32 size);
-extern UINT32 OsPerfOutPutWrite(CHAR *data, UINT32 size);
-extern VOID OsPerfOutPutInfo(VOID);
-extern VOID OsPerfOutPutFlush(VOID);
-extern VOID OsPerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func);
-extern VOID OsPerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func);
+extern UINT32 OsPerfOutPutInit(VOID *buf, UINT32 size);//初始化性能输出模块
+extern UINT32 OsPerfOutPutRead(CHAR *dest, UINT32 size);//从性能输出缓冲区中读取数据,将数据拷贝到指定的目标缓冲区中
+extern UINT32 OsPerfOutPutWrite(CHAR *data, UINT32 size);//将数据写入性能输出缓冲区
+extern VOID OsPerfOutPutInfo(VOID);//输出性能统计信息
+extern VOID OsPerfOutPutFlush(VOID);//刷新性能输出缓冲区
+extern VOID OsPerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func);//注册性能输出缓冲区通知
+extern VOID OsPerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func);//注册性能输出缓冲区刷新
#ifdef __cplusplus
#if __cplusplus
diff --git a/src/kernel/extended/perf/perf_pmu.c b/src/kernel/extended/perf/perf_pmu.c
index a2771ba..ff5cca6 100644
--- a/src/kernel/extended/perf/perf_pmu.c
+++ b/src/kernel/extended/perf/perf_pmu.c
@@ -36,11 +36,11 @@ extern "C" {
STATIC Pmu *g_pmuMgr[PERF_EVENT_TYPE_MAX] = {NULL};
-UINT32 OsPerfPmuRegister(Pmu *pmu)
+UINT32 OsPerfPmuRegister(Pmu *pmu)//注册性能计数器
{
UINT32 type;
- if ((pmu == NULL) || (pmu->type >= PERF_EVENT_TYPE_MAX)) {
+ if ((pmu == NULL) || (pmu->type >= PERF_EVENT_TYPE_MAX)) {//如果传入PMU为空指针或者type超出了有效范围
return LOS_NOK;
}
@@ -52,19 +52,20 @@ UINT32 OsPerfPmuRegister(Pmu *pmu)
return LOS_NOK;
}
-Pmu *OsPerfPmuGet(UINT32 type)
+Pmu *OsPerfPmuGet(UINT32 type)//获取指定类型的性能计数器
{
if (type >= PERF_EVENT_TYPE_MAX) {
return NULL;
}
- if (type == PERF_EVENT_TYPE_RAW) { /* process hardware raw events with hard pmu */
- type = PERF_EVENT_TYPE_HW;
+ if (type == PERF_EVENT_TYPE_RAW) { //如果是原始事件类型
+ /* process hardware raw events with hard pmu */
+ type = PERF_EVENT_TYPE_HW;//则将其转化为硬件事件类型
}
return g_pmuMgr[type];
}
-VOID OsPerfPmuRm(UINT32 type)
+VOID OsPerfPmuRm(UINT32 type)//删除指定类型的性能计数器
{
if (type >= PERF_EVENT_TYPE_MAX) {
return;
diff --git a/src/kernel/extended/perf/perf_pmu_pri.h b/src/kernel/extended/perf/perf_pmu_pri.h
index 2507d34..4cbb5bd 100644
--- a/src/kernel/extended/perf/perf_pmu_pri.h
+++ b/src/kernel/extended/perf/perf_pmu_pri.h
@@ -53,7 +53,7 @@ typedef struct {
VOID (*setPeriod)(Event *event);
UINTPTR (*readCnt)(Event *event);
UINT32 (*mapEvent)(UINT32 eventType, BOOL reverse);
-} HwPmu;
+} HwPmu;//硬件性能计数器结构体,包括硬件计数器、计数器是否能被分频、分频系数、启用、禁用、开始、停止、清除、设置周期、读取计数器值和事件映射等函数指针
typedef struct {
Pmu pmu;
@@ -69,35 +69,35 @@ typedef struct {
};
#endif
};
-} SwPmu;
+} SwPmu;//软件性能计数器结构体,包括软件计数器、是否启用标志位、定时器配置时间
#define GET_HW_PMU(item) LOS_DL_LIST_ENTRY(item, HwPmu, pmu)
-#define TIMER_PERIOD_LOWER_BOUND_US 100
+#define TIMER_PERIOD_LOWER_BOUND_US 100//定时器最小周期
-#define CCNT_FULL 0xFFFFFFFF
-#define CCNT_PERIOD_LOWER_BOUND 0x00000000
-#define CCNT_PERIOD_UPPER_BOUND 0xFFFFFF00
-#define PERIOD_CALC(p) (CCNT_FULL - (p))
+#define CCNT_FULL 0xFFFFFFFF//计数器最大值
+#define CCNT_PERIOD_LOWER_BOUND 0x00000000//最小周期
+#define CCNT_PERIOD_UPPER_BOUND 0xFFFFFF00//最大周期
+#define PERIOD_CALC(p) (CCNT_FULL - (p))//计算给定周期对应的计数器值
#define VALID_PERIOD(p) ((PERIOD_CALC(p) > CCNT_PERIOD_LOWER_BOUND) \
- && (PERIOD_CALC(p) < CCNT_PERIOD_UPPER_BOUND))
+ && (PERIOD_CALC(p) < CCNT_PERIOD_UPPER_BOUND))//判断给定周期是否合法
-#define PERF_HW_INVAILD_EVENT_TYPE 0xFFFFFFFF
+#define PERF_HW_INVAILD_EVENT_TYPE 0xFFFFFFFF//无效的事件类型
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
-extern UINT32 OsPerfPmuRegister(Pmu *pmu);
-extern VOID OsPerfPmuRm(UINT32 type);
-extern Pmu *OsPerfPmuGet(UINT32 type);
+extern UINT32 OsPerfPmuRegister(Pmu *pmu);//注册硬件性能计数器
+extern VOID OsPerfPmuRm(UINT32 type);//删除硬件性能计数器
+extern Pmu *OsPerfPmuGet(UINT32 type);//获取指定类型的硬件性能计数器
-extern UINT32 OsHwPmuInit(VOID);
-extern UINT32 OsSwPmuInit(VOID);
-extern UINT32 OsTimedPmuInit(VOID);
+extern UINT32 OsHwPmuInit(VOID);//初始化硬件性能计数器
+extern UINT32 OsSwPmuInit(VOID);//初始化软件性能计数器
+extern UINT32 OsTimedPmuInit(VOID);//初始化定时器性能计数器
-extern UINT32 OsGetPmuCounter0(VOID);
-extern UINT32 OsGetPmuMaxCounter(VOID);
-extern UINT32 OsGetPmuCycleCounter(VOID);
-extern UINT32 OsPerfHwInit(HwPmu *hwPmu);
+extern UINT32 OsGetPmuCounter0(VOID);//获取0核计数器值
+extern UINT32 OsGetPmuMaxCounter(VOID);//获取最大计数器数
+extern UINT32 OsGetPmuCycleCounter(VOID);//获取周期性计数器值
+extern UINT32 OsPerfHwInit(HwPmu *hwPmu);//初始化硬件性能计数器
#ifdef __cplusplus
#if __cplusplus
diff --git a/src/kernel/extended/perf/pmu/perf_hw_pmu.c b/src/kernel/extended/perf/pmu/perf_hw_pmu.c
index ca0b797..f76869d 100644
--- a/src/kernel/extended/perf/pmu/perf_hw_pmu.c
+++ b/src/kernel/extended/perf/pmu/perf_hw_pmu.c
@@ -34,7 +34,7 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
-STATIC Pmu *g_perfHw = NULL;
+STATIC Pmu *g_perfHw = NULL;//指向性能计数器相关的数据结构或对象
STATIC CHAR *g_eventName[PERF_COUNT_HW_MAX] = {
[PERF_COUNT_HW_CPU_CYCLES] = "cycles",
@@ -53,39 +53,41 @@ STATIC CHAR *g_eventName[PERF_COUNT_HW_MAX] = {
* 2.Find available counter for each event.
* 3.Decide whether this hardware pmu need prescaler (once every 64 cycle counts).
*/
-STATIC UINT32 OsPerfHwConfig(VOID)
+STATIC UINT32 OsPerfHwConfig(VOID)//性能计数器的配置函数,用于初始化和配置硬件性能计数器
{
UINT32 i;
HwPmu *armPmu = GET_HW_PMU(g_perfHw);
- UINT32 maxCounter = OsGetPmuMaxCounter();
- UINT32 counter = OsGetPmuCounter0();
- UINT32 cycleCounter = OsGetPmuCycleCounter();
+ UINT32 maxCounter = OsGetPmuMaxCounter();//获得最大计数器数量
+ UINT32 counter = OsGetPmuCounter0();//获取0核计数器的值
+ UINT32 cycleCounter = OsGetPmuCycleCounter();//周期计数器的值
UINT32 cycleCode = armPmu->mapEvent(PERF_COUNT_HW_CPU_CYCLES, PERF_EVENT_TO_CODE);
if (cycleCode == PERF_HW_INVAILD_EVENT_TYPE) {
return LOS_NOK;
}
-
+ //获取性能事件的列表的和数量并进行遍历
PerfEvent *events = &g_perfHw->events;
UINT32 eventNum = events->nr;
for (i = 0; i < eventNum; i++) {
Event *event = &(events->per[i]);
- if (!VALID_PERIOD(event->period)) {
+ if (!VALID_PERIOD(event->period)) {//检查事件周期是否合法
PRINT_ERR("Config period: 0x%x invalid, should be in (%#x, %#x)\n", event->period,
PERIOD_CALC(CCNT_PERIOD_UPPER_BOUND), PERIOD_CALC(CCNT_PERIOD_LOWER_BOUND));
return LOS_NOK;
}
if (g_perfHw->type == PERF_EVENT_TYPE_HW) { /* do map */
+ //映射编码
UINT32 eventId = armPmu->mapEvent(event->eventId, PERF_EVENT_TO_CODE);
if (eventId == PERF_HW_INVAILD_EVENT_TYPE) {
return LOS_NOK;
}
event->eventId = eventId;
}
-
+ //函数根据事件编码是否与周期计数器的事件编码相同,来确定该事件使用的计数器。
+ //如果相同,则使用周期计数器;否则,使用普通计数器,并递增计数器的值。
if (event->eventId == cycleCode) {
event->counter = cycleCounter;
} else {
@@ -93,11 +95,11 @@ STATIC UINT32 OsPerfHwConfig(VOID)
counter++;
}
- if (counter >= maxCounter) {
+ if (counter >= maxCounter) {//检查计数器是否超过了最大计数器数量
PRINT_ERR("max events: %u excluding cycle event\n", maxCounter - 1);
return LOS_NOK;
}
-
+ //打印结果,设置根据平台支持的分频
PRINT_DEBUG("Perf Config %u eventId = 0x%x, counter = 0x%x, period = 0x%x\n", i, event->eventId, event->counter,
event->period);
}
@@ -106,21 +108,21 @@ STATIC UINT32 OsPerfHwConfig(VOID)
return LOS_OK;
}
-STATIC UINT32 OsPerfHwStart(VOID)
+STATIC UINT32 OsPerfHwStart(VOID)//用于启动硬件性能计数器
{
UINT32 i;
UINT32 cpuid = ArchCurrCpuid();
- HwPmu *armPmu = GET_HW_PMU(g_perfHw);
+ HwPmu *armPmu = GET_HW_PMU(g_perfHw);//获取硬件性能计数器的指针
PerfEvent *events = &g_perfHw->events;
UINT32 eventNum = events->nr;
- armPmu->clear();
+ armPmu->clear();//清零计数器
for (i = 0; i < eventNum; i++) {
Event *event = &(events->per[i]);
- armPmu->setPeriod(event);
- armPmu->enable(event);
+ armPmu->setPeriod(event);//设置事件的计数周期
+ armPmu->enable(event);//启用事件的计数器
event->count[cpuid] = 0;
}
@@ -128,7 +130,7 @@ STATIC UINT32 OsPerfHwStart(VOID)
return LOS_OK;
}
-STATIC UINT32 OsPerfHwStop(VOID)
+STATIC UINT32 OsPerfHwStop(VOID)//停止硬件性能计数器
{
UINT32 i;
UINT32 cpuid = ArchCurrCpuid();
@@ -148,7 +150,9 @@ STATIC UINT32 OsPerfHwStop(VOID)
/* multiplier of cycle counter */
UINT32 eventId = armPmu->mapEvent(event->eventId, PERF_CODE_TO_EVENT);
if ((eventId == PERF_COUNT_HW_CPU_CYCLES) && (armPmu->cntDivided != 0)) {
+ //如果该事件的事件ID与周期计数器事件ID相同,并且硬件性能计数器的分频设置armPmu->cntDivided不为0
PRINT_DEBUG("perf stop is cycle\n");
+ //此处将该事件的计数值左移6位,相当于乘以64
event->count[cpuid] = event->count[cpuid] << 6; /* CCNT counts every 64th cpu cycle */
}
PRINT_DEBUG("perf stop eventCount[0x%x] : [%s] = %llu\n", event->eventId, g_eventName[eventId],
@@ -157,11 +161,11 @@ STATIC UINT32 OsPerfHwStop(VOID)
return LOS_OK;
}
-STATIC CHAR *OsPerfGetEventName(Event *event)
+STATIC CHAR *OsPerfGetEventName(Event *event)//获取事件名称
{
UINT32 eventId;
- HwPmu *armPmu = GET_HW_PMU(g_perfHw);
- eventId = armPmu->mapEvent(event->eventId, PERF_CODE_TO_EVENT);
+ HwPmu *armPmu = GET_HW_PMU(g_perfHw);//获取PMU上的事件信息
+ eventId = armPmu->mapEvent(event->eventId, PERF_CODE_TO_EVENT);//将事件ID映射位对应计数器事件ID
if (eventId < PERF_COUNT_HW_MAX) {
return g_eventName[eventId];
} else {
@@ -169,21 +173,21 @@ STATIC CHAR *OsPerfGetEventName(Event *event)
}
}
-UINT32 OsPerfHwInit(HwPmu *hwPmu)
+UINT32 OsPerfHwInit(HwPmu *hwPmu)//初始化性能计数器
{
UINT32 ret;
if (hwPmu == NULL) {
return LOS_NOK;
}
-
+ //设置性能计数器的类型,配置函数,启动函数,停止函数,获取事件名称函数
hwPmu->pmu.type = PERF_EVENT_TYPE_HW;
hwPmu->pmu.config = OsPerfHwConfig;
hwPmu->pmu.start = OsPerfHwStart;
hwPmu->pmu.stop = OsPerfHwStop;
hwPmu->pmu.getName = OsPerfGetEventName;
-
+ //将硬件性能计数器的事件数据结构清零
(VOID)memset_s(&hwPmu->pmu.events, sizeof(PerfEvent), 0, sizeof(PerfEvent));
- ret = OsPerfPmuRegister(&hwPmu->pmu);
+ ret = OsPerfPmuRegister(&hwPmu->pmu);//注册硬件性能计数器,将其存储在全局变量中
g_perfHw = OsPerfPmuGet(PERF_EVENT_TYPE_HW);
return ret;
diff --git a/src/kernel/extended/perf/pmu/perf_sw_pmu.c b/src/kernel/extended/perf/pmu/perf_sw_pmu.c
index 5ea7e52..fe6f251 100644
--- a/src/kernel/extended/perf/pmu/perf_sw_pmu.c
+++ b/src/kernel/extended/perf/pmu/perf_sw_pmu.c
@@ -51,7 +51,7 @@ STATIC CHAR* g_eventName[PERF_COUNT_SW_MAX] = {
[PERF_COUNT_SW_MUX_PEND] = "mux pend",
};
-VOID OsPerfHook(UINT32 eventType)
+VOID OsPerfHook(UINT32 eventType)//软件性能计数器的事件处理函数
{
if (!g_perfSw.enable) {
return;
@@ -69,7 +69,7 @@ VOID OsPerfHook(UINT32 eventType)
if (event->counter == eventType) {
OsPerfUpdateEventCount(event, 1);
if (event->count[ArchCurrCpuid()] % event->period == 0) {
- OsPerfFetchCallerRegs(®s);
+ OsPerfFetchCallerRegs(®s);//获取寄存器信息
OsPerfHandleOverFlow(event, ®s);
}
return;
@@ -77,7 +77,7 @@ VOID OsPerfHook(UINT32 eventType)
}
}
-STATIC UINT32 OsPerfSwConfig(VOID)
+STATIC UINT32 OsPerfSwConfig(VOID)//对软件性能计数器进行配置
{
UINT32 i;
PerfEvent *events = &g_perfSw.pmu.events;
@@ -94,29 +94,29 @@ STATIC UINT32 OsPerfSwConfig(VOID)
return LOS_OK;
}
-STATIC UINT32 OsPerfSwStart(VOID)
+STATIC UINT32 OsPerfSwStart(VOID)//启动软件性能计数器
{
UINT32 i;
UINT32 cpuid = ArchCurrCpuid();
PerfEvent *events = &g_perfSw.pmu.events;
UINT32 eventNum = events->nr;
- for (i = 0; i < eventNum; i++) {
+ for (i = 0; i < eventNum; i++) {//遍历所有事件
Event *event = &(events->per[i]);
- event->count[cpuid] = 0;
+ event->count[cpuid] = 0;//清零当前事件在CPU中的计数器
}
- g_perfSw.enable = TRUE;
+ g_perfSw.enable = TRUE;//启动计数器
return LOS_OK;
}
-STATIC UINT32 OsPerfSwStop(VOID)
+STATIC UINT32 OsPerfSwStop(VOID)//关闭软件性能计数器
{
g_perfSw.enable = FALSE;
return LOS_OK;
}
-STATIC CHAR *OsPerfGetEventName(Event *event)
+STATIC CHAR *OsPerfGetEventName(Event *event)//获取事件的名称
{
UINT32 eventId = event->eventId;
if (eventId < PERF_COUNT_SW_MAX) {
@@ -125,7 +125,7 @@ STATIC CHAR *OsPerfGetEventName(Event *event)
return "unknown";
}
-UINT32 OsSwPmuInit(VOID)
+UINT32 OsSwPmuInit(VOID)//对PMU计数器进行初始化
{
g_perfSw.pmu = (Pmu) {
.type = PERF_EVENT_TYPE_SW,
diff --git a/src/kernel/extended/perf/pmu/perf_timed_pmu.c b/src/kernel/extended/perf/pmu/perf_timed_pmu.c
index 4659c08..6080f90 100644
--- a/src/kernel/extended/perf/pmu/perf_timed_pmu.c
+++ b/src/kernel/extended/perf/pmu/perf_timed_pmu.c
@@ -39,12 +39,12 @@ extern "C" {
STATIC SwPmu g_perfTimed;
-STATIC BOOL OsPerfTimedPeriodValid(UINT32 period)
+STATIC BOOL OsPerfTimedPeriodValid(UINT32 period)//验证定时器中的时间周期是否合法
{
return period >= TIMER_PERIOD_LOWER_BOUND_US;
}
-STATIC UINT32 OsPerfTimedStart(VOID)
+STATIC UINT32 OsPerfTimedStart(VOID)//启动定时器事件
{
UINT32 i;
UINT32 cpuid = ArchCurrCpuid();
@@ -74,7 +74,7 @@ STATIC UINT32 OsPerfTimedStart(VOID)
return LOS_OK;
}
-STATIC UINT32 OsPerfTimedConfig(VOID)
+STATIC UINT32 OsPerfTimedConfig(VOID)//配置定时器,检验是否合法
{
UINT32 i;
PerfEvent *events = &g_perfTimed.pmu.events;
@@ -101,7 +101,7 @@ STATIC UINT32 OsPerfTimedConfig(VOID)
return LOS_NOK;
}
-STATIC UINT32 OsPerfTimedStop(VOID)
+STATIC UINT32 OsPerfTimedStop(VOID)//关闭定时器设置
{
UINT32 ret;
if (ArchCurrCpuid() != 0) { /* only need stop on one core */
@@ -116,7 +116,7 @@ STATIC UINT32 OsPerfTimedStop(VOID)
return LOS_OK;
}
-STATIC VOID OsPerfTimedHandle(VOID)
+STATIC VOID OsPerfTimedHandle(VOID)//处理定时器事件
{
UINT32 index;
PerfRegs regs;
@@ -125,7 +125,7 @@ STATIC VOID OsPerfTimedHandle(VOID)
UINT32 eventNum = events->nr;
(VOID)memset_s(®s, sizeof(PerfRegs), 0, sizeof(PerfRegs));
- OsPerfFetchIrqRegs(®s);
+ OsPerfFetchIrqRegs(®s);//获取当前寄存器状态
for (index = 0; index < eventNum; index++) {
Event *event = &(events->per[index]);
@@ -134,48 +134,50 @@ STATIC VOID OsPerfTimedHandle(VOID)
}
}
-STATIC enum hrtimer_restart OsPerfHrtimer(struct hrtimer *hrtimer)
+STATIC enum hrtimer_restart OsPerfHrtimer(struct hrtimer *hrtimer)//高精度定时器(hrtimer)的回调函数
{
SMP_CALL_PERF_FUNC(OsPerfTimedHandle); /* send to all cpu to collect data */
+ //将定时器事件的处理发送给所有CPU进行数据收集
return HRTIMER_RESTART;
}
-STATIC CHAR *OsPerfGetEventName(Event *event)
+STATIC CHAR *OsPerfGetEventName(Event *event)//获取事件名称
{
- if (event->eventId == PERF_COUNT_CPU_CLOCK) {
+ if (event->eventId == PERF_COUNT_CPU_CLOCK) {//读取事件ID是否与计数器中的事件记录相同
return "timed";
} else {
return "unknown";
}
}
-UINT32 OsTimedPmuInit(VOID)
+UINT32 OsTimedPmuInit(VOID)//初始化定时器
{
UINT32 ret;
- g_perfTimed.time = (union ktime) {
+ g_perfTimed.time = (union ktime) {//保存定时器信息
.tv.sec = 0,
.tv.usec = HRTIMER_DEFAULT_PERIOD_US,
};
- hrtimer_init(&g_perfTimed.hrtimer, 1, HRTIMER_MODE_REL);
+ hrtimer_init(&g_perfTimed.hrtimer, 1, HRTIMER_MODE_REL);//第一个参数代表定时器对象,第二个参数为时间源类型,代表的是相对时间,最后一个参数代表定时器模式,这里使用的是相对时间模式
- ret = hrtimer_create(&g_perfTimed.hrtimer, g_perfTimed.time, OsPerfHrtimer);
+ ret = hrtimer_create(&g_perfTimed.hrtimer, g_perfTimed.time, OsPerfHrtimer);//创建定时器
if (ret != LOS_OK) {
return ret;
}
g_perfTimed.pmu = (Pmu) {
- .type = PERF_EVENT_TYPE_TIMED,
- .config = OsPerfTimedConfig,
- .start = OsPerfTimedStart,
- .stop = OsPerfTimedStop,
- .getName = OsPerfGetEventName,
+ .type = PERF_EVENT_TYPE_TIMED,//此性能计数器是定时器类型
+ .config = OsPerfTimedConfig,//性能计数器的事件配置
+ .start = OsPerfTimedStart,//启动
+ .stop = OsPerfTimedStop,//停止
+ .getName = OsPerfGetEventName,//获取事件名称
};
(VOID)memset_s(&g_perfTimed.pmu.events, sizeof(PerfEvent), 0, sizeof(PerfEvent));
+ //执行完之后清零事件结构体,并在下面进行状态码的注册读取
ret = OsPerfPmuRegister(&g_perfTimed.pmu);
- return ret;
+ return ret;//返回值为初始化状态码
}
#ifdef __cplusplus
diff --git a/src/kernel/extended/软件工程代码阅读(初稿)-何佳聪-.docx b/src/kernel/extended/软件工程代码阅读(初稿)-何佳聪-.docx
new file mode 100644
index 0000000000000000000000000000000000000000..4d112b6f661c0c5322db4731bd81bfcdb797786f
GIT binary patch
literal 14017
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