Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
212
ohos/kernel/liteos_m/arch/csky/common/los_common_interrupt.c
Normal file
212
ohos/kernel/liteos_m/arch/csky/common/los_common_interrupt.c
Normal file
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 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_arch_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
UINT32 volatile g_intCount = 0;
|
||||
|
||||
STATIC UINT32 HwiNumValid(UINT32 num)
|
||||
{
|
||||
return ((num) >= OS_USER_HWI_MIN) && ((num) <= OS_USER_HWI_MAX);
|
||||
}
|
||||
|
||||
UINT32 ArchIntTrigger(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
if (!HwiNumValid(hwiNum)) {
|
||||
return LOS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
HwiControllerOps *hwiOps = ArchIntOpsGet();
|
||||
if (hwiOps->triggerIrq == NULL) {
|
||||
return OS_ERRNO_HWI_OPS_FUNC_NULL;
|
||||
}
|
||||
|
||||
return hwiOps->triggerIrq(hwiNum);
|
||||
}
|
||||
|
||||
UINT32 ArchIntEnable(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
if (!HwiNumValid(hwiNum)) {
|
||||
return LOS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
HwiControllerOps *hwiOps = ArchIntOpsGet();
|
||||
if (hwiOps->enableIrq == NULL) {
|
||||
return OS_ERRNO_HWI_OPS_FUNC_NULL;
|
||||
}
|
||||
|
||||
return hwiOps->enableIrq(hwiNum);
|
||||
}
|
||||
|
||||
UINT32 ArchIntDisable(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
if (!HwiNumValid(hwiNum)) {
|
||||
return LOS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
HwiControllerOps *hwiOps = ArchIntOpsGet();
|
||||
if (hwiOps->disableIrq == NULL) {
|
||||
return OS_ERRNO_HWI_OPS_FUNC_NULL;
|
||||
}
|
||||
|
||||
return hwiOps->disableIrq(hwiNum);
|
||||
}
|
||||
|
||||
UINT32 ArchIntClear(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
if (!HwiNumValid(hwiNum)) {
|
||||
return LOS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
HwiControllerOps *hwiOps = ArchIntOpsGet();
|
||||
if (hwiOps->clearIrq == NULL) {
|
||||
return OS_ERRNO_HWI_OPS_FUNC_NULL;
|
||||
}
|
||||
|
||||
return hwiOps->clearIrq(hwiNum);
|
||||
}
|
||||
|
||||
UINT32 ArchIntSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority)
|
||||
{
|
||||
if (!HwiNumValid(hwiNum)) {
|
||||
return LOS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
if (!HWI_PRI_VALID(priority)) {
|
||||
return OS_ERRNO_HWI_PRIO_INVALID;
|
||||
}
|
||||
|
||||
HwiControllerOps *hwiOps = ArchIntOpsGet();
|
||||
if (hwiOps->setIrqPriority == NULL) {
|
||||
return OS_ERRNO_HWI_OPS_FUNC_NULL;
|
||||
}
|
||||
|
||||
return hwiOps->setIrqPriority(hwiNum, priority);
|
||||
}
|
||||
|
||||
UINT32 ArchIntCurIrqNum(VOID)
|
||||
{
|
||||
HwiControllerOps *hwiOps = ArchIntOpsGet();
|
||||
return hwiOps->getCurIrqNum();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg)
|
||||
{
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
request_irq(num, vector, arg);
|
||||
ArchIntEnable(num);
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchHwiCreate
|
||||
Description : create hardware interrupt
|
||||
Input : hwiNum --- hwi num to create
|
||||
hwiPrio --- priority of the hwi
|
||||
hwiMode --- unused
|
||||
hwiHandler --- hwi handler
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum, HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T hwiMode, HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)hwiMode;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
if (hwiPrio > OS_HWI_PRIO_LOWEST) {
|
||||
return OS_ERRNO_HWI_PRIO_INVALID;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
if (irqParam != NULL) {
|
||||
OsSetVector(hwiNum, hwiHandler, irqParam->pDevId);
|
||||
} else {
|
||||
OsSetVector(hwiNum, hwiHandler, NULL);
|
||||
}
|
||||
|
||||
HwiControllerOps *hwiOps = ArchIntOpsGet();
|
||||
if (hwiOps->createIrq == NULL) {
|
||||
LOS_IntRestore(intSave);
|
||||
return OS_ERRNO_HWI_OPS_FUNC_NULL;
|
||||
}
|
||||
|
||||
hwiOps->createIrq(hwiNum, hwiPrio);
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
irqParam --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
(VOID)irqParam;
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
ArchIntDisable(hwiNum);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
release_irq(hwiNum);
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 ArchIsIntActive(VOID)
|
||||
{
|
||||
return (g_intCount > 0);
|
||||
}
|
||||
121
ohos/kernel/liteos_m/arch/csky/common/los_common_interrupt.h
Normal file
121
ohos/kernel/liteos_m/arch/csky/common/los_common_interrupt.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 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 _LOS_COMMON_INTERRUPT_H
|
||||
#define _LOS_COMMON_INTERRUPT_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_error.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Define the type of a hardware interrupt vector table function.
|
||||
*/
|
||||
typedef VOID (**HWI_VECTOR_FUNC)(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of interrupts.
|
||||
*/
|
||||
extern volatile UINT32 g_intCount;
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Maximum number of used hardware interrupts.
|
||||
*/
|
||||
#ifndef OS_HWI_MAX_NUM
|
||||
#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
typedef struct {
|
||||
HWI_PROC_FUNC pfnHandler;
|
||||
VOID *pParm;
|
||||
} HWI_HANDLER_FUNC;
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg);
|
||||
extern HWI_HANDLER_FUNC g_hwiHandlerForm[];
|
||||
#else
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
|
||||
extern HWI_PROC_FUNC g_hwiHandlerForm[];
|
||||
#endif
|
||||
|
||||
#define OS_EXC_IN_INIT 0
|
||||
#define OS_EXC_IN_TASK 1
|
||||
#define OS_EXC_IN_HWI 2
|
||||
#define OS_EXC_FLAG_FAULTADDR_VALID 0x01
|
||||
#define OS_EXC_IMPRECISE_ACCESS_ADDR 0xABABABAB
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* @brief: Default vector handling function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to configure interrupt for null function.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalHwiDefaultHandler(VOID);
|
||||
|
||||
VOID HalPreInterruptHandler(UINT32 arg);
|
||||
VOID HalAftInterruptHandler(UINT32 arg);
|
||||
VOID *ArchGetHwiFrom(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_COMMON_INTERRUPT_H */
|
||||
301
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_arch_atomic.h
Normal file
301
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_arch_atomic.h
Normal file
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 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 _LOS_ARCH_ATOMIC_H
|
||||
#define _LOS_ARCH_ATOMIC_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
#include "los_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
STATIC INLINE INT32 ArchAtomicRead(const Atomic *v)
|
||||
{
|
||||
INT32 val;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
__asm__ __volatile__("ldw %0, (%1)\n"
|
||||
: "=&r"(val)
|
||||
: "r"(v)
|
||||
: "cc");
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchAtomicSet(Atomic *v, INT32 setVal)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
__asm__ __volatile__("stw %1, (%0, 0)"
|
||||
:
|
||||
: "r"(v), "r"(setVal)
|
||||
: "cc");
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
STATIC INLINE INT32 ArchAtomicAdd(Atomic *v, INT32 addVal)
|
||||
{
|
||||
INT32 val;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
__asm__ __volatile__("ldw %0, (%1)\n"
|
||||
"add %0, %0, %2\n"
|
||||
"stw %0, (%1, 0)"
|
||||
: "=&r"(val)
|
||||
: "r"(v), "r"(addVal)
|
||||
: "cc");
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
STATIC INLINE INT32 ArchAtomicSub(Atomic *v, INT32 subVal)
|
||||
{
|
||||
INT32 val;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
__asm__ __volatile__("ldw %0, (%1)\n"
|
||||
"sub %0, %2\n"
|
||||
"stw %0, (%1, 0)"
|
||||
: "=&r"(val)
|
||||
: "r"(v), "r"(subVal)
|
||||
: "cc");
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchAtomicInc(Atomic *v)
|
||||
{
|
||||
(VOID)ArchAtomicAdd(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchAtomicDec(Atomic *v)
|
||||
{
|
||||
(VOID)ArchAtomicSub(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE INT32 ArchAtomicIncRet(Atomic *v)
|
||||
{
|
||||
return ArchAtomicAdd(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE INT32 ArchAtomicDecRet(Atomic *v)
|
||||
{
|
||||
return ArchAtomicSub(v, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_arch_atomic
|
||||
* @brief Atomic exchange for 32-bit variable.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 32-bit variable
|
||||
* and return the previous value of the atomic variable.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The exchange value.
|
||||
*
|
||||
* @retval #INT32 The previous value of the atomic variable
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT32 ArchAtomicXchg32bits(volatile INT32 *v, INT32 val)
|
||||
{
|
||||
INT32 prevVal = 0;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
__asm__ __volatile__("ldw %0, (%1)\n"
|
||||
"stw %2, (%1)"
|
||||
: "=&r"(prevVal)
|
||||
: "r"(v), "r"(val)
|
||||
: "cc");
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return prevVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_arch_atomic
|
||||
* @brief Atomic exchange for 32-bit variable with compare.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 32-bit variable, if the value of variable is equal to oldVal.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The new value.
|
||||
* @param oldVal [IN] The old value.
|
||||
*
|
||||
* @retval TRUE The previous value of the atomic variable is not equal to oldVal.
|
||||
* @retval FALSE The previous value of the atomic variable is equal to oldVal.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE BOOL ArchAtomicCmpXchg32bits(volatile INT32 *v, INT32 val, INT32 oldVal)
|
||||
{
|
||||
INT32 prevVal = 0;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
__asm__ __volatile__("ldw %0, (%1)\n"
|
||||
"cmpne %0, %2\n"
|
||||
"bt 1f\n"
|
||||
"stw %3, (%1)\n"
|
||||
"1:"
|
||||
: "=&r"(prevVal)
|
||||
: "r"(v), "r"(oldVal), "r"(val)
|
||||
: "cc");
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return prevVal != oldVal;
|
||||
}
|
||||
|
||||
STATIC INLINE INT64 ArchAtomic64Read(const Atomic64 *v)
|
||||
{
|
||||
INT64 val;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
val = *v;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchAtomic64Set(Atomic64 *v, INT64 setVal)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
*v = setVal;
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
STATIC INLINE INT64 ArchAtomic64Add(Atomic64 *v, INT64 addVal)
|
||||
{
|
||||
INT64 val;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
*v += addVal;
|
||||
val = *v;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
STATIC INLINE INT64 ArchAtomic64Sub(Atomic64 *v, INT64 subVal)
|
||||
{
|
||||
INT64 val;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
*v -= subVal;
|
||||
val = *v;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchAtomic64Inc(Atomic64 *v)
|
||||
{
|
||||
(VOID)ArchAtomic64Add(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE INT64 ArchAtomic64IncRet(Atomic64 *v)
|
||||
{
|
||||
return ArchAtomic64Add(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchAtomic64Dec(Atomic64 *v)
|
||||
{
|
||||
(VOID)ArchAtomic64Sub(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE INT64 ArchAtomic64DecRet(Atomic64 *v)
|
||||
{
|
||||
return ArchAtomic64Sub(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE INT64 ArchAtomicXchg64bits(Atomic64 *v, INT64 val)
|
||||
{
|
||||
INT64 prevVal;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
prevVal = *v;
|
||||
*v = val;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return prevVal;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL ArchAtomicCmpXchg64bits(Atomic64 *v, INT64 val, INT64 oldVal)
|
||||
{
|
||||
INT64 prevVal;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
prevVal = *v;
|
||||
if (prevVal == oldVal) {
|
||||
*v = val;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return prevVal != oldVal;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_ATOMIC_H */
|
||||
194
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_arch_context.h
Normal file
194
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_arch_context.h
Normal file
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 _LOS_ARCH_CONTEXT_H
|
||||
#define _LOS_ARCH_CONTEXT_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef CPU_CK803
|
||||
#define OS_TRAP_STACK_SIZE 512
|
||||
typedef struct TagTskContext {
|
||||
UINT32 R0;
|
||||
UINT32 R1;
|
||||
UINT32 R2;
|
||||
UINT32 R3;
|
||||
UINT32 R4;
|
||||
UINT32 R5;
|
||||
UINT32 R6;
|
||||
UINT32 R7;
|
||||
UINT32 R8;
|
||||
UINT32 R9;
|
||||
UINT32 R10;
|
||||
UINT32 R11;
|
||||
UINT32 R12;
|
||||
UINT32 R13;
|
||||
UINT32 R15;
|
||||
UINT32 R28;
|
||||
UINT32 EPSR;
|
||||
UINT32 EPC;
|
||||
} TaskContext;
|
||||
#endif
|
||||
|
||||
#ifdef CPU_CK804
|
||||
#define OS_TRAP_STACK_SIZE 512
|
||||
typedef struct TagTskContext {
|
||||
UINT32 R0;
|
||||
UINT32 R1;
|
||||
UINT32 R2;
|
||||
UINT32 R3;
|
||||
UINT32 R4;
|
||||
UINT32 R5;
|
||||
UINT32 R6;
|
||||
UINT32 R7;
|
||||
UINT32 R8;
|
||||
UINT32 R9;
|
||||
UINT32 R10;
|
||||
UINT32 R11;
|
||||
UINT32 R12;
|
||||
UINT32 R13;
|
||||
UINT32 R15;
|
||||
UINT32 R16;
|
||||
UINT32 R17;
|
||||
UINT32 R18;
|
||||
UINT32 R19;
|
||||
UINT32 R20;
|
||||
UINT32 R21;
|
||||
UINT32 R22;
|
||||
UINT32 R23;
|
||||
UINT32 R24;
|
||||
UINT32 R25;
|
||||
UINT32 R26;
|
||||
UINT32 R27;
|
||||
UINT32 R28;
|
||||
UINT32 R29;
|
||||
UINT32 R30;
|
||||
UINT32 R31;
|
||||
UINT32 EPSR;
|
||||
UINT32 EPC;
|
||||
} TaskContext;
|
||||
#endif
|
||||
|
||||
#ifdef CPU_CK804DF
|
||||
#define OS_TRAP_STACK_SIZE 768
|
||||
typedef struct TagTskContext {
|
||||
UINT32 R0;
|
||||
UINT32 R1;
|
||||
UINT32 R2;
|
||||
UINT32 R3;
|
||||
UINT32 R4;
|
||||
UINT32 R5;
|
||||
UINT32 R6;
|
||||
UINT32 R7;
|
||||
UINT32 R8;
|
||||
UINT32 R9;
|
||||
UINT32 R10;
|
||||
UINT32 R11;
|
||||
UINT32 R12;
|
||||
UINT32 R13;
|
||||
UINT32 R15;
|
||||
UINT32 R16;
|
||||
UINT32 R17;
|
||||
UINT32 R18;
|
||||
UINT32 R19;
|
||||
UINT32 R20;
|
||||
UINT32 R21;
|
||||
UINT32 R22;
|
||||
UINT32 R23;
|
||||
UINT32 R24;
|
||||
UINT32 R25;
|
||||
UINT32 R26;
|
||||
UINT32 R27;
|
||||
UINT32 R28;
|
||||
UINT32 R29;
|
||||
UINT32 R30;
|
||||
UINT32 R31;
|
||||
UINT32 VR0;
|
||||
UINT32 VR1;
|
||||
UINT32 VR2;
|
||||
UINT32 VR3;
|
||||
UINT32 VR4;
|
||||
UINT32 VR5;
|
||||
UINT32 VR6;
|
||||
UINT32 VR7;
|
||||
UINT32 VR8;
|
||||
UINT32 VR9;
|
||||
UINT32 VR10;
|
||||
UINT32 VR11;
|
||||
UINT32 VR12;
|
||||
UINT32 VR13;
|
||||
UINT32 VR14;
|
||||
UINT32 VR15;
|
||||
UINT32 EPSR;
|
||||
UINT32 EPC;
|
||||
} TaskContext;
|
||||
#endif
|
||||
|
||||
#ifdef CPU_CK802
|
||||
#define OS_TRAP_STACK_SIZE 500
|
||||
typedef struct TagTskContext {
|
||||
UINT32 R0;
|
||||
UINT32 R1;
|
||||
UINT32 R2;
|
||||
UINT32 R3;
|
||||
UINT32 R4;
|
||||
UINT32 R5;
|
||||
UINT32 R6;
|
||||
UINT32 R7;
|
||||
UINT32 R8;
|
||||
UINT32 R9;
|
||||
UINT32 R10;
|
||||
UINT32 R11;
|
||||
UINT32 R12;
|
||||
UINT32 R13;
|
||||
UINT32 R15;
|
||||
UINT32 EPSR;
|
||||
UINT32 EPC;
|
||||
} TaskContext;
|
||||
#endif
|
||||
|
||||
VOID HalStartToRun(VOID);
|
||||
VOID HalTaskContextSwitch(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_CONTEXT_H */
|
||||
324
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_arch_interrupt.h
Normal file
324
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_arch_interrupt.h
Normal file
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2023 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 _LOS_ARCH_INTERRUPT_H
|
||||
#define _LOS_ARCH_INTERRUPT_H
|
||||
|
||||
#include "los_common_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Highest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_HIGHEST
|
||||
#define OS_HWI_PRIO_HIGHEST 0
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Lowest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_LOWEST
|
||||
#define OS_HWI_PRIO_LOWEST 3
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Check the interrupt priority.
|
||||
*/
|
||||
#define HWI_PRI_VALID(pri) (((pri) >= OS_HWI_PRIO_HIGHEST) && ((pri) <= OS_HWI_PRIO_LOWEST))
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of C-sky system interrupt vector.
|
||||
*/
|
||||
#define OS_SYS_VECTOR_CNT 32
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of C-sky interrupt vector.
|
||||
*/
|
||||
#define OS_VECTOR_CNT (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM)
|
||||
|
||||
#define OS_USER_HWI_MIN 0
|
||||
#define OS_USER_HWI_MAX (LOSCFG_PLATFORM_HWI_LIMIT - 1)
|
||||
|
||||
#define HWI_ALIGNSIZE 0x400
|
||||
|
||||
#define PSR_VEC_OFFSET 16U
|
||||
#define VIC_REG_BASE 0xE000E100UL
|
||||
|
||||
typedef struct {
|
||||
UINT32 ISER[4U];
|
||||
UINT32 RESERVED0[12U];
|
||||
UINT32 IWER[4U];
|
||||
UINT32 RESERVED1[12U];
|
||||
UINT32 ICER[4U];
|
||||
UINT32 RESERVED2[12U];
|
||||
UINT32 IWDR[4U];
|
||||
UINT32 RESERVED3[12U];
|
||||
UINT32 ISPR[4U];
|
||||
UINT32 RESERVED4[12U];
|
||||
UINT32 ISSR[4U];
|
||||
UINT32 RESERVED5[12U];
|
||||
UINT32 ICPR[4U];
|
||||
UINT32 RESERVED6[12U];
|
||||
UINT32 ICSR[4U];
|
||||
UINT32 RESERVED7[12U];
|
||||
UINT32 IABR[4U];
|
||||
UINT32 RESERVED8[60U];
|
||||
UINT32 IPR[32U];
|
||||
UINT32 RESERVED9[480U];
|
||||
UINT32 ISR;
|
||||
UINT32 IPTR;
|
||||
UINT32 TSPEND;
|
||||
UINT32 TSABR;
|
||||
UINT32 TSPR;
|
||||
} VIC_TYPE;
|
||||
|
||||
extern VIC_TYPE *VIC_REG;
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Invalid interrupt number.
|
||||
*
|
||||
* Value: 0x02000900
|
||||
*
|
||||
* Solution: Ensure that the interrupt number is valid.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Null hardware interrupt handling function.
|
||||
*
|
||||
* Value: 0x02000901
|
||||
*
|
||||
* Solution: Pass in a valid non-null hardware interrupt handling function.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation.
|
||||
*
|
||||
* Value: 0x02000902
|
||||
*
|
||||
* Solution: Increase the configured maximum number of supported hardware interrupts.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Insufficient memory for hardware interrupt initialization.
|
||||
*
|
||||
* Value: 0x02000903
|
||||
*
|
||||
* Solution: Expand the configured memory.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: The interrupt has already been created.
|
||||
*
|
||||
* Value: 0x02000904
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Invalid interrupt priority.
|
||||
*
|
||||
* Value: 0x02000905
|
||||
*
|
||||
* Solution: Ensure that the interrupt priority is valid.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Incorrect interrupt creation mode.
|
||||
*
|
||||
* Value: 0x02000906
|
||||
*
|
||||
* Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: The interrupt has already been created as a fast interrupt.
|
||||
*
|
||||
* Value: 0x02000907
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Invalid interrupt operation function.
|
||||
*
|
||||
* Value: 0x0200090c
|
||||
*
|
||||
* Solution: Set a valid interrupt operation function
|
||||
*/
|
||||
#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Invalid interrupt number.
|
||||
*
|
||||
* Value: 0x02000900
|
||||
*
|
||||
* Solution: Ensure that the interrupt number is valid.
|
||||
*/
|
||||
#define LOS_ERRNO_HWI_NUM_INVALID OS_ERRNO_HWI_NUM_INVALID
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* @brief: Hardware interrupt entry function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used as all hardware interrupt handling function entry.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalInterrupt(VOID);
|
||||
|
||||
#define OS_VIC_INT_ENABLE_SIZE 0x4
|
||||
#define OS_VIC_INT_WAKER_SIZE 0x4
|
||||
#define OS_VIC_INT_ICER_SIZE 0x4
|
||||
#define OS_VIC_INT_ISPR_SIZE 0x4
|
||||
#define OS_VIC_INT_IABR_SIZE 0x4
|
||||
#define OS_VIC_INT_IPR_SIZE 0x4
|
||||
#define OS_VIC_INT_ISR_SIZE 0x4
|
||||
#define OS_VIC_INT_IPTR_SIZE 0x4
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* the struct of register files
|
||||
*
|
||||
* description: the register files that saved when exception triggered
|
||||
*
|
||||
* notes:the following register with prefix 'uw' correspond to the registers in the cpu data sheet.
|
||||
*/
|
||||
typedef struct TagExcContext {
|
||||
UINT32 R0;
|
||||
UINT32 R1;
|
||||
UINT32 R2;
|
||||
UINT32 R3;
|
||||
UINT32 R4;
|
||||
UINT32 R5;
|
||||
UINT32 R6;
|
||||
UINT32 R7;
|
||||
UINT32 R8;
|
||||
UINT32 R9;
|
||||
UINT32 R10;
|
||||
UINT32 R11;
|
||||
UINT32 R12;
|
||||
UINT32 R13;
|
||||
UINT32 R14;
|
||||
UINT32 R15;
|
||||
UINT32 EPSR;
|
||||
UINT32 EPC;
|
||||
} EXC_CONTEXT_S;
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* @brief: Exception handler function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to handle Exception.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param excBufAddr [IN] The address of stack pointer at which the error occurred.
|
||||
* @param faultAddr [IN] The address at which the error occurred.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(EXC_CONTEXT_S *excBufAddr, UINT32 faultAddr);
|
||||
|
||||
VOID IrqEntry(VOID);
|
||||
|
||||
VOID HandleEntry(VOID);
|
||||
|
||||
VOID HalHwiInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Exception information structure
|
||||
*
|
||||
* Description: Exception information saved when an exception is triggered on the Csky platform.
|
||||
*
|
||||
*/
|
||||
typedef struct TagExcInfo {
|
||||
UINT16 phase;
|
||||
UINT16 type;
|
||||
UINT32 faultAddr;
|
||||
UINT32 thrdPid;
|
||||
UINT16 nestCnt;
|
||||
UINT16 reserved;
|
||||
EXC_CONTEXT_S *context;
|
||||
} ExcInfo;
|
||||
|
||||
extern ExcInfo g_excInfo;
|
||||
|
||||
#define MAX_INT_INFO_SIZE (8 + 0x164)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_INTERRUPT_H */
|
||||
51
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_arch_timer.h
Normal file
51
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_arch_timer.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 _LOS_ARCH_TIMER_H
|
||||
#define _LOS_ARCH_TIMER_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_TIMER_H */
|
||||
128
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_ck804df.S
Normal file
128
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_ck804df.S
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2020, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 HalExcHandleEntry
|
||||
.extern g_trapStackBase
|
||||
|
||||
#define VIC_TSPDR 0XE000EC08
|
||||
|
||||
.section .text
|
||||
.align 2
|
||||
.type HalStartToRun, %function
|
||||
.global HalStartToRun
|
||||
HalStartToRun:
|
||||
lrw r1, g_losTask
|
||||
lrw r2, g_losTask + 4
|
||||
|
||||
ldw r0, (r2)
|
||||
|
||||
st.w r0, (r1)
|
||||
st.w r0, (r2)
|
||||
|
||||
ldw sp, (r0)
|
||||
|
||||
ldw r0, (sp, 192)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 188)
|
||||
mtcr r0, epsr
|
||||
|
||||
ldm r0-r13, (sp)
|
||||
ldw r15, (sp, 56)
|
||||
addi sp, 60
|
||||
ldm r16-r31, (sp)
|
||||
addi sp, 64
|
||||
fldms vr0-vr15, (sp)
|
||||
addi sp, 72
|
||||
rte
|
||||
|
||||
.align 2
|
||||
.type HalTaskContextSwitch, %function
|
||||
.global HalTaskContextSwitch
|
||||
HalTaskContextSwitch:
|
||||
lrw r0, VIC_TSPDR
|
||||
bgeni r1, 0
|
||||
stw r1, (r0)
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
rts
|
||||
|
||||
.align 2
|
||||
.type tspend_handler, %function
|
||||
.global tspend_handler
|
||||
tspend_handler:
|
||||
subi sp, 196
|
||||
stm r0-r13, (sp)
|
||||
stw r15, (sp, 56)
|
||||
addi r0, sp, 60
|
||||
stm r16-r31, (r0)
|
||||
addi r0, 64
|
||||
fstms vr0-vr15, (r0)
|
||||
mfcr r1, epsr
|
||||
stw r1, (r0, 64)
|
||||
mfcr r1, epc
|
||||
stw r1, (r0, 68)
|
||||
|
||||
jbsr OsSchedTaskSwitch
|
||||
bez r0, ret_con
|
||||
|
||||
lrw r2, g_losTask
|
||||
ldw r0, (r2)
|
||||
stw sp, (r0)
|
||||
|
||||
lrw r3, g_losTask + 4
|
||||
ldw r0, (r3)
|
||||
stw r0, (r2)
|
||||
|
||||
ldw sp, (r0)
|
||||
|
||||
ret_con:
|
||||
ldw r0, (sp, 192)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 188)
|
||||
mtcr r0, epsr
|
||||
|
||||
ldm r0-r13, (sp)
|
||||
ldw r15, (sp, 56)
|
||||
addi sp, 60
|
||||
ldm r16-r31, (sp)
|
||||
addi sp, 64
|
||||
fldms vr0-vr15, (sp)
|
||||
addi sp, 72
|
||||
rte
|
||||
|
||||
.global __get_PC
|
||||
.type __get_PC, %function
|
||||
|
||||
__get_PC:
|
||||
grs r0, __get_PC
|
||||
jmp r15
|
||||
|
||||
219
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_context.c
Normal file
219
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_context.c
Normal file
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_context.h"
|
||||
#include "securec.h"
|
||||
#include "los_arch_context.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchInit
|
||||
Description : arch init function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchSysExit
|
||||
Description : Task exit function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID)
|
||||
{
|
||||
(VOID)LOS_IntLock();
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchTskStackInit
|
||||
Description : Task stack initialization function
|
||||
Input : taskID --- TaskID
|
||||
stackSize --- Total size of the stack
|
||||
topStack --- Top of task's stack
|
||||
Output : None
|
||||
Return : Context pointer
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
|
||||
{
|
||||
TaskContext *context = (TaskContext *)((UINTPTR)topStack + stackSize - sizeof(TaskContext));
|
||||
|
||||
#if defined(CPU_CK804)
|
||||
context->R0 = taskID;
|
||||
context->R1 = 0x01010101L;
|
||||
context->R2 = 0x02020202L;
|
||||
context->R3 = 0x03030303L;
|
||||
context->R4 = 0x04040404L;
|
||||
context->R5 = 0x05050505L;
|
||||
context->R6 = 0x06060606L;
|
||||
context->R7 = 0x07070707L;
|
||||
context->R8 = 0x08080808L;
|
||||
context->R9 = 0x09090909L;
|
||||
context->R10 = 0x10101010L;
|
||||
context->R11 = 0x11111111L;
|
||||
context->R12 = 0x12121212L;
|
||||
context->R13 = 0x13131313L;
|
||||
context->R15 = (UINT32)ArchSysExit;
|
||||
context->R16 = 0x16161616L;
|
||||
context->R17 = 0x17171717L;
|
||||
context->R18 = 0x18181818L;
|
||||
context->R19 = 0x19191919L;
|
||||
context->R20 = 0x20202020L;
|
||||
context->R21 = 0x21212121L;
|
||||
context->R22 = 0x22222222L;
|
||||
context->R23 = 0x23232323L;
|
||||
context->R24 = 0x24242424L;
|
||||
context->R25 = 0x25252525L;
|
||||
context->R26 = 0x26262626L;
|
||||
context->R27 = 0x27272727L;
|
||||
context->R28 = 0x28282828L;
|
||||
context->R29 = 0x29292929L;
|
||||
context->R30 = 0x30303030L;
|
||||
context->R31 = 0x31313131L;
|
||||
context->EPSR = 0x80000340L;
|
||||
context->EPC = (UINT32)OsTaskEntry;
|
||||
#elif defined(CPU_CK804DF)
|
||||
context->R0 = taskID;
|
||||
context->R1 = 0x01010101L;
|
||||
context->R2 = 0x02020202L;
|
||||
context->R3 = 0x03030303L;
|
||||
context->R4 = 0x04040404L;
|
||||
context->R5 = 0x05050505L;
|
||||
context->R6 = 0x06060606L;
|
||||
context->R7 = 0x07070707L;
|
||||
context->R8 = 0x08080808L;
|
||||
context->R9 = 0x09090909L;
|
||||
context->R10 = 0x10101010L;
|
||||
context->R11 = 0x11111111L;
|
||||
context->R12 = 0x12121212L;
|
||||
context->R13 = 0x13131313L;
|
||||
context->R15 = (UINT32)ArchSysExit;
|
||||
context->R16 = 0x16161616L;
|
||||
context->R17 = 0x17171717L;
|
||||
context->R18 = 0x18181818L;
|
||||
context->R19 = 0x19191919L;
|
||||
context->R20 = 0x20202020L;
|
||||
context->R21 = 0x21212121L;
|
||||
context->R22 = 0x22222222L;
|
||||
context->R23 = 0x23232323L;
|
||||
context->R24 = 0x24242424L;
|
||||
context->R25 = 0x25252525L;
|
||||
context->R26 = 0x26262626L;
|
||||
context->R27 = 0x27272727L;
|
||||
context->R28 = 0x28282828L;
|
||||
context->R29 = 0x29292929L;
|
||||
context->R30 = 0x30303030L;
|
||||
context->R31 = 0x31313131L;
|
||||
context->VR0 = 0x12345678L;
|
||||
context->VR1 = 0x12345678L;
|
||||
context->VR2 = 0x12345678L;
|
||||
context->VR3 = 0x12345678L;
|
||||
context->VR4 = 0x12345678L;
|
||||
context->VR5 = 0x12345678L;
|
||||
context->VR6 = 0x12345678L;
|
||||
context->VR7 = 0x12345678L;
|
||||
context->VR8 = 0x12345678L;
|
||||
context->VR9 = 0x12345678L;
|
||||
context->VR10 = 0x12345678L;
|
||||
context->VR11 = 0x12345678L;
|
||||
context->VR12 = 0x12345678L;
|
||||
context->VR13 = 0x12345678L;
|
||||
context->VR14 = 0x12345678L;
|
||||
context->VR15 = 0x12345678L;
|
||||
context->EPSR = 0x80000340L;
|
||||
context->EPC = (UINT32)OsTaskEntry;
|
||||
#elif defined(CPU_CK803)
|
||||
context->R0 = taskID;
|
||||
context->R1 = 0x01010101L;
|
||||
context->R2 = 0x02020202L;
|
||||
context->R3 = 0x03030303L;
|
||||
context->R4 = 0x04040404L;
|
||||
context->R5 = 0x05050505L;
|
||||
context->R6 = 0x06060606L;
|
||||
context->R7 = 0x07070707L;
|
||||
context->R8 = 0x08080808L;
|
||||
context->R9 = 0x09090909L;
|
||||
context->R10 = 0x10101010L;
|
||||
context->R11 = 0x11111111L;
|
||||
context->R12 = 0x12121212L;
|
||||
context->R13 = 0x13131313L;
|
||||
context->R28 = 0x28282828L;
|
||||
context->R15 = (UINT32)ArchSysExit;
|
||||
context->EPSR = 0x80000140L;
|
||||
context->EPC = (UINT32)OsTaskEntry;
|
||||
#elif defined(CPU_CK802)
|
||||
context->R0 = taskID;
|
||||
context->R1 = 0x01010101L;
|
||||
context->R2 = 0x02020202L;
|
||||
context->R3 = 0x03030303L;
|
||||
context->R4 = 0x04040404L;
|
||||
context->R5 = 0x05050505L;
|
||||
context->R6 = 0x06060606L;
|
||||
context->R7 = 0x07070707L;
|
||||
context->R8 = 0x08080808L;
|
||||
context->R9 = 0x09090909L;
|
||||
context->R10 = 0x10101010L;
|
||||
context->R11 = 0x11111111L;
|
||||
context->R12 = 0x12121212L;
|
||||
context->R13 = 0x13131313L;
|
||||
context->R15 = (UINT32)ArchSysExit;
|
||||
context->EPSR = 0xe0000144L;
|
||||
context->EPC = (UINT32)OsTaskEntry;
|
||||
#else
|
||||
#error "** Unsupport CSKY Arch **"
|
||||
#endif
|
||||
return (VOID *)context;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
|
||||
{
|
||||
(VOID)LOS_IntLock();
|
||||
OsSchedStart();
|
||||
HalStartToRun();
|
||||
return LOS_OK; /* never return */
|
||||
}
|
||||
|
||||
VOID ArchTaskSchedule(VOID)
|
||||
{
|
||||
HalTaskContextSwitch();
|
||||
}
|
||||
|
||||
193
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_interrupt.c
Normal file
193
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_interrupt.c
Normal file
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2023 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 <stdarg.h>
|
||||
#include "securec.h"
|
||||
#include "los_context.h"
|
||||
#include "los_arch_context.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_hook.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
#include "osal/string.h"
|
||||
|
||||
#define INT_OFFSET 6
|
||||
#define PRI_OFF_PER_INT 8
|
||||
#define PRI_PER_REG 4
|
||||
#define PRI_OFF_IN_REG 6
|
||||
#define PRI_BITS 2
|
||||
#define PRI_HI 0
|
||||
#define PRI_LOW 7
|
||||
#define MASK_8_BITS 0xFF
|
||||
#define MASK_32_BITS 0xFFFFFFFF
|
||||
#define BYTES_OF_128_INT 4
|
||||
|
||||
|
||||
VIC_TYPE *VIC_REG = (VIC_TYPE *)VIC_REG_BASE;
|
||||
|
||||
UINT32 HalGetPsr(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ volatile("mfcr %0, psr" : "=r"(intSave) : : "memory");
|
||||
return intSave;
|
||||
}
|
||||
|
||||
UINT32 HalSetVbr(UINT32 intSave)
|
||||
{
|
||||
__asm__ volatile("mtcr %0, vbr" : : "r"(intSave) : "memory");
|
||||
return intSave;
|
||||
}
|
||||
|
||||
UINT32 ArchIntLock(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ __volatile__(
|
||||
"mfcr %0, psr \n"
|
||||
"psrclr ie"
|
||||
: "=r"(intSave)
|
||||
:
|
||||
: "memory");
|
||||
return intSave;
|
||||
}
|
||||
|
||||
UINT32 ArchIntUnLock(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ __volatile__(
|
||||
"mfcr %0, psr \n"
|
||||
"psrset ie"
|
||||
: "=r"(intSave)
|
||||
:
|
||||
: "memory");
|
||||
return intSave;
|
||||
}
|
||||
|
||||
VOID ArchIntRestore(UINT32 intSave)
|
||||
{
|
||||
__asm__ __volatile__("mtcr %0, psr" : : "r"(intSave));
|
||||
}
|
||||
|
||||
UINT32 ArchIntLocked(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ volatile("mfcr %0, psr" : "=r"(intSave) : : "memory");
|
||||
return !(intSave & (1 << INT_OFFSET));
|
||||
}
|
||||
|
||||
STATIC UINT32 HwiUnmask(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
VIC_REG->ISER[hwiNum / 32] = (UINT32)(1UL << (hwiNum % 32));
|
||||
VIC_REG->ISSR[hwiNum / 32] = (UINT32)(1UL << (hwiNum % 32));
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 HwiSetPriority(HWI_HANDLE_T hwiNum, UINT8 priority)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
VIC_REG->IPR[hwiNum / PRI_PER_REG] |= (((priority << PRI_OFF_IN_REG) << (hwiNum % PRI_PER_REG)) * PRI_OFF_PER_INT);
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 HwiMask(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
VIC_REG->ICER[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 HwiPending(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
VIC_REG->ISPR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 HwiClear(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
VIC_REG->ICPR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HwiNumGet
|
||||
Description : Get an interrupt number
|
||||
Input : None
|
||||
Output : None
|
||||
Return : Interrupt Indexes number
|
||||
**************************************************************************** */
|
||||
STATIC UINT32 HwiNumGet(VOID)
|
||||
{
|
||||
return (HalGetPsr() >> PSR_VEC_OFFSET) & MASK_8_BITS;
|
||||
}
|
||||
|
||||
STATIC UINT32 HwiCreate(HWI_HANDLE_T hwiNum, HWI_PRIOR_T hwiPrio)
|
||||
{
|
||||
HwiSetPriority(hwiNum, (UINT8)hwiPrio);
|
||||
HwiUnmask(hwiNum);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC HwiControllerOps g_archHwiOps = {
|
||||
.enableIrq = HwiUnmask,
|
||||
.disableIrq = HwiMask,
|
||||
.setIrqPriority = HwiSetPriority,
|
||||
.getCurIrqNum = HwiNumGet,
|
||||
.triggerIrq = HwiPending,
|
||||
.clearIrq = HwiClear,
|
||||
.createIrq = HwiCreate,
|
||||
};
|
||||
|
||||
HwiControllerOps *ArchIntOpsGet(VOID)
|
||||
{
|
||||
return &g_archHwiOps;
|
||||
}
|
||||
|
||||
163
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_timer.c
Normal file
163
ohos/kernel/liteos_m/arch/csky/v2/gcc/los_timer.c
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_timer.h"
|
||||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
typedef struct {
|
||||
UINT32 CTRL;
|
||||
UINT32 LOAD;
|
||||
UINT32 VAL;
|
||||
UINT32 CALIB;
|
||||
} CORE_TIM_TYPE;
|
||||
|
||||
#define CORE_TIM_BASE (0xE000E010UL)
|
||||
#define SysTick ((CORE_TIM_TYPE *)CORE_TIM_BASE)
|
||||
|
||||
#define CORETIM_ENABLE (1UL << 0)
|
||||
#define CORETIM_INTMASK (1UL << 1)
|
||||
#define CORETIM_SOURCE (1UL << 2)
|
||||
#define CORETIM_MODE (1UL << 16)
|
||||
|
||||
#ifdef CPU_CK802
|
||||
#define TIM_INT_NUM 5
|
||||
#endif
|
||||
#ifdef CPU_CK803
|
||||
#define TIM_INT_NUM 25
|
||||
#endif
|
||||
#ifdef CPU_CK804
|
||||
#define TIM_INT_NUM 25
|
||||
#endif
|
||||
#ifdef CPU_CK804DF
|
||||
#define TIM_INT_NUM 25
|
||||
#endif
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = TIM_INT_NUM,
|
||||
.periodMax = LOSCFG_BASE_CORE_TICK_RESPONSE_MAX,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
VOID systick_handler(VOID)
|
||||
{
|
||||
g_archTickTimer.tickHandler(NULL);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
tick->tickHandler = handler;
|
||||
tick->freq = OS_SYS_CLOCK;
|
||||
//设置所有的中断都能唤醒CPU
|
||||
VIC_REG->IWER[0] = 0xffffffff;
|
||||
VIC_REG->IWER[1] = 0xffffffff;
|
||||
VIC_REG->IWER[2] = 0xffffffff;
|
||||
VIC_REG->IWER[3] = 0xffffffff;
|
||||
ArchIntEnable(tick->irqNum);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT64 SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
if (nextResponseTime > g_archTickTimer.periodMax) {
|
||||
nextResponseTime = g_archTickTimer.periodMax;
|
||||
}
|
||||
SysTick->CTRL &= ~CORETIM_ENABLE;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL |= CORETIM_ENABLE;
|
||||
return nextResponseTime;
|
||||
}
|
||||
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
*period = SysTick->LOAD;
|
||||
hwCycle = *period - SysTick->VAL;
|
||||
LOS_IntRestore(intSave);
|
||||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~CORETIM_ENABLE;
|
||||
}
|
||||
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= CORETIM_ENABLE;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
VOID Wfi(VOID)
|
||||
{
|
||||
__asm__ volatile("wait");
|
||||
}
|
||||
|
||||
VOID Dsb(VOID)
|
||||
{
|
||||
__asm__ volatile("sync" : : : "memory");
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
Dsb();
|
||||
Wfi(); //CPU进入低功耗状态,等待中断唤醒
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
115
ohos/kernel/liteos_m/arch/include/los_arch.h
Normal file
115
ohos/kernel/liteos_m/arch/include/los_arch.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2023 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 _LOS_ARCH_H
|
||||
#define _LOS_ARCH_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if defined(__ICCARM__) || defined(__CC_ARM)
|
||||
STATIC INLINE UINTPTR ArchSpGet(VOID)
|
||||
{
|
||||
UINTPTR sp;
|
||||
__asm("mov %0, sp" : "=r" (sp));
|
||||
return sp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR ArchPspGet(VOID)
|
||||
{
|
||||
UINTPTR psp;
|
||||
__asm("mrs %0, psp" : "=r" (psp));
|
||||
return psp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR ArchMspGet(VOID)
|
||||
{
|
||||
UINTPTR msp;
|
||||
__asm("mrs %0, msp" : "=r" (msp));
|
||||
return msp;
|
||||
}
|
||||
|
||||
#define ARCH_LR_GET() \
|
||||
({ \
|
||||
UINTPTR lr; \
|
||||
__asm("mov %0, lr" : "=r" (lr)); \
|
||||
(lr); \
|
||||
})
|
||||
#define ArchLRGet ARCH_LR_GET
|
||||
#elif defined(__CLANG_ARM) || defined(__GNUC__)
|
||||
STATIC INLINE UINTPTR ArchSpGet(VOID)
|
||||
{
|
||||
UINTPTR sp;
|
||||
__asm volatile("mov %0, sp" : "=r" (sp));
|
||||
return sp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR ArchPspGet(VOID)
|
||||
{
|
||||
UINTPTR psp;
|
||||
__asm volatile("mrs %0, psp" : "=r" (psp));
|
||||
return psp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR ArchMspGet(VOID)
|
||||
{
|
||||
UINTPTR msp;
|
||||
__asm volatile("mrs %0, msp" : "=r" (msp));
|
||||
return msp;
|
||||
}
|
||||
|
||||
#define ARCH_LR_GET() \
|
||||
({ \
|
||||
UINTPTR lr; \
|
||||
__asm volatile("mov %0, lr" : "=r" (lr)); \
|
||||
(lr); \
|
||||
})
|
||||
#define ArchLRGet ARCH_LR_GET
|
||||
#else
|
||||
/* Other platforms to be improved */
|
||||
#endif
|
||||
|
||||
VOID ArchInit(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_H */
|
||||
|
||||
71
ohos/kernel/liteos_m/arch/include/los_atomic.h
Normal file
71
ohos/kernel/liteos_m/arch/include/los_atomic.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 _LOS_ATOMIC_H
|
||||
#define _LOS_ATOMIC_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
#include "los_arch_atomic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define LOS_AtomicRead ArchAtomicRead
|
||||
#define LOS_AtomicSet ArchAtomicSet
|
||||
#define LOS_AtomicAdd ArchAtomicAdd
|
||||
#define LOS_AtomicSub ArchAtomicSub
|
||||
#define LOS_AtomicInc ArchAtomicInc
|
||||
#define LOS_AtomicIncRet ArchAtomicIncRet
|
||||
#define LOS_AtomicDec ArchAtomicDec
|
||||
#define LOS_AtomicDecRet ArchAtomicDecRet
|
||||
#define LOS_Atomic64Read ArchAtomic64Read
|
||||
#define LOS_Atomic64Set ArchAtomic64Set
|
||||
#define LOS_Atomic64Add ArchAtomic64Add
|
||||
#define LOS_Atomic64Sub ArchAtomic64Sub
|
||||
#define LOS_Atomic64Inc ArchAtomic64Inc
|
||||
#define LOS_Atomic64IncRet ArchAtomic64IncRet
|
||||
#define LOS_Atomic64Dec ArchAtomic64Dec
|
||||
#define LOS_Atomic64DecRet ArchAtomic64DecRet
|
||||
#define LOS_AtomicXchg32bits ArchAtomicXchg32bits
|
||||
#define LOS_AtomicXchg64bits ArchAtomicXchg64bits
|
||||
#define LOS_AtomicCmpXchg32bits ArchAtomicCmpXchg32bits
|
||||
#define LOS_AtomicCmpXchg64bits ArchAtomicCmpXchg64bits
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ATOMIC_H */
|
||||
|
||||
117
ohos/kernel/liteos_m/arch/include/los_context.h
Normal file
117
ohos/kernel/liteos_m/arch/include/los_context.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_context hardware
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_CONTEXT_H
|
||||
#define _LOS_CONTEXT_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
#include "los_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_context
|
||||
* @brief: Task stack initialization.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize the task stack.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param taskID [IN] Type#UINT32: TaskID.
|
||||
* @param stackSize [IN] Type#UINT32: Total size of the stack.
|
||||
* @param topStack [IN] Type#VOID *: Top of task's stack.
|
||||
*
|
||||
* @retval: context Type#TaskContext *.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_context.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack);
|
||||
|
||||
/**
|
||||
* @ingroup los_context
|
||||
* @brief: Function to sys exit.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to sys exit.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval: None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_context.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
LITE_OS_SEC_TEXT_MINOR NORETURN VOID ArchSysExit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_context
|
||||
* @brief: Task scheduling Function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to scheduling task.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval: None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_context.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
VOID ArchTaskSchedule(VOID);
|
||||
|
||||
UINT32 ArchStartSchedule(VOID);
|
||||
VOID *ArchSignalContextInit(VOID *stackPointer, VOID *stackTop, UINTPTR sigHandler, UINT32 param);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_CONTEXT_H */
|
||||
180
ohos/kernel/liteos_m/arch/include/los_interrupt.h
Normal file
180
ohos/kernel/liteos_m/arch/include/los_interrupt.h
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2023 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 _LOS_INTERRUPT_H
|
||||
#define _LOS_INTERRUPT_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef UINT32 HWI_HANDLE_T;
|
||||
typedef UINT16 HWI_PRIOR_T;
|
||||
typedef UINT16 HWI_MODE_T;
|
||||
typedef UINT32 HWI_ARG_T;
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
typedef VOID (*HWI_PROC_FUNC)(VOID *parm);
|
||||
#else
|
||||
typedef VOID (*HWI_PROC_FUNC)(void);
|
||||
#endif
|
||||
|
||||
typedef struct tagIrqParam {
|
||||
int swIrq; /**< The interrupt number */
|
||||
VOID *pDevId; /**< The pointer to the device ID that launches the interrupt */
|
||||
const CHAR *pName; /**< The interrupt name */
|
||||
} HwiIrqParam;
|
||||
|
||||
typedef struct {
|
||||
UINT32 (*triggerIrq)(HWI_HANDLE_T hwiNum);
|
||||
UINT32 (*clearIrq)(HWI_HANDLE_T hwiNum);
|
||||
UINT32 (*enableIrq)(HWI_HANDLE_T hwiNum);
|
||||
UINT32 (*disableIrq)(HWI_HANDLE_T hwiNum);
|
||||
UINT32 (*setIrqPriority)(HWI_HANDLE_T hwiNum, UINT8 priority);
|
||||
UINT32 (*getCurIrqNum)(VOID);
|
||||
UINT32 (*createIrq)(HWI_HANDLE_T hwiNum, HWI_PRIOR_T hwiPrio);
|
||||
} HwiControllerOps;
|
||||
|
||||
/* stack protector */
|
||||
extern UINT32 __stack_chk_guard;
|
||||
extern VOID __stack_chk_fail(VOID);
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
extern UINT32 OsGetHwiFormCnt(UINT32 index);
|
||||
extern CHAR *OsGetHwiFormName(UINT32 index);
|
||||
extern BOOL OsHwiIsCreated(UINT32 index);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_interrupt
|
||||
* @brief Delete hardware interrupt.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete hardware interrupt.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The hardware interrupt module is usable only when the configuration item for hardware
|
||||
* interrupt tailoring is enabled.</li>
|
||||
* <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range
|
||||
* applicable for a Cortex-A7 platform is [32,95].</li>
|
||||
* <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
|
||||
* <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param hwiNum [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable
|
||||
* for a Cortex-A7 platform is [32,95].
|
||||
* @param irqParam [IN] Type #HwiIrqParam *. ID of hardware interrupt which will base on
|
||||
* when delete the hardware interrupt.
|
||||
* @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number.
|
||||
* @retval #LOS_OK 0 : The interrupt is successfully delete.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam);
|
||||
|
||||
/**
|
||||
* @ingroup los_interrupt
|
||||
* @brief Create a hardware interrupt.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to configure a hardware interrupt and register a hardware interrupt handling function.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The hardware interrupt module is usable only when the configuration item for hardware
|
||||
* interrupt tailoring is enabled.</li>
|
||||
* <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range
|
||||
* applicable for a Cortex-A7 platform is [32,95].</li>
|
||||
* <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
|
||||
* <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param hwiNum [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a
|
||||
* Cortex-A7 platform is [32,95].
|
||||
* @param hwiPrio [IN] Type#HWI_PRIOR_T: hardware interrupt priority. Ignore this parameter temporarily.
|
||||
* @param mode [IN] Type#HWI_MODE_T: hardware interrupt mode. Ignore this parameter temporarily.
|
||||
* @param handler [IN] Type#HWI_PROC_FUNC: interrupt handler used when a hardware interrupt is triggered.
|
||||
* @param irqParam [IN] Type#HwiIrqParam: input parameter of the interrupt
|
||||
* handler used when a hardware interrupt is triggered.
|
||||
*
|
||||
* @retval #OS_ERRNO_HWI_PROC_FUNC_NULL 0x02000901: Null hardware interrupt handling function.
|
||||
* @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number.
|
||||
* @retval #OS_ERRNO_HWI_NO_MEMORY 0x02000903: Insufficient memory for hardware interrupt creation.
|
||||
* @retval #OS_ERRNO_HWI_ALREADY_CREATED 0x02000904: The interrupt handler being created has
|
||||
* already been created.
|
||||
* @retval #LOS_OK 0 : The interrupt is successfully created.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum, HWI_PRIOR_T hwiPrio, HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler, HwiIrqParam *irqParam);
|
||||
UINT32 ArchIsIntActive(VOID);
|
||||
UINT32 ArchIntLock(VOID);
|
||||
UINT32 ArchIntUnLock(VOID);
|
||||
VOID ArchIntRestore(UINT32 intSave);
|
||||
UINT32 ArchIntTrigger(HWI_HANDLE_T hwiNum);
|
||||
UINT32 ArchIntEnable(HWI_HANDLE_T hwiNum);
|
||||
UINT32 ArchIntDisable(HWI_HANDLE_T hwiNum);
|
||||
UINT32 ArchIntClear(HWI_HANDLE_T hwiNum);
|
||||
UINT32 ArchIntSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority);
|
||||
UINT32 ArchIntCurIrqNum(VOID);
|
||||
HwiControllerOps *ArchIntOpsGet(VOID);
|
||||
|
||||
#define OS_INT_ACTIVE (ArchIsIntActive())
|
||||
#define OS_INT_INACTIVE (!(OS_INT_ACTIVE))
|
||||
#define LOS_IntLock ArchIntLock
|
||||
#define LOS_IntRestore ArchIntRestore
|
||||
#define LOS_IntUnLock ArchIntUnLock
|
||||
#define LOS_HwiDelete ArchHwiDelete
|
||||
#define LOS_HwiCreate ArchHwiCreate
|
||||
#define LOS_HwiTrigger ArchIntTrigger
|
||||
#define LOS_HwiEnable ArchIntEnable
|
||||
#define LOS_HwiDisable ArchIntDisable
|
||||
#define LOS_HwiClear ArchIntClear
|
||||
#define LOS_HwiSetPriority ArchIntSetPriority
|
||||
#define LOS_HwiCurIrqNum ArchIntCurIrqNum
|
||||
#define LOS_HwiOpsGet ArchIntOpsGet
|
||||
#define LOS_IntLocked ArchIntLocked
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_INTERRUPT_H */
|
||||
94
ohos/kernel/liteos_m/arch/include/los_mpu.h
Normal file
94
ohos/kernel/liteos_m/arch/include/los_mpu.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup memory protection
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MPU_H
|
||||
#define _LOS_MPU_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef enum {
|
||||
MPU_RW_BY_PRIVILEGED_ONLY = 0,
|
||||
MPU_RW_ANY = 1,
|
||||
MPU_RO_BY_PRIVILEGED_ONLY = 2,
|
||||
MPU_RO_ANY = 3,
|
||||
} MpuAccessPermission;
|
||||
|
||||
typedef enum {
|
||||
MPU_EXECUTABLE = 0,
|
||||
MPU_NON_EXECUTABLE = 1,
|
||||
} MpuExecutable;
|
||||
|
||||
typedef enum {
|
||||
MPU_NO_SHARE = 0,
|
||||
MPU_SHARE = 1,
|
||||
} MpuShareability;
|
||||
|
||||
typedef enum {
|
||||
MPU_MEM_ON_CHIP_ROM = 0,
|
||||
MPU_MEM_ON_CHIP_RAM = 1,
|
||||
MPU_MEM_XIP_PSRAM = 2,
|
||||
MPU_MEM_XIP_NOR_FLASH = 3,
|
||||
MPU_MEM_SHARE_MEM = 4,
|
||||
} MpuMemType;
|
||||
|
||||
typedef struct {
|
||||
UINT32 baseAddr;
|
||||
UINT64 size; /* armv7 size == 2^x (5 <= x <= 32) 128B - 4GB */
|
||||
MpuAccessPermission permission;
|
||||
MpuExecutable executable;
|
||||
MpuShareability shareability;
|
||||
MpuMemType memType;
|
||||
} MPU_CFG_PARA;
|
||||
|
||||
VOID ArchMpuEnable(UINT32 defaultRegionEnable);
|
||||
VOID ArchMpuDisable(VOID);
|
||||
UINT32 ArchMpuSetRegion(UINT32 regionId, MPU_CFG_PARA *para);
|
||||
UINT32 ArchMpuDisableRegion(UINT32 regionId);
|
||||
INT32 ArchMpuUnusedRegionGet(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_MPU_H */
|
||||
94
ohos/kernel/liteos_m/arch/include/los_timer.h
Normal file
94
ohos/kernel/liteos_m/arch/include/los_timer.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 _LOS_TIMER_H
|
||||
#define _LOS_TIMER_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
#include "los_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define TICK_CHECK 0x4000000
|
||||
#define CYCLE_CHECK 0xFFFFFFFFU
|
||||
#define SHIFT_32_BIT 32
|
||||
#define MAX_HOUR 24
|
||||
#define MAX_MINUTES 60
|
||||
#define MAX_SECONDS 60
|
||||
#define MILSEC 1000
|
||||
#define RTC_WAKEUPCLOCK_RTCCLK 32768
|
||||
#define RTC_WAKEUPCLOCK_RTCCLK_DIV 16
|
||||
#define RTC_CALIBRATE_SLEEP_TIME 8
|
||||
#define MACHINE_CYCLE_DEALAY_TIMES (LOSCFG_BASE_CORE_TICK_PER_SECOND << 2)
|
||||
|
||||
typedef struct {
|
||||
UINT32 freq;
|
||||
INT32 irqNum;
|
||||
UINT64 periodMax;
|
||||
UINT32 (*init)(HWI_PROC_FUNC tickHandler);
|
||||
UINT64 (*getCycle)(UINT32 *period);
|
||||
UINT64 (*reload)(UINT64 time);
|
||||
VOID (*lock)(VOID);
|
||||
VOID (*unlock)(VOID);
|
||||
HWI_PROC_FUNC tickHandler;
|
||||
} ArchTickTimer;
|
||||
|
||||
UINT32 ArchEnterSleep(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_timer
|
||||
* @brief Get tick timer control block.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get tick timer control block.
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @retval #tick timer control block
|
||||
* @par Dependency:
|
||||
* <ul><li>los_timer.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID);
|
||||
|
||||
#define LOS_SysTickTimerGet ArchSysTickTimerGet
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_TIMER_H */
|
||||
757
ohos/kernel/liteos_m/components/cpup/los_cpup.c
Normal file
757
ohos/kernel/liteos_m/components/cpup/los_cpup.c
Normal file
@@ -0,0 +1,757 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 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_cpup.h"
|
||||
#include "securec.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_tick.h"
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
#include "los_swtmr.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
#include "los_arch_interrupt.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_CPUP == 1)
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage-type macro: used for tasks.
|
||||
*/
|
||||
#define OS_THREAD_TYPE_TASK 0
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage-type macro: used for hardware interrupts.
|
||||
*/
|
||||
#define OS_THREAD_TYPE_HWI 1
|
||||
|
||||
#define OS_CPUP_RECORD_PERIOD (g_sysClock)
|
||||
|
||||
#define OS_SYS_CYCLE_TO_US(cycle) ((cycle) / (g_sysClock)) * OS_SYS_US_PER_SECOND + \
|
||||
((cycle) % (g_sysClock) * OS_SYS_US_PER_SECOND / (g_sysClock))
|
||||
|
||||
LITE_OS_SEC_BSS UINT16 g_cpupInitFlg = 0;
|
||||
LITE_OS_SEC_BSS OsCpupCB *g_cpup = NULL;
|
||||
LITE_OS_SEC_BSS UINT64 g_lastRecordTime;
|
||||
LITE_OS_SEC_BSS UINT16 g_hisPos; /* current Sampling point of historyTime */
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
LITE_OS_SEC_BSS UINT16 g_irqCpupInitFlg = 0;
|
||||
LITE_OS_SEC_BSS UINT16 g_irqHisPos = 0; /* current Sampling point of historyTime */
|
||||
LITE_OS_SEC_BSS UINT64 g_irqLastRecordTime;
|
||||
LITE_OS_SEC_BSS OsIrqCpupCB *g_irqCpup = NULL;
|
||||
LITE_OS_SEC_BSS STATIC UINT64 g_cpuHistoryTime[OS_CPUP_HISTORY_RECORD_NUM];
|
||||
#define OS_CPUP_USED 0x1U
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID)
|
||||
{
|
||||
UINT16 prevPos;
|
||||
UINT32 loop;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
prevPos = g_irqHisPos;
|
||||
|
||||
if (g_irqHisPos == OS_CPUP_HISTORY_RECORD_NUM - 1) {
|
||||
g_irqHisPos = 0;
|
||||
} else {
|
||||
g_irqHisPos++;
|
||||
}
|
||||
|
||||
g_cpuHistoryTime[prevPos] = 0;
|
||||
for (loop = 0; loop < LOSCFG_PLATFORM_HWI_LIMIT; loop++) {
|
||||
if (g_irqCpup[loop].status != OS_CPUP_USED) {
|
||||
continue;
|
||||
}
|
||||
g_irqCpup[loop].historyTime[prevPos] = g_irqCpup[loop].allTime;
|
||||
g_cpuHistoryTime[prevPos] += g_irqCpup[loop].allTime;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsCpupGuardCreator(VOID)
|
||||
{
|
||||
UINT32 cpupSwtmrID;
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
(VOID)LOS_SwtmrCreate(LOSCFG_BASE_CORE_TICK_PER_SECOND, LOS_SWTMR_MODE_PERIOD,
|
||||
(SWTMR_PROC_FUNC)OsCpupGuard, &cpupSwtmrID, 0,
|
||||
OS_SWTMR_ROUSES_ALLOW, OS_SWTMR_ALIGN_INSENSITIVE);
|
||||
#else
|
||||
(VOID)LOS_SwtmrCreate(LOSCFG_BASE_CORE_TICK_PER_SECOND, LOS_SWTMR_MODE_PERIOD,
|
||||
(SWTMR_PROC_FUNC)OsCpupGuard, &cpupSwtmrID, 0);
|
||||
#endif
|
||||
|
||||
(VOID)LOS_SwtmrStart(cpupSwtmrID);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsCpupDaemonInit
|
||||
Description: initialization of CPUP Daemon
|
||||
Input : None
|
||||
Return : LOS_OK or Error Information
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsCpupDaemonInit()
|
||||
{
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
(VOID)OsCpupGuardCreator();
|
||||
g_irqCpupInitFlg = 1;
|
||||
#endif
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsCpupInit
|
||||
Description: initialization of CPUP
|
||||
Input : None
|
||||
Return : LOS_OK or Error Information
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit()
|
||||
{
|
||||
UINT32 size;
|
||||
CHAR *cpupMem = NULL;
|
||||
|
||||
size = g_taskMaxNum * sizeof(OsCpupCB);
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
size += LOSCFG_PLATFORM_HWI_LIMIT * sizeof(OsIrqCpupCB);
|
||||
#endif
|
||||
|
||||
cpupMem = LOS_MemAlloc(m_aucSysMem0, size);
|
||||
if (cpupMem == NULL) {
|
||||
return LOS_ERRNO_CPUP_NO_MEMORY;
|
||||
}
|
||||
(VOID)memset_s(cpupMem, size, 0, size);
|
||||
|
||||
g_cpup = (OsCpupCB *)cpupMem;
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
g_irqCpup = (OsIrqCpupCB *)(cpupMem + g_taskMaxNum * sizeof(OsCpupCB));
|
||||
#endif
|
||||
|
||||
g_cpupInitFlg = 1;
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* The calculation time unit is changed to us to decouple the influence of
|
||||
* system frequency modulation on CPUP
|
||||
*/
|
||||
STATIC UINT64 CpupTimeUsGet(VOID)
|
||||
{
|
||||
UINT64 time = LOS_SysCycleGet();
|
||||
return OS_SYS_CYCLE_TO_US(time);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsTskCycleStart
|
||||
Description: start task to get cycles count in current task beginning
|
||||
Input : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleStart(VOID)
|
||||
{
|
||||
UINT32 taskID;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
taskID = g_losTask.newTask->taskID;
|
||||
g_cpup[taskID].cpupID = taskID;
|
||||
g_cpup[taskID].startTime = CpupTimeUsGet();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsTskCycleEnd
|
||||
Description: quit task and get cycle count
|
||||
Input : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEnd(VOID)
|
||||
{
|
||||
UINT32 taskID;
|
||||
UINT64 cpuTime;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
taskID = g_losTask.runTask->taskID;
|
||||
|
||||
if (g_cpup[taskID].startTime == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
cpuTime = CpupTimeUsGet();
|
||||
if (cpuTime < g_cpup[taskID].startTime) {
|
||||
cpuTime += OS_US_PER_TICK;
|
||||
}
|
||||
|
||||
g_cpup[taskID].allTime += (cpuTime - g_cpup[taskID].startTime);
|
||||
g_cpup[taskID].startTime = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsTskCycleEndStart
|
||||
Description: start task to get cycles count in current task ending
|
||||
Input : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEndStart(VOID)
|
||||
{
|
||||
UINT32 taskID;
|
||||
UINT64 cpuTime;
|
||||
UINT16 loopNum;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
taskID = g_losTask.runTask->taskID;
|
||||
cpuTime = CpupTimeUsGet();
|
||||
|
||||
if (g_cpup[taskID].startTime != 0) {
|
||||
if (cpuTime < g_cpup[taskID].startTime) {
|
||||
cpuTime += OS_US_PER_TICK;
|
||||
}
|
||||
|
||||
g_cpup[taskID].allTime += (cpuTime - g_cpup[taskID].startTime);
|
||||
g_cpup[taskID].startTime = 0;
|
||||
}
|
||||
|
||||
taskID = g_losTask.newTask->taskID;
|
||||
g_cpup[taskID].cpupID = taskID;
|
||||
g_cpup[taskID].startTime = cpuTime;
|
||||
|
||||
if ((cpuTime - g_lastRecordTime) > OS_CPUP_RECORD_PERIOD) {
|
||||
g_lastRecordTime = cpuTime;
|
||||
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
g_cpup[loopNum].historyTime[g_hisPos] = g_cpup[loopNum].allTime;
|
||||
}
|
||||
|
||||
if (g_hisPos == (OS_CPUP_HISTORY_RECORD_NUM - 1)) {
|
||||
g_hisPos = 0;
|
||||
} else {
|
||||
g_hisPos++;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR STATIC INLINE UINT16 OsGetPrePos(UINT16 curPos)
|
||||
{
|
||||
return (curPos == 0) ? (OS_CPUP_HISTORY_RECORD_NUM - 1) : (curPos - 1);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsGetPositions(UINT16 mode, UINT16* curPosAddr, UINT16* prePosAddr)
|
||||
{
|
||||
UINT16 curPos;
|
||||
UINT16 prePos = 0;
|
||||
|
||||
curPos = g_hisPos;
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
curPos = OsGetPrePos(curPos);
|
||||
prePos = OsGetPrePos(curPos);
|
||||
} else if (mode == CPUP_LESS_THAN_1S) {
|
||||
curPos = OsGetPrePos(curPos);
|
||||
}
|
||||
|
||||
*curPosAddr = curPos;
|
||||
*prePosAddr = prePos;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SysCpuUsage
|
||||
Description: get current CPU usage
|
||||
Input : None
|
||||
Return : cpupRet:current CPU usage
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_SysCpuUsage(VOID)
|
||||
{
|
||||
UINT64 cpuTimeAll = 0;
|
||||
UINT32 cpupRet = 0;
|
||||
UINT16 loopNum;
|
||||
UINT32 intSave;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return LOS_ERRNO_CPUP_NO_INIT;
|
||||
}
|
||||
|
||||
// get end time of current task
|
||||
intSave = LOS_IntLock();
|
||||
OsTskCycleEnd();
|
||||
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
cpuTimeAll += g_cpup[loopNum].allTime;
|
||||
}
|
||||
|
||||
if (cpuTimeAll) {
|
||||
cpupRet = LOS_CPUP_PRECISION - (UINT32)((LOS_CPUP_PRECISION *
|
||||
g_cpup[g_idleTaskID].allTime) / cpuTimeAll);
|
||||
}
|
||||
|
||||
OsTskCycleStart();
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return cpupRet;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_HistorySysCpuUsage
|
||||
Description: get CPU usage history
|
||||
Input : mode: mode,0 = usage in 10s,1 = usage in last 1s, else = less than 1s
|
||||
Return : cpupRet:CPU usage history
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistorySysCpuUsage(UINT16 mode)
|
||||
{
|
||||
UINT64 cpuTimeAll = 0;
|
||||
UINT64 idleCycleAll = 0;
|
||||
UINT32 cpupRet = 0;
|
||||
UINT16 loopNum;
|
||||
UINT16 curPos;
|
||||
UINT16 prePos = 0;
|
||||
UINT32 intSave;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return LOS_ERRNO_CPUP_NO_INIT;
|
||||
}
|
||||
|
||||
// get end time of current task
|
||||
intSave = LOS_IntLock();
|
||||
OsTskCycleEnd();
|
||||
|
||||
OsGetPositions(mode, &curPos, &prePos);
|
||||
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
if (mode == CPUP_IN_1S) {
|
||||
cpuTimeAll += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
|
||||
} else {
|
||||
cpuTimeAll += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
idleCycleAll += g_cpup[g_idleTaskID].historyTime[curPos] -
|
||||
g_cpup[g_idleTaskID].historyTime[prePos];
|
||||
} else {
|
||||
idleCycleAll += g_cpup[g_idleTaskID].allTime - g_cpup[g_idleTaskID].historyTime[curPos];
|
||||
}
|
||||
|
||||
if (cpuTimeAll) {
|
||||
cpupRet = (LOS_CPUP_PRECISION - (UINT32)((LOS_CPUP_PRECISION * idleCycleAll) / cpuTimeAll));
|
||||
}
|
||||
|
||||
OsTskCycleStart();
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return cpupRet;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_TaskCpuUsage
|
||||
Description: get CPU usage of certain task
|
||||
Input : taskID : task ID
|
||||
Return : cpupRet:CPU usage of certain task
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuUsage(UINT32 taskID)
|
||||
{
|
||||
UINT64 cpuTimeAll = 0;
|
||||
UINT16 loopNum;
|
||||
UINT32 intSave;
|
||||
UINT32 cpupRet = 0;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return LOS_ERRNO_CPUP_NO_INIT;
|
||||
}
|
||||
if (OS_TSK_GET_INDEX(taskID) >= g_taskMaxNum) {
|
||||
return LOS_ERRNO_CPUP_TSK_ID_INVALID;
|
||||
}
|
||||
if (g_cpup[taskID].cpupID != taskID) {
|
||||
return LOS_ERRNO_CPUP_THREAD_NO_CREATED;
|
||||
}
|
||||
if ((g_cpup[taskID].status & OS_TASK_STATUS_UNUSED) || (g_cpup[taskID].status == 0)) {
|
||||
return LOS_ERRNO_CPUP_THREAD_NO_CREATED;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
OsTskCycleEnd();
|
||||
|
||||
/* get total Cycle */
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
if ((g_cpup[loopNum].status & OS_TASK_STATUS_UNUSED) || (g_cpup[loopNum].status == 0)) {
|
||||
continue;
|
||||
}
|
||||
cpuTimeAll += g_cpup[loopNum].allTime;
|
||||
}
|
||||
|
||||
if (cpuTimeAll) {
|
||||
cpupRet = (UINT32)((LOS_CPUP_PRECISION * g_cpup[taskID].allTime) / cpuTimeAll);
|
||||
}
|
||||
|
||||
OsTskCycleStart();
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return cpupRet;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_HistoryTaskCpuUsage
|
||||
Description: get CPU usage history of certain task
|
||||
Input : taskID : task ID
|
||||
: mode: mode,0 = usage in 10s,1 = usage in last 1s, else = less than 1s
|
||||
Return : cpupRet:CPU usage history of task
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskID, UINT16 mode)
|
||||
{
|
||||
UINT64 cpuTimeAll = 0;
|
||||
UINT64 cpuTimeCurTsk = 0;
|
||||
UINT16 loopNum, curPos;
|
||||
UINT16 prePos = 0;
|
||||
UINT32 intSave;
|
||||
UINT32 cpupRet = 0;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return LOS_ERRNO_CPUP_NO_INIT;
|
||||
}
|
||||
if (OS_TSK_GET_INDEX(taskID) >= g_taskMaxNum) {
|
||||
return LOS_ERRNO_CPUP_TSK_ID_INVALID;
|
||||
}
|
||||
if (g_cpup[taskID].cpupID != taskID) {
|
||||
return LOS_ERRNO_CPUP_THREAD_NO_CREATED;
|
||||
}
|
||||
if ((g_cpup[taskID].status & OS_TASK_STATUS_UNUSED) || (g_cpup[taskID].status == 0)) {
|
||||
return LOS_ERRNO_CPUP_THREAD_NO_CREATED;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
OsTskCycleEnd();
|
||||
|
||||
OsGetPositions(mode, &curPos, &prePos);
|
||||
|
||||
/* get total Cycle in history */
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
if ((g_cpup[loopNum].status & OS_TASK_STATUS_UNUSED) || (g_cpup[loopNum].status == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
cpuTimeAll += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
|
||||
} else {
|
||||
cpuTimeAll += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
cpuTimeCurTsk += g_cpup[taskID].historyTime[curPos] - g_cpup[taskID].historyTime[prePos];
|
||||
} else {
|
||||
cpuTimeCurTsk += g_cpup[taskID].allTime - g_cpup[taskID].historyTime[curPos];
|
||||
}
|
||||
if (cpuTimeAll) {
|
||||
cpupRet = (UINT32)((LOS_CPUP_PRECISION * cpuTimeCurTsk) / cpuTimeAll);
|
||||
}
|
||||
|
||||
OsTskCycleStart();
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return cpupRet;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16 mode)
|
||||
{
|
||||
UINT16 loopNum;
|
||||
UINT16 curPos;
|
||||
UINT16 prePos = 0;
|
||||
UINT32 intSave;
|
||||
UINT64 cpuTimeAll = 0;
|
||||
UINT64 cpuTimeCurTsk = 0;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return LOS_ERRNO_CPUP_NO_INIT;
|
||||
}
|
||||
|
||||
if (cpupInfo == NULL) {
|
||||
return LOS_ERRNO_CPUP_TASK_PTR_NULL;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
OsTskCycleEnd();
|
||||
|
||||
OsGetPositions(mode, &curPos, &prePos);
|
||||
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
if ((g_cpup[loopNum].status & OS_TASK_STATUS_UNUSED) ||
|
||||
(g_cpup[loopNum].status == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
cpuTimeAll += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
|
||||
} else {
|
||||
cpuTimeAll += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
|
||||
}
|
||||
}
|
||||
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
if ((g_cpup[loopNum].status & OS_TASK_STATUS_UNUSED) ||
|
||||
(g_cpup[loopNum].status == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
cpuTimeCurTsk += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
|
||||
} else {
|
||||
cpuTimeCurTsk += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
|
||||
}
|
||||
cpupInfo[loopNum].usStatus = g_cpup[loopNum].status;
|
||||
if (cpuTimeAll) {
|
||||
cpupInfo[loopNum].uwUsage = (UINT32)((LOS_CPUP_PRECISION * cpuTimeCurTsk) / cpuTimeAll);
|
||||
}
|
||||
|
||||
cpuTimeCurTsk = 0;
|
||||
}
|
||||
|
||||
OsTskCycleStart();
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_CpupUsageMonitor
|
||||
Description: Get CPU usage history of certain task.
|
||||
Input : type: cpup type, SYS_CPU_USAGE and TASK_CPU_USAGE
|
||||
: taskID: task ID, Only in SYS_CPU_USAGE type, taskID is invalid
|
||||
: mode: mode, CPUP_IN_10S = usage in 10s, CPUP_IN_1S = usage in last 1s, CPUP_LESS_THAN_1S = less than 1s
|
||||
Return : LOS_OK on success, or OS_ERROR on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CpupUsageMonitor(CPUP_TYPE_E type, CPUP_MODE_E mode, UINT32 taskID)
|
||||
{
|
||||
UINT32 ret;
|
||||
LosTaskCB *taskCB = NULL;
|
||||
|
||||
switch (type) {
|
||||
case SYS_CPU_USAGE:
|
||||
if (mode == CPUP_IN_10S) {
|
||||
PRINTK("\nSysCpuUsage in 10s: ");
|
||||
} else if (mode == CPUP_IN_1S) {
|
||||
PRINTK("\nSysCpuUsage in 1s: ");
|
||||
} else {
|
||||
PRINTK("\nSysCpuUsage in <1s: ");
|
||||
}
|
||||
ret = LOS_HistorySysCpuUsage(mode);
|
||||
PRINTK("%d.%d", ret / LOS_CPUP_PRECISION_MULT, ret % LOS_CPUP_PRECISION_MULT);
|
||||
break;
|
||||
|
||||
case TASK_CPU_USAGE:
|
||||
if (taskID > LOSCFG_BASE_CORE_TSK_LIMIT) {
|
||||
PRINT_ERR("\nThe taskid is invalid.\n");
|
||||
return OS_ERROR;
|
||||
}
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
if ((taskCB->taskStatus & OS_TASK_STATUS_UNUSED)) {
|
||||
PRINT_ERR("\nThe taskid is invalid.\n");
|
||||
return OS_ERROR;
|
||||
}
|
||||
if (mode == CPUP_IN_10S) {
|
||||
PRINTK("\nCPUusage of taskID %d in 10s: ", taskID);
|
||||
} else if (mode == CPUP_IN_1S) {
|
||||
PRINTK("\nCPUusage of taskID %d in 1s: ", taskID);
|
||||
} else {
|
||||
PRINTK("\nCPUusage of taskID %d in <1s: ", taskID);
|
||||
}
|
||||
ret = LOS_HistoryTaskCpuUsage(taskID, mode);
|
||||
PRINTK("%u.%u", ret / LOS_CPUP_PRECISION_MULT, ret % LOS_CPUP_PRECISION_MULT);
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_ERR("\nThe type is invalid.\n");
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqStart(UINT32 intNum)
|
||||
{
|
||||
if (g_irqCpupInitFlg == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_irqCpup[intNum].startTime = CpupTimeUsGet();
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqEnd(UINT32 intNum)
|
||||
{
|
||||
UINT64 cpuTime;
|
||||
UINT64 usedTime;
|
||||
|
||||
if (g_irqCpupInitFlg == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_irqCpup[intNum].startTime == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
cpuTime = CpupTimeUsGet();
|
||||
if (cpuTime < g_irqCpup[intNum].startTime) {
|
||||
cpuTime += OS_US_PER_TICK;
|
||||
}
|
||||
|
||||
g_irqCpup[intNum].cpupID = intNum;
|
||||
g_irqCpup[intNum].status = OS_CPUP_USED;
|
||||
usedTime = cpuTime - g_irqCpup[intNum].startTime;
|
||||
|
||||
if (g_irqCpup[intNum].count <= 1000) { /* 1000, Take 1000 samples */
|
||||
g_irqCpup[intNum].allTime += usedTime;
|
||||
g_irqCpup[intNum].count++;
|
||||
} else {
|
||||
g_irqCpup[intNum].allTime = 0;
|
||||
g_irqCpup[intNum].count = 0;
|
||||
}
|
||||
g_irqCpup[intNum].startTime = 0;
|
||||
if (usedTime > g_irqCpup[intNum].timeMax) {
|
||||
g_irqCpup[intNum].timeMax = usedTime;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR OsIrqCpupCB *OsGetIrqCpupArrayBase(VOID)
|
||||
{
|
||||
return g_irqCpup;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsGetIrqPositions(UINT16 mode, UINT16* curPosAddr, UINT16* prePosAddr)
|
||||
{
|
||||
UINT16 curPos;
|
||||
UINT16 prePos = 0;
|
||||
|
||||
curPos = g_irqHisPos;
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
curPos = OsGetPrePos(curPos);
|
||||
prePos = OsGetPrePos(curPos);
|
||||
} else if (mode == CPUP_LESS_THAN_1S) {
|
||||
curPos = OsGetPrePos(curPos);
|
||||
}
|
||||
|
||||
*curPosAddr = curPos;
|
||||
*prePosAddr = prePos;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR STATIC UINT64 OsGetIrqAllTime(VOID)
|
||||
{
|
||||
INT32 i;
|
||||
UINT64 cpuTimeAll = 0;
|
||||
for (i = 0; i < OS_CPUP_HISTORY_RECORD_NUM; i++) {
|
||||
cpuTimeAll += g_cpuHistoryTime[i];
|
||||
}
|
||||
|
||||
return cpuTimeAll;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR STATIC UINT64 OsGetIrqAllHisTime(UINT32 num)
|
||||
{
|
||||
INT32 i;
|
||||
UINT64 historyTime = 0;
|
||||
for (i = 0; i < OS_CPUP_HISTORY_RECORD_NUM; i++) {
|
||||
historyTime += g_irqCpup[num].historyTime[i];
|
||||
}
|
||||
|
||||
return historyTime;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_GetAllIrqCpuUsage(UINT16 mode, CPUP_INFO_S *cpupInfo)
|
||||
{
|
||||
UINT16 loopNum;
|
||||
UINT16 curPos;
|
||||
UINT16 prePos = 0;
|
||||
UINT32 intSave;
|
||||
UINT64 cpuTimeAll;
|
||||
UINT64 cpuTimeCurIrq;
|
||||
|
||||
if (g_irqCpupInitFlg == 0) {
|
||||
return LOS_ERRNO_CPUP_NO_INIT;
|
||||
}
|
||||
|
||||
if (cpupInfo == NULL) {
|
||||
return LOS_ERRNO_CPUP_TASK_PTR_NULL;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
OsGetIrqPositions(mode, &curPos, &prePos);
|
||||
if (mode == CPUP_IN_10S) {
|
||||
cpuTimeAll = OsGetIrqAllTime();
|
||||
} else {
|
||||
cpuTimeAll = g_cpuHistoryTime[curPos] - g_cpuHistoryTime[prePos];
|
||||
}
|
||||
|
||||
for (loopNum = 0; loopNum < LOSCFG_PLATFORM_HWI_LIMIT; loopNum++) {
|
||||
if (g_irqCpup[loopNum].status != OS_CPUP_USED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cpupInfo[loopNum].usStatus = g_irqCpup[loopNum].status;
|
||||
|
||||
if (mode == CPUP_IN_10S) {
|
||||
cpuTimeCurIrq = OsGetIrqAllHisTime(loopNum);
|
||||
} else {
|
||||
cpuTimeCurIrq = g_irqCpup[loopNum].historyTime[curPos] - g_irqCpup[loopNum].historyTime[prePos];
|
||||
}
|
||||
|
||||
if (cpuTimeAll != 0) {
|
||||
cpupInfo[loopNum].uwUsage = (UINT32)((LOS_CPUP_PRECISION * cpuTimeCurIrq) / cpuTimeAll);
|
||||
}
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LOSCFG_BASE_CORE_CPUP */
|
||||
389
ohos/kernel/liteos_m/components/cpup/los_cpup.h
Normal file
389
ohos/kernel/liteos_m/components/cpup/los_cpup.h
Normal file
@@ -0,0 +1,389 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_cpup CPU usage
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_CPUP_H
|
||||
#define _LOS_CPUP_H
|
||||
|
||||
#include "los_interrupt.h"
|
||||
#include "los_task.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage error code: The request for memory fails.
|
||||
*
|
||||
* Value: 0x02001e00
|
||||
*
|
||||
* Solution: Decrease the maximum number of tasks.
|
||||
*/
|
||||
#define LOS_ERRNO_CPUP_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage error code: The pointer to an input parameter is NULL.
|
||||
*
|
||||
* Value: 0x02001e01
|
||||
*
|
||||
* Solution: Check whether the pointer to the input parameter is usable.
|
||||
*/
|
||||
#define LOS_ERRNO_CPUP_TASK_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage error code: The CPU usage is not initialized.
|
||||
*
|
||||
* Value: 0x02001e02
|
||||
*
|
||||
* Solution: Check whether the CPU usage is initialized.
|
||||
*/
|
||||
#define LOS_ERRNO_CPUP_NO_INIT LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage error code: The number of threads is invalid.
|
||||
*
|
||||
* Value: 0x02001e03
|
||||
*
|
||||
* Solution: Check whether the number of threads is applicable for the current operation.
|
||||
*/
|
||||
#define LOS_ERRNO_CPUP_MAXNUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage error code: The target thread is not created.
|
||||
*
|
||||
* Value: 0x02001e04
|
||||
*
|
||||
* Solution: Check whether the target thread is created.
|
||||
*/
|
||||
#define LOS_ERRNO_CPUP_THREAD_NO_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage error code: The target task ID is invalid.
|
||||
*
|
||||
* Value: 0x02001e05
|
||||
*
|
||||
* Solution: Check whether the target task ID is applicable for the current operation.
|
||||
*/
|
||||
#define LOS_ERRNO_CPUP_TSK_ID_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* Sum of cpup with all tasks. It means the value of cpup is a permillage.
|
||||
*/
|
||||
#define LOS_CPUP_PRECISION 1000
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* Multiple of current cpup precision change to percent.
|
||||
*/
|
||||
#define LOS_CPUP_PRECISION_MULT (LOS_CPUP_PRECISION / 100)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* Number of historical running time records
|
||||
*/
|
||||
#define OS_CPUP_HISTORY_RECORD_NUM 10
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* Count the CPU usage structures of a task.
|
||||
*/
|
||||
typedef struct {
|
||||
UINT32 cpupID; /**< Task ID */
|
||||
UINT16 status; /**< Task status */
|
||||
UINT64 allTime; /**< Total running time */
|
||||
UINT64 startTime; /**< Time before a task is invoked */
|
||||
UINT64 historyTime[OS_CPUP_HISTORY_RECORD_NUM]; /**< Historical running time */
|
||||
} OsCpupCB;
|
||||
|
||||
extern OsCpupCB *g_cpup;
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
typedef struct {
|
||||
UINT32 cpupID; /**< Irq ID */
|
||||
UINT16 status; /**< Irq status */
|
||||
UINT64 allTime; /**< Total running time */
|
||||
UINT64 startTime; /**< Time before a task is invoked */
|
||||
UINT64 timeMax; /**< Irq samples count */
|
||||
UINT64 count; /**< Irq samples count */
|
||||
UINT64 historyTime[OS_CPUP_HISTORY_RECORD_NUM]; /**< Historical running time */
|
||||
} OsIrqCpupCB;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Initialization cpup.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialization cpup.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval UINT32 Initialization result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsCpupInit(VOID);
|
||||
|
||||
extern UINT32 OsCpupDaemonInit(VOID);
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Start task to get cycles count in current task ending.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to start task to get cycles count in current task ending.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsTskCycleEndStart(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* Count the CPU usage structures of all tasks.
|
||||
*/
|
||||
typedef struct tagCpupInfo {
|
||||
UINT16 usStatus; /**< save the cur task status */
|
||||
UINT32 uwUsage; /**< Usage. The value range is [0,1000]. */
|
||||
} CPUP_INFO_S;
|
||||
|
||||
/**
|
||||
* @ingroup los_monitor
|
||||
* Type of the CPU usage query.
|
||||
*/
|
||||
typedef enum {
|
||||
SYS_CPU_USAGE = 0, /* system cpu occupancy rate */
|
||||
TASK_CPU_USAGE, /* task cpu occupancy rate */
|
||||
} CPUP_TYPE_E;
|
||||
|
||||
/**
|
||||
* @ingroup los_monitor
|
||||
* Mode of the CPU usage query.
|
||||
*/
|
||||
typedef enum {
|
||||
CPUP_IN_10S = 0, /* cpu occupancy rate in 10s */
|
||||
CPUP_IN_1S, /* cpu occupancy rate in 1s */
|
||||
CPUP_LESS_THAN_1S, /* cpu occupancy rate less than 1s, if the input mode is none of them, it will be this. */
|
||||
} CPUP_MODE_E;
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Obtain the current CPU usage.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the current CPU usage.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after the CPU usage is initialized. Otherwise, error codes will be returned.</li>
|
||||
* <li> The precision of the CPU usage can be adjusted by changing the value of the CPUP_PRECISION macro.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #cpup [0,1000], current CPU usage, of which the precision is adjustable.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SysCpuUsage
|
||||
*/
|
||||
extern UINT32 LOS_SysCpuUsage(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Obtain the historical CPU usage.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the historical CPU usage.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails
|
||||
* to be obtained.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s will be
|
||||
* obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained. Other values
|
||||
* indicate that the CPU usage in the period that is less than 1s will be obtained.
|
||||
*
|
||||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #cpup [0,1000], historical CPU usage, of which the precision is adjustable.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_HistoryTaskCpuUsage
|
||||
*/
|
||||
extern UINT32 LOS_HistorySysCpuUsage(UINT16 mode);
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Obtain the CPU usage of a specified task.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the CPU usage of a task specified by a passed-in task ID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails
|
||||
* to be obtained.</li>
|
||||
* <li>The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise,
|
||||
* the CPU usage fails to be obtained.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param taskID [IN] UINT32. Task ID.
|
||||
*
|
||||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #OS_ERRNO_CPUP_TSK_ID_INVALID 0x02001e05: The target task ID is invalid.
|
||||
* @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED 0x02001e04: The target thread is not created.
|
||||
* @retval #cpup [0,1000], CPU usage of the specified task.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_HistoryTaskCpuUsage
|
||||
*/
|
||||
extern UINT32 LOS_TaskCpuUsage(UINT32 taskID);
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Obtain the historical CPU usage of a specified task.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the historical CPU usage of a task specified by a passed-in task ID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after the CPU usage is initialized. Otherwise,
|
||||
* the CPU usage fails to be obtained.</li>
|
||||
* <li>The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise,
|
||||
* the CPU usage fails to be obtained.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param taskID [IN] UINT32. Task ID.
|
||||
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s
|
||||
* will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.
|
||||
* Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
|
||||
*
|
||||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #OS_ERRNO_CPUP_TSK_ID_INVALID 0x02001e05: The target task ID is invalid.
|
||||
* @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED 0x02001e04: The target thread is not created.
|
||||
* @retval #cpup [0,1000], CPU usage of the specified task.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_HistorySysCpuUsage
|
||||
*/
|
||||
extern UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskID, UINT16 mode);
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Obtain the CPU usage of all tasks.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the CPU usage of all tasks according to maximum number of threads.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails
|
||||
* to be obtained.</li>
|
||||
* <li>The input parameter pointer must not be NULL, Otherwise, the CPU usage fails to be obtained.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param cpupInfo [OUT]Type. CPUP_INFO_S* Pointer to the task CPUP information structure to be obtained.
|
||||
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s
|
||||
* will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.
|
||||
* Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
|
||||
*
|
||||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #OS_ERRNO_CPUP_TASK_PTR_NULL 0x02001e01: The input parameter pointer is NULL.
|
||||
* @retval #LOS_OK 0x00000000: The CPU usage of all tasks is successfully obtained.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SysCpuUsage
|
||||
*/
|
||||
extern UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16 mode);
|
||||
|
||||
/**
|
||||
* @ingroup los_monitor
|
||||
* @brief Obtain CPU usage history of certain task.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain CPU usage history of certain task.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after the CPU usage is initialized. Otherwise, -1 will be returned.</li>
|
||||
* <li> Only in SYS_CPU_USAGE type, uwTaskID is invalid.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param type [IN] cpup type, SYS_CPU_USAGE and TASK_CPU_USAGE
|
||||
* @param mode [IN] mode,CPUP_IN_10S = usage in 10s,CPUP_IN_1S = usage in last 1s,
|
||||
* CPUP_LESS_THAN_1S = less than 1s, if the input mode is none of them, it will be as CPUP_LESS_THAN_1S.
|
||||
* @param taskID [IN] task ID, Only in SYS_CPU_USAGE type, taskID is invalid
|
||||
*
|
||||
* @retval #OS_ERROR -1:CPU usage info obtain failed.
|
||||
* @retval #LOS_OK 0:CPU usage info is successfully obtained.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_monitor.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_CpupUsageMonitor
|
||||
*/
|
||||
extern UINT32 LOS_CpupUsageMonitor(CPUP_TYPE_E type, CPUP_MODE_E mode, UINT32 taskID);
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
extern VOID OsCpupIrqStart(UINT32 intNum);
|
||||
extern VOID OsCpupIrqEnd(UINT32 intNum);
|
||||
extern OsIrqCpupCB *OsGetIrqCpupArrayBase(VOID);
|
||||
extern UINT32 LOS_GetAllIrqCpuUsage(UINT16 mode, CPUP_INFO_S *cpupInfo);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_CPUP_H */
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_ARPA_INET_H
|
||||
#define _ADAPT_ARPA_INET_H
|
||||
|
||||
#include <sys/features.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
in_addr_t inet_addr(const char *cp);
|
||||
in_addr_t inet_network(const char *cp);
|
||||
char *inet_ntoa(struct in_addr addr);
|
||||
int inet_pton(int af, const char *__restrict src, void *__restrict dst);
|
||||
const char *inet_ntop(int af, const void *__restrict src, char *__restrict dst, socklen_t size);
|
||||
|
||||
int inet_aton(const char *cp, struct in_addr *addr);
|
||||
struct in_addr inet_makeaddr(in_addr_t net, in_addr_t host);
|
||||
in_addr_t inet_lnaof(struct in_addr addr);
|
||||
in_addr_t inet_netof(struct in_addr addr);
|
||||
|
||||
uint32_t htonl(uint32_t hostvar);
|
||||
uint16_t htons(uint16_t hostvar);
|
||||
uint32_t ntohl(uint32_t netvar);
|
||||
uint16_t ntohs(uint16_t netvar);
|
||||
|
||||
#undef INET_ADDRSTRLEN
|
||||
#undef INET6_ADDRSTRLEN
|
||||
#define INET_ADDRSTRLEN 16
|
||||
#define INET6_ADDRSTRLEN 46
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_ARPA_INET_H */
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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 _ADAPT_BYTESWAP_H
|
||||
#define _ADAPT_BYTESWAP_H
|
||||
|
||||
#include <sys/features.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static __inline uint16_t __bswap_16(uint16_t __x)
|
||||
{
|
||||
return (__x << 8) | (__x >> 8);
|
||||
}
|
||||
|
||||
static __inline uint32_t __bswap_32(uint32_t __x)
|
||||
{
|
||||
return (__x >> 24) | ((__x >> 8) & 0xff00) | ((__x << 8) & 0xff0000) | (__x << 24);
|
||||
}
|
||||
|
||||
static __inline uint64_t __bswap_64(uint64_t __x)
|
||||
{
|
||||
return ((__bswap_32(__x) + 0ULL) << 32) | __bswap_32(__x >> 32);
|
||||
}
|
||||
|
||||
#define bswap_16(x) __bswap_16(x)
|
||||
#define bswap_32(x) __bswap_32(x)
|
||||
#define bswap_64(x) __bswap_64(x)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_DIRENT_H
|
||||
#define _ADAPT_DIRENT_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define d_fileno d_ino
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
#define DT_UNKNOWN 0
|
||||
#define DT_FIFO 1
|
||||
#define DT_CHR 2
|
||||
#define DT_DIR 4
|
||||
#define DT_BLK 6
|
||||
#define DT_REG 8
|
||||
#define DT_LNK 10
|
||||
#define DT_SOCK 12
|
||||
#define DT_WHT 14
|
||||
#define IFTODT(x) ((x) >> 12 & 017)
|
||||
#define DTTOIF(x) ((x) << 12)
|
||||
#endif
|
||||
|
||||
typedef struct __dirstream DIR;
|
||||
|
||||
struct dirent {
|
||||
ino_t d_ino;
|
||||
off_t d_off;
|
||||
unsigned short d_reclen;
|
||||
unsigned char d_type;
|
||||
char d_name[NAME_MAX];
|
||||
};
|
||||
|
||||
int closedir(DIR *dir);
|
||||
DIR *opendir(const char *dirName);
|
||||
struct dirent *readdir(DIR *dir);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_DIRENT_H */
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_ENDIAN_H
|
||||
#define _ADAPT_ENDIAN_H
|
||||
|
||||
#define LITTLE_ENDIAN _LITTLE_ENDIAN
|
||||
#define BIG_ENDIAN _BIG_ENDIAN
|
||||
#define PDP_ENDIAN _PDP_ENDIAN
|
||||
#define BYTE_ORDER _BYTE_ORDER
|
||||
|
||||
#include_next <machine/endian.h>
|
||||
|
||||
#endif /* !_ADAPT_ENDIAN_H */
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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 _ADAPT_IFADDRS_H
|
||||
#define _ADAPT_IFADDRS_H
|
||||
|
||||
#include <sys/features.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct ifaddrs {
|
||||
struct ifaddrs *ifa_next;
|
||||
char *ifa_name;
|
||||
unsigned ifa_flags;
|
||||
struct sockaddr *ifa_addr;
|
||||
struct sockaddr *ifa_netmask;
|
||||
union {
|
||||
struct sockaddr *ifu_broadaddr;
|
||||
struct sockaddr *ifu_dstaddr;
|
||||
} ifa_ifu;
|
||||
void *ifa_data;
|
||||
};
|
||||
#define ifa_broadaddr ifa_ifu.ifu_broadaddr
|
||||
#define ifa_dstaddr ifa_ifu.ifu_dstaddr
|
||||
|
||||
void freeifaddrs(struct ifaddrs *);
|
||||
int getifaddrs(struct ifaddrs **);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_LIMITS_H
|
||||
#define _ADAPT_LIMITS_H
|
||||
|
||||
#include_next <limits.h>
|
||||
#include <sys/syslimits.h>
|
||||
|
||||
#define SSIZE_MAX LONG_MAX
|
||||
|
||||
#undef PATH_MAX
|
||||
#undef NAME_MAX
|
||||
#define PATH_MAX 256
|
||||
#define NAME_MAX 256
|
||||
|
||||
#define PTHREAD_KEYS_MAX 128
|
||||
|
||||
#endif /* !_ADAPT_LIMITS_H */
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_MALLOC_H
|
||||
#define _ADAPT_MALLOC_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
void __wrap__free_r(struct _reent *reent, void *aptr);
|
||||
size_t __wrap__malloc_usable_size_r(struct _reent *reent, void *aptr);
|
||||
void *__wrap__malloc_r(struct _reent *reent, size_t nbytes);
|
||||
void *__wrap__memalign_r(struct _reent *reent, size_t align, size_t nbytes);
|
||||
void *__wrap__realloc_r(struct _reent *reent, void *aptr, size_t nbytes);
|
||||
|
||||
#include_next <malloc.h>
|
||||
|
||||
#endif /* !_ADAPT_MALLOC_H */
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_MQUEUE_H
|
||||
#define _ADAPT_MQUEUE_H
|
||||
|
||||
#include <sys/features.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int mqd_t;
|
||||
|
||||
struct mq_attr {
|
||||
long mq_flags, mq_maxmsg, mq_msgsize, mq_curmsgs, _unused[4];
|
||||
};
|
||||
|
||||
struct sigevent;
|
||||
|
||||
int mq_close(mqd_t personal);
|
||||
int mq_getattr(mqd_t personal, struct mq_attr *attr);
|
||||
mqd_t mq_open(const char *mqName, int openFlag, ...);
|
||||
ssize_t mq_receive(mqd_t personal, char *msg_ptr, size_t msg_len, unsigned *msg_prio);
|
||||
int mq_send(mqd_t personal, const char *msg_ptr, size_t msg_len, unsigned msg_prio);
|
||||
int mq_setattr(mqd_t personal, const struct mq_attr *__restrict new, struct mq_attr *__restrict old);
|
||||
ssize_t mq_timedreceive(mqd_t personal, char *__restrict msg, size_t msg_len, \
|
||||
unsigned *__restrict msg_prio, const struct timespec *__restrict absTimeout);
|
||||
int mq_timedsend(mqd_t personal, const char *msg, size_t msg_len, unsigned msg_prio, const struct timespec *absTimeout);
|
||||
int mq_unlink(const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_MQUEUE_H */
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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 _ADAPT_NET_ETHERNET_H
|
||||
#define _ADAPT_NET_ETHERNET_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ETHERTYPE_PUP 0x0200
|
||||
#define ETHERTYPE_SPRITE 0x0500
|
||||
#define ETHERTYPE_IP 0x0800
|
||||
#define ETHERTYPE_ARP 0x0806
|
||||
#define ETHERTYPE_REVARP 0x8035
|
||||
#define ETHERTYPE_AT 0x809B
|
||||
#define ETHERTYPE_AARP 0x80F3
|
||||
#define ETHERTYPE_VLAN 0x8100
|
||||
#define ETHERTYPE_IPX 0x8137
|
||||
#define ETHERTYPE_IPV6 0x86dd
|
||||
|
||||
#define ETHER_ADDR_LEN ETH_ALEN
|
||||
#define ETHER_TYPE_LEN ETH_TLEN
|
||||
#define ETHER_CRC_LEN 4
|
||||
#define ETHER_HDR_LEN ETH_HLEN
|
||||
#define ETHER_MIN_LEN (ETH_ZLEN + ETHER_CRC_LEN)
|
||||
#define ETHER_MAX_LEN (ETH_FRAME_LEN + ETHER_CRC_LEN)
|
||||
|
||||
#define ETHER_IS_VALID_LEN(foo) ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
|
||||
|
||||
#define ETHERTYPE_TRAIL 0x1000
|
||||
#define ETHERTYPE_NTRAILER 16
|
||||
|
||||
#define ETHERMTU ETH_DATA_LEN
|
||||
#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
|
||||
|
||||
struct ether_addr {
|
||||
uint8_t ether_addr_octet[ETH_ALEN];
|
||||
};
|
||||
|
||||
struct ether_header {
|
||||
uint8_t ether_dhost[ETH_ALEN];
|
||||
uint8_t ether_shost[ETH_ALEN];
|
||||
uint16_t ether_type;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_NET_ETHERNET_H */
|
||||
157
ohos/kernel/liteos_m/kal/libc/newlib/porting/include/net/if.h
Normal file
157
ohos/kernel/liteos_m/kal/libc/newlib/porting/include/net/if.h
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_IF_H
|
||||
#define _ADAPT_IF_H
|
||||
|
||||
#include <sys/features.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define IF_NAMESIZE 16
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#define IFF_UP 0x1
|
||||
#define IFF_BROADCAST 0x2
|
||||
#define IFF_DEBUG 0x4
|
||||
#define IFF_LOOPBACK 0x8
|
||||
#define IFF_POINTOPOINT 0x10
|
||||
#define IFF_NOTRAILERS 0x20
|
||||
#define IFF_RUNNING 0x40
|
||||
#define IFF_NOARP 0x80
|
||||
#define IFF_PROMISC 0x100
|
||||
#define IFF_ALLMULTI 0x200
|
||||
#define IFF_MASTER 0x400
|
||||
#define IFF_SLAVE 0x800
|
||||
#define IFF_MULTICAST 0x1000
|
||||
#define IFF_PORTSEL 0x2000
|
||||
#define IFF_AUTOMEDIA 0x4000
|
||||
#define IFF_DYNAMIC 0x8000
|
||||
#define IFF_LOWER_UP 0x10000
|
||||
#define IFF_DORMANT 0x20000
|
||||
#define IFF_ECHO 0x40000
|
||||
#define IFF_VOLATILE (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_BROADCAST | \
|
||||
IFF_ECHO | IFF_MASTER | IFF_SLAVE | IFF_RUNNING| \
|
||||
IFF_LOWER_UP | IFF_DORMANT)
|
||||
|
||||
struct ifaddr {
|
||||
struct sockaddr ifa_addr;
|
||||
union {
|
||||
struct sockaddr ifu_broadaddr;
|
||||
struct sockaddr ifu_dstaddr;
|
||||
} ifa_ifu;
|
||||
struct iface *ifa_ifp;
|
||||
struct ifaddr *ifa_next;
|
||||
};
|
||||
|
||||
#define ifa_broadaddr ifa_ifu.ifu_broadaddr
|
||||
#define ifa_dstaddr ifa_ifu.ifu_dstaddr
|
||||
|
||||
struct ifmap {
|
||||
unsigned long int mem_start;
|
||||
unsigned long int mem_end;
|
||||
unsigned short int base_addr;
|
||||
unsigned char irq;
|
||||
unsigned char dma;
|
||||
unsigned char port;
|
||||
};
|
||||
|
||||
#define IFHWADDRLEN 6
|
||||
#define IFNAMSIZ IF_NAMESIZE
|
||||
|
||||
struct ifreq {
|
||||
union {
|
||||
char ifrn_name[IFNAMSIZ];
|
||||
} ifr_ifrn;
|
||||
union {
|
||||
struct sockaddr ifru_addr;
|
||||
struct sockaddr ifru_dstaddr;
|
||||
struct sockaddr ifru_broadaddr;
|
||||
struct sockaddr ifru_netmask;
|
||||
struct sockaddr ifru_hwaddr;
|
||||
short int ifru_flags;
|
||||
int ifru_ivalue;
|
||||
int ifru_mtu;
|
||||
struct ifmap ifru_map;
|
||||
char ifru_slave[IFNAMSIZ];
|
||||
char ifru_newname[IFNAMSIZ];
|
||||
char *ifru_data;
|
||||
} ifr_ifru;
|
||||
};
|
||||
|
||||
#define ifr_name ifr_ifrn.ifrn_name
|
||||
#define ifr_hwaddr ifr_ifru.ifru_hwaddr
|
||||
#define ifr_addr ifr_ifru.ifru_addr
|
||||
#define ifr_dstaddr ifr_ifru.ifru_dstaddr
|
||||
#define ifr_broadaddr ifr_ifru.ifru_broadaddr
|
||||
#define ifr_netmask ifr_ifru.ifru_netmask
|
||||
#define ifr_flags ifr_ifru.ifru_flags
|
||||
#define ifr_metric ifr_ifru.ifru_ivalue
|
||||
#define ifr_mtu ifr_ifru.ifru_mtu
|
||||
#define ifr_map ifr_ifru.ifru_map
|
||||
#define ifr_slave ifr_ifru.ifru_slave
|
||||
#define ifr_data ifr_ifru.ifru_data
|
||||
#define ifr_ifindex ifr_ifru.ifru_ivalue
|
||||
#define ifr_bandwidth ifr_ifru.ifru_ivalue
|
||||
#define ifr_qlen ifr_ifru.ifru_ivalue
|
||||
#define ifr_newname ifr_ifru.ifru_newname
|
||||
|
||||
struct ifconf {
|
||||
int ifc_len;
|
||||
union {
|
||||
char *ifcu_buf;
|
||||
struct ifreq *ifcu_req;
|
||||
} ifc_ifcu;
|
||||
};
|
||||
|
||||
#define ifc_buf ifc_ifcu.ifcu_buf
|
||||
#define ifc_req ifc_ifcu.ifcu_req
|
||||
#endif
|
||||
|
||||
struct if_nameindex {
|
||||
unsigned int if_index;
|
||||
char *if_name;
|
||||
};
|
||||
|
||||
unsigned int if_nametoindex(const char *name);
|
||||
char *if_indextoname(unsigned int index, char *name);
|
||||
struct if_nameindex *if_nameindex(void);
|
||||
void if_freenameindex(struct if_nameindex *ifNameIndex);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_IF_H */
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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 _ADAPT_NET_IF_ARP_H
|
||||
#define _ADAPT_NET_IF_ARP_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MAX_ADDR_LEN 7
|
||||
|
||||
#define ARPOP_REQUEST 1
|
||||
#define ARPOP_REPLY 2
|
||||
#define ARPOP_RREQUEST 3
|
||||
#define ARPOP_RREPLY 4
|
||||
#define ARPOP_InREQUEST 8
|
||||
#define ARPOP_InREPLY 9
|
||||
#define ARPOP_NAK 10
|
||||
|
||||
#define ATF_INUSE 0x01
|
||||
#define ATF_COM 0x02
|
||||
#define ATF_PERM 0x04
|
||||
#define ATF_PUBL 0x08
|
||||
#define ATF_USETRAILERS 0x10
|
||||
|
||||
#define ARPD_UPDATE 0x01
|
||||
#define ARPD_LOOKUP 0x02
|
||||
#define ARPD_FLUSH 0x03
|
||||
|
||||
struct arphdr {
|
||||
uint16_t ar_hrd;
|
||||
uint16_t ar_pro;
|
||||
uint8_t ar_hln;
|
||||
uint8_t ar_pln;
|
||||
uint16_t ar_op;
|
||||
};
|
||||
|
||||
#define ARP_DEV_LEN 16
|
||||
struct arpreq {
|
||||
struct sockaddr arp_pa;
|
||||
struct sockaddr arp_ha;
|
||||
int arp_flags;
|
||||
struct sockaddr arp_netmask;
|
||||
char arp_dev[ARP_DEV_LEN];
|
||||
};
|
||||
|
||||
struct arpreq_old {
|
||||
struct sockaddr arp_pa;
|
||||
struct sockaddr arp_ha;
|
||||
int arp_flags;
|
||||
struct sockaddr arp_netmask;
|
||||
};
|
||||
|
||||
struct arpd_request {
|
||||
unsigned short req;
|
||||
uint32_t ip;
|
||||
unsigned long dev;
|
||||
unsigned long stamp;
|
||||
unsigned long updated;
|
||||
unsigned char ha[MAX_ADDR_LEN];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_NET_IF_ARP_H */
|
||||
190
ohos/kernel/liteos_m/kal/libc/newlib/porting/include/netdb.h
Normal file
190
ohos/kernel/liteos_m/kal/libc/newlib/porting/include/netdb.h
Normal file
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 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 _ADAPT_NETDB_H
|
||||
#define _ADAPT_NETDB_H
|
||||
|
||||
#include <sys/features.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define AI_PASSIVE 0x01
|
||||
#define AI_CANONNAME 0x02
|
||||
#define AI_NUMERICHOST 0x04
|
||||
#define AI_V4MAPPED 0x08
|
||||
#define AI_ALL 0x10
|
||||
#define AI_ADDRCONFIG 0x20
|
||||
#define AI_NUMERICSERV 0x400
|
||||
|
||||
#define NI_NUMERICHOST 0x01
|
||||
#define NI_NUMERICSERV 0x02
|
||||
#define NI_NOFQDN 0x04
|
||||
#define NI_NAMEREQD 0x08
|
||||
#define NI_DGRAM 0x10
|
||||
#define NI_NUMERICSCOPE 0x100
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
#define NI_MAXHOST 255
|
||||
#define NI_MAXSERV 32
|
||||
#endif
|
||||
|
||||
#define EAI_BADFLAGS -1
|
||||
#define EAI_NONAME -2
|
||||
#define EAI_AGAIN -3
|
||||
#define EAI_FAIL -4
|
||||
#define EAI_FAMILY -6
|
||||
#define EAI_SOCKTYPE -7
|
||||
#define EAI_SERVICE -8
|
||||
#define EAI_MEMORY -10
|
||||
#define EAI_SYSTEM -11
|
||||
#define EAI_OVERFLOW -12
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
#define EAI_NODATA -5
|
||||
#define EAI_ADDRFAMILY -9
|
||||
#define EAI_INPROGRESS -100
|
||||
#define EAI_CANCELED -101
|
||||
#define EAI_NOTCANCELED -102
|
||||
#define EAI_ALLDONE -103
|
||||
#define EAI_INTR -104
|
||||
#define EAI_IDN_ENCODE -105
|
||||
#endif
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
#define HOST_NOT_FOUND 1
|
||||
#define TRY_AGAIN 2
|
||||
#define NO_RECOVERY 3
|
||||
#define NO_DATA 4
|
||||
#define NO_ADDRESS NO_DATA
|
||||
#endif
|
||||
|
||||
struct addrinfo {
|
||||
int ai_flags;
|
||||
int ai_family;
|
||||
int ai_socktype;
|
||||
int ai_protocol;
|
||||
socklen_t ai_addrlen;
|
||||
struct sockaddr *ai_addr;
|
||||
char *ai_canonname;
|
||||
struct addrinfo *ai_next;
|
||||
};
|
||||
|
||||
int getaddrinfo(const char *__restrict nodename, const char *__restrict servname, \
|
||||
const struct addrinfo *__restrict hints, struct addrinfo **__restrict res);
|
||||
void freeaddrinfo(struct addrinfo *res);
|
||||
int getnameinfo(const struct sockaddr * __restrict sa, socklen_t salen, char * __restrict host, \
|
||||
socklen_t hostlen, char * __restrict serv, socklen_t servlen, int flags);
|
||||
const char *gai_strerror(int errcode);
|
||||
|
||||
struct netent {
|
||||
char *n_name;
|
||||
char **n_aliases;
|
||||
int n_addrtype;
|
||||
uint32_t n_net;
|
||||
};
|
||||
|
||||
struct hostent {
|
||||
char *h_name;
|
||||
char **h_aliases;
|
||||
int h_addrtype;
|
||||
int h_length;
|
||||
char **h_addr_list;
|
||||
};
|
||||
#define h_addr h_addr_list[0]
|
||||
|
||||
struct servent {
|
||||
char *s_name;
|
||||
char **s_aliases;
|
||||
int s_port;
|
||||
char *s_proto;
|
||||
};
|
||||
|
||||
struct protoent {
|
||||
char *p_name;
|
||||
char **p_aliases;
|
||||
int p_proto;
|
||||
};
|
||||
|
||||
void sethostent(int stay_open);
|
||||
void endhostent(void);
|
||||
struct hostent *gethostent(void);
|
||||
|
||||
void setnetent(int stay_open);
|
||||
void endnetent(void);
|
||||
struct netent *getnetent(void);
|
||||
struct netent *getnetbyaddr(uint32_t net, int type);
|
||||
struct netent *getnetbyname(const char *name);
|
||||
|
||||
void setservent(int stay_open);
|
||||
void endservent(void);
|
||||
struct servent *getservent(void);
|
||||
struct servent *getservbyname(const char *name, const char *proto);
|
||||
struct servent *getservbyport(int port, const char *proto);
|
||||
|
||||
void setprotoent(int stay_open);
|
||||
void endprotoent(void);
|
||||
struct protoent *getprotoent(void);
|
||||
struct protoent *getprotobyname(const char *name);
|
||||
struct protoent *getprotobynumber(int proto);
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
|
||||
|| (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
|
||||
|| (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
|
||||
struct hostent *gethostbyname(const char *name);
|
||||
struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type);
|
||||
int *__h_errno_location(void);
|
||||
#define h_errno (*__h_errno_location())
|
||||
#endif
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
void herror(const char *str);
|
||||
const char *hstrerror(int errnum);
|
||||
int gethostbyname_r(const char * name, struct hostent * ret, char * buf, size_t buflen, \
|
||||
struct hostent ** result, int * h_errnop);
|
||||
int gethostbyname2_r(const char * __restrict name, int af, struct hostent * __restrict result_buf, \
|
||||
char * __restrict buf, size_t buflen, struct hostent ** __restrict result, \
|
||||
int * __restrict h_errnop);
|
||||
struct hostent *gethostbyname2(const char *name, int af);
|
||||
int gethostbyaddr_r(const void * __restrict addr, __socklen_t len, int type, struct hostent * __restrict result_buf, \
|
||||
char * __restrict buf, size_t buflen, struct hostent ** __restrict result, \
|
||||
int * __restrict h_errnop);
|
||||
int getservbyport_r(int port, const char * __restrict proto, struct servent * __restrict result_buf, \
|
||||
char * __restrict buf, size_t buflen, struct servent ** __restrict result);
|
||||
int getservbyname_r(const char *name, const char *proto, struct servent *result_buf, char *buf, size_t buflen, \
|
||||
struct servent **result);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_NETDB_H */
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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 _ADAPT_NETINET_IF_ETHER_H
|
||||
#define _ADAPT_NETINET_IF_ETHER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define ETH_ALEN 6
|
||||
#define ETH_TLEN 2
|
||||
#define ETH_HLEN 14
|
||||
#define ETH_ZLEN 60
|
||||
#define ETH_DATA_LEN 1500
|
||||
#define ETH_FRAME_LEN 1514
|
||||
#define ETH_FCS_LEN 4
|
||||
#define ETH_MIN_MTU 68
|
||||
#define ETH_MAX_MTU 0xFFFFU
|
||||
|
||||
struct ethhdr {
|
||||
uint8_t h_dest[ETH_ALEN];
|
||||
uint8_t h_source[ETH_ALEN];
|
||||
uint16_t h_proto;
|
||||
};
|
||||
|
||||
#include <net/ethernet.h>
|
||||
#include <net/if_arp.h>
|
||||
|
||||
struct ether_arp {
|
||||
struct arphdr ea_hdr;
|
||||
uint8_t arp_sha[ETH_ALEN];
|
||||
uint8_t arp_spa[4];
|
||||
uint8_t arp_tha[ETH_ALEN];
|
||||
uint8_t arp_tpa[4];
|
||||
};
|
||||
|
||||
#define arp_hrd ea_hdr.ar_hrd
|
||||
#define arp_pro ea_hdr.ar_pro
|
||||
#define arp_hln ea_hdr.ar_hln
|
||||
#define arp_pln ea_hdr.ar_pln
|
||||
#define arp_op ea_hdr.ar_op
|
||||
|
||||
#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
|
||||
do { \
|
||||
(enaddr)[0] = 0x01; \
|
||||
(enaddr)[1] = 0x00; \
|
||||
(enaddr)[2] = 0x5e; \
|
||||
(enaddr)[3] = ((uint8_t *)(ipaddr))[1] & 0x7f; \
|
||||
(enaddr)[4] = ((uint8_t *)(ipaddr))[2]; \
|
||||
(enaddr)[5] = ((uint8_t *)(ipaddr))[3]; \
|
||||
} while (0)
|
||||
|
||||
#endif /* !_ADAPT_NETINET_IF_ETHER_H */
|
||||
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_NETINET_IN_H
|
||||
#define _ADAPT_NETINET_IN_H
|
||||
|
||||
#include <sys/features.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define INADDR_ANY ((in_addr_t) 0x00000000)
|
||||
#define INADDR_BROADCAST ((in_addr_t) 0xffffffff)
|
||||
#define INADDR_NONE ((in_addr_t) 0xffffffff)
|
||||
#define INADDR_LOOPBACK ((in_addr_t) 0x7f000001)
|
||||
|
||||
#define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000)
|
||||
#define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001)
|
||||
#define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002)
|
||||
#define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a)
|
||||
#define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff)
|
||||
|
||||
#undef INET_ADDRSTRLEN
|
||||
#undef INET6_ADDRSTRLEN
|
||||
#define INET_ADDRSTRLEN 16
|
||||
#define INET6_ADDRSTRLEN 46
|
||||
|
||||
#define IPPORT_RESERVED 1024
|
||||
|
||||
#define IPPROTO_IP 0
|
||||
#define IPPROTO_HOPOPTS 0
|
||||
#define IPPROTO_ICMP 1
|
||||
#define IPPROTO_IGMP 2
|
||||
#define IPPROTO_IPIP 4
|
||||
#define IPPROTO_TCP 6
|
||||
#define IPPROTO_EGP 8
|
||||
#define IPPROTO_PUP 12
|
||||
#define IPPROTO_UDP 17
|
||||
#define IPPROTO_IDP 22
|
||||
#define IPPROTO_TP 29
|
||||
#define IPPROTO_DCCP 33
|
||||
#define IPPROTO_IPV6 41
|
||||
#define IPPROTO_ROUTING 43
|
||||
#define IPPROTO_FRAGMENT 44
|
||||
#define IPPROTO_RSVP 46
|
||||
#define IPPROTO_GRE 47
|
||||
#define IPPROTO_ESP 50
|
||||
#define IPPROTO_AH 51
|
||||
#define IPPROTO_ICMPV6 58
|
||||
#define IPPROTO_NONE 59
|
||||
#define IPPROTO_DSTOPTS 60
|
||||
#define IPPROTO_MTP 92
|
||||
#define IPPROTO_BEETPH 94
|
||||
#define IPPROTO_ENCAP 98
|
||||
#define IPPROTO_PIM 103
|
||||
#define IPPROTO_COMP 108
|
||||
#define IPPROTO_SCTP 132
|
||||
#define IPPROTO_MH 135
|
||||
#define IPPROTO_UDPLITE 136
|
||||
#define IPPROTO_MPLS 137
|
||||
#define IPPROTO_RAW 255
|
||||
#define IPPROTO_MAX 256
|
||||
|
||||
#define __ARE_4_EQUAL(a,b) \
|
||||
(!( (0[a] - 0[b]) | (1[a] - 1[b]) | (2[a] - 2[b]) | (3[a] - 3[b]) ))
|
||||
|
||||
#define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0)
|
||||
#define IN_CLASSA_NET 0xff000000
|
||||
#define IN_CLASSA_NSHIFT 24
|
||||
#define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
|
||||
#define IN_CLASSA_MAX 128
|
||||
#define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
|
||||
#define IN_CLASSB_NET 0xffff0000
|
||||
#define IN_CLASSB_NSHIFT 16
|
||||
#define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
|
||||
#define IN_CLASSB_MAX 65536
|
||||
#define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
|
||||
#define IN_CLASSC_NET 0xffffff00
|
||||
#define IN_CLASSC_NSHIFT 8
|
||||
#define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
|
||||
#define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
|
||||
#define IN_MULTICAST(a) IN_CLASSD(a)
|
||||
#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
|
||||
#define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)
|
||||
|
||||
#define IN_LOOPBACKNET 127
|
||||
|
||||
#define IP_TOS 1
|
||||
#define IP_TTL 2
|
||||
#define IP_HDRINCL 3
|
||||
#define IP_OPTIONS 4
|
||||
#define IP_ROUTER_ALERT 5
|
||||
#define IP_RECVOPTS 6
|
||||
#define IP_RETOPTS 7
|
||||
#define IP_PKTINFO 8
|
||||
#define IP_PKTOPTIONS 9
|
||||
#define IP_PMTUDISC 10
|
||||
#define IP_MTU_DISCOVER 10
|
||||
#define IP_RECVERR 11
|
||||
#define IP_RECVTTL 12
|
||||
#define IP_RECVTOS 13
|
||||
#define IP_MTU 14
|
||||
#define IP_FREEBIND 15
|
||||
#define IP_IPSEC_POLICY 16
|
||||
#define IP_XFRM_POLICY 17
|
||||
#define IP_PASSSEC 18
|
||||
#define IP_TRANSPARENT 19
|
||||
#define IP_ORIGDSTADDR 20
|
||||
#define IP_RECVORIGDSTADDR IP_ORIGDSTADDR
|
||||
#define IP_MINTTL 21
|
||||
#define IP_NODEFRAG 22
|
||||
#define IP_CHECKSUM 23
|
||||
#define IP_BIND_ADDRESS_NO_PORT 24
|
||||
#define IP_RECVFRAGSIZE 25
|
||||
#define IP_MULTICAST_IF 32
|
||||
#define IP_MULTICAST_TTL 33
|
||||
#define IP_MULTICAST_LOOP 34
|
||||
#define IP_ADD_MEMBERSHIP 35
|
||||
#define IP_DROP_MEMBERSHIP 36
|
||||
#define IP_UNBLOCK_SOURCE 37
|
||||
#define IP_BLOCK_SOURCE 38
|
||||
#define IP_ADD_SOURCE_MEMBERSHIP 39
|
||||
#define IP_DROP_SOURCE_MEMBERSHIP 40
|
||||
#define IP_MSFILTER 41
|
||||
#define IP_MULTICAST_ALL 49
|
||||
#define IP_UNICAST_IF 50
|
||||
|
||||
#define IP_RECVRETOPTS IP_RETOPTS
|
||||
|
||||
#define IP_PMTUDISC_DONT 0
|
||||
#define IP_PMTUDISC_WANT 1
|
||||
#define IP_PMTUDISC_DO 2
|
||||
#define IP_PMTUDISC_PROBE 3
|
||||
#define IP_PMTUDISC_INTERFACE 4
|
||||
#define IP_PMTUDISC_OMIT 5
|
||||
|
||||
#define IP_DEFAULT_MULTICAST_TTL 1
|
||||
#define IP_DEFAULT_MULTICAST_LOOP 1
|
||||
#define IP_MAX_MEMBERSHIPS 20
|
||||
|
||||
typedef uint16_t in_port_t;
|
||||
typedef uint32_t in_addr_t;
|
||||
|
||||
struct in_addr {
|
||||
in_addr_t s_addr;
|
||||
};
|
||||
|
||||
struct sockaddr_in {
|
||||
sa_family_t sin_family;
|
||||
in_port_t sin_port;
|
||||
struct in_addr sin_addr;
|
||||
uint8_t sin_zero[8];
|
||||
};
|
||||
|
||||
struct ip_opts {
|
||||
struct in_addr ip_dst;
|
||||
char ip_opts[40];
|
||||
};
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
struct ip_mreq {
|
||||
struct in_addr imr_multiaddr;
|
||||
struct in_addr imr_interface;
|
||||
};
|
||||
#endif
|
||||
|
||||
#define IPV6_ADDRFORM 1
|
||||
#define IPV6_CHECKSUM 7
|
||||
#define IPV6_NEXTHOP 9
|
||||
#define IPV6_AUTHHDR 10
|
||||
#define IPV6_UNICAST_HOPS 16
|
||||
#define IPV6_MULTICAST_IF 17
|
||||
#define IPV6_MULTICAST_HOPS 18
|
||||
#define IPV6_MULTICAST_LOOP 19
|
||||
#define IPV6_JOIN_GROUP 20
|
||||
#define IPV6_LEAVE_GROUP 21
|
||||
#define IPV6_V6ONLY 26
|
||||
#define IPV6_JOIN_ANYCAST 27
|
||||
#define IPV6_LEAVE_ANYCAST 28
|
||||
#define IPV6_IPSEC_POLICY 34
|
||||
|
||||
#define IN6ADDR_ANY_INIT {{{ 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00 }}}
|
||||
#define IN6ADDR_LOOPBACK_INIT {{{ 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x01 }}}
|
||||
|
||||
struct in6_addr {
|
||||
union {
|
||||
uint8_t __s6_addr[16];
|
||||
uint16_t __s6_addr16[8];
|
||||
uint32_t __s6_addr32[4];
|
||||
} __in6_union;
|
||||
};
|
||||
#define s6_addr __in6_union.__s6_addr
|
||||
#define s6_addr16 __in6_union.__s6_addr16
|
||||
#define s6_addr32 __in6_union.__s6_addr32
|
||||
|
||||
struct sockaddr_in6 {
|
||||
sa_family_t sin6_family;
|
||||
in_port_t sin6_port;
|
||||
uint32_t sin6_flowinfo;
|
||||
struct in6_addr sin6_addr;
|
||||
uint32_t sin6_scope_id;
|
||||
};
|
||||
|
||||
struct ipv6_mreq {
|
||||
struct in6_addr ipv6mr_multiaddr;
|
||||
unsigned ipv6mr_interface;
|
||||
};
|
||||
|
||||
uint32_t htonl(uint32_t);
|
||||
uint16_t htons(uint16_t);
|
||||
uint32_t ntohl(uint32_t);
|
||||
uint16_t ntohs(uint16_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_NETINET_IN_H */
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_NETINET_IP_H
|
||||
#define _ADAPT_NETINET_IP_H
|
||||
|
||||
#include <endian.h>
|
||||
#include <stdint.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct timestamp {
|
||||
uint8_t len;
|
||||
uint8_t ptr;
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
unsigned int flags:4;
|
||||
unsigned int overflow:4;
|
||||
#else
|
||||
unsigned int overflow:4;
|
||||
unsigned int flags:4;
|
||||
#endif
|
||||
uint32_t data[9];
|
||||
};
|
||||
|
||||
struct iphdr {
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
unsigned int ihl:4;
|
||||
unsigned int version:4;
|
||||
#else
|
||||
unsigned int version:4;
|
||||
unsigned int ihl:4;
|
||||
#endif
|
||||
uint8_t tos;
|
||||
uint16_t tot_len;
|
||||
uint16_t id;
|
||||
uint16_t frag_off;
|
||||
uint8_t ttl;
|
||||
uint8_t protocol;
|
||||
uint16_t check;
|
||||
uint32_t saddr;
|
||||
uint32_t daddr;
|
||||
};
|
||||
|
||||
struct ip {
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
unsigned int ip_hl:4;
|
||||
unsigned int ip_v:4;
|
||||
#else
|
||||
unsigned int ip_v:4;
|
||||
unsigned int ip_hl:4;
|
||||
#endif
|
||||
uint8_t ip_tos;
|
||||
uint16_t ip_len;
|
||||
uint16_t ip_id;
|
||||
uint16_t ip_off;
|
||||
uint8_t ip_ttl;
|
||||
uint8_t ip_p;
|
||||
uint16_t ip_sum;
|
||||
struct in_addr ip_src, ip_dst;
|
||||
};
|
||||
|
||||
#define IP_RF 0x8000
|
||||
#define IP_DF 0x4000
|
||||
#define IP_MF 0x2000
|
||||
#define IP_OFFMASK 0x1fff
|
||||
|
||||
struct ip_timestamp {
|
||||
uint8_t ipt_code;
|
||||
uint8_t ipt_len;
|
||||
uint8_t ipt_ptr;
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
unsigned int ipt_flg:4;
|
||||
unsigned int ipt_oflw:4;
|
||||
#else
|
||||
unsigned int ipt_oflw:4;
|
||||
unsigned int ipt_flg:4;
|
||||
#endif
|
||||
uint32_t data[9];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_NETINET_IP_H */
|
||||
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_NETINET_TCP_H
|
||||
#define _ADAPT_NETINET_TCP_H
|
||||
|
||||
#include <sys/features.h>
|
||||
|
||||
#define TCP_NODELAY 1
|
||||
#define TCP_MAXSEG 2
|
||||
#define TCP_CORK 3
|
||||
#define TCP_KEEPIDLE 4
|
||||
#define TCP_KEEPINTVL 5
|
||||
#define TCP_KEEPCNT 6
|
||||
#define TCP_SYNCNT 7
|
||||
|
||||
#define TCP_ESTABLISHED 1
|
||||
#define TCP_SYN_SENT 2
|
||||
#define TCP_SYN_RECV 3
|
||||
#define TCP_FIN_WAIT1 4
|
||||
#define TCP_FIN_WAIT2 5
|
||||
#define TCP_TIME_WAIT 6
|
||||
#define TCP_CLOSE 7
|
||||
#define TCP_CLOSE_WAIT 8
|
||||
#define TCP_LAST_ACK 9
|
||||
#define TCP_LISTEN 10
|
||||
#define TCP_CLOSING 11
|
||||
|
||||
#ifdef _GNU_SOURCE
|
||||
#define TCPI_OPT_TIMESTAMPS 1
|
||||
#define TCPI_OPT_SACK 2
|
||||
#define TCPI_OPT_WSCALE 4
|
||||
#define TCPI_OPT_ECN 8
|
||||
|
||||
#define TCP_CA_Open 0
|
||||
#define TCP_CA_Disorder 1
|
||||
#define TCP_CA_CWR 2
|
||||
#define TCP_CA_Recovery 3
|
||||
#define TCP_CA_Loss 4
|
||||
#endif
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
#define TCPOPT_EOL 0
|
||||
#define TCPOPT_NOP 1
|
||||
#define TCPOPT_MAXSEG 2
|
||||
#define TCPOPT_WINDOW 3
|
||||
#define TCPOPT_SACK_PERMITTED 4
|
||||
#define TCPOPT_SACK 5
|
||||
#define TCPOPT_TIMESTAMP 8
|
||||
#define TCPOLEN_SACK_PERMITTED 2
|
||||
#define TCPOLEN_WINDOW 3
|
||||
#define TCPOLEN_MAXSEG 4
|
||||
#define TCPOLEN_TIMESTAMP 10
|
||||
|
||||
#define SOL_TCP 6
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define TH_FIN 0x01
|
||||
#define TH_SYN 0x02
|
||||
#define TH_RST 0x04
|
||||
#define TH_PUSH 0x08
|
||||
#define TH_ACK 0x10
|
||||
#define TH_URG 0x20
|
||||
|
||||
typedef uint32_t tcp_seq;
|
||||
|
||||
struct tcphdr {
|
||||
#ifdef _GNU_SOURCE
|
||||
#ifdef __GNUC__
|
||||
__extension__
|
||||
#endif
|
||||
union { struct {
|
||||
|
||||
uint16_t source;
|
||||
uint16_t dest;
|
||||
uint32_t seq;
|
||||
uint32_t ack_seq;
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
uint16_t res1:4;
|
||||
uint16_t doff:4;
|
||||
uint16_t fin:1;
|
||||
uint16_t syn:1;
|
||||
uint16_t rst:1;
|
||||
uint16_t psh:1;
|
||||
uint16_t ack:1;
|
||||
uint16_t urg:1;
|
||||
uint16_t res2:2;
|
||||
#else
|
||||
uint16_t doff:4;
|
||||
uint16_t res1:4;
|
||||
uint16_t res2:2;
|
||||
uint16_t urg:1;
|
||||
uint16_t ack:1;
|
||||
uint16_t psh:1;
|
||||
uint16_t rst:1;
|
||||
uint16_t syn:1;
|
||||
uint16_t fin:1;
|
||||
#endif
|
||||
uint16_t window;
|
||||
uint16_t check;
|
||||
uint16_t urg_ptr;
|
||||
|
||||
}; struct {
|
||||
#endif
|
||||
|
||||
uint16_t th_sport;
|
||||
uint16_t th_dport;
|
||||
uint32_t th_seq;
|
||||
uint32_t th_ack;
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
uint8_t th_x2:4;
|
||||
uint8_t th_off:4;
|
||||
#else
|
||||
uint8_t th_off:4;
|
||||
uint8_t th_x2:4;
|
||||
#endif
|
||||
uint8_t th_flags;
|
||||
uint16_t th_win;
|
||||
uint16_t th_sum;
|
||||
uint16_t th_urp;
|
||||
|
||||
#ifdef _GNU_SOURCE
|
||||
}; };
|
||||
#endif
|
||||
};
|
||||
#endif /* _GNU_SOURCE || _BSD_SOURCE */
|
||||
|
||||
#ifdef _GNU_SOURCE
|
||||
#define TCP_MD5SIG_MAXKEYLEN 80
|
||||
#define TCP_MD5SIG_FLAG_PREFIX 1
|
||||
|
||||
#define TCP_REPAIR_ON 1
|
||||
#define TCP_REPAIR_OFF 0
|
||||
#define TCP_REPAIR_OFF_NO_WP -1
|
||||
|
||||
struct tcp_info {
|
||||
uint8_t tcpi_state;
|
||||
uint8_t tcpi_ca_state;
|
||||
uint8_t tcpi_retransmits;
|
||||
uint8_t tcpi_probes;
|
||||
uint8_t tcpi_backoff;
|
||||
uint8_t tcpi_options;
|
||||
uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
|
||||
uint8_t tcpi_delivery_rate_app_limited : 1;
|
||||
uint32_t tcpi_rto;
|
||||
uint32_t tcpi_ato;
|
||||
uint32_t tcpi_snd_mss;
|
||||
uint32_t tcpi_rcv_mss;
|
||||
uint32_t tcpi_unacked;
|
||||
uint32_t tcpi_sacked;
|
||||
uint32_t tcpi_lost;
|
||||
uint32_t tcpi_retrans;
|
||||
uint32_t tcpi_fackets;
|
||||
uint32_t tcpi_last_data_sent;
|
||||
uint32_t tcpi_last_ack_sent;
|
||||
uint32_t tcpi_last_data_recv;
|
||||
uint32_t tcpi_last_ack_recv;
|
||||
uint32_t tcpi_pmtu;
|
||||
uint32_t tcpi_rcv_ssthresh;
|
||||
uint32_t tcpi_rtt;
|
||||
uint32_t tcpi_rttvar;
|
||||
uint32_t tcpi_snd_ssthresh;
|
||||
uint32_t tcpi_snd_cwnd;
|
||||
uint32_t tcpi_advmss;
|
||||
uint32_t tcpi_reordering;
|
||||
uint32_t tcpi_rcv_rtt;
|
||||
uint32_t tcpi_rcv_space;
|
||||
uint32_t tcpi_total_retrans;
|
||||
uint64_t tcpi_pacing_rate;
|
||||
uint64_t tcpi_max_pacing_rate;
|
||||
uint64_t tcpi_bytes_acked;
|
||||
uint64_t tcpi_bytes_received;
|
||||
uint32_t tcpi_segs_out;
|
||||
uint32_t tcpi_segs_in;
|
||||
uint32_t tcpi_notsent_bytes;
|
||||
uint32_t tcpi_min_rtt;
|
||||
uint32_t tcpi_data_segs_in;
|
||||
uint32_t tcpi_data_segs_out;
|
||||
uint64_t tcpi_delivery_rate;
|
||||
uint64_t tcpi_busy_time;
|
||||
uint64_t tcpi_rwnd_limited;
|
||||
uint64_t tcpi_sndbuf_limited;
|
||||
uint32_t tcpi_delivered;
|
||||
uint32_t tcpi_delivered_ce;
|
||||
uint64_t tcpi_bytes_sent;
|
||||
uint64_t tcpi_bytes_retrans;
|
||||
uint32_t tcpi_dsack_dups;
|
||||
uint32_t tcpi_reord_seen;
|
||||
uint32_t tcpi_rcv_ooopack;
|
||||
uint32_t tcpi_snd_wnd;
|
||||
};
|
||||
|
||||
struct tcp_md5sig {
|
||||
struct sockaddr_storage tcpm_addr;
|
||||
uint8_t tcpm_flags;
|
||||
uint8_t tcpm_prefixlen;
|
||||
uint16_t tcpm_keylen;
|
||||
uint32_t __tcpm_pad;
|
||||
uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
|
||||
};
|
||||
|
||||
struct tcp_diag_md5sig {
|
||||
uint8_t tcpm_family;
|
||||
uint8_t tcpm_prefixlen;
|
||||
uint16_t tcpm_keylen;
|
||||
uint32_t tcpm_addr[4];
|
||||
uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
|
||||
};
|
||||
|
||||
struct tcp_repair_window {
|
||||
uint32_t snd_wl1;
|
||||
uint32_t snd_wnd;
|
||||
uint32_t max_window;
|
||||
uint32_t rcv_wnd;
|
||||
uint32_t rcv_wup;
|
||||
};
|
||||
|
||||
struct tcp_zerocopy_receive {
|
||||
uint64_t address;
|
||||
uint32_t length;
|
||||
uint32_t recv_skip_hint;
|
||||
};
|
||||
#endif /* _GNU_SOURCE */
|
||||
|
||||
#endif /* !_ADAPT_NETINET_TCP_H */
|
||||
62
ohos/kernel/liteos_m/kal/libc/newlib/porting/include/poll.h
Normal file
62
ohos/kernel/liteos_m/kal/libc/newlib/porting/include/poll.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_POLL_H
|
||||
#define _ADAPT_POLL_H
|
||||
|
||||
#include <sys/features.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define POLLIN 0x001
|
||||
#define POLLPRI 0x002
|
||||
#define POLLOUT 0x004
|
||||
#define POLLERR 0x008
|
||||
#define POLLHUP 0x010
|
||||
#define POLLNVAL 0x020
|
||||
|
||||
typedef unsigned long nfds_t;
|
||||
|
||||
struct pollfd {
|
||||
int fd;
|
||||
short events;
|
||||
short revents;
|
||||
};
|
||||
|
||||
int poll(struct pollfd *fds, nfds_t nfds, int timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_POLL_H */
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_SEMAPHORE_H
|
||||
#define _ADAPT_SEMAPHORE_H
|
||||
|
||||
#include <sys/features.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SEM_FAILED ((sem_t *)0)
|
||||
#define __SEM_NUM 4
|
||||
|
||||
typedef struct {
|
||||
volatile int __val[__SEM_NUM * sizeof(long) / sizeof(int)];
|
||||
} sem_t;
|
||||
|
||||
int sem_init(sem_t *sem, int shared, unsigned value);
|
||||
int sem_destroy(sem_t *sem);
|
||||
int sem_wait(sem_t *sem);
|
||||
int sem_trywait(sem_t *sem);
|
||||
int sem_post(sem_t *sem);
|
||||
int sem_timedwait(sem_t *__restrict sem, const struct timespec *__restrict timeout);
|
||||
int sem_getvalue(sem_t *__restrict sem, int *__restrict currVal);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_SEMAPHORE_H */
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_SYS_PTHREADTYPES_H
|
||||
#define _ADAPT_SYS_PTHREADTYPES_H
|
||||
|
||||
#define pthread_t __pthread_t_discard
|
||||
#define pthread_attr_t __pthread_attr_t_discard
|
||||
#define pthread_mutex_t __pthread_mutex_t_discard
|
||||
#define pthread_mutexattr_t __pthread_mutexattr_t_discard
|
||||
#define pthread_cond_t __pthread_cond_t_discard
|
||||
#define pthread_condattr_t __pthread_condattr_t_discard
|
||||
#define pthread_once_t __pthread_once_t_discard
|
||||
#define pthread_barrierattr_t __pthread_barrierattr_t_discard
|
||||
#define pthread_spinlock_t __pthread_spinlock_t_discard
|
||||
|
||||
#include_next <sys/_pthreadtypes.h>
|
||||
|
||||
#undef pthread_t
|
||||
#undef pthread_attr_t
|
||||
#undef pthread_mutex_t
|
||||
#undef pthread_mutexattr_t
|
||||
#undef pthread_cond_t
|
||||
#undef pthread_condattr_t
|
||||
#undef pthread_once_t
|
||||
#undef pthread_barrierattr_t
|
||||
#undef pthread_spinlock_t
|
||||
#undef _PTHREAD_MUTEX_INITIALIZER
|
||||
#undef _PTHREAD_COND_INITIALIZER
|
||||
#undef _PTHREAD_ONCE_INIT
|
||||
|
||||
#undef PTHREAD_STACK_MIN
|
||||
#undef PTHREAD_MUTEX_DEFAULT
|
||||
|
||||
#include "los_config.h"
|
||||
#define PTHREAD_STACK_MIN LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE
|
||||
|
||||
typedef unsigned long pthread_t; /* identify a thread */
|
||||
|
||||
typedef struct {
|
||||
unsigned int detachstate;
|
||||
unsigned int schedpolicy;
|
||||
struct sched_param schedparam;
|
||||
unsigned int inheritsched;
|
||||
unsigned int scope;
|
||||
unsigned int stackaddr_set;
|
||||
void *stackaddr;
|
||||
unsigned int stacksize_set;
|
||||
size_t stacksize;
|
||||
} pthread_attr_t;
|
||||
|
||||
#include "los_list.h"
|
||||
typedef struct { unsigned type; } pthread_mutexattr_t;
|
||||
typedef struct { unsigned int magic; unsigned int handle; pthread_mutexattr_t stAttr;} pthread_mutex_t;
|
||||
|
||||
#define _MUX_MAGIC 0xEBCFDEA0
|
||||
#define _MUX_INVALID_HANDLE 0xEEEEEEEF
|
||||
#define PTHREAD_MUTEX_DEFAULT 0
|
||||
|
||||
#define PTHREAD_MUTEXATTR_INITIALIZER { PTHREAD_MUTEX_RECURSIVE }
|
||||
#define _PTHREAD_MUTEX_INITIALIZER { _MUX_MAGIC, _MUX_INVALID_HANDLE, PTHREAD_MUTEXATTR_INITIALIZER }
|
||||
|
||||
#ifdef _GNU_SOURCE
|
||||
#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP { _MUX_MAGIC, _MUX_INVALID_HANDLE, PTHREAD_MUTEXATTR_INITIALIZER }
|
||||
#endif
|
||||
|
||||
#include "los_event.h"
|
||||
|
||||
typedef struct pthread_cond {
|
||||
volatile int count; /**< The number of tasks blocked by condition */
|
||||
EVENT_CB_S event; /**< Event object*/
|
||||
pthread_mutex_t* mutex; /**< Mutex locker for condition variable protection */
|
||||
volatile int value; /**< Condition variable state value*/
|
||||
int clock;
|
||||
} pthread_cond_t;
|
||||
|
||||
#define _PTHREAD_COND_INITIALIZER { 0 }
|
||||
|
||||
typedef struct { int clock; } pthread_condattr_t;
|
||||
|
||||
typedef __uint32_t pthread_key_t; /* thread-specific data keys */
|
||||
|
||||
typedef int pthread_once_t;
|
||||
|
||||
#define _PTHREAD_ONCE_INIT { 0 }
|
||||
|
||||
typedef struct { unsigned __attr; } pthread_barrierattr_t;
|
||||
|
||||
typedef int pthread_spinlock_t;
|
||||
|
||||
#endif /* !_ADAPT_SYS_PTHREADTYPES_H */
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_SYS_FCNTL_H
|
||||
#define _ADAPT_SYS_FCNTL_H
|
||||
|
||||
#include_next <sys/fcntl.h>
|
||||
|
||||
#define O_NDELAY _FNDELAY
|
||||
|
||||
#ifdef __riscv
|
||||
#ifndef O_CLOEXEC
|
||||
#define O_CLOEXEC 02000000
|
||||
#endif
|
||||
#endif /* __riscv */
|
||||
|
||||
#endif /* !_ADAPT_SYS_FCNTL_H */
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_SYS_FEATURES_H
|
||||
#define _ADAPT_SYS_FEATURES_H
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#define __USE_NEWLIB__
|
||||
|
||||
/* adapt time.h */
|
||||
#define _POSIX_TIMERS 1
|
||||
#define _POSIX_CPUTIME 1
|
||||
#define _POSIX_THREAD_CPUTIME 1
|
||||
#define _POSIX_MONOTONIC_CLOCK 1
|
||||
#define _POSIX_CLOCK_SELECTION 1
|
||||
|
||||
/* adapt sys/signal.h */
|
||||
#define _POSIX_REALTIME_SIGNALS 1
|
||||
|
||||
/* adapt pthread */
|
||||
#define _POSIX_THREADS 1
|
||||
#define _POSIX_TIMEOUTS
|
||||
#define _POSIX_THREAD_PRIORITY_SCHEDULING
|
||||
#define _UNIX98_THREAD_MUTEX_ATTRIBUTES
|
||||
#define _POSIX_THREAD_PROCESS_SHARED
|
||||
#define _POSIX_PRIORITY_SCHEDULING
|
||||
|
||||
#include_next <sys/features.h>
|
||||
|
||||
#endif /* !_ADAPT_SYS_FEATURES_H */
|
||||
126
ohos/kernel/liteos_m/kal/libc/newlib/porting/include/sys/ioctl.h
Normal file
126
ohos/kernel/liteos_m/kal/libc/newlib/porting/include/sys/ioctl.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_SYS_IOCTL_H
|
||||
#define _ADAPT_SYS_IOCTL_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TCGETS 0x5401
|
||||
#define TCSETS 0x5402
|
||||
#define TCSETSW 0x5403
|
||||
#define TCSETSF 0x5404
|
||||
#define TCGETA 0x5405
|
||||
#define TCSETA 0x5406
|
||||
#define TCSETAW 0x5407
|
||||
#define TCSETAF 0x5408
|
||||
#define TCSBRK 0x5409
|
||||
#define TCXONC 0x540A
|
||||
#define TCFLSH 0x540B
|
||||
#define TIOCEXCL 0x540C
|
||||
#define TIOCNXCL 0x540D
|
||||
#define TIOCSCTTY 0x540E
|
||||
#define TIOCGPGRP 0x540F
|
||||
#define TIOCSPGRP 0x5410
|
||||
#define TIOCOUTQ 0x5411
|
||||
#define TIOCSTI 0x5412
|
||||
#define TIOCGWINSZ 0x5413
|
||||
#define TIOCSWINSZ 0x5414
|
||||
#define TIOCMGET 0x5415
|
||||
#define TIOCMBIS 0x5416
|
||||
#define TIOCMBIC 0x5417
|
||||
#define TIOCMSET 0x5418
|
||||
#define TIOCGSOFTCAR 0x5419
|
||||
#define TIOCSSOFTCAR 0x541A
|
||||
#define FIONREAD 0x541B
|
||||
#define TIOCINQ FIONREAD
|
||||
#define TIOCLINUX 0x541C
|
||||
#define TIOCCONS 0x541D
|
||||
#define TIOCGSERIAL 0x541E
|
||||
#define TIOCSSERIAL 0x541F
|
||||
#define TIOCPKT 0x5420
|
||||
#define FIONBIO 0x5421
|
||||
|
||||
#define SIOCADDRT 0x890B
|
||||
#define SIOCDELRT 0x890C
|
||||
#define SIOCRTMSG 0x890D
|
||||
|
||||
#define SIOCGIFNAME 0x8910
|
||||
#define SIOCSIFLINK 0x8911
|
||||
#define SIOCGIFCONF 0x8912
|
||||
#define SIOCGIFFLAGS 0x8913
|
||||
#define SIOCSIFFLAGS 0x8914
|
||||
#define SIOCGIFADDR 0x8915
|
||||
#define SIOCSIFADDR 0x8916
|
||||
#define SIOCGIFDSTADDR 0x8917
|
||||
#define SIOCSIFDSTADDR 0x8918
|
||||
#define SIOCGIFBRDADDR 0x8919
|
||||
#define SIOCSIFBRDADDR 0x891a
|
||||
#define SIOCGIFNETMASK 0x891b
|
||||
#define SIOCSIFNETMASK 0x891c
|
||||
#define SIOCGIFMETRIC 0x891d
|
||||
#define SIOCSIFMETRIC 0x891e
|
||||
#define SIOCGIFMEM 0x891f
|
||||
#define SIOCSIFMEM 0x8920
|
||||
#define SIOCGIFMTU 0x8921
|
||||
#define SIOCSIFMTU 0x8922
|
||||
#define SIOCSIFNAME 0x8923
|
||||
#define SIOCSIFHWADDR 0x8924
|
||||
#define SIOCGIFENCAP 0x8925
|
||||
#define SIOCSIFENCAP 0x8926
|
||||
#define SIOCGIFHWADDR 0x8927
|
||||
#define SIOCGIFSLAVE 0x8929
|
||||
#define SIOCSIFSLAVE 0x8930
|
||||
#define SIOCADDMULTI 0x8931
|
||||
#define SIOCDELMULTI 0x8932
|
||||
#define SIOCGIFINDEX 0x8933
|
||||
#define SIOGIFINDEX SIOCGIFINDEX
|
||||
|
||||
#define _IOC(a, b, c, d) (((a) << 30) | ((b) << 8) | (c) | ((d) << 16))
|
||||
#define _IOC_NONE 0U
|
||||
#define _IOC_WRITE 1U
|
||||
#define _IOC_READ 2U
|
||||
|
||||
#define _IO(a, b) _IOC(_IOC_NONE, (a), (b), 0)
|
||||
#define _IOW(a, b, c) _IOC(_IOC_WRITE, (a), (b), sizeof(c))
|
||||
#define _IOR(a, b, c) _IOC(_IOC_READ, (a), (b), sizeof(c))
|
||||
#define _IOWR(a, b, c) _IOC(_IOC_READ | _IOC_WRITE, (a), (b), sizeof(c))
|
||||
|
||||
int ioctl(int, int, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_SYS_IOCTL_H */
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_SYS_MOUNT_H
|
||||
#define _ADAPT_SYS_MOUNT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MS_RDONLY 1
|
||||
#define MS_NOSUID 2
|
||||
#define MS_NODEV 4
|
||||
#define MS_NOEXEC 8
|
||||
#define MS_SYNCHRONOUS 16
|
||||
#define MS_REMOUNT 32
|
||||
#define MS_MANDLOCK 64
|
||||
#define MS_DIRSYNC 128
|
||||
|
||||
#define MNT_FORCE 1
|
||||
#define MNT_DETACH 2
|
||||
#define MNT_EXPIRE 4
|
||||
#define UMOUNT_NOFOLLOW 8
|
||||
|
||||
int mount(const char *source, const char *target, const char *filesystemtype, \
|
||||
unsigned long mountflags, const void *data);
|
||||
int umount(const char *target);
|
||||
int umount2(const char *target, int flag);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_SYS_MOUNT_H */
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 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 _ADAPT_SYS_PRCTL_H
|
||||
#define _ADAPT_SYS_PRCTL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct prctl_mm_map {
|
||||
uint64_t start_code;
|
||||
uint64_t end_code;
|
||||
uint64_t start_data;
|
||||
uint64_t end_data;
|
||||
uint64_t start_brk;
|
||||
uint64_t brk;
|
||||
uint64_t start_stack;
|
||||
uint64_t arg_start;
|
||||
uint64_t arg_end;
|
||||
uint64_t env_start;
|
||||
uint64_t env_end;
|
||||
uint64_t *auxv;
|
||||
uint32_t auxv_size;
|
||||
uint32_t exe_fd;
|
||||
};
|
||||
|
||||
int prctl(int, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_SYS_PRCTL_H */
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_SYS_SCHED_H
|
||||
#define _ADAPT_SYS_SCHED_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define sched_param sched_param_discard
|
||||
|
||||
#include_next <sys/sched.h>
|
||||
|
||||
#undef sched_param
|
||||
|
||||
struct sched_param {
|
||||
int sched_priority;
|
||||
int __reserved1;
|
||||
struct {
|
||||
time_t __reserved1;
|
||||
long __reserved2;
|
||||
} __reserved2[2];
|
||||
int __reserved3;
|
||||
};
|
||||
|
||||
typedef struct cpu_set_t { unsigned long __bits[128 / sizeof(long)]; } cpu_set_t;
|
||||
|
||||
#endif /* !_ADAPT_SYS_SCHED_H */
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_SYS_SELECT_H
|
||||
#define _ADAPT_SYS_SELECT_H
|
||||
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
#include "vfs_config.h"
|
||||
|
||||
#undef FD_SETSIZE
|
||||
#define FD_SETSIZE TIMER_FD_OFFSET
|
||||
|
||||
#else
|
||||
|
||||
#undef FD_SETSIZE
|
||||
#define FD_SETSIZE 1024
|
||||
|
||||
#endif
|
||||
|
||||
#include_next <sys/select.h>
|
||||
|
||||
#ifdef LOSCFG_ARCH_RISCV
|
||||
#ifdef FD_ISSET(d, s)
|
||||
#undef FD_ISSET(d, s)
|
||||
#define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long)))))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif //_ADAPT_SYS_SELECT_H
|
||||
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_SYS_SOCKET_H
|
||||
#define _ADAPT_SYS_SOCKET_H
|
||||
|
||||
#include <sys/features.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef unsigned socklen_t;
|
||||
typedef unsigned short sa_family_t;
|
||||
|
||||
struct msghdr {
|
||||
void *msg_name;
|
||||
socklen_t msg_namelen;
|
||||
struct iovec *msg_iov;
|
||||
#if LONG_MAX > 0x7fffffff && BYTE_ORDER == BIG_ENDIAN
|
||||
int __pad1;
|
||||
#endif
|
||||
int msg_iovlen;
|
||||
#if LONG_MAX > 0x7fffffff && BYTE_ORDER == LITTLE_ENDIAN
|
||||
int __pad1;
|
||||
#endif
|
||||
void *msg_control;
|
||||
#if LONG_MAX > 0x7fffffff && BYTE_ORDER == BIG_ENDIAN
|
||||
int __pad2;
|
||||
#endif
|
||||
socklen_t msg_controllen;
|
||||
#if LONG_MAX > 0x7fffffff && BYTE_ORDER == LITTLE_ENDIAN
|
||||
int __pad2;
|
||||
#endif
|
||||
int msg_flags;
|
||||
};
|
||||
|
||||
struct cmsghdr {
|
||||
#if LONG_MAX > 0x7fffffff && BYTE_ORDER == BIG_ENDIAN
|
||||
int __pad1;
|
||||
#endif
|
||||
socklen_t cmsg_len;
|
||||
#if LONG_MAX > 0x7fffffff && BYTE_ORDER == LITTLE_ENDIAN
|
||||
int __pad1;
|
||||
#endif
|
||||
int cmsg_level;
|
||||
int cmsg_type;
|
||||
};
|
||||
|
||||
#ifdef _GNU_SOURCE
|
||||
struct ucred {
|
||||
pid_t pid;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
};
|
||||
|
||||
struct mmsghdr {
|
||||
struct msghdr msg_hdr;
|
||||
unsigned int msg_len;
|
||||
};
|
||||
|
||||
struct timespec;
|
||||
|
||||
int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int);
|
||||
int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *);
|
||||
#endif
|
||||
|
||||
struct linger {
|
||||
int l_onoff;
|
||||
int l_linger;
|
||||
};
|
||||
|
||||
#define SHUT_RD 0
|
||||
#define SHUT_WR 1
|
||||
#define SHUT_RDWR 2
|
||||
|
||||
#ifndef SOCK_STREAM
|
||||
#define SOCK_STREAM 1
|
||||
#define SOCK_DGRAM 2
|
||||
#endif
|
||||
|
||||
#define SOCK_RAW 3
|
||||
#define SOCK_RDM 4
|
||||
#define SOCK_SEQPACKET 5
|
||||
#define SOCK_DCCP 6
|
||||
#define SOCK_PACKET 10
|
||||
|
||||
#ifndef SOCK_CLOEXEC
|
||||
#define SOCK_CLOEXEC 02000000
|
||||
#define SOCK_NONBLOCK 04000
|
||||
#endif
|
||||
|
||||
#define PF_UNSPEC 0
|
||||
#define PF_LOCAL 1
|
||||
#define PF_UNIX PF_LOCAL
|
||||
#define PF_FILE PF_LOCAL
|
||||
#define PF_INET 2
|
||||
#define PF_INET6 10
|
||||
#define PF_IPX 4
|
||||
|
||||
#define AF_UNSPEC PF_UNSPEC
|
||||
#define AF_LOCAL PF_LOCAL
|
||||
#define AF_UNIX AF_LOCAL
|
||||
#define AF_FILE AF_LOCAL
|
||||
#define AF_INET PF_INET
|
||||
#define AF_INET6 PF_INET6
|
||||
#define AF_IPX PF_IPX
|
||||
|
||||
#ifndef SO_DEBUG
|
||||
#define SO_DEBUG 1
|
||||
#define SO_REUSEADDR 2
|
||||
#define SO_TYPE 3
|
||||
#define SO_ERROR 4
|
||||
#define SO_DONTROUTE 5
|
||||
#define SO_BROADCAST 6
|
||||
#define SO_SNDBUF 7
|
||||
#define SO_RCVBUF 8
|
||||
#define SO_KEEPALIVE 9
|
||||
#define SO_OOBINLINE 10
|
||||
#define SO_NO_CHECK 11
|
||||
#define SO_PRIORITY 12
|
||||
#define SO_LINGER 13
|
||||
#define SO_BSDCOMPAT 14
|
||||
#define SO_REUSEPORT 15
|
||||
#define SO_PASSCRED 16
|
||||
#define SO_PEERCRED 17
|
||||
#define SO_RCVLOWAT 18
|
||||
#define SO_SNDLOWAT 19
|
||||
#define SO_ACCEPTCONN 30
|
||||
#define SO_PEERSEC 31
|
||||
#define SO_SNDBUFFORCE 32
|
||||
#define SO_RCVBUFFORCE 33
|
||||
#define SO_PROTOCOL 38
|
||||
#define SO_DOMAIN 39
|
||||
#endif
|
||||
|
||||
#ifndef SO_RCVTIMEO
|
||||
#if LONG_MAX == 0x7fffffff
|
||||
#define SO_RCVTIMEO 66
|
||||
#define SO_SNDTIMEO 67
|
||||
#else
|
||||
#define SO_RCVTIMEO 20
|
||||
#define SO_SNDTIMEO 21
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define SO_BINDTODEVICE 25
|
||||
|
||||
#ifndef SOL_SOCKET
|
||||
#define SOL_SOCKET 1
|
||||
#endif
|
||||
#define SOL_IP 0
|
||||
|
||||
#define MSG_OOB 0x0001
|
||||
#define MSG_PEEK 0x0002
|
||||
#define MSG_DONTROUTE 0x0004
|
||||
#define MSG_CTRUNC 0x0008
|
||||
#define MSG_PROXY 0x0010
|
||||
#define MSG_TRUNC 0x0020
|
||||
#define MSG_DONTWAIT 0x0040
|
||||
#define MSG_EOR 0x0080
|
||||
#define MSG_WAITALL 0x0100
|
||||
#define MSG_FIN 0x0200
|
||||
#define MSG_SYN 0x0400
|
||||
#define MSG_CONFIRM 0x0800
|
||||
#define MSG_RST 0x1000
|
||||
#define MSG_ERRQUEUE 0x2000
|
||||
#define MSG_NOSIGNAL 0x4000
|
||||
#define MSG_MORE 0x8000
|
||||
#define MSG_WAITFORONE 0x10000
|
||||
#define MSG_BATCH 0x40000
|
||||
#define MSG_ZEROCOPY 0x4000000
|
||||
#define MSG_FASTOPEN 0x20000000
|
||||
#define MSG_CMSG_CLOEXEC 0x40000000
|
||||
|
||||
#define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1))
|
||||
#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg))
|
||||
#define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen)
|
||||
|
||||
#define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1))
|
||||
#define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \
|
||||
__CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \
|
||||
? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg))
|
||||
#define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0)
|
||||
|
||||
#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))
|
||||
#define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr)))
|
||||
#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
|
||||
|
||||
#define SCM_RIGHTS 0x01
|
||||
#define SCM_CREDENTIALS 0x02
|
||||
|
||||
struct sockaddr {
|
||||
sa_family_t sa_family;
|
||||
char sa_data[14];
|
||||
};
|
||||
|
||||
struct sockaddr_storage {
|
||||
sa_family_t ss_family;
|
||||
char __ss_padding[128 - sizeof(long) - sizeof(sa_family_t)];
|
||||
unsigned long __ss_align;
|
||||
};
|
||||
|
||||
int socket(int, int, int);
|
||||
int socketpair(int, int, int, int [2]);
|
||||
|
||||
int shutdown(int, int);
|
||||
|
||||
int bind(int, const struct sockaddr *, socklen_t);
|
||||
int connect(int, const struct sockaddr *, socklen_t);
|
||||
int listen(int, int);
|
||||
int accept(int, struct sockaddr *__restrict, socklen_t *__restrict);
|
||||
int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int);
|
||||
|
||||
int getsockname(int, struct sockaddr *__restrict, socklen_t *__restrict);
|
||||
int getpeername(int, struct sockaddr *__restrict, socklen_t *__restrict);
|
||||
|
||||
ssize_t send(int, const void *, size_t, int);
|
||||
ssize_t recv(int, void *, size_t, int);
|
||||
ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
|
||||
ssize_t recvfrom(int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict);
|
||||
ssize_t sendmsg(int, const struct msghdr *, int);
|
||||
ssize_t recvmsg(int, struct msghdr *, int);
|
||||
|
||||
int getsockopt(int, int, int, void *__restrict, socklen_t *__restrict);
|
||||
int setsockopt(int, int, int, const void *, socklen_t);
|
||||
|
||||
int sockatmark(int);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_SYS_SOCKET_H */
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_SYS_STATFS_H
|
||||
#define _ADAPT_SYS_STATFS_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct __fsid_t {
|
||||
int __val[2];
|
||||
} fsid_t;
|
||||
|
||||
struct statfs {
|
||||
unsigned long f_type, f_bsize;
|
||||
fsblkcnt_t f_blocks, f_bfree, f_bavail;
|
||||
fsfilcnt_t f_files, f_ffree;
|
||||
fsid_t f_fsid;
|
||||
unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
|
||||
};
|
||||
|
||||
int statfs(const char *, struct statfs *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_SYS_STATFS_H */
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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 _ADAPT_SYS_UIO_H
|
||||
#define _ADAPT_SYS_UIO_H
|
||||
|
||||
#include <sys/features.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define UIO_MAXIOV 1024
|
||||
|
||||
struct iovec {
|
||||
void *iov_base;
|
||||
size_t iov_len;
|
||||
};
|
||||
|
||||
ssize_t readv(int, const struct iovec *, int);
|
||||
ssize_t writev(int, const struct iovec *, int);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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 _ADAPT_SYS_UN_H
|
||||
#define _ADAPT_SYS_UN_H
|
||||
|
||||
#include <sys/features.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct sockaddr_un {
|
||||
sa_family_t sun_family;
|
||||
char sun_path[108];
|
||||
};
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
size_t strlen(const char *);
|
||||
#define SUN_LEN(s) (2 + strlen((s)->sun_path))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
73
ohos/kernel/liteos_m/kal/libc/newlib/porting/include/time.h
Normal file
73
ohos/kernel/liteos_m/kal/libc/newlib/porting/include/time.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 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 _ADAPT_TIME_H
|
||||
#define _ADAPT_TIME_H
|
||||
|
||||
#define __TM_GMTOFF __tm_gmtoff
|
||||
#define __TM_ZONE __tm_zone
|
||||
|
||||
#include_next <time.h>
|
||||
|
||||
#ifdef __riscv
|
||||
#ifndef CLOCK_MONOTONIC_RAW
|
||||
#define CLOCK_MONOTONIC_RAW 12
|
||||
#endif
|
||||
|
||||
#ifndef CLOCK_REALTIME_COARSE
|
||||
#define CLOCK_REALTIME_COARSE 5
|
||||
#endif
|
||||
|
||||
#ifndef CLOCK_MONOTONIC_COARSE
|
||||
#define CLOCK_MONOTONIC_COARSE 6
|
||||
#endif
|
||||
|
||||
#ifndef CLOCK_BOOTTIME
|
||||
#define CLOCK_BOOTTIME 7
|
||||
#endif
|
||||
|
||||
#ifndef CLOCK_REALTIME_ALARM
|
||||
#define CLOCK_REALTIME_ALARM 8
|
||||
#endif
|
||||
|
||||
#ifndef CLOCK_BOOTTIME_ALARM
|
||||
#define CLOCK_BOOTTIME_ALARM 9
|
||||
#endif
|
||||
|
||||
#ifndef CLOCK_SGI_CYCLE
|
||||
#define CLOCK_SGI_CYCLE 10
|
||||
#endif
|
||||
|
||||
#ifndef CLOCK_TAI
|
||||
#define CLOCK_TAI 11
|
||||
#endif
|
||||
#endif /* __riscv */
|
||||
|
||||
#endif /* !_ADAPT_TIME_H */
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2023 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"
|
||||
#include <sys/cdefs.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
/*
|
||||
* fs adapter interface, such as _read, see component/fs
|
||||
* time adapter interface, such as _gettimeofday, see posix/src/time.c
|
||||
* malloc adapter interface, such as _malloc_r, see posix/src/malloc.c
|
||||
*/
|
||||
|
||||
int _isatty(int file)
|
||||
{
|
||||
return (int)(file <= 2); // 2: stderr
|
||||
}
|
||||
|
||||
int _kill(int i, int j)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _getpid(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _exit(int status)
|
||||
{
|
||||
write(1, "exit\n", 5); // 1: stdout; 5: string length
|
||||
(VOID)pthread_exit(&status);
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
46
ohos/kernel/liteos_m/kal/posix/include/libc.h
Normal file
46
ohos/kernel/liteos_m/kal/posix/include/libc.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 LIBC_H_
|
||||
#define LIBC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char *libc_get_version_string(void);
|
||||
int libc_get_version(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // LIBC_H_
|
||||
61
ohos/kernel/liteos_m/kal/posix/include/pipe_impl.h
Normal file
61
ohos/kernel/liteos_m/kal/posix/include/pipe_impl.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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 _PIPE_IMPL_H
|
||||
#define _PIPE_IMPL_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "los_config.h"
|
||||
#include "poll_impl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define PIPE_DEV_PATH "/dev/pipe"
|
||||
|
||||
UINT32 OsPipeInit(VOID);
|
||||
INT32 PipeOpen(const CHAR *path, INT32 openFlag, INT32 minFd);
|
||||
INT32 PipeClose(INT32 fd);
|
||||
INT32 PipeRead(INT32 fd, VOID *buf, size_t len);
|
||||
INT32 PipeWrite(INT32 fd, const VOID *buf, size_t len);
|
||||
INT32 PipeUnlink(const CHAR *path);
|
||||
INT32 PipePoll(INT32 fd, struct PollTable *table);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _PIPE_IMPL_H */
|
||||
74
ohos/kernel/liteos_m/kal/posix/include/poll_impl.h
Normal file
74
ohos/kernel/liteos_m/kal/posix/include/poll_impl.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 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 _POLL_IMPL_H
|
||||
#define _POLL_IMPL_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_list.h"
|
||||
#include "los_sem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef UINT32 PollEvent;
|
||||
|
||||
struct PollWaitQueue {
|
||||
LOS_DL_LIST queue;
|
||||
};
|
||||
|
||||
struct PollTable;
|
||||
struct PollWaitNode {
|
||||
LOS_DL_LIST node;
|
||||
struct PollTable *table;
|
||||
};
|
||||
|
||||
struct PollTable {
|
||||
struct PollWaitNode *node;
|
||||
PollEvent event;
|
||||
UINT32 sem;
|
||||
BOOL addQueueFlag;
|
||||
};
|
||||
|
||||
VOID PollWaitQueueInit(struct PollWaitQueue *waitQueue);
|
||||
VOID PollNotify(struct PollWaitQueue *waitQueue, PollEvent event);
|
||||
VOID PollWait(struct PollWaitQueue *waitQueue, struct PollTable *table);
|
||||
INT32 PollQueryFd(INT32 fd, struct PollTable *table);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _POLL_IMPL_H */
|
||||
95
ohos/kernel/liteos_m/kal/posix/include/rtc_time_hook.h
Normal file
95
ohos/kernel/liteos_m/kal/posix/include/rtc_time_hook.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022-2022 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 _RTC_TIME_HOOK_H
|
||||
#define _RTC_TIME_HOOK_H
|
||||
|
||||
#include "los_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/*
|
||||
* RTC interfaces for improving the accuracy of the time, need implement and
|
||||
* register by user, implementation method is as follows:
|
||||
*
|
||||
* UINT64 RtcGetTickHook(VOID)
|
||||
* brief: supplement expanded ticks
|
||||
* input: VOID
|
||||
* return: UINT64 ticks
|
||||
*
|
||||
* INT32 RtcGetTimeHook(UINT64 *usec)
|
||||
* brief: get RTC time
|
||||
* output: UINT64 *usec, pointer to get the time, value is counted in microsecond(us)
|
||||
* return: non-0 if error, 0 if success.
|
||||
*
|
||||
* INT32 RtcSetTimeHook(UINT64 msec, UINT64 *usec)
|
||||
* brief: set RTC time
|
||||
* input: UINT64 msec, the time to be set counted in millisecond(ms).
|
||||
* input: UINT64 *usec, the time to be set counted in microsecond(us)
|
||||
* return: non-0 if error, 0 if success.
|
||||
*
|
||||
* INT32 RtcGetTimezoneHook(INT32 *tz)
|
||||
* brief: get RTC timezone
|
||||
* output: INT32 *tz, pointer to get the timezone, value is counted in second
|
||||
* return: non-0 if error, 0 if success.
|
||||
*
|
||||
* INT32 RtcSetTimezoneHook(INT32 tz)
|
||||
* brief: set RTC timezone
|
||||
* input: INT32 tz, the timezone to be set, value is counted in second
|
||||
* return: non-0 if error, 0 if success.
|
||||
*/
|
||||
struct RtcTimeHook {
|
||||
UINT64 (*RtcGetTickHook)(VOID);
|
||||
INT32 (*RtcGetTimeHook)(UINT64 *usec);
|
||||
INT32 (*RtcSetTimeHook)(UINT64 msec, UINT64 *usec);
|
||||
INT32 (*RtcGetTimezoneHook)(INT32 *tz);
|
||||
INT32 (*RtcSetTimezoneHook)(INT32 tz);
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief let user register a RTC getter hook to improve time accuracy for time-related POSIX methods.
|
||||
* @param cfg, a structure, member is pointer to function to be registered
|
||||
* @return VOID.
|
||||
*/
|
||||
VOID LOS_RtcHookRegister(struct RtcTimeHook *cfg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
49
ohos/kernel/liteos_m/kal/posix/src/errno.c
Normal file
49
ohos/kernel/liteos_m/kal/posix/src/errno.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 <errno.h>
|
||||
#include "los_interrupt.h"
|
||||
#include "los_task.h"
|
||||
|
||||
/* the specific errno get or set in interrupt service routine */
|
||||
static int g_isrErrno;
|
||||
|
||||
int *__errno_location(void)
|
||||
{
|
||||
LosTaskCB *runTask = NULL;
|
||||
|
||||
if (OS_INT_INACTIVE) {
|
||||
runTask = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
|
||||
return &runTask->errorNo;
|
||||
} else {
|
||||
return &g_isrErrno;
|
||||
}
|
||||
}
|
||||
157
ohos/kernel/liteos_m/kal/posix/src/malloc.c
Normal file
157
ohos/kernel/liteos_m/kal/posix/src/malloc.c
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2023 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 <stdint.h>
|
||||
#include "securec.h"
|
||||
#include "los_config.h"
|
||||
#include "los_memory.h"
|
||||
|
||||
#if LOSCFG_BASE_CORE_MEMPOOL
|
||||
|
||||
#if (LOSCFG_LIBC_NEWLIB == 1)
|
||||
void *__wrap__calloc_r(struct _reent *reent, size_t nitems, size_t size)
|
||||
#else
|
||||
void *calloc(size_t nitems, size_t size)
|
||||
#endif
|
||||
{
|
||||
#if (LOSCFG_LIBC_NEWLIB == 1)
|
||||
(void)reent;
|
||||
#endif
|
||||
size_t real_size;
|
||||
void *ptr = NULL;
|
||||
|
||||
if ((nitems == 0) || (size == 0) || (nitems > (UINT32_MAX / size))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
real_size = (size_t)(nitems * size);
|
||||
ptr = LOS_MemAlloc(OS_SYS_MEM_ADDR, real_size);
|
||||
if (ptr != NULL) {
|
||||
(void)memset_s(ptr, real_size, 0, real_size);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#if (LOSCFG_LIBC_NEWLIB == 1)
|
||||
void __wrap__free_r(struct _reent *reent, void *ptr)
|
||||
#else
|
||||
void free(void *ptr)
|
||||
#endif
|
||||
{
|
||||
#if (LOSCFG_LIBC_NEWLIB == 1)
|
||||
(void)reent;
|
||||
#endif
|
||||
if (ptr == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, ptr);
|
||||
}
|
||||
|
||||
#if (LOSCFG_LIBC_NEWLIB == 1)
|
||||
size_t __wrap__malloc_usable_size_r(struct _reent *reent, void *aptr)
|
||||
{
|
||||
(void)reent;
|
||||
(void)aptr;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_LIBC_NEWLIB == 1)
|
||||
void *__wrap__malloc_r(struct _reent *reent, size_t size)
|
||||
#else
|
||||
void *malloc(size_t size)
|
||||
#endif
|
||||
{
|
||||
#if (LOSCFG_LIBC_NEWLIB == 1)
|
||||
(void)reent;
|
||||
#endif
|
||||
if (size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return LOS_MemAlloc(OS_SYS_MEM_ADDR, size);
|
||||
}
|
||||
|
||||
void *zalloc(size_t size)
|
||||
{
|
||||
void *ptr = NULL;
|
||||
|
||||
if (size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr = LOS_MemAlloc(OS_SYS_MEM_ADDR, size);
|
||||
if (ptr != NULL) {
|
||||
(void)memset_s(ptr, size, 0, size);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#if (LOSCFG_LIBC_NEWLIB == 1)
|
||||
void *__wrap__memalign_r(struct _reent *reent, size_t boundary, size_t size)
|
||||
#else
|
||||
void *memalign(size_t boundary, size_t size)
|
||||
#endif
|
||||
{
|
||||
#if (LOSCFG_LIBC_NEWLIB == 1)
|
||||
(void)reent;
|
||||
#endif
|
||||
if (size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return LOS_MemAllocAlign(OS_SYS_MEM_ADDR, size, boundary);
|
||||
}
|
||||
|
||||
#if (LOSCFG_LIBC_NEWLIB == 1)
|
||||
void *__wrap__realloc_r(struct _reent *reent, void *ptr, size_t size)
|
||||
#else
|
||||
void *realloc(void *ptr, size_t size)
|
||||
#endif
|
||||
{
|
||||
#if (LOSCFG_LIBC_NEWLIB == 1)
|
||||
(void)reent;
|
||||
#endif
|
||||
if (ptr == NULL) {
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
free(ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return LOS_MemRealloc(OS_SYS_MEM_ADDR, ptr, size);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
701
ohos/kernel/liteos_m/kernel/include/los_config.h
Normal file
701
ohos/kernel/liteos_m/kernel/include/los_config.h
Normal file
@@ -0,0 +1,701 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_config System configuration items
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_CONFIG_H
|
||||
#define _LOS_CONFIG_H
|
||||
|
||||
#include "target_config.h"
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* =============================================================================
|
||||
System clock module configuration
|
||||
============================================================================= */
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* System clock (unit: HZ)
|
||||
*/
|
||||
#ifndef OS_SYS_CLOCK
|
||||
#define OS_SYS_CLOCK 1000000
|
||||
#endif
|
||||
|
||||
#ifndef LOSCFG_BASE_CORE_MEMPOOL
|
||||
#define LOSCFG_BASE_CORE_MEMPOOL 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Number of Ticks in one second
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TICK_PER_SECOND
|
||||
#define LOSCFG_BASE_CORE_TICK_PER_SECOND (100UL)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Minimum response error accuracy of tick interrupts, number of ticks in one second.
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI
|
||||
#define LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI (1000UL) /* 1ms */
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_PER_SECOND > LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI)
|
||||
#error "LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI must be greater than LOSCFG_BASE_CORE_TICK_PER_SECOND"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI > 1000UL)
|
||||
#error "LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI must be less than or equal to 1000"
|
||||
#endif
|
||||
|
||||
#if defined(LOSCFG_BASE_CORE_TICK_PER_SECOND) && \
|
||||
((LOSCFG_BASE_CORE_TICK_PER_SECOND < 1UL) || (LOSCFG_BASE_CORE_TICK_PER_SECOND > 1000000000UL))
|
||||
#error "LOSCFG_BASE_CORE_TICK_PER_SECOND SHOULD big than 0, and less than 1000000000UL"
|
||||
#endif
|
||||
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_PER_SECOND <= 1000UL)
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* How much time one tick spent (unit:ms)
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TICK_PERIOD_MS
|
||||
#define LOSCFG_BASE_CORE_TICK_PERIOD_MS (1000UL / LOSCFG_BASE_CORE_TICK_PER_SECOND)
|
||||
#endif
|
||||
|
||||
#elif (LOSCFG_BASE_CORE_TICK_PER_SECOND <= 1000000UL)
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* How much time one tick spent (unit:us)
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TICK_PERIOD_US
|
||||
#define LOSCFG_BASE_CORE_TICK_PERIOD_US (1000000UL / LOSCFG_BASE_CORE_TICK_PER_SECOND)
|
||||
#endif
|
||||
|
||||
#else
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* How much time one tick spent (unit:ns)
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TICK_PERIOD_NS
|
||||
#define LOSCFG_BASE_CORE_TICK_PERIOD_NS (1000000000UL / LOSCFG_BASE_CORE_TICK_PER_SECOND)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* System timer is a 64/128 bit timer
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TICK_WTIMER
|
||||
#define LOSCFG_BASE_CORE_TICK_WTIMER 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* System timer count maximum
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TICK_RESPONSE_MAX
|
||||
#define LOSCFG_BASE_CORE_TICK_RESPONSE_MAX 0
|
||||
#endif
|
||||
|
||||
/* =============================================================================
|
||||
Hardware interrupt module configuration
|
||||
============================================================================= */
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item for hardware interrupt tailoring
|
||||
*/
|
||||
#ifndef LOSCFG_PLATFORM_HWI
|
||||
#define LOSCFG_PLATFORM_HWI 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item for using system defined vector base address and interrupt handlers.
|
||||
* If LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT is set to 0, vector base address will not be
|
||||
* modified by system. In arm, it should be noted that PendSV_Handler and SysTick_Handler should
|
||||
* be redefined to HalPendSV and OsTickHandler respectly in this case, because system depends on
|
||||
* these interrupt handlers to run normally. What's more, LOS_HwiCreate will not register handler.
|
||||
*/
|
||||
#ifndef LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT
|
||||
#define LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT 1
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI == 0)
|
||||
#error "if LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT is set to 1, then LOSCFG_PLATFORM_HWI must also be set to 1"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Maximum number of used hardware interrupts, including Tick timer interrupts.
|
||||
*/
|
||||
#ifndef LOSCFG_PLATFORM_HWI_LIMIT
|
||||
#define LOSCFG_PLATFORM_HWI_LIMIT 32
|
||||
#endif
|
||||
|
||||
/* =============================================================================
|
||||
Task module configuration
|
||||
============================================================================= */
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Minimum stack size.
|
||||
*
|
||||
* 0x80 bytes, aligned on a boundary of 8.
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE
|
||||
#define LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE (ALIGN(0x80, 4))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Default task priority
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO
|
||||
#define LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO 10
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Maximum supported number of tasks except the idle task rather than the number of usable tasks
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TSK_LIMIT
|
||||
#define LOSCFG_BASE_CORE_TSK_LIMIT 5
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Size of the idle task stack
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE
|
||||
#define LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE 0x180UL
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Default task stack size
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE
|
||||
#define LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE 0x400UL
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item for task Robin tailoring
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TIMESLICE
|
||||
#define LOSCFG_BASE_CORE_TIMESLICE 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Longest execution time of tasks with the same priorities
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT
|
||||
#define LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT 20000 /* 20ms */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item for task (stack) monitoring module tailoring
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TSK_MONITOR
|
||||
#define LOSCFG_BASE_CORE_TSK_MONITOR 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item for task perf task filter hook
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_EXC_TSK_SWITCH
|
||||
#define LOSCFG_BASE_CORE_EXC_TSK_SWITCH 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* @ingroup los_config
|
||||
* Configuration item for task context switch hook
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TSK_SWITCH_HOOK
|
||||
#define LOSCFG_BASE_CORE_TSK_SWITCH_HOOK()
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Define a usable task priority.Highest task priority.
|
||||
*/
|
||||
#ifndef LOS_TASK_PRIORITY_HIGHEST
|
||||
#define LOS_TASK_PRIORITY_HIGHEST 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Define a usable task priority.Lowest task priority.
|
||||
*/
|
||||
#ifndef LOS_TASK_PRIORITY_LOWEST
|
||||
#define LOS_TASK_PRIORITY_LOWEST 31
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item for task stack independent
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TASKSTACK_INDEPENDENT
|
||||
#define LOSCFG_BASE_CORE_TASKSTACK_INDEPENDENT 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* SP align size
|
||||
*/
|
||||
#ifndef LOSCFG_STACK_POINT_ALIGN_SIZE
|
||||
#define LOSCFG_STACK_POINT_ALIGN_SIZE 8
|
||||
#endif
|
||||
|
||||
/* =============================================================================
|
||||
Semaphore module configuration
|
||||
============================================================================= */
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item for semaphore module tailoring
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_IPC_SEM
|
||||
#define LOSCFG_BASE_IPC_SEM 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Maximum supported number of semaphores
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_IPC_SEM_LIMIT
|
||||
#define LOSCFG_BASE_IPC_SEM_LIMIT 6
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Maximum number of semaphores.
|
||||
*/
|
||||
#ifndef OS_SEM_COUNTING_MAX_COUNT
|
||||
#define OS_SEM_COUNTING_MAX_COUNT 0xFFFF
|
||||
#endif
|
||||
|
||||
/* =============================================================================
|
||||
Mutex module configuration
|
||||
============================================================================= */
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item for mutex module tailoring
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_IPC_MUX
|
||||
#define LOSCFG_BASE_IPC_MUX 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Maximum supported number of mutexes
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_IPC_MUX_LIMIT
|
||||
#define LOSCFG_BASE_IPC_MUX_LIMIT 6
|
||||
#endif
|
||||
|
||||
/* =============================================================================
|
||||
Queue module configuration
|
||||
============================================================================= */
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item for queue module tailoring
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_IPC_QUEUE
|
||||
#define LOSCFG_BASE_IPC_QUEUE 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Maximum supported number of queues rather than the number of usable queues
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_IPC_QUEUE_LIMIT
|
||||
#define LOSCFG_BASE_IPC_QUEUE_LIMIT 6
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Maximum supported number of static queues rather than the number of usable queues
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_IPC_STATIC_QUEUE_LIMIT
|
||||
#define LOSCFG_BASE_IPC_STATIC_QUEUE_LIMIT 3
|
||||
#endif
|
||||
|
||||
|
||||
/* =============================================================================
|
||||
Software timer module configuration
|
||||
============================================================================= */
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item for software timer module tailoring
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_SWTMR
|
||||
#define LOSCFG_BASE_CORE_SWTMR 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Maximum supported number of software timers rather than the number of usable software timers
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_SWTMR_LIMIT
|
||||
#define LOSCFG_BASE_CORE_SWTMR_LIMIT 5
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Software timer task stack size
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_TSK_SWTMR_STACK_SIZE
|
||||
#define LOSCFG_BASE_CORE_TSK_SWTMR_STACK_SIZE LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configurate item for software timer align tailoring
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_CORE_SWTMR_ALIGN
|
||||
#define LOSCFG_BASE_CORE_SWTMR_ALIGN 0
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 0)
|
||||
#error "if LOSCFG_BASE_CORE_SWTMR_ALIGN is set to 1, then LOSCFG_BASE_CORE_SWTMR must also be set to 1"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Maximum size of a software timer queue
|
||||
*/
|
||||
#ifndef OS_SWTMR_HANDLE_QUEUE_SIZE
|
||||
#define OS_SWTMR_HANDLE_QUEUE_SIZE (LOSCFG_BASE_CORE_SWTMR_LIMIT + 0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Minimum divisor of software timer multiple alignment
|
||||
*/
|
||||
#ifndef LOS_COMMON_DIVISOR
|
||||
#define LOS_COMMON_DIVISOR 10
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
#if (LOSCFG_BASE_IPC_QUEUE == 0)
|
||||
#error "if LOSCFG_BASE_CORE_SWTMR is set to 1, then LOSCFG_BASE_IPC_QUEUE must also be set to 1"
|
||||
#endif
|
||||
#endif
|
||||
/* =============================================================================
|
||||
Memory module configuration ---- to be refactored
|
||||
============================================================================= */
|
||||
extern UINT8 *m_aucSysMem0;
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configure whether the kernel uses external heap memory
|
||||
*/
|
||||
#ifndef LOSCFG_SYS_EXTERNAL_HEAP
|
||||
#define LOSCFG_SYS_EXTERNAL_HEAP 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Starting address of the memory
|
||||
*/
|
||||
#ifndef LOSCFG_SYS_HEAP_ADDR
|
||||
#define LOSCFG_SYS_HEAP_ADDR (&m_aucSysMem0[0])
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Starting address of the task stack
|
||||
*/
|
||||
#ifndef OS_TASK_STACK_ADDR
|
||||
#define OS_TASK_STACK_ADDR LOSCFG_SYS_HEAP_ADDR
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Memory size
|
||||
*/
|
||||
#ifndef LOSCFG_SYS_HEAP_SIZE
|
||||
#define LOSCFG_SYS_HEAP_SIZE 0x10000UL
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration module tailoring of more memory pool checking
|
||||
*/
|
||||
#ifndef LOSCFG_MEM_MUL_POOL
|
||||
#define LOSCFG_MEM_MUL_POOL 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration module tailoring of memory released by task id
|
||||
*/
|
||||
#ifndef LOSCFG_MEM_FREE_BY_TASKID
|
||||
#define LOSCFG_MEM_FREE_BY_TASKID 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration module tailoring of mem node integrity checking
|
||||
*/
|
||||
#ifndef LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK
|
||||
#define LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* The default is 4, which means that the function call stack is recorded from the kernel interface,
|
||||
* such as LOS_MemAlloc/LOS_MemAllocAlign/LOS_MemRealloc/LOS_MemFree. If you want to further ignore
|
||||
* the number of function call layers, you can increase this value appropriately.
|
||||
* @attention
|
||||
* The default is in the IAR tool. Under different compilation environments, this value needs to be adjusted.
|
||||
*/
|
||||
#ifndef LOSCFG_MEM_OMIT_LR_CNT
|
||||
#define LOSCFG_MEM_OMIT_LR_CNT 4
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* The record number of layers of the function call relationship starting from the number of
|
||||
* ignored layers(LOSCFG_MEM_OMIT_LR_CNT).
|
||||
*/
|
||||
#ifndef LOSCFG_MEM_RECORD_LR_CNT
|
||||
#define LOSCFG_MEM_RECORD_LR_CNT 3
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration memory leak recorded num
|
||||
*/
|
||||
#ifndef LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM
|
||||
#define LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM 1024
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration of memory pool record memory consumption waterline
|
||||
*/
|
||||
#ifndef LOSCFG_MEM_WATERLINE
|
||||
#define LOSCFG_MEM_WATERLINE 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Number of memory checking blocks
|
||||
*/
|
||||
#ifndef OS_SYS_MEM_NUM
|
||||
#define OS_SYS_MEM_NUM 20
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Size of unaligned memory
|
||||
*/
|
||||
#ifndef OS_SYS_NOCACHEMEM_SIZE
|
||||
#define OS_SYS_NOCACHEMEM_SIZE 0x0UL
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Starting address of the unaligned memory
|
||||
*/
|
||||
#if (OS_SYS_NOCACHEMEM_SIZE > 0)
|
||||
#define OS_SYS_NOCACHEMEM_ADDR (&g_sysNoCacheMem0[0])
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration of multiple non-continuous memory regions as one memory pool
|
||||
*/
|
||||
#ifndef LOSCFG_MEM_MUL_REGIONS
|
||||
#define LOSCFG_MEM_MUL_REGIONS 0
|
||||
#endif
|
||||
|
||||
/* =============================================================================
|
||||
Exception module configuration
|
||||
============================================================================= */
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration of hardware stack protection
|
||||
*/
|
||||
#ifndef LOSCFG_EXC_HARDWARE_STACK_PROTECTION
|
||||
#define LOSCFG_EXC_HARDWARE_STACK_PROTECTION 0
|
||||
#endif
|
||||
|
||||
/* =============================================================================
|
||||
KAL module configuration
|
||||
============================================================================= */
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration CMSIS_OS_VER
|
||||
*/
|
||||
#ifndef CMSIS_OS_VER
|
||||
#define CMSIS_OS_VER 2
|
||||
#endif
|
||||
|
||||
/* =============================================================================
|
||||
Trace module configuration
|
||||
============================================================================= */
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration trace tool
|
||||
*/
|
||||
|
||||
#if (LOSCFG_KERNEL_TRACE == 1)
|
||||
|
||||
#ifndef NUM_HAL_INTERRUPT_UART
|
||||
#define NUM_HAL_INTERRUPT_UART 0xff
|
||||
#endif
|
||||
|
||||
#ifndef OS_TICK_INT_NUM
|
||||
#define OS_TICK_INT_NUM 0xff
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* =============================================================================
|
||||
printf configuration
|
||||
============================================================================= */
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration liteos printf
|
||||
*/
|
||||
#ifndef LOSCFG_KERNEL_PRINTF
|
||||
#define LOSCFG_KERNEL_PRINTF 1
|
||||
#endif
|
||||
|
||||
/* =============================================================================
|
||||
misc configuration
|
||||
============================================================================= */
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item for mpu.
|
||||
*/
|
||||
#ifndef LOSCFG_MPU_ENABLE
|
||||
#define LOSCFG_MPU_ENABLE 0
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_EXC_HARDWARE_STACK_PROTECTION == 1) && (LOSCFG_MPU_ENABLE == 0)
|
||||
#error "if hardware stack protection is enabled, then MPU should be supported and enabled"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item to get task used memory.
|
||||
*/
|
||||
#ifndef LOSCFG_TASK_MEM_USED
|
||||
#define LOSCFG_TASK_MEM_USED 0
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_interrupt
|
||||
* Configuration item for interrupt with argument
|
||||
*/
|
||||
#ifndef LOSCFG_PLATFORM_HWI_WITH_ARG
|
||||
#define LOSCFG_PLATFORM_HWI_WITH_ARG 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item to set interrupt vector align size.
|
||||
*/
|
||||
#ifndef LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#define LOSCFG_ARCH_HWI_VECTOR_ALIGN 0x100
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Task extension field additional functions, such as IAR TLS.
|
||||
* Please Use the LOSCFG_TASK_STRUCT_EXTENSION macro to define your task extended fields in target_config.h
|
||||
*/
|
||||
#ifndef LOSCFG_TASK_CREATE_EXTENSION_HOOK
|
||||
#define LOSCFG_TASK_CREATE_EXTENSION_HOOK(taskCB)
|
||||
#endif
|
||||
#ifndef LOSCFG_TASK_DELETE_EXTENSION_HOOK
|
||||
#define LOSCFG_TASK_DELETE_EXTENSION_HOOK(taskCB)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item to enable kernel signal.
|
||||
*/
|
||||
#ifndef LOSCFG_KERNEL_SIGNAL
|
||||
#define LOSCFG_KERNEL_SIGNAL 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item to enable kernel power module.
|
||||
*/
|
||||
#ifndef LOSCFG_KERNEL_PM
|
||||
#define LOSCFG_KERNEL_PM 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item to enable kernel power module in idle task.
|
||||
*/
|
||||
#ifndef LOSCFG_KERNEL_PM_IDLE
|
||||
#define LOSCFG_KERNEL_PM_IDLE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Configuration item to set shell stack size.
|
||||
*/
|
||||
#ifndef LOSCFG_SHELL_STACK_SIZE
|
||||
#define LOSCFG_SHELL_STACK_SIZE 0x1000
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* _LOS_CONFIG_H */
|
||||
345
ohos/kernel/liteos_m/kernel/include/los_event.h
Normal file
345
ohos/kernel/liteos_m/kernel/include/los_event.h
Normal file
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_event Event
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_EVENT_H
|
||||
#define _LOS_EVENT_H
|
||||
|
||||
#include "los_list.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading mode: The task waits for all its expected events to occur.
|
||||
*/
|
||||
#define LOS_WAITMODE_AND (4) /* all bits must be set */
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading mode: The task waits for any of its expected events to occur.
|
||||
*/
|
||||
#define LOS_WAITMODE_OR (2) /* any bit must be set */
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading mode: The event flag is immediately cleared after the event is read.
|
||||
*/
|
||||
#define LOS_WAITMODE_CLR (1) /* clear when satisfied */
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Bit 25 of the event mask cannot be set to an event because it is set to an error code.
|
||||
*
|
||||
* Value: 0x02001c00
|
||||
*
|
||||
* Solution: Set bits excluding bit 25 of the event mask to events.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_SETBIT_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x00)
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: Event reading times out.
|
||||
*
|
||||
* Value: 0x02001c01
|
||||
*
|
||||
* Solution: Increase the waiting time for event reading, or make another task write a mask for the event.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_READ_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: The EVENTMASK input parameter value is valid. The input parameter value must not be 0.
|
||||
*
|
||||
* Value: 0x02001c02
|
||||
*
|
||||
* Solution: Pass in a valid EVENTMASK value.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_EVENTMASK_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: The event is being read during an interrupt.
|
||||
*
|
||||
* Value: 0x02001c03
|
||||
*
|
||||
* Solution: Read the event in a task.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_READ_IN_INTERRUPT LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: The uwFlags input parameter value used in the event reading API is invalid.
|
||||
* This input parameter value is obtained by performing an OR operation on corresponding bits of either OS_EVENT_ANY or
|
||||
* OS_EVENT_ANY and corresponding bits of either OS_EVENT_WAIT or OS_EVENT_NOWAIT. The waiting time must be set to
|
||||
* a nonzero value when an event is read in the mode of OS_EVENT_WAIT.
|
||||
*
|
||||
* Value: 0x02001c04
|
||||
*
|
||||
* Solution: Pass in a valid uwFlags value.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_FLAGS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: The task is locked and is unable to read the event.
|
||||
*
|
||||
* Value: 0x02001c05
|
||||
*
|
||||
* Solution: Unlock the task and read the event.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_READ_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: Null pointer.
|
||||
*
|
||||
* Value: 0x02001c06
|
||||
*
|
||||
* Solution: Check whether the input parameter is null.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x06)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: no initialized.
|
||||
*
|
||||
* Value: 0x02001c07
|
||||
*
|
||||
* Solution: Check whether the event is initialized.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_NOT_INITIALIZED LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x07)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: should not be destroyed.
|
||||
*
|
||||
* Value: 0x02001c08
|
||||
*
|
||||
* Solution: Check whether the event list is not empty.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_SHOULD_NOT_DESTROYED LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x08)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: The event is being read in a system-level task.
|
||||
* Value: 0x02001c09
|
||||
*
|
||||
* Solution: Read the event in a valid task.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_READ_IN_SYSTEM_TASK LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x09)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event control structure
|
||||
*/
|
||||
typedef struct tagEvent {
|
||||
UINT32 uwEventID; /**< Event mask in the event control block,
|
||||
indicating the event that has been logically processed. */
|
||||
LOS_DL_LIST stEventList; /**< Event control block linked list */
|
||||
} EVENT_CB_S, *PEVENT_CB_S;
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* @brief Initialize an event control block.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize the event control block pointed to by eventCB.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param eventCB [IN/OUT] Pointer to the event control block to be initialized.
|
||||
*
|
||||
* @retval #LOS_ERRNO_EVENT_PTR_NULL Null pointer.
|
||||
* @retval #LOS_OK The event control block is successfully initialized.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_event.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_EventClear
|
||||
*/
|
||||
extern UINT32 LOS_EventInit(PEVENT_CB_S eventCB);
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* @brief Obtain an event specified by the event ID.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to check whether an event expected by the user occurs according to the event ID, event mask,
|
||||
* and event reading mode, and process the event based on the event reading mode. The event ID must point to
|
||||
* valid memory.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>When the mode is LOS_WAITMODE_CLR, the eventID is passed-out.</li>
|
||||
* <li>Otherwise the eventID is passed-in.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param eventID [IN/OUT] Pointer to the ID of the event to be checked.
|
||||
* @param eventMask [IN] Mask of the event expected to occur by the user, indicating the event obtained after
|
||||
* it is logically processed that matches the ID pointed to by mode.
|
||||
* @param mode [IN] Event reading mode. The modes include LOS_WAITMODE_AND, LOS_WAITMODE_OR, LOS_WAITMODE_CLR.
|
||||
*
|
||||
* @retval 0 The event expected by the user does not occur.
|
||||
* @retval #UINT32 The event expected by the user occurs.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_event.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_EventRead | LOS_EventWrite
|
||||
*/
|
||||
extern UINT32 LOS_EventPoll(UINT32 *eventID, UINT32 eventMask, UINT32 mode);
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* @brief Read an event.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to block or schedule a task that reads an event of which the event control block, event mask,
|
||||
* reading mode,
|
||||
* and timeout information are specified.
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>An error code and an event return value can be same. To differentiate the error code and return value, bit 25 of
|
||||
* the event mask is forbidden to be used.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param eventCB [IN/OUT] Pointer to the event control block to be checked. This parameter must point to
|
||||
* valid memory.
|
||||
* @param eventMask [IN] Mask of the event expected to occur by the user, indicating the event obtained after
|
||||
* it is logically processed that matches the ID pointed to by eventID.
|
||||
* @param mode [IN] Event reading mode.
|
||||
* @param timeOut [IN] Timeout interval of event reading (unit: Tick).
|
||||
*
|
||||
* @retval #LOS_ERRNO_EVENT_SETBIT_INVALID Bit 25 of the event mask cannot be set because
|
||||
* it is set to an error number.
|
||||
* @retval #LOS_ERRNO_EVENT_EVENTMASK_INVALID The passed-in event reading mode is incorrect.
|
||||
* @retval #LOS_ERRNO_EVENT_READ_IN_INTERRUPT The event is being read during an interrupt.
|
||||
* @retval #LOS_ERRNO_EVENT_FLAGS_INVALID The event mode is invalid.
|
||||
* @retval #LOS_ERRNO_EVENT_READ_IN_LOCK The event reading task is locked.
|
||||
* @retval #LOS_ERRNO_EVENT_PTR_NULL The passed-in pointer is null.
|
||||
* @retval 0 The event expected by the user does not occur.
|
||||
* @retval #UINT32 The event expected by the user occurs.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_event.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_EventPoll | LOS_EventWrite
|
||||
*/
|
||||
extern UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* @brief Write an event.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to write an event specified by the passed-in event mask into an event control block
|
||||
* pointed to by eventCB.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>To determine whether the LOS_EventRead API returns an event or an error code, bit 25 of the event mask
|
||||
* is forbidden to be used.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param eventCB [IN/OUT] Pointer to the event control block into which an event is to be written.
|
||||
* This parameter must point to valid memory.
|
||||
* @param events [IN] Event mask to be written.
|
||||
*
|
||||
* @retval #LOS_ERRNO_EVENT_SETBIT_INVALID Bit 25 of the event mask cannot be set to an event
|
||||
* because it is set to an error code.
|
||||
* @retval #LOS_ERRNO_EVENT_PTR_NULL Null pointer.
|
||||
* @retval #LOS_OK The event is successfully written.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_event.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_EventPoll | LOS_EventRead
|
||||
*/
|
||||
extern UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events);
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* @brief Clear the event of the eventCB by a specified eventMask.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to set the ID of an event that has a specified mask and of which the information is stored in
|
||||
* an event control block pointed to by eventCB to 0. eventCB must point to valid memory.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The value of events needs to be reversed when it is passed-in.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param eventCB [IN/OUT] Pointer to the event control block to be cleared.
|
||||
* @param eventMask [IN] Mask of the event to be cleared.
|
||||
*
|
||||
* @retval #LOS_ERRNO_EVENT_PTR_NULL Null pointer.
|
||||
* @retval #LOS_OK The event is successfully cleared.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_event.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_EventPoll | LOS_EventRead | LOS_EventWrite
|
||||
*/
|
||||
extern UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 eventMask);
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* @brief Destroy an event.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to Destroy an event.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific event should be a valid one.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param eventCB [IN/OUT] Pointer to the event control block to be Destroyed.
|
||||
*
|
||||
* @retval #LOS_ERRNO_EVENT_PTR_NULL Null pointer.
|
||||
* @retval #LOS_OK The event is successfully cleared.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_event.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_EventPoll | LOS_EventRead | LOS_EventWrite
|
||||
*/
|
||||
extern UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB);
|
||||
|
||||
extern UINT32 OsEventReadOnce(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeOut);
|
||||
extern UINT32 OsEventWriteOnce(PEVENT_CB_S eventCB, UINT32 events);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_EVENT_H */
|
||||
258
ohos/kernel/liteos_m/kernel/include/los_membox.h
Normal file
258
ohos/kernel/liteos_m/kernel/include/los_membox.h
Normal file
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_membox Static memory
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MEMBOX_H
|
||||
#define _LOS_MEMBOX_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OS_MEMBOX_NEXT(addr, blkSize) (LOS_MEMBOX_NODE *)(VOID *)((UINT8 *)(addr) + (blkSize))
|
||||
|
||||
#define OS_MEMBOX_NODE_HEAD_SIZE sizeof(LOS_MEMBOX_NODE)
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* Structure of a free node in a memory pool
|
||||
*/
|
||||
typedef struct tagMEMBOX_NODE {
|
||||
struct tagMEMBOX_NODE *pstNext; /**< Free node's pointer to the next node in a memory pool */
|
||||
} LOS_MEMBOX_NODE;
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* Memory pool information structure
|
||||
*/
|
||||
typedef struct LOS_MEMBOX_INFO {
|
||||
UINT32 uwBlkSize; /**< Block size */
|
||||
UINT32 uwBlkNum; /**< Block number */
|
||||
UINT32 uwBlkCnt; /**< The number of allocated blocks */
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
struct LOS_MEMBOX_INFO *nextMemBox; /**< Point to the next membox */
|
||||
#endif
|
||||
LOS_MEMBOX_NODE stFreeList; /**< Free list */
|
||||
} LOS_MEMBOX_INFO;
|
||||
|
||||
typedef LOS_MEMBOX_INFO OS_MEMBOX_S;
|
||||
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
UINT32 OsMemboxExcInfoGet(UINT32 memNumMax, MemInfoCB *memExcInfo);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* Memory pool alignment
|
||||
*/
|
||||
#define LOS_MEMBOX_ALIGNED(memAddr) (((UINTPTR)(memAddr) + sizeof(UINTPTR) - 1) & (~(sizeof(UINTPTR) - 1)))
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* Memory pool size
|
||||
*/
|
||||
#define LOS_MEMBOX_SIZE(blkSize, blkNum) \
|
||||
(sizeof(LOS_MEMBOX_INFO) + (LOS_MEMBOX_ALIGNED((blkSize) + OS_MEMBOX_NODE_HEAD_SIZE) * (blkNum)))
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* @brief Initialize a memory pool.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to initialize a memory pool.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The poolSize parameter value should match the following two conditions :
|
||||
* 1) Be less than or equal to the Memory pool size;
|
||||
* 2) Be greater than the size of LOS_MEMBOX_INFO.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Memory pool address.
|
||||
* @param poolSize [IN] Memory pool size.
|
||||
* @param blkSize [IN] Memory block size.
|
||||
*
|
||||
* @retval #LOS_NOK The memory pool fails to be initialized.
|
||||
* @retval #LOS_OK The memory pool is successfully initialized.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_membox.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemboxInit(VOID *pool, UINT32 poolSize, UINT32 blkSize);
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* @brief Request a memory block.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to request a memory block.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemboxInit.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Memory pool address.
|
||||
*
|
||||
* @retval #VOID* The request is accepted, and return a memory block address.
|
||||
* @retval #NULL The request fails.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_membox.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see LOS_MemboxFree
|
||||
*/
|
||||
extern VOID *LOS_MemboxAlloc(VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* @brief Free a memory block.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to free a memory block.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemboxInit.</li>
|
||||
* <li>The input box parameter must be allocated by LOS_MemboxAlloc.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Memory pool address.
|
||||
* @param box [IN] Memory block address.
|
||||
*
|
||||
* @retval #LOS_NOK This memory block fails to be freed.
|
||||
* @retval #LOS_OK This memory block is successfully freed.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_membox.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see LOS_MemboxAlloc
|
||||
*/
|
||||
extern UINT32 LOS_MemboxFree(VOID *pool, VOID *box);
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* @brief Clear a memory block.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to set the memory block value to be 0.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemboxInit.</li>
|
||||
* <li>The input box parameter must be allocated by LOS_MemboxAlloc.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Memory pool address.
|
||||
* @param box [IN] Memory block address.
|
||||
*
|
||||
* @retval VOID
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_membox.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID LOS_MemboxClr(VOID *pool, VOID *box);
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* @brief show membox info.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to show the memory pool info.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemboxInit.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Memory pool address.
|
||||
*
|
||||
* @retval VOID
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_membox.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID LOS_ShowBox(VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* @brief calculate membox information.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to calculate membox information.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>One parameter of this interface is a pointer, it should be a correct value, otherwise, the system may
|
||||
* be abnormal.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param boxMem [IN] Type #VOID* Pointer to the calculate membox.
|
||||
* @param maxBlk [OUT] Type #UINT32* Record membox max block.
|
||||
* @param blkCnt [OUT] Type #UINT32* Record membox block count already allocated.
|
||||
* @param blkSize [OUT] Type #UINT32* Record membox block size.
|
||||
*
|
||||
* @retval #LOS_OK The heap status calculate success.
|
||||
* @retval #LOS_NOK The membox status calculate with some error.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemAlloc | LOS_MemRealloc | LOS_MemFree
|
||||
*/
|
||||
extern UINT32 LOS_MemboxStatisticsGet(const VOID *boxMem, UINT32 *maxBlk, UINT32 *blkCnt, UINT32 *blkSize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_MEMBOX_H */
|
||||
570
ohos/kernel/liteos_m/kernel/include/los_memory.h
Normal file
570
ohos/kernel/liteos_m/kernel/include/los_memory.h
Normal file
@@ -0,0 +1,570 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_memory Dynamic memory
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MEMORY_H
|
||||
#define _LOS_MEMORY_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_list.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
UINT32 OsMemExcInfoGet(UINT32 memNumMax, MemInfoCB *memExcInfo);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* Starting address of the memory.
|
||||
*/
|
||||
#define OS_SYS_MEM_ADDR LOSCFG_SYS_HEAP_ADDR
|
||||
|
||||
#if (LOSCFG_MEM_LEAKCHECK == 1)
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Print function call stack information of all used nodes.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to print function call stack information of all used nodes.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Starting address of memory.
|
||||
*
|
||||
* @retval none.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_memory.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID LOS_MemUsedNodeShow(VOID *pool);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_MEM_MUL_POOL == 1)
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Deinitialize dynamic memory.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to deinitialize the dynamic memory of a doubly linked list.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Starting address of memory.
|
||||
*
|
||||
* @retval #OS_ERROR The dynamic memory fails to be deinitialized.
|
||||
* @retval #LOS_OK The dynamic memory is successfully deinitialized.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_memory.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemDeInit(VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Print information about all pools.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to print information about all pools.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @retval #UINT32 The pool number.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_memory.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemPoolList(VOID);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_MEM_FREE_BY_TASKID == 1)
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Free memory nodes allocated by the specified task.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to free all memory nodes allocated by the specified task.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] The memory pool address.
|
||||
* @param taskID [IN] The task ID and all memory nodes allocated by this task will be freed.
|
||||
*
|
||||
* @retval #OS_ERROR The memory pool is NULL or the task ID is invalid.
|
||||
* @retval #LOS_OK All memory nodes allocated by this task are freed successfully.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_memory.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemFreeByTaskID(VOID *pool, UINT32 taskID);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_MEM_MUL_REGIONS == 1)
|
||||
typedef struct {
|
||||
VOID *startAddress;
|
||||
UINT32 length;
|
||||
} LosMemRegion;
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Initialize multiple non-continuous memory regions.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to initialize multiple non-continuous memory regions. If the starting address of a pool is
|
||||
* specified, the memory regions will be linked to the pool as free nodes. Otherwise, the first memory region will
|
||||
* be initialized as a * new pool, and the rest regions will be linked as free nodes to the new pool.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>If the starting address of a memory pool is specified, the start address of the non-continuous memory regions should be
|
||||
* greater than the end address of the memory pool.</li>
|
||||
* <li>The multiple non-continuous memory regions shouldn't conflict with each other.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] The memory pool address. If NULL is specified, the start address of first memory region will be
|
||||
* initialized as the memory pool address. If not NULL, it should be a valid address of a memory pool.
|
||||
* @param memRegions [IN] The LosMemRegion array that contains multiple non-continuous memory regions. The start address
|
||||
* of the memory regions are placed in ascending order.
|
||||
* @param memRegionCount [IN] The count of non-continuous memory regions, and it should be the length of the LosMemRegion array.
|
||||
*
|
||||
* @retval #LOS_NOK The multiple non-continuous memory regions fails to be initialized.
|
||||
* @retval #LOS_OK The multiple non-continuous memory regions is initialized successfully.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_memory.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemRegionsAdd(VOID *pool, const LosMemRegion * const memRegions, UINT32 memRegionCount);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* Memory pool extern information structure
|
||||
*/
|
||||
typedef struct {
|
||||
UINT32 totalUsedSize;
|
||||
UINT32 totalFreeSize;
|
||||
UINT32 maxFreeNodeSize;
|
||||
UINT32 usedNodeNum;
|
||||
UINT32 freeNodeNum;
|
||||
#if (LOSCFG_MEM_WATERLINE == 1)
|
||||
UINT32 usageWaterLine;
|
||||
#endif
|
||||
} LOS_MEM_POOL_STATUS;
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Initialize dynamic memory.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to initialize the dynamic memory of a doubly linked list.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The size parameter value should match the following two conditions :
|
||||
* 1) Be less than or equal to the Memory pool size;
|
||||
* 2) Be greater than the size of OS_MEM_MIN_POOL_SIZE.</li>
|
||||
* <li>Call this API when dynamic memory needs to be initialized during the startup of Huawei LiteOS.</li>
|
||||
* <li>The parameter input must be four byte-aligned.</li>
|
||||
* <li>The init area [pool, pool + size] should not conflict with other pools.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Starting address of memory.
|
||||
* @param size [IN] Memory size.
|
||||
*
|
||||
* @retval #OS_ERROR The dynamic memory fails to be initialized.
|
||||
* @retval #LOS_OK The dynamic memory is successfully initialized.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_memory.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemInit(VOID *pool, UINT32 size);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Allocate dynamic memory.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to allocate a memory block of which the size is specified.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* <li>The size of the input parameter size can not be greater than the memory pool size that specified at the second
|
||||
* input parameter of LOS_MemInit.</li>
|
||||
* <li>The size of the input parameter size must be four byte-aligned.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
|
||||
* @param size [IN] Size of the memory block to be allocated (unit: byte).
|
||||
*
|
||||
* @retval #NULL The memory fails to be allocated.
|
||||
* @retval #VOID* The memory is successfully allocated with the starting address of the allocated memory block
|
||||
* returned.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemRealloc | LOS_MemAllocAlign | LOS_MemFree
|
||||
*/
|
||||
extern VOID *LOS_MemAlloc(VOID *pool, UINT32 size);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Free dynamic memory.
|
||||
*
|
||||
* @par Description:
|
||||
* <li>This API is used to free specified dynamic memory that has been allocated.</li>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* <li>The input ptr parameter must be allocated by LOS_MemAlloc or LOS_MemAllocAlign or LOS_MemRealloc.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the dynamic memory block to be freed.
|
||||
* @param ptr [IN] Starting address of the memory block to be freed.
|
||||
*
|
||||
* @retval #LOS_NOK The memory block fails to be freed because the starting address of the memory block is
|
||||
* invalid, or the memory overwriting occurs.
|
||||
* @retval #LOS_OK The memory block is successfully freed.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemAlloc | LOS_MemRealloc | LOS_MemAllocAlign
|
||||
*/
|
||||
extern UINT32 LOS_MemFree(VOID *pool, VOID *ptr);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Re-allocate a memory block.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to allocate a new memory block of which the size is specified by size if the original memory
|
||||
* block size is insufficient. The new memory block will copy the data in the original memory block of which the
|
||||
* address is specified by ptr. The size of the new memory block determines the maximum size of data to be copied.
|
||||
* After the new memory block is created, the original one is freed.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* <li>The input ptr parameter must be allocated by LOS_MemAlloc or LOS_MemAllocAlign.</li>
|
||||
* <li>The size of the input parameter size can not be greater than the memory pool size that specified at the second
|
||||
* input parameter of LOS_MemInit.</li>
|
||||
* <li>The size of the input parameter size must be aligned as follows: 1) if the ptr is allocated by LOS_MemAlloc,
|
||||
* it must be four byte-aligned; 2) if the ptr is allocated by LOS_MemAllocAlign, it must be aligned with the size of
|
||||
* the input parameter boundary of LOS_MemAllocAlign.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the original and new memory blocks.
|
||||
* @param ptr [IN] Address of the original memory block.
|
||||
* @param size [IN] Size of the new memory block.
|
||||
*
|
||||
* @retval #NULL The memory fails to be re-allocated.
|
||||
* @retval #VOID* The memory is successfully re-allocated with the starting address of the new memory block returned.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemAlloc | LOS_MemAllocAlign | LOS_MemFree
|
||||
*/
|
||||
extern VOID *LOS_MemRealloc(VOID *pool, VOID *ptr, UINT32 size);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Allocate aligned memory.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to allocate memory blocks of specified size and of which the starting addresses are aligned on
|
||||
* a specified boundary.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* <li>The size of the input parameter size can not be greater than the memory pool size that specified at the second
|
||||
* input parameter of LOS_MemInit.</li>
|
||||
* <li>The alignment parameter value must be a power of 2 with the minimum value being 4.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory blocks to be allocated.
|
||||
* @param size [IN] Size of the memory to be allocated.
|
||||
* @param boundary [IN] Boundary on which the memory is aligned.
|
||||
*
|
||||
* @retval #NULL The memory fails to be allocated.
|
||||
* @retval #VOID* The memory is successfully allocated with the starting address of the allocated memory returned.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemAlloc | LOS_MemRealloc | LOS_MemFree
|
||||
*/
|
||||
extern VOID *LOS_MemAllocAlign(VOID *pool, UINT32 size, UINT32 boundary);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Get the size of memory pool's size.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get the size of memory pool' total size.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] A pointer pointed to the memory pool.
|
||||
*
|
||||
* @retval #LOS_NOK The incoming parameter pool is NULL.
|
||||
* @retval #UINT32 The size of the memory pool.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemPoolSizeGet(const VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Get the size of memory totally used.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get the size of memory totally used in memory pool.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] A pointer pointed to the memory pool.
|
||||
*
|
||||
* @retval #LOS_NOK The incoming parameter pool is NULL.
|
||||
* @retval #UINT32 The size of the memory pool used.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemTotalUsedGet(VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Get the information of memory pool.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get the information of memory pool.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] A pointer pointed to the memory pool.
|
||||
* @param poolStatus [IN] A pointer for storage the pool status
|
||||
*
|
||||
* @retval #LOS_NOK The incoming parameter pool is NULL or invalid.
|
||||
* @retval #LOS_OK Success to get memory information.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Get the number of free node in every size.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get the number of free node in every size.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] A pointer pointed to the memory pool.
|
||||
*
|
||||
* @retval #LOS_NOK The incoming parameter pool is NULL.
|
||||
* @retval #UINT32 The address of the last used node that casts to UINT32.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemFreeNodeShow(VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Check the memory pool integrity.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to check the memory pool integrity.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* <li>LOS_MemIntegrityCheck will be called by malloc function when the macro of LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK
|
||||
* is defined in LiteOS.</li>
|
||||
* <li>LOS_MemIntegrityCheck function can be called by user anytime.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] A pointer pointed to the memory pool.
|
||||
*
|
||||
* @retval #LOS_NOK The memory pool (pool) is impaired.
|
||||
* @retval #LOS_OK The memory pool (pool) is integrated.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemIntegrityCheck(const VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Enable memory pool to support no internal lock during using interfaces.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to enable memory pool to support no internal lock during using interfaces,</li>
|
||||
* <li>such as LOS_MemAlloc/LOS_MemAllocAlign/LOS_MemRealloc/LOS_MemFree and so on.
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The memory pool does not support multi-threaded concurrent application scenarios.
|
||||
* <li>If you want to use this function, you need to call this interface before the memory
|
||||
* pool is used, it cannot be called during the trial period.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Starting address of memory.
|
||||
*
|
||||
* @retval node.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_memory.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
|
||||
/* Supposing a Second Level Index: SLI = 3. */
|
||||
#define OS_MEM_SLI 3
|
||||
/* Giving 1 free list for each small bucket: 4, 8, 12, up to 124. */
|
||||
#define OS_MEM_SMALL_BUCKET_COUNT 31
|
||||
#define OS_MEM_SMALL_BUCKET_MAX_SIZE 128
|
||||
/* Giving 2^OS_MEM_SLI free lists for each large bucket. */
|
||||
#define OS_MEM_LARGE_BUCKET_COUNT 24
|
||||
/* OS_MEM_SMALL_BUCKET_MAX_SIZE to the power of 2 is 7. */
|
||||
#define OS_MEM_LARGE_START_BUCKET 7
|
||||
|
||||
/* The count of free list. */
|
||||
#define OS_MEM_FREE_LIST_COUNT (OS_MEM_SMALL_BUCKET_COUNT + (OS_MEM_LARGE_BUCKET_COUNT << OS_MEM_SLI))
|
||||
/* The bitmap is used to indicate whether the free list is empty, 1: not empty, 0: empty. */
|
||||
#define OS_MEM_BITMAP_WORDS ((OS_MEM_FREE_LIST_COUNT >> 5) + 1)
|
||||
|
||||
struct OsMemNodeHead {
|
||||
#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == 1)
|
||||
UINT32 magic;
|
||||
#endif
|
||||
#if (LOSCFG_MEM_LEAKCHECK == 1)
|
||||
UINTPTR linkReg[LOSCFG_MEM_RECORD_LR_CNT];
|
||||
#endif
|
||||
union {
|
||||
struct OsMemNodeHead *prev; /* The prev is used for current node points to the previous node */
|
||||
struct OsMemNodeHead *next; /* The next is used for sentinel node points to the expand node */
|
||||
} ptr;
|
||||
#if (LOSCFG_TASK_MEM_USED == 1)
|
||||
UINT32 taskID;
|
||||
UINT32 sizeAndFlag;
|
||||
#elif (LOSCFG_MEM_FREE_BY_TASKID == 1)
|
||||
UINT32 taskID : 6;
|
||||
UINT32 sizeAndFlag : 26;
|
||||
#else
|
||||
UINT32 sizeAndFlag;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct OsMemFreeNodeHead {
|
||||
struct OsMemNodeHead header;
|
||||
struct OsMemFreeNodeHead *prev;
|
||||
struct OsMemFreeNodeHead *next;
|
||||
};
|
||||
|
||||
struct OsMemPoolInfo {
|
||||
VOID *pool;
|
||||
UINT32 totalSize;
|
||||
UINT32 attr;
|
||||
#if (LOSCFG_MEM_WATERLINE == 1)
|
||||
UINT32 waterLine; /* Maximum usage size in a memory pool */
|
||||
UINT32 curUsedSize; /* Current usage size in a memory pool */
|
||||
#endif
|
||||
#if (LOSCFG_MEM_MUL_REGIONS == 1)
|
||||
UINT32 totalGapSize;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct OsMemPoolHead {
|
||||
struct OsMemPoolInfo info;
|
||||
UINT32 freeListBitmap[OS_MEM_BITMAP_WORDS];
|
||||
struct OsMemFreeNodeHead *freeList[OS_MEM_FREE_LIST_COUNT];
|
||||
#if (LOSCFG_MEM_MUL_POOL == 1)
|
||||
VOID *nextPool;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern VOID LOS_MemUnlockEnable(VOID *pool);
|
||||
|
||||
extern UINT32 OsMemSystemInit(VOID);
|
||||
extern VOID OsTaskMemUsed(VOID *pool, UINT32 *tskMemInfoBuf, UINT32 tskMemInfoCnt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_MEMORY_H */
|
||||
369
ohos/kernel/liteos_m/kernel/include/los_mux.h
Normal file
369
ohos/kernel/liteos_m/kernel/include/los_mux.h
Normal file
@@ -0,0 +1,369 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_mux Mutex
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MUX_H
|
||||
#define _LOS_MUX_H
|
||||
|
||||
#include "los_task.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: The memory request fails.
|
||||
*
|
||||
* Value: 0x02001d00
|
||||
*
|
||||
* Solution: Decrease the number of mutexes defined by LOSCFG_BASE_IPC_MUX_LIMIT.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: The mutex is not usable.
|
||||
*
|
||||
* Value: 0x02001d01
|
||||
*
|
||||
* Solution: Check whether the mutex ID and the mutex state are applicable for the current operation.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: Null pointer.
|
||||
*
|
||||
* Value: 0x02001d02
|
||||
*
|
||||
* Solution: Check whether the input parameter is usable.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: No mutex is available and the mutex request fails.
|
||||
*
|
||||
* Value: 0x02001d03
|
||||
*
|
||||
* Solution: Increase the number of mutexes defined by LOSCFG_BASE_IPC_MUX_LIMIT.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_ALL_BUSY LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: The mutex fails to be locked in non-blocking mode because it is locked by another thread.
|
||||
*
|
||||
* Value: 0x02001d04
|
||||
*
|
||||
* Solution: Lock the mutex after it is unlocked by the thread that owns it, or set a waiting time.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: The mutex is being locked during an interrupt.
|
||||
*
|
||||
* Value: 0x02001d05
|
||||
*
|
||||
* Solution: Check whether the mutex is being locked during an interrupt.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_IN_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: A thread locks a mutex after waiting for the mutex to be unlocked by another thread
|
||||
* when the task scheduling is disabled.
|
||||
*
|
||||
* Value: 0x02001d06
|
||||
*
|
||||
* Solution: Check whether the task scheduling is disabled, or set timeout to 0, which means that the
|
||||
* thread will not wait for the mutex to become available.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_PEND_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x06)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: The mutex locking times out.
|
||||
*
|
||||
* Value: 0x02001d07
|
||||
*
|
||||
* Solution: Increase the waiting time or set the waiting time to LOS_WAIT_FOREVER (forever-blocking mode).
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x07)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
*
|
||||
* Value: 0x02001d08
|
||||
* Not in use temporarily.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_OVERFLOW LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x08)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: The mutex to be deleted is being locked.
|
||||
*
|
||||
* Value: 0x02001d09
|
||||
*
|
||||
* Solution: Delete the mutex after it is unlocked.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_PENDED LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x09)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
*
|
||||
* Value: 0x02001d0A
|
||||
* Not in use temporarily.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_GET_COUNT_ERR LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0A)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
*
|
||||
* Value: 0x02001d0B
|
||||
* Not in use temporarily.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_REG_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0B)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
*
|
||||
* Mutex error code: LOS_ERRNO_MUX_MAXNUM_ZERO is zero.
|
||||
* Value: 0x02001d0C
|
||||
*
|
||||
* Solution: LOS_ERRNO_MUX_MAXNUM_ZERO should not be zero.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_MAXNUM_ZERO LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0C)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
*
|
||||
* Mutex error code: The API is called in a system-level task, which is forbidden.
|
||||
* Value: 0x02001d0D
|
||||
*
|
||||
* Solution: Do not call the API in system-level tasks.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_PEND_IN_SYSTEM_TASK LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0D)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* @brief Create a mutex.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create a mutex. A mutex handle is assigned to muxHandle when the mutex is created successfully.
|
||||
* Return LOS_OK on creating successful, return specific error code otherwise.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The total number of mutexes is pre-configured. If there are no available mutexes, the mutex creation fails.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param muxHandle [OUT] Handle pointer of the successfully created mutex. The value of handle should be in
|
||||
* [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
|
||||
*
|
||||
* @retval #LOS_ERRNO_MUX_PTR_NULL The muxHandle pointer is NULL.
|
||||
* @retval #LOS_ERRNO_MUX_ALL_BUSY No available mutex.
|
||||
* @retval #LOS_OK The mutex is successfully created.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MuxDelete
|
||||
*/
|
||||
extern UINT32 LOS_MuxCreate(UINT32 *muxHandle);
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* @brief Delete a mutex.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete a specified mutex. Return LOS_OK on deleting successfully, return specific error code
|
||||
* otherwise.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific mutex should be created firstly.</li>
|
||||
* <li>The mutex can be deleted successfully only if no other tasks pend on it.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param muxHandle [IN] Handle of the mutex to be deleted. The value of handle should be in
|
||||
* [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
|
||||
*
|
||||
* @retval #LOS_ERRNO_MUX_INVALID Invalid handle or mutex in use.
|
||||
* @retval #LOS_ERRNO_MUX_PENDED Tasks pended on this mutex.
|
||||
* @retval #LOS_OK The mutex is successfully deleted.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MuxCreate
|
||||
*/
|
||||
extern UINT32 LOS_MuxDelete(UINT32 muxHandle);
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* @brief Wait to lock a mutex.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to wait for a specified period of time to lock a mutex.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific mutex should be created firstly.</li>
|
||||
* <li>The function fails if the mutex that is waited on is already locked by another thread when the task scheduling
|
||||
* is disabled.</li>
|
||||
* <li>Do not wait on a mutex during an interrupt.</li>
|
||||
* <li>The priority inheritance protocol is supported. If a higher-priority thread is waiting on a mutex, it changes
|
||||
* the priority of the thread that owns the mutex to avoid priority inversion.</li>
|
||||
* <li>A recursive mutex can be locked more than once by the same thread.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param muxHandle [IN] Handle of the mutex to be waited on. The value of handle should be
|
||||
* in [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
|
||||
* @param timeout [IN] Waiting time. The value range is [0, LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_ERRNO_MUX_INVALID The mutex state (for example, the mutex does not exist or is not in use)
|
||||
* is not applicable for the current operation.
|
||||
* @retval #LOS_ERRNO_MUX_UNAVAILABLE The mutex fails to be locked because it is locked by another thread and
|
||||
* a period of time is not set for waiting for the mutex to become available.
|
||||
* @retval #LOS_ERRNO_MUX_IN_INTERR The mutex is being locked during an interrupt.
|
||||
* @retval #LOS_ERRNO_MUX_PEND_IN_LOCK The mutex is waited on when the task scheduling is disabled.
|
||||
* @retval #LOS_ERRNO_MUX_TIMEOUT The mutex waiting times out.
|
||||
* @retval #LOS_OK The mutex is successfully locked.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MuxCreate | LOS_MuxPost
|
||||
*/
|
||||
extern UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout, UINT32 lr);
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* @brief Release a mutex.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to release a specified mutex.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific mutex should be created firstly.</li>
|
||||
* <li>Do not release a mutex during an interrupt.</li>
|
||||
* <li>If a recursive mutex is locked for many times, it must be unlocked for the same times to be released.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param muxHandle [IN] Handle of the mutex to be released. The value of handle should be in
|
||||
* [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
|
||||
*
|
||||
* @retval #LOS_ERRNO_MUX_INVALID The mutex state (for example, the mutex does not exist or is not in use
|
||||
* or owned by other thread) is not applicable for the current operation.
|
||||
* @retval #LOS_ERRNO_MUX_IN_INTERR The mutex is being released during an interrupt.
|
||||
* @retval #LOS_OK The mutex is successfully released.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MuxCreate | LOS_MuxPend
|
||||
*/
|
||||
extern UINT32 LOS_MuxPost(UINT32 muxHandle);
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex object.
|
||||
*/
|
||||
typedef struct {
|
||||
UINT8 muxStat; /**< State OS_MUX_UNUSED,OS_MUX_USED */
|
||||
UINT16 muxCount; /**< Times of locking a mutex */
|
||||
UINT32 muxID; /**< Handle ID */
|
||||
LOS_DL_LIST muxList; /**< Mutex linked list */
|
||||
LosTaskCB *owner; /**< The current thread that is locking a mutex */
|
||||
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
|
||||
UINTPTR createInfo; /**< Return address of the caller */
|
||||
#endif
|
||||
UINT16 priority; /**< Priority of the thread that is locking a mutex */
|
||||
} LosMuxCB;
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex state: not in use.
|
||||
*/
|
||||
#define OS_MUX_UNUSED 0
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex state: in use.
|
||||
*/
|
||||
#define OS_MUX_USED 1
|
||||
|
||||
extern LosMuxCB *g_allMux;
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Obtain the pointer to a mutex object of the mutex that has a specified handle.
|
||||
*/
|
||||
#define GET_MUX(muxid) (((LosMuxCB *)g_allMux) + (muxid))
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* @brief Initializes the mutex.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initializes the mutex.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval UINT32 Initialization result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MuxDelete
|
||||
*/
|
||||
extern UINT32 OsMuxInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Obtain the pointer to the linked list in the mutex pointed to by a specified pointer.
|
||||
*/
|
||||
#define GET_MUX_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosMuxCB, muxList)
|
||||
|
||||
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
|
||||
STATIC INLINE VOID OsSetMutexCreateInfo(LosMuxCB *mux, UINTPTR val)
|
||||
{
|
||||
mux->createInfo = val;
|
||||
}
|
||||
#endif /* LOSCFG_MUTEX_CREATE_TRACE == 1 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_MUX_H */
|
||||
985
ohos/kernel/liteos_m/kernel/include/los_queue.h
Normal file
985
ohos/kernel/liteos_m/kernel/include/los_queue.h
Normal file
@@ -0,0 +1,985 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_queue Queue
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_QUEUE_H
|
||||
#define _LOS_QUEUE_H
|
||||
|
||||
#include "los_list.h"
|
||||
#include "los_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The maximum number of queue resources is configured to 0.
|
||||
*
|
||||
* Value: 0x02000600
|
||||
*
|
||||
* Solution: Configure the maximum number of queue resources to be greater than 0. If queue modules are not used,
|
||||
* set the configuration item for the tailoring of the maximum number of queue resources to NO.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_MAXNUM_ZERO LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The queue block memory fails to be initialized.
|
||||
*
|
||||
* Value: 0x02000601
|
||||
*
|
||||
* Solution: Allocate the queue block bigger memory partition, or decrease the maximum number of queue resources.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The memory for queue creation fails to be requested.
|
||||
*
|
||||
* Value: 0x02000602
|
||||
*
|
||||
* Solution: Allocate more memory for queue creation, or decrease the queue length and the number of nodes
|
||||
* in the queue to be created.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_CREATE_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The size of the biggest message in the created queue is too big.
|
||||
*
|
||||
* Value: 0x02000603
|
||||
*
|
||||
* Solution: Change the size of the biggest message in the created queue.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_SIZE_TOO_BIG LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The upper limit of the number of created queues is exceeded.
|
||||
*
|
||||
* Value: 0x02000604
|
||||
*
|
||||
* Solution: Increase the configured number of resources for queues.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: Invalid queue.
|
||||
*
|
||||
* Value: 0x02000605
|
||||
*
|
||||
* Solution: Ensure that the passed-in queue ID is valid.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_NOT_FOUND LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The task is forbidden to be blocked on a queue when the task is locked.
|
||||
*
|
||||
* Value: 0x02000606
|
||||
*
|
||||
* Solution: Unlock the task before using a queue.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_PEND_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x06)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The time set for waiting to processing the queue expires.
|
||||
*
|
||||
* Value: 0x02000607
|
||||
*
|
||||
* Solution: Check whether the expiry time setting is appropriate.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x07)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The queue that blocks a task cannot be deleted.
|
||||
*
|
||||
* Value: 0x02000608
|
||||
*
|
||||
* Solution: Enable the task to obtain resources rather than be blocked on the queue.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_IN_TSKUSE LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x08)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The queue cannot be written during an interrupt when the time for waiting to
|
||||
* processing the queue expires.
|
||||
*
|
||||
* Value: 0x02000609
|
||||
*
|
||||
* Solution: Set the expiry time to the never-waiting mode, or use asynchronous queues.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x09)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The queue is not created.
|
||||
*
|
||||
* Value: 0x0200060a
|
||||
*
|
||||
* Solution: Check whether the passed-in queue handle value is valid.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_NOT_CREATE LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0a)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: Queue reading and writing are not synchronous.
|
||||
*
|
||||
* Value: 0x0200060b
|
||||
*
|
||||
* Solution: Synchronize queue reading with queue writing.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_IN_TSKWRITE LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0b)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: Parameters passed in during queue creation are null pointers.
|
||||
*
|
||||
* Value: 0x0200060c
|
||||
*
|
||||
* Solution: Ensure the passed-in parameters are not null pointers.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_CREAT_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0c)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The queue length or message node size passed in during queue creation is 0.
|
||||
*
|
||||
* Value: 0x0200060d
|
||||
*
|
||||
* Solution: Pass in correct queue length and message node size.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_PARA_ISZERO LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0d)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The handle of the queue is invalid.
|
||||
*
|
||||
* Value: 0x0200060e
|
||||
*
|
||||
* Solution: Check whether the passed-in queue handle value is valid.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0e)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The pointer passed in during queue reading is null.
|
||||
*
|
||||
* Value: 0x0200060f
|
||||
*
|
||||
* Solution: Check whether the passed-in pointer is null.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_READ_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0f)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The buffer size passed in during queue reading is 0.
|
||||
*
|
||||
* Value: 0x02000610
|
||||
*
|
||||
* Solution: Pass in a correct buffer size.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_READSIZE_ISZERO LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x10)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The pointer passed in during queue writing is null.
|
||||
*
|
||||
* Value: 0x02000612
|
||||
*
|
||||
* Solution: Check whether the passed-in pointer is null.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_WRITE_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x12)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The buffer size passed in during queue writing is 0.
|
||||
*
|
||||
* Value: 0x02000613
|
||||
*
|
||||
* Solution: Pass in a correct buffer size.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_WRITESIZE_ISZERO LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x13)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The buffer size passed in during queue writing is bigger than the queue size.
|
||||
*
|
||||
* Value: 0x02000615
|
||||
*
|
||||
* Solution: Decrease the buffer size, or use a queue in which nodes are bigger.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x15)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: No free node is available during queue writing.
|
||||
*
|
||||
* Value: 0x02000616
|
||||
*
|
||||
* Solution: Ensure that free nodes are available before queue writing.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_ISFULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x16)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The pointer passed in when the queue information is being obtained is null.
|
||||
*
|
||||
* Value: 0x02000617
|
||||
*
|
||||
* Solution: Check whether the passed-in pointer is null.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x17)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The queue cannot be read during an interrupt
|
||||
* when the time for waiting to processing the queue expires.
|
||||
*
|
||||
* Value: 0x02000618
|
||||
*
|
||||
* Solution: Set the expiry time to the never-waiting mode, or use asynchronous queues.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_READ_IN_INTERRUPT LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x18)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The handle of the queue passed-in when the memory for the queue is being freed is invalid.
|
||||
*
|
||||
* Value: 0x02000619
|
||||
*
|
||||
* Solution: Check whether the passed-in queue handle value is valid.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_MAIL_HANDLE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x19)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The pointer to the memory to be freed is null.
|
||||
*
|
||||
* Value: 0x0200061a
|
||||
*
|
||||
* Solution: Check whether the passed-in pointer is null.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_MAIL_PTR_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x1a)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The memory for the queue fails to be freed.
|
||||
*
|
||||
* Value: 0x0200061b
|
||||
*
|
||||
* Solution: Pass in correct input parameters.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_MAIL_FREE_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x1b)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: No resource is in the queue that is being read when the
|
||||
* time for waiting to processing the queue expires.
|
||||
*
|
||||
* Value: 0x0200061d
|
||||
*
|
||||
* Solution: Ensure that the queue contains messages when it is being read.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_ISEMPTY LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x1d)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The buffer size passed in during queue reading is smaller than the queue size.
|
||||
*
|
||||
* Value: 0x0200061f
|
||||
*
|
||||
* Solution: Increase the buffer size, or use a queue in which nodes are smaller.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x1f)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The buffer size passed in during queue reading or writing is bigger than the biggest size.
|
||||
*
|
||||
* Value: 0x02000620
|
||||
*
|
||||
* Solution: Decrease the buffer size.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_BUFFER_SIZE_TOO_BIG LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x20)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* In struct QueueInfo, the length of each waitReadTask/waitWriteTask/waitMemTask array depends on the value
|
||||
* LOSCFG_BASE_CORE_TSK_LIMIT. The type of each array element is UINT32, which means that each element could
|
||||
* mark 32(=2^5) tasks.
|
||||
* OS_WAIT_TASK_ARRAY_LEN is used to calculate the array length.
|
||||
* OS_WAIT_TASK_ID_TO_ARRAY_IDX is used to transfer task ID to array index.
|
||||
* OS_WAIT_TASK_ARRAY_ELEMENT_MASK is the mask for each element.
|
||||
*/
|
||||
#define OS_WAIT_TASK_ARRAY_LEN ((LOSCFG_BASE_CORE_TSK_LIMIT >> 5) + 1)
|
||||
#define OS_WAIT_TASK_ID_TO_ARRAY_IDX(taskID) (taskID >> 5)
|
||||
#define OS_WAIT_TASK_ARRAY_ELEMENT_MASK (31)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Structure of the block for queue information query
|
||||
*/
|
||||
typedef struct tagQueueInfo {
|
||||
UINT32 queueID; /**< Queue ID */
|
||||
UINT16 queueLen; /**< Queue length */
|
||||
UINT16 queueSize; /**< Node size */
|
||||
UINT16 queueHead; /**< Node head */
|
||||
UINT16 queueTail; /**< Node tail */
|
||||
UINT16 writableCnt; /**< Count of writable resources */
|
||||
UINT16 readableCnt; /**< Count of readable resources */
|
||||
UINT32 waitReadTask[OS_WAIT_TASK_ARRAY_LEN]; /**< Resource reading task*/
|
||||
UINT32 waitWriteTask[OS_WAIT_TASK_ARRAY_LEN]; /**< Resource writing task */
|
||||
UINT32 waitMemTask[OS_WAIT_TASK_ARRAY_LEN]; /**< Memory task */
|
||||
} QUEUE_INFO_S;
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Create a message queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create a message queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>There are LOSCFG_BASE_IPC_QUEUE_LIMIT queues available, change it's value when necessary.</li>
|
||||
* </ul>
|
||||
* @param queueName [IN] Message queue name.
|
||||
* @param len [IN] Queue length. The value range is [1,0xffff].
|
||||
* @param queueID [OUT] ID of the queue control structure that is successfully created.
|
||||
* @param flags [IN] Queue mode. Reserved parameter, not used for now.
|
||||
* @param maxMsgSize [IN] Node size. The value range is [1,0xffff-4].
|
||||
*
|
||||
* @retval #LOS_OK The message queue is successfully created.
|
||||
* @retval #LOS_ERRNO_QUEUE_CB_UNAVAILABLE The upper limit of the number of created queues is exceeded.
|
||||
* @retval #LOS_ERRNO_QUEUE_CREATE_NO_MEMORY Insufficient memory for queue creation.
|
||||
* @retval #LOS_ERRNO_QUEUE_CREAT_PTR_NULL Null pointer, queueID is NULL.
|
||||
* @retval #LOS_ERRNO_QUEUE_PARA_ISZERO The queue length or message node size passed in during queue
|
||||
* creation is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_SIZE_TOO_BIG The parameter maxMsgSize is larger than 0xffff - 4.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueDelete
|
||||
*/
|
||||
extern UINT32 LOS_QueueCreate(const CHAR *queueName,
|
||||
UINT16 len,
|
||||
UINT32 *queueID,
|
||||
UINT32 flags,
|
||||
UINT16 maxMsgSize);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Create a static message queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create a message queue using static memory for data storage.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>There are LOSCFG_BASE_IPC_QUEUE_LIMIT queues available, change it's value when necessary.</li>
|
||||
* </ul>
|
||||
* @param queueName [IN] Message queue name.
|
||||
* @param len [IN] Queue length. The value range is [1,0xffff].
|
||||
* @param queueID [OUT] ID of the queue control structure that is successfully created.
|
||||
* @param staticMem [IN] Pointer to a static memory for the message queue data.
|
||||
* @param flags [IN] Queue mode. Reserved parameter, not used for now.
|
||||
* @param maxMsgSize [IN] Node size. The value range is [1,0xffff-4].
|
||||
*
|
||||
* @retval #LOS_OK The message queue is successfully created.
|
||||
* @retval #LOS_ERRNO_QUEUE_CB_UNAVAILABLE The upper limit of the number of created queues is exceeded.
|
||||
* @retval #LOS_ERRNO_QUEUE_CREATE_NO_MEMORY Insufficient memory for queue creation.
|
||||
* @retval #LOS_ERRNO_QUEUE_CREAT_PTR_NULL Null pointer, queueID is NULL.
|
||||
* @retval #LOS_ERRNO_QUEUE_PARA_ISZERO The queue length or message node size passed in during queue
|
||||
* creation is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_SIZE_TOO_BIG The parameter maxMsgSize is larger than 0xffff - 4.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueDelete
|
||||
*/
|
||||
extern UINT32 LOS_QueueCreateStatic(const CHAR *queueName,
|
||||
UINT16 len,
|
||||
UINT32 *queueID,
|
||||
UINT8 *staticMem,
|
||||
UINT32 flags,
|
||||
UINT16 maxMsgSize);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Read a queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to read data in a specified queue, and store the obtained data to the address specified
|
||||
* by bufferAddr. The address and the size of the data to be read are defined by users.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific queue should be created firstly.</li>
|
||||
* <li>Queue reading adopts the fist in first out (FIFO) mode. The data that is first stored in the queue is read
|
||||
* first.</li>
|
||||
* <li>bufferAddr stores the obtained data.</li>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param bufferAddr [OUT] Starting address that stores the obtained data. The starting address must not be
|
||||
* null.
|
||||
* @param bufferSize [IN/OUT] Where to maintain the buffer expected-size before read, and the real-size after read.
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_OK The queue is successfully read.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The handle of the queue that is being read is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_READ_PTR_NULL The pointer passed in during queue reading is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_READSIZE_ISZERO The buffer size passed in during queue reading is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_READ_IN_INTERRUPT The queue cannot be read during an interrupt when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue to be read is not created.
|
||||
* @retval #LOS_ERRNO_QUEUE_ISEMPTY No resource is in the queue that is being read when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is
|
||||
* locked.
|
||||
* @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL The buffer size passed in during queue reading is less than
|
||||
* the queue size.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueWriteCopy | LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueReadCopy(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 *bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Write data into a queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to write the data of the size specified by bufferSize and stored at the address specified by
|
||||
* bufferAddr into a queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific queue should be created firstly.</li>
|
||||
* <li>Do not read or write a queue in unblocking modes such as interrupt.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The data to be written is of the size specified by bufferSize and is stored at the address specified by
|
||||
* BufferAddr.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param bufferAddr [IN] Starting address that stores the data to be written.The starting address must
|
||||
* not be null.
|
||||
* @param bufferSize [IN] Passed-in buffer size. The value range is [1,USHRT_MAX - sizeof(UINT32)].
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_OK The data is successfully written into the queue.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The queue handle passed in during queue writing is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_PTR_NULL The pointer passed in during queue writing is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITESIZE_ISZERO The buffer size passed in during queue writing is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT The queue cannot be written during an interrupt when the time
|
||||
* for waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue into which the data is written is not created.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG The buffer size passed in during queue writing is bigger than
|
||||
* the queue size.
|
||||
* @retval #LOS_ERRNO_QUEUE_ISFULL No free node is available during queue writing.
|
||||
* @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when
|
||||
* the task is locked.
|
||||
* @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueReadCopy | LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueWriteCopy(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Read a queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to read the address of data in a specified queue, and store it to the address specified by
|
||||
* bufferAddr.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific queue should be created firstly.</li>
|
||||
* <li>Queue reading adopts the fist in first out (FIFO) mode. The data that is first stored in the queue is
|
||||
* read first.</li>
|
||||
* <li>bufferAddr stores the obtained data address.</li>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* <li>The bufferSize is not really used in LOS_QueueRead, because the interface is only used to
|
||||
* obtain the address of data.</li>
|
||||
* <li>The buffer which the bufferAddr pointing to must be greater than or equal to 4 bytes.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param bufferAddr [OUT] Starting address that stores the obtained data. The starting address must
|
||||
* not be null.
|
||||
* @param bufferSize [IN] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff].
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_OK The queue is successfully read.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The handle of the queue that is being read is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_READ_PTR_NULL The pointer passed in during queue reading is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_READSIZE_ISZERO The buffer size passed in during queue reading is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_READ_IN_INTERRUPT The queue cannot be read during an interrupt when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue to be read is not created.
|
||||
* @retval #LOS_ERRNO_QUEUE_ISEMPTY No resource is in the queue that is being read when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is
|
||||
* locked.
|
||||
* @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: The header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueWrite | LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueRead(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Write data into a queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to write the address of data specified by bufferAddr into a queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific queue should be created firstly.</li>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The address of the data of the size specified by bufferSize and stored at the address specified by
|
||||
* BufferAddr is to be written.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* <li>The bufferSize is not really used in LOS_QueueWrite, because the interface is only used to write the address
|
||||
* of data specified by bufferAddr into a queue.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param bufferAddr [IN] Starting address that stores the data to be written. The starting address
|
||||
* must not be null.
|
||||
* @param bufferSize [IN] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff].
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_OK The data is successfully written into the queue.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The queue handle passed in during queue writing is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_PTR_NULL The pointer passed in during queue writing is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITESIZE_ISZERO The buffer size passed in during queue writing is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT The queue cannot be written during an interrupt when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue into which the data is written is not created.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG The buffer size passed in during queue writing is bigger than
|
||||
* the queue size.
|
||||
* @retval #LOS_ERRNO_QUEUE_ISFULL No free node is available during queue writing.
|
||||
* @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is
|
||||
* locked.
|
||||
* @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: The header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueRead | LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueWrite(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Write data into a queue header.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to write the data of the size specified by bufferSize and stored at the address specified by
|
||||
* bufferAddr into a queue header.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The address of the data of the size specified by bufferSize and stored at the address specified by
|
||||
* BufferAddr is to be written.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* <li>LOS_QueueRead and LOS_QueueWriteHead are a set of interfaces, and the two groups of interfaces need to be used.
|
||||
* <li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param bufferAddr [OUT] Starting address that stores the data to be written. The starting address
|
||||
* must not be null.
|
||||
* @param bufferSize [IN] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff].
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_OK The data is successfully written into the queue.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The queue handle passed in during queue writing is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_PTR_NULL The pointer passed in during queue writing is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITESIZE_ISZERO The buffer size passed in during queue writing is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT The queue cannot be written during an interrupt when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue into which the data is written is not created.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG The buffer size passed in during queue writing is bigger than
|
||||
* the queue size.
|
||||
* @retval #LOS_ERRNO_QUEUE_ISFULL No free node is available during queue writing.
|
||||
* @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is
|
||||
* locked.
|
||||
* @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: The header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueRead | LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueWriteHead(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Write data into a queue header.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to write the data of the size specified by bufferSize and stored at the address specified by
|
||||
* bufferAddr into a queue header.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The address of the data of the size specified by bufferSize and stored at the address specified by
|
||||
* BufferAddr is to be written.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* <li>LOS_QueueRead and LOS_QueueWriteHead are a set of interfaces, and the two groups of interfaces need to be
|
||||
* used.<li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param bufferAddr [OUT] Starting address that stores the data to be written.
|
||||
* The starting address must not be null.
|
||||
* @param bufferSize [IN] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff].
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_OK The data is successfully written into the queue.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The queue handle passed in during queue writing is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_PTR_NULL The pointer passed in during queue writing is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITESIZE_ISZERO The buffer size passed in during queue writing is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT The queue cannot be written during an interrupt when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue into which the data is written is not created.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG The buffer size passed in during queue writing is bigger than
|
||||
* the queue size.
|
||||
* @retval #LOS_ERRNO_QUEUE_ISFULL No free node is available during queue writing.
|
||||
* @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is
|
||||
* locked.
|
||||
* @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: The header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueWrite | LOS_QueueWriteHead
|
||||
*/
|
||||
extern UINT32 LOS_QueueWriteHeadCopy(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Delete a queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete a queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API cannot be used to delete a queue that is not created.</li>
|
||||
* <li>A synchronous queue fails to be deleted if any tasks are blocked on it, or some queues are being read or
|
||||
* written.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
*
|
||||
* @retval #LOS_OK The queue is successfully deleted.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_FOUND The queue cannot be found.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue handle passed in when the queue is being deleted is
|
||||
* incorrect.
|
||||
* @retval #LOS_ERRNO_QUEUE_IN_TSKUSE The queue that blocks a task cannot be deleted.
|
||||
* @retval #LOS_ERRNO_QUEUE_IN_TSKWRITE Queue reading and writing are not synchronous.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueCreate | LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueDelete(UINT32 queueID);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Obtain queue information.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain queue information.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific queue should be created firstly.</li>
|
||||
* </ul>
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param queueInfo [OUT] The queue information to be read must not be null.
|
||||
*
|
||||
* @retval #LOS_OK The queue information is successfully obtained.
|
||||
* @retval #LOS_ERRNO_QUEUE_PTR_NULL The pointer to the queue information to be obtained is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The handle of the queue that is being read is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue in which the information to be obtained is stored is
|
||||
* not created.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueInfoGet(UINT32 queueID, QUEUE_INFO_S *queueInfo);
|
||||
|
||||
typedef enum {
|
||||
OS_QUEUE_READ,
|
||||
OS_QUEUE_WRITE
|
||||
} QueueReadWrite;
|
||||
|
||||
typedef enum {
|
||||
OS_QUEUE_HEAD,
|
||||
OS_QUEUE_TAIL
|
||||
} QueueHeadTail;
|
||||
|
||||
typedef enum {
|
||||
OS_QUEUE_NOT_POINT,
|
||||
OS_QUEUE_POINT
|
||||
} QueuePointOrNot;
|
||||
|
||||
#define OS_QUEUE_OPERATE_TYPE(ReadOrWrite, HeadOrTail, PointOrNot) \
|
||||
(((UINT32)(PointOrNot) << 2) | ((UINT32)(HeadOrTail) << 1) | (ReadOrWrite))
|
||||
#define OS_QUEUE_READ_WRITE_GET(type) ((type) & (0x01))
|
||||
#define OS_QUEUE_READ_HEAD (OS_QUEUE_READ | (OS_QUEUE_HEAD << 1))
|
||||
#define OS_QUEUE_READ_TAIL (OS_QUEUE_READ | (OS_QUEUE_TAIL << 1))
|
||||
#define OS_QUEUE_WRITE_HEAD (OS_QUEUE_WRITE | (OS_QUEUE_HEAD << 1))
|
||||
#define OS_QUEUE_WRITE_TAIL (OS_QUEUE_WRITE | (OS_QUEUE_TAIL << 1))
|
||||
#define OS_QUEUE_OPERATE_GET(type) ((type) & (0x03))
|
||||
#define OS_QUEUE_IS_POINT(type) ((type) & (0x04))
|
||||
#define OS_QUEUE_IS_READ(type) (OS_QUEUE_READ_WRITE_GET(type) == OS_QUEUE_READ)
|
||||
#define OS_QUEUE_IS_WRITE(type) (OS_QUEUE_READ_WRITE_GET(type) == OS_QUEUE_WRITE)
|
||||
#define OS_READWRITE_LEN 2
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue information block structure
|
||||
*/
|
||||
typedef struct {
|
||||
UINT8 *queue; /**< Pointer to a queue handle */
|
||||
UINT8 *queueName; /**< Queue name */
|
||||
UINT16 queueState; /**< Queue state */
|
||||
UINT16 queueLen; /**< Queue length */
|
||||
UINT16 queueSize; /**< Node size */
|
||||
UINT16 queueID; /**< queueID */
|
||||
UINT16 queueHead; /**< Node head */
|
||||
UINT16 queueTail; /**< Node tail */
|
||||
UINT16 readWriteableCnt[OS_READWRITE_LEN]; /**< Count of readable or writable resources, 0:readable, 1:writable */
|
||||
LOS_DL_LIST readWriteList[OS_READWRITE_LEN]; /**< Pointer to the linked list to be read or written,
|
||||
0:readlist, 1:writelist */
|
||||
LOS_DL_LIST memList; /**< Pointer to the memory linked list */
|
||||
} LosQueueCB;
|
||||
|
||||
|
||||
extern LosQueueCB *OsGetQueueHandle(UINT32 queueID);
|
||||
|
||||
/* queue state */
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Message queue state: not in use.
|
||||
*/
|
||||
#define OS_QUEUE_UNUSED 0
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Message queue state: used.
|
||||
*/
|
||||
#define OS_QUEUE_INUSED 1
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Not in use.
|
||||
*/
|
||||
#define OS_QUEUE_WAIT_FOR_POOL 1
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Normal message queue.
|
||||
*/
|
||||
#define OS_QUEUE_NORMAL 0
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue information control block
|
||||
*/
|
||||
extern LosQueueCB *g_allQueue;
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Obtain a handle of the queue that has a specified ID.
|
||||
*/
|
||||
#define GET_QUEUE_HANDLE(QueueID) OsGetQueueHandle(QueueID)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Obtain the head node in a queue doubly linked list.
|
||||
*/
|
||||
#define GET_QUEUE_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosQueueCB, readWriteList[OS_QUEUE_WRITE])
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Maximum number of queues
|
||||
*/
|
||||
#if (LOSCFG_BASE_IPC_QUEUE_STATIC == 1)
|
||||
#define OS_ALL_IPC_QUEUE_LIMIT LOSCFG_BASE_IPC_QUEUE_LIMIT + LOSCFG_BASE_IPC_STATIC_QUEUE_LIMIT
|
||||
#else
|
||||
#define OS_ALL_IPC_QUEUE_LIMIT LOSCFG_BASE_IPC_QUEUE_LIMIT
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Alloc a stationary memory for a mail.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to alloc a stationary memory for a mail according to queueID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Do not alloc memory in unblocking modes such as interrupt.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param mailPool [IN] The memory poll that stores the mail.
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER].
|
||||
*
|
||||
* @retval #NULL The memory allocation is failed.
|
||||
* @retval #mem The address of alloc memory.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsQueueMailFree
|
||||
*/
|
||||
extern VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Free a stationary memory of a mail.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to free a stationary memory for a mail according to queueID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param mailPool [IN] The mail memory poll address.
|
||||
* @param mailMem [IN] The mail memory block address.
|
||||
*
|
||||
* @retval #LOS_OK 0x00000000: The memory free successfully.
|
||||
* @retval #OS_ERRNO_QUEUE_MAIL_HANDLE_INVALID 0x02000619: The handle of the queue passed-in when the memory for
|
||||
the queue is being freed is invalid.
|
||||
* @retval #OS_ERRNO_QUEUE_MAIL_PTR_INVALID 0x0200061a: The pointer to the memory to be freed is null.
|
||||
* @retval #OS_ERRNO_QUEUE_MAIL_FREE_ERROR 0x0200061b: The memory for the queue fails to be freed.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsQueueMailAlloc
|
||||
*/
|
||||
extern UINT32 OsQueueMailFree(UINT32 queueID, VOID *mailPool, VOID *mailMem);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Initialization queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialization queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval UINT32 Initialization result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsQueueInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Handle when read or write queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to handle when read or write queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue id.
|
||||
* @param operateType [IN] Operate type
|
||||
* @param bufferAddr [IN] Buffer address.
|
||||
* @param bufferSize [IN] Buffer size.
|
||||
* @param timeOut [IN] Timeout.
|
||||
*
|
||||
* @retval UINT32 Handle result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_QUEUE_H */
|
||||
164
ohos/kernel/liteos_m/kernel/include/los_sched.h
Normal file
164
ohos/kernel/liteos_m/kernel/include/los_sched.h
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 _LOS_SCHED_H
|
||||
#define _LOS_SCHED_H
|
||||
|
||||
#include "los_task.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_sortlink.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OS_SCHED_MINI_PERIOD (g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI)
|
||||
#define OS_SCHED_MAX_RESPONSE_TIME OS_SORT_LINK_UINT64_MAX
|
||||
|
||||
extern UINT32 g_taskScheduled;
|
||||
typedef BOOL (*SchedScan)(VOID);
|
||||
|
||||
VOID OsSchedResetSchedResponseTime(UINT64 responseTime);
|
||||
|
||||
VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask);
|
||||
|
||||
UINT32 OsSchedSwtmrScanRegister(SchedScan func);
|
||||
|
||||
VOID OsSchedUpdateExpireTime(VOID);
|
||||
|
||||
UINT64 OsSchedGetNextExpireTime(UINT64 startTime);
|
||||
|
||||
VOID OsSchedTaskDeQueue(LosTaskCB *taskCB);
|
||||
|
||||
VOID OsSchedTaskEnQueue(LosTaskCB *taskCB);
|
||||
|
||||
VOID OsSchedTaskWait(LOS_DL_LIST *list, UINT32 timeout);
|
||||
|
||||
VOID OsSchedTaskWake(LosTaskCB *resumedTask);
|
||||
|
||||
BOOL OsSchedModifyTaskSchedParam(LosTaskCB *taskCB, UINT16 priority);
|
||||
|
||||
VOID OsSchedDelay(LosTaskCB *runTask, UINT32 tick);
|
||||
|
||||
VOID OsSchedYield(VOID);
|
||||
|
||||
VOID OsSchedTaskExit(LosTaskCB *taskCB);
|
||||
|
||||
VOID OsSchedSuspend(LosTaskCB *taskCB);
|
||||
|
||||
BOOL OsSchedResume(LosTaskCB *taskCB);
|
||||
|
||||
VOID OsSchedTick(VOID);
|
||||
|
||||
UINT32 OsSchedInit(VOID);
|
||||
|
||||
VOID OsSchedStart(VOID);
|
||||
|
||||
BOOL OsSchedTaskSwitch(VOID);
|
||||
|
||||
LosTaskCB *OsGetTopTask(VOID);
|
||||
|
||||
VOID OsSchedTimeConvertFreq(UINT32 oldFreq);
|
||||
|
||||
STATIC INLINE UINT64 OsGetCurrSchedTimeCycle(VOID)
|
||||
{
|
||||
return LOS_SysCycleGet();
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL OsCheckKernelRunning(VOID)
|
||||
{
|
||||
return (g_taskScheduled && LOS_CHECK_SCHEDULE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_sched
|
||||
* @brief Get the time, in nanoseconds, remaining before the next tick interrupt response.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the time, in nanoseconds, remaining before the next tick interrupt response.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #time, in nanoseconds.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sched.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern UINT64 LOS_SchedTickTimeoutNsGet(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_sched
|
||||
* @brief The system-provided tick interrupt handler.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to wake up a task that is blocked by time.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sched.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern VOID LOS_SchedTickHandler(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_sched
|
||||
* @brief Trigger a system dispatch.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to trigger a system dispatch.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sched.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern VOID LOS_Schedule(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_SCHED_H */
|
||||
391
ohos/kernel/liteos_m/kernel/include/los_sem.h
Normal file
391
ohos/kernel/liteos_m/kernel/include/los_sem.h
Normal file
@@ -0,0 +1,391 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_sem Semaphore
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SEM_H
|
||||
#define _LOS_SEM_H
|
||||
|
||||
#include "los_task.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: The memory is insufficient.
|
||||
*
|
||||
* Value: 0x02000700
|
||||
*
|
||||
* Solution: Allocate more memory.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: Invalid parameter.
|
||||
*
|
||||
* Value: 0x02000701
|
||||
*
|
||||
* Solution: Change the passed-in invalid parameter value to a valid value.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: Null pointer.
|
||||
*
|
||||
* Value: 0x02000702
|
||||
*
|
||||
* Solution: Change the passed-in null pointer to a valid non-null pointer.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: No semaphore control structure is available.
|
||||
*
|
||||
* Value: 0x02000703
|
||||
*
|
||||
* Solution: Perform corresponding operations based on the requirements in the code context.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_ALL_BUSY LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: Invalid parameter that specifies the timeout interval.
|
||||
*
|
||||
* Value: 0x02000704
|
||||
*
|
||||
*
|
||||
* Solution: Change the passed-in parameter value to a valid nonzero value.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: The API is called during an interrupt, which is forbidden.
|
||||
*
|
||||
* Value: 0x02000705
|
||||
*
|
||||
* Solution: Do not call the API during an interrupt.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_PEND_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: The task is unable to request a semaphore because task scheduling is locked.
|
||||
*
|
||||
* Value: 0x02000706
|
||||
*
|
||||
* Solution: Do not call LOS_SemPend when task scheduling is locked.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_PEND_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x06)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: The request for a semaphore times out.
|
||||
*
|
||||
* Value: 0x02000707
|
||||
*
|
||||
* Solution: Change the passed-in parameter value to the value within the valid range.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x07)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: The times of semaphore release exceed the maximum times permitted.
|
||||
*
|
||||
* Value: 0x02000708
|
||||
*
|
||||
* Solution: Perform corresponding operations based on the requirements in the code context.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_OVERFLOW LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x08)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: The queue of the tasks that are waiting on the semaphore control structure is not null.
|
||||
*
|
||||
* Value: 0x02000709
|
||||
*
|
||||
* Solution: Delete the semaphore after awaking all tasks that are waiting on the semaphore.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_PENDED LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x09)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: LOS_ERRNO_SEM_MAXNUM_ZERO is error.
|
||||
*
|
||||
* Value: 0x0200070A
|
||||
*
|
||||
* Solution: LOS_ERRNO_SEM_MAXNUM_ZERO should not be error.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_MAXNUM_ZERO LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x0A)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: The API is called in a system-level task, which is forbidden.
|
||||
* Value: 0x0200070B
|
||||
*
|
||||
* Solution: Do not call the API in system-level tasks.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_PEND_IN_SYSTEM_TASK LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x0B)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Create a Counting semaphore.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create a semaphore control structure according to the initial number of available semaphores
|
||||
* specified by count and return the ID of this semaphore control structure.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param count [IN] Initial number of available semaphores. The value range is [0, OS_SEM_COUNTING_MAX_COUNT).
|
||||
* @param semHandle [OUT] ID of the semaphore control structure that is initialized.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SEM_PTR_NULL The passed-in semHandle value is NULL.
|
||||
* @retval #LOS_ERRNO_SEM_OVERFLOW The passed-in count value is greater than the maximum number of available
|
||||
* semaphores.
|
||||
* @retval #LOS_ERRNO_SEM_ALL_BUSY No semaphore control structure is available.
|
||||
* @retval #LOS_OK The semaphore is successfully created.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SemDelete
|
||||
*/
|
||||
extern UINT32 LOS_SemCreate(UINT16 count, UINT32 *semHandle);
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Create a binary semaphore.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create a binary semaphore control structure according to the initial number of available
|
||||
* semaphores specified by count and return the ID of this semaphore control structure.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param count [IN] Initial number of available semaphores. The value range is [0, 1].
|
||||
* @param semHandle [OUT] ID of the semaphore control structure that is initialized.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SEM_PTR_NULL The passed-in semHandle value is NULL.
|
||||
* @retval #LOS_ERRNO_SEM_OVERFLOW The passed-in count value is greater than the maximum number of available
|
||||
* semaphores.
|
||||
* @retval #LOS_ERRNO_SEM_ALL_BUSY No semaphore control structure is available.
|
||||
* @retval #LOS_OK The semaphore is successfully created.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SemDelete
|
||||
*/
|
||||
extern UINT32 LOS_BinarySemCreate(UINT16 count, UINT32 *semHandle);
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Delete a semaphore.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete a semaphore control structure that has an ID specified by semHandle.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specified sem id must be created first. </li>
|
||||
* </ul>
|
||||
*
|
||||
* @param semHandle [IN] ID of the semaphore control structure to be deleted. The ID of the semaphore
|
||||
* control structure is obtained from semaphore creation.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SEM_INVALID The passed-in semHandle value is invalid.
|
||||
* @retval #LOS_ERRNO_SEM_PENDED The queue of the tasks that are waiting on the semaphore control structure is
|
||||
* not null.
|
||||
* @retval #LOS_OK The semaphore control structure is successfully deleted.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SemCreate
|
||||
*/
|
||||
extern UINT32 LOS_SemDelete(UINT32 semHandle);
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Request a semaphore.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to request a semaphore based on the semaphore control structure ID specified by semHandle and the
|
||||
* parameter that specifies the timeout period.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specified sem id must be created first. </li>
|
||||
* </ul>
|
||||
*
|
||||
* @param semHandle [IN] ID of the semaphore control structure to be requested. The ID of the semaphore control
|
||||
* structure is obtained from semaphore creation.
|
||||
* @param timeout [IN] Timeout interval for waiting on the semaphore. The value range is [0, 0xFFFFFFFF].
|
||||
* If the value is set to 0, the semaphore is not waited on. If the value is set to 0xFFFFFFFF,
|
||||
* the semaphore is waited on forever(unit: Tick).
|
||||
*
|
||||
* @retval #LOS_ERRNO_SEM_INVALID The passed-in semHandle value is invalid.
|
||||
* @retval #LOS_ERRNO_SEM_UNAVAILABLE There is no available semaphore resource.
|
||||
* @retval #LOS_ERRNO_SEM_PEND_INTERR The API is called during an interrupt, which is forbidden.
|
||||
* @retval #LOS_ERRNO_SEM_PEND_IN_LOCK The task is unable to request a semaphore because task scheduling is locked.
|
||||
* @retval #LOS_ERRNO_SEM_TIMEOUT The request for the semaphore times out.
|
||||
* @retval #LOS_OK The semaphore request succeeds.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SemPost | LOS_SemCreate
|
||||
*/
|
||||
extern UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout);
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Release a semaphore.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to release a semaphore that has a semaphore control structure ID specified by semHandle.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specified sem id must be created first. </li>
|
||||
* </ul>
|
||||
*
|
||||
* @param semHandle [IN] ID of the semaphore control structure to be released.The ID of the semaphore control
|
||||
* structure is obtained from semaphore creation.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SEM_INVALID The passed-in semHandle value is invalid.
|
||||
* @retval #LOS_ERRNO_SEM_OVERFLOW The times of semaphore release exceed the maximum times permitted.
|
||||
* @retval #LOS_OK The semaphore is successfully released.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SemPend | LOS_SemCreate
|
||||
*/
|
||||
extern UINT32 LOS_SemPost(UINT32 semHandle);
|
||||
|
||||
extern UINT32 LOS_SemGetValue(UINT32 semHandle, INT32 *currVal);
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore control structure.
|
||||
*/
|
||||
typedef struct {
|
||||
UINT16 semStat; /**< Semaphore state */
|
||||
UINT16 semCount; /**< Number of available semaphores */
|
||||
UINT16 maxSemCount; /**< Max number of available semaphores */
|
||||
UINT16 semID; /**< Semaphore control structure ID */
|
||||
LOS_DL_LIST semList; /**< Queue of tasks that are waiting on a semaphore */
|
||||
} LosSemCB;
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* Max count of binary semaphores.
|
||||
*/
|
||||
#define OS_SEM_BINARY_MAX_COUNT 1
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* The semaphore is not in use.
|
||||
*/
|
||||
#define OS_SEM_UNUSED 0
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* The semaphore is used.
|
||||
*/
|
||||
#define OS_SEM_USED 1
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Obtain the head node in a semaphore doubly linked list.
|
||||
*/
|
||||
#define GET_SEM_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosSemCB, semList)
|
||||
|
||||
extern LosSemCB *g_allSem;
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Obtain a semaphore ID.
|
||||
*
|
||||
*/
|
||||
#define GET_SEM(semid) (((LosSemCB *)g_allSem) + (semid))
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Initialize the Semaphore doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize the Semaphore doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval UINT32 Initialization result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsSemInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Create Semaphore.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create Semaphore.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param count [IN]Type #UINT16 Semaphore count.
|
||||
* @param maxCount [IN]Type #UINT16 Max semaphore count.
|
||||
* @param semHandle [OUT]Type #UINT32 * Index of semaphore.
|
||||
*
|
||||
* @retval UINT32 Create result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
UINT32 OsSemCreate(UINT16 count, UINT16 maxCount, UINT32 *semHandle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_SEM_H */
|
||||
127
ohos/kernel/liteos_m/kernel/include/los_sortlink.h
Normal file
127
ohos/kernel/liteos_m/kernel/include/los_sortlink.h
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 _LOS_SORTLINK_H
|
||||
#define _LOS_SORTLINK_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
#include "los_list.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef enum {
|
||||
OS_SORT_LINK_TASK = 1,
|
||||
OS_SORT_LINK_SWTMR = 2,
|
||||
} SortLinkType;
|
||||
|
||||
typedef struct {
|
||||
LOS_DL_LIST sortLinkNode;
|
||||
UINT64 responseTime;
|
||||
} SortLinkList;
|
||||
|
||||
typedef struct {
|
||||
LOS_DL_LIST sortLink;
|
||||
} SortLinkAttribute;
|
||||
|
||||
extern SortLinkAttribute g_taskSortLink;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
extern SortLinkAttribute g_swtmrSortLink;
|
||||
#endif
|
||||
|
||||
#define OS_SORT_LINK_INVALID_TIME ((UINT64)-1)
|
||||
#define SET_SORTLIST_VALUE(sortList, value) (((SortLinkList *)(sortList))->responseTime = (value))
|
||||
#define GET_SORTLIST_VALUE(sortList) (((SortLinkList *)(sortList))->responseTime)
|
||||
|
||||
#define OS_SORT_LINK_UINT64_MAX ((UINT64)-1)
|
||||
|
||||
STATIC INLINE UINT64 OsSortLinkGetRemainTime(UINT64 currTime, const SortLinkList *targetSortList)
|
||||
{
|
||||
if (currTime >= targetSortList->responseTime) {
|
||||
return 0;
|
||||
}
|
||||
return (targetSortList->responseTime - currTime);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsDeleteNodeSortLink(SortLinkList *sortList)
|
||||
{
|
||||
LOS_ListDelete(&sortList->sortLinkNode);
|
||||
SET_SORTLIST_VALUE(sortList, OS_SORT_LINK_INVALID_TIME);
|
||||
}
|
||||
|
||||
STATIC INLINE UINT64 GetSortLinkNextExpireTime(SortLinkAttribute *sortHead, UINT64 startTime, UINT32 tickPrecision)
|
||||
{
|
||||
LOS_DL_LIST *head = &sortHead->sortLink;
|
||||
LOS_DL_LIST *list = head->pstNext;
|
||||
|
||||
if (LOS_ListEmpty(head)) {
|
||||
return OS_SORT_LINK_UINT64_MAX - tickPrecision;
|
||||
}
|
||||
|
||||
SortLinkList *listSorted = LOS_DL_LIST_ENTRY(list, SortLinkList, sortLinkNode);
|
||||
if (listSorted->responseTime <= (startTime + tickPrecision)) {
|
||||
return (startTime + tickPrecision);
|
||||
}
|
||||
|
||||
return listSorted->responseTime;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT64 OsGetNextExpireTime(UINT64 startTime, UINT32 tickPrecision)
|
||||
{
|
||||
UINT64 taskExpireTime = GetSortLinkNextExpireTime(&g_taskSortLink, startTime, tickPrecision);
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
UINT64 swtmrExpireTime = GetSortLinkNextExpireTime(&g_swtmrSortLink, startTime, tickPrecision);
|
||||
#else
|
||||
UINT64 swtmrExpireTime = taskExpireTime;
|
||||
#endif
|
||||
return (taskExpireTime < swtmrExpireTime) ? taskExpireTime : swtmrExpireTime;
|
||||
}
|
||||
|
||||
SortLinkAttribute *OsGetSortLinkAttribute(SortLinkType type);
|
||||
UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHead);
|
||||
VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type);
|
||||
VOID OsDeleteSortLink(SortLinkList *node);
|
||||
UINT64 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList);
|
||||
UINT64 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHead);
|
||||
VOID OsSortLinkResponseTimeConvertFreq(UINT32 oldFreq);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_SORTLINK_H */
|
||||
511
ohos/kernel/liteos_m/kernel/include/los_swtmr.h
Normal file
511
ohos/kernel/liteos_m/kernel/include/los_swtmr.h
Normal file
@@ -0,0 +1,511 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_swtmr Software timer
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SWTMR_H
|
||||
#define _LOS_SWTMR_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_sortlink.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The timeout handling function is NULL.
|
||||
*
|
||||
* Value: 0x02000300
|
||||
*
|
||||
* Solution: Define the timeout handling function.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The expiration time is 0.
|
||||
*
|
||||
* Value: 0x02000301
|
||||
*
|
||||
* Solution: Re-define the expiration time.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_INTERVAL_NOT_SUITED LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: Invalid software timer mode.
|
||||
*
|
||||
* Value: 0x02000302
|
||||
*
|
||||
* Solution: Check the mode value. The value range is [0,3].
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The passed-in software timer ID is NULL.
|
||||
*
|
||||
* Value: 0x02000303
|
||||
*
|
||||
* Solution: Define the software timer ID before passing it in.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_RET_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The number of software timers exceeds the configured permitted maximum number.
|
||||
*
|
||||
* Value: 0x02000304
|
||||
*
|
||||
* Solution: Re-configure the permitted maximum number of software timers, or wait for a software timer to become
|
||||
* available.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_MAXSIZE LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: Invalid software timer ID.
|
||||
*
|
||||
* Value: 0x02000305
|
||||
*
|
||||
* Solution: Pass in a valid software timer ID.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_ID_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The software timer is not created.
|
||||
*
|
||||
* Value: 0x02000306
|
||||
*
|
||||
* Solution: Create a software timer.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_NOT_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x06)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: Insufficient memory for software timer linked list creation.
|
||||
*
|
||||
* Value: 0x02000307
|
||||
*
|
||||
* Solution: Allocate bigger memory partition to software timer linked list creation.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x07)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: Invalid configured number of software timers.
|
||||
*
|
||||
* Value: 0x02000308
|
||||
*
|
||||
* Solution: Re-configure the number of software timers.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_MAXSIZE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x08)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The software timer is being used during an interrupt.
|
||||
*
|
||||
* Value: 0x02000309
|
||||
*
|
||||
* Solution: Change the source code and do not use the software timer during an interrupt.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_HWI_ACTIVE LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x09)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: Insufficient memory allocated by membox.
|
||||
*
|
||||
* Value: 0x0200030a
|
||||
*
|
||||
* Solution: Expand the memory allocated by membox.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_HANDLER_POOL_NO_MEM LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0a)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The software timer queue fails to be created.
|
||||
*
|
||||
* Value: 0x0200030b
|
||||
*
|
||||
* Solution: Check whether more memory can be allocated to the queue to be created.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_QUEUE_CREATE_FAILED LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0b)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The software timer task fails to be created.
|
||||
*
|
||||
* Value: 0x0200030c
|
||||
*
|
||||
* Solution: Check whether the memory is sufficient and re-create the task.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_TASK_CREATE_FAILED LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0c)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The software timer is not started.
|
||||
*
|
||||
* Value: 0x0200030d
|
||||
*
|
||||
* Solution: Start the software timer.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_NOT_STARTED LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0d)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: Invalid software timer state.
|
||||
*
|
||||
* Value: 0x0200030e
|
||||
*
|
||||
* Solution: Check the software timer state.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_STATUS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0e)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* This error code is not in use temporarily.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_SORTLIST_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0f)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The passed-in number of remaining Ticks configured on the software timer is NULL.
|
||||
*
|
||||
* Value: 0x02000310
|
||||
*
|
||||
* Solution: Define a variable of the number of remaining Ticks before passing in the number of remaining Ticks.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_TICK_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x10)
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
#define OS_ERRNO_SWTMR_ROUSES_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x11)
|
||||
#define OS_ERRNO_SWTMR_ALIGN_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x12)
|
||||
|
||||
enum enSwTmrRousesType {
|
||||
OS_SWTMR_ROUSES_IGNORE, /* timer don't need to wake up system */
|
||||
OS_SWTMR_ROUSES_ALLOW, /* timer can wake up system */
|
||||
};
|
||||
|
||||
enum enSwTmrAlignSensitive {
|
||||
OS_SWTMR_ALIGN_SENSITIVE, /* timer don't need to align */
|
||||
OS_SWTMR_ALIGN_INSENSITIVE, /* timer need to align */
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer mode
|
||||
*/
|
||||
enum EnSwTmrType {
|
||||
LOS_SWTMR_MODE_ONCE, /* One-off software timer */
|
||||
LOS_SWTMR_MODE_PERIOD, /* Periodic software timer */
|
||||
LOS_SWTMR_MODE_NO_SELFDELETE, /* One-off software timer, but not self-delete */
|
||||
LOS_SWTMR_MODE_OPP, /* After the one-off timer finishes timing,
|
||||
the periodic software timer is enabled.
|
||||
This mode is not supported temporarily. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Define the type of a callback function that handles software timer timeout.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to define the type of a callback function that handles software timer timeout, so that it can be
|
||||
* called when software timer timeout.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param para [IN] the parameter of the callback function that handles software timer timeout.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
typedef VOID (*SWTMR_PROC_FUNC)(UINT32 para);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer control structure
|
||||
*/
|
||||
typedef struct tagSwTmrCtrl {
|
||||
struct tagSwTmrCtrl *pstNext; /* Pointer to the next software timer */
|
||||
UINT8 ucState; /* Software timer state */
|
||||
UINT8 ucMode; /* Software timer mode */
|
||||
UINT8 ucOverrun; /* Times that a software timer repeats timing */
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
UINT8 ucRouses; /* wake up enable */
|
||||
UINT8 ucSensitive; /* align enable */
|
||||
#endif
|
||||
UINT32 usTimerID; /* Software timer ID */
|
||||
UINT32 uwInterval; /* Timeout interval of a periodic software timer */
|
||||
UINT32 uwArg; /* Parameter passed in when the callback function
|
||||
that handles software timer timeout is called */
|
||||
SWTMR_PROC_FUNC pfnHandler; /* Callback function that handles software timer timeout */
|
||||
SortLinkList stSortList;
|
||||
UINT64 startTime;
|
||||
} SWTMR_CTRL_S;
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Start a software timer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to start a software timer that has a specified ID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific timer must be created first</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param swtmrID [IN] Software timer ID created by LOS_SwtmrCreate.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SWTMR_ID_INVALID Invalid software timer ID.
|
||||
* @retval #LOS_ERRNO_SWTMR_NOT_CREATED The software timer is not created.
|
||||
* @retval #LOS_ERRNO_SWTMR_STATUS_INVALID Invalid software timer state.
|
||||
* @retval #LOS_OK The software timer is successfully started.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SwtmrStop | LOS_SwtmrCreate
|
||||
*/
|
||||
extern UINT32 LOS_SwtmrStart(UINT32 swtmrID);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Stop a software timer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to stop a software timer that has a specified ID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific timer should be created and started firstly.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param swtmrID [IN] Software timer ID created by LOS_SwtmrCreate.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SWTMR_ID_INVALID Invalid software timer ID.
|
||||
* @retval #LOS_ERRNO_SWTMR_NOT_CREATED The software timer is not created.
|
||||
* @retval #LOS_ERRNO_SWTMR_NOT_STARTED The software timer is not started.
|
||||
* @retval #LOS_ERRNO_SWTMR_STATUS_INVALID Invalid software timer state.
|
||||
* @retval #LOS_OK The software timer is successfully stopped.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SwtmrStart | LOS_SwtmrCreate
|
||||
*/
|
||||
extern UINT32 LOS_SwtmrStop(UINT32 swtmrID);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Obtain the number of remaining Ticks configured on a software timer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the number of remaining Ticks configured on the software timer of which the ID is
|
||||
* specified by usSwTmrID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific timer should be created and started successfully, error happens otherwise.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param swtmrID [IN] Software timer ID created by LOS_SwtmrCreate.
|
||||
* @param tick [OUT] Number of remaining Ticks configured on the software timer.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SWTMR_ID_INVALID Invalid software timer ID.
|
||||
* @retval #LOS_ERRNO_SWTMR_NOT_CREATED The software timer is not created.
|
||||
* @retval #LOS_ERRNO_SWTMR_NOT_STARTED The software timer is not started.
|
||||
* @retval #LOS_ERRNO_SWTMR_STATUS_INVALID Invalid software timer state.
|
||||
* @retval #LOS_OK The number of remaining Ticks is successfully obtained.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SwtmrCreate
|
||||
*/
|
||||
extern UINT32 LOS_SwtmrTimeGet(UINT32 swtmrID, UINT32 *tick);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Create a software timer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create a software timer that has specified timing duration, timeout handling function,
|
||||
* and trigger mode, and to return a handle by which the software timer can be referenced.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Do not use the delay interface in the callback function that handles software timer timeout.</li>
|
||||
* <li>There are LOSCFG_BASE_CORE_SWTMR_LIMIT timers available, change it's value when necessary.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param interval [IN] Timing duration of the software timer to be created (unit: ms).
|
||||
* @param mode [IN] Software timer mode. Pass in one of the modes specified by EnSwTmrType. There are three
|
||||
* types of modes, one-off, periodic, and continuously periodic after one-off, of which the third mode is not
|
||||
* supported temporarily.
|
||||
* @param handler [IN] Callback function that handles software timer timeout.
|
||||
* @param swtmrID [OUT] Software timer ID created by LOS_SwtmrCreate.
|
||||
* @param arg [IN] Parameter passed in when the callback function that handles software timer timeout is
|
||||
* called.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SWTMR_INTERVAL_NOT_SUITED The software timer timeout interval is 0.
|
||||
* @retval #LOS_ERRNO_SWTMR_MODE_INVALID Invalid software timer mode.
|
||||
* @retval #LOS_ERRNO_SWTMR_PTR_NULL The callback function that handles software timer timeout is NULL.
|
||||
* @retval #LOS_ERRNO_SWTMR_RET_PTR_NULL The passed-in software timer ID is NULL.
|
||||
* @retval #LOS_ERRNO_SWTMR_MAXSIZE The number of software timers exceeds the configured permitted
|
||||
* maximum number.
|
||||
* @retval #LOS_OK The software timer is successfully created.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SwtmrDelete
|
||||
*/
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
extern UINT32 LOS_SwtmrCreate(UINT32 interval,
|
||||
UINT8 mode,
|
||||
SWTMR_PROC_FUNC handler,
|
||||
UINT32 *swtmrID,
|
||||
UINT32 arg,
|
||||
UINT8 rouses,
|
||||
UINT8 sensitive);
|
||||
#else
|
||||
extern UINT32 LOS_SwtmrCreate(UINT32 interval,
|
||||
UINT8 mode,
|
||||
SWTMR_PROC_FUNC handler,
|
||||
UINT32 *swtmrID,
|
||||
UINT32 arg);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Delete a software timer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete a software timer.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific timer should be created and then stopped firstly.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param swtmrID [IN] Software timer ID created by LOS_SwtmrCreate.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SWTMR_ID_INVALID Invalid software timer ID.
|
||||
* @retval #LOS_ERRNO_SWTMR_NOT_CREATED The software timer is not created.
|
||||
* @retval #LOS_ERRNO_SWTMR_STATUS_INVALID Invalid software timer state.
|
||||
* @retval #LOS_OK The software timer is successfully deleted.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SwtmrCreate
|
||||
*/
|
||||
extern UINT32 LOS_SwtmrDelete(UINT32 swtmrID);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer state
|
||||
*/
|
||||
enum SwtmrState {
|
||||
OS_SWTMR_STATUS_UNUSED, /**< The software timer is not used. */
|
||||
OS_SWTMR_STATUS_CREATED, /**< The software timer is created. */
|
||||
OS_SWTMR_STATUS_TICKING /**< The software timer is timing. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Structure of the callback function that handles software timer timeout
|
||||
*/
|
||||
typedef struct {
|
||||
SWTMR_PROC_FUNC handler; /**< Callback function that handles software timer timeout */
|
||||
UINT32 arg; /**< Parameter passed in when the callback function
|
||||
that handles software timer timeout is called */
|
||||
UINT32 swtmrID; /**< The id used to obtain the software timer handle */
|
||||
} SwtmrHandlerItem;
|
||||
|
||||
extern SWTMR_CTRL_S *g_swtmrCBArray;
|
||||
|
||||
#define OS_SWT_FROM_SID(swtmrId) ((SWTMR_CTRL_S *)g_swtmrCBArray + ((swtmrId) % LOSCFG_BASE_CORE_SWTMR_LIMIT))
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Initialization software timer.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to initialization software.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsSwtmrInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Get next timeout.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get next timeout.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsSwtmrGetNextTimeout(VOID);
|
||||
|
||||
extern VOID OsSwtmrResponseTimeReset(UINT64 startTime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_SWTMR_H */
|
||||
1806
ohos/kernel/liteos_m/kernel/include/los_task.h
Normal file
1806
ohos/kernel/liteos_m/kernel/include/los_task.h
Normal file
File diff suppressed because it is too large
Load Diff
648
ohos/kernel/liteos_m/kernel/include/los_tick.h
Normal file
648
ohos/kernel/liteos_m/kernel/include/los_tick.h
Normal file
@@ -0,0 +1,648 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_tick
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_TICK_H
|
||||
#define _LOS_TICK_H
|
||||
|
||||
#include "los_error.h"
|
||||
#include "los_timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Tick error code: The Tick configuration is incorrect.
|
||||
*
|
||||
* Value: 0x02000400
|
||||
*
|
||||
* Solution: Change values of the OS_SYS_CLOCK and LOSCFG_BASE_CORE_TICK_PER_SECOND
|
||||
* system time configuration modules in Los_config.h.
|
||||
*/
|
||||
#define LOS_ERRNO_TICK_CFG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TICK, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Tick error code: The system tick timer uninitialized.
|
||||
*
|
||||
* Value: 0x02000401
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_TICK_NO_HWTIMER LOS_ERRNO_OS_ERROR(LOS_MOD_TICK, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Tick error code: The number of Ticks is too small.
|
||||
*
|
||||
* Value: 0x02000402
|
||||
*
|
||||
* Solution: Change values of the OS_SYS_CLOCK and LOSCFG_BASE_CORE_TICK_PER_SECOND
|
||||
* system time configuration modules according to the SysTick_Config function.
|
||||
*/
|
||||
#define LOS_ERRNO_TICK_PER_SEC_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_TICK, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief: System timer cycles get function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get system timer cycles.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param: None.
|
||||
*
|
||||
* @retval: current system cycles.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*
|
||||
* */
|
||||
extern UINT64 LOS_SysCycleGet(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Number of milliseconds in one second.
|
||||
*/
|
||||
#define OS_SYS_MS_PER_SECOND 1000
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Ticks per second
|
||||
*/
|
||||
extern UINT32 g_ticksPerSec;
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Cycles per Second
|
||||
*/
|
||||
extern UINT32 g_uwCyclePerSec;
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Cycles per Tick
|
||||
*/
|
||||
extern UINT32 g_cyclesPerTick;
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System Clock
|
||||
*/
|
||||
extern UINT32 g_sysClock;
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Number of microseconds in one second.
|
||||
*/
|
||||
#define OS_SYS_US_PER_SECOND 1000000
|
||||
|
||||
#define OS_SYS_NS_PER_SECOND 1000000000
|
||||
|
||||
#define OS_SYS_NS_PER_MS 1000000
|
||||
|
||||
#define OS_SYS_NS_PER_US 1000
|
||||
|
||||
#define OS_CYCLE_PER_TICK (g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND)
|
||||
|
||||
#define OS_NS_PER_CYCLE (OS_SYS_NS_PER_SECOND / g_sysClock)
|
||||
|
||||
#define OS_MS_PER_TICK (OS_SYS_MS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND)
|
||||
|
||||
#define OS_US_PER_TICK (OS_SYS_US_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND)
|
||||
|
||||
#define OS_NS_PER_TICK (OS_SYS_NS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND)
|
||||
|
||||
#define OS_SYS_CYCLE_TO_NS(cycle, freq) ((cycle) / (freq)) * OS_SYS_NS_PER_SECOND + \
|
||||
((cycle) % (freq) * OS_SYS_NS_PER_SECOND / (freq))
|
||||
|
||||
#define OS_SYS_NS_TO_CYCLE(time, freq) (((time) / OS_SYS_NS_PER_SECOND) * (freq) + \
|
||||
((time) % OS_SYS_NS_PER_SECOND) * (freq) / OS_SYS_NS_PER_SECOND)
|
||||
|
||||
#define OS_SYS_TICK_TO_CYCLE(ticks) (((UINT64)(ticks) * g_sysClock) / LOSCFG_BASE_CORE_TICK_PER_SECOND)
|
||||
|
||||
#define OS_SYS_CYCLE_TO_TICK(cycle) ((((UINT64)(cycle)) * LOSCFG_BASE_CORE_TICK_PER_SECOND) / g_sysClock)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System time basic function error code: Null pointer.
|
||||
*
|
||||
* Value: 0x02000010
|
||||
*
|
||||
* Solution: Check whether the input parameter is null.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x10)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System time basic function error code: Invalid system clock configuration.
|
||||
*
|
||||
* Value: 0x02000011
|
||||
*
|
||||
* Solution: Configure a valid system clock in los_config.h.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_CLOCK_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x11)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System time basic function error code: This error code is not in use temporarily.
|
||||
*
|
||||
* Value: 0x02000012
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_MAXNUMOFCORES_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x12)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System time error code: This error code is not in use temporarily.
|
||||
*
|
||||
* Value: 0x02000013
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_PERIERRCOREID_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x13)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System time error code: This error code is not in use temporarily.
|
||||
*
|
||||
* Value: 0x02000014
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_HOOK_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x14)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System time error code: The Tick Timer must be registered before kernel initialization.
|
||||
*
|
||||
* Value: 0x02000015
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_TIMER_IS_RUNNING LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x15)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System time error code: The tick timer method is NULL.
|
||||
*
|
||||
* Value: 0x02000016
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_HOOK_IS_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x16)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System time error code: The tick timer addr fault.
|
||||
*
|
||||
* Value: 0x02000017
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_TIMER_ADDR_FAULT LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x16)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* system time structure.
|
||||
*/
|
||||
typedef struct TagSysTime {
|
||||
UINT16 uwYear; /**< value 1970 ~ 2038 or 1970 ~ 2100 */
|
||||
UINT8 ucMonth; /**< value 1 - 12 */
|
||||
UINT8 ucDay; /**< value 1 - 31 */
|
||||
UINT8 ucHour; /**< value 0 - 23 */
|
||||
UINT8 ucMinute; /**< value 0 - 59 */
|
||||
UINT8 ucSecond; /**< value 0 - 59 */
|
||||
UINT8 ucWeek; /**< value 0 - 6 */
|
||||
} SYS_TIME_S;
|
||||
|
||||
UINT64 OsTickTimerReload(UINT64 period);
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
VOID OsTickTimerBaseReset(UINT64 currTime);
|
||||
#endif
|
||||
|
||||
UINT32 OsTickTimerInit(VOID);
|
||||
|
||||
VOID OsTickSysTimerStartTimeSet(UINT64 currTime);
|
||||
|
||||
STATIC INLINE UINT64 OsTimeConvertFreq(UINT64 time, UINT32 oldFreq, UINT32 newFreq)
|
||||
{
|
||||
if (oldFreq >= newFreq) {
|
||||
return (time / (oldFreq / newFreq));
|
||||
}
|
||||
|
||||
return (time * (newFreq / oldFreq));
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Adjust the system tick timer clock frequency function hooks.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to adjust the system tick timer clock frequency.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param param [IN] Function parameters.
|
||||
*
|
||||
* @retval 0: Adjust the system tick timer clock frequency failed.
|
||||
* @retval more than zero: Adjust after the system tick timer clock frequency.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None
|
||||
*/
|
||||
typedef UINT32 (*SYS_TICK_FREQ_ADJUST_FUNC)(UINTPTR param);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Adjust the system tick timer clock frequency.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to adjust the system tick timer clock frequency.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This function needs to be invoked only when the clock frequency of the system tick timer adjust as a result of
|
||||
* changing the CPU frequency.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param handler [IN] Adjust the system tick timer clock frequency function hooks.
|
||||
* @param param [IN] Function parameters.
|
||||
*
|
||||
* @retval LOS_OK or Error code.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None
|
||||
*/
|
||||
extern UINT32 LOS_SysTickClockFreqAdjust(const SYS_TICK_FREQ_ADJUST_FUNC handler, UINTPTR param);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Obtain the number of Ticks.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the number of Ticks.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @retval UINT64 The number of Ticks.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None
|
||||
*/
|
||||
extern UINT64 LOS_TickCountGet(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Obtain the number of cycles in one second.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the number of cycles in one second.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @retval UINT32 Number of cycles obtained in one second.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None
|
||||
*/
|
||||
extern UINT32 LOS_CyclePerTickGet(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Convert Ticks to milliseconds.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to convert Ticks to milliseconds.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The number of milliseconds obtained through the conversion is 32-bit.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param ticks [IN] Number of Ticks. The value range is (0,OS_SYS_CLOCK).
|
||||
*
|
||||
* @retval UINT32 Number of milliseconds obtained through the conversion. Ticks are successfully converted to
|
||||
* milliseconds.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MS2Tick
|
||||
*/
|
||||
extern UINT32 LOS_Tick2MS(UINT32 ticks);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Convert milliseconds to Ticks.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to convert milliseconds to Ticks.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>If the parameter passed in is equal to 0xFFFFFFFF, the retval is 0xFFFFFFFF. Pay attention to the value to be
|
||||
* converted because data possibly overflows.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param millisec [IN] Number of milliseconds.
|
||||
*
|
||||
* @retval UINT32 Number of Ticks obtained through the conversion.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_Tick2MS
|
||||
*/
|
||||
extern UINT32 LOS_MS2Tick(UINT32 millisec);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Re-initializes the system tick timer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to re-initialize the system Tick timer.
|
||||
* @attention
|
||||
*
|
||||
* @param timer [IN] Specify the tick timer.
|
||||
* @param tickHandler [IN] Tick Interrupts the execution of the hook function.
|
||||
*
|
||||
* @retval LOS_OK or Error code.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern UINT32 LOS_TickTimerRegister(const ArchTickTimer *timer, const HWI_PROC_FUNC tickHandler);
|
||||
|
||||
/* *
|
||||
* @ingroup los_task
|
||||
* @brief: cpu delay.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to cpu delay, no task switching.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param UINT64 [IN] delay times, microseconds.
|
||||
*
|
||||
* @retval: None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID LOS_UDelay(UINT64 microseconds);
|
||||
|
||||
/* *
|
||||
* @ingroup los_task
|
||||
* @brief: cpu delay.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to cpu delay, no task switching.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param UINT32 [IN] delay times, millisecond.
|
||||
*
|
||||
* @retval: None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID LOS_MDelay(UINT32 millisec);
|
||||
|
||||
/* *
|
||||
* @ingroup los_task
|
||||
* @brief: cpu nanosecond get.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the current number of nanoseconds.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param none.
|
||||
*
|
||||
* @retval: None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT64 LOS_CurrNanosec(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Handle the system tick timeout.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is called when the system tick timeout and triggers the interrupt.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param none.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsTickHandler(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Define the CPU Tick structure.
|
||||
*/
|
||||
typedef struct TagCpuTick {
|
||||
UINT32 cntHi; /* < Upper 32 bits of the tick value */
|
||||
UINT32 cntLo; /* < Lower 32 bits of the tick value */
|
||||
} CpuTick;
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Number of operable bits of a 32-bit operand
|
||||
*/
|
||||
#define OS_SYS_MV_32_BIT 32
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Number of milliseconds in one second.
|
||||
*/
|
||||
#define OS_SYS_MS_PER_SECOND 1000
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Number of microseconds in one second.
|
||||
*/
|
||||
#define OS_SYS_US_PER_SECOND 1000000
|
||||
|
||||
#define OS_SYS_US_PER_MS 1000
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* The maximum length of name.
|
||||
*/
|
||||
#define OS_SYS_APPVER_NAME_MAX 64
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* The magic word.
|
||||
*/
|
||||
#define OS_SYS_MAGIC_WORD 0xAAAAAAAA
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* The initialization value of stack space.
|
||||
*/
|
||||
#define OS_SYS_EMPTY_STACK 0xCACACACA
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Convert cycles to milliseconds.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to convert cycles to milliseconds.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param cpuTick [IN] Number of CPU cycles.
|
||||
* @param msHi [OUT] Upper 32 bits of the number of milliseconds.
|
||||
* @param msLo [OUT] Lower 32 bits of the number of milliseconds.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SYS_PTR_NULL 0x02000011: Invalid parameter.
|
||||
* @retval #LOS_OK 0: Cycles are successfully converted to microseconds.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsCpuTick2MS(CpuTick *cpuTick, UINT32 *msHi, UINT32 *msLo);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Convert cycles to microseconds.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to convert cycles to microseconds.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param cpuTick [IN] Number of CPU cycles.
|
||||
* @param usHi [OUT] Upper 32 bits of the number of microseconds.
|
||||
* @param usLo [OUT] Lower 32 bits of the number of microseconds.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SYS_PTR_NULL 0x02000011: Invalid parameter.
|
||||
* @retval #LOS_OK 0: Cycles are successfully converted to microseconds.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsCpuTick2US(CpuTick *cpuTick, UINT32 *usHi, UINT32 *usLo);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Convert cycles to milliseconds.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to convert cycles to milliseconds.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param cycle [IN] Number of cycles.
|
||||
*
|
||||
* @retval Number of milliseconds obtained through the conversion. Cycles are successfully converted to milliseconds.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
STATIC_INLINE UINT64 OsCycle2MS(UINT64 cycle)
|
||||
{
|
||||
return (UINT64)((cycle / (g_sysClock / OS_SYS_MS_PER_SECOND)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Convert cycles to microseconds.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to convert cycles to microseconds.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param cycle [IN] Number of cycles.
|
||||
*
|
||||
* @retval Number of microseconds obtained through the conversion. Cycles are successfully converted to microseconds.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
STATIC_INLINE UINT64 OsCycle2US(UINT64 cycle)
|
||||
{
|
||||
UINT64 tmp = g_sysClock / OS_SYS_US_PER_SECOND;
|
||||
if (tmp == 0) {
|
||||
return 0;
|
||||
}
|
||||
return (UINT64)(cycle / tmp);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_TICK_H */
|
||||
222
ohos/kernel/liteos_m/kernel/src/los_event.c
Normal file
222
ohos/kernel/liteos_m/kernel/src/los_event.c
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_event.h"
|
||||
#include "los_hook.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB)
|
||||
{
|
||||
if (eventCB == NULL) {
|
||||
return LOS_ERRNO_EVENT_PTR_NULL;
|
||||
}
|
||||
eventCB->uwEventID = 0;
|
||||
LOS_ListInit(&eventCB->stEventList);
|
||||
OsHookCall(LOS_HOOK_TYPE_EVENT_INIT, eventCB);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_EventPoll(UINT32 *eventID, UINT32 eventMask, UINT32 mode)
|
||||
{
|
||||
UINT32 ret = 0;
|
||||
UINT32 intSave;
|
||||
|
||||
if (eventID == NULL) {
|
||||
return LOS_ERRNO_EVENT_PTR_NULL;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
if (mode & LOS_WAITMODE_OR) {
|
||||
if ((*eventID & eventMask) != 0) {
|
||||
ret = *eventID & eventMask;
|
||||
}
|
||||
} else {
|
||||
if ((eventMask != 0) && (eventMask == (*eventID & eventMask))) {
|
||||
ret = *eventID & eventMask;
|
||||
}
|
||||
}
|
||||
if (ret && (mode & LOS_WAITMODE_CLR)) {
|
||||
*eventID = *eventID & ~(ret);
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT STATIC_INLINE UINT32 OsEventReadParamCheck(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode)
|
||||
{
|
||||
if (eventCB == NULL) {
|
||||
return LOS_ERRNO_EVENT_PTR_NULL;
|
||||
}
|
||||
if ((eventCB->stEventList.pstNext == NULL) || (eventCB->stEventList.pstPrev == NULL)) {
|
||||
return LOS_ERRNO_EVENT_NOT_INITIALIZED;
|
||||
}
|
||||
if (eventMask == 0) {
|
||||
return LOS_ERRNO_EVENT_EVENTMASK_INVALID;
|
||||
}
|
||||
if (eventMask & LOS_ERRTYPE_ERROR) {
|
||||
return LOS_ERRNO_EVENT_SETBIT_INVALID;
|
||||
}
|
||||
if (((mode & LOS_WAITMODE_OR) && (mode & LOS_WAITMODE_AND)) ||
|
||||
(mode & ~(LOS_WAITMODE_OR | LOS_WAITMODE_AND | LOS_WAITMODE_CLR)) ||
|
||||
!(mode & (LOS_WAITMODE_OR | LOS_WAITMODE_AND))) {
|
||||
return LOS_ERRNO_EVENT_FLAGS_INVALID;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeOut)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
LosTaskCB *runTsk = NULL;
|
||||
|
||||
ret = OsEventReadParamCheck(eventCB, eventMask, mode);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
return LOS_ERRNO_EVENT_READ_IN_INTERRUPT;
|
||||
}
|
||||
if (g_losTask.runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
|
||||
return LOS_ERRNO_EVENT_READ_IN_SYSTEM_TASK;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
ret = LOS_EventPoll(&(eventCB->uwEventID), eventMask, mode);
|
||||
OsHookCall(LOS_HOOK_TYPE_EVENT_READ, eventCB, eventMask, mode, timeOut);
|
||||
if (ret == 0) {
|
||||
if (timeOut == 0) {
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (g_losTaskLock) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_EVENT_READ_IN_LOCK;
|
||||
}
|
||||
runTsk = g_losTask.runTask;
|
||||
runTsk->eventMask = eventMask;
|
||||
runTsk->eventMode = mode;
|
||||
OsSchedTaskWait(&eventCB->stEventList, timeOut);
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (runTsk->taskStatus & OS_TASK_STATUS_TIMEOUT) {
|
||||
runTsk->taskStatus &= ~OS_TASK_STATUS_TIMEOUT;
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_EVENT_READ_TIMEOUT;
|
||||
}
|
||||
|
||||
ret = LOS_EventPoll(&eventCB->uwEventID, eventMask, mode);
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events)
|
||||
{
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
LosTaskCB *nextTask = (LosTaskCB *)NULL;
|
||||
UINT32 intSave;
|
||||
UINT8 exitFlag = 0;
|
||||
if (eventCB == NULL) {
|
||||
return LOS_ERRNO_EVENT_PTR_NULL;
|
||||
}
|
||||
if ((eventCB->stEventList.pstNext == NULL) || (eventCB->stEventList.pstPrev == NULL)) {
|
||||
return LOS_ERRNO_EVENT_NOT_INITIALIZED;
|
||||
}
|
||||
if (events & LOS_ERRTYPE_ERROR) {
|
||||
return LOS_ERRNO_EVENT_SETBIT_INVALID;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
OsHookCall(LOS_HOOK_TYPE_EVENT_WRITE, eventCB, events);
|
||||
eventCB->uwEventID |= events;
|
||||
if (!LOS_ListEmpty(&eventCB->stEventList)) {
|
||||
for (resumedTask = LOS_DL_LIST_ENTRY((&eventCB->stEventList)->pstNext, LosTaskCB, pendList);
|
||||
&resumedTask->pendList != (&eventCB->stEventList);) {
|
||||
nextTask = LOS_DL_LIST_ENTRY(resumedTask->pendList.pstNext, LosTaskCB, pendList);
|
||||
|
||||
if (((resumedTask->eventMode & LOS_WAITMODE_OR) && (resumedTask->eventMask & events) != 0) ||
|
||||
((resumedTask->eventMode & LOS_WAITMODE_AND) &&
|
||||
((resumedTask->eventMask & eventCB->uwEventID) == resumedTask->eventMask))) {
|
||||
exitFlag = 1;
|
||||
|
||||
OsSchedTaskWake(resumedTask);
|
||||
}
|
||||
resumedTask = nextTask;
|
||||
}
|
||||
|
||||
if (exitFlag == 1) {
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
return LOS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (eventCB == NULL) {
|
||||
return LOS_ERRNO_EVENT_PTR_NULL;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
if (!LOS_ListEmpty(&eventCB->stEventList)) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_EVENT_SHOULD_NOT_DESTROYED;
|
||||
}
|
||||
eventCB->stEventList.pstNext = (LOS_DL_LIST *)NULL;
|
||||
eventCB->stEventList.pstPrev = (LOS_DL_LIST *)NULL;
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_EVENT_DESTROY, eventCB);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 eventMask)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (eventCB == NULL) {
|
||||
return LOS_ERRNO_EVENT_PTR_NULL;
|
||||
}
|
||||
OsHookCall(LOS_HOOK_TYPE_EVENT_CLEAR, eventCB, eventMask);
|
||||
intSave = LOS_IntLock();
|
||||
eventCB->uwEventID &= eventMask;
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
287
ohos/kernel/liteos_m/kernel/src/los_init.c
Normal file
287
ohos/kernel/liteos_m/kernel/src/los_init.c
Normal file
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 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 "stdarg.h"
|
||||
#include "los_arch.h"
|
||||
#include "los_config.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_mux.h"
|
||||
#include "los_queue.h"
|
||||
#include "los_sem.h"
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI == 1)
|
||||
#include "los_interrupt.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
#include "los_swtmr.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_CPUP == 1)
|
||||
#include "los_cpup.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
#include "los_exc_info.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BACKTRACE_TYPE != 0)
|
||||
#include "los_backtrace.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_PM == 1)
|
||||
#include "los_pm.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DYNLINK == 1)
|
||||
#include "los_dynlink.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_LMS
|
||||
#include "los_lms_pri.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_LMK == 1)
|
||||
#include "los_lmk.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_POSIX_PIPE_API == 1)
|
||||
#include "pipe_impl.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_SIGNAL == 1)
|
||||
#include "los_signal.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_SECURE == 1)
|
||||
#include "los_syscall.h"
|
||||
#include "los_box.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_FS_VFS == 1)
|
||||
#include "vfs_operations.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_TRACE == 1)
|
||||
#include "los_trace_pri.h"
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_Reboot
|
||||
Description : system exception, die in here, wait for watchdog.
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT VOID LOS_Reboot(VOID)
|
||||
{
|
||||
OsDoExcHook(EXC_REBOOT);
|
||||
ArchSysExit();
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID LOS_Panic(const CHAR *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
PRINT_ERR(fmt, ap);
|
||||
va_end(ap);
|
||||
OsDoExcHook(EXC_PANIC);
|
||||
#if (LOSCFG_BACKTRACE_TYPE != 0)
|
||||
LOS_BackTrace();
|
||||
#endif
|
||||
ArchSysExit();
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_Start(VOID)
|
||||
{
|
||||
return ArchStartSchedule();
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_KernelInit
|
||||
Description : System kernel initialization function, configure all system modules
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
PRINTK("entering kernel init...\n");
|
||||
|
||||
#if (LOSCFG_BACKTRACE_TYPE != 0)
|
||||
OsBackTraceInit();
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_LMS
|
||||
OsLmsInit();
|
||||
#endif
|
||||
#if LOSCFG_BASE_CORE_MEMPOOL
|
||||
ret = OsMemSystemInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("OsMemSystemInit error %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
ArchInit();
|
||||
|
||||
ret = OsTickTimerInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("OsTickTimerInit error! 0x%x\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = OsTaskInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("OsTaskInit error\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TSK_MONITOR == 1)
|
||||
OsTaskMonInit();
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_CPUP == 1)
|
||||
ret = OsCpupInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("OsCpupInit error\n");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_IPC_SEM == 1)
|
||||
ret = OsSemInit();
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_IPC_MUX == 1)
|
||||
ret = OsMuxInit();
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_IPC_QUEUE == 1)
|
||||
ret = OsQueueInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("OsQueueInit error\n");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
ret = OsSwtmrInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("OsSwtmrInit error\n");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
|
||||
ret = OsCpupDaemonInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("OsCpupDaemonInit error\n");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_FS_VFS == 1)
|
||||
ret = OsVfsInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("OsVfsInit error\n");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = OsIdleTaskCreate();
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_TRACE == 1)
|
||||
ret = OsTraceInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("OsTraceInit error\n");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_PM == 1)
|
||||
ret = OsPmInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Pm init failed!\n");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_LMK == 1)
|
||||
OsLmkInit();
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
OsExcMsgDumpInit();
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DYNLINK == 1)
|
||||
ret = LOS_DynlinkInit();
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_POSIX_PIPE_API == 1)
|
||||
ret = OsPipeInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Pipe init failed!\n");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_SIGNAL == 1)
|
||||
ret = OsSignalInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Signal init failed!\n");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_SECURE == 1)
|
||||
OsSyscallHandleInit();
|
||||
LOS_BoxStart();
|
||||
#endif
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
347
ohos/kernel/liteos_m/kernel/src/los_mux.c
Normal file
347
ohos/kernel/liteos_m/kernel/src/los_mux.c
Normal file
@@ -0,0 +1,347 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_mux.h"
|
||||
#include "los_config.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_hook.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_sched.h"
|
||||
|
||||
#if (LOSCFG_BASE_IPC_MUX == 1)
|
||||
|
||||
LITE_OS_SEC_BSS LosMuxCB* g_allMux = NULL;
|
||||
LITE_OS_SEC_DATA_INIT LOS_DL_LIST g_unusedMuxList;
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsMuxInit
|
||||
Description : Initializes the mutex
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsMuxInit(VOID)
|
||||
{
|
||||
LosMuxCB *muxNode = NULL;
|
||||
UINT32 index;
|
||||
|
||||
LOS_ListInit(&g_unusedMuxList);
|
||||
|
||||
if (LOSCFG_BASE_IPC_MUX_LIMIT == 0) {
|
||||
return LOS_ERRNO_MUX_MAXNUM_ZERO;
|
||||
}
|
||||
|
||||
g_allMux = (LosMuxCB *)LOS_MemAlloc(m_aucSysMem0, (LOSCFG_BASE_IPC_MUX_LIMIT * sizeof(LosMuxCB)));
|
||||
if (g_allMux == NULL) {
|
||||
return LOS_ERRNO_MUX_NO_MEMORY;
|
||||
}
|
||||
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_MUX_LIMIT; index++) {
|
||||
muxNode = ((LosMuxCB *)g_allMux) + index;
|
||||
muxNode->muxID = index;
|
||||
muxNode->owner = (LosTaskCB *)NULL;
|
||||
muxNode->muxStat = OS_MUX_UNUSED;
|
||||
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
|
||||
muxNode->createInfo = 0;
|
||||
#endif
|
||||
LOS_ListTailInsert(&g_unusedMuxList, &muxNode->muxList);
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_MuxCreate
|
||||
Description : Create a mutex
|
||||
Input : None
|
||||
Output : muxHandle ------ Mutex operation handle
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_MuxCreate(UINT32 *muxHandle)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosMuxCB *muxCreated = NULL;
|
||||
LOS_DL_LIST *unusedMux = NULL;
|
||||
UINT32 errNo;
|
||||
UINT32 errLine;
|
||||
|
||||
if (muxHandle == NULL) {
|
||||
return LOS_ERRNO_MUX_PTR_NULL;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (LOS_ListEmpty(&g_unusedMuxList)) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_ALL_BUSY);
|
||||
}
|
||||
|
||||
unusedMux = LOS_DL_LIST_FIRST(&(g_unusedMuxList));
|
||||
LOS_ListDelete(unusedMux);
|
||||
muxCreated = (GET_MUX_LIST(unusedMux));
|
||||
muxCreated->muxCount = 0;
|
||||
muxCreated->muxStat = OS_MUX_USED;
|
||||
muxCreated->priority = 0;
|
||||
muxCreated->owner = (LosTaskCB *)NULL;
|
||||
LOS_ListInit(&muxCreated->muxList);
|
||||
*muxHandle = (UINT32)muxCreated->muxID;
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_MUX_CREATE, muxCreated);
|
||||
return LOS_OK;
|
||||
ERR_HANDLER:
|
||||
OS_RETURN_ERROR_P2(errLine, errNo);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_MuxDelete
|
||||
Description : Delete a mutex
|
||||
Input : muxHandle ------Mutex operation handle
|
||||
Output : None
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_MuxDelete(UINT32 muxHandle)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosMuxCB *muxDeleted = NULL;
|
||||
UINT32 errNo;
|
||||
UINT32 errLine;
|
||||
|
||||
if (muxHandle >= (UINT32)LOSCFG_BASE_IPC_MUX_LIMIT) {
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_INVALID);
|
||||
}
|
||||
|
||||
muxDeleted = GET_MUX(muxHandle);
|
||||
intSave = LOS_IntLock();
|
||||
if (muxDeleted->muxStat == OS_MUX_UNUSED) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_INVALID);
|
||||
}
|
||||
|
||||
if ((!LOS_ListEmpty(&muxDeleted->muxList)) || muxDeleted->muxCount) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_PENDED);
|
||||
}
|
||||
|
||||
LOS_ListAdd(&g_unusedMuxList, &muxDeleted->muxList);
|
||||
muxDeleted->muxStat = OS_MUX_UNUSED;
|
||||
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
|
||||
muxDeleted->createInfo = 0;
|
||||
#endif
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_MUX_DELETE, muxDeleted);
|
||||
return LOS_OK;
|
||||
ERR_HANDLER:
|
||||
OS_RETURN_ERROR_P2(errLine, errNo);
|
||||
}
|
||||
|
||||
STATIC_INLINE UINT32 OsMuxValidCheck(LosMuxCB *muxPended)
|
||||
{
|
||||
if (muxPended->muxStat == OS_MUX_UNUSED) {
|
||||
return LOS_ERRNO_MUX_INVALID;
|
||||
}
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
return LOS_ERRNO_MUX_IN_INTERR;
|
||||
}
|
||||
|
||||
if (g_losTaskLock) {
|
||||
PRINT_ERR("!!!LOS_ERRNO_MUX_PEND_IN_LOCK!!!\n");
|
||||
return LOS_ERRNO_MUX_PEND_IN_LOCK;
|
||||
}
|
||||
|
||||
if (g_losTask.runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
|
||||
return LOS_ERRNO_MUX_PEND_IN_SYSTEM_TASK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#ifdef MUTEX_LOCKERR_MAX
|
||||
extern uint32_t mutex_lockerr_list[MUTEX_LOCKERR_MAX];
|
||||
extern uint32_t mutex_lockerr_cnt;
|
||||
void LOS_MUX_Lockerr(k_mutex_handle_t mutex_handle, uint32_t lr)
|
||||
{
|
||||
int i = 0;
|
||||
for(i=0; i<mutex_lockerr_cnt; i++){
|
||||
if(mutex_lockerr_list[i] == lr){
|
||||
return;
|
||||
}
|
||||
}
|
||||
mutex_lockerr_list[mutex_lockerr_cnt++] = lr;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_MuxPend
|
||||
Description : Specify the mutex P operation
|
||||
Input : muxHandle ------ Mutex operation handleone
|
||||
: timeOut ------- waiting time
|
||||
Output : None
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout, UINT32 lr)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosMuxCB *muxPended = NULL;
|
||||
UINT32 retErr;
|
||||
LosTaskCB *runningTask = NULL;
|
||||
UINT32 lockerr = LOS_IntLocked();
|
||||
|
||||
if (muxHandle >= (UINT32)LOSCFG_BASE_IPC_MUX_LIMIT) {
|
||||
OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
|
||||
}
|
||||
|
||||
muxPended = GET_MUX(muxHandle);
|
||||
intSave = LOS_IntLock();
|
||||
retErr = OsMuxValidCheck(muxPended);
|
||||
if (retErr || lockerr) {
|
||||
#ifdef MUTEX_LOCKERR_MAX
|
||||
LOS_MUX_Lockerr(lr);
|
||||
#endif
|
||||
goto ERROR_MUX_PEND;
|
||||
}
|
||||
|
||||
runningTask = (LosTaskCB *)g_losTask.runTask;
|
||||
if (muxPended->muxCount == 0) {
|
||||
muxPended->muxCount++;
|
||||
muxPended->owner = runningTask;
|
||||
muxPended->priority = runningTask->priority;
|
||||
LOS_IntRestore(intSave);
|
||||
goto HOOK;
|
||||
}
|
||||
|
||||
if (muxPended->owner == runningTask) {
|
||||
muxPended->muxCount++;
|
||||
LOS_IntRestore(intSave);
|
||||
goto HOOK;
|
||||
}
|
||||
|
||||
if (!timeout) {
|
||||
retErr = LOS_ERRNO_MUX_UNAVAILABLE;
|
||||
goto ERROR_MUX_PEND;
|
||||
}
|
||||
|
||||
runningTask->taskMux = (VOID *)muxPended;
|
||||
|
||||
if (muxPended->owner->priority > runningTask->priority) {
|
||||
(VOID)OsSchedModifyTaskSchedParam(muxPended->owner, runningTask->priority);
|
||||
}
|
||||
|
||||
OsSchedTaskWait(&muxPended->muxList, timeout);
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_MUX_PEND, muxPended, timeout);
|
||||
LOS_Schedule();
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (runningTask->taskStatus & OS_TASK_STATUS_TIMEOUT) {
|
||||
runningTask->taskStatus &= (~OS_TASK_STATUS_TIMEOUT);
|
||||
retErr = LOS_ERRNO_MUX_TIMEOUT;
|
||||
goto ERROR_MUX_PEND;
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
|
||||
HOOK:
|
||||
OsHookCall(LOS_HOOK_TYPE_MUX_PEND, muxPended, timeout);
|
||||
return LOS_OK;
|
||||
|
||||
ERROR_MUX_PEND:
|
||||
LOS_IntRestore(intSave);
|
||||
OS_RETURN_ERROR(retErr);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_MuxPost
|
||||
Description : Specify the mutex V operation,
|
||||
Input : muxHandle ------ Mutex operation handle
|
||||
Output : None
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_MuxPost(UINT32 muxHandle)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosMuxCB *muxPosted = GET_MUX(muxHandle);
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
LosTaskCB *runningTask = NULL;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
if ((muxHandle >= (UINT32)LOSCFG_BASE_IPC_MUX_LIMIT) ||
|
||||
(muxPosted->muxStat == OS_MUX_UNUSED)) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
|
||||
}
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_RETURN_ERROR(LOS_ERRNO_MUX_IN_INTERR);
|
||||
}
|
||||
|
||||
runningTask = (LosTaskCB *)g_losTask.runTask;
|
||||
if ((muxPosted->muxCount == 0) || (muxPosted->owner != runningTask)) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
|
||||
}
|
||||
|
||||
if (--(muxPosted->muxCount) != 0) {
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_MUX_POST, muxPosted);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if ((muxPosted->owner->priority) != muxPosted->priority) {
|
||||
(VOID)OsSchedModifyTaskSchedParam(muxPosted->owner, muxPosted->priority);
|
||||
}
|
||||
|
||||
if (!LOS_ListEmpty(&muxPosted->muxList)) {
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(muxPosted->muxList)));
|
||||
|
||||
muxPosted->muxCount = 1;
|
||||
muxPosted->owner = resumedTask;
|
||||
muxPosted->priority = resumedTask->priority;
|
||||
resumedTask->taskMux = NULL;
|
||||
|
||||
OsSchedTaskWake(resumedTask);
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_MUX_POST, muxPosted);
|
||||
LOS_Schedule();
|
||||
} else {
|
||||
muxPosted->owner = NULL;
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#endif /* (LOSCFG_BASE_IPC_MUX == 1) */
|
||||
801
ohos/kernel/liteos_m/kernel/src/los_queue.c
Normal file
801
ohos/kernel/liteos_m/kernel/src/los_queue.c
Normal file
@@ -0,0 +1,801 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 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_queue.h"
|
||||
#include "securec.h"
|
||||
#include "los_config.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_hook.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_membox.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#if (LOSCFG_BASE_IPC_QUEUE == 1)
|
||||
|
||||
LITE_OS_SEC_BSS LosQueueCB *g_allQueue = NULL ;
|
||||
LITE_OS_SEC_BSS LOS_DL_LIST g_freeQueueList;
|
||||
|
||||
#if (LOSCFG_BASE_IPC_QUEUE_STATIC == 1)
|
||||
LITE_OS_SEC_BSS LosQueueCB *g_staticQueue = NULL ;
|
||||
LITE_OS_SEC_BSS LOS_DL_LIST g_freeStaticQueueList;
|
||||
#endif
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsQueueInit
|
||||
Description : queue initial
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID)
|
||||
{
|
||||
LosQueueCB *queueNode = NULL;
|
||||
UINT16 index;
|
||||
|
||||
#if (LOSCFG_BASE_IPC_QUEUE_STATIC == 1)
|
||||
LosQueueCB *queueNodeStatic = NULL;
|
||||
#endif
|
||||
|
||||
if (OS_ALL_IPC_QUEUE_LIMIT == 0) {
|
||||
return LOS_ERRNO_QUEUE_MAXNUM_ZERO;
|
||||
}
|
||||
|
||||
g_allQueue = (LosQueueCB *)LOS_MemAlloc(m_aucSysMem0, LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(LosQueueCB));
|
||||
if (g_allQueue == NULL) {
|
||||
return LOS_ERRNO_QUEUE_NO_MEMORY;
|
||||
}
|
||||
|
||||
(VOID)memset_s(g_allQueue, LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(LosQueueCB),
|
||||
0, LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(LosQueueCB));
|
||||
|
||||
LOS_ListInit(&g_freeQueueList);
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) {
|
||||
queueNode = ((LosQueueCB *)g_allQueue) + index;
|
||||
queueNode->queueID = index;
|
||||
LOS_ListTailInsert(&g_freeQueueList, &queueNode->readWriteList[OS_QUEUE_WRITE]);
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_IPC_QUEUE_STATIC == 1)
|
||||
g_staticQueue = (LosQueueCB *)LOS_MemAlloc(m_aucSysMem0, LOSCFG_BASE_IPC_STATIC_QUEUE_LIMIT * sizeof(LosQueueCB));
|
||||
if (g_staticQueue == NULL) {
|
||||
return LOS_ERRNO_QUEUE_NO_MEMORY;
|
||||
}
|
||||
|
||||
(VOID)memset_s(g_staticQueue, LOSCFG_BASE_IPC_STATIC_QUEUE_LIMIT * sizeof(LosQueueCB),
|
||||
0, LOSCFG_BASE_IPC_STATIC_QUEUE_LIMIT * sizeof(LosQueueCB));
|
||||
|
||||
LOS_ListInit(&g_freeStaticQueueList);
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_STATIC_QUEUE_LIMIT; index++) {
|
||||
queueNodeStatic = ((LosQueueCB *)g_staticQueue) + index;
|
||||
queueNodeStatic->queueID = index + LOSCFG_BASE_IPC_QUEUE_LIMIT;
|
||||
LOS_ListTailInsert(&g_freeStaticQueueList, &queueNodeStatic->readWriteList[OS_QUEUE_WRITE]);
|
||||
}
|
||||
#endif
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
|
||||
static UINT32 OsQueueCreate(const CHAR *queueName,
|
||||
UINT16 len,
|
||||
UINT32 *queueID,
|
||||
UINT8 *staticMem,
|
||||
UINT32 flags,
|
||||
UINT16 maxMsgSize)
|
||||
{
|
||||
LosQueueCB *queueCB = NULL;
|
||||
UINT32 intSave;
|
||||
LOS_DL_LIST *unusedQueue = NULL;
|
||||
UINT8 *queue = NULL;
|
||||
UINT16 msgSize;
|
||||
|
||||
(VOID)flags;
|
||||
|
||||
if (queueID == NULL) {
|
||||
return LOS_ERRNO_QUEUE_CREAT_PTR_NULL;
|
||||
}
|
||||
|
||||
if (maxMsgSize > (OS_NULL_SHORT - sizeof(UINT32))) {
|
||||
return LOS_ERRNO_QUEUE_SIZE_TOO_BIG;
|
||||
}
|
||||
|
||||
if ((len == 0) || (maxMsgSize == 0)) {
|
||||
return LOS_ERRNO_QUEUE_PARA_ISZERO;
|
||||
}
|
||||
msgSize = maxMsgSize + sizeof(UINT32);
|
||||
|
||||
/* Memory allocation is time-consuming, to shorten the time of disable interrupt,
|
||||
move the memory allocation to here. */
|
||||
if ((UINT32_MAX / msgSize) < len) {
|
||||
return LOS_ERRNO_QUEUE_SIZE_TOO_BIG;
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_IPC_QUEUE_STATIC == 1)
|
||||
if (staticMem != NULL) {
|
||||
queue = staticMem;
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
if (LOS_ListEmpty(&g_freeStaticQueueList)) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_QUEUE_CB_UNAVAILABLE;
|
||||
}
|
||||
unusedQueue = LOS_DL_LIST_FIRST(&(g_freeStaticQueueList));
|
||||
} else {
|
||||
queue = (UINT8 *)LOS_MemAlloc(m_aucSysMem0, (UINT32)len * msgSize);
|
||||
if (queue == NULL) {
|
||||
return LOS_ERRNO_QUEUE_CREATE_NO_MEMORY;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (LOS_ListEmpty(&g_freeQueueList)) {
|
||||
LOS_IntRestore(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, queue);
|
||||
return LOS_ERRNO_QUEUE_CB_UNAVAILABLE;
|
||||
}
|
||||
unusedQueue = LOS_DL_LIST_FIRST(&(g_freeQueueList));
|
||||
}
|
||||
#else
|
||||
queue = (UINT8 *)LOS_MemAlloc(m_aucSysMem0, (UINT32)len * msgSize);
|
||||
if (queue == NULL) {
|
||||
return LOS_ERRNO_QUEUE_CREATE_NO_MEMORY;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (LOS_ListEmpty(&g_freeQueueList)) {
|
||||
LOS_IntRestore(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, queue);
|
||||
return LOS_ERRNO_QUEUE_CB_UNAVAILABLE;
|
||||
}
|
||||
unusedQueue = LOS_DL_LIST_FIRST(&(g_freeQueueList));
|
||||
#endif
|
||||
|
||||
LOS_ListDelete(unusedQueue);
|
||||
queueCB = (GET_QUEUE_LIST(unusedQueue));
|
||||
queueCB->queueName = (UINT8 *)queueName; // The name can be null
|
||||
queueCB->queueLen = len;
|
||||
queueCB->queueSize = msgSize;
|
||||
queueCB->queue = queue;
|
||||
queueCB->queueState = OS_QUEUE_INUSED;
|
||||
queueCB->readWriteableCnt[OS_QUEUE_READ] = 0;
|
||||
queueCB->readWriteableCnt[OS_QUEUE_WRITE] = len;
|
||||
queueCB->queueHead = 0;
|
||||
queueCB->queueTail = 0;
|
||||
LOS_ListInit(&queueCB->readWriteList[OS_QUEUE_READ]);
|
||||
LOS_ListInit(&queueCB->readWriteList[OS_QUEUE_WRITE]);
|
||||
LOS_ListInit(&queueCB->memList);
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
*queueID = queueCB->queueID;
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_QUEUE_CREATE, queueCB);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_QueueCreateStatic
|
||||
Description : Create a queue use static menory
|
||||
Input : queueName --- Queue name, less than 4 characters
|
||||
: len --- Queue length
|
||||
: queueMem --- Queue static memory for data storage
|
||||
: flags --- Queue type, FIFO or PRIO
|
||||
: maxMsgSize --- Maximum message size in byte
|
||||
Output : queueID --- Queue ID
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
#if (LOSCFG_BASE_IPC_QUEUE_STATIC == 1)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreateStatic(const CHAR *queueName,
|
||||
UINT16 len,
|
||||
UINT32 *queueID,
|
||||
UINT8 *staticMem,
|
||||
UINT32 flags,
|
||||
UINT16 maxMsgSize)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
(VOID)flags;
|
||||
|
||||
ret = OsQueueCreate(queueName, len, queueID, staticMem, 0, maxMsgSize);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_QueueCreate
|
||||
Description : Create a queue
|
||||
Input : queueName --- Queue name, less than 4 characters
|
||||
: len --- Queue length
|
||||
: flags --- Queue type, FIFO or PRIO
|
||||
: maxMsgSize --- Maximum message size in byte
|
||||
Output : queueID --- Queue ID
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(const CHAR *queueName,
|
||||
UINT16 len,
|
||||
UINT32 *queueID,
|
||||
UINT32 flags,
|
||||
UINT16 maxMsgSize)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
(VOID)flags;
|
||||
|
||||
ret = OsQueueCreate(queueName, len, queueID, NULL, 0, maxMsgSize);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static INLINE LITE_OS_SEC_TEXT UINT32 OsQueueReadParameterCheck(UINT32 queueID, VOID *bufferAddr,
|
||||
UINT32 *bufferSize, UINT32 timeOut)
|
||||
{
|
||||
if (queueID >= OS_ALL_IPC_QUEUE_LIMIT) {
|
||||
return LOS_ERRNO_QUEUE_INVALID;
|
||||
}
|
||||
if ((bufferAddr == NULL) || (bufferSize == NULL)) {
|
||||
return LOS_ERRNO_QUEUE_READ_PTR_NULL;
|
||||
}
|
||||
|
||||
if (*bufferSize == 0) {
|
||||
return LOS_ERRNO_QUEUE_READSIZE_ISZERO;
|
||||
}
|
||||
|
||||
if (timeOut != LOS_NO_WAIT) {
|
||||
if (OS_INT_ACTIVE) {
|
||||
return LOS_ERRNO_QUEUE_READ_IN_INTERRUPT;
|
||||
}
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
static INLINE LITE_OS_SEC_TEXT UINT32 OsQueueWriteParameterCheck(UINT32 queueID, VOID *bufferAddr,
|
||||
UINT32 *bufferSize, UINT32 timeOut)
|
||||
{
|
||||
if (queueID >= OS_ALL_IPC_QUEUE_LIMIT) {
|
||||
return LOS_ERRNO_QUEUE_INVALID;
|
||||
}
|
||||
|
||||
if (bufferAddr == NULL) {
|
||||
return LOS_ERRNO_QUEUE_WRITE_PTR_NULL;
|
||||
}
|
||||
|
||||
if (*bufferSize == 0) {
|
||||
return LOS_ERRNO_QUEUE_WRITESIZE_ISZERO;
|
||||
}
|
||||
|
||||
if (timeOut != LOS_NO_WAIT) {
|
||||
if (OS_INT_ACTIVE) {
|
||||
return LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT;
|
||||
}
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
static INLINE VOID OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType,
|
||||
VOID *bufferAddr, UINT32 *bufferSize)
|
||||
{
|
||||
UINT8 *queueNode = NULL;
|
||||
UINT32 msgDataSize;
|
||||
UINT16 queuePosition;
|
||||
errno_t rc;
|
||||
|
||||
/* get the queue position */
|
||||
switch (OS_QUEUE_OPERATE_GET(operateType)) {
|
||||
case OS_QUEUE_READ_HEAD:
|
||||
queuePosition = queueCB->queueHead;
|
||||
((queueCB->queueHead + 1) == queueCB->queueLen) ? (queueCB->queueHead = 0) : (queueCB->queueHead++);
|
||||
break;
|
||||
|
||||
case OS_QUEUE_WRITE_HEAD:
|
||||
(queueCB->queueHead == 0) ? (queueCB->queueHead = (queueCB->queueLen - 1)) : (--queueCB->queueHead);
|
||||
queuePosition = queueCB->queueHead;
|
||||
break;
|
||||
|
||||
case OS_QUEUE_WRITE_TAIL:
|
||||
queuePosition = queueCB->queueTail;
|
||||
((queueCB->queueTail + 1) == queueCB->queueLen) ? (queueCB->queueTail = 0) : (queueCB->queueTail++);
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_ERR("invalid queue operate type!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
queueNode = &(queueCB->queue[(queuePosition * (queueCB->queueSize))]);
|
||||
|
||||
if (OS_QUEUE_IS_POINT(operateType)) {
|
||||
if (OS_QUEUE_IS_READ(operateType)) {
|
||||
*(UINTPTR *)bufferAddr = *(UINTPTR *)(VOID *)queueNode;
|
||||
} else {
|
||||
*(UINTPTR *)(VOID *)queueNode = *(UINTPTR *)bufferAddr;
|
||||
}
|
||||
} else {
|
||||
if (OS_QUEUE_IS_READ(operateType)) {
|
||||
msgDataSize = *((UINT32 *)(UINTPTR)((queueNode + queueCB->queueSize) - sizeof(UINT32)));
|
||||
msgDataSize = (*bufferSize < msgDataSize) ? *bufferSize : msgDataSize;
|
||||
rc = memcpy_s((VOID *)bufferAddr, *bufferSize, (VOID *)queueNode, msgDataSize);
|
||||
if (rc != EOK) {
|
||||
PRINT_ERR("%s[%d] memcpy failed, error type = %u\n", __FUNCTION__, __LINE__, rc);
|
||||
return;
|
||||
}
|
||||
|
||||
*bufferSize = msgDataSize;
|
||||
} else {
|
||||
*((UINT32 *)(UINTPTR)((queueNode + queueCB->queueSize) - sizeof(UINT32))) = *bufferSize;
|
||||
rc = memcpy_s((VOID *)queueNode, queueCB->queueSize, (VOID *)bufferAddr, *bufferSize);
|
||||
if (rc != EOK) {
|
||||
PRINT_ERR("%s[%d] memcpy failed, error type = %u\n", __FUNCTION__, __LINE__, rc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE UINT32 OsQueueOperateParamCheck(const LosQueueCB *queueCB, UINT32 operateType, const UINT32 *bufferSize)
|
||||
{
|
||||
if (queueCB->queueState == OS_QUEUE_UNUSED) {
|
||||
return LOS_ERRNO_QUEUE_NOT_CREATE;
|
||||
}
|
||||
|
||||
if (OS_QUEUE_IS_WRITE(operateType) && (*bufferSize > (queueCB->queueSize - sizeof(UINT32)))) {
|
||||
return LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG;
|
||||
}
|
||||
|
||||
if (*bufferSize >= SECUREC_MEM_MAX_LEN) {
|
||||
return LOS_ERRNO_QUEUE_BUFFER_SIZE_TOO_BIG;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize, UINT32 timeOut)
|
||||
{
|
||||
LosQueueCB *queueCB = NULL;
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
UINT32 ret;
|
||||
UINT32 readWrite = OS_QUEUE_READ_WRITE_GET(operateType);
|
||||
UINT32 readWriteTmp = !readWrite;
|
||||
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
|
||||
queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID);
|
||||
ret = OsQueueOperateParamCheck(queueCB, operateType, bufferSize);
|
||||
if (ret != LOS_OK) {
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
if (queueCB->readWriteableCnt[readWrite] == 0) {
|
||||
if (timeOut == LOS_NO_WAIT) {
|
||||
ret = OS_QUEUE_IS_READ(operateType) ? LOS_ERRNO_QUEUE_ISEMPTY : LOS_ERRNO_QUEUE_ISFULL;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
if (g_losTaskLock) {
|
||||
ret = LOS_ERRNO_QUEUE_PEND_IN_LOCK;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
LosTaskCB *runTsk = (LosTaskCB *)g_losTask.runTask;
|
||||
OsSchedTaskWait(&queueCB->readWriteList[readWrite], timeOut);
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (runTsk->taskStatus & OS_TASK_STATUS_TIMEOUT) {
|
||||
runTsk->taskStatus &= ~OS_TASK_STATUS_TIMEOUT;
|
||||
ret = LOS_ERRNO_QUEUE_TIMEOUT;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
} else {
|
||||
queueCB->readWriteableCnt[readWrite]--;
|
||||
}
|
||||
|
||||
OsQueueBufferOperate(queueCB, operateType, bufferAddr, bufferSize);
|
||||
|
||||
if (!LOS_ListEmpty(&queueCB->readWriteList[readWriteTmp])) {
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&queueCB->readWriteList[readWriteTmp]));
|
||||
OsSchedTaskWake(resumedTask);
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
return LOS_OK;
|
||||
} else {
|
||||
queueCB->readWriteableCnt[readWriteTmp]++;
|
||||
}
|
||||
|
||||
QUEUE_END:
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_QueueReadCopy(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 *bufferSize,
|
||||
UINT32 timeOut)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 operateType;
|
||||
|
||||
ret = OsQueueReadParameterCheck(queueID, bufferAddr, bufferSize, timeOut);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_READ, OS_QUEUE_HEAD, OS_QUEUE_NOT_POINT);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_QUEUE_READ_COPY, (LosQueueCB *)GET_QUEUE_HANDLE(queueID),
|
||||
operateType, *bufferSize, timeOut);
|
||||
|
||||
return OsQueueOperate(queueID, operateType, bufferAddr, bufferSize, timeOut);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHeadCopy(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 operateType;
|
||||
|
||||
ret = OsQueueWriteParameterCheck(queueID, bufferAddr, &bufferSize, timeOut);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_HEAD, OS_QUEUE_NOT_POINT);
|
||||
return OsQueueOperate(queueID, operateType, bufferAddr, &bufferSize, timeOut);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteCopy(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 operateType;
|
||||
|
||||
ret = OsQueueWriteParameterCheck(queueID, bufferAddr, &bufferSize, timeOut);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_TAIL, OS_QUEUE_NOT_POINT);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_QUEUE_WRITE_COPY, (LosQueueCB *)GET_QUEUE_HANDLE(queueID),
|
||||
operateType, bufferSize, timeOut);
|
||||
|
||||
return OsQueueOperate(queueID, operateType, bufferAddr, &bufferSize, timeOut);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_QueueRead(UINT32 queueID, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeOut)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 operateType;
|
||||
|
||||
ret = OsQueueReadParameterCheck(queueID, bufferAddr, &bufferSize, timeOut);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_READ, OS_QUEUE_HEAD, OS_QUEUE_POINT);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_QUEUE_READ, (LosQueueCB *)GET_QUEUE_HANDLE(queueID), operateType, bufferSize, timeOut);
|
||||
|
||||
return OsQueueOperate(queueID, operateType, bufferAddr, &bufferSize, timeOut);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_QueueWrite(UINT32 queueID, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeOut)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 operateType;
|
||||
UINT32 size = sizeof(UINT32 *);
|
||||
(VOID)bufferSize;
|
||||
|
||||
ret = OsQueueWriteParameterCheck(queueID, bufferAddr, &size, timeOut);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_TAIL, OS_QUEUE_POINT);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_QUEUE_WRITE, (LosQueueCB *)GET_QUEUE_HANDLE(queueID), operateType, size, timeOut);
|
||||
|
||||
return OsQueueOperate(queueID, operateType, &bufferAddr, &size, timeOut);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHead(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut)
|
||||
{
|
||||
UINT32 size = sizeof(UINT32 *);
|
||||
(VOID)bufferSize;
|
||||
|
||||
if (bufferAddr == NULL) {
|
||||
return LOS_ERRNO_QUEUE_WRITE_PTR_NULL;
|
||||
}
|
||||
|
||||
return LOS_QueueWriteHeadCopy(queueID, &bufferAddr, size, timeOut);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsQueueMailAlloc
|
||||
Description : Mail allocate memory
|
||||
Input : queueID --- QueueID
|
||||
: mailPool --- MailPool
|
||||
: timeOut --- TimeOut
|
||||
Output : None
|
||||
Return : mem:pointer if success otherwise NULL
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 timeOut)
|
||||
{
|
||||
VOID *mem = (VOID *)NULL;
|
||||
UINT32 intSave;
|
||||
LosQueueCB *queueCB = (LosQueueCB *)NULL;
|
||||
LosTaskCB *runTsk = (LosTaskCB *)NULL;
|
||||
|
||||
if (queueID >= OS_ALL_IPC_QUEUE_LIMIT) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mailPool == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (timeOut != LOS_NO_WAIT) {
|
||||
if (OS_INT_ACTIVE) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
queueCB = GET_QUEUE_HANDLE(queueID);
|
||||
if (queueCB->queueState == OS_QUEUE_UNUSED) {
|
||||
goto END;
|
||||
}
|
||||
|
||||
mem = LOS_MemboxAlloc(mailPool);
|
||||
if (mem == NULL) {
|
||||
if (timeOut == LOS_NO_WAIT) {
|
||||
goto END;
|
||||
}
|
||||
|
||||
runTsk = (LosTaskCB *)g_losTask.runTask;
|
||||
OsSchedTaskWait(&queueCB->memList, timeOut);
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (runTsk->taskStatus & OS_TASK_STATUS_TIMEOUT) {
|
||||
runTsk->taskStatus &= (~OS_TASK_STATUS_TIMEOUT);
|
||||
goto END;
|
||||
} else {
|
||||
/* When enters the current branch, means the current task already got an available membox,
|
||||
* so the runTsk->msg can not be NULL.
|
||||
*/
|
||||
mem = runTsk->msg;
|
||||
runTsk->msg = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
END:
|
||||
LOS_IntRestore(intSave);
|
||||
return mem;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsQueueMailFree
|
||||
Description : Mail free memory
|
||||
Input : queueID --- QueueID
|
||||
: mailPool --- MailPool
|
||||
: mailMem --- MailMem
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 OsQueueMailFree(UINT32 queueID, VOID *mailPool, VOID *mailMem)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosQueueCB *queueCB = (LosQueueCB *)NULL;
|
||||
LosTaskCB *resumedTask = (LosTaskCB *)NULL;
|
||||
|
||||
if (queueID >= OS_ALL_IPC_QUEUE_LIMIT) {
|
||||
return LOS_ERRNO_QUEUE_MAIL_HANDLE_INVALID;
|
||||
}
|
||||
|
||||
if (mailPool == NULL) {
|
||||
return LOS_ERRNO_QUEUE_MAIL_PTR_INVALID;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
queueCB = GET_QUEUE_HANDLE(queueID);
|
||||
if (queueCB->queueState == OS_QUEUE_UNUSED) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_QUEUE_NOT_CREATE;
|
||||
}
|
||||
|
||||
if (!LOS_ListEmpty(&queueCB->memList)) {
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&queueCB->memList));
|
||||
/* When enter this branch, it means the resumed task can
|
||||
* get an available mailMem.
|
||||
*/
|
||||
resumedTask->msg = mailMem;
|
||||
OsSchedTaskWake(resumedTask);
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
} else {
|
||||
/* No task waiting for the mailMem, so free it. */
|
||||
if (LOS_MemboxFree(mailPool, mailMem)) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_QUEUE_MAIL_FREE_ERROR;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_QueueDelete
|
||||
Description : Delete a queue
|
||||
Input : queueID --- QueueID
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueDelete(UINT32 queueID)
|
||||
{
|
||||
LosQueueCB *queueCB = NULL;
|
||||
UINT8 *queue = NULL;
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
|
||||
if (queueID >= OS_ALL_IPC_QUEUE_LIMIT) {
|
||||
return LOS_ERRNO_QUEUE_NOT_FOUND;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID);
|
||||
if (queueCB->queueState == OS_QUEUE_UNUSED) {
|
||||
ret = LOS_ERRNO_QUEUE_NOT_CREATE;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
if (!LOS_ListEmpty(&queueCB->readWriteList[OS_QUEUE_READ])) {
|
||||
ret = LOS_ERRNO_QUEUE_IN_TSKUSE;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
if (!LOS_ListEmpty(&queueCB->readWriteList[OS_QUEUE_WRITE])) {
|
||||
ret = LOS_ERRNO_QUEUE_IN_TSKUSE;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
if (!LOS_ListEmpty(&queueCB->memList)) {
|
||||
ret = LOS_ERRNO_QUEUE_IN_TSKUSE;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
if ((queueCB->readWriteableCnt[OS_QUEUE_WRITE] + queueCB->readWriteableCnt[OS_QUEUE_READ]) !=
|
||||
queueCB->queueLen) {
|
||||
ret = LOS_ERRNO_QUEUE_IN_TSKWRITE;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
queue = queueCB->queue;
|
||||
queueCB->queue = (UINT8 *)NULL;
|
||||
queueCB->queueName = (UINT8 *)NULL;
|
||||
queueCB->queueState = OS_QUEUE_UNUSED;
|
||||
|
||||
#if (LOSCFG_BASE_IPC_QUEUE_STATIC == 1)
|
||||
if (queueID >= LOSCFG_BASE_IPC_QUEUE_LIMIT && queueID < OS_ALL_IPC_QUEUE_LIMIT) {
|
||||
LOS_ListAdd(&g_freeStaticQueueList, &queueCB->readWriteList[OS_QUEUE_WRITE]);
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
LOS_ListAdd(&g_freeQueueList, &queueCB->readWriteList[OS_QUEUE_WRITE]);
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_QUEUE_DELETE, queueCB);
|
||||
|
||||
ret = LOS_MemFree(m_aucSysMem0, (VOID *)queue);
|
||||
return ret;
|
||||
|
||||
QUEUE_END:
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_QueueInfoGet(UINT32 queueID, QUEUE_INFO_S *queueInfo)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret = LOS_OK;
|
||||
LosQueueCB *queueCB = NULL;
|
||||
LosTaskCB *tskCB = NULL;
|
||||
|
||||
if (queueInfo == NULL) {
|
||||
return LOS_ERRNO_QUEUE_PTR_NULL;
|
||||
}
|
||||
|
||||
if (queueID >= OS_ALL_IPC_QUEUE_LIMIT) {
|
||||
return LOS_ERRNO_QUEUE_INVALID;
|
||||
}
|
||||
|
||||
(VOID)memset_s((VOID *)queueInfo, sizeof(QUEUE_INFO_S), 0, sizeof(QUEUE_INFO_S));
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID);
|
||||
if (queueCB->queueState == OS_QUEUE_UNUSED) {
|
||||
ret = LOS_ERRNO_QUEUE_NOT_CREATE;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
queueInfo->queueID = queueID;
|
||||
queueInfo->queueLen = queueCB->queueLen;
|
||||
queueInfo->queueSize = queueCB->queueSize;
|
||||
queueInfo->queueHead = queueCB->queueHead;
|
||||
queueInfo->queueTail = queueCB->queueTail;
|
||||
queueInfo->readableCnt = queueCB->readWriteableCnt[OS_QUEUE_READ];
|
||||
queueInfo->writableCnt = queueCB->readWriteableCnt[OS_QUEUE_WRITE];
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(tskCB, &queueCB->readWriteList[OS_QUEUE_READ], LosTaskCB, pendList) {
|
||||
queueInfo->waitReadTask[OS_WAIT_TASK_ID_TO_ARRAY_IDX(tskCB->taskID)] |=
|
||||
(1 << (tskCB->taskID & OS_WAIT_TASK_ARRAY_ELEMENT_MASK));
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(tskCB, &queueCB->readWriteList[OS_QUEUE_WRITE], LosTaskCB, pendList) {
|
||||
queueInfo->waitWriteTask[OS_WAIT_TASK_ID_TO_ARRAY_IDX(tskCB->taskID)] |=
|
||||
(1 << (tskCB->taskID & OS_WAIT_TASK_ARRAY_ELEMENT_MASK));
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(tskCB, &queueCB->memList, LosTaskCB, pendList) {
|
||||
queueInfo->waitMemTask[OS_WAIT_TASK_ID_TO_ARRAY_IDX(tskCB->taskID)] |=
|
||||
(1 << (tskCB->taskID & OS_WAIT_TASK_ARRAY_ELEMENT_MASK));
|
||||
}
|
||||
|
||||
QUEUE_END:
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LosQueueCB *OsGetQueueHandle(UINT32 queueID)
|
||||
{
|
||||
#if (LOSCFG_BASE_IPC_QUEUE_STATIC == 1)
|
||||
if (queueID >= LOSCFG_BASE_IPC_QUEUE_LIMIT && queueID < OS_ALL_IPC_QUEUE_LIMIT) {
|
||||
return (((LosQueueCB *)g_staticQueue) + (queueID - LOSCFG_BASE_IPC_QUEUE_LIMIT));
|
||||
}
|
||||
#endif
|
||||
|
||||
return (((LosQueueCB *)g_allQueue) + (queueID));
|
||||
}
|
||||
|
||||
#endif /* (LOSCFG_BASE_IPC_QUEUE == 1) */
|
||||
|
||||
624
ohos/kernel/liteos_m/kernel/src/los_sched.c
Normal file
624
ohos/kernel/liteos_m/kernel/src/los_sched.c
Normal file
@@ -0,0 +1,624 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_sched.h"
|
||||
#include "los_task.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_swtmr.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_hook.h"
|
||||
#if (LOSCFG_KERNEL_PM == 1)
|
||||
#include "los_pm.h"
|
||||
#endif
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
#include "los_debugtools.h"
|
||||
#endif
|
||||
|
||||
#define OS_PRIORITY_QUEUE_NUM 32
|
||||
#define PRIQUEUE_PRIOR0_BIT 0x80000000U
|
||||
#define OS_TICK_RESPONSE_TIME_MAX LOSCFG_BASE_CORE_TICK_RESPONSE_MAX
|
||||
#if (LOSCFG_BASE_CORE_TICK_RESPONSE_MAX == 0)
|
||||
#error "Must specify the maximum value that tick timer counter supports!"
|
||||
#endif
|
||||
|
||||
#define OS_TASK_BLOCKED_STATUS (OS_TASK_STATUS_PEND | OS_TASK_STATUS_SUSPEND | \
|
||||
OS_TASK_STATUS_EXIT | OS_TASK_STATUS_UNUSED)
|
||||
|
||||
STATIC SchedScan g_swtmrScan = NULL;
|
||||
STATIC SortLinkAttribute *g_taskSortLinkList = NULL;
|
||||
STATIC LOS_DL_LIST g_priQueueList[OS_PRIORITY_QUEUE_NUM];
|
||||
STATIC UINT32 g_queueBitmap;
|
||||
|
||||
STATIC UINT32 g_schedResponseID = 0;
|
||||
STATIC UINT16 g_tickIntLock = 0;
|
||||
STATIC UINT64 g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
|
||||
STATIC INT32 g_schedTimeSlice;
|
||||
STATIC INT32 g_schedTimeSliceMin;
|
||||
STATIC UINT32 g_schedTickMinPeriod;
|
||||
STATIC UINT32 g_tickResponsePrecision;
|
||||
|
||||
VOID OsSchedResetSchedResponseTime(UINT64 responseTime)
|
||||
{
|
||||
if (responseTime <= g_schedResponseTime) {
|
||||
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsTimeSliceUpdate(LosTaskCB *taskCB, UINT64 currTime)
|
||||
{
|
||||
LOS_ASSERT(currTime >= taskCB->startTime);
|
||||
|
||||
INT32 incTime = currTime - taskCB->startTime;
|
||||
if (taskCB->taskID != g_idleTaskID) {
|
||||
taskCB->timeSlice -= incTime;
|
||||
}
|
||||
taskCB->startTime = currTime;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedSetNextExpireTime(UINT32 responseID, UINT64 taskEndTime)
|
||||
{
|
||||
UINT64 nextResponseTime;
|
||||
BOOL isTimeSlice = FALSE;
|
||||
|
||||
UINT64 currTime = OsGetCurrSchedTimeCycle();
|
||||
UINT64 nextExpireTime = OsGetNextExpireTime(currTime, g_tickResponsePrecision);
|
||||
/* The response time of the task time slice is aligned to the next response time in the delay queue */
|
||||
if ((nextExpireTime > taskEndTime) && ((nextExpireTime - taskEndTime) > g_schedTickMinPeriod)) {
|
||||
nextExpireTime = taskEndTime;
|
||||
isTimeSlice = TRUE;
|
||||
}
|
||||
|
||||
if ((g_schedResponseTime <= nextExpireTime) ||
|
||||
((g_schedResponseTime - nextExpireTime) < g_tickResponsePrecision)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isTimeSlice) {
|
||||
/* The expiration time of the current system is the thread's slice expiration time */
|
||||
g_schedResponseID = responseID;
|
||||
} else {
|
||||
g_schedResponseID = OS_INVALID;
|
||||
}
|
||||
|
||||
nextResponseTime = nextExpireTime - currTime;
|
||||
if (nextResponseTime < g_tickResponsePrecision) {
|
||||
nextResponseTime = g_tickResponsePrecision;
|
||||
}
|
||||
g_schedResponseTime = currTime + OsTickTimerReload(nextResponseTime);
|
||||
}
|
||||
|
||||
VOID OsSchedUpdateExpireTime(VOID)
|
||||
{
|
||||
UINT64 endTime;
|
||||
BOOL isPmMode = FALSE;
|
||||
LosTaskCB *runTask = g_losTask.runTask;
|
||||
|
||||
if (!g_taskScheduled || g_tickIntLock) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_PM == 1)
|
||||
isPmMode = OsIsPmMode();
|
||||
#endif
|
||||
if ((runTask->taskID != g_idleTaskID) && !isPmMode) {
|
||||
INT32 timeSlice = (runTask->timeSlice <= g_schedTimeSliceMin) ? g_schedTimeSlice : runTask->timeSlice;
|
||||
endTime = runTask->startTime + timeSlice;
|
||||
} else {
|
||||
endTime = OS_SCHED_MAX_RESPONSE_TIME - g_tickResponsePrecision;
|
||||
}
|
||||
OsSchedSetNextExpireTime(runTask->taskID, endTime);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedPriQueueEnHead(LOS_DL_LIST *priqueueItem, UINT32 priority)
|
||||
{
|
||||
/*
|
||||
* Task control blocks are inited as zero. And when task is deleted,
|
||||
* and at the same time would be deleted from priority queue or
|
||||
* other lists, task pend node will restored as zero.
|
||||
*/
|
||||
if (LOS_ListEmpty(&g_priQueueList[priority])) {
|
||||
g_queueBitmap |= PRIQUEUE_PRIOR0_BIT >> priority;
|
||||
}
|
||||
|
||||
LOS_ListAdd(&g_priQueueList[priority], priqueueItem);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedPriQueueEnTail(LOS_DL_LIST *priqueueItem, UINT32 priority)
|
||||
{
|
||||
if (LOS_ListEmpty(&g_priQueueList[priority])) {
|
||||
g_queueBitmap |= PRIQUEUE_PRIOR0_BIT >> priority;
|
||||
}
|
||||
|
||||
LOS_ListTailInsert(&g_priQueueList[priority], priqueueItem);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedPriQueueDelete(LOS_DL_LIST *priqueueItem, UINT32 priority)
|
||||
{
|
||||
LOS_ListDelete(priqueueItem);
|
||||
if (LOS_ListEmpty(&g_priQueueList[priority])) {
|
||||
g_queueBitmap &= ~(PRIQUEUE_PRIOR0_BIT >> priority);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedWakePendTimeTask(LosTaskCB *taskCB, BOOL *needSchedule)
|
||||
{
|
||||
UINT16 tempStatus = taskCB->taskStatus;
|
||||
if (tempStatus & (OS_TASK_STATUS_PEND | OS_TASK_STATUS_DELAY)) {
|
||||
taskCB->taskStatus &= ~(OS_TASK_STATUS_PEND | OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY);
|
||||
if (tempStatus & OS_TASK_STATUS_PEND) {
|
||||
taskCB->taskStatus |= OS_TASK_STATUS_TIMEOUT;
|
||||
LOS_ListDelete(&taskCB->pendList);
|
||||
taskCB->taskMux = NULL;
|
||||
taskCB->taskSem = NULL;
|
||||
}
|
||||
|
||||
if (!(tempStatus & OS_TASK_STATUS_SUSPEND)) {
|
||||
OsSchedTaskEnQueue(taskCB);
|
||||
*needSchedule = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL OsSchedScanTimerList(VOID)
|
||||
{
|
||||
BOOL needSchedule = FALSE;
|
||||
LOS_DL_LIST *listObject = &g_taskSortLinkList->sortLink;
|
||||
/*
|
||||
* When task is pended with timeout, the task block is on the timeout sortlink
|
||||
* (per cpu) and ipc(mutex,sem and etc.)'s block at the same time, it can be waken
|
||||
* up by either timeout or corresponding ipc it's waiting.
|
||||
*
|
||||
* Now synchronize sortlink procedure is used, therefore the whole task scan needs
|
||||
* to be protected, preventing another core from doing sortlink deletion at same time.
|
||||
*/
|
||||
|
||||
if (LOS_ListEmpty(listObject)) {
|
||||
return needSchedule;
|
||||
}
|
||||
|
||||
SortLinkList *sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
|
||||
UINT64 currTime = OsGetCurrSchedTimeCycle();
|
||||
while (sortList->responseTime <= currTime) {
|
||||
LosTaskCB *taskCB = LOS_DL_LIST_ENTRY(sortList, LosTaskCB, sortList);
|
||||
OsDeleteNodeSortLink(&taskCB->sortList);
|
||||
OsSchedWakePendTimeTask(taskCB, &needSchedule);
|
||||
if (LOS_ListEmpty(listObject)) {
|
||||
break;
|
||||
}
|
||||
|
||||
sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
|
||||
}
|
||||
|
||||
return needSchedule;
|
||||
}
|
||||
|
||||
VOID OsSchedTaskEnQueue(LosTaskCB *taskCB)
|
||||
{
|
||||
LOS_ASSERT(!(taskCB->taskStatus & OS_TASK_STATUS_READY));
|
||||
|
||||
if (taskCB->taskID != g_idleTaskID) {
|
||||
if (taskCB->timeSlice > g_schedTimeSliceMin) {
|
||||
OsSchedPriQueueEnHead(&taskCB->pendList, taskCB->priority);
|
||||
} else {
|
||||
taskCB->timeSlice = g_schedTimeSlice;
|
||||
OsSchedPriQueueEnTail(&taskCB->pendList, taskCB->priority);
|
||||
}
|
||||
OsHookCall(LOS_HOOK_TYPE_MOVEDTASKTOREADYSTATE, taskCB);
|
||||
}
|
||||
|
||||
taskCB->taskStatus &= ~(OS_TASK_STATUS_PEND | OS_TASK_STATUS_SUSPEND |
|
||||
OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME);
|
||||
|
||||
taskCB->taskStatus |= OS_TASK_STATUS_READY;
|
||||
}
|
||||
|
||||
VOID OsSchedTaskDeQueue(LosTaskCB *taskCB)
|
||||
{
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
|
||||
if (taskCB->taskID != g_idleTaskID) {
|
||||
OsSchedPriQueueDelete(&taskCB->pendList, taskCB->priority);
|
||||
}
|
||||
|
||||
taskCB->taskStatus &= ~OS_TASK_STATUS_READY;
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsSchedTaskExit(LosTaskCB *taskCB)
|
||||
{
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
|
||||
OsSchedTaskDeQueue(taskCB);
|
||||
} else if (taskCB->taskStatus & OS_TASK_STATUS_PEND) {
|
||||
LOS_ListDelete(&taskCB->pendList);
|
||||
taskCB->taskStatus &= ~OS_TASK_STATUS_PEND;
|
||||
}
|
||||
|
||||
if (taskCB->taskStatus & (OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME)) {
|
||||
OsDeleteSortLink(&taskCB->sortList);
|
||||
taskCB->taskStatus &= ~(OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME);
|
||||
}
|
||||
taskCB->taskStatus |= OS_TASK_STATUS_EXIT;
|
||||
}
|
||||
|
||||
VOID OsSchedYield(VOID)
|
||||
{
|
||||
LosTaskCB *runTask = g_losTask.runTask;
|
||||
|
||||
runTask->timeSlice = 0;
|
||||
}
|
||||
|
||||
VOID OsSchedDelay(LosTaskCB *runTask, UINT32 tick)
|
||||
{
|
||||
runTask->taskStatus |= OS_TASK_STATUS_DELAY;
|
||||
runTask->waitTimes = tick;
|
||||
}
|
||||
|
||||
VOID OsSchedTaskWait(LOS_DL_LIST *list, UINT32 ticks)
|
||||
{
|
||||
LosTaskCB *runTask = g_losTask.runTask;
|
||||
|
||||
runTask->taskStatus |= OS_TASK_STATUS_PEND;
|
||||
LOS_ListTailInsert(list, &runTask->pendList);
|
||||
|
||||
if (ticks != LOS_WAIT_FOREVER) {
|
||||
runTask->taskStatus |= OS_TASK_STATUS_PEND_TIME;
|
||||
runTask->waitTimes = ticks;
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsSchedTaskWake(LosTaskCB *resumedTask)
|
||||
{
|
||||
LOS_ListDelete(&resumedTask->pendList);
|
||||
resumedTask->taskStatus &= ~OS_TASK_STATUS_PEND;
|
||||
|
||||
if (resumedTask->taskStatus & OS_TASK_STATUS_PEND_TIME) {
|
||||
OsDeleteSortLink(&resumedTask->sortList);
|
||||
resumedTask->taskStatus &= ~OS_TASK_STATUS_PEND_TIME;
|
||||
}
|
||||
|
||||
if (!(resumedTask->taskStatus & OS_TASK_STATUS_SUSPEND) &&
|
||||
!(resumedTask->taskStatus & OS_TASK_STATUS_RUNNING)) {
|
||||
OsSchedTaskEnQueue(resumedTask);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsSchedFreezeTask(LosTaskCB *taskCB)
|
||||
{
|
||||
UINT64 responseTime = GET_SORTLIST_VALUE(&taskCB->sortList);
|
||||
OsDeleteSortLink(&taskCB->sortList);
|
||||
SET_SORTLIST_VALUE(&taskCB->sortList, responseTime);
|
||||
taskCB->taskStatus |= OS_TASK_FLAG_FREEZE;
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC VOID OsSchedUnfreezeTask(LosTaskCB *taskCB)
|
||||
{
|
||||
UINT64 currTime, responseTime;
|
||||
UINT32 remainTick;
|
||||
|
||||
taskCB->taskStatus &= ~OS_TASK_FLAG_FREEZE;
|
||||
currTime = OsGetCurrSchedTimeCycle();
|
||||
responseTime = GET_SORTLIST_VALUE(&taskCB->sortList);
|
||||
if (responseTime > currTime) {
|
||||
remainTick = ((responseTime - currTime) + OS_CYCLE_PER_TICK - 1) / OS_CYCLE_PER_TICK;
|
||||
OsAdd2SortLink(&taskCB->sortList, currTime, remainTick, OS_SORT_LINK_TASK);
|
||||
return;
|
||||
}
|
||||
|
||||
SET_SORTLIST_VALUE(&taskCB->sortList, OS_SORT_LINK_INVALID_TIME);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_PEND) {
|
||||
LOS_ListDelete(&taskCB->pendList);
|
||||
}
|
||||
taskCB->taskStatus &= ~(OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_PEND);
|
||||
return;
|
||||
}
|
||||
|
||||
VOID OsSchedSuspend(LosTaskCB *taskCB)
|
||||
{
|
||||
BOOL isPmMode = FALSE;
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
|
||||
OsSchedTaskDeQueue(taskCB);
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_PM == 1)
|
||||
isPmMode = OsIsPmMode();
|
||||
#endif
|
||||
if ((taskCB->taskStatus & (OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY)) && isPmMode) {
|
||||
OsSchedFreezeTask(taskCB);
|
||||
}
|
||||
|
||||
taskCB->taskStatus |= OS_TASK_STATUS_SUSPEND;
|
||||
OsHookCall(LOS_HOOK_TYPE_MOVEDTASKTOSUSPENDEDLIST, taskCB);
|
||||
}
|
||||
|
||||
BOOL OsSchedResume(LosTaskCB *taskCB)
|
||||
{
|
||||
if (taskCB->taskStatus & OS_TASK_FLAG_FREEZE) {
|
||||
OsSchedUnfreezeTask(taskCB);
|
||||
}
|
||||
|
||||
taskCB->taskStatus &= (~OS_TASK_STATUS_SUSPEND);
|
||||
if (!(taskCB->taskStatus & (OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND))) {
|
||||
OsSchedTaskEnQueue(taskCB);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL OsSchedModifyTaskSchedParam(LosTaskCB *taskCB, UINT16 priority)
|
||||
{
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
|
||||
OsSchedTaskDeQueue(taskCB);
|
||||
taskCB->priority = priority;
|
||||
OsSchedTaskEnQueue(taskCB);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
taskCB->priority = priority;
|
||||
OsHookCall(LOS_HOOK_TYPE_TASK_PRIMODIFY, taskCB, taskCB->priority);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask)
|
||||
{
|
||||
OsSchedTaskEnQueue(idleTask);
|
||||
}
|
||||
|
||||
UINT32 OsSchedSwtmrScanRegister(SchedScan func)
|
||||
{
|
||||
if (func == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
g_swtmrScan = func;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsTaskNextSwitchTimeGet(VOID)
|
||||
{
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
UINT32 ticks = OsSortLinkGetNextExpireTime(g_taskSortLinkList);
|
||||
LOS_IntRestore(intSave);
|
||||
return ticks;
|
||||
}
|
||||
|
||||
UINT64 OsSchedGetNextExpireTime(UINT64 startTime)
|
||||
{
|
||||
return OsGetNextExpireTime(startTime, g_tickResponsePrecision);
|
||||
}
|
||||
|
||||
STATIC VOID TaskSchedTimeConvertFreq(UINT32 oldFreq)
|
||||
{
|
||||
for (UINT32 loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
LosTaskCB *taskCB = (((LosTaskCB *)g_taskCBArray) + loopNum);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
continue;
|
||||
}
|
||||
if (taskCB->timeSlice > 0) {
|
||||
taskCB->timeSlice = (INT32)OsTimeConvertFreq((UINT64)taskCB->timeSlice, oldFreq, g_sysClock);
|
||||
} else {
|
||||
taskCB->timeSlice = 0;
|
||||
}
|
||||
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
|
||||
taskCB->startTime = OsTimeConvertFreq(taskCB->startTime, oldFreq, g_sysClock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID SchedTimeBaseInit(VOID)
|
||||
{
|
||||
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
|
||||
g_schedTickMinPeriod = g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI;
|
||||
g_tickResponsePrecision = (g_schedTickMinPeriod * 75) / 100; /* 75 / 100: minimum accuracy */
|
||||
g_schedTimeSlice = (INT32)(((UINT64)g_sysClock * LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT) / OS_SYS_US_PER_SECOND);
|
||||
g_schedTimeSliceMin = (INT32)(((UINT64)g_sysClock * 50) / OS_SYS_US_PER_SECOND); /* Minimum time slice 50 us */
|
||||
}
|
||||
|
||||
VOID OsSchedTimeConvertFreq(UINT32 oldFreq)
|
||||
{
|
||||
SchedTimeBaseInit();
|
||||
TaskSchedTimeConvertFreq(oldFreq);
|
||||
OsSortLinkResponseTimeConvertFreq(oldFreq);
|
||||
OsSchedUpdateExpireTime();
|
||||
}
|
||||
|
||||
UINT32 OsSchedInit(VOID)
|
||||
{
|
||||
UINT16 pri;
|
||||
for (pri = 0; pri < OS_PRIORITY_QUEUE_NUM; pri++) {
|
||||
LOS_ListInit(&g_priQueueList[pri]);
|
||||
}
|
||||
g_queueBitmap = 0;
|
||||
|
||||
g_taskSortLinkList = OsGetSortLinkAttribute(OS_SORT_LINK_TASK);
|
||||
if (g_taskSortLinkList == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
OsSortLinkInit(g_taskSortLinkList);
|
||||
SchedTimeBaseInit();
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LosTaskCB *OsGetTopTask(VOID)
|
||||
{
|
||||
UINT32 priority;
|
||||
LosTaskCB *newTask = NULL;
|
||||
if (g_queueBitmap) {
|
||||
priority = CLZ(g_queueBitmap);
|
||||
newTask = LOS_DL_LIST_ENTRY(((LOS_DL_LIST *)&g_priQueueList[priority])->pstNext, LosTaskCB, pendList);
|
||||
} else {
|
||||
newTask = OS_TCB_FROM_TID(g_idleTaskID);
|
||||
}
|
||||
|
||||
return newTask;
|
||||
}
|
||||
|
||||
VOID OsSchedStart(VOID)
|
||||
{
|
||||
PRINTK("Entering scheduler\n");
|
||||
|
||||
(VOID)LOS_IntLock();
|
||||
LosTaskCB *newTask = OsGetTopTask();
|
||||
|
||||
newTask->taskStatus |= OS_TASK_STATUS_RUNNING;
|
||||
g_losTask.newTask = newTask;
|
||||
g_losTask.runTask = g_losTask.newTask;
|
||||
|
||||
newTask->startTime = OsGetCurrSchedTimeCycle();
|
||||
OsSchedTaskDeQueue(newTask);
|
||||
|
||||
OsTickSysTimerStartTimeSet(newTask->startTime);
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
OsSwtmrResponseTimeReset(newTask->startTime);
|
||||
#endif
|
||||
|
||||
/* Initialize the schedule timeline and enable scheduling */
|
||||
g_taskScheduled = TRUE;
|
||||
|
||||
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
g_schedResponseID = OS_INVALID;
|
||||
OsSchedSetNextExpireTime(newTask->taskID, newTask->startTime + newTask->timeSlice);
|
||||
}
|
||||
|
||||
BOOL OsSchedTaskSwitch(VOID)
|
||||
{
|
||||
UINT64 endTime;
|
||||
BOOL isTaskSwitch = FALSE;
|
||||
LosTaskCB *runTask = g_losTask.runTask;
|
||||
OsTimeSliceUpdate(runTask, OsGetCurrSchedTimeCycle());
|
||||
|
||||
if (runTask->taskStatus & (OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY)) {
|
||||
OsAdd2SortLink(&runTask->sortList, runTask->startTime, runTask->waitTimes, OS_SORT_LINK_TASK);
|
||||
} else if (!(runTask->taskStatus & OS_TASK_BLOCKED_STATUS)) {
|
||||
OsSchedTaskEnQueue(runTask);
|
||||
}
|
||||
|
||||
LosTaskCB *newTask = OsGetTopTask();
|
||||
g_losTask.newTask = newTask;
|
||||
|
||||
if (runTask != newTask) {
|
||||
#if (LOSCFG_BASE_CORE_TSK_MONITOR == 1)
|
||||
OsTaskSwitchCheck();
|
||||
#endif
|
||||
runTask->taskStatus &= ~OS_TASK_STATUS_RUNNING;
|
||||
newTask->taskStatus |= OS_TASK_STATUS_RUNNING;
|
||||
newTask->startTime = runTask->startTime;
|
||||
isTaskSwitch = TRUE;
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_TASK_SWITCHEDIN);
|
||||
#if (LOSCFG_DEBUG_TOOLS == 1)
|
||||
OsSchedTraceRecord(newTask, runTask);
|
||||
#endif
|
||||
}
|
||||
|
||||
OsSchedTaskDeQueue(newTask);
|
||||
|
||||
if (newTask->taskID != g_idleTaskID) {
|
||||
endTime = newTask->startTime + newTask->timeSlice;
|
||||
} else {
|
||||
endTime = OS_SCHED_MAX_RESPONSE_TIME - g_tickResponsePrecision;
|
||||
}
|
||||
|
||||
if (g_schedResponseID == runTask->taskID) {
|
||||
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
}
|
||||
OsSchedSetNextExpireTime(newTask->taskID, endTime);
|
||||
|
||||
return isTaskSwitch;
|
||||
}
|
||||
|
||||
UINT64 LOS_SchedTickTimeoutNsGet(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT64 responseTime;
|
||||
UINT64 currTime;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
responseTime = g_schedResponseTime;
|
||||
currTime = OsGetCurrSchedTimeCycle();
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
if (responseTime > currTime) {
|
||||
responseTime = responseTime - currTime;
|
||||
} else {
|
||||
responseTime = 0; /* Tick interrupt already timeout */
|
||||
}
|
||||
|
||||
return OS_SYS_CYCLE_TO_NS(responseTime, g_sysClock);
|
||||
}
|
||||
|
||||
VOID LOS_SchedTickHandler(VOID)
|
||||
{
|
||||
if (!g_taskScheduled) {
|
||||
return;
|
||||
}
|
||||
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
UINT64 tickStartTime = OsGetCurrSchedTimeCycle();
|
||||
if (g_schedResponseID == OS_INVALID) {
|
||||
g_tickIntLock++;
|
||||
if (g_swtmrScan != NULL) {
|
||||
(VOID)g_swtmrScan();
|
||||
}
|
||||
|
||||
(VOID)OsSchedScanTimerList();
|
||||
g_tickIntLock--;
|
||||
}
|
||||
|
||||
OsTimeSliceUpdate(g_losTask.runTask, tickStartTime);
|
||||
g_losTask.runTask->startTime = OsGetCurrSchedTimeCycle();
|
||||
|
||||
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
if (LOS_CHECK_SCHEDULE) {
|
||||
ArchTaskSchedule();
|
||||
} else {
|
||||
OsSchedUpdateExpireTime();
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
VOID LOS_Schedule(VOID)
|
||||
{
|
||||
if (OsCheckKernelRunning()) {
|
||||
ArchTaskSchedule();
|
||||
}
|
||||
}
|
||||
330
ohos/kernel/liteos_m/kernel/src/los_sem.c
Normal file
330
ohos/kernel/liteos_m/kernel/src/los_sem.c
Normal file
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_sem.h"
|
||||
#include "los_config.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_hook.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_sched.h"
|
||||
|
||||
|
||||
#if (LOSCFG_BASE_IPC_SEM == 1)
|
||||
|
||||
LITE_OS_SEC_DATA_INIT LOS_DL_LIST g_unusedSemList;
|
||||
LITE_OS_SEC_BSS LosSemCB *g_allSem = NULL;
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSemInit
|
||||
Description : Initialize the Semaphore doubly linked list
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsSemInit(VOID)
|
||||
{
|
||||
LosSemCB *semNode = NULL;
|
||||
UINT16 index;
|
||||
|
||||
LOS_ListInit(&g_unusedSemList);
|
||||
|
||||
if (LOSCFG_BASE_IPC_SEM_LIMIT == 0) {
|
||||
return LOS_ERRNO_SEM_MAXNUM_ZERO;
|
||||
}
|
||||
|
||||
g_allSem = (LosSemCB *)LOS_MemAlloc(m_aucSysMem0, (LOSCFG_BASE_IPC_SEM_LIMIT * sizeof(LosSemCB)));
|
||||
if (g_allSem == NULL) {
|
||||
return LOS_ERRNO_SEM_NO_MEMORY;
|
||||
}
|
||||
|
||||
/* Connect all the semaphore CBs in a doubly linked list. */
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_SEM_LIMIT; index++) {
|
||||
semNode = ((LosSemCB *)g_allSem) + index;
|
||||
semNode->semID = index;
|
||||
semNode->semStat = OS_SEM_UNUSED;
|
||||
LOS_ListTailInsert(&g_unusedSemList, &semNode->semList);
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSemCreate
|
||||
Description : create the Semaphore
|
||||
Input : count --- Semaphore count
|
||||
: maxCount --- Max semaphore count for check
|
||||
Output : semHandle --- Index of semaphore
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsSemCreate(UINT16 count, UINT16 maxCount, UINT32 *semHandle)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosSemCB *semCreated = NULL;
|
||||
LOS_DL_LIST *unusedSem = NULL;
|
||||
UINT32 errNo;
|
||||
UINT32 errLine;
|
||||
|
||||
if (semHandle == NULL) {
|
||||
return LOS_ERRNO_SEM_PTR_NULL;
|
||||
}
|
||||
|
||||
if (count > maxCount) {
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_OVERFLOW);
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
if (LOS_ListEmpty(&g_unusedSemList)) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_ALL_BUSY);
|
||||
}
|
||||
|
||||
unusedSem = LOS_DL_LIST_FIRST(&(g_unusedSemList));
|
||||
LOS_ListDelete(unusedSem);
|
||||
semCreated = (GET_SEM_LIST(unusedSem));
|
||||
semCreated->semCount = count;
|
||||
semCreated->semStat = OS_SEM_USED;
|
||||
semCreated->maxSemCount = maxCount;
|
||||
LOS_ListInit(&semCreated->semList);
|
||||
*semHandle = (UINT32)semCreated->semID;
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_SEM_CREATE, semCreated);
|
||||
return LOS_OK;
|
||||
|
||||
ERR_HANDLER:
|
||||
OS_RETURN_ERROR_P2(errLine, errNo);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SemCreate
|
||||
Description : Create a semaphore
|
||||
Input : count--------- semaphore count
|
||||
Output : semHandle-----Index of semaphore
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemCreate(UINT16 count, UINT32 *semHandle)
|
||||
{
|
||||
return OsSemCreate(count, OS_SEM_COUNTING_MAX_COUNT, semHandle);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_BinarySemCreate
|
||||
Description : Create a binary semaphore
|
||||
Input : count--------- semaphore count
|
||||
Output : semHandle-----Index of semaphore
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_BinarySemCreate(UINT16 count, UINT32 *semHandle)
|
||||
{
|
||||
return OsSemCreate(count, OS_SEM_BINARY_MAX_COUNT, semHandle);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SemDelete
|
||||
Description : Delete a semaphore
|
||||
Input : semHandle--------- semaphore operation handle
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemDelete(UINT32 semHandle)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosSemCB *semDeleted = NULL;
|
||||
UINT32 errNo;
|
||||
UINT32 errLine;
|
||||
|
||||
if (semHandle >= (UINT32)LOSCFG_BASE_IPC_SEM_LIMIT) {
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_INVALID);
|
||||
}
|
||||
|
||||
semDeleted = GET_SEM(semHandle);
|
||||
intSave = LOS_IntLock();
|
||||
if (semDeleted->semStat == OS_SEM_UNUSED) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_INVALID);
|
||||
}
|
||||
|
||||
if (!LOS_ListEmpty(&semDeleted->semList)) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_PENDED);
|
||||
}
|
||||
|
||||
LOS_ListAdd(&g_unusedSemList, &semDeleted->semList);
|
||||
semDeleted->semStat = OS_SEM_UNUSED;
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_SEM_DELETE, semDeleted);
|
||||
return LOS_OK;
|
||||
ERR_HANDLER:
|
||||
OS_RETURN_ERROR_P2(errLine, errNo);
|
||||
}
|
||||
|
||||
STATIC_INLINE UINT32 OsSemValidCheck(LosSemCB *semPended)
|
||||
{
|
||||
if (semPended->semStat == OS_SEM_UNUSED) {
|
||||
return LOS_ERRNO_SEM_INVALID;
|
||||
}
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
PRINT_ERR("!!!LOS_ERRNO_SEM_PEND_INTERR!!!\n");
|
||||
return LOS_ERRNO_SEM_PEND_INTERR;
|
||||
}
|
||||
|
||||
if (g_losTaskLock) {
|
||||
PRINT_ERR("!!!LOS_ERRNO_SEM_PEND_IN_LOCK!!!\n");
|
||||
return LOS_ERRNO_SEM_PEND_IN_LOCK;
|
||||
}
|
||||
|
||||
if (g_losTask.runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
|
||||
return LOS_ERRNO_SEM_PEND_IN_SYSTEM_TASK;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SemPend
|
||||
Description : Specified semaphore P operation
|
||||
Input : semHandle --------- semaphore operation handle
|
||||
: timeout --------- waitting time
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosSemCB *semPended = NULL;
|
||||
UINT32 retErr;
|
||||
LosTaskCB *runningTask = NULL;
|
||||
|
||||
if (semHandle >= (UINT32)LOSCFG_BASE_IPC_SEM_LIMIT) {
|
||||
OS_RETURN_ERROR(LOS_ERRNO_SEM_INVALID);
|
||||
}
|
||||
|
||||
semPended = GET_SEM(semHandle);
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
retErr = OsSemValidCheck(semPended);
|
||||
if (retErr) {
|
||||
goto ERROR_SEM_PEND;
|
||||
}
|
||||
|
||||
runningTask = (LosTaskCB *)g_losTask.runTask;
|
||||
|
||||
if (semPended->semCount > 0) {
|
||||
semPended->semCount--;
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_SEM_PEND, semPended, runningTask, timeout);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (!timeout) {
|
||||
retErr = LOS_ERRNO_SEM_UNAVAILABLE;
|
||||
goto ERROR_SEM_PEND;
|
||||
}
|
||||
|
||||
runningTask->taskSem = (VOID *)semPended;
|
||||
OsSchedTaskWait(&semPended->semList, timeout);
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_SEM_PEND, semPended, runningTask, timeout);
|
||||
LOS_Schedule();
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (runningTask->taskStatus & OS_TASK_STATUS_TIMEOUT) {
|
||||
runningTask->taskStatus &= (~OS_TASK_STATUS_TIMEOUT);
|
||||
retErr = LOS_ERRNO_SEM_TIMEOUT;
|
||||
goto ERROR_SEM_PEND;
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
|
||||
ERROR_SEM_PEND:
|
||||
LOS_IntRestore(intSave);
|
||||
OS_RETURN_ERROR(retErr);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SemPost
|
||||
Description : Specified semaphore V operation
|
||||
Input : semHandle--------- semaphore operation handle
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosSemCB *semPosted = GET_SEM(semHandle);
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
|
||||
if (semHandle >= LOSCFG_BASE_IPC_SEM_LIMIT) {
|
||||
return LOS_ERRNO_SEM_INVALID;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
if (semPosted->semStat == OS_SEM_UNUSED) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_RETURN_ERROR(LOS_ERRNO_SEM_INVALID);
|
||||
}
|
||||
|
||||
if (semPosted->maxSemCount == semPosted->semCount) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_RETURN_ERROR(LOS_ERRNO_SEM_OVERFLOW);
|
||||
}
|
||||
if (!LOS_ListEmpty(&semPosted->semList)) {
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(semPosted->semList)));
|
||||
resumedTask->taskSem = NULL;
|
||||
OsSchedTaskWake(resumedTask);
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_SEM_POST, semPosted, resumedTask);
|
||||
LOS_Schedule();
|
||||
} else {
|
||||
semPosted->semCount++;
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_SEM_POST, semPosted, resumedTask);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_SemGetValue(UINT32 semHandle, INT32 *currVal)
|
||||
{
|
||||
LosSemCB *sem = GET_SEM(semHandle);
|
||||
|
||||
if (semHandle >= (UINT32)LOSCFG_BASE_IPC_SEM_LIMIT) {
|
||||
OS_RETURN_ERROR(LOS_ERRNO_SEM_INVALID);
|
||||
}
|
||||
|
||||
*currVal = sem->semCount;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* (LOSCFG_BASE_IPC_SEM == 1) */
|
||||
171
ohos/kernel/liteos_m/kernel/src/los_sortlink.c
Normal file
171
ohos/kernel/liteos_m/kernel/src/los_sortlink.c
Normal file
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_sortlink.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
SortLinkAttribute g_taskSortLink;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
SortLinkAttribute g_swtmrSortLink;
|
||||
#endif
|
||||
|
||||
UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHead)
|
||||
{
|
||||
LOS_ListInit(&sortLinkHead->sortLink);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsAddNode2SortLink(SortLinkAttribute *sortLinkHead, SortLinkList *sortList)
|
||||
{
|
||||
LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHead->sortLink;
|
||||
|
||||
if (LOS_ListEmpty(head)) {
|
||||
LOS_ListAdd(head, &sortList->sortLinkNode);
|
||||
return;
|
||||
}
|
||||
|
||||
SortLinkList *listSorted = LOS_DL_LIST_ENTRY(head->pstNext, SortLinkList, sortLinkNode);
|
||||
if (listSorted->responseTime > sortList->responseTime) {
|
||||
LOS_ListAdd(head, &sortList->sortLinkNode);
|
||||
return;
|
||||
} else if (listSorted->responseTime == sortList->responseTime) {
|
||||
LOS_ListAdd(head->pstNext, &sortList->sortLinkNode);
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_DL_LIST *prevNode = head->pstPrev;
|
||||
do {
|
||||
listSorted = LOS_DL_LIST_ENTRY(prevNode, SortLinkList, sortLinkNode);
|
||||
if (listSorted->responseTime <= sortList->responseTime) {
|
||||
LOS_ListAdd(prevNode, &sortList->sortLinkNode);
|
||||
break;
|
||||
}
|
||||
|
||||
prevNode = prevNode->pstPrev;
|
||||
} while (1);
|
||||
}
|
||||
|
||||
VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SortLinkAttribute *sortLinkHead = NULL;
|
||||
|
||||
if (type == OS_SORT_LINK_TASK) {
|
||||
sortLinkHead = &g_taskSortLink;
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
} else if (type == OS_SORT_LINK_SWTMR) {
|
||||
sortLinkHead = &g_swtmrSortLink;
|
||||
#endif
|
||||
} else {
|
||||
LOS_Panic("Sort link type error : %u\n", type);
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
SET_SORTLIST_VALUE(node, startTime + OS_SYS_TICK_TO_CYCLE(waitTicks));
|
||||
OsAddNode2SortLink(sortLinkHead, node);
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
VOID OsDeleteSortLink(SortLinkList *node)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (node->responseTime != OS_SORT_LINK_INVALID_TIME) {
|
||||
OsSchedResetSchedResponseTime(node->responseTime);
|
||||
OsDeleteNodeSortLink(node);
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID SortLinkNodeTimeUpdate(SortLinkAttribute *sortLinkHead, UINT32 oldFreq)
|
||||
{
|
||||
LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHead->sortLink;
|
||||
|
||||
if (LOS_ListEmpty(head)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_DL_LIST *nextNode = head->pstNext;
|
||||
do {
|
||||
SortLinkList *listSorted = LOS_DL_LIST_ENTRY(nextNode, SortLinkList, sortLinkNode);
|
||||
listSorted->responseTime = OsTimeConvertFreq(listSorted->responseTime, oldFreq, g_sysClock);
|
||||
nextNode = nextNode->pstNext;
|
||||
} while (nextNode != head);
|
||||
}
|
||||
|
||||
VOID OsSortLinkResponseTimeConvertFreq(UINT32 oldFreq)
|
||||
{
|
||||
SortLinkAttribute *taskHead = &g_taskSortLink;
|
||||
SortLinkNodeTimeUpdate(taskHead, oldFreq);
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
SortLinkAttribute *swtmrHead = &g_swtmrSortLink;
|
||||
SortLinkNodeTimeUpdate(swtmrHead, oldFreq);
|
||||
#endif
|
||||
}
|
||||
|
||||
SortLinkAttribute *OsGetSortLinkAttribute(SortLinkType type)
|
||||
{
|
||||
if (type == OS_SORT_LINK_TASK) {
|
||||
return &g_taskSortLink;
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
} else if (type == OS_SORT_LINK_SWTMR) {
|
||||
return &g_swtmrSortLink;
|
||||
#endif
|
||||
}
|
||||
|
||||
PRINT_ERR("Invalid sort link type!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UINT64 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList)
|
||||
{
|
||||
if (currTime >= targetSortList->responseTime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (targetSortList->responseTime - currTime);
|
||||
}
|
||||
|
||||
UINT64 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHead)
|
||||
{
|
||||
LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHead->sortLink;
|
||||
|
||||
if (LOS_ListEmpty(head)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SortLinkList *listSorted = LOS_DL_LIST_ENTRY(head->pstNext, SortLinkList, sortLinkNode);
|
||||
return OsSortLinkGetTargetExpireTime(OsGetCurrSchedTimeCycle(), listSorted);
|
||||
}
|
||||
715
ohos/kernel/liteos_m/kernel/src/los_swtmr.c
Normal file
715
ohos/kernel/liteos_m/kernel/src/los_swtmr.c
Normal file
@@ -0,0 +1,715 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 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_swtmr.h"
|
||||
#include "securec.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_task.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_queue.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_hook.h"
|
||||
#include "los_sched.h"
|
||||
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == 1)
|
||||
|
||||
LITE_OS_SEC_BSS UINT32 g_swtmrHandlerQueue; /* Software Timer timeout queue ID */
|
||||
LITE_OS_SEC_BSS SWTMR_CTRL_S *g_swtmrCBArray = NULL; /* first address in Timer memory space */
|
||||
LITE_OS_SEC_BSS SWTMR_CTRL_S *g_swtmrFreeList = NULL; /* Free list of Software Timer */
|
||||
LITE_OS_SEC_BSS SortLinkAttribute *g_swtmrSortLinkList = NULL; /* The software timer count list */
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
typedef struct SwtmrAlignDataStr {
|
||||
UINT32 times : 24;
|
||||
UINT32 : 5;
|
||||
UINT32 canMultiple : 1;
|
||||
UINT32 canAlign : 1;
|
||||
UINT32 isAligned : 1;
|
||||
} SwtmrAlignData;
|
||||
LITE_OS_SEC_BSS SwtmrAlignData g_swtmrAlignID[LOSCFG_BASE_CORE_SWTMR_LIMIT] = {0}; /* store swtmr align */
|
||||
#endif
|
||||
|
||||
#define SWTMR_MAX_RUNNING_TICKS 2
|
||||
#define OS_SWTMR_MAX_TIMERID ((0xFFFFFFFF / LOSCFG_BASE_CORE_SWTMR_LIMIT) * LOSCFG_BASE_CORE_SWTMR_LIMIT)
|
||||
|
||||
STATIC VOID OsSwtmrDelete(SWTMR_CTRL_S *swtmr);
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrTask
|
||||
Description : Swtmr task main loop, handle time-out timer.
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT VOID OsSwtmrTask(VOID)
|
||||
{
|
||||
SwtmrHandlerItem swtmrHandle;
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
UINT32 intSave;
|
||||
UINT32 readSize;
|
||||
UINT32 ret;
|
||||
UINT64 tick;
|
||||
|
||||
for (;;) {
|
||||
readSize = sizeof(SwtmrHandlerItem);
|
||||
ret = LOS_QueueReadCopy(g_swtmrHandlerQueue, &swtmrHandle, &readSize, LOS_WAIT_FOREVER);
|
||||
if ((ret == LOS_OK) && (readSize == sizeof(SwtmrHandlerItem))) {
|
||||
if ((swtmrHandle.handler == NULL) || (swtmrHandle.swtmrID >= OS_SWTMR_MAX_TIMERID)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
swtmr = g_swtmrCBArray + swtmrHandle.swtmrID % LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
if (swtmr->usTimerID != swtmrHandle.swtmrID) {
|
||||
LOS_IntRestore(intSave);
|
||||
continue;
|
||||
}
|
||||
if (swtmr->ucMode == LOS_SWTMR_MODE_ONCE) {
|
||||
OsSwtmrDelete(swtmr);
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
tick = LOS_TickCountGet();
|
||||
swtmrHandle.handler(swtmrHandle.arg);
|
||||
tick = LOS_TickCountGet() - tick;
|
||||
if (tick >= SWTMR_MAX_RUNNING_TICKS) {
|
||||
PRINT_WARN("timer_handler(%p) cost too many ms(%d)\n",
|
||||
swtmrHandle.handler,
|
||||
(UINT32)((tick * OS_SYS_MS_PER_SECOND) / LOSCFG_BASE_CORE_TICK_PER_SECOND));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrTaskCreate
|
||||
Description : Create Software Timer
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
TSK_INIT_PARAM_S swtmrTask;
|
||||
|
||||
// Ignore the return code when matching CSEC rule 6.6(4).
|
||||
(VOID)memset_s(&swtmrTask, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S));
|
||||
|
||||
swtmrTask.pfnTaskEntry = (TSK_ENTRY_FUNC)OsSwtmrTask;
|
||||
swtmrTask.uwStackSize = LOSCFG_BASE_CORE_TSK_SWTMR_STACK_SIZE;
|
||||
swtmrTask.pcName = "Swt_Task";
|
||||
swtmrTask.usTaskPrio = 0;
|
||||
ret = LOS_TaskCreate(&g_swtmrTaskID, &swtmrTask);
|
||||
if (ret == LOS_OK) {
|
||||
OS_TCB_FROM_TID(g_swtmrTaskID)->taskStatus |= OS_TASK_FLAG_SYSTEM_TASK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
STATIC UINT64 OsSwtmrCalcStartTime(UINT64 currTime, SWTMR_CTRL_S *swtmr, const SWTMR_CTRL_S *alignSwtmr)
|
||||
{
|
||||
UINT64 usedTime, startTime;
|
||||
UINT64 alignEnd = OS_SYS_TICK_TO_CYCLE(alignSwtmr->uwInterval);
|
||||
UINT64 swtmrTime = OS_SYS_TICK_TO_CYCLE(swtmr->uwInterval);
|
||||
UINT64 remainTime = OsSortLinkGetRemainTime(currTime, &alignSwtmr->stSortList);
|
||||
if (remainTime == 0) {
|
||||
startTime = GET_SORTLIST_VALUE(&alignSwtmr->stSortList);
|
||||
} else {
|
||||
usedTime = alignEnd - remainTime;
|
||||
startTime = alignSwtmr->startTime + (usedTime / swtmrTime) * swtmrTime;
|
||||
}
|
||||
|
||||
return startTime;
|
||||
}
|
||||
|
||||
UINT64 OsSwtmrFindAlignPos(UINT64 currTime, SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
SWTMR_CTRL_S *minInLarge = (SWTMR_CTRL_S *)NULL;
|
||||
SWTMR_CTRL_S *maxInLittle = (SWTMR_CTRL_S *)NULL;
|
||||
UINT32 minInLargeVal = OS_NULL_INT;
|
||||
UINT32 maxInLittleVal = OS_NULL_INT;
|
||||
LOS_DL_LIST *listHead = &g_swtmrSortLinkList->sortLink;
|
||||
SwtmrAlignData swtmrAlgInfo = g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT];
|
||||
LOS_DL_LIST *listObject = listHead->pstNext;
|
||||
|
||||
if (LOS_ListEmpty(listHead)) {
|
||||
goto RETURN_PERIOD;
|
||||
}
|
||||
|
||||
do {
|
||||
SortLinkList *sortList = LOS_DL_LIST_ENTRY(listObject, SortLinkList, sortLinkNode);
|
||||
SWTMR_CTRL_S *swtmrListNode = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
|
||||
SwtmrAlignData alignListNode = g_swtmrAlignID[swtmrListNode->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT];
|
||||
|
||||
/* swtmr not start */
|
||||
if ((alignListNode.isAligned == 0) || (alignListNode.canAlign == 0)) {
|
||||
goto CONTINUE_NEXT_NODE;
|
||||
}
|
||||
|
||||
/* find same interval timer, directly return */
|
||||
if (swtmrListNode->uwInterval == swtmr->uwInterval) {
|
||||
return OsSwtmrCalcStartTime(currTime, swtmr, swtmrListNode);
|
||||
}
|
||||
|
||||
if ((swtmrAlgInfo.canMultiple != 1) || (alignListNode.times == 0)) {
|
||||
goto CONTINUE_NEXT_NODE;
|
||||
}
|
||||
|
||||
if (swtmrAlgInfo.times == 0) {
|
||||
goto RETURN_PERIOD;
|
||||
}
|
||||
|
||||
if ((alignListNode.times >= swtmrAlgInfo.times) && ((alignListNode.times % swtmrAlgInfo.times) == 0)) {
|
||||
if (minInLargeVal > (alignListNode.times / swtmrAlgInfo.times)) {
|
||||
minInLargeVal = alignListNode.times / swtmrAlgInfo.times;
|
||||
minInLarge = swtmrListNode;
|
||||
}
|
||||
} else if ((alignListNode.times < swtmrAlgInfo.times) && ((swtmrAlgInfo.times % alignListNode.times) == 0)) {
|
||||
if (maxInLittleVal > (swtmrAlgInfo.times / alignListNode.times)) {
|
||||
maxInLittleVal = swtmrAlgInfo.times / alignListNode.times;
|
||||
maxInLittle = swtmrListNode;
|
||||
}
|
||||
}
|
||||
|
||||
CONTINUE_NEXT_NODE:
|
||||
listObject = listObject->pstNext;
|
||||
} while (listObject != listHead);
|
||||
|
||||
if (minInLarge != NULL) {
|
||||
return OsSwtmrCalcStartTime(currTime, swtmr, minInLarge);
|
||||
} else if (maxInLittle != NULL) {
|
||||
return OsSwtmrCalcStartTime(currTime, swtmr, maxInLittle);
|
||||
}
|
||||
|
||||
RETURN_PERIOD:
|
||||
return currTime;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrStart
|
||||
Description : Start Software Timer
|
||||
Input : currTime ------- Current system time
|
||||
Input : swtmr ---------- Need to start Software Timer
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT VOID OsSwtmrStart(UINT64 currTime, SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
swtmr->ucState = OS_SWTMR_STATUS_TICKING;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
if ((g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].canAlign == 1) &&
|
||||
(g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].isAligned == 0)) {
|
||||
g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].isAligned = 1;
|
||||
swtmr->startTime = OsSwtmrFindAlignPos(currTime, swtmr);
|
||||
}
|
||||
#endif
|
||||
OsAdd2SortLink(&swtmr->stSortList, swtmr->startTime, swtmr->uwInterval, OS_SORT_LINK_SWTMR);
|
||||
OsSchedUpdateExpireTime();
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrDelete
|
||||
Description : Delete Software Timer
|
||||
Input : swtmr --- Need to delete Software Timer, When using, Ensure that it can't be NULL.
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
STATIC VOID OsSwtmrDelete(SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
if (swtmr->usTimerID < (OS_SWTMR_MAX_TIMERID - LOSCFG_BASE_CORE_SWTMR_LIMIT)) {
|
||||
swtmr->usTimerID += LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
} else {
|
||||
swtmr->usTimerID %= LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
}
|
||||
|
||||
/* insert to free list */
|
||||
swtmr->pstNext = g_swtmrFreeList;
|
||||
g_swtmrFreeList = swtmr;
|
||||
swtmr->ucState = OS_SWTMR_STATUS_UNUSED;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
(VOID)memset_s((VOID *)&g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT],
|
||||
sizeof(SwtmrAlignData), 0, sizeof(SwtmrAlignData));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsSwtmrStop(SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
OsDeleteSortLink(&swtmr->stSortList);
|
||||
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
|
||||
|
||||
swtmr->ucOverrun = 0;
|
||||
OsSchedUpdateExpireTime();
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].isAligned = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC VOID OsSwtmrTimeoutHandle(UINT64 currTime, SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
SwtmrHandlerItem swtmrHandler;
|
||||
|
||||
swtmrHandler.handler = swtmr->pfnHandler;
|
||||
swtmrHandler.arg = swtmr->uwArg;
|
||||
swtmrHandler.swtmrID = swtmr->usTimerID;
|
||||
|
||||
(VOID)LOS_QueueWriteCopy(g_swtmrHandlerQueue, &swtmrHandler, sizeof(SwtmrHandlerItem), LOS_NO_WAIT);
|
||||
if (swtmr->ucMode == LOS_SWTMR_MODE_PERIOD) {
|
||||
swtmr->ucOverrun++;
|
||||
OsSwtmrStart(currTime, swtmr);
|
||||
} else if (swtmr->ucMode == LOS_SWTMR_MODE_NO_SELFDELETE) {
|
||||
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC BOOL OsSwtmrScan(VOID)
|
||||
{
|
||||
BOOL needSchedule = FALSE;
|
||||
LOS_DL_LIST *listObject = &g_swtmrSortLinkList->sortLink;
|
||||
|
||||
if (LOS_ListEmpty(listObject)) {
|
||||
return needSchedule;
|
||||
}
|
||||
|
||||
SortLinkList *sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
|
||||
UINT64 currTime = OsGetCurrSchedTimeCycle();
|
||||
while (sortList->responseTime <= currTime) {
|
||||
SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
|
||||
swtmr->startTime = GET_SORTLIST_VALUE(sortList);
|
||||
|
||||
OsDeleteNodeSortLink(sortList);
|
||||
OsHookCall(LOS_HOOK_TYPE_SWTMR_EXPIRED, swtmr);
|
||||
OsSwtmrTimeoutHandle(currTime, swtmr);
|
||||
|
||||
needSchedule = TRUE;
|
||||
if (LOS_ListEmpty(listObject)) {
|
||||
break;
|
||||
}
|
||||
|
||||
sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
|
||||
}
|
||||
|
||||
return needSchedule;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsSwtmrResponseTimeReset(UINT64 startTime)
|
||||
{
|
||||
LOS_DL_LIST *listHead = &g_swtmrSortLinkList->sortLink;
|
||||
LOS_DL_LIST *listNext = listHead->pstNext;
|
||||
|
||||
while (listNext != listHead) {
|
||||
SortLinkList *sortList = LOS_DL_LIST_ENTRY(listNext, SortLinkList, sortLinkNode);
|
||||
SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
|
||||
OsDeleteNodeSortLink(sortList);
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].isAligned = 0;
|
||||
#endif
|
||||
swtmr->startTime = startTime;
|
||||
OsSwtmrStart(startTime, swtmr);
|
||||
listNext = listNext->pstNext;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrGetNextTimeout
|
||||
Description : Get next timeout
|
||||
Input : None
|
||||
Output : None
|
||||
Return : Count of the Timer list
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
|
||||
{
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
UINT64 time = OsSortLinkGetNextExpireTime(g_swtmrSortLinkList);
|
||||
LOS_IntRestore(intSave);
|
||||
time = OS_SYS_CYCLE_TO_TICK(time);
|
||||
if (time > OS_NULL_INT) {
|
||||
time = OS_NULL_INT;
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 OsSwtmrTimeGet(const SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
UINT64 time = OsSortLinkGetTargetExpireTime(OsGetCurrSchedTimeCycle(), &swtmr->stSortList);
|
||||
time = OS_SYS_CYCLE_TO_TICK(time);
|
||||
if (time > OS_NULL_INT) {
|
||||
time = OS_NULL_INT;
|
||||
}
|
||||
return (UINT32)time;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrInit
|
||||
Description : Initializes Software Timer
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
|
||||
{
|
||||
UINT32 size;
|
||||
UINT16 index;
|
||||
UINT32 ret;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
// Ignore the return code when matching CSEC rule 6.6(1).
|
||||
(VOID)memset_s((VOID *)g_swtmrAlignID, sizeof(SwtmrAlignData) * LOSCFG_BASE_CORE_SWTMR_LIMIT,
|
||||
0, sizeof(SwtmrAlignData) * LOSCFG_BASE_CORE_SWTMR_LIMIT);
|
||||
#endif
|
||||
|
||||
size = sizeof(SWTMR_CTRL_S) * LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
SWTMR_CTRL_S *swtmr = (SWTMR_CTRL_S *)LOS_MemAlloc(m_aucSysMem0, size);
|
||||
if (swtmr == NULL) {
|
||||
return LOS_ERRNO_SWTMR_NO_MEMORY;
|
||||
}
|
||||
// Ignore the return code when matching CSEC rule 6.6(3).
|
||||
(VOID)memset_s((VOID *)swtmr, size, 0, size);
|
||||
g_swtmrCBArray = swtmr;
|
||||
g_swtmrFreeList = swtmr;
|
||||
swtmr->usTimerID = 0;
|
||||
SWTMR_CTRL_S *temp = swtmr;
|
||||
swtmr++;
|
||||
for (index = 1; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) {
|
||||
swtmr->usTimerID = index;
|
||||
temp->pstNext = swtmr;
|
||||
temp = swtmr;
|
||||
}
|
||||
|
||||
ret = LOS_QueueCreate((CHAR *)NULL, OS_SWTMR_HANDLE_QUEUE_SIZE,
|
||||
&g_swtmrHandlerQueue, 0, sizeof(SwtmrHandlerItem));
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, swtmr);
|
||||
return LOS_ERRNO_SWTMR_QUEUE_CREATE_FAILED;
|
||||
}
|
||||
|
||||
ret = OsSwtmrTaskCreate();
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, swtmr);
|
||||
return LOS_ERRNO_SWTMR_TASK_CREATE_FAILED;
|
||||
}
|
||||
|
||||
g_swtmrSortLinkList = OsGetSortLinkAttribute(OS_SORT_LINK_SWTMR);
|
||||
if (g_swtmrSortLinkList == NULL) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, swtmr);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = OsSortLinkInit(g_swtmrSortLinkList);
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, swtmr);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = OsSchedSwtmrScanRegister((SchedScan)OsSwtmrScan);
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, swtmr);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SwtmrCreate
|
||||
Description : Create software timer
|
||||
Input : interval
|
||||
mode
|
||||
handler
|
||||
arg
|
||||
Output : swtmrId
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
|
||||
UINT8 mode,
|
||||
SWTMR_PROC_FUNC handler,
|
||||
UINT32 *swtmrId,
|
||||
UINT32 arg,
|
||||
UINT8 rouses,
|
||||
UINT8 sensitive)
|
||||
#else
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
|
||||
UINT8 mode,
|
||||
SWTMR_PROC_FUNC handler,
|
||||
UINT32 *swtmrId,
|
||||
UINT32 arg)
|
||||
#endif
|
||||
{
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
UINT32 intSave;
|
||||
|
||||
if (interval == 0) {
|
||||
return LOS_ERRNO_SWTMR_INTERVAL_NOT_SUITED;
|
||||
}
|
||||
|
||||
if ((mode != LOS_SWTMR_MODE_ONCE) &&
|
||||
(mode != LOS_SWTMR_MODE_PERIOD) &&
|
||||
(mode != LOS_SWTMR_MODE_NO_SELFDELETE)) {
|
||||
return LOS_ERRNO_SWTMR_MODE_INVALID;
|
||||
}
|
||||
|
||||
if (handler == NULL) {
|
||||
return LOS_ERRNO_SWTMR_PTR_NULL;
|
||||
}
|
||||
|
||||
if (swtmrId == NULL) {
|
||||
return LOS_ERRNO_SWTMR_RET_PTR_NULL;
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
if ((rouses != OS_SWTMR_ROUSES_IGNORE) && (rouses != OS_SWTMR_ROUSES_ALLOW)) {
|
||||
return OS_ERRNO_SWTMR_ROUSES_INVALID;
|
||||
}
|
||||
|
||||
if ((sensitive != OS_SWTMR_ALIGN_INSENSITIVE) && (sensitive != OS_SWTMR_ALIGN_SENSITIVE)) {
|
||||
return OS_ERRNO_SWTMR_ALIGN_INVALID;
|
||||
}
|
||||
#endif
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (g_swtmrFreeList == NULL) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SWTMR_MAXSIZE;
|
||||
}
|
||||
|
||||
swtmr = g_swtmrFreeList;
|
||||
g_swtmrFreeList = swtmr->pstNext;
|
||||
LOS_IntRestore(intSave);
|
||||
swtmr->pfnHandler = handler;
|
||||
swtmr->ucMode = mode;
|
||||
swtmr->uwInterval = interval;
|
||||
swtmr->pstNext = (SWTMR_CTRL_S *)NULL;
|
||||
swtmr->uwArg = arg;
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
swtmr->ucRouses = rouses;
|
||||
swtmr->ucSensitive = sensitive;
|
||||
#endif
|
||||
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
|
||||
swtmr->ucOverrun = 0;
|
||||
*swtmrId = swtmr->usTimerID;
|
||||
SET_SORTLIST_VALUE(&swtmr->stSortList, OS_SORT_LINK_INVALID_TIME);
|
||||
OsHookCall(LOS_HOOK_TYPE_SWTMR_CREATE, swtmr);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SwtmrStart
|
||||
Description : Start software timer
|
||||
Input : swtmrId ------- Software timer ID
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT32 swtmrId)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret = LOS_OK;
|
||||
|
||||
if (swtmrId >= OS_SWTMR_MAX_TIMERID) {
|
||||
return LOS_ERRNO_SWTMR_ID_INVALID;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
SWTMR_CTRL_S *swtmr = g_swtmrCBArray + swtmrId % LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
if (swtmr->usTimerID != swtmrId) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
if ((swtmr->ucSensitive == OS_SWTMR_ALIGN_INSENSITIVE) && (swtmr->ucMode == LOS_SWTMR_MODE_PERIOD)) {
|
||||
UINT32 swtmrAlignIdIndex = swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
g_swtmrAlignID[swtmrAlignIdIndex].canAlign = 1;
|
||||
if ((swtmr->uwInterval % LOS_COMMON_DIVISOR) == 0) {
|
||||
g_swtmrAlignID[swtmrAlignIdIndex].canMultiple = 1;
|
||||
g_swtmrAlignID[swtmrAlignIdIndex].times = swtmr->uwInterval / LOS_COMMON_DIVISOR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (swtmr->ucState) {
|
||||
case OS_SWTMR_STATUS_UNUSED:
|
||||
ret = LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
OsSwtmrStop(swtmr);
|
||||
/* fall through */
|
||||
case OS_SWTMR_STATUS_CREATED:
|
||||
swtmr->startTime = OsGetCurrSchedTimeCycle();
|
||||
OsSwtmrStart(swtmr->startTime, swtmr);
|
||||
break;
|
||||
default:
|
||||
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
|
||||
break;
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_SWTMR_START, swtmr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SwtmrStop
|
||||
Description : Stop software timer
|
||||
Input : swtmrId ------- Software timer ID
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT32 swtmrId)
|
||||
{
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
UINT32 intSave;
|
||||
UINT16 swtmrCbId;
|
||||
UINT32 ret = LOS_OK;
|
||||
|
||||
if (swtmrId >= OS_SWTMR_MAX_TIMERID) {
|
||||
return LOS_ERRNO_SWTMR_ID_INVALID;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
swtmrCbId = swtmrId % LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
swtmr = g_swtmrCBArray + swtmrCbId;
|
||||
if (swtmr->usTimerID != swtmrId) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
}
|
||||
|
||||
switch (swtmr->ucState) {
|
||||
case OS_SWTMR_STATUS_UNUSED:
|
||||
ret = LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_CREATED:
|
||||
ret = LOS_ERRNO_SWTMR_NOT_STARTED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
OsSwtmrStop(swtmr);
|
||||
break;
|
||||
default:
|
||||
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
|
||||
break;
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_SWTMR_STOP, swtmr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrTimeGet(UINT32 swtmrId, UINT32 *tick)
|
||||
{
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
UINT32 intSave;
|
||||
UINT32 ret = LOS_OK;
|
||||
UINT16 swtmrCbId;
|
||||
|
||||
if (swtmrId >= OS_SWTMR_MAX_TIMERID) {
|
||||
return LOS_ERRNO_SWTMR_ID_INVALID;
|
||||
}
|
||||
|
||||
if (tick == NULL) {
|
||||
return LOS_ERRNO_SWTMR_TICK_PTR_NULL;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
swtmrCbId = swtmrId % LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
swtmr = g_swtmrCBArray + swtmrCbId;
|
||||
if (swtmr->usTimerID != swtmrId) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
}
|
||||
switch (swtmr->ucState) {
|
||||
case OS_SWTMR_STATUS_UNUSED:
|
||||
ret = LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_CREATED:
|
||||
ret = LOS_ERRNO_SWTMR_NOT_STARTED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
*tick = OsSwtmrTimeGet(swtmr);
|
||||
break;
|
||||
default:
|
||||
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
|
||||
break;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SwtmrDelete
|
||||
Description : Delete software timer
|
||||
Input : swtmrId ------- Software timer ID
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT32 swtmrId)
|
||||
{
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
UINT32 intSave;
|
||||
UINT32 ret = LOS_OK;
|
||||
UINT16 swtmrCbId;
|
||||
|
||||
if (swtmrId >= OS_SWTMR_MAX_TIMERID) {
|
||||
return LOS_ERRNO_SWTMR_ID_INVALID;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
swtmrCbId = swtmrId % LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
swtmr = g_swtmrCBArray + swtmrCbId;
|
||||
if (swtmr->usTimerID != swtmrId) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
}
|
||||
|
||||
switch (swtmr->ucState) {
|
||||
case OS_SWTMR_STATUS_UNUSED:
|
||||
ret = LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
OsSwtmrStop(swtmr);
|
||||
/* fall through */
|
||||
case OS_SWTMR_STATUS_CREATED:
|
||||
OsSwtmrDelete(swtmr);
|
||||
break;
|
||||
default:
|
||||
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
|
||||
break;
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
OsHookCall(LOS_HOOK_TYPE_SWTMR_DELETE, swtmr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* (LOSCFG_BASE_CORE_SWTMR == 1) */
|
||||
1627
ohos/kernel/liteos_m/kernel/src/los_task.c
Normal file
1627
ohos/kernel/liteos_m/kernel/src/los_task.c
Normal file
File diff suppressed because it is too large
Load Diff
451
ohos/kernel/liteos_m/kernel/src/los_tick.c
Normal file
451
ohos/kernel/liteos_m/kernel/src/los_tick.c
Normal file
@@ -0,0 +1,451 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_tick.h"
|
||||
#include "securec.h"
|
||||
#include "los_config.h"
|
||||
#include "los_task.h"
|
||||
#include "los_swtmr.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
#include "stdint.h"
|
||||
|
||||
LITE_OS_SEC_BSS STATIC ArchTickTimer *g_sysTickTimer = NULL;
|
||||
LITE_OS_SEC_BSS UINT32 g_ticksPerSec;
|
||||
LITE_OS_SEC_BSS UINT32 g_uwCyclePerSec;
|
||||
LITE_OS_SEC_BSS UINT32 g_cyclesPerTick;
|
||||
LITE_OS_SEC_BSS UINT32 g_sysClock;
|
||||
LITE_OS_SEC_BSS STATIC BOOL g_sysTimerIsInit = FALSE;
|
||||
LITE_OS_SEC_BSS STATIC UINT64 g_tickTimerStartTime;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
STATIC UINT64 g_tickTimerBase;
|
||||
STATIC UINT64 g_oldTickTimerBase;
|
||||
STATIC BOOL g_tickTimerBaseUpdate = FALSE;
|
||||
|
||||
LITE_OS_SEC_TEXT STATIC VOID OsUpdateSysTimeBase(VOID)
|
||||
{
|
||||
UINT32 period = 0;
|
||||
|
||||
if (g_tickTimerBaseUpdate == FALSE) {
|
||||
(VOID)g_sysTickTimer->getCycle(&period);
|
||||
g_tickTimerBase += period;
|
||||
}
|
||||
g_tickTimerBaseUpdate = FALSE;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsTickTimerBaseReset(UINT64 currTime)
|
||||
{
|
||||
LOS_ASSERT(currTime >= g_tickTimerBase);
|
||||
|
||||
g_tickTimerBase = currTime;
|
||||
}
|
||||
#endif
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsTickHandler(VOID)
|
||||
{
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
OsUpdateSysTimeBase();
|
||||
#endif
|
||||
|
||||
LOS_SchedTickHandler();
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT64 OsTickTimerReload(UINT64 period)
|
||||
{
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
g_tickTimerBase = LOS_SysCycleGet();
|
||||
#endif
|
||||
return g_sysTickTimer->reload(period);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT64 LOS_SysCycleGet(VOID)
|
||||
{
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 1)
|
||||
return g_sysTickTimer->getCycle(NULL);
|
||||
#else
|
||||
UINT32 period = 0;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
UINT64 time = g_sysTickTimer->getCycle(&period);
|
||||
UINT64 schedTime = g_tickTimerBase + time;
|
||||
if (schedTime < g_oldTickTimerBase) {
|
||||
/* Turn the timer count */
|
||||
g_tickTimerBase += period;
|
||||
schedTime = g_tickTimerBase + time;
|
||||
g_tickTimerBaseUpdate = TRUE;
|
||||
}
|
||||
|
||||
LOS_ASSERT(schedTime >= g_oldTickTimerBase);
|
||||
|
||||
g_oldTickTimerBase = schedTime;
|
||||
LOS_IntRestore(intSave);
|
||||
return schedTime;
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC UINT32 TickTimerCheck(const ArchTickTimer *tick)
|
||||
{
|
||||
if (tick == NULL) {
|
||||
return LOS_ERRNO_SYS_PTR_NULL;
|
||||
}
|
||||
|
||||
if ((tick->freq == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > tick->freq)) {
|
||||
return LOS_ERRNO_SYS_CLOCK_INVALID;
|
||||
}
|
||||
|
||||
if (tick->irqNum > (INT32)LOSCFG_PLATFORM_HWI_LIMIT) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
|
||||
if (tick->periodMax == 0) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
|
||||
if ((tick->init == NULL) || (tick->reload == NULL) ||
|
||||
(tick->lock == NULL) || (tick->unlock == NULL) ||
|
||||
(tick->getCycle == NULL)) {
|
||||
return LOS_ERRNO_SYS_HOOK_IS_NULL;
|
||||
}
|
||||
|
||||
if (g_sysTimerIsInit) {
|
||||
return LOS_ERRNO_SYS_TIMER_IS_RUNNING;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsTickTimerInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
HWI_PROC_FUNC tickHandler = (HWI_PROC_FUNC)OsTickHandler;
|
||||
|
||||
g_sysTickTimer = LOS_SysTickTimerGet();
|
||||
if ((g_sysTickTimer->init == NULL) || (g_sysTickTimer->reload == NULL) ||
|
||||
(g_sysTickTimer->lock == NULL) || (g_sysTickTimer->unlock == NULL) ||
|
||||
(g_sysTickTimer->getCycle == NULL)) {
|
||||
return LOS_ERRNO_SYS_HOOK_IS_NULL;
|
||||
}
|
||||
|
||||
if (g_sysTickTimer->tickHandler != NULL) {
|
||||
tickHandler = g_sysTickTimer->tickHandler;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
ret = g_sysTickTimer->init(tickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((g_sysTickTimer->freq == 0) || (g_sysTickTimer->freq < LOSCFG_BASE_CORE_TICK_PER_SECOND)) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SYS_CLOCK_INVALID;
|
||||
}
|
||||
|
||||
if (g_sysTickTimer->irqNum > (INT32)LOSCFG_PLATFORM_HWI_LIMIT) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
|
||||
g_sysClock = g_sysTickTimer->freq;
|
||||
g_cyclesPerTick = g_sysTickTimer->freq / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
g_sysTimerIsInit = TRUE;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_TickTimerRegister(const ArchTickTimer *timer, const HWI_PROC_FUNC tickHandler)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
|
||||
if ((timer == NULL) && (tickHandler == NULL)) {
|
||||
return LOS_ERRNO_SYS_PTR_NULL;
|
||||
}
|
||||
|
||||
if (timer != NULL) {
|
||||
ret = TickTimerCheck(timer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (g_sysTickTimer == NULL) {
|
||||
g_sysTickTimer = LOS_SysTickTimerGet();
|
||||
}
|
||||
|
||||
if (g_sysTickTimer == timer) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SYS_TIMER_ADDR_FAULT;
|
||||
}
|
||||
|
||||
errno_t errRet = memcpy_s(g_sysTickTimer, sizeof(ArchTickTimer), timer, sizeof(ArchTickTimer));
|
||||
if (errRet != EOK) {
|
||||
PRINT_ERR("%s timer addr fault! errno %d\n", __FUNCTION__, errRet);
|
||||
ret = LOS_ERRNO_SYS_TIMER_ADDR_FAULT;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (g_sysTimerIsInit) {
|
||||
return LOS_ERRNO_SYS_TIMER_IS_RUNNING;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (g_sysTickTimer == NULL) {
|
||||
g_sysTickTimer = LOS_SysTickTimerGet();
|
||||
}
|
||||
|
||||
g_sysTickTimer->tickHandler = tickHandler;
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 LOS_SysTickClockFreqAdjust(const SYS_TICK_FREQ_ADJUST_FUNC handler, UINTPTR param)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 freq;
|
||||
UINT32 oldFreq = g_sysClock;
|
||||
|
||||
if (handler == NULL) {
|
||||
return LOS_ERRNO_SYS_HOOK_IS_NULL;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_sysTickTimer->lock();
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
UINT64 currTimeCycle = LOS_SysCycleGet();
|
||||
#endif
|
||||
|
||||
freq = handler(param);
|
||||
if ((freq == 0) || (freq == g_sysClock)) {
|
||||
g_sysTickTimer->unlock();
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SYS_CLOCK_INVALID;
|
||||
}
|
||||
|
||||
g_sysTickTimer->reload(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
g_sysTickTimer->unlock();
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
g_tickTimerBase = OsTimeConvertFreq(currTimeCycle, oldFreq, freq);
|
||||
g_oldTickTimerBase = OsTimeConvertFreq(g_oldTickTimerBase, oldFreq, freq);
|
||||
g_tickTimerStartTime = OsTimeConvertFreq(g_tickTimerStartTime, oldFreq, freq);
|
||||
#endif
|
||||
|
||||
g_sysTickTimer->freq = freq;
|
||||
g_sysClock = g_sysTickTimer->freq;
|
||||
g_cyclesPerTick = g_sysTickTimer->freq / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
OsSchedTimeConvertFreq(oldFreq);
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsTickSysTimerStartTimeSet(UINT64 currTime)
|
||||
{
|
||||
g_tickTimerStartTime = currTime;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_TickCountGet
|
||||
Description : get current tick
|
||||
Input : None
|
||||
Output : None
|
||||
Return : current tick
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID)
|
||||
{
|
||||
return OS_SYS_CYCLE_TO_TICK(LOS_SysCycleGet() - g_tickTimerStartTime);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_CyclePerTickGet
|
||||
Description : Get System cycle number corresponding to each tick
|
||||
Input : None
|
||||
Output : None
|
||||
Return : cycle number corresponding to each tick
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CyclePerTickGet(VOID)
|
||||
{
|
||||
return g_cyclesPerTick;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_MS2Tick
|
||||
Description : milliseconds convert to Tick
|
||||
Input : millisec ---------- milliseconds
|
||||
Output : None
|
||||
Return : Tick
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MS2Tick(UINT32 millisec)
|
||||
{
|
||||
if (millisec == OS_NULL_INT) {
|
||||
return OS_NULL_INT;
|
||||
}
|
||||
|
||||
return ((UINT64)millisec * LOSCFG_BASE_CORE_TICK_PER_SECOND) / OS_SYS_MS_PER_SECOND;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_Tick2MS
|
||||
Description : Tick convert to milliseconds
|
||||
Input : ticks ---------- ticks
|
||||
Output : None
|
||||
Return : milliseconds
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_Tick2MS(UINT32 ticks)
|
||||
{
|
||||
return ((UINT64)ticks * OS_SYS_MS_PER_SECOND) / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsCpuTick2MS
|
||||
Description : cycle convert to milliseconds
|
||||
Input : cpuTick ---------- cycle
|
||||
Output : msHi ---------- High 32 milliseconds
|
||||
msLo ---------- Low 32 milliseconds
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsCpuTick2MS(CpuTick *cpuTick, UINT32 *msHi, UINT32 *msLo)
|
||||
{
|
||||
UINT64 tmpCpuTick;
|
||||
DOUBLE temp;
|
||||
|
||||
if ((cpuTick == NULL) || (msHi == NULL) || (msLo == NULL)) {
|
||||
return LOS_ERRNO_SYS_PTR_NULL;
|
||||
}
|
||||
|
||||
if (g_sysClock == 0) {
|
||||
return LOS_ERRNO_SYS_CLOCK_INVALID;
|
||||
}
|
||||
tmpCpuTick = ((UINT64)cpuTick->cntHi << OS_SYS_MV_32_BIT) | cpuTick->cntLo;
|
||||
temp = tmpCpuTick / ((DOUBLE)g_sysClock / OS_SYS_MS_PER_SECOND);
|
||||
|
||||
tmpCpuTick = (UINT64)temp;
|
||||
|
||||
*msLo = (UINT32)tmpCpuTick;
|
||||
*msHi = (UINT32)(tmpCpuTick >> OS_SYS_MV_32_BIT);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsCpuTick2US
|
||||
Description : cycle convert to Microsecond
|
||||
Input : cpuTick ---------- cycle
|
||||
Output : usHi ---------- High 32 Microsecond
|
||||
usLo ---------- Low 32 Microsecond
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsCpuTick2US(CpuTick *cpuTick, UINT32 *usHi, UINT32 *usLo)
|
||||
{
|
||||
UINT64 tmpCpuTick;
|
||||
DOUBLE temp;
|
||||
|
||||
if ((cpuTick == NULL) || (usHi == NULL) || (usLo == NULL)) {
|
||||
return LOS_ERRNO_SYS_PTR_NULL;
|
||||
}
|
||||
|
||||
if (g_sysClock == 0) {
|
||||
return LOS_ERRNO_SYS_CLOCK_INVALID;
|
||||
}
|
||||
tmpCpuTick = ((UINT64)cpuTick->cntHi << OS_SYS_MV_32_BIT) | cpuTick->cntLo;
|
||||
temp = tmpCpuTick / ((DOUBLE)g_sysClock / OS_SYS_US_PER_SECOND);
|
||||
|
||||
tmpCpuTick = (UINT64)temp;
|
||||
|
||||
*usLo = (UINT32)tmpCpuTick;
|
||||
*usHi = (UINT32)(tmpCpuTick >> OS_SYS_MV_32_BIT);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_MS2Tick
|
||||
Description : get current nanoseconds
|
||||
Input : None
|
||||
Output : None
|
||||
Return : nanoseconds
|
||||
*****************************************************************************/
|
||||
UINT64 LOS_CurrNanosec(VOID)
|
||||
{
|
||||
UINT64 nanos;
|
||||
nanos = LOS_SysCycleGet() * (OS_SYS_NS_PER_SECOND / OS_SYS_NS_PER_MS) / (g_sysClock / OS_SYS_NS_PER_MS);
|
||||
return nanos;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_UDelay
|
||||
Description : cpu delay function
|
||||
Input : microseconds ---------- microseconds
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
VOID LOS_UDelay(UINT64 microseconds)
|
||||
{
|
||||
UINT64 endTime;
|
||||
|
||||
if (microseconds == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
endTime = (microseconds / OS_SYS_US_PER_SECOND) * g_sysClock +
|
||||
(microseconds % OS_SYS_US_PER_SECOND) * g_sysClock / OS_SYS_US_PER_SECOND;
|
||||
endTime = LOS_SysCycleGet() + endTime;
|
||||
while (LOS_SysCycleGet() < endTime) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_MDelay
|
||||
Description : cpu delay function
|
||||
Input : millisec ---------- milliseconds
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
VOID LOS_MDelay(UINT32 millisec)
|
||||
{
|
||||
UINT32 delayUs = (UINT32_MAX / OS_SYS_US_PER_MS) * OS_SYS_US_PER_MS;
|
||||
while (millisec > UINT32_MAX / OS_SYS_US_PER_MS) {
|
||||
LOS_UDelay(delayUs);
|
||||
millisec -= (UINT32_MAX / OS_SYS_US_PER_MS);
|
||||
}
|
||||
LOS_UDelay(millisec * OS_SYS_US_PER_MS);
|
||||
return;
|
||||
}
|
||||
147
ohos/kernel/liteos_m/utils/internal/los_hook_types.h
Normal file
147
ohos/kernel/liteos_m/utils/internal/los_hook_types.h
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 _LOS_HOOK_TYPES_H
|
||||
#define _LOS_HOOK_TYPES_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
#include "los_config.h"
|
||||
#include "los_context.h"
|
||||
#include "los_event.h"
|
||||
#include "los_mux.h"
|
||||
#include "los_queue.h"
|
||||
#include "los_sem.h"
|
||||
#include "los_task.h"
|
||||
#include "los_swtmr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_DEBUG_HOOK == 1)
|
||||
typedef VOID *VOID_PTR;
|
||||
#define LOS_HOOK_ALL_TYPES_DEF \
|
||||
/* Hook types supported by memory modules */ \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_INIT, (VOID_PTR pool, UINT32 size)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_DEINIT, (VOID_PTR pool)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_ALLOC, (VOID_PTR pool, VOID_PTR ptr, UINT32 size)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_FREE, (VOID_PTR pool, VOID_PTR ptr)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_REALLOC, (VOID_PTR pool, VOID_PTR ptr, UINT32 size)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_ALLOCALIGN, (VOID_PTR pool, VOID_PTR ptr, UINT32 size, UINT32 boundary)) \
|
||||
/* Hook types supported by event modules */ \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_INIT, (PEVENT_CB_S eventCB)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_READ, (PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, \
|
||||
UINT32 timeout)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_WRITE, (PEVENT_CB_S eventCB, UINT32 events)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_CLEAR, (PEVENT_CB_S eventCB, UINT32 events)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_DESTROY, (PEVENT_CB_S eventCB)) \
|
||||
/* Hook types supported by queue modules */ \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_CREATE, (const LosQueueCB *queueCB)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_READ, (const LosQueueCB *queueCB, UINT32 operateType, \
|
||||
UINT32 bufferSize, UINT32 timeout)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_READ_COPY, (const LosQueueCB *queueCB, UINT32 operateType, \
|
||||
UINT32 bufferSize, UINT32 timeout)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_WRITE, (const LosQueueCB *queueCB, UINT32 operateType, \
|
||||
UINT32 bufferSize, UINT32 timeout)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_WRITE_COPY, (const LosQueueCB *queueCB, UINT32 operateType, \
|
||||
UINT32 bufferSize, UINT32 timeout)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_DELETE, (const LosQueueCB *queueCB)) \
|
||||
/* Hook types supported by semaphore modules */ \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SEM_CREATE, (const LosSemCB *semCreated)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SEM_POST, (const LosSemCB *semPosted, const LosTaskCB *resumedTask)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SEM_PEND, (const LosSemCB *semPended, const LosTaskCB *runningTask, \
|
||||
UINT32 timeout)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SEM_DELETE, (const LosSemCB *semDeleted)) \
|
||||
/* Hook types supported by mutex modules */ \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_CREATE, (const LosMuxCB *muxCreated)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_POST, (const LosMuxCB *muxPosted)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_PEND, (const LosMuxCB *muxPended, UINT32 timeout)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_DELETE, (const LosMuxCB *muxDeleted)) \
|
||||
/* Hook types supported by task modules */ \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_CREATE, (const LosTaskCB *taskCB)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_DELAY, (UINT32 tick)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_PRIMODIFY, (const LosTaskCB *pxTask, UINT32 uxNewPriority)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_DELETE, (const LosTaskCB *taskCB)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_SWITCHEDIN, (VOID)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MOVEDTASKTOREADYSTATE, (const LosTaskCB *pstTaskCB)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MOVEDTASKTODELAYEDLIST, (const LosTaskCB *pstTaskCB)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MOVEDTASKTOSUSPENDEDLIST, (const LosTaskCB *pstTaskCB)) \
|
||||
/* Hook types supported by interrupt modules */ \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_ISR_EXITTOSCHEDULER, (VOID)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_ISR_ENTER, (UINT32 hwiIndex)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_ISR_EXIT, (UINT32 hwiIndex)) \
|
||||
/* Hook types supported by swtmr modules */ \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SWTMR_CREATE, (const SWTMR_CTRL_S *swtmr)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SWTMR_DELETE, (const SWTMR_CTRL_S *swtmr)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SWTMR_EXPIRED, (const SWTMR_CTRL_S *swtmr)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SWTMR_START, (const SWTMR_CTRL_S *swtmr)) \
|
||||
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SWTMR_STOP, (const SWTMR_CTRL_S *swtmr))
|
||||
|
||||
/**
|
||||
* Defines the types of all hooks.
|
||||
*/
|
||||
#define LOS_HOOK_TYPE_DEF(type, paramList) type,
|
||||
|
||||
typedef enum {
|
||||
/* Used to manage hook pools */
|
||||
LOS_HOOK_TYPE_START = 0,
|
||||
/* All supported hook types */
|
||||
LOS_HOOK_ALL_TYPES_DEF
|
||||
/* Used to manage hook pools */
|
||||
LOS_HOOK_TYPE_END
|
||||
} HookType;
|
||||
|
||||
#undef LOS_HOOK_TYPE_DEF
|
||||
|
||||
/**
|
||||
* Declare the type and interface of the hook functions.
|
||||
*/
|
||||
#define LOS_HOOK_TYPE_DEF(type, paramList) \
|
||||
typedef VOID (*type##_FN) paramList; \
|
||||
extern UINT32 type##_RegHook(type##_FN func); \
|
||||
extern UINT32 type##_UnRegHook(type##_FN func); \
|
||||
extern VOID type##_CallHook paramList;
|
||||
|
||||
LOS_HOOK_ALL_TYPES_DEF
|
||||
|
||||
#undef LOS_HOOK_TYPE_DEF
|
||||
|
||||
#endif /* LOSCFG_DEBUG_HOOK */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_HOOK_TYPES_H */
|
||||
76
ohos/kernel/liteos_m/utils/internal/los_hook_types_parse.h
Normal file
76
ohos/kernel/liteos_m/utils/internal/los_hook_types_parse.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 _LOS_HOOK_TYPES_PARSE_H
|
||||
#define _LOS_HOOK_TYPES_PARSE_H
|
||||
|
||||
#define ADDR(a) (&(a))
|
||||
#define ARGS(a) (a)
|
||||
#define ADDRn(...) _CONCAT(ADDR, _NARGS(__VA_ARGS__))(__VA_ARGS__)
|
||||
#define ARGSn(...) _CONCAT(ARGS, _NARGS(__VA_ARGS__))(__VA_ARGS__)
|
||||
#define ARGS0()
|
||||
#define ADDR0()
|
||||
#define ARGS1(a) ARGS(a)
|
||||
#define ADDR1(a) ADDR(a)
|
||||
|
||||
#define ARG_const _ARG_const(
|
||||
#define _ARG_const(a) ARG_CP_##a)
|
||||
#define ARG_CP_LosSemCB ADDR(
|
||||
#define ARG_CP_LosTaskCB ADDR(
|
||||
#define ARG_CP_UINT32 ADDR(
|
||||
#define ARG_CP_LosMuxCB ADDR(
|
||||
#define ARG_CP_LosQueueCB ADDR(
|
||||
#define ARG_CP_SWTMR_CTRL_S ADDR(
|
||||
#define ARG_UINT32 ARGS(
|
||||
#define ARG_VOID_PTR ARGS(
|
||||
#define ARG_PEVENT_CB_S ARGS(
|
||||
#define ARG_void ADDRn(
|
||||
#define ARG(a) ARG_##a)
|
||||
|
||||
#define PARAM_TO_ARGS1(a) ARG(a)
|
||||
#define PARAM_TO_ARGS2(a, b) ARG(a), PARAM_TO_ARGS1(b)
|
||||
#define PARAM_TO_ARGS3(a, b, c) ARG(a), PARAM_TO_ARGS2(b, c)
|
||||
#define PARAM_TO_ARGS4(a, b, c, d) ARG(a), PARAM_TO_ARGS3(b, c, d)
|
||||
#define PARAM_TO_ARGS5(a, b, c, d, e) ARG(a), PARAM_TO_ARGS4(b, c, d, e)
|
||||
#define PARAM_TO_ARGS6(a, b, c, d, e, f) ARG(a), PARAM_TO_ARGS5(b, c, d, e, f)
|
||||
#define PARAM_TO_ARGS7(a, b, c, d, e, f, g) ARG(a), PARAM_TO_ARGS6(b, c, d, e, f, g)
|
||||
|
||||
#define _ZERO_ARGS 7, 6, 5, 4, 3, 2, 1, 0
|
||||
#define ___NARGS(a, b, c, d, e, f, g, h, n, ...) n
|
||||
#define __NARGS(...) ___NARGS(__VA_ARGS__)
|
||||
#define _NARGS(...) __NARGS(x, __VA_ARGS__##_ZERO_ARGS, 7, 6, 5, 4, 3, 2, 1, 0)
|
||||
#define __CONCAT(a, b) a##b
|
||||
#define _CONCAT(a, b) __CONCAT(a, b)
|
||||
|
||||
#define PARAM_TO_ARGS(...) _CONCAT(PARAM_TO_ARGS, _NARGS(__VA_ARGS__))(__VA_ARGS__)
|
||||
#define OS_HOOK_PARAM_TO_ARGS(paramList) (PARAM_TO_ARGS paramList)
|
||||
|
||||
#endif /* _LOS_HOOK_TYPES_PARSE_H */
|
||||
546
ohos/kernel/liteos_m/utils/los_compiler.h
Normal file
546
ohos/kernel/liteos_m/utils/los_compiler.h
Normal file
@@ -0,0 +1,546 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2023 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 _LOS_COMPILER_H
|
||||
#define _LOS_COMPILER_H
|
||||
|
||||
/* for IAR Compiler */
|
||||
#ifdef __ICCARM__
|
||||
#include "iccarm_builtin.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* for IAR Compiler */
|
||||
#ifdef __ICCARM__
|
||||
|
||||
#ifndef ASM
|
||||
#define ASM __asm
|
||||
#endif
|
||||
|
||||
#ifndef INLINE
|
||||
#define INLINE inline
|
||||
#endif
|
||||
|
||||
#ifndef STATIC_INLINE
|
||||
#define STATIC_INLINE static inline
|
||||
#endif
|
||||
|
||||
#ifndef USED
|
||||
#define USED __root
|
||||
#endif
|
||||
|
||||
#ifndef WEAK
|
||||
#define WEAK __weak
|
||||
#endif
|
||||
|
||||
#ifndef CLZ
|
||||
#define CLZ __iar_builtin_CLZ
|
||||
#endif
|
||||
|
||||
#ifndef NORETURN
|
||||
#define NORETURN __attribute__ ((__noreturn__))
|
||||
#endif
|
||||
|
||||
#ifndef UNREACHABLE
|
||||
#define UNREACHABLE while (1)
|
||||
#endif
|
||||
|
||||
/* for ARM Compiler */
|
||||
#elif defined(__CC_ARM)
|
||||
|
||||
#ifndef ASM
|
||||
#define ASM __asm
|
||||
#endif
|
||||
|
||||
#ifndef INLINE
|
||||
#define INLINE __inline
|
||||
#endif
|
||||
|
||||
#ifndef STATIC_INLINE
|
||||
#define STATIC_INLINE static __inline
|
||||
#endif
|
||||
|
||||
#ifndef USED
|
||||
#define USED __attribute__((used))
|
||||
#endif
|
||||
|
||||
#ifndef WEAK
|
||||
#define WEAK __attribute__((weak))
|
||||
#endif
|
||||
|
||||
#ifndef CLZ
|
||||
#define CLZ __clz
|
||||
#endif
|
||||
|
||||
#ifndef NORETURN
|
||||
#define NORETURN __declspec(noreturn)
|
||||
#endif
|
||||
|
||||
#ifndef UNREACHABLE
|
||||
#define UNREACHABLE while (1)
|
||||
#endif
|
||||
|
||||
#pragma anon_unions
|
||||
|
||||
/* for GNU Compiler */
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
#ifndef ASM
|
||||
#define ASM __asm
|
||||
#endif
|
||||
|
||||
#ifndef INLINE
|
||||
#define INLINE inline
|
||||
#endif
|
||||
|
||||
#ifndef STATIC_INLINE
|
||||
#define STATIC_INLINE static inline
|
||||
#endif
|
||||
|
||||
#ifndef USED
|
||||
#define USED __attribute__((used))
|
||||
#endif
|
||||
|
||||
#ifndef WEAK
|
||||
#define WEAK __attribute__((weak))
|
||||
#endif
|
||||
|
||||
#ifndef CLZ
|
||||
#define CLZ __builtin_clz
|
||||
#endif
|
||||
|
||||
#ifndef NORETURN
|
||||
#define NORETURN __attribute__ ((__noreturn__))
|
||||
#endif
|
||||
|
||||
#ifndef UNREACHABLE
|
||||
#define UNREACHABLE __builtin_unreachable()
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error Unknown compiler.
|
||||
#endif
|
||||
|
||||
#ifndef STATIC
|
||||
#define STATIC static
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* Define inline keyword
|
||||
*/
|
||||
#ifndef INLINE
|
||||
#define INLINE static inline
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* Little endian
|
||||
*/
|
||||
#define OS_LITTLE_ENDIAN 0x1234
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* Big endian
|
||||
*/
|
||||
#define OS_BIG_ENDIAN 0x4321
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* Byte order
|
||||
*/
|
||||
#ifndef OS_BYTE_ORDER
|
||||
#define OS_BYTE_ORDER OS_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
/* Define OS code data sections */
|
||||
/* The indicator function is inline */
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* Allow inline sections
|
||||
*/
|
||||
#ifndef LITE_OS_SEC_ALW_INLINE
|
||||
#define LITE_OS_SEC_ALW_INLINE // __attribute__((always_inline))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* Vector table section
|
||||
*/
|
||||
#ifndef LITE_OS_SEC_VEC
|
||||
#define LITE_OS_SEC_VEC __attribute__ ((section(".vector")))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* .Text section (Code section)
|
||||
*/
|
||||
#ifndef LITE_OS_SEC_TEXT
|
||||
#define LITE_OS_SEC_TEXT // __attribute__((section(".sram.text")))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* .Text.ddr section
|
||||
*/
|
||||
#ifndef LITE_OS_SEC_TEXT_MINOR
|
||||
#define LITE_OS_SEC_TEXT_MINOR // __attribute__((section(".dyn.text")))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* .Text.init section
|
||||
*/
|
||||
#ifndef LITE_OS_SEC_TEXT_INIT
|
||||
#define LITE_OS_SEC_TEXT_INIT // __attribute__((section(".dyn.text")))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* .Data section
|
||||
*/
|
||||
#ifndef LITE_OS_SEC_DATA
|
||||
#define LITE_OS_SEC_DATA // __attribute__((section(".dyn.data")))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* .Data.init section
|
||||
*/
|
||||
#ifndef LITE_OS_SEC_DATA_INIT
|
||||
#define LITE_OS_SEC_DATA_INIT // __attribute__((section(".dyn.data")))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* Not initialized variable section
|
||||
*/
|
||||
#ifndef LITE_OS_SEC_BSS
|
||||
#define LITE_OS_SEC_BSS // __attribute__((section(".sym.bss")))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* .bss.ddr section
|
||||
*/
|
||||
#ifndef LITE_OS_SEC_BSS_MINOR
|
||||
#define LITE_OS_SEC_BSS_MINOR
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_builddef
|
||||
* .bss.init sections
|
||||
*/
|
||||
#ifndef LITE_OS_SEC_BSS_INIT
|
||||
#define LITE_OS_SEC_BSS_INIT
|
||||
#endif
|
||||
|
||||
#ifndef LITE_OS_SEC_TEXT_DATA
|
||||
#define LITE_OS_SEC_TEXT_DATA // __attribute__((section(".dyn.data")))
|
||||
#define LITE_OS_SEC_TEXT_BSS // __attribute__((section(".dyn.bss")))
|
||||
#define LITE_OS_SEC_TEXT_RODATA // __attribute__((section(".dyn.rodata")))
|
||||
#endif
|
||||
|
||||
#ifndef LITE_OS_SEC_SYMDATA
|
||||
#define LITE_OS_SEC_SYMDATA // __attribute__((section(".sym.data")))
|
||||
#endif
|
||||
|
||||
#ifndef LITE_OS_SEC_SYMBSS
|
||||
#define LITE_OS_SEC_SYMBSS // __attribute__((section(".sym.bss")))
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef LITE_OS_SEC_KEEP_DATA_DDR
|
||||
#define LITE_OS_SEC_KEEP_DATA_DDR // __attribute__((section(".keep.data.ddr")))
|
||||
#endif
|
||||
|
||||
#ifndef LITE_OS_SEC_KEEP_TEXT_DDR
|
||||
#define LITE_OS_SEC_KEEP_TEXT_DDR // __attribute__((section(".keep.text.ddr")))
|
||||
#endif
|
||||
|
||||
#ifndef LITE_OS_SEC_KEEP_DATA_SRAM
|
||||
#define LITE_OS_SEC_KEEP_DATA_SRAM // __attribute__((section(".keep.data.sram")))
|
||||
#endif
|
||||
|
||||
#ifndef LITE_OS_SEC_KEEP_TEXT_SRAM
|
||||
#define LITE_OS_SEC_KEEP_TEXT_SRAM // __attribute__((section(".keep.text.sram")))
|
||||
#endif
|
||||
|
||||
#ifndef LITE_OS_SEC_BSS_MINOR
|
||||
#define LITE_OS_SEC_BSS_MINOR
|
||||
#endif
|
||||
|
||||
/* type definitions */
|
||||
typedef unsigned char UINT8;
|
||||
typedef unsigned short UINT16;
|
||||
typedef unsigned int UINT32;
|
||||
typedef signed char INT8;
|
||||
typedef signed short INT16;
|
||||
typedef signed int INT32;
|
||||
typedef float FLOAT;
|
||||
typedef double DOUBLE;
|
||||
typedef char CHAR;
|
||||
|
||||
typedef unsigned long long UINT64;
|
||||
typedef signed long long INT64;
|
||||
typedef unsigned int UINTPTR;
|
||||
typedef signed int INTPTR;
|
||||
|
||||
typedef volatile INT32 Atomic;
|
||||
typedef volatile INT64 Atomic64;
|
||||
|
||||
#ifndef DEFINED_BOOL
|
||||
typedef unsigned int BOOL;
|
||||
#define DEFINED_BOOL
|
||||
#endif
|
||||
|
||||
#ifndef VOID
|
||||
#define VOID void
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE ((BOOL)0)
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE ((BOOL)1)
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#ifdef __cplusplus
|
||||
#define NULL 0L
|
||||
#else
|
||||
#define NULL ((void*)0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define OS_NULL_BYTE ((UINT8)0xFF)
|
||||
#define OS_NULL_SHORT ((UINT16)0xFFFF)
|
||||
#define OS_NULL_INT ((UINT32)0xFFFFFFFF)
|
||||
|
||||
#ifndef LOS_OK
|
||||
#define LOS_OK 0U
|
||||
#endif
|
||||
|
||||
#ifndef LOS_NOK
|
||||
#define LOS_NOK (UINT32)(-1)
|
||||
#endif
|
||||
|
||||
#define OS_FAIL 1
|
||||
#define OS_ERROR (UINT32)(-1)
|
||||
#define OS_INVALID (UINT32)(-1)
|
||||
#define OS_64BIT_MAX (0xFFFFFFFFFFFFFFFFULL)
|
||||
|
||||
#define asm __asm
|
||||
#ifdef typeof
|
||||
#undef typeof
|
||||
#endif
|
||||
#define typeof __typeof__
|
||||
|
||||
#define SIZE(a) (a)
|
||||
|
||||
#define LOS_ASSERT_COND(expression)
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Align the beginning of the object with the base address addr,
|
||||
* with boundary bytes being the smallest unit of alignment.
|
||||
*/
|
||||
#ifndef ALIGN
|
||||
#define ALIGN(addr, boundary) LOS_Align(addr, boundary)
|
||||
#endif
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Align the tail of the object with the base address addr, with size bytes being the smallest unit of alignment.
|
||||
*/
|
||||
#define TRUNCATE(addr, size) ((addr) & ~((size) - 1))
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* @brief Align the value (addr) by some bytes (boundary) you specify.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to align the value (addr) by some bytes (boundary) you specify.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>the value of boundary usually is 4,8,16,32.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param addr [IN] The variable what you want to align.
|
||||
* @param boundary [IN] The align size what you want to align.
|
||||
*
|
||||
* @retval #UINT32 The variable what have been aligned.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_base.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
static inline UINT32 LOS_Align(UINT32 addr, UINT32 boundary)
|
||||
{
|
||||
return (addr + (((addr + (boundary - 1)) > addr) ? (boundary - 1) : 0)) & ~(boundary - 1);
|
||||
}
|
||||
|
||||
#define OS_GOTO_ERREND() \
|
||||
do { \
|
||||
goto LOS_ERREND; \
|
||||
} while (0)
|
||||
|
||||
#ifndef UNUSED
|
||||
#define UNUSED(X) (void)X
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#ifndef __XTENSA_LX6__
|
||||
static inline void maybe_release_fence(int model)
|
||||
{
|
||||
switch (model) {
|
||||
case __ATOMIC_RELEASE:
|
||||
__atomic_thread_fence (__ATOMIC_RELEASE);
|
||||
break;
|
||||
case __ATOMIC_ACQ_REL:
|
||||
__atomic_thread_fence (__ATOMIC_ACQ_REL);
|
||||
break;
|
||||
case __ATOMIC_SEQ_CST:
|
||||
__atomic_thread_fence (__ATOMIC_SEQ_CST);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void maybe_acquire_fence(int model)
|
||||
{
|
||||
switch (model) {
|
||||
case __ATOMIC_ACQUIRE:
|
||||
__atomic_thread_fence (__ATOMIC_ACQUIRE);
|
||||
break;
|
||||
case __ATOMIC_ACQ_REL:
|
||||
__atomic_thread_fence (__ATOMIC_ACQ_REL);
|
||||
break;
|
||||
case __ATOMIC_SEQ_CST:
|
||||
__atomic_thread_fence (__ATOMIC_SEQ_CST);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#define __LIBATOMIC_N_LOCKS (1 << 4) /* 4, 1<<4 locks num */
|
||||
static inline BOOL *__libatomic_flag_for_address(void *addr)
|
||||
{
|
||||
static BOOL flag_table[__LIBATOMIC_N_LOCKS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
UINTPTR p = (UINTPTR)(UINTPTR *)addr;
|
||||
p += (p >> 2) + (p << 4); /* 2, 4, hash data */
|
||||
p += (p >> 7) + (p << 5); /* 7, 5, hash data */
|
||||
p += (p >> 17) + (p << 13); /* 17, 13, hash data */
|
||||
|
||||
if (sizeof(void *) > 4) { /* 4, sizeof int in 32bit system */
|
||||
p += (p >> 31); /* 31, for hash high bits data */
|
||||
}
|
||||
|
||||
p &= (__LIBATOMIC_N_LOCKS - 1);
|
||||
return flag_table + p;
|
||||
}
|
||||
|
||||
static inline void get_lock(void *addr, int model)
|
||||
{
|
||||
BOOL *lock_ptr = __libatomic_flag_for_address (addr);
|
||||
|
||||
maybe_release_fence (model);
|
||||
while (__atomic_test_and_set (lock_ptr, __ATOMIC_ACQUIRE) == 1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void free_lock(void *addr, int model)
|
||||
{
|
||||
BOOL *lock_ptr = __libatomic_flag_for_address (addr);
|
||||
|
||||
__atomic_clear (lock_ptr, __ATOMIC_RELEASE);
|
||||
maybe_acquire_fence (model);
|
||||
}
|
||||
|
||||
static inline UINT64 __atomic_load_8(const volatile void *mem, int model)
|
||||
{
|
||||
UINT64 ret;
|
||||
|
||||
void *memP = (void *)mem;
|
||||
get_lock (memP, model);
|
||||
ret = *(UINT64 *)mem;
|
||||
free_lock (memP, model);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void __atomic_store_8(volatile void *mem, UINT64 val, int model)
|
||||
{
|
||||
void *memP = (void *)mem;
|
||||
get_lock (memP, model);
|
||||
*(UINT64 *)mem = val;
|
||||
free_lock (memP, model);
|
||||
}
|
||||
|
||||
static inline UINT64 __atomic_exchange_8(volatile void *mem, UINT64 val, int model)
|
||||
{
|
||||
UINT64 ret;
|
||||
|
||||
void *memP = (void *)mem;
|
||||
get_lock (memP, model);
|
||||
ret = *(UINT64 *)mem;
|
||||
*(UINT64 *)mem = val;
|
||||
free_lock (memP, model);
|
||||
return ret;
|
||||
}
|
||||
#endif /* __XTENSA_LX6__ */
|
||||
|
||||
#define ALIAS_OF(of) __attribute__((alias(#of)))
|
||||
#define FUNC_ALIAS(real_func, new_alias, args_list, return_type) \
|
||||
return_type new_alias args_list ALIAS_OF(real_func)
|
||||
|
||||
#else
|
||||
|
||||
#define FUNC_ALIAS(real_func, new_alias, args_list, return_type)
|
||||
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_COMPILER_H */
|
||||
106
ohos/kernel/liteos_m/utils/los_debug.c
Normal file
106
ohos/kernel/liteos_m/utils/los_debug.c
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_debug.h"
|
||||
#include "stdarg.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_task.h"
|
||||
|
||||
#if (LOSCFG_KERNEL_PRINTF == 1)
|
||||
STATIC const CHAR *g_logString[] = {
|
||||
"EMG",
|
||||
"COMMON",
|
||||
"ERR",
|
||||
"WARN",
|
||||
"INFO",
|
||||
"DEBUG",
|
||||
};
|
||||
#endif
|
||||
|
||||
STATIC ExcHookFn g_excHook;
|
||||
STATIC BACK_TRACE_HOOK g_backTraceHook = NULL;
|
||||
|
||||
VOID OsBackTraceHookSet(BACK_TRACE_HOOK hook)
|
||||
{
|
||||
if (g_backTraceHook == NULL) {
|
||||
g_backTraceHook = hook;
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsBackTraceHookCall(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
|
||||
{
|
||||
if (g_backTraceHook != NULL) {
|
||||
g_backTraceHook(LR, LRSize, jumpCount, SP);
|
||||
} else {
|
||||
PRINT_ERR("Record LR failed, because of g_backTraceHook is not registered, "
|
||||
"should call OSBackTraceInit firstly\n");
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsExcHookRegister(ExcHookFn excHookFn)
|
||||
{
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
if (!g_excHook) {
|
||||
g_excHook = excHookFn;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
VOID OsDoExcHook(EXC_TYPE excType)
|
||||
{
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
if (g_excHook) {
|
||||
g_excHook(excType);
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_PRINTF == 1)
|
||||
INT32 OsLogLevelCheck(INT32 level)
|
||||
{
|
||||
if (level > PRINT_LEVEL) {
|
||||
return (INT32)LOS_NOK;
|
||||
}
|
||||
|
||||
if ((level != LOG_COMMON_LEVEL) && ((level > LOG_EMG_LEVEL) && (level <= LOG_DEBUG_LEVEL))) {
|
||||
PRINTK("[%s][%s]", g_logString[level], LOS_CurTaskNameGet());
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_PRINTF > 1)
|
||||
WEAK VOID HalConsoleOutput(LogModuleType type, INT32 level, const CHAR *fmt, ...)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
178
ohos/kernel/liteos_m/utils/los_debug.h
Normal file
178
ohos/kernel/liteos_m/utils/los_debug.h
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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.
|
||||
*/
|
||||
|
||||
/**@defgroup los_debug
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_DEBUG_H
|
||||
#define _LOS_DEBUG_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
enum MemMangType {
|
||||
MEM_MANG_MEMBOX,
|
||||
MEM_MANG_MEMORY,
|
||||
MEM_MANG_EMPTY
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
UINT32 type;
|
||||
UINT32 startAddr;
|
||||
UINT32 size;
|
||||
VOID *blkAddrArray;
|
||||
} MemInfo;
|
||||
|
||||
typedef struct {
|
||||
enum MemMangType type;
|
||||
UINT32 startAddr;
|
||||
UINT32 size;
|
||||
UINT32 free;
|
||||
UINT32 blockSize;
|
||||
UINT32 errorAddr;
|
||||
UINT32 errorLen;
|
||||
UINT32 errorOwner;
|
||||
} MemInfoCB;
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
EXC_REBOOT,
|
||||
EXC_ASSERT,
|
||||
EXC_PANIC,
|
||||
EXC_STACKOVERFLOW,
|
||||
EXC_INTERRUPT,
|
||||
EXC_TYPE_END
|
||||
} EXC_TYPE;
|
||||
|
||||
typedef VOID (*ExcHookFn)(EXC_TYPE excType);
|
||||
|
||||
VOID OsExcHookRegister(ExcHookFn excHookFn);
|
||||
|
||||
VOID OsDoExcHook(EXC_TYPE excType);
|
||||
|
||||
#define LOG_EMG_LEVEL 0
|
||||
|
||||
#define LOG_COMMON_LEVEL (LOG_EMG_LEVEL + 1)
|
||||
|
||||
#define LOG_ERR_LEVEL (LOG_COMMON_LEVEL + 1)
|
||||
|
||||
#define LOG_WARN_LEVEL (LOG_ERR_LEVEL + 1)
|
||||
|
||||
#define LOG_INFO_LEVEL (LOG_WARN_LEVEL + 1)
|
||||
|
||||
#define LOG_DEBUG_LEVEL (LOG_INFO_LEVEL + 1)
|
||||
|
||||
#ifndef PRINT_LEVEL
|
||||
#define PRINT_LEVEL LOG_ERR_LEVEL
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
LOG_MODULE_KERNEL,
|
||||
LOG_MODULE_FS,
|
||||
LOS_MODULE_OTHERS
|
||||
} LogModuleType;
|
||||
|
||||
/**
|
||||
* @ingroup los_printf
|
||||
* @brief Format and print data.
|
||||
*
|
||||
* @par Description:
|
||||
* Print argument(s) according to fmt.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param type [IN] Type LogModuleType indicates the log type.
|
||||
* @param level [IN] Type LogLevel indicates the log level.
|
||||
* @param fmt [IN] Type char* controls the output as in C printf.
|
||||
*
|
||||
* @retval None
|
||||
* @par Dependency:
|
||||
* <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_Printf
|
||||
*/
|
||||
#if (LOSCFG_KERNEL_PRINTF == 1)
|
||||
extern INT32 printf(const CHAR *fmt, ...);
|
||||
extern INT32 OsLogLevelCheck(INT32 level);
|
||||
#define LOS_Printf(type, level, fmt, args...) do { \
|
||||
if (!OsLogLevelCheck(level)) { \
|
||||
printf(fmt, ##args); \
|
||||
} \
|
||||
} while (0)
|
||||
#elif (LOSCFG_KERNEL_PRINTF == 0)
|
||||
#define LOS_Printf(type, level, fmt, args...)
|
||||
#else
|
||||
extern VOID HalConsoleOutput(LogModuleType type, INT32 level, const CHAR *fmt, ...);
|
||||
#define LOS_Printf HalConsoleOutput
|
||||
#endif
|
||||
|
||||
#define PRINT_DEBUG(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_DEBUG_LEVEL, fmt, ##args)
|
||||
#define PRINT_INFO(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_INFO_LEVEL, fmt, ##args)
|
||||
#define PRINT_WARN(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_WARN_LEVEL, fmt, ##args)
|
||||
#define PRINT_ERR(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_ERR_LEVEL, fmt, ##args)
|
||||
#define PRINTK(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_COMMON_LEVEL, fmt, ##args)
|
||||
#define PRINT_EMG(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_EMG_LEVEL, fmt, ##args)
|
||||
|
||||
#if PRINT_LEVEL < LOG_ERR_LEVEL
|
||||
#define LOS_ASSERT(judge)
|
||||
#else
|
||||
#define LOS_ASSERT(judge) \
|
||||
do { \
|
||||
if ((judge) == 0) { \
|
||||
OsDoExcHook(EXC_ASSERT); \
|
||||
(VOID)LOS_IntLock(); \
|
||||
PRINT_ERR("ASSERT ERROR! %s, %d, %s\n", __FILE__, __LINE__, __func__); \
|
||||
while (1) { } \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
typedef VOID (*BACK_TRACE_HOOK)(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP);
|
||||
extern VOID OsBackTraceHookSet(BACK_TRACE_HOOK hook);
|
||||
extern VOID OsBackTraceHookCall(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_PRINTF_H */
|
||||
61
ohos/kernel/liteos_m/utils/los_error.c
Normal file
61
ohos/kernel/liteos_m/utils/los_error.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_error.h"
|
||||
|
||||
|
||||
LITE_OS_SEC_BSS UserErrFunc g_userErrFunc;
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_ErrHandle
|
||||
Description : Error handle
|
||||
Input : fileName -- file name
|
||||
lineNo -- error line number
|
||||
errorNo -- user defined error number
|
||||
paraLen -- length of pPara
|
||||
para -- user description of error
|
||||
Output : None
|
||||
Return : LOS_OK always
|
||||
Other : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_ErrHandle(CHAR *fileName,
|
||||
UINT32 lineNo,
|
||||
UINT32 errorNo,
|
||||
UINT32 paraLen,
|
||||
VOID *para)
|
||||
{
|
||||
if (g_userErrFunc.pfnHook != NULL) {
|
||||
g_userErrFunc.pfnHook(fileName, lineNo, errorNo, paraLen, para);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
294
ohos/kernel/liteos_m/utils/los_error.h
Normal file
294
ohos/kernel/liteos_m/utils/los_error.h
Normal file
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_errno Error code
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_ERRNO_H
|
||||
#define _LOS_ERRNO_H
|
||||
#include "los_compiler.h"
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* OS error code flag.
|
||||
*/
|
||||
#define LOS_ERRNO_OS_ID ((UINT32)0x00 << 16)
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define the error level as informative.
|
||||
*/
|
||||
#define LOS_ERRTYPE_NORMAL ((UINT32)0x00 << 24)
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define the error level as warning.
|
||||
*/
|
||||
#define LOS_ERRTYPE_WARN ((UINT32)0x01 << 24)
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define the error level as critical.
|
||||
*/
|
||||
#define LOS_ERRTYPE_ERROR ((UINT32)0x02 << 24)
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define the error level as fatal.
|
||||
*/
|
||||
#define LOS_ERRTYPE_FATAL ((UINT32)0x03 << 24)
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define fatal OS errors.
|
||||
*/
|
||||
#define LOS_ERRNO_OS_FATAL(moduleID, errno) \
|
||||
(LOS_ERRTYPE_FATAL | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define critical OS errors.
|
||||
*/
|
||||
#define LOS_ERRNO_OS_ERROR(moduleID, errno) \
|
||||
(LOS_ERRTYPE_ERROR | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define warning OS errors.
|
||||
*/
|
||||
#define LOS_ERRNO_OS_WARN(moduleID, errno) \
|
||||
(LOS_ERRTYPE_WARN | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define informative OS errors.
|
||||
*/
|
||||
#define LOS_ERRNO_OS_NORMAL(moduleID, errno) \
|
||||
(LOS_ERRTYPE_NORMAL | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* @brief Define the pointer to the error handling function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to define the pointer to the error handling function.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param fileName [IN] Log file that stores error information.
|
||||
* @param lineNo [IN] Line number of the erroneous line.
|
||||
* @param errorNo [IN] Error code.
|
||||
* @param paraLen [IN] Length of the input parameter pPara.
|
||||
* @param para [IN] User label of the error.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_err.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
typedef VOID (*LOS_ERRORHANDLE_FUNC)(CHAR *fileName,
|
||||
UINT32 lineNo, /**< Line number of the erroneous line. */
|
||||
UINT32 errorNo, /**< Error code. */
|
||||
UINT32 paraLen, /**< Length of the input parameter pPara. */
|
||||
VOID *para);
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* @brief Error handling function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to perform different operations according to error types.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param fileName [IN] Log file that stores error information.
|
||||
* @param lineNo [IN] Line number of the erroneous line which should not be OS_ERR_MAGIC_WORD.
|
||||
* @param errorNo [IN] Error code.
|
||||
* @param paraLen [IN] Length of the input parameter pPara.
|
||||
* @param para [IN] User label of the error.
|
||||
*
|
||||
* @retval LOS_OK The error is successfully processed.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_err.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None
|
||||
*/
|
||||
extern UINT32 LOS_ErrHandle(CHAR *fileName, UINT32 lineNo,
|
||||
UINT32 errorNo, UINT32 paraLen,
|
||||
VOID *para);
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* Error handling function structure.
|
||||
*/
|
||||
typedef struct tagUserErrFunc {
|
||||
LOS_ERRORHANDLE_FUNC pfnHook; /**< Hook function for error handling. */
|
||||
} UserErrFunc;
|
||||
|
||||
|
||||
enum LOS_MODULE_ID {
|
||||
LOS_MOD_SYS = 0x0,
|
||||
LOS_MOD_MEM = 0x1,
|
||||
LOS_MOD_TSK = 0x2,
|
||||
LOS_MOD_SWTMR = 0x3,
|
||||
LOS_MOD_TICK = 0x4,
|
||||
LOS_MOD_MSG = 0x5,
|
||||
LOS_MOD_QUE = 0x6,
|
||||
LOS_MOD_SEM = 0x7,
|
||||
LOS_MOD_MBOX = 0x8,
|
||||
LOS_MOD_HWI = 0x9,
|
||||
LOS_MOD_HWWDG = 0xa,
|
||||
LOS_MOD_CACHE = 0xb,
|
||||
LOS_MOD_HWTMR = 0xc,
|
||||
LOS_MOD_MMU = 0xd,
|
||||
|
||||
LOS_MOD_LOG = 0xe,
|
||||
LOS_MOD_ERR = 0xf,
|
||||
|
||||
LOS_MOD_EXC = 0x10,
|
||||
LOS_MOD_CSTK = 0x11,
|
||||
|
||||
LOS_MOD_MPU = 0x12,
|
||||
LOS_MOD_NMHWI = 0x13,
|
||||
LOS_MOD_TRACE = 0x14,
|
||||
LOS_MOD_IPC = 0x18,
|
||||
LOS_MOD_TIMER = 0x1a,
|
||||
LOS_MOD_EVENT = 0x1c,
|
||||
LOS_MOD_MUX = 0X1d,
|
||||
LOS_MOD_CPUP = 0x1e,
|
||||
LOS_MOD_HOOK = 0x1f,
|
||||
LOS_MOD_PM = 0x20,
|
||||
LOS_MOD_LMK = 0x21,
|
||||
LOS_MOD_SHELL = 0x31,
|
||||
LOS_MOD_SIGNAL = 0x32,
|
||||
LOS_MOD_BUTT
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* Define the error magic word.
|
||||
*/
|
||||
#define OS_ERR_MAGIC_WORD 0xa1b2c3f8
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* @brief Error handling macro capable of returning error codes.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to call the error handling function by using an error code and return the same error code.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param errNo [IN] Error code.
|
||||
*
|
||||
* @retval errNo
|
||||
* @par Dependency:
|
||||
* <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
#define OS_RETURN_ERROR(errNo) \
|
||||
do { \
|
||||
(VOID)LOS_ErrHandle("os_unspecific_file", OS_ERR_MAGIC_WORD, errNo, 0, NULL); \
|
||||
return (errNo); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* @brief Error handling macro capable of returning error codes.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to call the error handling function by using an error code and the line number of the erroneous line,
|
||||
and return the same error code.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param errLine [IN] Line number of the erroneous line.
|
||||
* @param errNo [IN] Error code.
|
||||
*
|
||||
* @retval errNo
|
||||
* @par Dependency:
|
||||
* <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
#define OS_RETURN_ERROR_P2(errLine, errNo) \
|
||||
do { \
|
||||
(VOID)LOS_ErrHandle("os_unspecific_file", errLine, errNo, 0, NULL); \
|
||||
return (errNo); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* @brief Macro for jumping to error handler.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to call the error handling function by using an error code.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param errorNo [IN] Error code.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
#define OS_GOTO_ERR_HANDLER(errorNo) \
|
||||
do { \
|
||||
errNo = (errorNo); \
|
||||
errLine = OS_ERR_MAGIC_WORD; \
|
||||
goto ERR_HANDLER; \
|
||||
} while (0)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ERRNO_H */
|
||||
67
ohos/kernel/liteos_m/utils/los_hook.c
Normal file
67
ohos/kernel/liteos_m/utils/los_hook.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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_hook.h"
|
||||
#include "internal/los_hook_types_parse.h"
|
||||
|
||||
|
||||
#if (LOSCFG_DEBUG_HOOK == 1)
|
||||
#define LOS_HOOK_TYPE_DEF(type, paramList) \
|
||||
STATIC type##_FN g_fn##type; \
|
||||
UINT32 type##_RegHook(type##_FN func) { \
|
||||
if ((func) == NULL) { \
|
||||
return LOS_ERRNO_HOOK_REG_INVALID; \
|
||||
} \
|
||||
if (g_fn##type) { \
|
||||
return LOS_ERRNO_HOOK_POOL_IS_FULL; \
|
||||
} \
|
||||
g_fn##type = (func); \
|
||||
return LOS_OK; \
|
||||
} \
|
||||
UINT32 type##_UnRegHook(type##_FN func) { \
|
||||
if (((func) == NULL) || (g_fn##type != (func))) { \
|
||||
return LOS_ERRNO_HOOK_UNREG_INVALID; \
|
||||
} \
|
||||
g_fn##type = NULL; \
|
||||
return LOS_OK; \
|
||||
} \
|
||||
VOID type##_CallHook paramList { \
|
||||
if (g_fn##type) { \
|
||||
g_fn##type(PARAM_TO_ARGS paramList); \
|
||||
} \
|
||||
}
|
||||
|
||||
LOS_HOOK_ALL_TYPES_DEF;
|
||||
|
||||
#undef LOS_HOOK_TYPE_DEF
|
||||
|
||||
#endif /* LOSCFG_DEBUG_HOOK */
|
||||
|
||||
137
ohos/kernel/liteos_m/utils/los_hook.h
Normal file
137
ohos/kernel/liteos_m/utils/los_hook.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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 _LOS_HOOK_H
|
||||
#define _LOS_HOOK_H
|
||||
|
||||
#include "internal/los_hook_types.h"
|
||||
#include "los_config.h"
|
||||
#include "los_error.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_DEBUG_HOOK == 1)
|
||||
/**
|
||||
* @ingroup los_hook
|
||||
* Hook error code: The hook pool is insufficient.
|
||||
*
|
||||
* Value: 0x02001f00
|
||||
*
|
||||
* Solution: Deregister the registered hook.
|
||||
*/
|
||||
#define LOS_ERRNO_HOOK_POOL_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_hook
|
||||
* Hook error code: Invalid parameter.
|
||||
*
|
||||
* Value: 0x02001f01
|
||||
*
|
||||
* Solution: Check the input parameters of LOS_HookReg.
|
||||
*/
|
||||
#define LOS_ERRNO_HOOK_REG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_hook
|
||||
* Hook error code: Invalid parameter.
|
||||
*
|
||||
* Value: 0x02001f02
|
||||
*
|
||||
* Solution: Check the input parameters of LOS_HookUnReg.
|
||||
*/
|
||||
#define LOS_ERRNO_HOOK_UNREG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_hook
|
||||
* @brief Registration of hook function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to register hook function.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li> None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param hookType [IN] Register the type of the hook.
|
||||
* @param hookFn [IN] The function to be registered.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hook.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_HookReg(hookType, hookFn) hookType##_RegHook(hookFn)
|
||||
|
||||
/**
|
||||
* @ingroup los_hook
|
||||
* @brief Deregistration of hook function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to deregister hook function.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li> None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param hookType [IN] Deregister the type of the hook.
|
||||
* @param hookFn [IN] The function to be deregistered.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hook.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_HookUnReg(hookType, hookFn) hookType##_UnRegHook(hookFn)
|
||||
|
||||
/**
|
||||
* Call hook functions.
|
||||
*/
|
||||
#define OsHookCall(hookType, ...) hookType##_CallHook(__VA_ARGS__)
|
||||
|
||||
#else
|
||||
#define LOS_HookReg(hookType, hookFn)
|
||||
#define LOS_HookUnReg(hookType, hookFn)
|
||||
#define OsHookCall(hookType, ...)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_HOOK_H */
|
||||
431
ohos/kernel/liteos_m/utils/los_list.h
Normal file
431
ohos/kernel/liteos_m/utils/los_list.h
Normal file
@@ -0,0 +1,431 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_list Doubly linked list
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_LIST_H
|
||||
#define _LOS_LIST_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* Structure of a node in a doubly linked list.
|
||||
*/
|
||||
typedef struct LOS_DL_LIST {
|
||||
struct LOS_DL_LIST *pstPrev; /**< Current node's pointer to the previous node */
|
||||
struct LOS_DL_LIST *pstNext; /**< Current node's pointer to the next node */
|
||||
} LOS_DL_LIST;
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Initialize a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Node in a doubly linked list.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
|
||||
{
|
||||
list->pstNext = list;
|
||||
list->pstPrev = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Point to the next node pointed to by the current node.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to point to the next node pointed to by the current node.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param object [IN] Node in the doubly linked list.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_FIRST(object) ((object)->pstNext)
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Insert a new node to a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to insert a new node to a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameters passed in should be ensured to be legal pointers.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked list where the new node is inserted.
|
||||
* @param node [IN] New node to be inserted.
|
||||
*
|
||||
* @retval None
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_ListDelete
|
||||
*/
|
||||
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListAdd(LOS_DL_LIST *list, LOS_DL_LIST *node)
|
||||
{
|
||||
node->pstNext = list->pstNext;
|
||||
node->pstPrev = list;
|
||||
list->pstNext->pstPrev = node;
|
||||
list->pstNext = node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Insert a node to the tail of a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to insert a new node to the tail of a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameters passed in should be ensured to be legal pointers.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked list where the new node is inserted.
|
||||
* @param node [IN] New node to be inserted.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_ListAdd | LOS_ListHeadInsert
|
||||
*/
|
||||
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
|
||||
{
|
||||
LOS_ListAdd(list->pstPrev, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Insert a node to the head of a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to insert a new node to the head of a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameters passed in should be ensured to be legal pointers.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked list where the new node is inserted.
|
||||
* @param node [IN] New node to be inserted.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_ListAdd | LOS_ListTailInsert
|
||||
*/
|
||||
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListHeadInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
|
||||
{
|
||||
LOS_ListAdd(list, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Delete a specified node from a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to delete a specified node from a doubly linked list.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param node [IN] Node to be deleted.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_ListAdd
|
||||
*/
|
||||
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
|
||||
{
|
||||
node->pstNext->pstPrev = node->pstPrev;
|
||||
node->pstPrev->pstNext = node->pstNext;
|
||||
node->pstNext = (LOS_DL_LIST *)NULL;
|
||||
node->pstPrev = (LOS_DL_LIST *)NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Identify whether a specified doubly linked list is empty.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to return whether a doubly linked list is empty.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked node.
|
||||
*
|
||||
* @retval TRUE The doubly linked list is empty.
|
||||
* @retval FALSE The doubly linked list is not empty.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
LITE_OS_SEC_ALW_INLINE STATIC_INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *node)
|
||||
{
|
||||
return (BOOL)(node->pstNext == node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Obtain the pointer to a doubly linked list in a structure.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the pointer to a doubly linked list in a structure.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param type [IN] Structure name.
|
||||
* @param member [IN] Member name of the doubly linked list in the structure.
|
||||
*
|
||||
* @retval Pointer to the doubly linked list in the structure.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_OFF_SET_OF(type, member) ((UINT32)&(((type *)0)->member))
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Obtain the pointer to a structure that contains a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the pointer to a structure that contains a doubly linked list.
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Current node's pointer to the next node.
|
||||
* @param type [IN] Structure name.
|
||||
* @param member [IN] Member name of the doubly linked list in the structure.
|
||||
*
|
||||
* @retval Pointer to the structure that contains the doubly linked list.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_ENTRY(item, type, member) \
|
||||
((type *)(VOID *)((CHAR *)(item) - LOS_OFF_SET_OF(type, member))) \
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Iterate over a doubly linked list of given type.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to iterate over a doubly linked list of given type.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
* @param type [IN] Structure name.
|
||||
* @param member [IN] Member name of the doubly linked list in the structure.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_FOR_EACH_ENTRY(item, list, type, member) \
|
||||
for ((item) = LOS_DL_LIST_ENTRY((list)->pstNext, type, member); \
|
||||
&(item)->member != (list); \
|
||||
(item) = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member))
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief iterate over a doubly linked list safe against removal of list entry.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to iterate over a doubly linked list safe against removal of list entry.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
|
||||
* @param next [IN] Save the next node.
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
* @param type [IN] Structure name.
|
||||
* @param member [IN] Member name of the doubly linked list in the structure.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, next, list, type, member) \
|
||||
for ((item) = LOS_DL_LIST_ENTRY((list)->pstNext, type, member), \
|
||||
(next) = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member); \
|
||||
&((item)->member) != (list); \
|
||||
(item) = (next), (next) = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member))
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Delete initialize a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete initialize a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameter passed in should be ensured to be s legal pointer.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked list.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListDelInit(LOS_DL_LIST *list)
|
||||
{
|
||||
list->pstNext->pstPrev = list->pstPrev;
|
||||
list->pstPrev->pstNext = list->pstNext;
|
||||
LOS_ListInit(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief iterate over a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to iterate over a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_FOR_EACH(item, list) \
|
||||
for ((item) = (list)->pstNext; (item) != (list); (item) = (item)->pstNext)
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Iterate over a doubly linked list safe against removal of list entry.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to iterate over a doubly linked list safe against removal of list entry.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
|
||||
* @param next [IN] Save the next node.
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_FOR_EACH_SAFE(item, next, list) \
|
||||
for ((item) = (list)->pstNext, (next) = (item)->pstNext; (item) != (list); \
|
||||
(item) = (next), (next) = (item)->pstNext)
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Initialize a double linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize a double linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_HEAD(list) \
|
||||
LOS_DL_LIST list = { &(list), &(list) }
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_LIST_H */
|
||||
117
ohos/kernel/liteos_m/utils/los_reg.h
Normal file
117
ohos/kernel/liteos_m/utils/los_reg.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup kernel Kernel
|
||||
* @defgroup los_reg Basic definitions
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_REG_H
|
||||
#define _LOS_REG_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Read a UINT8 value from addr and store in value.
|
||||
*/
|
||||
#define READ_UINT8(value, addr) ((value) = *((volatile UINT8 *)(addr)))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Read a UINT16 value from addr and store in addr.
|
||||
*/
|
||||
#define READ_UINT16(value, addr) ((value) = *((volatile UINT16 *)(addr)))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Read a UINT32 value from addr and store in value.
|
||||
*/
|
||||
#define READ_UINT32(value, addr) ((value) = *((volatile UINT32 *)(addr)))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Read a UINT64 value from addr and store in value.
|
||||
*/
|
||||
#define READ_UINT64(value, addr) ((value) = *((volatile UINT64 *)(addr)))
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Get a UINT8 value from addr.
|
||||
*/
|
||||
#define GET_UINT8(addr) (*((volatile UINT8 *)(addr)))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Get a UINT16 value from addr.
|
||||
*/
|
||||
#define GET_UINT16(addr) (*((volatile UINT16 *)(addr)))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Get a UINT32 value from addr.
|
||||
*/
|
||||
#define GET_UINT32(addr) (*((volatile UINT32 *)(addr)))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Get a UINT64 value from addr.
|
||||
*/
|
||||
#define GET_UINT64(addr) (*((volatile UINT64 *)(addr)))
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Write a UINT8 value to addr.
|
||||
*/
|
||||
#define WRITE_UINT8(value, addr) (*((volatile UINT8 *)(addr)) = (value))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Write a UINT16 value to addr.
|
||||
*/
|
||||
#define WRITE_UINT16(value, addr) (*((volatile UINT16 *)(addr)) = (value))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Write a UINT32 value to addr.
|
||||
*/
|
||||
#define WRITE_UINT32(value, addr) (*((volatile UINT32 *)(addr)) = (value))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Write a UINT64 addr to addr.
|
||||
*/
|
||||
#define WRITE_UINT64(value, addr) (*((volatile UINT64 *)(addr)) = (value))
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_REG_H */
|
||||
Reference in New Issue
Block a user