Description: refactor

Reviewed-by: likailong
This commit is contained in:
Caoruihong
2020-12-16 17:21:23 +08:00
parent b295e8e28f
commit 1405111aa9
269 changed files with 6962 additions and 9592 deletions
-11
View File
@@ -1,11 +0,0 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
import("//build/lite/config/component/lite_component.gni")
lite_component("kal") {
features = [
"cmsis",
"posix",
#"kal", # kal is not supported now.
]
}
-15
View File
@@ -1,15 +0,0 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
import("//build/lite/config/component/lite_component.gni")
static_library("cmsis") {
sources = [ "cmsis_liteos.c" ]
include_dirs = [
"//kernel/liteos_m/kal",
"//third_party/bounds_checking_function/include",
]
defines = [ "LITEOS_WIFI_IOT_VERSION" ]
cflags = [ "-Wno-error" ]
}
Executable → Regular
View File
Executable → Regular
+23 -59
View File
@@ -30,24 +30,21 @@
*/
#include "cmsis_os.h"
#include "los_typedef.h"
#include "los_printf.h"
#include "los_event.h"
#include "los_membox.h"
#include "los_memory.h"
#include "los_hwi.h"
#include "los_interrupt.h"
#include "los_mux.h"
#include "los_queue.h"
#include "los_sem.h"
#include "los_swtmr.h"
#include "los_task.h"
#include "kal.h"
#include "los_debug.h"
#include "los_mux_pri.h"
#include "los_queue_pri.h"
#include "los_sem_pri.h"
#include "los_swtmr_pri.h"
#include "los_sys_pri.h"
#include "los_task_pri.h"
#include "los_tick_pri.h"
#include "string.h"
#include "securec.h"
//#include "system_config.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
@@ -74,7 +71,7 @@ const osVersion_t g_stLosVersion = { 001, 001 };
((UINT32)LITEOS_VERSION_BUILD * 1UL))
#define KERNEL_ID "HUAWEI-LiteOS"
#define UNUSED(var) do { (void)var; } while(0)
#define UNUSED(var) do { (void)var; } while (0)
// ==== Kernel Management Functions ====
uint32_t osTaskStackWaterMarkGet(UINT32 taskID);
@@ -659,7 +656,7 @@ uint32_t osThreadGetCount(void)
// ==== Generic Wait Functions ====
WEAK UINT32 LOS_HalDelay(UINT32 ticks)
WEAK UINT32 HalDelay(UINT32 ticks)
{
UNUSED(ticks);
return LOS_ERRNO_TSK_DELAY_IN_INT;
@@ -668,12 +665,12 @@ WEAK UINT32 LOS_HalDelay(UINT32 ticks)
osStatus_t osDelay(uint32_t ticks)
{
UINT32 uwRet = 0;
UINT32 uwRet;
if (ticks == 0) {
return osOK;
}
if (osKernelGetState() != osKernelRunning) {
uwRet = LOS_HalDelay(ticks);
uwRet = HalDelay(ticks);
} else {
uwRet = LOS_TaskDelay(ticks);
}
@@ -706,41 +703,14 @@ osStatus_t osDelayUntil(uint32_t ticks)
}
// ==== Timer Management Functions ====
#if (LOSCFG_BASE_CORE_SWTMR == YES)
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
#if 0
osTimerId_t osTimerExtNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr,
os_timer_rouses_type ucRouses, os_timer_align_type ucSensitive)
{
UNUSED(attr);
UINT16 usSwTmrID;
UINT8 mode;
if ((OS_INT_ACTIVE) || (NULL == func) || ((osTimerOnce != type) && (osTimerPeriodic != type))) {
return (osTimerId_t)NULL;
}
if (osTimerOnce == type) {
mode = LOS_SWTMR_MODE_NO_SELFDELETE;
} else {
mode = LOS_SWTMR_MODE_PERIOD;
}
if (LOS_OK != LOS_SwtmrCreate(1, mode, (SWTMR_PROC_FUNC)func, &usSwTmrID, (UINT32)(UINTPTR)argument, ucRouses, ucSensitive)) {
return (osTimerId_t)NULL;
}
return (osTimerId_t)OS_SWT_FROM_SID(usSwTmrID);
}
#endif
#endif
#if 1
#if (LOSCFG_BASE_CORE_SWTMR == 1)
osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr)
{
UNUSED(attr);
UINT16 usSwTmrID;
UINT8 mode;
if ((OS_INT_ACTIVE) || (NULL == func) || ((osTimerOnce != type) && (osTimerPeriodic != type))) {
if ((NULL == func) || ((osTimerOnce != type) && (osTimerPeriodic != type))) {
return (osTimerId_t)NULL;
}
@@ -749,7 +719,7 @@ osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, c
} else {
mode = LOS_SWTMR_MODE_PERIOD;
}
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
if (LOS_OK != LOS_SwtmrCreate(1, mode, (SWTMR_PROC_FUNC)func, &usSwTmrID, (UINT32)(UINTPTR)argument,
osTimerRousesAllow, osTimerAlignIgnore)) {
return (osTimerId_t)NULL;
@@ -762,7 +732,7 @@ osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, c
return (osTimerId_t)OS_SWT_FROM_SID(usSwTmrID);
}
#endif
osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)
{
UINT32 uwRet;
@@ -772,9 +742,11 @@ osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)
return osErrorParameter;
}
UINTPTR intSave = LOS_IntLock();
pstSwtmr = (SWTMR_CTRL_S *)timer_id;
pstSwtmr->uwInterval = ticks;
uwRet = LOS_SwtmrStart(pstSwtmr->usTimerID);
LOS_IntRestore(intSave);
if (LOS_OK == uwRet) {
return osOK;
} else if (LOS_ERRNO_SWTMR_ID_INVALID == uwRet) {
@@ -797,10 +769,6 @@ osStatus_t osTimerStop(osTimerId_t timer_id)
UINT32 uwRet;
SWTMR_CTRL_S *pstSwtmr = (SWTMR_CTRL_S *)timer_id;
if (OS_INT_ACTIVE) {
return osErrorISR;
}
if (NULL == pstSwtmr) {
return osErrorParameter;
}
@@ -818,7 +786,7 @@ osStatus_t osTimerStop(osTimerId_t timer_id)
uint32_t osTimerIsRunning(osTimerId_t timer_id)
{
if ((OS_INT_ACTIVE) || (NULL == timer_id)) {
if (NULL == timer_id) {
return 0;
}
@@ -831,10 +799,6 @@ osStatus_t osTimerDelete(osTimerId_t timer_id)
UINT32 uwRet;
SWTMR_CTRL_S *pstSwtmr = (SWTMR_CTRL_S *)timer_id;
if (OS_INT_ACTIVE) {
return osErrorISR;
}
if (NULL == pstSwtmr) {
return osErrorParameter;
}
@@ -1014,7 +978,7 @@ osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id)
}
// ==== Mutex Management Functions ====
#if (LOSCFG_BASE_IPC_MUX == YES)
#if (LOSCFG_BASE_IPC_MUX == 1)
osMutexId_t osMutexNew(const osMutexAttr_t *attr)
{
UINT32 uwRet;
@@ -1122,7 +1086,7 @@ osStatus_t osMutexDelete(osMutexId_t mutex_id)
#endif
// ==== Semaphore Management Functions ====
#if (LOSCFG_BASE_IPC_SEM == YES)
#if (LOSCFG_BASE_IPC_SEM == 1)
osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr)
{
@@ -1241,7 +1205,7 @@ osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id)
// ==== Message Queue Management Functions ====
#if (LOSCFG_BASE_IPC_QUEUE == YES)
#if (LOSCFG_BASE_IPC_QUEUE == 1)
osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr)
{
UINT32 uwQueueID;
Executable → Regular
+4
View File
@@ -29,6 +29,9 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CMSIS_OS_H_
#define CMSIS_OS_H_
#include "los_config.h"
#if (CMSIS_OS_VER == 1)
@@ -37,3 +40,4 @@
#include "cmsis_os2.h"
#endif
#endif /* CMSIS_OS_H_ */
Executable → Regular
+4 -4
View File
@@ -656,8 +656,8 @@ uint32_t osKernelGetSysTimerFreq (void);
/**
* @brief Creates an active thread.
*
* The priority ranges from 9 to 38. Select a proper priority as required.
* The maximum of tasks is LOSCFG_BASE_CORE_TSK_LIMIT(LOSCFG_BASE_CORE_TSK_LIMIT is defined in the traget_config.h).
* The task priority ranges from 9 (highest priority) to 38 (lowest priority). {@code LOSCFG_BASE_CORE_TSK_LIMIT} declared in target_config.h specifies the
maximum number of tasks running in this system.
* @param func Indicates the entry of the thread callback function.
* @param argument Indicates the pointer to the argument passed to the thread.
* @param attr Indicates the thread attributes.
@@ -956,7 +956,7 @@ uint32_t osEventFlagsGet (osEventFlagsId_t ef_id);
/**
* @brief Waits for event flags to trigger.
*
* When the specified flag of the event is set, the function returns immediately. Otherwise, the thread is blocked.
* This function is blocked if the specified event flags are not set via {@code flags}.
* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
* @param flags Indicates the event flags to trigger.
* @param options Indicates the configuration of the event flags to trigger.
@@ -1054,7 +1054,7 @@ const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id);
* @brief Acquires a token of a semaphore object.
*
* @param semaphore_id Indicates the semaphore ID, which is obtained using osSemaphoreNew.
* @param timeout Indicates the timeout duration. This parameter is the number of ticks.
* @param timeout Indicates the timeout duration, in ticks.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
Executable → Regular
+3 -3
View File
@@ -33,7 +33,7 @@
#define HOS_CMSIS_ADP_H
#include "cmsis_os.h"
#include "ohos_types.h"
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
@@ -43,8 +43,8 @@ extern "C" {
typedef struct {
osSemaphoreAttr_t attr;
uint32 maxCount;
uint32 initialCount;
UINT32 maxCount;
UINT32 initialCount;
} SemaphoreEx;
#ifdef __cplusplus
+71
View File
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "kal.h"
#include "los_swtmr.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cpluscplus */
#endif /* __cpluscplus */
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
osTimerId_t osTimerExtNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr,
osTimerRouses_t ucRouses, osTimerAlign_t ucSensitive)
{
UNUSED(attr);
UINT16 usSwTmrID;
UINT8 mode;
if ((OS_INT_ACTIVE) || (NULL == func) || ((osTimerOnce != type) && (osTimerPeriodic != type))) {
return (osTimerId_t)NULL;
}
if (osTimerOnce == type) {
mode = LOS_SWTMR_MODE_NO_SELFDELETE;
} else {
mode = LOS_SWTMR_MODE_PERIOD;
}
if (LOS_OK != LOS_SwtmrCreate(1, mode, (SWTMR_PROC_FUNC)func, &usSwTmrID,
(UINT32)(UINTPTR)argument, ucRouses, ucSensitive)) {
return (osTimerId_t)NULL;
}
return (osTimerId_t)OS_SWT_FROM_SID(usSwTmrID);
}
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cpluscplus */
#endif /* __cpluscplus */
+78
View File
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _KAL_H
#define _KAL_H
#include "cmsis_os2.h"
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
/**
* @brief Enumerates timer permissions.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** The timer is not allowed to wake up the RTOS. */
osTimerRousesIgnore = 0,
/** The timer is allowed to wake up the RTOS. */
osTimerRousesAllow = 1
} osTimerRouses_t;
/**
* @brief Enumerates timer alignment modes.
*
*/
typedef enum {
/** The timer ignores alignment. */
osTimerAlignIgnore = 0,
/** The timer allows alignment. */
osTimerAlignAllow = 1
} osTimerAlign_t;
osTimerId_t osTimerExtNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr,
osTimerRouses_t ucRouses, osTimerAlign_t ucSensitive);
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _KAL_H */
-15
View File
@@ -1,15 +0,0 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
import("//build/lite/config/component/lite_component.gni")
static_library("kal") {
sources = [ "kal.c" ]
include_dirs = [
"//kernel/liteos_m/kal",
"//third_party/bounds_checking_function/include",
]
defines = [ "LITEOS_WIFI_IOT_VERSION" ]
cflags = [ "-Werror" ]
}
-220
View File
@@ -1,220 +0,0 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "securec.h"
#include "hi_mem.h"
#include "los_task.h"
#include "los_swtmr.h"
#include "los_swtmr_pri.h"
#include "los_hwi.h"
#include "kal.h"
#ifdef __cplusplus
#define NULL 0L
#else
#ifndef NULL
#define NULL ((void *)0)
#endif
#endif
#define MS_PER_SECOND 1000
unsigned int KalThreadGetInfo(unsigned int threadId, ThreadInfo *info)
{
unsigned int ret;
if (info == NULL) {
return -1;
}
(void)memset_s(info, sizeof(ThreadInfo), 0, sizeof(ThreadInfo));
TSK_INFO_S *losTaskInfo = (TSK_INFO_S *)malloc(sizeof(TSK_INFO_S));
if (losTaskInfo == NULL) {
return -1;
}
(void)memset_s(losTaskInfo, sizeof(TSK_INFO_S), 0, sizeof(TSK_INFO_S));
ret = LOS_TaskInfoGet(threadId, losTaskInfo);
if (ret == LOS_OK) {
info->id = losTaskInfo->uwTaskID;
info->status = losTaskInfo->usTaskStatus;
info->priority = losTaskInfo->usTaskPrio;
info->taskSem = losTaskInfo->pTaskSem;
info->taskMutex = losTaskInfo->pTaskMux;
info->eventMask = losTaskInfo->uwEventMask;
info->stackSize = losTaskInfo->uwStackSize;
info->topOfStack = losTaskInfo->uwTopOfStack;
info->bottomOfStack = losTaskInfo->uwBottomOfStack;
info->mstatus = losTaskInfo->mstatus;
info->mepc = losTaskInfo->mepc;
info->tp = losTaskInfo->tp;
info->ra = losTaskInfo->ra;
info->sp = losTaskInfo->uwSP;
info->currUsed = losTaskInfo->uwCurrUsed;
info->peakUsed = losTaskInfo->uwPeakUsed;
info->overflowFlag = losTaskInfo->bOvf;
ret = memcpy_s(info->name, sizeof(info->name), losTaskInfo->acName, sizeof(info->name) - 1);
}
free(losTaskInfo);
return ret;
}
void KalDelayUs(unsigned int us)
{
unsigned int ticks;
if (us == 0) {
return;
}
ticks = LOS_MS2Tick(us / MS_PER_SECOND);
(void)LOS_TaskDelay(ticks);
}
KalTimerId KalTimerCreate(KalTimerProc func, KalTimerType type, void *arg, unsigned int ticks)
{
UINT16 swtmrId;
UINT8 mode;
if ((OS_INT_ACTIVE) || (NULL == func) || ((KAL_TIMER_ONCE != type) && (KAL_TIMER_PERIODIC != type))) {
return (KalTimerId)NULL;
}
if (KAL_TIMER_ONCE == type) {
mode = LOS_SWTMR_MODE_NO_SELFDELETE;
} else {
mode = LOS_SWTMR_MODE_PERIOD;
}
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
if (LOS_OK != LOS_SwtmrCreate(ticks, mode, (SWTMR_PROC_FUNC)func, &swtmrId, (UINT32)(UINTPTR)arg,
osTimerRousesAllow, osTimerAlignIgnore)) {
return (KalTimerId)NULL;
}
#else
if (LOS_OK != LOS_SwtmrCreate(ticks, mode, (SWTMR_PROC_FUNC)func, &swtmrId, (UINT32)(UINTPTR)arg)) {
return (KalTimerId)NULL;
}
#endif
return (KalTimerId)OS_SWT_FROM_SID(swtmrId);
}
KalErrCode KalTransRetCode(unsigned int ret)
{
if (LOS_OK == ret) {
return KAL_OK;
} else if (LOS_ERRNO_SWTMR_ID_INVALID == ret) {
return KAL_ERR_PARA;
} else {
return KAL_ERR_INNER;
}
}
KalErrCode KalTimerStart(KalTimerId timerId)
{
UINT32 ret;
SWTMR_CTRL_S *swtmr = NULL;
if (NULL == timerId) {
return KAL_ERR_PARA;
}
swtmr = (SWTMR_CTRL_S *)timerId;
ret = LOS_SwtmrStart(swtmr->usTimerID);
return KalTransRetCode(ret);
}
// support change while not running.
KalErrCode KalTimerChange(KalTimerId timerId, unsigned int ticks)
{
SWTMR_CTRL_S *swtmr = NULL;
if ((0 == ticks) || (NULL == timerId)) {
return KAL_ERR_PARA;
}
swtmr = (SWTMR_CTRL_S *)timerId;
if (OS_SWTMR_STATUS_TICKING == swtmr->ucState) {
return KAL_ERR_TIMER_STATE;
}
swtmr->uwInterval = ticks;
return KAL_OK;
}
KalErrCode KalTimerStop(KalTimerId timerId)
{
UINT32 ret;
SWTMR_CTRL_S *swtmr = NULL;
if (NULL == timerId) {
return KAL_ERR_PARA;
}
swtmr = (SWTMR_CTRL_S *)timerId;
ret = LOS_SwtmrStop(swtmr->usTimerID);
return KalTransRetCode(ret);
}
KalErrCode KalTimerDelete(KalTimerId timerId)
{
UINT32 ret;
SWTMR_CTRL_S *swtmr = NULL;
if (NULL == timerId) {
return KAL_ERR_PARA;
}
swtmr = (SWTMR_CTRL_S *)timerId;
ret = LOS_SwtmrDelete(swtmr->usTimerID);
return KalTransRetCode(ret);
}
unsigned int KalTimerIsRunning(KalTimerId timerId)
{
if ((OS_INT_ACTIVE) || (NULL == timerId)) {
return 0;
}
return (OS_SWTMR_STATUS_TICKING == ((SWTMR_CTRL_S *)timerId)->ucState);
}
unsigned int KalTickToMs(unsigned int ticks)
{
return LOS_Tick2MS(ticks);
}
unsigned int KalMsToTick(unsigned int millisec)
{
return LOS_MS2Tick(millisec);
}
KalErrCode KalGetMemInfo(MemInfo *pmemInfo)
{
hi_mdm_mem_info hiMemInfo;
hi_u32 hiRet;
if (NULL == pmemInfo) {
return KAL_ERR_PARA;
}
hiRet = hi_mem_get_sys_info(&hiMemInfo);
if (hiRet != 0) {
return KAL_ERR_INNER;
}
pmemInfo->total = hiMemInfo.total;
pmemInfo->used = hiMemInfo.used;
pmemInfo->free = hiMemInfo.free;
pmemInfo->freeNodeNum = hiMemInfo.free_node_num;
pmemInfo->usedNodeNum = hiMemInfo.used_node_num;
pmemInfo->maxFreeNodeSize = hiMemInfo.max_free_node_size;
pmemInfo->mallocFailCount = hiMemInfo.malloc_fail_count;
pmemInfo->peekSize = hiMemInfo.peek_size;
pmemInfo->totalLmp = hiMemInfo.total_lmp;
pmemInfo->usedLmp = hiMemInfo.used_lmp;
pmemInfo->freeLmp = hiMemInfo.free_lmp;
return KAL_OK;
}
-182
View File
@@ -1,182 +0,0 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @addtogroup KAL
* @{
*
* @brief Defines the kernel adaptation layer (KAL), which provides compatible interfaces across L0 and L1 systems.
*
*
* @since 1.0
* @version 1.0
*/
#ifndef KAL_H_
#define KAL_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Indicates the maximum length of a thread name.
*
* @since 1.0
* @version 1.0
*/
#define KAL_TASK_NAME_LEN 32
typedef void (*KalTimerProc)(void *arg);
typedef void *KalTimerId;
typedef enum {
KAL_TIMER_ONCE = 0, // /< One-shot timer.
KAL_TIMER_PERIODIC = 1 // /< Repeating timer.
} KalTimerType;
typedef enum {
KAL_OK = 0,
KAL_ERR_PARA = 1,
KAL_ERR_INNER = 2,
KAL_ERR_TIMER_STATE = 0x100,
} KalErrCode;
/**
* @brief Describes a thread.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
/** Thread name */
char name[KAL_TASK_NAME_LEN];
/** Thread ID */
unsigned int id;
/** Thread status */
unsigned short status;
/** Thread priority */
unsigned short priority;
/** Thread semaphore */
void *taskSem;
/** Thread mutex */
void *taskMutex;
/** Thread event */
unsigned int eventStru[3];
/** Thread event mask */
unsigned int eventMask;
/** Thread stack size */
unsigned int stackSize;
/** Thread stack top */
unsigned int topOfStack;
/** Thread stack bottom */
unsigned int bottomOfStack;
/** Thread current mstatus */
unsigned int mstatus;
/** Thread current mepc */
unsigned int mepc;
/** Thread current tp */
unsigned int tp;
/** Thread current ra */
unsigned int ra;
/** Thread stack pointer */
unsigned int sp;
/** Current stack space usage */
unsigned int currUsed;
/** Peak stack space usage */
unsigned int peakUsed;
/** Thread stack overflow flag */
unsigned int overflowFlag;
} ThreadInfo;
typedef struct {
/**< Total space of the memory pool. */
unsigned int total;
/**< Used space of the memory pool. */
unsigned int used;
/**< Free space of the memory pool. */
unsigned int free;
/**< Number of free nodes in the memory pool. */
unsigned int freeNodeNum;
/**< Number of used nodes in the memory pool. */
unsigned int usedNodeNum;
/**< Maximum size of the node in the free space of the memory pool. */
unsigned int maxFreeNodeSize;
/**< Number of memory application failures. */
unsigned int mallocFailCount;
/**< Peak memory usage of the memory pool. */
unsigned int peekSize;
/**< Total space of the little memory pool. */
unsigned int totalLmp;
/**< Used space of the little memory pool. */
unsigned int usedLmp;
/**< Free space of the little memory pool. */
unsigned int freeLmp;
} MemInfo;
/**
* @brief Obtains thread information.
*
* @param threadId Indicates the thread ID.
* @param info Indicates the pointer to the buffer for storing the obtained thread information.
* @return Returns <b>0</b> if the thread information is obtained; returns a negative value otherwise.
* @since 1.0
* @version 1.0
*/
unsigned int KalThreadGetInfo(unsigned int threadId, ThreadInfo *info);
/**
* @brief Delays a thread.
*
* The delay unit is microsecond. The actual delay precision can reach only the tick level.
*
* @param us Indicates the number of microseconds to delay. The actual delay precision is one tick.
* @since 1.0
* @version 1.0
*/
void KalDelayUs(unsigned int us);
KalTimerId KalTimerCreate(KalTimerProc func, KalTimerType type, void *arg, unsigned int ticks);
KalErrCode KalTimerStart(KalTimerId timerId);
KalErrCode KalTimerChange(KalTimerId timerId, unsigned int ticks);
KalErrCode KalTimerStop(KalTimerId timerId);
KalErrCode KalTimerDelete(KalTimerId timerId);
unsigned int KalTimerIsRunning(KalTimerId timerId);
unsigned int KalTickToMs(unsigned int ticks);
unsigned int KalMsToTick(unsigned int millisec);
KalErrCode KalGetMemInfo(MemInfo *pmemInfo);
#ifdef __cplusplus
}
#endif
#endif // KAL_H_
/* * @} */
-20
View File
@@ -1,20 +0,0 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
import("//build/lite/config/component/lite_component.gni")
static_library("posix") {
sources = [
"src/file.c",
"src/pthread.c",
"src/pthread_attr.c",
"src/time.c",
"src/version.c",
]
include_dirs = [ "include" ]
defines = [
"LIBC_VERSION_NUM=0x00010000",
"LIBC_VERSION_STR=\"1.0.0-liteos_m\"",
]
cflags = [ "-Werror" ]
}
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
+8 -4
View File
@@ -72,15 +72,19 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
return EINVAL;
}
taskInitParam.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
if (attr) {
if (attr->detachstate == PTHREAD_CREATE_DETACHED) {
return ENOTSUP;
}
if (attr->stackaddr_set) {
return ENOTSUP;
}
if (attr->stacksize_set) {
taskInitParam.uwStackSize = attr->stacksize;
}
taskInitParam.usTaskPrio = (UINT16)attr->schedparam.sched_priority;
taskInitParam.uwStackSize = attr->stacksize;
} else {
taskInitParam.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
}
taskInitParam.pcName = malloc(PTHREAD_NAMELEN);
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File