add OpenHarmony 1.0 baseline

This commit is contained in:
wenjun
2020-09-08 10:21:39 +08:00
parent 757d8285e4
commit dc16ffa8cb
107 changed files with 26347 additions and 0 deletions

83
components/BUILD.gn Executable file
View File

@@ -0,0 +1,83 @@
# 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.
import("//build/lite/config/component/lite_component.gni")
source_set("sec") {
sources = [
"cmsis/cmsis_liteos.c",
"../../../third_party/bounds_checking_function/src/fscanf_s.c",
"../../../third_party/bounds_checking_function/src/fwscanf_s.c",
"../../../third_party/bounds_checking_function/src/gets_s.c",
"../../../third_party/bounds_checking_function/src/memcpy_s.c",
"../../../third_party/bounds_checking_function/src/memmove_s.c",
"../../../third_party/bounds_checking_function/src/memset_s.c",
"../../../third_party/bounds_checking_function/src/scanf_s.c",
"../../../third_party/bounds_checking_function/src/securecutil.c",
"../../../third_party/bounds_checking_function/src/secureinput_a.c",
"../../../third_party/bounds_checking_function/src/secureinput_w.c",
"../../../third_party/bounds_checking_function/src/secureprintoutput_a.c",
"../../../third_party/bounds_checking_function/src/secureprintoutput_w.c",
"../../../third_party/bounds_checking_function/src/snprintf_s.c",
"../../../third_party/bounds_checking_function/src/sprintf_s.c",
"../../../third_party/bounds_checking_function/src/sscanf_s.c",
"../../../third_party/bounds_checking_function/src/strcat_s.c",
"../../../third_party/bounds_checking_function/src/strcpy_s.c",
"../../../third_party/bounds_checking_function/src/strncat_s.c",
"../../../third_party/bounds_checking_function/src/strncpy_s.c",
"../../../third_party/bounds_checking_function/src/strtok_s.c",
"../../../third_party/bounds_checking_function/src/swprintf_s.c",
"../../../third_party/bounds_checking_function/src/swscanf_s.c",
"../../../third_party/bounds_checking_function/src/vfscanf_s.c",
"../../../third_party/bounds_checking_function/src/vfwscanf_s.c",
"../../../third_party/bounds_checking_function/src/vscanf_s.c",
"../../../third_party/bounds_checking_function/src/vsnprintf_s.c",
"../../../third_party/bounds_checking_function/src/vsprintf_s.c",
"../../../third_party/bounds_checking_function/src/vsscanf_s.c",
"../../../third_party/bounds_checking_function/src/vswprintf_s.c",
"../../../third_party/bounds_checking_function/src/vswscanf_s.c",
"../../../third_party/bounds_checking_function/src/vwscanf_s.c",
"../../../third_party/bounds_checking_function/src/wcscat_s.c",
"../../../third_party/bounds_checking_function/src/wcscpy_s.c",
"../../../third_party/bounds_checking_function/src/wcsncat_s.c",
"../../../third_party/bounds_checking_function/src/wcsncpy_s.c",
"../../../third_party/bounds_checking_function/src/wcstok_s.c",
"../../../third_party/bounds_checking_function/src/wmemcpy_s.c",
"../../../third_party/bounds_checking_function/src/wmemmove_s.c",
"../../../third_party/bounds_checking_function/src/wscanf_s.c",
]
}
lite_component("components") {
features = [
":sec"
]
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
../../../../../third_party/cmsis/CMSIS/RTOS2/Include/cmsis_os2.h

47
components/cmsis/BUILD.gn Executable file
View File

@@ -0,0 +1,47 @@
# 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.
import("//build/lite/config/component/lite_component.gni")
static_library("cmsis") {
sources = [
"cmsis_liteos.c"
]
include_dirs = [
"//kernel/liteos_m/components/cmsis",
"//third_party/bounds_checking_function/include",
]
defines = [
"LITEOS_WIFI_IOT_VERSION",
]
cflags = [ "-Wno-error" ]
}

38
components/cmsis/cmsis_liteos.c Executable file
View File

@@ -0,0 +1,38 @@
/*
* 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 "los_config.h"
#if (CMSIS_OS_VER == 1)
#include "1.0/cmsis_liteos1.c"
#elif (CMSIS_OS_VER == 2)
#include "2.0/cmsis_liteos2.c"
#endif

39
components/cmsis/cmsis_os.h Executable file
View File

@@ -0,0 +1,39 @@
/*
* 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 "los_config.h"
#if (CMSIS_OS_VER == 1)
#error "cmsis version 1.0 is not supported now!"
#elif (CMSIS_OS_VER == 2)
#include "2.0/cmsis_os2.h"
#endif

View File

@@ -0,0 +1,56 @@
/*
* 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 HOS_CMSIS_ADP_H
#define HOS_CMSIS_ADP_H
#include "cmsis_os.h"
#include "hos_types.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
typedef struct {
osSemaphoreAttr_t attr;
uint32 maxCount;
uint32 initialCount;
} SemaphoreEx;
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif

47
components/kal/BUILD.gn Executable file
View File

@@ -0,0 +1,47 @@
# 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.
import("//build/lite/config/component/lite_component.gni")
static_library("kal") {
sources = [
"src/kal.c",
]
include_dirs = [
"//kernel/liteos_m/components/kal/include",
"//third_party/bounds_checking_function/include",
]
defines = [
"LITEOS_WIFI_IOT_VERSION",
]
cflags = [ "-Werror" ]
}

182
components/kal/include/kal.h Executable file
View File

@@ -0,0 +1,182 @@
/*
* 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_
/* * @} */

220
components/kal/src/kal.c Executable file
View File

@@ -0,0 +1,220 @@
/*
* 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;
}