pull/1/head
tree 1 year ago
parent 99c01f46b7
commit a5ed7a0caa

@ -26,6 +26,10 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*这是一个位图bitmap的实现用于对位图进行设置、清除和获取最高/最低位的操作。
使32UINT32
*/
#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) {

@ -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;

@ -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)
{

@ -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 */

@ -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();

@ -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();

@ -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)
{

@ -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;

@ -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
*/
//OsMuxInitMutex初始化函数用于初始化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;

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

@ -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);

Loading…
Cancel
Save