feature: Support kernel signal and POSIX API.

内核支持信号功能,支持注册、屏蔽、等待及触发等操作。

close #I4R72Q

Signed-off-by: JerryH <huangjieliang@huawei.com>
Change-Id: I26fb11a03d1899c6f7e665f0798824c578d592a6
This commit is contained in:
JerryH
2022-01-20 10:06:59 +08:00
parent 1f8151649b
commit 8d7468b44c
49 changed files with 1847 additions and 188 deletions

View File

@@ -651,12 +651,10 @@ extern UINT8 *m_aucSysMem0;
/**
* @ingroup los_config
* Configuration item to enable pipe device.
* Configuration item to enable kernel signal.
*/
#ifndef LOSCFG_POSIX_PIPE_API
#ifndef LOSCFG_PIPE_DEV
#define LOSCFG_POSIX_PIPE_API 0
#endif
#ifndef LOSCFG_KERNEL_SIGNAL
#define LOSCFG_KERNEL_SIGNAL 0
#endif
#ifdef __cplusplus

View File

@@ -430,6 +430,16 @@ extern "C" {
*/
#define LOS_ERRNO_TSK_SCHED_LOCKED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x28)
/**
* @ingroup los_task
* Task error code: The task is processing signals.
*
* Value: 0x02000229
*
* Solution: Check and Stop the trigger signal so that the task is not processing the signal.
*/
#define LOS_ERRNO_TSK_PROCESS_SIGNAL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x29)
/**
* @ingroup los_task
* Define the type of the task entry function.
@@ -1293,6 +1303,13 @@ extern UINT32 LOS_TaskDetach(UINT32 taskID);
*/
#define OS_TASK_FLAG_SYSTEM_TASK 0x1000U
/**
* @ingroup los_task
* Flag that indicates the task is processing signal.
*
*/
#define OS_TASK_FLAG_SIGNAL 0x2000
/**
* @ingroup los_task
* Flag that indicates the task or task control block status.
@@ -1480,6 +1497,9 @@ typedef struct {
UINT32 eventMode; /**< Event mode */
VOID *msg; /**< Memory allocated to queues */
INT32 errorNo;
#if (LOSCFG_KERNEL_SIGNAL == 1)
VOID *sig; /**< Task signal */
#endif
LOSCFG_TASK_STRUCT_EXTENSION /**< Task extension field */
} LosTaskCB;
@@ -1754,6 +1774,11 @@ extern VOID *OsTskUserStackInit(VOID* stackPtr, VOID* userSP, UINT32 userStackSi
extern UINT32 OsPmEnterHandlerSet(VOID (*func)(VOID));
STATIC INLINE LosTaskCB *OsCurrTaskGet(VOID)
{
return g_losTask.runTask;
}
#ifdef __cplusplus
#if __cplusplus
}

View File

@@ -78,6 +78,10 @@
#include "pipe_impl.h"
#endif
#if (LOSCFG_KERNEL_SIGNAL == 1)
#include "los_signal.h"
#endif
/*****************************************************************************
Function : LOS_Reboot
Description : system exception, die in here, wait for watchdog.
@@ -250,6 +254,14 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID)
}
#endif
#if (LOSCFG_KERNEL_SIGNAL == 1)
ret = OsSignalInit();
if (ret != LOS_OK) {
PRINT_ERR("Signal init failed!\n");
return ret;
}
#endif
return LOS_OK;
}

View File

@@ -683,7 +683,10 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsNewTaskInit(LosTaskCB *taskCB, TSK_INIT_PARAM_S *
taskCB->eventMask = 0;
taskCB->taskName = taskInitParam->pcName;
taskCB->msg = NULL;
taskCB->stackPointer = ArchTskStackInit(taskCB->taskID, taskInitParam->uwStackSize, topOfStack);
#if (LOSCFG_KERNEL_SIGNAL == 1)
taskCB->sig = NULL;
#endif
SET_SORTLIST_VALUE(&taskCB->sortList, OS_SORT_LINK_INVALID_TIME);
LOS_EventInit(&(taskCB->event));
@@ -691,6 +694,10 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsNewTaskInit(LosTaskCB *taskCB, TSK_INIT_PARAM_S *
taskCB->taskStatus |= OS_TASK_FLAG_JOINABLE;
LOS_ListInit(&taskCB->joinList);
}
*((UINT32 *)taskCB->topOfStack) = OS_TASK_MAGIC_WORD;
taskCB->stackPointer = ArchTskStackInit(taskCB->taskID, taskCB->stackSize, (VOID *)taskCB->topOfStack);
return LOS_OK;
}
@@ -744,6 +751,9 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S
LOS_IntRestore(intSave);
return LOS_ERRNO_TSK_NO_MEMORY;
}
/* initialize the task stack, write magic num to stack top */
(VOID)memset_s(topOfStack, taskInitParam->uwStackSize,
(INT32)(OS_TASK_STACK_INIT & 0xFF), taskInitParam->uwStackSize);
retVal = OsNewTaskInit(taskCB, taskInitParam, topOfStack);
if (retVal != LOS_OK) {
@@ -1066,6 +1076,11 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID)
return LOS_ERRNO_TSK_ALREADY_EXIT;
}
if (taskCB->taskStatus & OS_TASK_FLAG_SIGNAL) {
LOS_IntRestore(intSave);
return LOS_ERRNO_TSK_PROCESS_SIGNAL;
}
/* If the task is running and scheduler is locked then you can not delete it */
if (((taskCB->taskStatus) & OS_TASK_STATUS_RUNNING) && (g_losTaskLock != 0)) {
PRINT_INFO("In case of task lock, task deletion is not recommended\n");
@@ -1084,6 +1099,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID)
(VOID)memset_s((VOID *)&g_cpup[taskCB->taskID], sizeof(OsCpupCB), 0, sizeof(OsCpupCB));
#endif
#if (LOSCFG_KERNEL_SIGNAL == 1)
if (taskCB->sig != NULL) {
LOS_MemFree(OS_SYS_MEM_ADDR, taskCB->sig);
taskCB->sig = NULL;
}
#endif
LOSCFG_TASK_DELETE_EXTENSION_HOOK(taskCB);
if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {