oujiashu_branch #1

Merged
p2gpamesw merged 5 commits from oujiashu_branch into develop 11 months ago

Binary file not shown.

@ -26,6 +26,10 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/*这是一个位图bitmap的实现用于对位图进行设置、清除和获取最高/最低位的操作。
使32UINT32
*/
#include "los_bitmap.h" #include "los_bitmap.h"
#include "los_toolchain.h" #include "los_toolchain.h"
@ -36,7 +40,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#define OS_BITMAP_MASK 0x1FU #define OS_BITMAP_MASK 0x1FU
//LOS_BitmapSet将指定位置的位设置为1
VOID LOS_BitmapSet(UINT32 *bitmap, UINT16 pos) VOID LOS_BitmapSet(UINT32 *bitmap, UINT16 pos)
{ {
if (bitmap == NULL) { if (bitmap == NULL) {
@ -45,7 +49,7 @@ VOID LOS_BitmapSet(UINT32 *bitmap, UINT16 pos)
*bitmap |= 1U << (pos & OS_BITMAP_MASK); *bitmap |= 1U << (pos & OS_BITMAP_MASK);
} }
//LOS_BitmapClr将指定位置的位清除为0
VOID LOS_BitmapClr(UINT32 *bitmap, UINT16 pos) VOID LOS_BitmapClr(UINT32 *bitmap, UINT16 pos)
{ {
if (bitmap == NULL) { if (bitmap == NULL) {
@ -54,7 +58,7 @@ VOID LOS_BitmapClr(UINT32 *bitmap, UINT16 pos)
*bitmap &= ~(1U << (pos & OS_BITMAP_MASK)); *bitmap &= ~(1U << (pos & OS_BITMAP_MASK));
} }
//LOS_HighBitGet获取位图中最高位值为1的位置的索引
UINT16 LOS_HighBitGet(UINT32 bitmap) UINT16 LOS_HighBitGet(UINT32 bitmap)
{ {
if (bitmap == 0) { if (bitmap == 0) {
@ -63,7 +67,7 @@ UINT16 LOS_HighBitGet(UINT32 bitmap)
return (OS_BITMAP_MASK - CLZ(bitmap)); return (OS_BITMAP_MASK - CLZ(bitmap));
} }
//LOS_LowBitGet获取位图中最低位值为1的位置的索引
UINT16 LOS_LowBitGet(UINT32 bitmap) UINT16 LOS_LowBitGet(UINT32 bitmap)
{ {
if (bitmap == 0) { if (bitmap == 0) {

@ -25,7 +25,8 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/*这段代码是关于错误处理的相关功能,包括注册错误处理函数和执行错误处理的函数。
*/
#include "los_err.h" #include "los_err.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -35,8 +36,9 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/* Hook function for error handling. */ /* Hook function for error handling. */
//g_usrErrFunc全局变量用于保存用户注册的错误处理函数
LITE_OS_SEC_BSS LOS_ERRORHANDLE_FUNC 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, LITE_OS_SEC_TEXT_INIT UINT32 LOS_ErrHandle(CHAR *fileName, UINT32 lineNo, UINT32 errorNo,
UINT32 paraLen, VOID *para) UINT32 paraLen, VOID *para)
{ {
@ -46,7 +48,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_ErrHandle(CHAR *fileName, UINT32 lineNo, UINT32
return LOS_OK; return LOS_OK;
} }
//LOS_RegErrHandle用于注册错误处理函数的接口用户可以通过该函数注册自定义的错误处理函数
LITE_OS_SEC_TEXT_INIT VOID LOS_RegErrHandle(LOS_ERRORHANDLE_FUNC func) LITE_OS_SEC_TEXT_INIT VOID LOS_RegErrHandle(LOS_ERRORHANDLE_FUNC func)
{ {
g_usrErrFunc = func; g_usrErrFunc = func;

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/*这段代码是关于事件管理的实现,包括事件的初始化、读取、写入、清除等操作。*/
#include "los_event_pri.h" #include "los_event_pri.h"
#include "los_task_pri.h" #include "los_task_pri.h"
#include "los_spinlock.h" #include "los_spinlock.h"
@ -38,7 +38,7 @@
extern "C" { extern "C" {
#endif #endif
#endif /* __cplusplus */ #endif /* __cplusplus */
//LOS_EventInit()函数用于初始化事件控制块eventCB并将事件ID、事件列表等属性设置为初始值
LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB) LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB)
{ {
UINT32 intSave; UINT32 intSave;
@ -55,7 +55,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB)
LOS_IntRestore(intSave); LOS_IntRestore(intSave);
return LOS_OK; return LOS_OK;
} }
//OsEventParamCheck()函数用于检查参数的有效性包括事件掩码eventMask、模式mode
LITE_OS_SEC_TEXT STATIC UINT32 OsEventParamCheck(const VOID *ptr, UINT32 eventMask, UINT32 mode) LITE_OS_SEC_TEXT STATIC UINT32 OsEventParamCheck(const VOID *ptr, UINT32 eventMask, UINT32 mode)
{ {
if (ptr == NULL) { 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))) { !(mode & (LOS_WAITMODE_OR | LOS_WAITMODE_AND))) {
return LOS_ERRNO_EVENT_FLAGS_INVALID; return LOS_ERRNO_EVENT_FLAGS_INVALID;
} }
//指针非空事件掩码非0事件掩码不包含LOS_ERRTYPE_ERROR标志位模式合法
return LOS_OK; return LOS_OK;
} }
//OsEventPoll()函数用于轮询事件,根据指定的事件掩码和模式判断是否满足条件
LITE_OS_SEC_TEXT STATIC UINT32 OsEventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode) LITE_OS_SEC_TEXT STATIC UINT32 OsEventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode)
{ {
UINT32 ret = 0; UINT32 ret = 0;
LOS_ASSERT(ArchIntLocked()); LOS_ASSERT(ArchIntLocked());
LOS_ASSERT(LOS_SpinHeld(&g_taskSpin)); LOS_ASSERT(LOS_SpinHeld(&g_taskSpin));
if (mode & LOS_WAITMODE_OR) { if (mode & LOS_WAITMODE_OR) {
if ((*eventId & eventMask) != 0) { if ((*eventId & eventMask) != 0) {
ret = *eventId & eventMask; ret = *eventId & eventMask;
@ -101,7 +102,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventPoll(UINT32 *eventId, UINT32 eventMask, UI
return ret; return ret;
} }
//OsEventReadCheck()函数用于检查事件读取操作的参数有效性包括事件控制块eventCB、事件掩码eventMask、模式mode
LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadCheck(const PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode) LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadCheck(const PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode)
{ {
UINT32 ret; UINT32 ret;
@ -122,7 +123,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadCheck(const PEVENT_CB_S eventCB, UINT3
} }
return LOS_OK; return LOS_OK;
} }
//OsEventReadImp()函数是事件读取的实现,根据指定的事件掩码和模式进行轮询,并根据超时时间和是否只读取一次进行相应的操作
LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadImp(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadImp(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode,
UINT32 timeout, BOOL once, UINT32 *intSave) 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; return ret;
} }
//OsEventRead()函数是对外提供的事件读取接口调用OsEventReadCheck()和OsEventReadImp()实现事件的读取操作
LITE_OS_SEC_TEXT STATIC UINT32 OsEventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, LITE_OS_SEC_TEXT STATIC UINT32 OsEventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode,
UINT32 timeout, BOOL once) UINT32 timeout, BOOL once)
{ {
@ -184,7 +185,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventRead(PEVENT_CB_S eventCB, UINT32 eventMask
SCHEDULER_UNLOCK(intSave); SCHEDULER_UNLOCK(intSave);
return ret; return ret;
} }
//OsEventWrite()函数用于向事件控制块中写入指定的事件
LITE_OS_SEC_TEXT STATIC UINT32 OsEventWrite(PEVENT_CB_S eventCB, UINT32 events, BOOL once) LITE_OS_SEC_TEXT STATIC UINT32 OsEventWrite(PEVENT_CB_S eventCB, UINT32 events, BOOL once)
{ {
LosTaskCB *resumedTask = NULL; LosTaskCB *resumedTask = NULL;
@ -230,7 +231,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventWrite(PEVENT_CB_S eventCB, UINT32 events,
} }
return LOS_OK; return LOS_OK;
} }
//LOS_EventPoll()函数是对外提供的事件轮询接口调用OsEventParamCheck()和OsEventPoll()实现事件的轮询操作
LITE_OS_SEC_TEXT UINT32 LOS_EventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode) LITE_OS_SEC_TEXT UINT32 LOS_EventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode)
{ {
UINT32 ret; UINT32 ret;
@ -246,17 +247,17 @@ LITE_OS_SEC_TEXT UINT32 LOS_EventPoll(UINT32 *eventId, UINT32 eventMask, UINT32
SCHEDULER_UNLOCK(intSave); SCHEDULER_UNLOCK(intSave);
return ret; return ret;
} }
//LOS_EventRead()函数是对外提供的事件读取接口调用OsEventRead()实现事件的读取操作
LITE_OS_SEC_TEXT UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout) LITE_OS_SEC_TEXT UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout)
{ {
return OsEventRead(eventCB, eventMask, mode, timeout, FALSE); return OsEventRead(eventCB, eventMask, mode, timeout, FALSE);
} }
//LOS_EventWrite()函数是对外提供的事件写入接口调用OsEventWrite()实现事件的写入操作
LITE_OS_SEC_TEXT UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events) LITE_OS_SEC_TEXT UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events)
{ {
return OsEventWrite(eventCB, events, FALSE); return OsEventWrite(eventCB, events, FALSE);
} }
//LOS_EventDestroy()函数用于销毁事件控制块将事件ID设置为0
LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB) LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB)
{ {
UINT32 intSave; UINT32 intSave;
@ -279,7 +280,7 @@ OUT:
LOS_TRACE(EVENT_DELETE, (UINTPTR)eventCB, ret); LOS_TRACE(EVENT_DELETE, (UINTPTR)eventCB, ret);
return ret; return ret;
} }
//LOS_EventClear()函数用于清除指定的事件
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events) LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events)
{ {
UINT32 intSave; UINT32 intSave;
@ -296,18 +297,19 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events)
return LOS_OK; return LOS_OK;
} }
//OsEventWriteOnce()函数是事件写入的实现与OsEventWrite()类似,但只写入一次
LITE_OS_SEC_TEXT_MINOR UINT32 OsEventWriteOnce(PEVENT_CB_S eventCB, UINT32 events) LITE_OS_SEC_TEXT_MINOR UINT32 OsEventWriteOnce(PEVENT_CB_S eventCB, UINT32 events)
{ {
return OsEventWrite(eventCB, events, TRUE); return OsEventWrite(eventCB, events, TRUE);
} }
#ifdef LOSCFG_COMPAT_POSIX #ifdef LOSCFG_COMPAT_POSIX
//OsEventReadOnce()函数是事件读取的实现与OsEventRead()类似,但只读取一次
LITE_OS_SEC_TEXT_MINOR UINT32 OsEventReadOnce(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout) LITE_OS_SEC_TEXT_MINOR UINT32 OsEventReadOnce(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout)
{ {
return OsEventRead(eventCB, eventMask, mode, timeout, TRUE); return OsEventRead(eventCB, eventMask, mode, timeout, TRUE);
} }
// /OsEventReadWithCond()函数用于根据条件读取事件,只有当条件满足时才进行事件读取操作
LITE_OS_SEC_TEXT UINT32 OsEventReadWithCond(const EventCond *cond, PEVENT_CB_S eventCB, LITE_OS_SEC_TEXT UINT32 OsEventReadWithCond(const EventCond *cond, PEVENT_CB_S eventCB,
UINT32 eventMask, UINT32 mode, UINT32 timeout) UINT32 eventMask, UINT32 mode, UINT32 timeout)
{ {

@ -25,7 +25,8 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/*这是关于LiteOS中异常处理的代码其中包括记录异常信息、异常信息保存和读取等功能。
*/
#include "los_exc.h" #include "los_exc.h"
#include "los_printf_pri.h" #include "los_printf_pri.h"
#include "los_task_pri.h" #include "los_task_pri.h"
@ -48,7 +49,7 @@
extern "C" { extern "C" {
#endif #endif
#endif /* __cplusplus */ #endif /* __cplusplus */
//ExcInfoDumpFormat的结构体类型包含了用于存储异常信息的缓冲区指针、偏移量、长度和存储地址等信息
#ifdef LOSCFG_SHELL_EXCINFO_DUMP #ifdef LOSCFG_SHELL_EXCINFO_DUMP
typedef struct { typedef struct {
CHAR *buf; /* pointer to the buffer for storing the exception information */ 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 */ UINT32 len; /* the size of storing the exception information */
UINTPTR dumpAddr; /* the address of storing the exception information */ UINTPTR dumpAddr; /* the address of storing the exception information */
} ExcInfoDumpFormat; } ExcInfoDumpFormat;
//全局变量g_excInfoPool用于存储异常信息的缓冲区和相关的信息
STATIC ExcInfoDumpFormat g_excInfoPool = {0}; STATIC ExcInfoDumpFormat g_excInfoPool = {0};
/* the hook of read-writing exception information */ /* the hook of read-writing exception information */
STATIC __attribute__((section(".data"))) LogReadWriteFunc g_dumpHook = NULL; STATIC __attribute__((section(".data"))) LogReadWriteFunc g_dumpHook = NULL;
//LOS_ExcInfoRegHook注册异常信息读写钩子函数用于设置异常信息的存储地址、长度以及缓冲区等信息
//"钩子函数"是指在特定事件发生时会被调用的函数
//通过使用钩子函数,可以在异常发生时灵活地执行特定的操作,例如记录异常信息、进行特定的处理或通知其他模块进行相应的操作
VOID LOS_ExcInfoRegHook(UINTPTR startAddr, UINT32 len, CHAR *buf, LogReadWriteFunc hook) VOID LOS_ExcInfoRegHook(UINTPTR startAddr, UINT32 len, CHAR *buf, LogReadWriteFunc hook)
{ {
if ((hook == NULL) || (buf == NULL)) { if ((hook == NULL) || (buf == NULL)) {
@ -78,57 +81,57 @@ VOID LOS_ExcInfoRegHook(UINTPTR startAddr, UINT32 len, CHAR *buf, LogReadWriteFu
g_excInfoPool.buf = buf; g_excInfoPool.buf = buf;
g_dumpHook = hook; g_dumpHook = hook;
} }
//OsSetExcInfoRW设置异常信息读写钩子函数
VOID OsSetExcInfoRW(LogReadWriteFunc func) VOID OsSetExcInfoRW(LogReadWriteFunc func)
{ {
g_dumpHook = func; g_dumpHook = func;
} }
//OsGetExcInfoRW获取异常信息读写钩子函数
LogReadWriteFunc OsGetExcInfoRW(VOID) LogReadWriteFunc OsGetExcInfoRW(VOID)
{ {
return g_dumpHook; return g_dumpHook;
} }
//OsSetExcInfoBuf设置异常信息的缓冲区
VOID OsSetExcInfoBuf(CHAR *buf) VOID OsSetExcInfoBuf(CHAR *buf)
{ {
g_excInfoPool.buf = buf; g_excInfoPool.buf = buf;
} }
//OsGetExcInfoBuf获取异常信息的缓冲区
CHAR *OsGetExcInfoBuf(VOID) CHAR *OsGetExcInfoBuf(VOID)
{ {
return g_excInfoPool.buf; return g_excInfoPool.buf;
} }
//OsSetExcInfoOffset设置异常信息的偏移量
VOID OsSetExcInfoOffset(UINT32 Offset) VOID OsSetExcInfoOffset(UINT32 Offset)
{ {
g_excInfoPool.offset = Offset; g_excInfoPool.offset = Offset;
} }
//OsGetExcInfoOffset获取异常信息的偏移量
UINT32 OsGetExcInfoOffset(VOID) UINT32 OsGetExcInfoOffset(VOID)
{ {
return g_excInfoPool.offset; return g_excInfoPool.offset;
} }
//OsSetExcInfoDumpAddr设置异常信息的存储地址
VOID OsSetExcInfoDumpAddr(UINTPTR addr) VOID OsSetExcInfoDumpAddr(UINTPTR addr)
{ {
g_excInfoPool.dumpAddr = addr; g_excInfoPool.dumpAddr = addr;
} }
//OsGetExcInfoDumpAddr获取异常信息的存储地址
UINTPTR OsGetExcInfoDumpAddr(VOID) UINTPTR OsGetExcInfoDumpAddr(VOID)
{ {
return g_excInfoPool.dumpAddr; return g_excInfoPool.dumpAddr;
} }
//OsSetExcInfoLen设置异常信息的长度
VOID OsSetExcInfoLen(UINT32 len) VOID OsSetExcInfoLen(UINT32 len)
{ {
g_excInfoPool.len = len; g_excInfoPool.len = len;
} }
//OsGetExcInfoLen获取异常信息的长度
UINT32 OsGetExcInfoLen(VOID) UINT32 OsGetExcInfoLen(VOID)
{ {
return g_excInfoPool.len; return g_excInfoPool.len;
} }
//WriteExcBufVa将格式化的字符串写入异常信息缓冲区
VOID WriteExcBufVa(const CHAR *format, va_list arglist) VOID WriteExcBufVa(const CHAR *format, va_list arglist)
{ {
errno_t ret; errno_t ret;
@ -143,7 +146,7 @@ VOID WriteExcBufVa(const CHAR *format, va_list arglist)
g_excInfoPool.offset += ret; g_excInfoPool.offset += ret;
} }
} }
//WriteExcInfoToBuf将格式化的字符串写入异常信息缓冲区
VOID WriteExcInfoToBuf(const CHAR *format, ...) VOID WriteExcInfoToBuf(const CHAR *format, ...)
{ {
va_list arglist; va_list arglist;
@ -152,7 +155,7 @@ VOID WriteExcInfoToBuf(const CHAR *format, ...)
WriteExcBufVa(format, arglist); WriteExcBufVa(format, arglist);
va_end(arglist); va_end(arglist);
} }
//OsRecordExcInfoTime记录异常信息的时间
VOID OsRecordExcInfoTime(VOID) VOID OsRecordExcInfoTime(VOID)
{ {
#define NOW_TIME_LENGTH 24 #define NOW_TIME_LENGTH 24
@ -169,7 +172,7 @@ VOID OsRecordExcInfoTime(VOID)
#undef NOW_TIME_LENGTH #undef NOW_TIME_LENGTH
PrintExcInfo("%s \n", nowTime); PrintExcInfo("%s \n", nowTime);
} }
//OsShellCmdReadExcInfo读取并打印异常信息的Shell命令
#ifdef LOSCFG_SHELL #ifdef LOSCFG_SHELL
INT32 OsShellCmdReadExcInfo(INT32 argc, const CHAR **argv) INT32 OsShellCmdReadExcInfo(INT32 argc, const CHAR **argv)
{ {
@ -200,6 +203,9 @@ SHELLCMD_ENTRY(readExcInfo_shellcmd, CMD_TYPE_EX, "excInfo", 0, (CmdCallBackFunc
#endif #endif
#ifdef LOSCFG_EXC_INTERACTION #ifdef LOSCFG_EXC_INTERACTION
//OsCheckExcInteractionTask检查任务是否为异常交互任务
//异常交互任务通常指的是用于处理异常情况的特殊任务或线程
//当系统发生严重的错误或异常时,需要立即采取相应的措施来处理异常情况,这就需要使用异常交互任务来处理
UINT32 OsCheckExcInteractionTask(const TSK_INIT_PARAM_S *initParam) UINT32 OsCheckExcInteractionTask(const TSK_INIT_PARAM_S *initParam)
{ {
if ((initParam->pfnTaskEntry == (TSK_ENTRY_FUNC)ShellTask) || if ((initParam->pfnTaskEntry == (TSK_ENTRY_FUNC)ShellTask) ||
@ -209,7 +215,7 @@ UINT32 OsCheckExcInteractionTask(const TSK_INIT_PARAM_S *initParam)
} }
return LOS_NOK; return LOS_NOK;
} }
//OsKeepExcInteractionTask保留异常交互任务删除其他任务
VOID OsKeepExcInteractionTask(VOID) VOID OsKeepExcInteractionTask(VOID)
{ {
LosTaskCB *taskCB = NULL; LosTaskCB *taskCB = NULL;
@ -243,7 +249,7 @@ VOID OsKeepExcInteractionTask(VOID)
} }
#endif #endif
//LOS_Panic打印异常信息并停止CPU执行
VOID LOS_Panic(const CHAR *fmt, ...) VOID LOS_Panic(const CHAR *fmt, ...)
{ {
va_list ap; va_list ap;
@ -252,7 +258,7 @@ VOID LOS_Panic(const CHAR *fmt, ...)
va_end(ap); va_end(ap);
ArchHaltCpu(); ArchHaltCpu();
} }
//LOS_BackTrace打印当前任务的运行信息和回溯堆栈
VOID LOS_BackTrace(VOID) VOID LOS_BackTrace(VOID)
{ {
#ifdef LOSCFG_BACKTRACE #ifdef LOSCFG_BACKTRACE
@ -262,7 +268,7 @@ VOID LOS_BackTrace(VOID)
ArchBackTrace(); ArchBackTrace();
#endif #endif
} }
//LOS_TaskBackTrace打印指定任务的运行信息和回溯堆栈
VOID LOS_TaskBackTrace(UINT32 taskID) VOID LOS_TaskBackTrace(UINT32 taskID)
{ {
#ifdef LOSCFG_BACKTRACE #ifdef LOSCFG_BACKTRACE
@ -289,6 +295,7 @@ VOID LOS_TaskBackTrace(UINT32 taskID)
#ifdef __GNUC__ #ifdef __GNUC__
/* stack protector */ /* stack protector */
//__stack_chk_fail用于栈保护机制当发现栈被破坏时触发异常处理
VOID __stack_chk_fail(VOID) VOID __stack_chk_fail(VOID)
{ {
/* __builtin_return_address is a builtin function, building in gcc */ /* __builtin_return_address is a builtin function, building in gcc */

@ -25,7 +25,9 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/*
LiteOS使
*/
#include "los_hwi_pri.h" #include "los_hwi_pri.h"
#include "los_hwi.h" #include "los_hwi.h"
#include "los_memory.h" #include "los_memory.h"
@ -61,7 +63,7 @@ const HwiControllerOps *g_hwiOps = NULL;
typedef VOID (*HWI_PROC_FUNC0)(VOID); typedef VOID (*HWI_PROC_FUNC0)(VOID);
typedef VOID (*HWI_PROC_FUNC2)(INT32, VOID *); typedef VOID (*HWI_PROC_FUNC2)(INT32, VOID *);
//OsIrqNestingActive用于在处理中断期间激活中断嵌套计数器避免在处理时钟中断时进行抢占
STATIC INLINE VOID OsIrqNestingActive(UINT32 hwiNum) STATIC INLINE VOID OsIrqNestingActive(UINT32 hwiNum)
{ {
#ifdef LOSCFG_ARCH_INTERRUPT_PREEMPTION #ifdef LOSCFG_ARCH_INTERRUPT_PREEMPTION
@ -71,7 +73,7 @@ STATIC INLINE VOID OsIrqNestingActive(UINT32 hwiNum)
} }
#endif #endif
} }
//OsIrqNestingInactive用于在处理中断结束后禁用中断嵌套计数器
STATIC INLINE VOID OsIrqNestingInactive(UINT32 hwiNum) STATIC INLINE VOID OsIrqNestingInactive(UINT32 hwiNum)
{ {
#ifdef LOSCFG_ARCH_INTERRUPT_PREEMPTION #ifdef LOSCFG_ARCH_INTERRUPT_PREEMPTION
@ -80,17 +82,17 @@ STATIC INLINE VOID OsIrqNestingInactive(UINT32 hwiNum)
} }
#endif #endif
} }
//OsIrqNestingCntGet获取当前CPU的中断嵌套计数值
size_t OsIrqNestingCntGet(VOID) size_t OsIrqNestingCntGet(VOID)
{ {
return g_intCount[ArchCurrCpuid()]; return g_intCount[ArchCurrCpuid()];
} }
//OsIrqNestingCntSet设置当前CPU的中断嵌套计数值
VOID OsIrqNestingCntSet(size_t val) VOID OsIrqNestingCntSet(size_t val)
{ {
g_intCount[ArchCurrCpuid()] = val; g_intCount[ArchCurrCpuid()] = val;
} }
//InterruptHandle处理中断的实际函数根据中断号调用对应的中断处理函数
STATIC INLINE VOID InterruptHandle(HwiHandleInfo *hwiForm) STATIC INLINE VOID InterruptHandle(HwiHandleInfo *hwiForm)
{ {
hwiForm->respCount++; hwiForm->respCount++;
@ -114,7 +116,7 @@ STATIC INLINE VOID InterruptHandle(HwiHandleInfo *hwiForm)
} }
#endif #endif
} }
//OsIntHandle中断处理入口函数负责处理中断前的一些准备工作如调用中断处理前的钩子函数等
VOID OsIntHandle(UINT32 hwiNum, HwiHandleInfo *hwiForm) VOID OsIntHandle(UINT32 hwiNum, HwiHandleInfo *hwiForm)
{ {
size_t *intCnt = NULL; size_t *intCnt = NULL;
@ -148,7 +150,7 @@ VOID OsIntHandle(UINT32 hwiNum, HwiHandleInfo *hwiForm)
OsCpupIrqEnd(hwiNum); OsCpupIrqEnd(hwiNum);
#endif #endif
} }
//OsIntEntry中断向量入口函数根据中断号调用对应的中断处理函数
VOID OsIntEntry(VOID) VOID OsIntEntry(VOID)
{ {
if ((g_hwiOps != NULL) && (g_hwiOps->handleIrq != NULL)) { if ((g_hwiOps != NULL) && (g_hwiOps->handleIrq != NULL)) {
@ -156,7 +158,7 @@ VOID OsIntEntry(VOID)
} }
return; return;
} }
//OsHwiCpIrqParam根据传入的中断参数结构体分配内存并将参数信息拷贝到新分配的内存中
STATIC HWI_ARG_T OsHwiCpIrqParam(const HWI_IRQ_PARAM_S *irqParam) STATIC HWI_ARG_T OsHwiCpIrqParam(const HWI_IRQ_PARAM_S *irqParam)
{ {
HWI_IRQ_PARAM_S *paramByAlloc = NULL; 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; return (HWI_ARG_T)paramByAlloc;
} }
#ifndef LOSCFG_SHARED_IRQ #ifndef LOSCFG_SHARED_IRQ
//OsHwiDel删除指定的中断处理函数
STATIC UINT32 OsHwiDel(HwiHandleInfo *hwiForm, const HWI_IRQ_PARAM_S *irqParam, UINT32 irqId) STATIC UINT32 OsHwiDel(HwiHandleInfo *hwiForm, const HWI_IRQ_PARAM_S *irqParam, UINT32 irqId)
{ {
UINT32 intSave; UINT32 intSave;
@ -190,7 +193,7 @@ STATIC UINT32 OsHwiDel(HwiHandleInfo *hwiForm, const HWI_IRQ_PARAM_S *irqParam,
HWI_UNLOCK(intSave); HWI_UNLOCK(intSave);
return LOS_OK; return LOS_OK;
} }
//OsHwiCreate创建中断处理函数并将其添加到中断处理链表中
STATIC UINT32 OsHwiCreate(HwiHandleInfo *hwiForm, HWI_MODE_T hwiMode, HWI_PROC_FUNC hwiHandler, STATIC UINT32 OsHwiCreate(HwiHandleInfo *hwiForm, HWI_MODE_T hwiMode, HWI_PROC_FUNC hwiHandler,
const HWI_IRQ_PARAM_S *irqParam) 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; return LOS_OK;
} }
#else /* LOSCFG_SHARED_IRQ */ #else /* LOSCFG_SHARED_IRQ */
//函数OsFreeHwiNode:用于释放中断处理函数节点,并在需要时禁止该中断
STATIC INLINE UINT32 OsFreeHwiNode(HwiHandleInfo *head, HwiHandleInfo *hwiForm, UINT32 irqId) STATIC INLINE UINT32 OsFreeHwiNode(HwiHandleInfo *head, HwiHandleInfo *hwiForm, UINT32 irqId)
{ {
UINT32 ret = LOS_OK; UINT32 ret = LOS_OK;
@ -240,7 +244,8 @@ STATIC INLINE UINT32 OsFreeHwiNode(HwiHandleInfo *head, HwiHandleInfo *hwiForm,
return ret; return ret;
} }
//OsHwiDel:用于删除硬件中断处理函数,它首先判断中断是否是共享中断
//如果不是,则直接释放该中断的处理函数节点;如果是共享中断则遍历链表找到对应的设备ID然后释放该中断的处理函数节点
STATIC UINT32 OsHwiDel(HwiHandleInfo *head, const HWI_IRQ_PARAM_S *irqParam, UINT32 irqId) STATIC UINT32 OsHwiDel(HwiHandleInfo *head, const HWI_IRQ_PARAM_S *irqParam, UINT32 irqId)
{ {
HwiHandleInfo *hwiFormPrev = NULL; HwiHandleInfo *hwiFormPrev = NULL;
@ -290,7 +295,8 @@ STATIC UINT32 OsHwiDel(HwiHandleInfo *head, const HWI_IRQ_PARAM_S *irqParam, UIN
HWI_UNLOCK(intSave); HWI_UNLOCK(intSave);
return ret; return ret;
} }
//OsHwiCreate:用于创建硬件中断处理函数它首先判断中断是否是共享中断并检查是否已经存在具有相同设备ID的中断处理函数节点如果存在则返回错误
//然后申请内存并初始化新的中断处理函数节点,将其添加到链表中
STATIC UINT32 OsHwiCreate(HwiHandleInfo *head, HWI_MODE_T hwiMode, HWI_PROC_FUNC hwiHandler, STATIC UINT32 OsHwiCreate(HwiHandleInfo *head, HWI_MODE_T hwiMode, HWI_PROC_FUNC hwiHandler,
const HWI_IRQ_PARAM_S *irqParam) const HWI_IRQ_PARAM_S *irqParam)
{ {
@ -359,7 +365,9 @@ size_t IntActive()
LOS_IntRestore(intSave); LOS_IntRestore(intSave);
return intCount; return intCount;
} }
//LOS_HwiCreate 函数:用于创建硬件中断处理函数
//它会注册一个中断处理函数,并将其与指定的硬件中断号相关联
//可以设置中断的优先级、硬件中断模式和处理函数
LITE_OS_SEC_TEXT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum, LITE_OS_SEC_TEXT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
HWI_PRIOR_T hwiPrio, HWI_PRIOR_T hwiPrio,
HWI_MODE_T hwiMode, HWI_MODE_T hwiMode,
@ -396,7 +404,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
} }
return ret; return ret;
} }
//LOS_HwiDelete 函数:用于删除已经创建的硬件中断处理函数
//通过指定硬件中断号,可以将之前注册的中断处理函数从系统中删除
LITE_OS_SEC_TEXT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S *irqParam) LITE_OS_SEC_TEXT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S *irqParam)
{ {
UINT32 ret; UINT32 ret;
@ -417,7 +426,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S *irqP
return ret; return ret;
} }
//LOS_HwiTrigger 函数:用于手动触发指定的硬件中断
//调用该函数后,会立即触发对应的硬件中断,使得系统执行相应的中断处理函数
LITE_OS_SEC_TEXT UINT32 LOS_HwiTrigger(HWI_HANDLE_T hwiNum) LITE_OS_SEC_TEXT UINT32 LOS_HwiTrigger(HWI_HANDLE_T hwiNum)
{ {
if ((g_hwiOps == NULL) || (g_hwiOps->triggerIrq == NULL)) { 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); return g_hwiOps->triggerIrq(hwiNum);
} }
//LOS_HwiEnable 函数:用于使能指定的硬件中断
//调用该函数后,系统将允许对应的硬件中断产生,并执行相应的中断处理函数
LITE_OS_SEC_TEXT UINT32 LOS_HwiEnable(HWI_HANDLE_T hwiNum) LITE_OS_SEC_TEXT UINT32 LOS_HwiEnable(HWI_HANDLE_T hwiNum)
{ {
if ((g_hwiOps == NULL) || (g_hwiOps->enableIrq == NULL)) { 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); return g_hwiOps->enableIrq(hwiNum);
} }
//LOS_HwiDisable 函数:用于禁止指定的硬件中断
//调用该函数后,系统将阻止对应的硬件中断产生,屏蔽其影响
LITE_OS_SEC_TEXT UINT32 LOS_HwiDisable(HWI_HANDLE_T hwiNum) LITE_OS_SEC_TEXT UINT32 LOS_HwiDisable(HWI_HANDLE_T hwiNum)
{ {
if ((g_hwiOps == NULL) || (g_hwiOps->disableIrq == NULL)) { 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); return g_hwiOps->disableIrq(hwiNum);
} }
//LOS_HwiClear 函数:用于清除指定的硬件中断
//在某些平台上,硬件中断发生后可能需要手动清除中断标志位,以便正确处理后续的中断
LITE_OS_SEC_TEXT UINT32 LOS_HwiClear(HWI_HANDLE_T hwiNum) LITE_OS_SEC_TEXT UINT32 LOS_HwiClear(HWI_HANDLE_T hwiNum)
{ {
if ((g_hwiOps == NULL) || (g_hwiOps->clearIrq == NULL)) { 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); return g_hwiOps->clearIrq(hwiNum);
} }
//LOS_HwiSetPriority 函数:用于设置硬件中断的优先级
//通过指定硬件中断号和优先级,可以调整硬件中断的触发顺序
LITE_OS_SEC_TEXT UINT32 LOS_HwiSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority) LITE_OS_SEC_TEXT UINT32 LOS_HwiSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority)
{ {
if ((g_hwiOps == NULL) || (g_hwiOps->setIrqPriority == NULL)) { 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); return g_hwiOps->setIrqPriority(hwiNum, priority);
} }
#ifdef LOSCFG_KERNEL_SMP #ifdef LOSCFG_KERNEL_SMP
//LOS_HwiSetAffinity函数用于设置硬件中断的处理CPU亲和性
//它首先检查硬件中断操作函数指针是否为空然后调用具体的操作函数来设置中断的处理CPU亲和性
LITE_OS_SEC_TEXT UINT32 LOS_HwiSetAffinity(HWI_HANDLE_T hwiNum, UINT32 cpuMask) LITE_OS_SEC_TEXT UINT32 LOS_HwiSetAffinity(HWI_HANDLE_T hwiNum, UINT32 cpuMask)
{ {
if ((g_hwiOps == NULL) || (g_hwiOps->setIrqCpuAffinity == NULL)) { 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); return g_hwiOps->setIrqCpuAffinity(hwiNum, cpuMask);
} }
//LOS_HwiSendIpi函数用于发送硬件中断处理请求给指定的CPU
//它首先检查硬件中断操作函数指针是否为空,然后调用具体的操作函数来发送中断处理请求
LITE_OS_SEC_TEXT UINT32 LOS_HwiSendIpi(HWI_HANDLE_T hwiNum, UINT32 cpuMask) LITE_OS_SEC_TEXT UINT32 LOS_HwiSendIpi(HWI_HANDLE_T hwiNum, UINT32 cpuMask)
{ {
if ((g_hwiOps == NULL) || (g_hwiOps->sendIpi == NULL)) { 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 #endif
#ifdef LOSCFG_KERNEL_LOWPOWER #ifdef LOSCFG_KERNEL_LOWPOWER
//LOS_IntWakeupHookReg函数用于注册中断唤醒回调函数
//它将传入的回调函数赋值给全局变量g_intWakeupHook以便在中断唤醒时调用该回调函数
LITE_OS_SEC_TEXT_MINOR VOID LOS_IntWakeupHookReg(WAKEUPFROMINTHOOK hook) LITE_OS_SEC_TEXT_MINOR VOID LOS_IntWakeupHookReg(WAKEUPFROMINTHOOK hook)
{ {
g_intWakeupHook = hook; g_intWakeupHook = hook;
@ -497,6 +516,8 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_IntWakeupHookReg(WAKEUPFROMINTHOOK hook)
#endif #endif
/* Initialization of the hardware interrupt */ /* Initialization of the hardware interrupt */
//OsHwiInit函数用于初始化硬件中断
//它会调用具体的平台相关函数来进行硬件中断的初始化操作
LITE_OS_SEC_TEXT_INIT VOID OsHwiInit(VOID) LITE_OS_SEC_TEXT_INIT VOID OsHwiInit(VOID)
{ {
ArchIrqInit(); ArchIrqInit();

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/*这段代码是关于锁依赖检查的实现。包含了一些头文件和函数的定义,用于在多核系统中检测锁的使用情况*/
#include "los_base.h" #include "los_base.h"
#include "los_spinlock.h" #include "los_spinlock.h"
#include "los_task_pri.h" #include "los_task_pri.h"
@ -47,6 +47,8 @@ extern "C" {
STATIC Atomic g_lockdepAvailable = 1; STATIC Atomic g_lockdepAvailable = 1;
/* atomic insurance for lockdep check */ /* atomic insurance for lockdep check */
//OsLockDepRequire该函数用于获取锁依赖检查的原子操作确保在进行锁依赖检查时不会被中断
//原子操作是指在计算机科学中,不会被中断的操作
STATIC INLINE VOID OsLockDepRequire(UINT32 *intSave) STATIC INLINE VOID OsLockDepRequire(UINT32 *intSave)
{ {
*intSave = LOS_IntLock(); *intSave = LOS_IntLock();
@ -54,13 +56,13 @@ STATIC INLINE VOID OsLockDepRequire(UINT32 *intSave)
/* busy waiting */ /* busy waiting */
} }
} }
//OsLockDepRelease释放锁依赖检查的原子操作用于在完成锁依赖检查后恢复正常的中断状态
STATIC INLINE VOID OsLockDepRelease(UINT32 intSave) STATIC INLINE VOID OsLockDepRelease(UINT32 intSave)
{ {
LOS_AtomicSet(&g_lockdepAvailable, 1); LOS_AtomicSet(&g_lockdepAvailable, 1);
LOS_IntRestore(intSave); LOS_IntRestore(intSave);
} }
//OsLockDepGetCycles获取当前 CPU 的周期计数器的值,用于记录锁请求和释放时的时间戳
STATIC INLINE UINT64 OsLockDepGetCycles(VOID) STATIC INLINE UINT64 OsLockDepGetCycles(VOID)
{ {
UINT32 high, low; UINT32 high, low;
@ -69,7 +71,7 @@ STATIC INLINE UINT64 OsLockDepGetCycles(VOID)
/* combine cycleHi and cycleLo into 8 bytes cycles */ /* combine cycleHi and cycleLo into 8 bytes cycles */
return (((UINT64)high << 32) + low); return (((UINT64)high << 32) + low);
} }
//OsLockDepErrorStringGet根据错误类型返回对应的错误字符串用于打印错误信息
STATIC INLINE CHAR *OsLockDepErrorStringGet(enum LockDepErrType type) STATIC INLINE CHAR *OsLockDepErrorStringGet(enum LockDepErrType type)
{ {
CHAR *errorString = NULL; CHAR *errorString = NULL;
@ -94,7 +96,7 @@ STATIC INLINE CHAR *OsLockDepErrorStringGet(enum LockDepErrType type)
return errorString; return errorString;
} }
//OsLockDepPanic当发生严重错误时触发系统的崩溃通常在检测到死锁等无法修复的情况下调用
WEAK VOID OsLockDepPanic(enum LockDepErrType errType) WEAK VOID OsLockDepPanic(enum LockDepErrType errType)
{ {
/* halt here */ /* halt here */
@ -103,7 +105,7 @@ WEAK VOID OsLockDepPanic(enum LockDepErrType errType)
OsBackTrace(); OsBackTrace();
while (1) {} while (1) {}
} }
//OsLockDepDumpLock输出锁依赖检查失败时的调试信息包括任务名、任务 ID、CPU 号等,并最终触发崩溃
STATIC VOID OsLockDepDumpLock(const LosTaskCB *task, const SPIN_LOCK_S *lock, STATIC VOID OsLockDepDumpLock(const LosTaskCB *task, const SPIN_LOCK_S *lock,
const VOID *requestAddr, enum LockDepErrType errType) const VOID *requestAddr, enum LockDepErrType errType)
{ {
@ -143,7 +145,7 @@ STATIC VOID OsLockDepDumpLock(const LosTaskCB *task, const SPIN_LOCK_S *lock,
OsLockDepPanic(errType); OsLockDepPanic(errType);
} }
//OsLockDepCheckDependancy检查当前任务与锁的所有者之间是否存在依赖关系以避免死锁
STATIC BOOL OsLockDepCheckDependancy(const LosTaskCB *current, const LosTaskCB *lockOwner) STATIC BOOL OsLockDepCheckDependancy(const LosTaskCB *current, const LosTaskCB *lockOwner)
{ {
BOOL checkResult = TRUE; BOOL checkResult = TRUE;
@ -164,7 +166,7 @@ STATIC BOOL OsLockDepCheckDependancy(const LosTaskCB *current, const LosTaskCB *
return checkResult; return checkResult;
} }
//OsLockDepCheckIn在请求锁时进行依赖检查记录锁的请求地址和等待时间如检查失败则触发崩溃
VOID OsLockDepCheckIn(const SPIN_LOCK_S *lock) VOID OsLockDepCheckIn(const SPIN_LOCK_S *lock)
{ {
UINT32 intSave; UINT32 intSave;
@ -217,7 +219,7 @@ OUT:
OsLockDepRelease(intSave); OsLockDepRelease(intSave);
} }
//OsLockDepRecord记录成功获取锁的时间戳和持有者信息并更新锁的所有者和 CPU 号等信息
VOID OsLockDepRecord(SPIN_LOCK_S *lock) VOID OsLockDepRecord(SPIN_LOCK_S *lock)
{ {
UINT32 intSave; UINT32 intSave;
@ -250,7 +252,7 @@ VOID OsLockDepRecord(SPIN_LOCK_S *lock)
OsLockDepRelease(intSave); OsLockDepRelease(intSave);
} }
//OsLockDepCheckOut在释放锁时进行依赖检查记录持有时间并清除相关信息如检查失败则触发崩溃
VOID OsLockDepCheckOut(SPIN_LOCK_S *lock) VOID OsLockDepCheckOut(SPIN_LOCK_S *lock)
{ {
UINT32 intSave; UINT32 intSave;
@ -302,7 +304,8 @@ VOID OsLockDepCheckOut(SPIN_LOCK_S *lock)
OUT: OUT:
OsLockDepRelease(intSave); OsLockDepRelease(intSave);
} }
//OsLockdepClearSpinlocks清除当前任务持有的所有自旋锁通常在系统处于异常状态下调用以确保解锁
//自旋锁是一种用于多线程同步的机制。在使用自旋锁时,线程会反复检查锁是否被释放,如果锁已经被占用,线程就会一直循环等待,直到锁被释放为止
VOID OsLockdepClearSpinlocks(VOID) VOID OsLockdepClearSpinlocks(VOID)
{ {
LosTaskCB *task = OsCurrTaskGet(); LosTaskCB *task = OsCurrTaskGet();

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
//操作系统的基础函数
#include "los_task_pri.h" #include "los_task_pri.h"
#include "los_misc_pri.h" #include "los_misc_pri.h"
#include "los_memory_pri.h" #include "los_memory_pri.h"
@ -48,23 +48,23 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#ifdef LOSCFG_LIB_CONFIGURABLE #ifdef LOSCFG_LIB_CONFIGURABLE
LITE_OS_SEC_BSS UINT32 g_osSysClock; LITE_OS_SEC_BSS UINT32 g_osSysClock; //操作系统的系统时钟频率
LITE_OS_SEC_BSS UINT32 g_semLimit; LITE_OS_SEC_BSS UINT32 g_semLimit; //信号量的最大数量限制
LITE_OS_SEC_BSS UINT32 g_muxLimit; LITE_OS_SEC_BSS UINT32 g_muxLimit; //互斥锁的最大数量限制
LITE_OS_SEC_BSS UINT32 g_queueLimit; LITE_OS_SEC_BSS UINT32 g_queueLimit; //队列最大数量限制
LITE_OS_SEC_BSS UINT32 g_swtmrLimit; LITE_OS_SEC_BSS UINT32 g_swtmrLimit; //软件定时器的最大数量限制
LITE_OS_SEC_BSS UINT32 g_taskLimit; LITE_OS_SEC_BSS UINT32 g_taskLimit; //任务的最大数量限制
LITE_OS_SEC_BSS UINT32 g_minusOneTickPerSecond; LITE_OS_SEC_BSS UINT32 g_minusOneTickPerSecond; //每秒减去的滴答数,用于时间戳计算
LITE_OS_SEC_BSS UINT32 g_taskMinStkSize; LITE_OS_SEC_BSS UINT32 g_taskMinStkSize;//任务的最小堆栈大小
LITE_OS_SEC_BSS UINT32 g_taskIdleStkSize; LITE_OS_SEC_BSS UINT32 g_taskIdleStkSize; //空闲任务的堆栈大小
LITE_OS_SEC_BSS UINT32 g_taskSwtmrStkSize; LITE_OS_SEC_BSS UINT32 g_taskSwtmrStkSize; //软件定时器任务的堆栈大小
LITE_OS_SEC_BSS UINT32 g_taskDfltStkSize; LITE_OS_SEC_BSS UINT32 g_taskDfltStkSize; //默认任务的堆栈大小
LITE_OS_SEC_BSS UINT32 g_timeSliceTimeOut; LITE_OS_SEC_BSS UINT32 g_timeSliceTimeOut; //时间片的超时时间
LITE_OS_SEC_DATA BOOL g_nxEnabled = FALSE; LITE_OS_SEC_DATA BOOL g_nxEnabled = FALSE; //是否启用了内存保护机制
LITE_OS_SEC_BSS UINTPTR g_dlNxHeapBase; LITE_OS_SEC_BSS UINTPTR g_dlNxHeapBase; //动态加载库的内存堆起始地址
LITE_OS_SEC_BSS UINT32 g_dlNxHeapSize; LITE_OS_SEC_BSS UINT32 g_dlNxHeapSize; //动态加载库的内存堆大小
#endif #endif
#ifdef LOSCFG_KERNEL_TRACE #ifdef LOSCFG_KERNEL_TRACE
@ -77,11 +77,12 @@ LMS_INIT_HOOK g_lmsMemInitHook = NULL;
LMS_FUNC_HOOK g_lmsMallocHook = NULL; LMS_FUNC_HOOK g_lmsMallocHook = NULL;
LMS_FUNC_HOOK g_lmsFreeHook = NULL; LMS_FUNC_HOOK g_lmsFreeHook = NULL;
#endif #endif
//LOS_Align用于将给定的地址按指定的边界对齐返回对齐后的地址
LITE_OS_SEC_TEXT UINTPTR LOS_Align(UINTPTR addr, UINT32 boundary) LITE_OS_SEC_TEXT UINTPTR LOS_Align(UINTPTR addr, UINT32 boundary)
{ {
return (addr + boundary - 1) & ~((UINTPTR)(boundary - 1)); return (addr + boundary - 1) & ~((UINTPTR)(boundary - 1));
} }
//OsDumpMemByte用于以字节为单位打印内存中的数据
LITE_OS_SEC_TEXT_MINOR VOID LOS_Msleep(UINT32 msecs) LITE_OS_SEC_TEXT_MINOR VOID LOS_Msleep(UINT32 msecs)
{ {
UINT32 interval; UINT32 interval;
@ -97,7 +98,7 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_Msleep(UINT32 msecs)
(VOID)LOS_TaskDelay(interval); (VOID)LOS_TaskDelay(interval);
} }
//OsDumpMemByte用于以字节为单位打印内存中的数据
VOID OsDumpMemByte(size_t length, UINTPTR addr) VOID OsDumpMemByte(size_t length, UINTPTR addr)
{ {
size_t dataLen; 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) #if defined(LOSCFG_DEBUG_SEMAPHORE) || defined(LOSCFG_DEBUG_MUTEX) || defined(LOSCFG_DEBUG_QUEUE)
//OsArraySort快速排序
VOID OsArraySort(UINT32 *sortArray, UINT32 start, UINT32 end, VOID OsArraySort(UINT32 *sortArray, UINT32 start, UINT32 end,
const SortParam *sortParam, OsCompareFunc compareFunc) const SortParam *sortParam, OsCompareFunc compareFunc)
{ {

@ -25,7 +25,8 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/*针对多处理器SMP系统的操作系统内核部分的实现
*/
#include "los_mp_pri.h" #include "los_mp_pri.h"
#include "los_task_pri.h" #include "los_task_pri.h"
#include "los_percpu_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_LOCK(state) LOS_SpinLockSave(&g_mpCallSpin, &(state))
#define MP_CALL_UNLOCK(state) LOS_SpinUnlockRestore(&g_mpCallSpin, (state)) #define MP_CALL_UNLOCK(state) LOS_SpinUnlockRestore(&g_mpCallSpin, (state))
#endif #endif
//LOS_MpSchedule多处理器调度函数用于向指定的处理器发送调度中断
VOID LOS_MpSchedule(UINT32 target) VOID LOS_MpSchedule(UINT32 target)
{ {
UINT32 ret; UINT32 ret;
@ -57,12 +58,12 @@ VOID LOS_MpSchedule(UINT32 target)
} }
return; return;
} }
//OsMpWakeHandler多处理器唤醒处理函数目前为空实现无特定操作
VOID OsMpWakeHandler(VOID) VOID OsMpWakeHandler(VOID)
{ {
/* generic wakeup ipi, do nothing */ /* generic wakeup ipi, do nothing */
} }
//OsMpScheduleHandler多处理器调度处理函数设置调度标志以触发调度器在中断结束时执行调度
VOID OsMpScheduleHandler(VOID) VOID OsMpScheduleHandler(VOID)
{ {
/* /*
@ -71,7 +72,7 @@ VOID OsMpScheduleHandler(VOID)
*/ */
OsPercpuGet()->schedFlag = INT_PEND_RESCH; OsPercpuGet()->schedFlag = INT_PEND_RESCH;
} }
//OsMpHaltHandler多处理器停机处理函数将当前处理器标记为已停机状态并进入死循环
VOID OsMpHaltHandler(VOID) VOID OsMpHaltHandler(VOID)
{ {
(VOID)LOS_IntLock(); (VOID)LOS_IntLock();
@ -79,7 +80,7 @@ VOID OsMpHaltHandler(VOID)
while (1) {} while (1) {}
} }
//OsMpCollectTasks多处理器任务回收函数用于递归检查所有可用任务并删除标记为需要销毁的任务
VOID OsMpCollectTasks(VOID) VOID OsMpCollectTasks(VOID)
{ {
LosTaskCB *taskCB = NULL; LosTaskCB *taskCB = NULL;
@ -109,6 +110,7 @@ VOID OsMpCollectTasks(VOID)
} }
#ifdef LOSCFG_KERNEL_SMP_CALL #ifdef LOSCFG_KERNEL_SMP_CALL
//OsMpFuncCall多处理器函数调用函数用于向指定的处理器发送函数调用请求
VOID OsMpFuncCall(UINT32 target, SMP_FUNC_CALL func, VOID *args) VOID OsMpFuncCall(UINT32 target, SMP_FUNC_CALL func, VOID *args)
{ {
UINT32 index; UINT32 index;
@ -144,7 +146,7 @@ VOID OsMpFuncCall(UINT32 target, SMP_FUNC_CALL func, VOID *args)
} }
return; return;
} }
//OsMpFuncCallHandler多处理器函数调用处理函数从本处理器的函数调用队列中取出并执行函数调用请求
VOID OsMpFuncCallHandler(VOID) VOID OsMpFuncCallHandler(VOID)
{ {
UINT32 intSave; UINT32 intSave;
@ -166,7 +168,7 @@ VOID OsMpFuncCallHandler(VOID)
} }
MP_CALL_UNLOCK(intSave); MP_CALL_UNLOCK(intSave);
} }
//OsMpFuncCallInit多处理器函数调用初始化函数用于初始化每个核心的函数调用队列
VOID OsMpFuncCallInit(VOID) VOID OsMpFuncCallInit(VOID)
{ {
UINT32 index; UINT32 index;
@ -176,7 +178,7 @@ VOID OsMpFuncCallInit(VOID)
} }
} }
#endif /* LOSCFG_KERNEL_SMP_CALL */ #endif /* LOSCFG_KERNEL_SMP_CALL */
//OsMpInit多处理器初始化函数包括创建周期性软件定时器和初始化函数调用队列等
UINT32 OsMpInit(VOID) UINT32 OsMpInit(VOID)
{ {
UINT16 swtmrId; UINT16 swtmrId;

@ -25,7 +25,8 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/*代码实现了一个简单的互斥锁Mutex用于保护共享资源的访问
线访访*/
#include "los_mux_pri.h" #include "los_mux_pri.h"
#include "los_mux_debug_pri.h" #include "los_mux_debug_pri.h"
#include "los_bitmap.h" #include "los_bitmap.h"
@ -49,6 +50,7 @@ LITE_OS_SEC_DATA_INIT STATIC LOS_DL_LIST g_unusedMuxList;
* Description : Initializes the mutex * Description : Initializes the mutex
* Return : LOS_OK on success, or error code on failure * Return : LOS_OK on success, or error code on failure
*/ */
//OsMuxInitMutex初始化函数用于初始化Mutex数据结构并设置初始状态
LITE_OS_SEC_TEXT UINT32 OsMuxInit(VOID) LITE_OS_SEC_TEXT UINT32 OsMuxInit(VOID)
{ {
LosMuxCB *muxNode = NULL; LosMuxCB *muxNode = NULL;
@ -74,7 +76,7 @@ LITE_OS_SEC_TEXT UINT32 OsMuxInit(VOID)
} }
return LOS_OK; return LOS_OK;
} }
//LOS_MuxCreate创建Mutex函数用于创建一个新的Mutex对象并返回其句柄
LITE_OS_SEC_TEXT UINT32 LOS_MuxCreate(UINT32 *muxHandle) LITE_OS_SEC_TEXT UINT32 LOS_MuxCreate(UINT32 *muxHandle)
{ {
UINT32 intSave; UINT32 intSave;
@ -113,7 +115,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxCreate(UINT32 *muxHandle)
ERR_HANDLER: ERR_HANDLER:
OS_RETURN_ERROR_P2(errLine, errNo); OS_RETURN_ERROR_P2(errLine, errNo);
} }
//LOS_MuxDelete删除Mutex函数用于删除指定的Mutex对象及其相关资源
LITE_OS_SEC_TEXT UINT32 LOS_MuxDelete(UINT32 muxHandle) LITE_OS_SEC_TEXT UINT32 LOS_MuxDelete(UINT32 muxHandle)
{ {
UINT32 intSave; UINT32 intSave;
@ -154,7 +156,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxDelete(UINT32 muxHandle)
ERR_HANDLER: ERR_HANDLER:
OS_RETURN_ERROR_P2(errLine, errNo); OS_RETURN_ERROR_P2(errLine, errNo);
} }
//OsMuxParaCheck 函数主要用于验证互斥量操作的参数是否有效,包括互斥量是否被正确创建和传入的句柄是否有效,以及当前是否处于中断上下文
LITE_OS_SEC_TEXT STATIC UINT32 OsMuxParaCheck(const LosMuxCB *muxCB, UINT32 muxHandle) LITE_OS_SEC_TEXT STATIC UINT32 OsMuxParaCheck(const LosMuxCB *muxCB, UINT32 muxHandle)
{ {
if ((muxCB->muxStat == LOS_UNUSED) || (muxCB->muxId != 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; return LOS_OK;
} }
//OsMuxBitmapSet 函数用于在互斥量等待队列中设置任务的优先级位图,并根据需要调整任务的优先级,以确保任务在等待互斥量时能够正确反映其优先级关系
LITE_OS_SEC_TEXT STATIC VOID OsMuxBitmapSet(const LosTaskCB *runTask, const MuxBaseCB *muxPended) LITE_OS_SEC_TEXT STATIC VOID OsMuxBitmapSet(const LosTaskCB *runTask, const MuxBaseCB *muxPended)
{ {
if (muxPended->owner->priority > runTask->priority) { 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); OsTaskPriModify(muxPended->owner, runTask->priority);
} }
} }
//OsMuxBitmapRestore 函数用于恢复任务的优先级位图,并根据需要更新拥有者任务的优先级
LITE_OS_SEC_TEXT STATIC VOID OsMuxBitmapRestore(const LosTaskCB *runTask, LosTaskCB *owner) LITE_OS_SEC_TEXT STATIC VOID OsMuxBitmapRestore(const LosTaskCB *runTask, LosTaskCB *owner)
{ {
UINT16 bitMapPri; UINT16 bitMapPri;
@ -244,7 +246,8 @@ LITE_OS_SEC_TEXT STATIC LOS_DL_LIST *OsMuxPendFindPos(const LosTaskCB *runTask,
return node; return node;
} }
#endif #endif
//总体来说OsMuxPostOp 函数用于处理 Mutex 的释放操作,包括唤醒等待任务、更新 Mutex 状态和持有者等
//确保 Mutex 能够按照预期的方式被正确释放和传递给下一个任务
LITE_OS_SEC_TEXT UINT32 OsMuxPendOp(LosTaskCB *runTask, MuxBaseCB *muxPended, UINT32 timeout, LITE_OS_SEC_TEXT UINT32 OsMuxPendOp(LosTaskCB *runTask, MuxBaseCB *muxPended, UINT32 timeout,
UINT32 *intSave) UINT32 *intSave)
{ {
@ -270,7 +273,7 @@ LITE_OS_SEC_TEXT UINT32 OsMuxPendOp(LosTaskCB *runTask, MuxBaseCB *muxPended, UI
return ret; return ret;
} }
//LOS_MuxPend等待Mutex函数用于尝试获取指定Mutex的访问权限。如果Mutex已被其他任务持有则当前任务会被挂起直到Mutex可用
LITE_OS_SEC_TEXT UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout) LITE_OS_SEC_TEXT UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout)
{ {
UINT32 ret; UINT32 ret;
@ -332,7 +335,7 @@ OUT_UNLOCK:
} }
return ret; return ret;
} }
//OsMuxPostOpSub:通过比较当前任务和 Mutex 等待队列中的任务的优先级,来调整当前任务的优先级位图,并将 Mutex 持有者的优先级提升
LITE_OS_SEC_TEXT STATIC VOID OsMuxPostOpSub(LosTaskCB *runTask, MuxBaseCB *muxPosted) LITE_OS_SEC_TEXT STATIC VOID OsMuxPostOpSub(LosTaskCB *runTask, MuxBaseCB *muxPosted)
{ {
LosTaskCB *pendedTask = NULL; LosTaskCB *pendedTask = NULL;
@ -350,7 +353,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsMuxPostOpSub(LosTaskCB *runTask, MuxBaseCB *muxPo
LOS_BitmapClr(&runTask->priBitMap, bitMapPri); LOS_BitmapClr(&runTask->priBitMap, bitMapPri);
OsTaskPriModify(muxPosted->owner, bitMapPri); OsTaskPriModify(muxPosted->owner, bitMapPri);
} }
//
LITE_OS_SEC_TEXT UINT32 OsMuxPostOp(LosTaskCB *runTask, MuxBaseCB *muxPosted) LITE_OS_SEC_TEXT UINT32 OsMuxPostOp(LosTaskCB *runTask, MuxBaseCB *muxPosted)
{ {
LosTaskCB *resumedTask = NULL; LosTaskCB *resumedTask = NULL;
@ -386,7 +389,7 @@ LITE_OS_SEC_TEXT UINT32 OsMuxPostOp(LosTaskCB *runTask, MuxBaseCB *muxPosted)
return MUX_SCHEDULE; return MUX_SCHEDULE;
} }
//LOS_MuxPost释放Mutex函数用于释放当前任务对指定Mutex的访问权限以便其他任务可以获取该Mutex
LITE_OS_SEC_TEXT UINT32 LOS_MuxPost(UINT32 muxHandle) LITE_OS_SEC_TEXT UINT32 LOS_MuxPost(UINT32 muxHandle)
{ {
UINT32 ret; UINT32 ret;

@ -33,7 +33,7 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __cplusplus */ #endif /* __cplusplus */
//定义全局变量数组用于存储每个CPU核心的私有数据
Percpu g_percpu[LOSCFG_KERNEL_CORE_NUM]; Percpu g_percpu[LOSCFG_KERNEL_CORE_NUM];
#ifdef __cplusplus #ifdef __cplusplus

@ -32,7 +32,7 @@
* It should not add OS inner invocation, which is not allowed to be accessed in user space. * 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. * But it's allowed to invoke syscall interface.
*---------------------------------------------------------------------------- */ *---------------------------------------------------------------------------- */
/*这段代码是一个输出控制模块,根据不同的输出类型将字符串输出到不同的设备上*/
#ifdef LOSCFG_LIB_LIBC #ifdef LOSCFG_LIB_LIBC
#include "unistd.h" #include "unistd.h"
#endif #endif
@ -62,13 +62,13 @@ typedef enum {
CONSOLE_OUTPUT = 2, CONSOLE_OUTPUT = 2,
EXC_OUTPUT = 3 EXC_OUTPUT = 3
} OutputType; } OutputType;
//ErrorMsg用于输出错误信息当字符串输出非法或者vsnprintf_s函数失败时调用
STATIC VOID ErrorMsg(VOID) STATIC VOID ErrorMsg(VOID)
{ {
const CHAR *p = "Output illegal string! vsnprintf_s failed!\n"; const CHAR *p = "Output illegal string! vsnprintf_s failed!\n";
UartPuts(p, (UINT32)strlen(p), UART_WITH_LOCK); UartPuts(p, (UINT32)strlen(p), UART_WITH_LOCK);
} }
//UartOutput实际将字符串输出到串口的函数根据配置可能会进行一些额外的处理
STATIC VOID UartOutput(const CHAR *str, UINT32 len, BOOL isLock) STATIC VOID UartOutput(const CHAR *str, UINT32 len, BOOL isLock)
{ {
#ifdef LOSCFG_SHELL_DMESG #ifdef LOSCFG_SHELL_DMESG
@ -82,7 +82,7 @@ STATIC VOID UartOutput(const CHAR *str, UINT32 len, BOOL isLock)
UartPuts(str, len, isLock); UartPuts(str, len, isLock);
#endif #endif
} }
//OutputControl根据输出类型选择相应的输出设备并调用对应的输出函数
STATIC VOID OutputControl(const CHAR *str, UINT32 len, OutputType type) STATIC VOID OutputControl(const CHAR *str, UINT32 len, OutputType type)
{ {
switch (type) { switch (type) {
@ -105,14 +105,14 @@ STATIC VOID OutputControl(const CHAR *str, UINT32 len, OutputType type)
} }
return; return;
} }
//OsVprintfFree释放动态分配的缓冲区内存
STATIC VOID OsVprintfFree(CHAR *buf, UINT32 bufLen) STATIC VOID OsVprintfFree(CHAR *buf, UINT32 bufLen)
{ {
if (bufLen != SIZEBUF) { if (bufLen != SIZEBUF) {
(VOID)LOS_MemFree(m_aucSysMem0, buf); (VOID)LOS_MemFree(m_aucSysMem0, buf);
} }
} }
//OsVprintf核心函数根据给定的格式化字符串和可变参数进行字符串格式化并输出到相应的设备
STATIC VOID OsVprintf(const CHAR *fmt, va_list ap, OutputType type) STATIC VOID OsVprintf(const CHAR *fmt, va_list ap, OutputType type)
{ {
INT32 len; INT32 len;
@ -156,7 +156,7 @@ STATIC VOID OsVprintf(const CHAR *fmt, va_list ap, OutputType type)
OutputControl(bBuf, len, type); OutputControl(bBuf, len, type);
OsVprintfFree(bBuf, bufLen); OsVprintfFree(bBuf, bufLen);
} }
//UartVprintf、ConsoleVprintf、UartPrintf、dprintf、LkDprintf、DmesgPrintf、ExcPrintf、PrintExcInfo这些函数都是对OsVprintf的封装提供了不同的输出接口在不同的场景下调用OsVprintf来完成字符串的格式化和输出
VOID UartVprintf(const CHAR *fmt, va_list ap) VOID UartVprintf(const CHAR *fmt, va_list ap)
{ {
OsVprintf(fmt, ap, UART_OUTPUT); OsVprintf(fmt, ap, UART_OUTPUT);

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
//实现了一个基于轻量级操作系统的队列管理模块,提供了队列的创建、读写、删除以及信息获取等功能
#include "los_queue_pri.h" #include "los_queue_pri.h"
#include "los_queue_debug_pri.h" #include "los_queue_debug_pri.h"
#include "los_task_pri.h" #include "los_task_pri.h"
@ -53,6 +53,7 @@ LITE_OS_SEC_BSS STATIC LOS_DL_LIST g_freeQueueList;
* Description : queue initial * Description : queue initial
* Return : LOS_OK on success or error code on failure * Return : LOS_OK on success or error code on failure
*/ */
//初始化队列,返回成功或失败错误码
LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID) LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID)
{ {
LosQueueCB *queueNode = NULL; LosQueueCB *queueNode = NULL;
@ -78,7 +79,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID)
} }
return LOS_OK; return LOS_OK;
} }
//OsQueueCreateParameterCheck函数用于检查创建队列时传入的参数是否合法
STATIC INLINE UINT32 OsQueueCreateParameterCheck(UINT16 len, const UINT32 *queueId, UINT16 maxMsgSize) STATIC INLINE UINT32 OsQueueCreateParameterCheck(UINT16 len, const UINT32 *queueId, UINT16 maxMsgSize)
{ {
if (queueId == NULL) { if (queueId == NULL) {
@ -94,7 +95,7 @@ STATIC INLINE UINT32 OsQueueCreateParameterCheck(UINT16 len, const UINT32 *queue
} }
return LOS_OK; return LOS_OK;
} }
//OsQueueCreateInternal函数用于创建队列包括在队列控制块中记录队列长度、消息大小等信息
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsQueueCreateInternal(UINT16 len, UINT32 *queueId, UINT16 msgSize, LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsQueueCreateInternal(UINT16 len, UINT32 *queueId, UINT16 msgSize,
UINT8 *queue, UINT8 queueMemType) UINT8 *queue, UINT8 queueMemType)
{ {
@ -165,7 +166,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreateStatic(const CHAR *queueName,
return OsQueueCreateInternal(len, queueId, msgSize, queueMem, OS_QUEUE_ALLOC_STATIC); return OsQueueCreateInternal(len, queueId, msgSize, queueMem, OS_QUEUE_ALLOC_STATIC);
} }
#endif #endif
//创建队列
LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(const CHAR *queueName, UINT16 len, UINT32 *queueId, LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(const CHAR *queueName, UINT16 len, UINT32 *queueId,
UINT32 flags, UINT16 maxMsgSize) UINT32 flags, UINT16 maxMsgSize)
{ {
@ -198,7 +199,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(const CHAR *queueName, UINT16 len,
return LOS_OK; return LOS_OK;
} }
//OsQueueReadParameterCheck和OsQueueWriteParameterCheck分别用于检查读和写操作的参数合法性
LITE_OS_SEC_TEXT STATIC UINT32 OsQueueReadParameterCheck(UINT32 queueId, const VOID *bufferAddr, LITE_OS_SEC_TEXT STATIC UINT32 OsQueueReadParameterCheck(UINT32 queueId, const VOID *bufferAddr,
const UINT32 *bufferSize, UINT32 timeout) const UINT32 *bufferSize, UINT32 timeout)
{ {
@ -248,7 +249,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsQueueWriteParameterCheck(UINT32 queueId, const
} }
return LOS_OK; return LOS_OK;
} }
//实现了队列的读取和写入操作,并对可能出现的错误进行了处理
STATIC UINT32 OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize) STATIC UINT32 OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize)
{ {
UINT8 *queueNode = NULL; UINT8 *queueNode = NULL;
@ -296,7 +297,7 @@ STATIC UINT32 OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType, VOID
} }
return LOS_OK; return LOS_OK;
} }
//用于处理队列操作函数 OsQueueBufferOperate 返回的错误码,使得在发生错误时能够打印相应的错误信息
STATIC VOID OsQueueBufferOperateErrProcess(UINT32 errorCode) STATIC VOID OsQueueBufferOperateErrProcess(UINT32 errorCode)
{ {
switch (errorCode) { switch (errorCode) {
@ -336,7 +337,7 @@ STATIC UINT32 OsQueueOperateParamCheck(const LosQueueCB *queueCB, UINT32 queueId
} }
return LOS_OK; return LOS_OK;
} }
//OsQueueOperate:实现了对队列的操作,包括参数检查、任务挂起与唤醒以及错误处理等功能
STATIC UINT32 OsQueueOperate(UINT32 queueId, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize, UINT32 timeout) STATIC UINT32 OsQueueOperate(UINT32 queueId, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize, UINT32 timeout)
{ {
LosQueueCB *queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueId); LosQueueCB *queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueId);
@ -400,7 +401,7 @@ QUEUE_END:
OsQueueBufferOperateErrProcess(errorCode); OsQueueBufferOperateErrProcess(errorCode);
return ret; return ret;
} }
//LOS_QueueReadCopy从队列中读取数据通过参数检查后调用OsQueueOperate函数进行实际的读取操作
LITE_OS_SEC_TEXT UINT32 LOS_QueueReadCopy(UINT32 queueId, LITE_OS_SEC_TEXT UINT32 LOS_QueueReadCopy(UINT32 queueId,
VOID *bufferAddr, VOID *bufferAddr,
UINT32 *bufferSize, UINT32 *bufferSize,
@ -417,7 +418,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueReadCopy(UINT32 queueId,
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_READ, OS_QUEUE_HEAD); operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_READ, OS_QUEUE_HEAD);
return OsQueueOperate(queueId, operateType, bufferAddr, bufferSize, timeout); return OsQueueOperate(queueId, operateType, bufferAddr, bufferSize, timeout);
} }
//LOS_QueueWriteHeadCopy向队列的头部写入数据通过参数检查后调用OsQueueOperate函数进行实际的写入操作
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHeadCopy(UINT32 queueId, LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHeadCopy(UINT32 queueId,
VOID *bufferAddr, VOID *bufferAddr,
UINT32 bufferSize, UINT32 bufferSize,
@ -434,7 +435,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHeadCopy(UINT32 queueId,
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_HEAD); operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_HEAD);
return OsQueueOperate(queueId, operateType, bufferAddr, &bufferSize, timeout); return OsQueueOperate(queueId, operateType, bufferAddr, &bufferSize, timeout);
} }
//LOS_QueueWriteCopy向队列的尾部写入数据通过参数检查后调用OsQueueOperate函数进行实际的写入操作
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteCopy(UINT32 queueId, LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteCopy(UINT32 queueId,
VOID *bufferAddr, VOID *bufferAddr,
UINT32 bufferSize, UINT32 bufferSize,
@ -451,12 +452,12 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteCopy(UINT32 queueId,
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_TAIL); operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_TAIL);
return OsQueueOperate(queueId, operateType, bufferAddr, &bufferSize, timeout); return OsQueueOperate(queueId, operateType, bufferAddr, &bufferSize, timeout);
} }
//LOS_QueueRead从队列中读取数据的简化接口直接调用LOS_QueueReadCopy函数
LITE_OS_SEC_TEXT UINT32 LOS_QueueRead(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout) LITE_OS_SEC_TEXT UINT32 LOS_QueueRead(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout)
{ {
return LOS_QueueReadCopy(queueId, bufferAddr, &bufferSize, timeout); return LOS_QueueReadCopy(queueId, bufferAddr, &bufferSize, timeout);
} }
//LOS_QueueWrite向队列中写入数据的简化接口先进行参数检查然后调用LOS_QueueWriteCopy函数
LITE_OS_SEC_TEXT UINT32 LOS_QueueWrite(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout) LITE_OS_SEC_TEXT UINT32 LOS_QueueWrite(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout)
{ {
if (bufferAddr == NULL) { if (bufferAddr == NULL) {
@ -465,7 +466,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueWrite(UINT32 queueId, VOID *bufferAddr, UINT32
bufferSize = sizeof(CHAR *); bufferSize = sizeof(CHAR *);
return LOS_QueueWriteCopy(queueId, &bufferAddr, bufferSize, timeout); return LOS_QueueWriteCopy(queueId, &bufferAddr, bufferSize, timeout);
} }
//LOS_QueueWriteHead向队列头部写入数据的简化接口先进行参数检查然后调用LOS_QueueWriteHeadCopy函数
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHead(UINT32 queueId, LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHead(UINT32 queueId,
VOID *bufferAddr, VOID *bufferAddr,
UINT32 bufferSize, UINT32 bufferSize,
@ -477,7 +478,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHead(UINT32 queueId,
bufferSize = sizeof(CHAR *); bufferSize = sizeof(CHAR *);
return LOS_QueueWriteHeadCopy(queueId, &bufferAddr, bufferSize, timeout); return LOS_QueueWriteHeadCopy(queueId, &bufferAddr, bufferSize, timeout);
} }
//LOS_QueueDelete删除队列的函数
//首先检查队列是否存在,如果存在则检查是否有任务正在使用队列或者队列中还有未释放的内存块,如果满足条件则释放队列所占用的资源
LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueDelete(UINT32 queueId) LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueDelete(UINT32 queueId)
{ {
LosQueueCB *queueCB = NULL; LosQueueCB *queueCB = NULL;
@ -537,7 +539,7 @@ QUEUE_END:
SCHEDULER_UNLOCK(intSave); SCHEDULER_UNLOCK(intSave);
return ret; return ret;
} }
//LOS_QueueInfoGet:获取指定队列的相关信息包括队列ID、队列长度、队列大小、队列头尾指针、等待读取和写入的任务数等
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_QueueInfoGet(UINT32 queueId, QUEUE_INFO_S *queueInfo) LITE_OS_SEC_TEXT_MINOR UINT32 LOS_QueueInfoGet(UINT32 queueId, QUEUE_INFO_S *queueInfo)
{ {
UINT32 intSave; UINT32 intSave;
@ -595,6 +597,9 @@ QUEUE_END:
* : timeout --- Expiry time. The value range is [0,LOS_WAIT_FOREVER] * : timeout --- Expiry time. The value range is [0,LOS_WAIT_FOREVER]
* Return : pointer if success otherwise NULL * Return : pointer if success otherwise NULL
*/ */
//OsQueueMailAlloc函数用来从邮件池中分配一个邮件内存块
//如果没有可用的内存块,则根据超时时间挂起当前任务,并将其加入到等待内存块的任务链表中
//当有内存块可用时,会将任务从任务链表中移除,并返回分配的内存块指针
LITE_OS_SEC_TEXT VOID *OsQueueMailAlloc(UINT32 queueId, VOID *mailPool, UINT32 timeout) LITE_OS_SEC_TEXT VOID *OsQueueMailAlloc(UINT32 queueId, VOID *mailPool, UINT32 timeout)
{ {
VOID *mem = NULL; VOID *mem = NULL;
@ -663,6 +668,8 @@ END:
* : mailMem --- The mail memory block address * : mailMem --- The mail memory block address
* Return : LOS_OK on success or error code on failure * Return : LOS_OK on success or error code on failure
*/ */
//OsQueueMailFree函数用来释放指定的邮件内存块并将其加入到邮件池的空闲链表中
//如果有任务在等待内存块,则会从任务链表中唤醒一个任务,并将其从任务链表中移除
LITE_OS_SEC_TEXT UINT32 OsQueueMailFree(UINT32 queueId, VOID *mailPool, VOID *mailMem) LITE_OS_SEC_TEXT UINT32 OsQueueMailFree(UINT32 queueId, VOID *mailPool, VOID *mailMem)
{ {
VOID *mem = NULL; VOID *mem = NULL;

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/*实现环形缓冲区。环形缓冲区是一种循环使用固定大小存储空间的数据结构,常用于解决生产者-消费者问题*/
#include "los_ringbuf.h" #include "los_ringbuf.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -33,7 +33,7 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __cplusplus */ #endif /* __cplusplus */
//LOS_RingbufUsedSize获取环形缓冲区已使用的大小
UINT32 LOS_RingbufUsedSize(Ringbuf *ringbuf) UINT32 LOS_RingbufUsedSize(Ringbuf *ringbuf)
{ {
UINT32 size; UINT32 size;
@ -56,6 +56,7 @@ UINT32 LOS_RingbufUsedSize(Ringbuf *ringbuf)
* | * |
* endIdx * endIdx
*/ */
//OsRingbufWriteLinear线性写入数据到环形缓冲区
STATIC UINT32 OsRingbufWriteLinear(Ringbuf *ringbuf, const CHAR *buf, UINT32 size) STATIC UINT32 OsRingbufWriteLinear(Ringbuf *ringbuf, const CHAR *buf, UINT32 size)
{ {
UINT32 cpSize; UINT32 cpSize;
@ -77,7 +78,7 @@ STATIC UINT32 OsRingbufWriteLinear(Ringbuf *ringbuf, const CHAR *buf, UINT32 siz
return cpSize; return cpSize;
} }
//OsRingbufWriteLoop循环写入数据到环形缓冲区
STATIC UINT32 OsRingbufWriteLoop(Ringbuf *ringbuf, const CHAR *buf, UINT32 size) STATIC UINT32 OsRingbufWriteLoop(Ringbuf *ringbuf, const CHAR *buf, UINT32 size)
{ {
UINT32 right, cpSize; UINT32 right, cpSize;
@ -105,7 +106,7 @@ STATIC UINT32 OsRingbufWriteLoop(Ringbuf *ringbuf, const CHAR *buf, UINT32 size)
return cpSize; return cpSize;
} }
//LOS_RingbufWrite向环形缓冲区写入数据
UINT32 LOS_RingbufWrite(Ringbuf *ringbuf, const CHAR *buf, UINT32 size) UINT32 LOS_RingbufWrite(Ringbuf *ringbuf, const CHAR *buf, UINT32 size)
{ {
UINT32 cpSize = 0; UINT32 cpSize = 0;
@ -130,7 +131,7 @@ EXIT:
LOS_SpinUnlockRestore(&ringbuf->lock, intSave); LOS_SpinUnlockRestore(&ringbuf->lock, intSave);
return cpSize; return cpSize;
} }
//OsRingbufReadLinear线性读取环形缓冲区中的数据
STATIC UINT32 OsRingbufReadLinear(Ringbuf *ringbuf, CHAR *buf, UINT32 size) STATIC UINT32 OsRingbufReadLinear(Ringbuf *ringbuf, CHAR *buf, UINT32 size)
{ {
UINT32 cpSize, remain; UINT32 cpSize, remain;
@ -153,7 +154,7 @@ STATIC UINT32 OsRingbufReadLinear(Ringbuf *ringbuf, CHAR *buf, UINT32 size)
return cpSize; return cpSize;
} }
//OsRingbufReadLoop循环读取环形缓冲区中的数据
STATIC UINT32 OsRingbufReadLoop(Ringbuf *ringbuf, CHAR *buf, UINT32 size) STATIC UINT32 OsRingbufReadLoop(Ringbuf *ringbuf, CHAR *buf, UINT32 size)
{ {
UINT32 right, cpSize; UINT32 right, cpSize;
@ -179,7 +180,7 @@ STATIC UINT32 OsRingbufReadLoop(Ringbuf *ringbuf, CHAR *buf, UINT32 size)
return cpSize; return cpSize;
} }
//LOS_RingbufRead从环形缓冲区读取数据
UINT32 LOS_RingbufRead(Ringbuf *ringbuf, CHAR *buf, UINT32 size) UINT32 LOS_RingbufRead(Ringbuf *ringbuf, CHAR *buf, UINT32 size)
{ {
UINT32 cpSize; UINT32 cpSize;
@ -205,7 +206,7 @@ EXIT:
LOS_SpinUnlockRestore(&ringbuf->lock, intSave); LOS_SpinUnlockRestore(&ringbuf->lock, intSave);
return cpSize; return cpSize;
} }
//LOS_RingbufInit初始化环形缓冲区
UINT32 LOS_RingbufInit(Ringbuf *ringbuf, CHAR *fifo, UINT32 size) UINT32 LOS_RingbufInit(Ringbuf *ringbuf, CHAR *fifo, UINT32 size)
{ {
if ((ringbuf == NULL) || (fifo == NULL) || if ((ringbuf == NULL) || (fifo == NULL) ||
@ -221,7 +222,7 @@ UINT32 LOS_RingbufInit(Ringbuf *ringbuf, CHAR *fifo, UINT32 size)
ringbuf->status = RBUF_INITED; ringbuf->status = RBUF_INITED;
return LOS_OK; return LOS_OK;
} }
//LOS_RingbufReset重置环形缓冲区
VOID LOS_RingbufReset(Ringbuf *ringbuf) VOID LOS_RingbufReset(Ringbuf *ringbuf)
{ {
UINT32 intSave; UINT32 intSave;

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/*实现信号量的操作系统内核代码主要包括信号量的创建、删除、等待Pend和释放Post等操作*/
#include "los_sem_pri.h" #include "los_sem_pri.h"
#include "los_sem_debug_pri.h" #include "los_sem_debug_pri.h"
#include "los_err_pri.h" #include "los_err_pri.h"
@ -49,7 +49,7 @@ STATIC_INLINE VOID OsSemNodeRecycle(LosSemCB *semNode)
semNode->semStat = LOS_UNUSED; semNode->semStat = LOS_UNUSED;
LOS_ListTailInsert(&g_unusedSemList, &semNode->semList); LOS_ListTailInsert(&g_unusedSemList, &semNode->semList);
} }
//OsSemInit()函数:用于初始化信号量管理模块,包括申请创建信号量所需要的内存空间、将信号量结构体加入到未使用链表中等
LITE_OS_SEC_TEXT_INIT UINT32 OsSemInit(VOID) LITE_OS_SEC_TEXT_INIT UINT32 OsSemInit(VOID)
{ {
LosSemCB *semNode = NULL; LosSemCB *semNode = NULL;
@ -74,7 +74,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSemInit(VOID)
} }
return LOS_OK; return LOS_OK;
} }
//OsSemCreate函数:用于创建一个信号量,并将其加入到已使用信号量列表中
//参数count表示信号量的初始值type表示信号量的类型计数信号量或二进制信号量semHandle用于返回创建的信号量的句柄
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsSemCreate(UINT16 count, UINT8 type, UINT32 *semHandle) LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsSemCreate(UINT16 count, UINT8 type, UINT32 *semHandle)
{ {
UINT32 intSave; UINT32 intSave;
@ -109,7 +110,7 @@ LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsSemCreate(UINT16 count, UINT8 type, UINT32
LOS_TRACE(SEM_CREATE, semCreated->semId, type, count); LOS_TRACE(SEM_CREATE, semCreated->semId, type, count);
return LOS_OK; return LOS_OK;
} }
//LOS_SemCreate:对外部提供的接口函数,用于创建一个计数信号量
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemCreate(UINT16 count, UINT32 *semHandle) LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemCreate(UINT16 count, UINT32 *semHandle)
{ {
if (count > LOS_SEM_COUNT_MAX) { if (count > LOS_SEM_COUNT_MAX) {
@ -117,7 +118,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemCreate(UINT16 count, UINT32 *semHandle)
} }
return OsSemCreate(count, OS_SEM_COUNTING, semHandle); return OsSemCreate(count, OS_SEM_COUNTING, semHandle);
} }
//LOS_BinarySemCreate:对外部提供的接口函数,用于创建一个二进制信号量
LITE_OS_SEC_TEXT_INIT UINT32 LOS_BinarySemCreate(UINT16 count, UINT32 *semHandle) LITE_OS_SEC_TEXT_INIT UINT32 LOS_BinarySemCreate(UINT16 count, UINT32 *semHandle)
{ {
if (count > OS_SEM_BINARY_COUNT_MAX) { if (count > OS_SEM_BINARY_COUNT_MAX) {
@ -125,7 +126,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_BinarySemCreate(UINT16 count, UINT32 *semHandle
} }
return OsSemCreate(count, OS_SEM_BINARY, semHandle); return OsSemCreate(count, OS_SEM_BINARY, semHandle);
} }
//OsSemStateVerify:用于验证信号量的状态是否有效
//参数semId表示要验证的信号量的IDsemNode是指向信号量控制块的指针
STATIC_INLINE UINT32 OsSemStateVerify(UINT32 semId, const LosSemCB *semNode) STATIC_INLINE UINT32 OsSemStateVerify(UINT32 semId, const LosSemCB *semNode)
{ {
#ifndef LOSCFG_RESOURCE_ID_NOT_USE_HIGH_BITS #ifndef LOSCFG_RESOURCE_ID_NOT_USE_HIGH_BITS
@ -137,7 +139,8 @@ STATIC_INLINE UINT32 OsSemStateVerify(UINT32 semId, const LosSemCB *semNode)
} }
return LOS_OK; return LOS_OK;
} }
//OsSemGetCBWithCheck:用于根据信号量句柄获取信号量的控制块
//参数semHandle表示信号量的句柄semCB是一个指向指针的指针用于返回获取到的信号量控制块
STATIC UINT32 OsSemGetCBWithCheck(UINT32 semHandle, LosSemCB **semCB) STATIC UINT32 OsSemGetCBWithCheck(UINT32 semHandle, LosSemCB **semCB)
{ {
if (GET_SEM_INDEX(semHandle) >= (UINT32)KERNEL_SEM_LIMIT) { if (GET_SEM_INDEX(semHandle) >= (UINT32)KERNEL_SEM_LIMIT) {
@ -147,7 +150,7 @@ STATIC UINT32 OsSemGetCBWithCheck(UINT32 semHandle, LosSemCB **semCB)
*semCB = GET_SEM(semHandle); *semCB = GET_SEM(semHandle);
return LOS_OK; return LOS_OK;
} }
//LOS_SemDelete:用于删除指定句柄的信号量,如果有任务正在等待该信号量,则删除失败
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemDelete(UINT32 semHandle) LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemDelete(UINT32 semHandle)
{ {
UINT32 intSave; UINT32 intSave;
@ -184,7 +187,7 @@ OUT:
LOS_TRACE(SEM_DELETE, semHandle, ret); LOS_TRACE(SEM_DELETE, semHandle, ret);
return ret; return ret;
} }
//LOS_SemPend:用于等待Pend一个信号量如果信号量不可用则阻塞当前任务直到信号量可用或超时。timeout表示超时时间
LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout) LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout)
{ {
UINT32 intSave; UINT32 intSave;
@ -252,7 +255,7 @@ OUT:
SCHEDULER_UNLOCK(intSave); SCHEDULER_UNLOCK(intSave);
return ret; return ret;
} }
//LOS_SemPost:用于释放Post一个信号量使其变为可用状态并唤醒等待该信号量的任务中的第一个任务
LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle) LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle)
{ {
UINT32 intSave; UINT32 intSave;

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/*嵌入式操作系统中与任务调度相关的排序链表管理代码。包括了对排序链表的初始化、向排序链表中添加节点、从排序链表中删除节点、获取下一个超时时间等操作*/
#include "los_sortlink_pri.h" #include "los_sortlink_pri.h"
#include "los_memory.h" #include "los_memory.h"
#include "los_exc.h" #include "los_exc.h"
@ -39,7 +39,7 @@ extern "C" {
#define OS_INVALID_VALUE 0xFFFFFFFF #define OS_INVALID_VALUE 0xFFFFFFFF
#ifdef LOSCFG_BASE_CORE_USE_MULTI_LIST #ifdef LOSCFG_BASE_CORE_USE_MULTI_LIST
//OsSortLinkInit初始化排序链表为排序链表的头节点分配内存并进行初始化
LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader) LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
{ {
UINT32 size; UINT32 size;
@ -60,7 +60,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
} }
return LOS_OK; return LOS_OK;
} }
//OsAdd2SortLink将一个节点添加到排序链表中根据节点的超时时间计算节点在排序链表中的位置然后插入到相应位置
LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList) LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
{ {
SortLinkList *listSorted = NULL; SortLinkList *listSorted = NULL;
@ -106,7 +106,7 @@ LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, So
LOS_ListTailInsert(&listSorted->sortLinkNode, &sortList->sortLinkNode); LOS_ListTailInsert(&listSorted->sortLinkNode, &sortList->sortLinkNode);
} }
} }
//OsCheckSortLink检查排序链表是否合法排除循环引用和无效节点
LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const LOS_DL_LIST *listNode) LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const LOS_DL_LIST *listNode)
{ {
LOS_DL_LIST *tmp = listNode->pstPrev; LOS_DL_LIST *tmp = listNode->pstPrev;
@ -122,7 +122,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const
/* delete invalid sortlink node */ /* delete invalid sortlink node */
OsBackTrace(); OsBackTrace();
} }
//OsDeleteSortLink从排序链表中删除一个节点然后更新相邻节点的超时时间
LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList) LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
{ {
LOS_DL_LIST *listObject = NULL; LOS_DL_LIST *listObject = NULL;
@ -141,7 +141,7 @@ LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader,
} }
LOS_ListDelete(&sortList->sortLinkNode); LOS_ListDelete(&sortList->sortLinkNode);
} }
//OsCalcExpierTime根据当前的排序链表游标和节点的位置计算超时时间
LITE_OS_SEC_TEXT STATIC INLINE UINT32 OsCalcExpierTime(UINT32 rollNum, UINT32 sortIndex, UINT16 curSortIndex) LITE_OS_SEC_TEXT STATIC INLINE UINT32 OsCalcExpierTime(UINT32 rollNum, UINT32 sortIndex, UINT16 curSortIndex)
{ {
UINT32 expireTime; UINT32 expireTime;
@ -154,7 +154,7 @@ LITE_OS_SEC_TEXT STATIC INLINE UINT32 OsCalcExpierTime(UINT32 rollNum, UINT32 so
expireTime = ((rollNum - 1) << OS_TSK_SORTLINK_LOGLEN) + sortIndex; expireTime = ((rollNum - 1) << OS_TSK_SORTLINK_LOGLEN) + sortIndex;
return expireTime; return expireTime;
} }
//OsSortLinkGetNextExpireTime获取排序链表中下一个超时时间最小的节点的超时时间
LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader) LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
{ {
UINT16 cursor; UINT16 cursor;
@ -184,7 +184,7 @@ LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sor
return expireTime; return expireTime;
} }
//OsSortLinkUpdateExpireTime更新排序链表中所有节点的超时时间并更新游标
LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader) LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader)
{ {
SortLinkList *sortList = NULL; SortLinkList *sortList = NULL;
@ -215,7 +215,7 @@ LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttr
} }
sortLinkHeader->cursor = (sortLinkHeader->cursor + sleepTicks - 1) % OS_TSK_SORTLINK_LEN; sortLinkHeader->cursor = (sortLinkHeader->cursor + sleepTicks - 1) % OS_TSK_SORTLINK_LEN;
} }
//OsSortLinkGetTargetExpireTime获取目标节点的超时时间
LITE_OS_SEC_TEXT_MINOR UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader, LITE_OS_SEC_TEXT_MINOR UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader,
const SortLinkList *targetSortList) const SortLinkList *targetSortList)
{ {
@ -235,7 +235,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttrib
} }
#else /* LOSCFG_BASE_CORE_USE_SINGLE_LIST */ #else /* LOSCFG_BASE_CORE_USE_SINGLE_LIST */
//OsSortLinkInit:初始化排序链表头部
LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader) LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
{ {
UINT32 size; UINT32 size;
@ -252,7 +252,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
LOS_ListInit(listObject); LOS_ListInit(listObject);
return LOS_OK; return LOS_OK;
} }
//OsAdd2SortLink:向排序链表中添加元素
LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList) LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
{ {
SortLinkList *listSorted = NULL; SortLinkList *listSorted = NULL;
@ -286,7 +286,7 @@ LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, So
LOS_ListTailInsert(&listSorted->sortLinkNode, &sortList->sortLinkNode); LOS_ListTailInsert(&listSorted->sortLinkNode, &sortList->sortLinkNode);
} }
} }
//OsCheckSortLink:检查排序链表的有效性,用于内部调用
LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const LOS_DL_LIST *listNode) LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const LOS_DL_LIST *listNode)
{ {
LOS_DL_LIST *tmp = listNode->pstPrev; LOS_DL_LIST *tmp = listNode->pstPrev;
@ -302,7 +302,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const
/* delete invalid sortlink node */ /* delete invalid sortlink node */
OsBackTrace(); OsBackTrace();
} }
//OsDeleteSortLink:从排序链表中删除指定元素
LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList) LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
{ {
LOS_DL_LIST *listObject = NULL; LOS_DL_LIST *listObject = NULL;
@ -319,7 +319,7 @@ LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader,
} }
LOS_ListDelete(&sortList->sortLinkNode); LOS_ListDelete(&sortList->sortLinkNode);
} }
//OsSortLinkGetNextExpireTime:获取排序链表中下一个到期的时间
LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader) LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
{ {
UINT32 expireTime = OS_INVALID_VALUE; UINT32 expireTime = OS_INVALID_VALUE;
@ -333,7 +333,7 @@ LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sor
} }
return expireTime; return expireTime;
} }
//OsSortLinkUpdateExpireTime:更新排序链表中到期时间
LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader) LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader)
{ {
SortLinkList *sortList = NULL; SortLinkList *sortList = NULL;
@ -349,7 +349,7 @@ LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttr
ROLLNUM_SUB(sortList->idxRollNum, sleepTicks - 1); ROLLNUM_SUB(sortList->idxRollNum, sleepTicks - 1);
} }
} }
//OsSortLinkGetTargetExpireTime:获取指定排序链表元素的到期时间
LITE_OS_SEC_TEXT_MINOR UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader, LITE_OS_SEC_TEXT_MINOR UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader,
const SortLinkList *targetSortList) const SortLinkList *targetSortList)
{ {

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
//栈
#include "securec.h" #include "securec.h"
#include "los_stackinfo_pri.h" #include "los_stackinfo_pri.h"
#ifdef LOSCFG_SHELL #ifdef LOSCFG_SHELL
@ -35,7 +35,7 @@
const StackInfo *g_stackInfo = NULL; const StackInfo *g_stackInfo = NULL;
UINT32 g_stackNum; UINT32 g_stackNum;
//OsStackWaterLineGet:获取栈的使用情况
UINT32 OsStackWaterLineGet(const UINTPTR *stackBottom, const UINTPTR *stackTop, UINT32 *peakUsed) UINT32 OsStackWaterLineGet(const UINTPTR *stackBottom, const UINTPTR *stackTop, UINT32 *peakUsed)
{ {
UINT32 size; UINT32 size;
@ -53,20 +53,20 @@ UINT32 OsStackWaterLineGet(const UINTPTR *stackBottom, const UINTPTR *stackTop,
return LOS_NOK; return LOS_NOK;
} }
} }
//OsExcStackInfoReg:注册异常栈信息
VOID OsExcStackInfoReg(const StackInfo *stackInfo, UINT32 stackNum) VOID OsExcStackInfoReg(const StackInfo *stackInfo, UINT32 stackNum)
{ {
g_stackInfo = stackInfo; g_stackInfo = stackInfo;
g_stackNum = stackNum; g_stackNum = stackNum;
} }
//OsStackInit:初始化任务栈
VOID OsStackInit(VOID *stacktop, UINT32 stacksize) VOID OsStackInit(VOID *stacktop, UINT32 stacksize)
{ {
/* initialize the task stack, write magic num to stack top */ /* initialize the task stack, write magic num to stack top */
(VOID)memset_s(stacktop, stacksize, (INT32)OS_STACK_INIT, stacksize); (VOID)memset_s(stacktop, stacksize, (INT32)OS_STACK_INIT, stacksize);
*((UINTPTR *)stacktop) = OS_STACK_MAGIC_WORD; *((UINTPTR *)stacktop) = OS_STACK_MAGIC_WORD;
} }
//OsGetStackInfo:获取栈信息
VOID OsGetStackInfo(const StackInfo **stackInfo, UINT32 *stackNum) VOID OsGetStackInfo(const StackInfo **stackInfo, UINT32 *stackNum)
{ {
*stackInfo = g_stackInfo; *stackInfo = g_stackInfo;

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/*软件定时器的实现,涉及软件定时器的创建、启动、停止、删除等操作*/
#include "los_swtmr_pri.h" #include "los_swtmr_pri.h"
#include "los_sortlink_pri.h" #include "los_sortlink_pri.h"
#include "los_queue_pri.h" #include "los_queue_pri.h"
@ -52,6 +52,7 @@ LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_swtmrSpin);
* Description: Start Software Timer * Description: Start Software Timer
* Input : swtmr --- Need to start software timer * Input : swtmr --- Need to start software timer
*/ */
//OsSwtmrStart启动软件定时器
LITE_OS_SEC_TEXT VOID OsSwtmrStart(LosSwtmrCB *swtmr) LITE_OS_SEC_TEXT VOID OsSwtmrStart(LosSwtmrCB *swtmr)
{ {
if ((swtmr->overrun == 0) && ((swtmr->mode == LOS_SWTMR_MODE_ONCE) || if ((swtmr->overrun == 0) && ((swtmr->mode == LOS_SWTMR_MODE_ONCE) ||
@ -75,13 +76,14 @@ LITE_OS_SEC_TEXT VOID OsSwtmrStart(LosSwtmrCB *swtmr)
* Description: Delete Software Timer * Description: Delete Software Timer
* Input : swtmr --- Need to delete software timer, When using, Ensure that it can't be NULL. * Input : swtmr --- Need to delete software timer, When using, Ensure that it can't be NULL.
*/ */
//OsSwtmrDelete删除软件定时器
STATIC INLINE VOID OsSwtmrDelete(LosSwtmrCB *swtmr) STATIC INLINE VOID OsSwtmrDelete(LosSwtmrCB *swtmr)
{ {
/* insert to free list */ /* insert to free list */
LOS_ListTailInsert(&g_swtmrFreeList, &swtmr->sortList.sortLinkNode); LOS_ListTailInsert(&g_swtmrFreeList, &swtmr->sortList.sortLinkNode);
swtmr->state = OS_SWTMR_STATUS_UNUSED; swtmr->state = OS_SWTMR_STATUS_UNUSED;
} }
//OsSwtmrUpdate更新软件定时器
STATIC INLINE VOID OsSwtmrUpdate(LosSwtmrCB *swtmr) STATIC INLINE VOID OsSwtmrUpdate(LosSwtmrCB *swtmr)
{ {
if (swtmr->mode == LOS_SWTMR_MODE_ONCE) { if (swtmr->mode == LOS_SWTMR_MODE_ONCE) {
@ -101,6 +103,7 @@ STATIC INLINE VOID OsSwtmrUpdate(LosSwtmrCB *swtmr)
} }
#ifndef LOSCFG_BASE_CORE_SWTMR_IN_ISR #ifndef LOSCFG_BASE_CORE_SWTMR_IN_ISR
//OsSwtmrTask软件定时器任务处理函数用于处理定时器超时事件
LITE_OS_SEC_TEXT VOID OsSwtmrTask(VOID) LITE_OS_SEC_TEXT VOID OsSwtmrTask(VOID)
{ {
UINT32 ret, swtmrHandlerQueue; UINT32 ret, swtmrHandlerQueue;
@ -136,7 +139,7 @@ BOOL IsSwtmrTask(UINT32 taskId)
return FALSE; return FALSE;
} }
#endif #endif
//OsSwtmrTaskCreate创建软件定时器任务
LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID) LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID)
{ {
UINT32 ret, swtmrTaskId; UINT32 ret, swtmrTaskId;
@ -161,7 +164,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID)
return ret; return ret;
} }
#endif #endif
//OsSwtmrInit软件定时器初始化
LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID) LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
{ {
UINT32 size; UINT32 size;
@ -209,6 +212,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
* Description: Tick interrupt interface module of software timer * Description: Tick interrupt interface module of software timer
* Return : LOS_OK on success or error code on failure * Return : LOS_OK on success or error code on failure
*/ */
//OsSwtmrScan扫描软件定时器
LITE_OS_SEC_TEXT VOID OsSwtmrScan(VOID) LITE_OS_SEC_TEXT VOID OsSwtmrScan(VOID)
{ {
SortLinkList *sortList = NULL; SortLinkList *sortList = NULL;
@ -277,6 +281,7 @@ LITE_OS_SEC_TEXT VOID OsSwtmrScan(VOID)
* Description: Get next timeout * Description: Get next timeout
* Return : Count of the Timer list * Return : Count of the Timer list
*/ */
//OsSwtmrGetNextTimeout获取下一个超时时间
LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID) LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
{ {
return OsSortLinkGetNextExpireTime(&OsPercpuGet()->swtmrSortLink); return OsSortLinkGetNextExpireTime(&OsPercpuGet()->swtmrSortLink);
@ -286,6 +291,7 @@ LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
* Description: Stop of Software Timer interface * Description: Stop of Software Timer interface
* Input : swtmr --- the software timer control handler * Input : swtmr --- the software timer control handler
*/ */
//OsSwtmrStop停止软件定时器
LITE_OS_SEC_TEXT STATIC VOID OsSwtmrStop(LosSwtmrCB *swtmr) LITE_OS_SEC_TEXT STATIC VOID OsSwtmrStop(LosSwtmrCB *swtmr)
{ {
SortLinkAttribute *sortLinkHeader = NULL; SortLinkAttribute *sortLinkHeader = NULL;
@ -309,6 +315,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsSwtmrStop(LosSwtmrCB *swtmr)
* Description: Get next software timer expiretime * Description: Get next software timer expiretime
* Input : swtmr --- the software timer control handler * Input : swtmr --- the software timer control handler
*/ */
//获取指定软件定时器的剩余时间
LITE_OS_SEC_TEXT STATIC UINT32 OsSwtmrTimeGet(const LosSwtmrCB *swtmr) LITE_OS_SEC_TEXT STATIC UINT32 OsSwtmrTimeGet(const LosSwtmrCB *swtmr)
{ {
SortLinkAttribute *sortLinkHeader = NULL; SortLinkAttribute *sortLinkHeader = NULL;
@ -325,7 +332,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsSwtmrTimeGet(const LosSwtmrCB *swtmr)
return OsSortLinkGetTargetExpireTime(sortLinkHeader, &swtmr->sortList); return OsSortLinkGetTargetExpireTime(sortLinkHeader, &swtmr->sortList);
} }
//创建一个软件定时器
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval, LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
UINT8 mode, UINT8 mode,
SWTMR_PROC_FUNC handler, SWTMR_PROC_FUNC handler,
@ -377,7 +384,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
return LOS_OK; return LOS_OK;
} }
//启动一个软件定时器
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrId) LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrId)
{ {
LosSwtmrCB *swtmr = NULL; LosSwtmrCB *swtmr = NULL;
@ -421,7 +428,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrId)
LOS_TRACE(SWTMR_START, swtmr->timerId, swtmr->mode, swtmr->overrun, swtmr->interval, swtmr->expiry); LOS_TRACE(SWTMR_START, swtmr->timerId, swtmr->mode, swtmr->overrun, swtmr->interval, swtmr->expiry);
return ret; return ret;
} }
//停止一个软件定时器
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrId) LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrId)
{ {
LosSwtmrCB *swtmr = NULL; LosSwtmrCB *swtmr = NULL;
@ -461,7 +468,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrId)
LOS_TRACE(SWTMR_STOP, swtmr->timerId); LOS_TRACE(SWTMR_STOP, swtmr->timerId);
return ret; return ret;
} }
//获取一个软件定时器的剩余时间
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrTimeGet(UINT16 swtmrId, UINT32 *tick) LITE_OS_SEC_TEXT UINT32 LOS_SwtmrTimeGet(UINT16 swtmrId, UINT32 *tick)
{ {
LosSwtmrCB *swtmr = NULL; LosSwtmrCB *swtmr = NULL;
@ -502,7 +509,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrTimeGet(UINT16 swtmrId, UINT32 *tick)
SWTMR_UNLOCK(intSave); SWTMR_UNLOCK(intSave);
return ret; return ret;
} }
//删除一个软件定时器
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrId) LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrId)
{ {
LosSwtmrCB *swtmr = NULL; LosSwtmrCB *swtmr = NULL;

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/*时钟模块:主要包括系统时钟的初始化、时钟中断处理函数、获取系统tick数等功能*/
#include "los_tick_pri.h" #include "los_tick_pri.h"
#include "los_swtmr_pri.h" #include "los_swtmr_pri.h"
#include "los_task_pri.h" #include "los_task_pri.h"
@ -52,6 +52,7 @@ STATIC WAKEUPFROMINTHOOK g_tickWakeupHook = NULL;
/* /*
* Description : Tick interruption handler * Description : Tick interruption handler
*/ */
//OsTickHandler函数时钟中断处理函数用于处理时钟中断事件。
LITE_OS_SEC_TEXT VOID OsTickHandler(VOID) LITE_OS_SEC_TEXT VOID OsTickHandler(VOID)
{ {
UINT32 intSave; UINT32 intSave;
@ -76,7 +77,7 @@ LITE_OS_SEC_TEXT VOID OsTickHandler(VOID)
OsSwtmrScan(); OsSwtmrScan();
#endif #endif
} }
//OsTickInit初始化系统时钟
LITE_OS_SEC_TEXT_INIT UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond) LITE_OS_SEC_TEXT_INIT UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond)
{ {
if ((systemClock == 0) || if ((systemClock == 0) ||
@ -88,12 +89,12 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond
return LOS_OK; return LOS_OK;
} }
//启动系统时钟
LITE_OS_SEC_TEXT_INIT VOID OsTickStart(VOID) LITE_OS_SEC_TEXT_INIT VOID OsTickStart(VOID)
{ {
HalClockStart(); HalClockStart();
} }
//LOS_TickCountGet函数获取系统tick数
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID) LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID)
{ {
UINT32 intSave; UINT32 intSave;
@ -109,12 +110,12 @@ LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID)
return tick; return tick;
} }
//LOS_CyclePerTickGet函数获取每个tick所对应的CPU周期数
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CyclePerTickGet(VOID) LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CyclePerTickGet(VOID)
{ {
return g_sysClock / KERNEL_TICK_PER_SECOND; return g_sysClock / KERNEL_TICK_PER_SECOND;
} }
//LOS_GetCpuCycle函数获取CPU周期数
LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *highCnt, UINT32 *lowCnt) LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *highCnt, UINT32 *lowCnt)
{ {
UINT64 cycle; UINT64 cycle;
@ -129,7 +130,7 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *highCnt, UINT32 *lowCnt)
/* get the low 32 bits */ /* get the low 32 bits */
*lowCnt = (UINT32)(cycle & 0xFFFFFFFFULL); *lowCnt = (UINT32)(cycle & 0xFFFFFFFFULL);
} }
//LOS_CurrNanosec函数获取当前的纳秒数
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_CurrNanosec(VOID) LITE_OS_SEC_TEXT_MINOR UINT64 LOS_CurrNanosec(VOID)
{ {
UINT64 nanos; UINT64 nanos;
@ -137,7 +138,7 @@ LITE_OS_SEC_TEXT_MINOR UINT64 LOS_CurrNanosec(VOID)
nanos = HalClockGetCycles() * (OS_SYS_NS_PER_SECOND / OS_SYS_NS_PER_MS) / (g_sysClock / OS_SYS_NS_PER_MS); nanos = HalClockGetCycles() * (OS_SYS_NS_PER_SECOND / OS_SYS_NS_PER_MS) / (g_sysClock / OS_SYS_NS_PER_MS);
return nanos; return nanos;
} }
//LOS_MS2Tick函数将毫秒转换为tick数
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MS2Tick(UINT32 millisec) LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MS2Tick(UINT32 millisec)
{ {
UINT64 delaySec; UINT64 delaySec;
@ -149,17 +150,17 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MS2Tick(UINT32 millisec)
delaySec = (UINT64)millisec * KERNEL_TICK_PER_SECOND; delaySec = (UINT64)millisec * KERNEL_TICK_PER_SECOND;
return (UINT32)((delaySec + OS_SYS_MS_PER_SECOND - 1) / OS_SYS_MS_PER_SECOND); return (UINT32)((delaySec + OS_SYS_MS_PER_SECOND - 1) / OS_SYS_MS_PER_SECOND);
} }
//LOS_Tick2MS函数将tick数转换为毫秒数
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_Tick2MS(UINT32 tick) LITE_OS_SEC_TEXT_MINOR UINT32 LOS_Tick2MS(UINT32 tick)
{ {
return (UINT32)(((UINT64)tick * OS_SYS_MS_PER_SECOND) / KERNEL_TICK_PER_SECOND); return (UINT32)(((UINT64)tick * OS_SYS_MS_PER_SECOND) / KERNEL_TICK_PER_SECOND);
} }
//LOS_Udelay函数微秒级延迟函数
LITE_OS_SEC_TEXT_MINOR VOID LOS_Udelay(UINT32 usecs) LITE_OS_SEC_TEXT_MINOR VOID LOS_Udelay(UINT32 usecs)
{ {
HalDelayUs(usecs); HalDelayUs(usecs);
} }
//LOS_Mdelay函数毫秒级延迟函数
LITE_OS_SEC_TEXT_MINOR VOID LOS_Mdelay(UINT32 msecs) LITE_OS_SEC_TEXT_MINOR VOID LOS_Mdelay(UINT32 msecs)
{ {
UINT32 delayUs = (UINT32_MAX / OS_SYS_US_PER_MS) * OS_SYS_US_PER_MS; UINT32 delayUs = (UINT32_MAX / OS_SYS_US_PER_MS) * OS_SYS_US_PER_MS;

Loading…
Cancel
Save