|
|
|
@ -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.
|
|
|
|
|
* --------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/*关于LiteOS中任务管理模块的部分实现,包括任务控制块的初始化、任务创建、任务删除等功能*/
|
|
|
|
|
#include "los_task_pri.h"
|
|
|
|
|
#include "los_priqueue_pri.h"
|
|
|
|
|
#include "los_sem_pri.h"
|
|
|
|
@ -282,7 +282,7 @@ LITE_OS_SEC_TEXT VOID OsTaskScan(VOID)
|
|
|
|
|
LOS_Schedule();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//OsTaskInit用于初始化任务管理模块,包括任务控制块数组、空闲任务列表、任务回收列表等数据结构的初始化
|
|
|
|
|
LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID)
|
|
|
|
|
{
|
|
|
|
|
UINT32 index;
|
|
|
|
@ -335,7 +335,7 @@ UINT32 OsGetIdleTaskId(VOID)
|
|
|
|
|
Percpu *perCpu = OsPercpuGet();
|
|
|
|
|
return perCpu->idleTaskId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//创建空闲任务(Idle Task)
|
|
|
|
|
LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
|
|
|
|
|
{
|
|
|
|
|
UINT32 ret;
|
|
|
|
@ -363,6 +363,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
|
|
|
|
|
* Description : get id of current running task.
|
|
|
|
|
* Return : task id
|
|
|
|
|
*/
|
|
|
|
|
//读取任务ID
|
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID)
|
|
|
|
|
{
|
|
|
|
|
LosTaskCB *runTask = OsCurrTaskGet();
|
|
|
|
@ -372,7 +373,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID)
|
|
|
|
|
}
|
|
|
|
|
return runTask->taskId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取当前正在运行的任务的任务名称
|
|
|
|
|
LITE_OS_SEC_TEXT CHAR *OsCurTaskNameGet(VOID)
|
|
|
|
|
{
|
|
|
|
|
LosTaskCB *runTask = OsCurrTaskGet();
|
|
|
|
@ -428,12 +429,12 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_LowpowerHookReg(LOWPOWERIDLEHOOK hook)
|
|
|
|
|
g_lowPowerHook = hook;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//注册空闲任务钩子函数,即在系统空闲时执行的函数
|
|
|
|
|
LITE_OS_SEC_TEXT_MINOR VOID LOS_IdleHandlerHookReg(IDLEHANDLERHOOK hook)
|
|
|
|
|
{
|
|
|
|
|
g_idleHandlerHook = hook;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//检查任务是否分离(detached)
|
|
|
|
|
STATIC BOOL OsTaskDeleteCheckDetached(const LosTaskCB *taskCB)
|
|
|
|
|
{
|
|
|
|
|
#if LOSCFG_COMPAT_POSIX
|
|
|
|
@ -442,7 +443,7 @@ STATIC BOOL OsTaskDeleteCheckDetached(const LosTaskCB *taskCB)
|
|
|
|
|
return TRUE;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除已分离的任务
|
|
|
|
|
STATIC VOID OsTaskDeleteDetached(const LosTaskCB *taskCB)
|
|
|
|
|
{
|
|
|
|
|
UINT32 intSave;
|
|
|
|
@ -451,7 +452,7 @@ STATIC VOID OsTaskDeleteDetached(const LosTaskCB *taskCB)
|
|
|
|
|
LOS_IntRestore(intSave);
|
|
|
|
|
(VOID)LOS_TaskDelete(taskCB->taskId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除已加入的任务
|
|
|
|
|
STATIC VOID OsTaskDeleteJoined(LosTaskCB *taskCB, VOID *ret)
|
|
|
|
|
{
|
|
|
|
|
#ifdef LOSCFG_COMPAT_POSIX
|
|
|
|
@ -481,6 +482,8 @@ STATIC VOID OsTaskDeleteJoined(LosTaskCB *taskCB, VOID *ret)
|
|
|
|
|
* Description : All task entry
|
|
|
|
|
* Input : taskId --- The ID of the task to be run
|
|
|
|
|
*/
|
|
|
|
|
//执行任务的实际代码,并根据任务的属性判断是否需要删除任务
|
|
|
|
|
//如果任务是分离的,则直接删除任务;如果任务是加入的,则将任务加入的其他任务唤醒,并重新调度任务
|
|
|
|
|
LITE_OS_SEC_TEXT_INIT VOID OsTaskEntry(UINT32 taskId)
|
|
|
|
|
{
|
|
|
|
|
LosTaskCB *taskCB = NULL;
|
|
|
|
@ -511,7 +514,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsTaskEntry(UINT32 taskId)
|
|
|
|
|
OsTaskDeleteJoined(taskCB, ret);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//对任务初始化参数进行检查,确保任务参数的合法性
|
|
|
|
|
STATIC UINT32 OsTaskInitParamCheck(const TSK_INIT_PARAM_S *initParam)
|
|
|
|
|
{
|
|
|
|
|
if (initParam == NULL) {
|
|
|
|
@ -566,7 +569,7 @@ STATIC UINT32 OsTaskCreateParamCheckStatic(const UINT32 *taskId,
|
|
|
|
|
return LOS_OK;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//对任务创建参数进行检查,确保参数的合法性。如果参数不合法,则返回相应的错误码;否则返回成功
|
|
|
|
|
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsTaskCreateParamCheck(const UINT32 *taskId,
|
|
|
|
|
TSK_INIT_PARAM_S *initParam, VOID **pool)
|
|
|
|
|
{
|
|
|
|
@ -776,6 +779,7 @@ LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskDelAction(LosTaskCB *taskCB, BOOL useUsr
|
|
|
|
|
* 3. Do the deletion in hard-irq
|
|
|
|
|
* then LOS_TaskDelete will directly return with 'ret' value.
|
|
|
|
|
*/
|
|
|
|
|
//OsTaskDeleteCheckOnRun函数用来检查是否需要在任务运行时进行删除操作
|
|
|
|
|
LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskDeleteCheckOnRun(LosTaskCB *taskCB, UINT32 *ret)
|
|
|
|
|
{
|
|
|
|
|
/* init default out return value */
|
|
|
|
@ -813,7 +817,7 @@ LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskDeleteCheckOnRun(LosTaskCB *taskCB, UINT
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//OsTaskCBInit函数用于初始化任务控制块,设置任务的各种属性和状态
|
|
|
|
|
LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam,
|
|
|
|
|
VOID *stackPtr, const VOID *topStack, BOOL useUsrStack)
|
|
|
|
|
{
|
|
|
|
@ -869,7 +873,7 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT
|
|
|
|
|
(VOID)memset_s(&taskCB->schedStat, sizeof(SchedStat), 0, sizeof(SchedStat));
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//OsTaskGetFreeTaskCB函数用于获取一个空闲的任务控制块
|
|
|
|
|
STATIC UINT32 OsTaskGetFreeTaskCB(LosTaskCB **taskCB)
|
|
|
|
|
{
|
|
|
|
|
if (LOS_ListEmpty(&g_losFreeTask)) {
|
|
|
|
@ -883,7 +887,7 @@ STATIC UINT32 OsTaskGetFreeTaskCB(LosTaskCB **taskCB)
|
|
|
|
|
LOS_ListDelete(LOS_DL_LIST_FIRST(&g_losFreeTask));
|
|
|
|
|
return LOS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//OsTaskCreateOnly函数用于创建一个新的任务,其中会对参数进行合法性检查
|
|
|
|
|
STATIC UINT32 OsTaskCreateOnly(UINT32 *taskId, TSK_INIT_PARAM_S *initParam, VOID *topStack, BOOL useUsrStack)
|
|
|
|
|
{
|
|
|
|
|
UINT32 intSave, errRet;
|
|
|
|
@ -947,7 +951,7 @@ LOS_ERREND:
|
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
|
return errRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//OsTaskResume函数用于恢复一个被挂起的任务
|
|
|
|
|
STATIC VOID OsTaskResume(const UINT32 *taskId)
|
|
|
|
|
{
|
|
|
|
|
UINT32 intSave;
|
|
|
|
@ -998,7 +1002,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskId, TSK_INIT_PARAM_S
|
|
|
|
|
{
|
|
|
|
|
return OsTaskCreateOnly(taskId, initParam, NULL, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//LOS_TaskCreate该函数用于创建一个新的任务,包括任务的名称、优先级、栈大小等参数的设置
|
|
|
|
|
//在创建任务时,需要进行一些参数的合法性检查,例如是否超出最大任务数量、是否有足够的堆栈空间等
|
|
|
|
|
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskId, TSK_INIT_PARAM_S *initParam)
|
|
|
|
|
{
|
|
|
|
|
UINT32 ret;
|
|
|
|
@ -1012,7 +1017,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskId, TSK_INIT_PARAM_S *in
|
|
|
|
|
|
|
|
|
|
return LOS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//LOS_TaskDelete用于删除一个已经存在的任务
|
|
|
|
|
//在删除任务时,需要对任务的状态进行判断。如果任务正在运行,则将其标记为删除状态并放入回收列表;否则直接释放任务占用的资源
|
|
|
|
|
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskId)
|
|
|
|
|
{
|
|
|
|
|
LosTaskCB *taskCB = NULL;
|
|
|
|
@ -1072,7 +1078,7 @@ LOS_RETURN:
|
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
|
return errRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//LOS_TaskResume函数用于恢复一个挂起的任务
|
|
|
|
|
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskResume(UINT32 taskId)
|
|
|
|
|
{
|
|
|
|
|
UINT32 intSave;
|
|
|
|
@ -1136,6 +1142,7 @@ LOS_ERREND:
|
|
|
|
|
* 3. Do the suspension in hard-irq
|
|
|
|
|
* then LOS_TaskSuspend will directly return with 'ret' value.
|
|
|
|
|
*/
|
|
|
|
|
//OsTaskSuspendCheckOnRun:检查当前任务是否需要挂起的函数,根据条件判断是否需要进行任务挂起操作
|
|
|
|
|
LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskSuspendCheckOnRun(LosTaskCB *taskCB, UINT32 *ret)
|
|
|
|
|
{
|
|
|
|
|
/* init default out return value */
|
|
|
|
@ -1164,7 +1171,8 @@ LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskSuspendCheckOnRun(LosTaskCB *taskCB, UIN
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//LOS_TaskSuspend:挂起指定任务的函数
|
|
|
|
|
//如果任务已经处于挂起状态或者正在运行,并且不满足挂起条件,则直接返回错误码;否则执行挂起操作
|
|
|
|
|
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskSuspend(UINT32 taskId)
|
|
|
|
|
{
|
|
|
|
|
UINT32 intSave;
|
|
|
|
@ -1218,7 +1226,7 @@ LOS_RETURN:
|
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
|
return errRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//LOS_TaskDelay该函数用于让任务进入延时状态,在指定的时间后重新被调度执行
|
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_TaskDelay(UINT32 tick)
|
|
|
|
|
{
|
|
|
|
|
UINT32 intSave;
|
|
|
|
@ -1250,7 +1258,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_TaskDelay(UINT32 tick)
|
|
|
|
|
|
|
|
|
|
return LOS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//LOS_TaskDelay:将任务进入延时状态,在指定的时间后重新被调度执行,如果当前在中断中或者不可抢占,则返回相应的错误码
|
|
|
|
|
LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskPriGet(UINT32 taskId)
|
|
|
|
|
{
|
|
|
|
|
UINT32 intSave;
|
|
|
|
@ -1273,7 +1281,7 @@ LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskPriGet(UINT32 taskId)
|
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
|
return priority;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//LOS_TaskPriGet:获取指定任务的优先级
|
|
|
|
|
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskId, UINT16 taskPrio)
|
|
|
|
|
{
|
|
|
|
|
BOOL isReady = FALSE;
|
|
|
|
@ -1325,7 +1333,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskId, UINT16 taskPrio)
|
|
|
|
|
}
|
|
|
|
|
return LOS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//LOS_TaskPriSet:设置指定任务的优先级,根据任务当前状态选择不同的处理方式
|
|
|
|
|
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CurTaskPriSet(UINT16 taskPrio)
|
|
|
|
|
{
|
|
|
|
|
return LOS_TaskPriSet(OsCurrTaskGet()->taskId, taskPrio);
|
|
|
|
@ -1337,6 +1345,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CurTaskPriSet(UINT16 taskPrio)
|
|
|
|
|
* taskStatus --- task status
|
|
|
|
|
* timeOut --- Expiry time
|
|
|
|
|
* Return : LOS_OK on success or LOS_NOK on failure
|
|
|
|
|
* OsTaskWait和OsTaskWake:任务等待和唤醒的辅助函数
|
|
|
|
|
*/
|
|
|
|
|
VOID OsTaskWait(LOS_DL_LIST *list, UINT16 taskStatus, UINT32 timeout)
|
|
|
|
|
{
|
|
|
|
@ -1373,7 +1382,7 @@ VOID OsTaskWake(LosTaskCB *resumedTask, UINT16 taskStatus)
|
|
|
|
|
OsPriQueueEnqueue(&resumedTask->pendList, resumedTask->priority);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//LOS_TaskYield用于使当前任务主动放弃 CPU 控制权,让出 CPU 给其他高优先级任务执行
|
|
|
|
|
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID)
|
|
|
|
|
{
|
|
|
|
|
UINT32 tskCount;
|
|
|
|
@ -1412,6 +1421,8 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID)
|
|
|
|
|
return LOS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//LOS_TaskLock和LOS_TaskUnlock:任务锁定和解锁函数,用于保护临界区
|
|
|
|
|
|
|
|
|
|
LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskLock(VOID)
|
|
|
|
|
{
|
|
|
|
|
UINT32 intSave;
|
|
|
|
@ -1446,7 +1457,7 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskUnlock(VOID)
|
|
|
|
|
|
|
|
|
|
LOS_IntRestore(intSave);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//LOS_TaskInfoGet:获取指定任务的信息,包括任务名、栈大小、堆栈使用情况等
|
|
|
|
|
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskId, TSK_INFO_S *taskInfo)
|
|
|
|
|
{
|
|
|
|
|
UINT32 intSave;
|
|
|
|
@ -1503,7 +1514,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskId, TSK_INFO_S *taskInf
|
|
|
|
|
|
|
|
|
|
return LOS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//LOS_TaskCpuAffiSet和LOS_TaskCpuAffiGet:设置和获取任务的 CPU 亲和性,仅在支持多核的情况下有效
|
|
|
|
|
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiSet(UINT32 taskId, UINT16 cpuAffiMask)
|
|
|
|
|
{
|
|
|
|
|
#ifdef LOSCFG_KERNEL_SMP
|
|
|
|
@ -1580,6 +1591,7 @@ LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskCpuAffiGet(UINT32 taskId)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Description : Process pending signals tagged by others cores
|
|
|
|
|
*OsTaskProcSignal:处理挂起、删除任务等信号
|
|
|
|
|
*/
|
|
|
|
|
LITE_OS_SEC_TEXT_MINOR UINT32 OsTaskProcSignal(VOID)
|
|
|
|
|
{
|
|
|
|
|