Compare commits

..

4 Commits

@ -0,0 +1 @@
Subproject commit 89507f4501ab34c8ef90692b559131df24cb7661

@ -0,0 +1,294 @@
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved.
* Description: Dynload ElfLib HeadFile
* Author: Huawei LiteOS Team
* Create: 2013-01-01
* 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_dynload Dynamic loading
* @ingroup kernel
*/
#ifndef _LOS_LD_ELFLIB_H
#define _LOS_LD_ELFLIB_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_KERNEL_DYNLOAD_DYN
#ifdef LOSCFG_DYNLOAD_DYN_FROM_FS
/**
* @ingroup los_dynload
* Define an enum type indicates load strategy.
*
* Type of load strategy of dynamic load, ZIP means using zipped shared object, NOZIP means using normal shared object.
*/
enum LOAD_STRATEGY {
ZIP,
NOZIP
};
/*这是一个枚举类型的定义名称为LOAD_STRATEGY。它包含两个成员ZIP和NOZIP。*/
/**
* @ingroup los_dynload
* Define the structure of the parameters used for dynamic.
*
* Information of specified parameters passed in during dynamic load.
*/
typedef struct tagDynloadParam {
enum LOAD_STRATEGY enLoadStrategy;
} DYNLOAD_PARAM_S;
/*这个结构体可以用来存储动态加载的参数信息,
enLoadStrategyZIPNOZIP使
*/
/**
* @ingroup los_dynload
* @brief Register the dynamic parameters.
*
* @par Description:
* This API is used to register the dynamic load parameters.
* @attention
* <ul>
* <li></li>
* </ul>
*
* @param dynloadParam [IN] dynamic load parameters to be registered.
*
* @par Dependency:
* <ul><li>los_ld_elflib.h: the header file that contains the API declaration.</li></ul>
* @see LOS_FindSymByName | LOS_LdDestroy
* @since Huawei LiteOS V100R001C00
*/
extern VOID LOS_DynParamReg(DYNLOAD_PARAM_S *dynloadParam);
/*通过调用LOS_DynParamReg函数并传递一个指向DYNLOAD_PARAM_S类型对象的指针
*/
/**
* @ingroup los_dynload
* @brief Load a shared object file.
*
* @par Description:
* This API is used to load a shared object file under a particular module file path.
* @attention
* <ul>
* <li>The parameter passed to this API should be a legal path of a shared object file.</li>
* </ul>
*
* @param elfFileName [IN] Shared object file path.
*
* @retval NULL The shared object file fails to be loaded.
* @retval VOID* The shared object file is successfully loaded.
* @par Dependency:
* <ul><li>los_ld_elflib.h: the header file that contains the API declaration.</li></ul>
* @see LOS_ModuleUnload
* @since Huawei LiteOS V100R001C00
*/
extern VOID *LOS_SoLoad(CHAR *elfFileName);
#endif /* LOSCFG_DYNLOAD_DYN_FROM_FS */
#ifdef LOSCFG_DYNLOAD_DYN_FROM_MEM
/**
* @ingroup los_dynload
* @brief Load a shared object file from the memory.
*
* @par Description:
* This API is used to load a shared object file that is in memory.
* @attention
* <ul>
* <li>The shared object file does not depend on other shared objects.</li>
* </ul>
*
* @param elfFileName [IN] Shared object file name.
* @param fileNameLen [IN] The length of shared object file name.
* @param elfFileBuf [IN] Shared object file buffer in memory.
* @param bufLen [IN] the length of shared object file buffer in memory.
*
* @retval NULL The shared object file fails to be loaded.
* @retval VOID* The shared object file is successfully loaded.
* @par Dependency:
* <ul><li>los_ld_elflib.h: the header file that contains the API declaration.</li></ul>
* @see LOS_ModuleUnload
* @since Huawei LiteOS V200R003C00
*/
extern VOID *LOS_MemLoad(const CHAR *elfFileName, UINT32 fileNameLen,
const CHAR *elfFileBuf, UINT32 bufLen);
#endif /* LOSCFG_DYNLOAD_DYN_FROM_MEM */
#endif /* LOSCFG_KERNEL_DYNLOAD_DYN */
/*这段代码中使用了条件编译指令#ifdef和#endif用于在不同的编译环境下选择是否启用动态加载功能。*/
#ifdef LOSCFG_KERNEL_DYNLOAD_REL
/**
* @ingroup los_dynload
* @brief Load a object file.
*
* @par Description:
* This API is used to load a object file under a particular module file path.
* @attention
* <ul>
* <li>The parameter passed to this API should be a legal path of an object file.</li>
* </ul>
*
* @param elfFileName [IN] Object file path.
*
* @retval NULL The object file fails to be loaded.
* @retval VOID* The object file is successfully loaded.
* @par Dependency:
* <ul><li>los_ld_elflib.h: the header file that contains the API declaration.</li></ul>
* @see LOS_ModuleUnload
* @since Huawei LiteOS V100R001C00
*/
extern VOID *LOS_ObjLoad(CHAR *elfFileName);
#endif /* LOSCFG_KERNEL_DYNLOAD_REL */
/*如果宏定义LOSCFG_KERNEL_DYNLOAD_REL被定义
LOS_ObjLoad
CHARVOID*/
/**
* @ingroup los_dynload
* @brief Unload a module.
*
* @par Description:
* This API is used to unload a module with a particular module handle.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param handle [IN] Module handle.
*
* @retval #LOS_NOK The module fails to be unloaded.
* @retval #LOS_OK The module is successfully unloaded.
* @par Dependency:
* <ul><li>los_ld_elflib.h: the header file that contains the API declaration.</li></ul>
* @see LOS_ObjLoad
* @since Huawei LiteOS V100R001C00
*/
extern INT32 LOS_ModuleUnload(VOID *handle);
/*通过调用LOS_ModuleUnload函数并传递一个动态库的句柄
*/
/**
* @ingroup los_dynload
* @brief Destroy a dynamic loader.
*
* @par Description:
* This API is used to destroy a dynamic linker.
* @attention
* <ul>
* <li>When dynamic loading is no longer needed, call this API to destroy the dynamic linker.</li>
* </ul>
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_ld_elflib.h: the header file that contains the API declaration.</li></ul>
* @see LOS_FindSymByName
* @since Huawei LiteOS V100R001C00
*/
extern VOID LOS_LdDestroy(VOID);
/*这段代码声明了一个外部函数LOS_LdDestroy该函数没有参数和返回值。
LOS_LdDestroyLoader*/
/**
* @ingroup los_dynload
* @brief Search for a symbol address.
*
* @par Description:
* This API is used to search for the address of a symbol according to a particular module handle and symbol name.
* @attention
* <ul>
* <li>If the value of handle is NULL, Huawei LiteOS searches for symbols (including system symbols) in the global
* symbol table. If handle is set to a valid module handle, Huawei LiteOS searches for symbols in the module that
* comes with the module handle.</li>
* </ul>
*
* @param handle [IN] Module handle.
* @param name [IN] Name of the symbol to be searched for.
*
* @retval NULL The symbol address is not found.
* @retval VOID* Symbol address.
* @par Dependency:
* <ul><li>los_ld_elflib.h: the header file that contains the API declaration.</li></ul>
* @see LOS_LdDestroy
* @since Huawei LiteOS V100R001C00
*/
extern VOID *LOS_FindSymByName(VOID *handle, CHAR *name);
/**
* @ingroup los_dynload
* @brief Add a default path.
*
* @par Description:
* This API is used to add a path to default paths.
* @attention
* <ul>
* <li></li>
* </ul>
*
* @param path [IN] Path to be added to default paths.
*
* @retval #LOS_NOK The path is added unsuccessfully.
* @retval #LOS_OK The path is added successfully.
* @par Dependency:
* <ul><li>los_ld_elflib.h: the header file that contains the API declaration.</li></ul>
* @see LOS_FindSymByName | LOS_LdDestroy
* @since Huawei LiteOS V100R001C00
*/
extern INT32 LOS_PathAdd(CHAR *path);
/*通过调用LOS_PathAdd函数并传递一个路径可以将该路径添加到动态库搜索路径中。
*/
/**
* @ingroup los_dynload
* @brief Set the memory pool address used by dynload
*
* @par Description:
* This API is used to set the memory pool address used by dynload.
* @attention
* <ul>
* <li>The parameter passed to this API should be a legal memory pool address by managed with LiteOS's memory
* algorithm, and whose value is outside of the LiteOS system memory</li>
* </ul>
*
* @param memPool [IN] the memory pool address.
*
* @retval TRUE Set successful.
* @retval FLASE Set failed.
* @par Dependency:
* <ul><li>los_ld_elflib.h: the header file that contains the API declaration.</li></ul>
* @see LOS_ModuleUnload
* @since Huawei LiteOS V200R002C00
*/
extern BOOL LOS_DynMemPoolSet(VOID *memPool);
/*通过调用LOS_DynMemPoolSet函数并传递一个内存池指针
*/
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_LD_ELFLIB_H */

@ -0,0 +1,545 @@
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved.
* Description: Doubly linked list
* Author: Huawei LiteOS Team
* Create: 2013-01-01
* 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_typedef.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;
/*这种结构体通常用于实现双向链表数据结构。
LOS_DL_LIST
*/
/**
* @ingroup los_list
* @brief Initialize the input node to a doubly linked list.
*
* @par Description:
* This API is used to initialize the input node (the first parameter list) to
* a doubly linked list.
* @attention
* The parameter passed in should be a legal pointer.
*
* @param list [IN] A 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 LOS_DL_LIST_HEAD
* @since Huawei LiteOS V100R001C00
*/
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
{
list->pstNext = list;
list->pstPrev = list;
}
/*这段代码定义了一个静态内联函数LOS_ListInit
LOS_DL_LISTlist
pstNextpstPrev
*/
/**
* @ingroup los_list
* @brief Point to the next node of the current node.
*
* @par Description:
* This API is used to point to the next node of the current node.
* @attention
* None.
*
* @param object [IN] Type #LOS_DL_LIST * The 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 LOS_DL_LIST_LAST
* @since Huawei LiteOS V100R001C00
*/
#define LOS_DL_LIST_FIRST(object) ((object)->pstNext)
/*这段代码定义了一个宏LOS_DL_LIST_FIRST(object)
LOS_DL_LISTobject
object
便
访*/
/**
* @ingroup los_list
* @brief Point to the previous node of the current node.
*
* @par Description:
* This API is used to point to the previous node of the current node.
* @attention
* None.
*
* @param object [IN] Type #LOS_DL_LIST * The 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 LOS_DL_LIST_FIRST
* @since Huawei LiteOS V100R001C00
*/
#define LOS_DL_LIST_LAST(object) ((object)->pstPrev)
/*这段代码是一个宏定义,用于获取双向链表中指定节点的前一个节点。
object
pstPrev
*/
/**
* @ingroup los_list
* @brief Insert a new node to a doubly linked list.
*
* @par Description:
* This API is used to insert a new node after the list node to a doubly linked list.
* @attention
* The parameters passed in should be legal pointers.
*
* @param list [IN] Doubly linked list which the new node will be inserted in.
* @param node [IN] The 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 | LOS_ListTailInsert | LOS_ListHeadInsert
* @since Huawei LiteOS V100R001C00
*/
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;
}
/*该函数将新节点插入到链表头部,具体步骤如下:
next
prev
prev
next
*/
/**
* @ingroup los_list
* @brief Insert a node to a doubly linked list.
*
* @par Description:
* This API is used to insert a new node before the list node to a doubly linked list.
* @attention
* The parameters passed in should be legal pointers.
*
* @param list [IN] Doubly linked list which the new node will be inserted in.
* @param node [IN] The 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
* @since Huawei LiteOS V100R001C00
*/
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
{
LOS_ListAdd(list->pstPrev, node);
}
/*在该函数中,使用了宏定义 LOS_DL_LIST 来表示链表节点,
使 STATIC INLINE
LOS_ListAdd
*/
/**
* @ingroup los_list
* @brief Insert a node to a doubly linked list.
*
* @par Description:
* This API is used to insert a new node after the list node to a doubly linked list.
* It is same with #LOS_ListAdd.
* @attention
* The parameters passed in should be legal pointers.
*
* @param list [IN] Doubly linked list which the new node will be inserted in.
* @param node [IN] The 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
* @since Huawei LiteOS V100R001C00
*/
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:
* This API is used to delete a specified node from a doubly linked list.
* @attention
* The parameter passed in should be a legal pointer.
*
* @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
* @since Huawei LiteOS V100R001C00
*/
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 = NULL;
node->pstPrev = NULL;
}
/*该函数的实现非常简单,具体步骤如下:
next prev prev
prev next next
next prev
*/
/**
* @ingroup los_list
* @brief Identify whether a specified doubly linked list is empty or not.
*
* @par Description:
* This API is used to judge whether a doubly linked list is empty or not. It
* returns a Boolean value.
* @attention
* The parameter passed in should be a legal pointer.
*
* @param list [IN] Doubly linked list.
*
* @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>
* @since Huawei LiteOS V100R001C00
*/
LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
{
return (BOOL)(list->pstNext == list);
}
/*具体步骤如下:
pstNext
TRUE
FALSE
*/
/**
* @ingroup los_list
* @brief Obtain the offset of a structure member relative to the structure start address.
*
* @par Description:
* This API is used to obtain the offset of the structure member (member) relative to
* the start address of the structure (type). And return the offset of #UINTPTR type.
* @attention
* None.
*
* @param type [IN] Structure name.
* @param member [IN] The structure member name which needs to measure the offset.
*
* @retval #UINTPTR Offset of the member relative to the structure start address.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @since Huawei LiteOS V100R001C00
*/
#define LOS_OFF_SET_OF(type, member) ((UINTPTR)&((type *)0)->member)
/* Obsolete API, please use LOS_OFF_SET_OF instead */
#define OFFSET_OF_FIELD(type, field) LOS_OFF_SET_OF(type, field)
/*这些宏的作用是帮助程序员在编写代码时可以方便地获取结构体成员的偏移量。
*/
/**
* @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 the doubly
* linked list which the first parameter item specified.
* @attention
* None.
*
* @param item [IN] Type #LOS_DL_LIST * The node of the doubly linked list.
* @param type [IN] Structure name.
* @param member [IN] The doubly linked list name in the structure.
*
* @retval The pointer to the structure that contains the doubly linked list. And
* the doubly linked list has the node of the first parameter item.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see LOS_DL_LIST_FOR_EACH_ENTRY | LOS_DL_LIST_FOR_EACH_ENTRY_SAFE
* @since Huawei LiteOS V100R001C00
*/
#define LOS_DL_LIST_ENTRY(item, type, member) \
((type *)(VOID *)((CHAR *)(item) - LOS_OFF_SET_OF(type, member)))
/**
* @ingroup los_list
* @brief Traverse a doubly linked list which is included in a given type structure.
*
* @par Description:
* This API is used to traverse a doubly linked list which is included in a given type
* structure. The API is a loop. The start node of the doubly linked list is the second
* parameter list. And in each loop, the obtained pointer to a structure that contains
* the list is outputted in the first parameter item.
* @attention
* None.
*
* @param item [IN/OUT] The pointer to the structure that contains the doubly linked list.
* @param list [IN] Type #LOS_DL_LIST * The start node of the doubly linked list to
* be traversed.
* @param type [IN] Structure name.
* @param member [IN] The doubly linked list name in the structure.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see LOS_DL_LIST_ENTRY | LOS_DL_LIST_FOR_EACH_ENTRY_SAFE | LOS_DL_LIST_FOR_EACH
* @since Huawei LiteOS V100R001C00
*/
#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))
/*宏的实现通过 for 循环来实现链表的遍历,具体步骤如下:
使 LOS_DL_LIST_ENTRY item
&(item)->member != (list)
使 LOS_DL_LIST_ENTRY
便*/
/**
* @ingroup los_list
* @brief Traverse a doubly linked list which is included in a given type structure. And
* it is safe against removal of list entry.
*
* @par Description:
* This API is used to traverse a doubly linked list which is included in a given type
* structure. The API is a loop. The start node of the doubly linked list is the third
* parameter list. And in each loop, the obtained pointer to a structure that contains
* the list is outputted in the first parameter item. And the next node is outputted in
* the second parameter next.
* @attention
* None.
*
* @param item [IN/OUT] The pointer to the structure that contains the doubly linked list.
* @param next [IN/OUT] The pointer to the structure that contains the next node of the
* doubly linked list.
* @param list [IN] Type #LOS_DL_LIST * The start node of the doubly linked list to
* be traversed.
* @param type [IN] Structure name.
* @param member [IN] The doubly linked list name in the structure.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see LOS_DL_LIST_ENTRY | LOS_DL_LIST_FOR_EACH_ENTRY | LOS_DL_LIST_FOR_EACH_SAFE
* @since Huawei LiteOS V100R001C00
*/
#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))
/*该宏的功能是按顺序遍历链表中的每个节点,并对每个节点执行指定的操作。其参数包括:
item
next
list
type
member*/
/**
* @ingroup los_list
* @brief Iterate over a doubly linked list of given type, and call hook for any extra procedures every time.
*
* @par Description:
* This API is used to iterate over a doubly linked list of given type,
* and call hook for any extra procedures every time.
* @attention
* None.
*
* @param item [IN/OUT] 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.
* @param hook [IN] Hook for extra procedures which will be called every time when dev is fetched.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see LOS_DL_LIST_ENTRY | LOS_DL_LIST_FOR_EACH_ENTRY
* @since Huawei LiteOS V200R005C10
*/
#define LOS_DL_LIST_FOR_EACH_ENTRY_HOOK(item, list, type, member, hook) \
for (item = LOS_DL_LIST_ENTRY((list)->pstNext, type, member), hook; \
&(item)->member != (list); \
item = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member), hook)
/*该宏的功能是按顺序遍历链表中的每个节点,并在每个节点遍历之前执行指定的钩子函数。其参数包括:
item
list
type
member
hook*/
/**
* @ingroup los_list
* @brief Delete a specified node from a doubly linked list and reinitialize the node.
*
* @par Description:
* This API is used to delete a specified node (the first parameter list) from the doubly
* linked list. And reinitialize the deleted node to a doubly linked list.
*
* @attention
* The parameter passed in should be a legal pointer.
*
* @param list [IN] Node to be deleted and reinitialize to a doubly linked list.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see LOS_ListInit | LOS_ListDelete
* @since Huawei LiteOS V100R001C00
*/
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 Traverse a doubly linked list.
*
* @par Description:
* This API is used to traverse a doubly linked list. The API is a loop. The start node of the
* doubly linked list is the second parameter list. And in each loop, the obtained pointer to
* the next node of the doubly linked list is outputted in the first parameter item.
* @attention
* None.
*
* @param item [IN/OUT] Type #LOS_DL_LIST * The pointer to the next node in the doubly
* linked list.
* @param list [IN] Type #LOS_DL_LIST * The pointer to the node of 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 LOS_DL_LIST_FOR_EACH_SAFE | LOS_DL_LIST_FOR_EACH_ENTRY
* @since Huawei LiteOS V100R001C00
*/
#define LOS_DL_LIST_FOR_EACH(item, list) \
for (item = (list)->pstNext; \
(item) != (list); \
item = (item)->pstNext)
/*宏的实现通过 for 循环来实现链表的遍历,具体步骤如下:
item (list)->pstNext
(item) != (list) item
item (item)->pstNext
便*/
/**
* @ingroup los_list
* @brief Traverse a doubly linked list safe against removal of list entry.
*
* @par Description:
* This API is used to traverse a doubly linked list safe against removal of list entry. The
* API is a loop. The start node of the doubly linked list is the third parameter list. And
* in each loop, the obtained pointer to the next node of the doubly linked list is outputted
* in the first parameter item. And the next node of the the node specified by first parameter
* item is outputted in the second parameter next.
* @attention
* None.
*
* @param item [IN/OUT] Type #LOS_DL_LIST * The pointer to the next node in the doubly
* linked list.
* @param next [IN/OUT] Type #LOS_DL_LIST * The pointer to the next node of the the node
* specified by first parameter item.
* @param list [IN] Type #LOS_DL_LIST * The pointer to the node of 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 LOS_DL_LIST_FOR_EACH | LOS_DL_LIST_FOR_EACH_ENTRY_SAFE
* @since Huawei LiteOS V100R001C00
*/
#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 the input node (the parameter list) to a double linked
* list. The difference with LOS_ListInit is that the parameter list is not a pointer while
* in LOS_ListInit it is a pointer.
* @attention
* None.
*
* @param list [IN] Type #LOS_DL_LIST A node to be initialized to a doubly linked list.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see LOS_ListInit
* @since Huawei LiteOS V100R001C00
*/
#define LOS_DL_LIST_HEAD(list) LOS_DL_LIST list = { &(list), &(list) }
/*通过这个宏,可以方便地定义和初始化一个双向链表的头部节点,为链表的后续操作提供了便利。*/
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_LIST_H */

@ -0,0 +1,86 @@
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: Lite Memory Sanitizer HeadFile
* Author: Huawei LiteOS Team
* Create: 2020-09-01
* 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_LMS_H
#define _LOS_LMS_H
#include "los_typedef.h"
#include "securec.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_KERNEL_LMS
// Start: Kernel Address Sanitizer(KASAN) for LiteOS
// Redefine memcpy and other memory opration functions to enable KASAN check ability for LiteOS
// This is a debug feature and only available when LOSCFG_KERNEL_LMS is configured to Y
#define memcpy KasanMemcpy
#define memmove KasanMemmove
#define strcat KasanStrcat
#define strcpy KasanStrcpy
#define memcpy_s KasanMemcpySec
#define memmove_s KasanMemmoveSec
#define strcat_s KasanStrcatSec
#define strcpy_s KasanStrcpySec
/*使用#define预处理指令来重新定义标准库函数的名称。这种技术通常用于调试或测试目的或者提供这些函数的自定义实现。
memcpymemmovestrcatstrcpyKasanMemcpy
KasanMemmoveKasanStrcatKasanStrcpymemcpy_smemmove_sstrcat_sstrcpy_s
KasanMemcpySecKasanMemmoveSecKasanStrcatSecKasanStrcpySec*/
// End: Kernel Address Sanitizer(KASAN) for LiteOS
VOID *KasanMemcpy(VOID *__restrict dest, const VOID *__restrict src, size_t copyAmount);
VOID *KasanMemmove(VOID *dest, const VOID *src, size_t len);
CHAR *KasanStrcat(CHAR *s, const CHAR *append);
CHAR *KasanStrcpy(CHAR *dest, const CHAR *src);
/*KasanMemcpy类似于标准库中的memcpy用于在内存中复制一定数量的数据。可能会包含额外的内存访问检查。
KasanMemmovememmove访
KasanStrcatstrcat访
KasanStrcpystrcpy访*/
errno_t KasanMemcpySec(VOID *dest, size_t destMax, const VOID *src, size_t copyAmount);
errno_t KasanMemmoveSec(VOID *dest, size_t destMax, const VOID *src, size_t len);
errno_t KasanStrcatSec(CHAR *s, size_t destMax, const CHAR *append);
errno_t KasanStrcpySec(CHAR *dest, size_t destMax, const CHAR *src);
/*主要是用于处理字符串和内存拷贝操作。这里的 destMax 参数通常表示目标缓冲区的最大长度,以防止缓冲区溢出等安全问题。
KasanMemcpySecmemcpy
KasanMemmoveSecmemmove
KasanStrcatSecstrcat
KasanStrcpySecstrcpy*/
#endif /* LOSCFG_KERNEL_LMS */
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_LMS_H */

@ -0,0 +1,173 @@
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* Description: Lock Dependency Check.
* Author: Huawei LiteOS Team
* Create: 2018-10-18
* 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_lockdep lockdep
* @ingroup kernel
*/
#ifndef _LOS_LOCKDEP_H
#define _LOS_LOCKDEP_H
#include "los_config.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct Spinlock SPIN_LOCK_S;
#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
#define MAX_LOCK_DEPTH 16U
enum LockDepErrType {
LOCKDEP_SUCEESS = 0,
LOCKDEP_ERR_DOUBLE_LOCK,
LOCKDEP_ERR_DEAD_LOCK,
LOCKDEP_ERR_UNLOCK_WITHOUT_LOCK,
/* overflow, needs expand */
LOCKDEP_ERR_OVERFLOW,
};
/*这是一个枚举类型 LockDepErrType用于表示在锁依赖性检查中可能发生的不同错误类型。下面是该枚举类型定义的各个取值及其含义
LOCKDEP_SUCCESS
LOCKDEP_ERR_DOUBLE_LOCK线
LOCKDEP_ERR_DEAD_LOCK线
LOCKDEP_ERR_UNLOCK_WITHOUT_LOCK线线
LOCKDEP_ERR_OVERFLOW*/
typedef struct {
VOID *lockPtr;
VOID *lockAddr;
UINT64 waitTime;
UINT64 holdTime;
} HeldLocks;
/*这个结构体主要用于在锁依赖性分析和调试过程中记录当前线程持有的锁的相关信息。通过记录这些信息,
使便
lockPtr VOID*
lockAddr VOID*
waitTime UINT64 线
holdTime UINT64 线*/
typedef struct {
VOID *waitLock;
INT32 lockDepth;
HeldLocks heldLocks[MAX_LOCK_DEPTH];
} LockDep;
/*这个结构体主要用于在锁依赖性分析和调试过程中记录当前线程的锁依赖关系。
线
使便*/
/**
* @ingroup los_lockdep
*
* @par Description:
* This API is used to check dead lock in spinlock.
* @attention
* <ul>
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
* </ul>
*
* @param lock [IN] point to a SPIN_LOCK_S.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lockdep.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V200R003C00
*/
extern VOID OsLockDepCheckIn(const SPIN_LOCK_S *lock);
/*函数名称为 OsLockDepCheckIn参数类型为 const SPIN_LOCK_S* lock返回类型为 VOID。该函数的作用是将指定
lock */
/**
* @ingroup los_lockdep
*
* @par Description:
* This API is used to trace when a spinlock locked.
* @attention
* <ul>
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
* </ul>
*
* @param lock [IN] point to a SPIN_LOCK_S.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lockdep.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V200R003C00
*/
extern VOID OsLockDepRecord(SPIN_LOCK_S *lock);
/**
* @ingroup los_lockdep
*
* @par Description:
* This API is used to trace when a spinlock unlocked.
* @attention
* <ul>
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
* </ul>
*
* @param lock [IN] point to a SPIN_LOCK_S.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lockdep.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V200R003C00
*/
extern VOID OsLockDepCheckOut(SPIN_LOCK_S *lock);
/*函数名称为 OsLockDepCheckOut参数类型为 SPIN_LOCK_S* lock返回类型为 VOID。该函数的作用
lock*/
/**
* @ingroup los_lockdep
*
* @par Description:
* This API is used to clear lockdep record of current task.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None
* @retval None.
* @par Dependency:
* <ul><li>los_lockdep.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V200R003C00
*/
extern VOID OsLockdepClearSpinlocks(VOID);
#endif /* LOSCFG_KERNEL_SMP_LOCKDEP */
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* _LOS_LOCKDEP_H */

@ -0,0 +1,381 @@
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: Low-power Framework.
* Author: Huawei LiteOS Team
* Create: 2020-09-19
* 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_lowpower lowpower_framework
* @ingroup kernel
*/
#ifndef _LOS_LOWPOWER_H
#define _LOS_LOWPOWER_H
#include "los_base.h"
#include "los_sys.h"
#include "los_err.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_lowpower
*
* Intermit modes
*/
typedef enum LOS_INTERMIT_MODE {
LOS_INTERMIT_NONE = 0,
LOS_INTERMIT_LIGHT_SLEEP, /**< Light sleep mode */
LOS_INTERMIT_DEEP_SLEEP, /**< Deep sleep mode */
LOS_INTERMIT_STANDBY, /**< Standby mode */
LOS_INTERMIT_SHUTDOWN, /**< Shutdown mode */
LOS_INTERMIT_MAX,
} LosIntermitMode;
/*这是一个枚举类型 LOS_INTERMIT_MODE 的定义,包含了几个枚举常量:
LOS_INTERMIT_NONE
LOS_INTERMIT_LIGHT_SLEEP
LOS_INTERMIT_DEEP_SLEEP
LOS_INTERMIT_STANDBY
LOS_INTERMIT_SHUTDOWN
LOS_INTERMIT_MAX*/
/**
* @ingroup los_lowpower
*
* System main frequency modes
*/
typedef enum LOS_FREQ_MODE {
LOS_SYS_FREQ_SUPER = 0, /**< Super high freq */
LOS_SYS_FREQ_HIGH, /**< High freq */
LOS_SYS_FREQ_NORMAL, /**< Normal freq */
LOS_SYS_FREQ_LOW, /**< Low freq */
LOS_SYS_FREQ_MAX,
} LosFreqMode;
/*这是另一个枚举类型 LOS_FREQ_MODE 的定义,包含了几个枚举常量:
LOS_SYS_FREQ_SUPER
LOS_SYS_FREQ_HIGH
LOS_SYS_FREQ_NORMAL
LOS_SYS_FREQ_LOW
LOS_SYS_FREQ_MAX*/
typedef UINT32 (*LowpowerExternalVoterHandle)(VOID);
STATIC INLINE BOOL FreqHigher(LosFreqMode freq1, LosFreqMode freq2)
{
return freq1 < freq2;
}
/**
* @ingroup los_lowpower
*
* Define the structure of the power manager operations.
*/
typedef struct {
VOID (*process)(VOID); /**< Power manager framework entry interface */
VOID (*wakeupFromReset)(VOID); /**< Recovery interface used to wakeup from image */
VOID (*resumeFromInterrupt)(UINT32); /**< Recovery interface used to wakeup from interrupt */
VOID (*changeFreq)(LosFreqMode); /**< System frequency tuning interface, the param is LosFreqMode */
VOID (*deepSleepVoteBegin)(VOID); /**< Deep sleep vote mark interface */
VOID (*deepSleepVoteEnd)(VOID); /**< Deep sleep vote erase interface */
VOID (*deepSleepVoteDelay)(UINT32 tick); /**< Deep sleep vote delay interface, the param is the delayed ticks */
VOID (*registerExternalVoter)(UINT32 (*handler)(VOID)); /**< External voter registration interface */
UINT32 (*getDeepSleepVoteCount)(VOID); /**< Get deep sleep vote count interface */
UINT32 (*getSleepMode)(VOID); /**< Get sleep mode interface, the retval type is LosIntermitMode */
VOID (*setSleepMode)(UINT32 mode); /**< Set sleep mode interface, the param type is LosIntermitMode */
} PowerMgrOps;
/*这是一个结构体类型 PowerMgrOps 的定义,包含了多个函数指针成员:
process
wakeupFromReset
resumeFromInterrupt
changeFreq LosFreqMode
deepSleepVoteBegin
deepSleepVoteEnd
deepSleepVoteDelay
registerExternalVoter UINT32
getDeepSleepVoteCount UINT32
getSleepMode LosIntermitMode
setSleepMode UINT32 LosIntermitMode*/
/**
* @ingroup los_lowpower
* @brief System main frequency tuning.
*
* @par Description:
* This API is used to tune the system main frequency.
*
* @attention None.
*
* @param freq [IN] The system frequency, corresponding to LosFreqMode.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lowpower.h: the header file that contains the API declaration.</li></ul>
* @see None.
* @since Huawei LiteOS V200R005C10
*/
extern VOID LOS_PowerMgrChangeFreq(LosFreqMode freq);
/*这是一个外部声明extern的函数 LOS_PowerMgrChangeFreq
LosFreqMode freq
*/
/**
* @ingroup los_lowpower
* @brief Vote to enter deep sleep.
*
* @par Description:
* This API is used to mark the deep sleep vote. Called when the current state is idle.
*
* @attention None.
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lowpower.h: the header file that contains the API declaration.</li></ul>
* @see None.
* @since Huawei LiteOS V200R005C10
*/
extern VOID LOS_PowerMgrDeepSleepVoteBegin(VOID);
/**
* @ingroup los_lowpower
* @brief Erase the deep sleep vote.
*
* @par Description:
* This API is used to erase the deep sleep vote. Called when the current state is busy.
*
* @attention None.
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lowpower.h: the header file that contains the API declaration.</li></ul>
* @see None.
* @since Huawei LiteOS V200R005C10
*/
extern VOID LOS_PowerMgrDeepSleepVoteEnd(VOID);
/*这是一个外部声明extern的函数 LOS_PowerMgrDeepSleepVoteEnd它没有任何参数返回类型为 VOID。根据函数名来看
*/
/**
* @ingroup los_lowpower
* @brief Sleep delay vote.
*
* @par Description:
* This API is used to delay sleep vote. Called when the current state busy, but can enter sleep later.
*
* @attention None.
*
* @param tick [IN] The sleeptime.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lowpower.h: the header file that contains the API declaration.</li></ul>
* @see None.
* @since Huawei LiteOS V200R005C10
*/
extern VOID LOS_PowerMgrSleepDelay(UINT32 tick);
/*这是一个外部声明extern的函数 LOS_PowerMgrSleepDelay它接受一个 UINT32 类型的参数 tick
*/
/**
* @ingroup los_lowpower
* @brief Register the external voter.
*
* @par Description:
* This API is used to register the external voter, provided for developers with special needs.
*
* @attention None.
*
* @param UINT32 (*)(VOID) [IN] The external voter.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lowpower.h: the header file that contains the API declaration.</li></ul>
* @see None.
* @since Huawei LiteOS V200R005C10
*/
extern VOID LOS_PowerMgrRegisterExtVoter(UINT32 (*)(VOID));
/*这是一个外部声明extern的函数 LOS_PowerMgrRegisterExtVoter
UINT32
*/
/**
* @ingroup los_lowpower
* @brief Get the sleep mode.
*
* @par Description:
* This API is used to get sleep mode. Developers can set different corresponding modes.
* according to the actual scene, then perform follow-up operations.
*
* @attention None.
*
* @param None.
*
* @retval #UINT32 Sleep mode, corresponding to LosIntermitMode.
* @par Dependency:
* <ul><li>los_lowpower.h: the header file that contains the API declaration.</li></ul>
* @see None.
* @since Huawei LiteOS V200R005C10
*/
extern UINT32 LOS_PowerMgrGetSleepMode(VOID);
/**
* @ingroup los_lowpower
* @brief Get the deep sleep vote count.
*
* @par Description:
* This API is used to get the deep sleep vote count.
*
* @attention None.
*
* @param None.
*
* @retval #UINT32 Deep sleep vote count.
* @par Dependency:
* <ul><li>los_lowpower.h: the header file that contains the API declaration.</li></ul>
* @see None.
* @since Huawei LiteOS V200R005C10
*/
extern UINT32 LOS_PowerMgrGetDeepSleepVoteCount(VOID);
/**
* @ingroup los_lowpower
* @brief Register power manager operations.
*
*
* @par Description:
* This API is used to register power manager operations or customized power manager by developers.
*
* @attention None.
*
* @param pmOps [IN] The power manager operations.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lowpower.h: the header file that contains the API declaration.</li></ul>
* @see None.
* @since Huawei LiteOS V200R005C10
*/
extern VOID LOS_LowpowerInit(const PowerMgrOps *pmOps);
/*这是一个外部声明extern的函数 LOS_LowpowerInit
const PowerMgrOps * pmOps
便*/
/**
* @ingroup los_lowpower
* @brief Define the lowpower framework process function type.
*
* @par Description:
* This API is used to define the lowpower framework entry function type.
*
* @attention None.
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lowpower.h: the header file that contains the API declaration.</li></ul>
* @see None.
* @since Huawei LiteOS V200R005C10
*/
typedef VOID (*LowPowerHookFn)(VOID);
/*这是一个类型定义语句,定义了一个名为 LowPowerHookFn 的函数指针类型。
VOID
便退*/
/**
* @ingroup los_lowpower
* @brief Register a hook to enter lowpower framework process.
*
* @par Description:
* This API is used to register lowpower framework entry function.
*
* @attention None.
*
* @param hook [IN] The lowpower framework hook.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lowpower.h: the header file that contains the API declaration.</li></ul>
* @see None.
* @since Huawei LiteOS V200R005C10
*/
extern VOID LOS_LowpowerHookReg(LowPowerHookFn hook);
/*这是一个外部声明extern的函数 LOS_LowpowerHookReg
LowPowerHookFn hook
便退*/
/**
* @ingroup los_lowpower
* @brief Define the lowpower framework wakup function type.
*
* @par Description:
* This API is used to define the lowpower framework wakup function type.
*
* @attention None.
*
* @param hwiNum [IN] The interrupt number.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lowpower.h: the header file that contains the API declaration.</li></ul>
* @see None.
* @since Huawei LiteOS V200R005C10
*/
typedef VOID (*IntWakeupHookFn)(HWI_HANDLE_T hwiNum);
/*这是一个类型定义语句,定义了一个名为 IntWakeupHookFn 的函数指针类型。
HWI_HANDLE_T VOID
便
*/
/**
* @ingroup los_lowpower
* @brief Register a hook to wakeup from interrupt.
*
* @par Description:
* This API is used to register a recovery function after wakeup from interrupt
*
* @attention None.
*
* @param hook [IN] The lowpower wakeup hook.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lowpower.h: the header file that contains the API declaration.</li></ul>
* @see None.
* @since Huawei LiteOS V200R005C10
*/
extern VOID LOS_IntWakeupHookReg(IntWakeupHookFn hook);
/*这是一个外部声明extern的函数 LOS_IntWakeupHookReg
IntWakeupHookFn hook
便
*/
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_LOWPOWER_H */

@ -0,0 +1,159 @@
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: Low-power Framework.
* Author: Huawei LiteOS Team
* Create: 2020-09-19
* 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_LOWPOWER_IMPL_H
#define _LOS_LOWPOWER_IMPL_H
#include "los_lowpower.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_lowpower
*
* Power manager run options
*/
typedef struct {
VOID (*changeFreq)(UINT8 freq); /**< Tune system frequency */
VOID (*enterLightSleep)(VOID); /**< Enter light sleep */
VOID (*enterDeepSleep)(VOID); /**< Enter deep sleep */
VOID (*setWakeUpTimer)(UINT32 timeout); /**< Set wakeup timer */
UINT32 (*withdrawWakeUpTimer)(VOID); /**< Withdraw wakeup timer */
UINT32 (*getSleepTime)(VOID); /**< Get sleep time */
UINT32 (*selectSleepMode)(UINT32); /**< Select sleep mode, developers can set their own mode selecetion
strategy */
UINT32 (*preConfig)(VOID); /**< Preconfig, provided for special needs before entering sleep */
VOID (*postConfig)(VOID); /**< Postconfig, provided for special needs after wakeup */
VOID (*contextSave)(VOID); /**< Context save */
VOID (*contextRestore)(VOID); /**< Context restore */
UINT32 (*getDeepSleepVoteCount)(VOID); /**< Get deep sleep vote count */
UINT32 (*getSleepMode)(VOID); /**< Get sleep mode */
VOID (*setSleepMode)(UINT32 mode); /**< Set sleep mode */
} PowerMgrRunOps;
/*具体来说,该结构体包含以下函数指针成员:
changeFreq
enterLightSleeplight sleep
enterDeepSleepdeep sleep
setWakeUpTimer
withdrawWakeUpTimer
getSleepTime
selectSleepMode
preConfig
postConfig
contextSave
contextRestore
getDeepSleepVoteCount
getSleepMode
setSleepMode*/
/**
* @ingroup los_lowpower
*
* Power manager config, corresponding to mode selection strategies.
*/
typedef struct {
UINT32 minLightSleepTicks; /**< Min light sleep ticks */
UINT32 minDeepSleepTicks; /**< Min deep sleep ticks */
UINT32 maxDeepSleepTicks; /**< Max deep sleep ticks */
} PowerMgrConfig;
/*minLightSleepTicks最小轻度睡眠light sleep时钟周期数。
minDeepSleepTicksdeep sleep
maxDeepSleepTicksdeep sleep
使*/
/**
* @ingroup los_lowpower
*
* Power manager deep sleep options
*/
typedef struct {
BOOL (*couldDeepSleep)(VOID); /**< Check whether could enter deep sleep */
VOID (*systemWakeup)(VOID); /**< System wakup */
BOOL (*suspendPreConfig)(VOID); /**< Suspend preconfig, provided for special needs before entering deep sleep */
VOID (*suspendDevice)(VOID); /**< Supend device before entering deep sleep */
VOID (*rollback)(VOID); /**< Rollback if failed */
VOID (*resumeDevice)(VOID); /**< Resume device after wakeup from deep sleep */
VOID (*resumePostConfig)(VOID); /**< Resume postconfig, provided for special needs after wakeup from deep sleep */
VOID (*resumeCallBack)(VOID); /**< Resume callback */
VOID (*otherCoreResume)(VOID); /**< Other core Resume for multi-core scenes */
VOID (*resumeFromReset)(VOID); /**< Resume from image */
} PowerMgrDeepSleepOps;
/*couldDeepSleep检查系统是否可以进入深度睡眠状态。
systemWakeup
suspendPreConfig
suspendDevice
rollback
resumeDevice
resumePostConfig
resumeCallBack
otherCoreResume
resumeFromReset*/
/**
* @ingroup los_lowpower
*
* Power manager parameter
*/
typedef struct {
PowerMgrRunOps runOps; /**< power manager framework running operations */
PowerMgrDeepSleepOps deepSleepOps; /**< power manager deep sleep operations */
PowerMgrConfig config; /**< power manager config */
} PowerMgrParameter;
/*runOps类型为 PowerMgrRunOps 的结构体变量,用于描述系统运行状态下的功耗管理操作集合。
deepSleepOps PowerMgrDeepSleepOps
config PowerMgrConfig
PowerMgrParameter */
/**
* @ingroup los_lowpower
* @brief Init the power manager framework.
*
* @par Description:
* This API is used to init the power manager framework.
*
* @attention None.
*
* @param para [IN] The power manager parameter.
*
* @retval None.
* @par Dependency:
* <ul><li>los_lopower_impl.h: the header file that contains the API declaration.</li></ul>
* @see None.
* @since Huawei LiteOS V200R005C10
*/
extern VOID LOS_PowerMgrInit(const PowerMgrParameter *para);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif // _LOS_LOWPOWER_IMPL_H

@ -0,0 +1,308 @@
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved.
* Description: LiteOS memory Module HeadFile
* Author: Huawei LiteOS Team
* Create: 2013-01-01
* 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"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_membox
* @brief Align the input parameter.
*
* @par Description:
* The macro is used to align memAddr based on UINTPTR. memAddr is the input parameter.
* @attention
* None.
*
* @param memAddr [IN] The variable that need to be aligned. Usually memAddr is an unsigned integer
* or an unsigned long integer on 64-bit platporm.
*
* @retval The memAddr value after alignment.
* @par Dependency:
* <ul>
* <li>los_membox.h: the header file that contains the API declaration.</li>
* </ul>
* @since Huawei LiteOS V100R001C00
*/
#define LOS_MEMBOX_ALLIGNED(memAddr) (((UINTPTR)(memAddr) + sizeof(UINTPTR) - 1) & (~(sizeof(UINTPTR) - 1)))
#ifdef LOSCFG_KERNEL_MEMBOX_STATIC
/**
* @ingroup los_membox
* Get next node in static memory pool
*/
#define OS_MEMBOX_NEXT(addr, blkSize) (LOS_MEMBOX_NODE *)(VOID *)((UINT8 *)(addr) + (blkSize))
/**
* @ingroup los_membox
* Head size of each node in staic memory pool
*/
#define OS_MEMBOX_NODE_HEAD_SIZE sizeof(LOS_MEMBOX_NODE)
/*LOS_MEMBOX_ALLIGNED(memAddr) 宏用于对内存地址进行对齐操作。
memAddr UINTPTR sizeof(UINTPTR) -
1 ~(sizeof(UINTPTR) - 1)
sizeof(UINTPTR)
OS_MEMBOX_NEXT(addr, blkSize)
addr UINT8* blkSize
OS_MEMBOX_NODE_HEAD_SIZE LOS_MEMBOX_NODE
*/
/**
* @ingroup los_membox
* @brief Obtain the size of the static memory pool.
*
* @par Description:
* The macro is used to obtain the size of the static memory pool according to the memory
* block size and number.
* @attention
* None.
*
* @param blkSize [IN] Type #UINT32 The memory block size of the static memory pool.
* @param blkNum [IN] Type #UINT32 The total memory block number of the static memory pool.
*
* @retval The size of the static memory pool.
* @par Dependency:
* <ul>
* <li>los_membox.h: the header file that contains the API declaration.</li>
* </ul>
* @since Huawei LiteOS V100R001C00
*/
#define LOS_MEMBOX_SIZE(blkSize, blkNum) \
(sizeof(LOS_MEMBOX_INFO) + (LOS_MEMBOX_ALLIGNED((blkSize) + OS_MEMBOX_NODE_HEAD_SIZE) * (blkNum)))
/*该宏首先使用 LOS_MEMBOX_ALLIGNED 宏对 (blkSize) + OS_MEMBOX_NODE_HEAD_SIZE 进行对齐操作,确保每个内存块都按照节点大小对齐。然后将对齐后的大小乘以 blkNum并加上 sizeof(LOS_MEMBOX_INFO),得到静态内存池的总大小。
sizeof(LOS_MEMBOX_INFO)
*/
/**
* @ingroup los_membox
* Structure of a free node in a static memory pool
*/
typedef struct tagMEMBOX_NODE {
struct tagMEMBOX_NODE *pstNext; /**< Free node's pointer to the next node in a static memory pool. */
} LOS_MEMBOX_NODE;
#endif
/**
* @ingroup los_membox
* Static memory pool information structure
*/
typedef struct {
UINT32 uwBlkSize; /**< The memory block size of the static memory pool */
UINT32 uwBlkNum; /**< The total memory block number of the static memory pool */
UINT32 uwBlkCnt; /**< The number of allocated memory blocks in the static memory pool */
#ifdef LOSCFG_KERNEL_MEMBOX_STATIC
LOS_MEMBOX_NODE stFreeList; /**< The list of free memory block node in the static memory pool. This
structure member is available only LOSCFG_KERNEL_MEMBOX_STATIC is
defined. */
#endif
} LOS_MEMBOX_INFO;
typedef LOS_MEMBOX_INFO OS_MEMBOX_S;
/*LOS_MEMBOX_INFO静态内存池的元信息结构体。包含了静态内存池的起始地址、
uwBlkCnt
stFreeList LOSCFG_KERNEL_MEMBOX_STATIC
OS_MEMBOX_S LOS_MEMBOX_INFO */
/**
* @ingroup los_membox
* @brief Initialize a static memory pool.
*
* @par Description:
* This API is used to initialize a static memory pool. The start address of the memory pool is specified
* by the first parameter. In the API, it will set the memory block size, total block number, allocated
* block number and the list of free memory block nodes of the static memory pool.
* @attention
* The poolSize parameter value should match the following two conditions:
* <ul>
* <li>Be less than or equal to the size of the memory pool specified by the pool parameter.</li>
* <li>Be greater than the size of LOS_MEMBOX_INFO.</li>
* </ul>
*
* @param pool [IN] Memory pool address.
* @param poolSize [IN] The total size of the static memory pool.
* @param blkSize [IN] The memory block size of the static memory pool.
*
* @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>
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemboxInit(VOID *pool, UINT32 poolSize, UINT32 blkSize);
/*该函数会使用提供的内存池起始地址和大小来初始化静态内存池,并指定每个内存块的大小。
*/
/**
* @ingroup los_membox
* @brief Request a static memory block.
*
* @par Description:
* This API is used to request a static memory block from the static memory pool which has been initialized.
* @attention
* The input pool parameter must be initialized via func #LOS_MemboxInit.
*
* @param pool [IN] Memory pool address.
*
* @retval #VOID* This API will return a memory block address, if the request is accepted successfully.
* @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
* @since Huawei LiteOS V100R001C00
*/
extern VOID *LOS_MemboxAlloc(VOID *pool);
/**
* @ingroup los_membox
* @brief Free a static memory block.
*
* @par Description:
* This API is used to free a static memory block to the static memory pool.
* @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. The memory block need to release is requested
* from this memory pool.
* @param box [IN] The pointer to the memory block to be released.
*
* @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
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemboxFree(VOID *pool, VOID *box);
/*调用该函数将会释放 box 所指向的内存块,并将其重新加入到内存池的空闲内存块链表中,以便下次分配使用。*/
/**
* @ingroup los_membox
* @brief Clear a static memory block.
*
* @par Description:
* This API is used to set the memory block value to 0.
* @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. The memory block need to clear is requested
* from this memory pool.
* @param box [IN] The pointer to the memory block to clear.
* @retval None.
* @par Dependency:
* <ul>
* <li>los_membox.h: the header file that contains the API declaration.</li>
* </ul>
* @since Huawei LiteOS V100R001C00
*/
extern VOID LOS_MemboxClr(VOID *pool, VOID *box);
/*调用该函数将会将 box 所指向的内存块的数据内容清零,使其变为初始状态。
使*/
/**
* @ingroup los_membox
* @brief show static memory pool information.
*
* @par Description:
* This API is used to print static memory pool information. It can print the memory pool address,
* the memory block size, the total block number, the list of free memory block node and the total block
* node list of the static memory pool.
* @attention
* The input pool parameter must be initialized via func #LOS_MemboxInit.
*
* @param pool [IN] Memory pool address.
*
* @retval None.
* @par Dependency:
* <ul>
* <li>los_membox.h: the header file that contains the API declaration.</li>
* </ul>
* @see LOS_MemboxStatisticsGet
* @since Huawei LiteOS V100R001C00
*/
extern VOID LOS_ShowBox(VOID *pool);
/**
* @ingroup los_membox
* @brief Obtain the static memory pool information.
*
* @par Description:
* This API is used to obtain the static memory pool information. The information includes
* the total memory block number, block size and the allocated block number of the static
* memory pool. The obtained information will be outputted in the last three parameters.
*
* @attention
* The first parameter boxMem of this interface is a pointer, it should be a correct value.
* Otherwise the system may be abnormal.
*
* @param boxMem [IN] Type #VOID* Pointer to the static memory pool.
* @param maxBlk [OUT] Type #UINT32* The total memory block number is outputted to this parameter.
* @param blkCnt [OUT] Type #UINT32* The allocated memory block number is outputted to this parameter.
* @param blkSize [OUT] Type #UINT32* The memory block size is outputted to this parameter.
*
* @retval #LOS_OK Obtain the static memory pool information successfully.
* @retval #LOS_NOK Failed to obtain the static memory pool information, check whether the
* parameters is NULL or not.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @see LOS_ShowBox
* @since Huawei LiteOS V100R001C00
*/
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 */

@ -0,0 +1,853 @@
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved.
* Description: LiteOS Mem Module HeadFile
* Author: Huawei LiteOS Team
* Create: 2013-01-01
* 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_base.h"
#include "los_toolchain.h"
#include "los_membox.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_MEM_LEAKCHECK
/**
* @ingroup los_memory
* The omit layers of function call from kernel memory interfaces such as
* LOS_MemAlloc/LOS_MemAllocAlign/LOS_MemRealloc/LOS_MemFree.
* Note that this macro is defined only when LOSCFG_MEM_LEAKCHECK is defined.
*/
#define LOS_OMIT_LR_CNT 2
/**
* @ingroup los_memory
* The recorded layers of function call.
* Note that this macro is defined only when LOSCFG_MEM_LEAKCHECK is defined.
*/
#define LOS_RECORD_LR_CNT 3
#endif
#define OS_MEM_ALIGN_SIZE (sizeof(UINTPTR))
/**
* @ingroup los_memory
* @brief Define the type of the customized tuning function when calling the API LOS_MemAlloc to allocate
* memory.
*
* @par Description:
* This definition is used to declare the customized tuning function when calling the API LOS_MemAlloc to
* allocate memory.
* @attention
* None.
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @since Huawei LiteOS V100R001C00
*/
typedef VOID (*MALLOC_HOOK)(VOID);
/**
* @ingroup los_memory
* Customized tuning function when calling the API LOS_MemAlloc to allocate memory.
*/
extern MALLOC_HOOK g_MALLOC_HOOK;
/**
* @ingroup los_memory
* The start address of exception interaction dynamic memory pool address, when the exception
* interaction feature not support, m_aucSysMem0 equals to m_aucSysMem1.
*/
extern UINT8 *m_aucSysMem0;
/**
* @ingroup los_memory
* The start address of system dynamic memory pool address.
*/
extern UINT8 *m_aucSysMem1;
/**
* @ingroup los_memory
* The end address of system memory.
*/
extern UINTPTR g_sys_mem_addr_end;
#ifdef LOSCFG_EXC_INTERACTION
/**
* @ingroup los_memory
* The size of exception interaction memory.
*/
extern UINTPTR g_excInteractMemSize;
#endif
#ifdef LOSCFG_MEM_MUL_MODULE
/**
* @ingroup los_memory
* The memory usage statistics depend on module, this is the max module number 0x20.
* Note that this macro is defined only when LOSCFG_MEM_MUL_MODULE is defined.
*/
#define MEM_MODULE_MAX 0x20
/**
* @ingroup los_memory
* @brief Allocate dynamic memory.
*
* @par Description:
* This API is used to allocate a memory block of which the size is specified and update module mem used.
* @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>
* <li>This function is defined only when LOSCFG_MEM_MUL_MODULE is defined.</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).
* @param moduleId [IN] module ID (0~MODULE_MAX).
*
* @retval #NULL The memory fails to be allocated.
* @retval #VOID* The memory is successfully allocated, and the API returns the pointer to
* the allocated memory block.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MemMrealloc | LOS_MemMallocAlign | LOS_MemMfree
* @since Huawei LiteOS V100R001C00
*/
extern VOID *LOS_MemMalloc(VOID *pool, UINT32 size, UINT32 moduleId);
/*pool指向内存池起始地址的指针。
size
moduleId ID
size
NULL
ID moduleId 使*/
/**
* @ingroup los_memory
* @brief Allocate aligned memory.
*
* @par Description:
* This API is used to allocate memory blocks of specified size and of which the starting addresses are aligned on
* a specified boundary and update module mem used.
* @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>
* <li>This function is defined only when LOSCFG_MEM_MUL_MODULE is defined.</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.
* @param moduleId [IN] module ID (0~MODULE_MAX).
*
* @retval #NULL The memory fails to be allocated.
* @retval #VOID* The memory is successfully allocated, and the API returns the pointer to the allocated memory.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MemMalloc | LOS_MemRealloc | LOS_MemMfree
* @since Huawei LiteOS V100R001C00
*/
extern VOID *LOS_MemMallocAlign(VOID *pool, UINT32 size, UINT32 boundary, UINT32 moduleId);
/*调用该函数将会在指定的内存池中按照指定的对齐边界boundary分配大小为 size 的内存块,并将其地址返回给调用者。
boundary
NULL
ID moduleId 使*/
/**
* @ingroup los_memory
* @brief Free dynamic memory.
*
* @par Description:
* This API is used to free specified dynamic memory that has been allocated and update module mem used.
* @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_MemMalloc or LOS_MemMallocAlign or LOS_MemMrealloc.</li>
* <li>This function is defined only when LOSCFG_MEM_MUL_MODULE is defined.</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.
* @param moduleId [IN] module ID (0~MODULE_MAX).
*
* @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 freed successfully.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MemMalloc | LOS_MemMrealloc | LOS_MemMallocAlign
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemMfree(VOID *pool, VOID *ptr, UINT32 moduleId);
/*调用该函数将会释放由 ptr 指向的内存块,并将其归还给指定的内存池。同时,通过 moduleId 参数指定要释放的内存块所属的模块 ID以便进行相关的内存管理操作。
LOS_MemMalloc LOS_MemMallocAlign */
/**
* @ingroup los_memory
* @brief Re-allocate a memory block.
*
* @par Description:
* 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. And update module mem used.
* @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_MemMalloc or LOS_MemMallocAlign.</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_MemMallocAlign, it must be aligned with the size of
* the input parameter boundary of LOS_MemMallocAlign.</li>
* <li>This function is defined only when LOSCFG_MEM_MUL_MODULE is defined.</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.
* @param moduleId [IN] module ID (0~MODULE_MAX).
*
* @retval #NULL The memory fails to be re-allocated.
* @retval #VOID* The memory is successfully re-allocated, and the API returns the pointer to
* the new memory block.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MemMalloc | LOS_MemMallocAlign | LOS_MemMfree
* @since Huawei LiteOS V100R001C00
*/
extern VOID *LOS_MemMrealloc(VOID *pool, VOID *ptr, UINT32 size, UINT32 moduleId);
/**
* @ingroup los_memory
* @brief get the uesed memory size of the specified module.
*
* @par Description:
* This API is used to get the specified module's memory consume size.
* @attention This function is defined only when LOSCFG_MEM_MUL_MODULE is defined.
*
* @param moduleId [IN] module ID (0~MODULE_MAX).
*
* @retval #UINT32 The size of the specified module's consumed memory.
* @retval #OS_NULL_INT The input module id is illegal.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemMusedGet(UINT32 moduleId);
#endif
#ifdef LOSCFG_MEM_MUL_POOL
/**
* @ingroup los_memory
* @brief Deinitialize dynamic memory.
*
* @par Description:
* This API is used to deinitialize the dynamic memory of a doubly linked list.
* @attention This function is defined only when LOSCFG_MEM_MUL_POOL is defined.
*
* @param pool [IN] Starting address of memory.
*
* @retval #LOS_NOK 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>
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemDeInit(VOID *pool);
/**
* @ingroup los_memory
* @brief Print information about all pools.
*
* @par Description:
* This API is used to print information about all pools.
*
* @attention This function is defined only when LOSCFG_MEM_MUL_POOL is defined.
*
* @param None.
*
* @retval #UINT32 The pool number.
* @par Dependency:
* <ul>
* <li>los_memory.h: the header file that contains the API declaration.</li>
* </ul>
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemPoolList(VOID);
#endif
/**
* @ingroup los_memory
* Memory pool extern information structure
*/
typedef struct {
UINT32 uwTotalUsedSize;
UINT32 uwTotalFreeSize;
UINT32 uwMaxFreeNodeSize;
UINT32 uwUsedNodeNum;
UINT32 uwFreeNodeNum;
#ifdef LOSCFG_MEM_TASK_STAT
UINT32 uwUsageWaterLine; /**< this structure member is defined only when LOSCFG_MEM_TASK_STAT is defined. */
#endif
} LOS_MEM_POOL_STATUS;
/*uwTotalUsedSize内存池中已使用的总大小单位字节
uwTotalFreeSize使
uwMaxFreeNodeSize
uwUsedNodeNum使
uwFreeNodeNum使
uwUsageWaterLine LOSCFG_MEM_TASK_STAT 使线使
使使使
LOSCFG_MEM_TASK_STAT使线*/
/**
* @ingroup los_memory
* @brief Initialize dynamic memory.
*
* @par Description:
* This API is used to initialize the dynamic memory of a doubly linked list.
* @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 OS_MEM_ALIGN_SIZE 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 #LOS_NOK 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>
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemInit(VOID *pool, UINT32 size);
/*调用该函数将会对指定的内存池进行初始化操作,使其具备可用于分配和管理内存块的能力。
*/
/**
* @ingroup los_memory
* @brief Allocate dynamic memory.
*
* @par Description:
* This API is used to allocate a memory block of which the size is specified.
* @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, and the API returns the pointer to
* the allocated memory block.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MemRealloc | LOS_MemAllocAlign | LOS_MemFree
* @since Huawei LiteOS V100R001C00
*/
extern VOID *LOS_MemAlloc(VOID *pool, UINT32 size);
/*通过该函数可以动态地从内存池中获取一块指定大小的内存块,以满足程序运行时的内存需求。分配的内存块可以根据实际需要进行读写操作
*/
/**
* @ingroup los_memory
* @brief Free dynamic memory.
*
* @par Description:
* This API is used to free specified dynamic memory that has been allocated.
* @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
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemFree(VOID *pool, VOID *ptr);
/**
* @ingroup los_memory
* @brief Re-allocate a memory block.
*
* @par Description:
* 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.
* @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; if the ptr is allocated by LOS_MemAllocAlign,
* the alignment of the newly allocated memory address cannot be guaranteed to be consistent with the original
* memory address.</li>
* <li>The input size parameter can not be greater than the memory pool size that specified at the second
* input parameter of LOS_MemInit.</li>
* <li>The input size parameter 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>
* <li> If the user has special requirements for address alignment, it is not recommended to use this realloc function
* for address allocated by LOS_MemAllocAlign. For example, on a 32-bit system, LiteOS's default address alignment
* is 4 bytes, and if the boundary specified in LOS_MemAllocAlign is 8 bytes, it is cannot be ensured that the
* reallocated address is 8 bytes aligned.</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, and the API returns the pointer to the new memory block.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MemAlloc | LOS_MemAllocAlign | LOS_MemFree
* @since Huawei LiteOS V100R001C00
*/
extern VOID *LOS_MemRealloc(VOID *pool, VOID *ptr, UINT32 size);
//通过该函数可以动态地调整已分配内存块的大小,以满足程序运行时动态变化的内存需求。
/**
* @ingroup los_memory
* @brief Allocate aligned memory.
*
* @par Description:
* This API is used to allocate memory blocks of specified size and of which the starting addresses are aligned on
* a specified boundary.
* @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, and the API returns the pointer to the allocated memory.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MemAlloc | LOS_MemRealloc | LOS_MemFree
* @since Huawei LiteOS V100R001C00
*/
extern VOID *LOS_MemAllocAlign(VOID *pool, UINT32 size, UINT32 boundary);
/*通过该函数可以动态地从内存池中获取一块指定大小并满足对齐要求的内存块,
*/
/**
* @ingroup los_memory
* @brief Get the size of memory pool's size.
*
* @par Description:
* This API is used to get the size of memory pool' total size.
* @attention
* The input pool parameter must be initialized via func LOS_MemInit.
*
* @param pool [IN] A pointer pointed to the memory pool.
*
* @retval #LOS_NOK The input 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>
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemPoolSizeGet(const VOID *pool);
/**
* @ingroup los_memory
* @brief Get the size of memory totally used.
*
* @par Description:
* This API is used to get the size of memory totally used in memory pool.
* @attention
* The input pool parameter must be initialized via func LOS_MemInit.
*
* @param pool [IN] A pointer pointed to the memory pool.
*
* @retval #LOS_NOK The input parameter pool is NULL.
* @retval #UINT32 The size of the used memory pool.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemTotalUsedGet(VOID *pool);
/**
* @ingroup los_memory
* @brief Get the number of free memory nodes.
*
* @par Description:
* This API is used to get the number of free memory nodes in memory pool.
* @attention
* The input pool parameter must be initialized via func LOS_MemInit.
*
* @param pool [IN] A pointer pointed to the memory pool.
*
* @retval #LOS_NOK The input parameter pool is NULL.
* @retval #UINT32 The number of free memory nodes.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemFreeBlksGet(VOID *pool);
/**
* @ingroup los_memory
* @brief Get the number of used memory nodes.
*
* @par Description:
* This API is used to get the number of used memory nodes in memory pool.
* @attention
* The input pool parameter must be initialized via func LOS_MemInit.
*
* @param pool [IN] A pointer pointed to the memory pool.
*
* @retval #LOS_NOK The input parameter pool is NULL.
* @retval #UINT32 The number of used memory nodes.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemUsedBlksGet(VOID *pool);
/**
* @ingroup los_memory
* @brief Get the task ID of a used memory node.
*
* @par Description:
* This API is used to get the task ID of a used memory node.
* @attention
* <ul>
* <li>The input ptr parameter must be allocated by LOS_MemAlloc or LOS_MemAllocAlign.</li>
* <li>This interface only support obtain the task ID of a used memory node which is allocated from the system memory
* pool (OS_SYS_MEM_ADDR) at present.</li>
* </ul>
*
* @param ptr [IN] A used memory node.
*
* @retval #OS_INVALID The input parameter ptr is illegal.
* @retval #UINT32 The task ID of used memory node ptr.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemTaskIdGet(const VOID *ptr);
/**
* @ingroup los_memory
* @brief Get the address of last node.
*
* @par Description:
* This API is used to get the address of last node.
* @attention
* <ul>
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
* <li>The last node of memory pool is not the end node.</li>
* </ul>
*
* @param pool [IN] A pointer pointed to the memory pool.
*
* @retval #LOS_NOK The input parameter pool is NULL.
* @retval #UINTPTR The pointer to the last used node.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @since Huawei LiteOS V100R001C00
*/
extern UINTPTR LOS_MemLastUsedGet(VOID *pool);
/**
* @ingroup los_memory
* @brief Get the information of memory pool.
*
* @par Description:
* This API is used to get the information of memory pool.
* @attention
* The input pool parameter must be initialized via func LOS_MemInit.
*
* @param pool [IN] A pointer pointed to the memory pool.
* @param poolStatus [OUT] A pointer for storage the pool status
*
* @retval #LOS_NOK The input parameter pool is NULL or invalid.
* @retval #LOS_OK Get memory information successfully.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus);
/*调用该函数将会获取指定内存池的状态信息,并将其保存到指定的 LOS_MEM_POOL_STATUS 结构体中。如果获取成功,返回 LOS_OK否则返回错误码。
使便*/
/**
* @ingroup los_memory
* @brief Get the number of free node in every size.
*
* @par Description:
* This API is used to print the number of free node in every size.
* @attention
* The input pool parameter must be initialized via func LOS_MemInit.
*
* @param pool [IN] A pointer pointed to the memory pool.
*
* @retval #LOS_NOK The input parameter pool is NULL.
* @retval #LOS_OK Print the number of free node in every size successfully.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemFreeNodeShow(VOID *pool);
/**
* @ingroup los_memory
* @brief Check the memory pool integrity.
*
* @par Description:
* This API is used to check the memory pool integrity.
* @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 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>
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemIntegrityCheck(VOID *pool);
#ifdef LOSCFG_BASE_MEM_NODE_SIZE_CHECK
/*调用该函数将会对指定的内存池进行完整性检查,以确保内存池中分配的内存块没有损坏或越界等问题。如果检查通过,返回 LOS_OK否则返回错误码。
#ifdef LOSCFG_BASE_MEM_NODE_SIZE_CHECK
*/
/**
* @ingroup los_memory
* @brief Check the size of the specified memory node.
*
* @par Description:
* This API is used to check the size of memory node.
* @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 function will be called by function specified, such as memset or memcpy.</li>
* <li>The feature can be enabled when you set the macro value of LOSCFG_BASE_MEM_NODE_SIZE_CHECK as YES.</li>
* <li>You had better set memory check level as LOS_MEM_CHECK_LEVEL_DISABLE when copy bin file.</li>
* </ul>
*
* @param pool [IN] A pointer pointed to the memory pool.
* @param ptr [IN] A pointer pointed to the source node.
* @param totalSize [OUT] A pointer to save total size, must point to valid memory.
* @param availSize [OUT] A pointer to save available size, must point to valid memory.
*
* @retval #LOS_ERRNO_MEMCHECK_DISABLED Memcheck function does not open.
* @retval #LOS_ERRNO_MEMCHECK_PARA_NULL The pool or ptr is NULL.
* @retval #LOS_ERRNO_MEMCHECK_OUTSIDE The ptr address is not in the reasonable range.
* @retval #LOS_ERRNO_MEMCHECK_NO_HEAD Can't find the control head node from ptr.
* @retval #LOS_ERRNO_MEMCHECK_WRONG_LEVEL The memory check level is illegal.
* @retval #LOS_OK Success to get total size and available size of the memory node (ptr).
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MemCheckLevelSet | LOS_MemCheckLevelGet
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemNodeSizeCheck(VOID *pool, VOID *ptr, UINT32 *totalSize, UINT32 *availSize);
/*调用该函数将会检查指定内存池中给定内存节点的大小,并将总大小和可用大小分别保存到指定的变量中。如果检查成功,返回 LOS_OK否则返回错误码。
使使*/
/**
* @ingroup los_memory
* @brief Set the memory check level.
*
* @par Description:
* This API is used to set the memory check level.
* @attention
* <ul>
* <li>There are three level you can set.</li>
* <li>The legal level are LOS_MEM_CHECK_LEVEL_LOW, LOS_MEM_CHECK_LEVEL_HIGH, LOS_MEM_CHECK_LEVEL_DISABLE.</li>
* </ul>
*
* @param checkLevel [IN] The level what you want to set.
*
* @retval #LOS_ERRNO_MEMCHECK_WRONG_LEVEL The input memory check level is illegal.
* @retval #LOS_OK Set the memory check level successfully.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MemNodeSizeCheck | LOS_MemCheckLevelGet
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MemCheckLevelSet(UINT8 checkLevel);
/**
* @ingroup los_memory
* @brief Get the memory check level.
*
* @par Description:
* This API is used to get the current memory check level.
* @attention None.
*
* @param None.
*
* @retval #UINT8 The current memory check level.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MemNodeSizeCheck | LOS_MemCheckLevelSet
* @since Huawei LiteOS V100R001C00
*/
extern UINT8 LOS_MemCheckLevelGet(VOID);
#endif
/**
* @ingroup los_memory
* Define a mem size check intensity
*
* Lowest mem check.
*/
#define LOS_MEM_CHECK_LEVEL_LOW 0
/**
* @ingroup los_memory
* Define a mem size check intensity
*
* Highest mem check.
*/
#define LOS_MEM_CHECK_LEVEL_HIGH 1
/**
* @ingroup los_memory
* Define a mem size check intensity
*
* disable mem check.
*/
#define LOS_MEM_CHECK_LEVEL_DISABLE 0xff
/**
* @ingroup los_memory
* Define a mem size check intensity.
*
* default intensity set mem check.
*/
#define LOS_MEM_CHECK_LEVEL_DEFAULT LOS_MEM_CHECK_LEVEL_DISABLE
/**
* @ingroup los_memory
* memcheck error code: the pointer or pool is NULL.
*
* Value: 0x02000101.
*
* Solution: don't give a NULL parameter.
*/
#define LOS_ERRNO_MEMCHECK_PARA_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x1)
/**
* @ingroup los_memory
* memcheck error code: the pointer address is not in the suitable range.
*
* Value: 0x02000102.
*
* Solution: check pointer and comfirm it is in stack.
*/
#define LOS_ERRNO_MEMCHECK_OUTSIDE LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x2)
/**
* @ingroup los_memory
* memcheck error code: can't find the control node.
*
* Value: 0x02000103.
*
* Solution: check if the node which the pointer points to has been freed or not been allocated.
*/
#define LOS_ERRNO_MEMCHECK_NO_HEAD LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x3)
/**
* @ingroup los_memory
* memcheck error code: the memcheck level is wrong.
*
* Value: 0x02000104.
*
* Solution: check the memcheck level by the function "LOS_MemCheckLevelGet".
*/
#define LOS_ERRNO_MEMCHECK_WRONG_LEVEL LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x4)
/**
* @ingroup los_memory
* memcheck error code: memcheck function is not enable.
*
* Value: 0x02000105.
*
* Solution: enable memcheck by the function "LOS_MemCheckLevelSet".
*/
#define LOS_ERRNO_MEMCHECK_DISABLED LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x5)
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_MEMORY_H */

@ -0,0 +1,319 @@
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved.
* Description: Mutex
* Author: Huawei LiteOS Team
* Create: 2013-01-01
* 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_base.h"
#include "los_sys.h"
#include "los_list.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)
/*这段代码定义了一个名为 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)
//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)
//这段代码定义了一个名为 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)
/*这段代码定义了一个名为 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)
/*这段代码定义了一个名为 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_PEND_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x05)
/*这段代码定义了一个名为 LOS_ERRNO_MUX_PEND_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)
/*这段代码定义了一个名为 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)
//LOS_ERRNO_OS_ERROR 是一个宏用于生成具有模块和错误码的错误码值。在这里LOS_MOD_MUX 表示错误所属的模块是互斥锁模块0x07 是该错误码在该模块中的具体数值。
/**
* @ingroup los_mux
* The error code is not in use temporarily.
*
* Value: 0x02001d08
* @deprecated This error code is obsolete since LiteOS 5.0.0.
*/
#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
* The error code is not in use temporarily.
*
* Value: 0x02001d0A
* @deprecated This error code is obsolete since LiteOS 5.0.0.
*/
#define LOS_ERRNO_MUX_GET_COUNT_ERR LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0A)
/**
* @ingroup los_mux
* The error code is not in use temporarily.
*
* Value: 0x02001d0B
* @deprecated This error code is obsolete since LiteOS 5.0.0.
*/
#define LOS_ERRNO_MUX_REG_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0B)
/**
* @ingroup los_mux
* Mutex error code: The mutex is being locked in system-level task.
* old usage: The mutex is being locked in software timer task(LOS_ERRNO_MUX_PEND_IN_SWTMR_TSK).
*
* Value: 0x02001d0C.
*
* Solution: Pend the mutex in a vailid task.
* @deprecated This error code is obsolete since LiteOS 5.0.0.
*/
#define LOS_ERRNO_MUX_PEND_IN_SYSTEM_TASK LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0C)
/*其中 LOS_ERRNO_OS_ERROR 是一个宏函数,用于生成错误码。该宏函数接受两个参数:模块号和错误码。在这里,模块号为 LOS_MOD_MUX错误码为 0x0C。
便使*/
/**
* @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 when creating is successful, return specific error code otherwise.
* @attention
* The total number of mutexes is pre-configured. If there are no available mutexes, the mutex creation will fail.
*
* @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
* @since Huawei LiteOS V100R001C00
*/
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 if the mutex deletion is successfully,
* otherwise return specific error code.
* @attention
* <ul>
* <li>The specific mutex should be created firstly.</li>
* <li>The mutex can be deleted successfully only when there is no other tasks pend on it.</li>
* </ul>
*
* @param muxHandle [IN] The mutex handle 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
* @since Huawei LiteOS V100R001C00
*/
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>
* <li>Do not recommend to use this API in software timer callback. </li>
* </ul>
*
* @param muxHandle [IN] The mutex handle to be waited for. 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_PEND_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
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout);
/*参数说明:
muxHandle
timeout0
LOS_OK
*/
/**
* @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] The mutex handle 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_PEND_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
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_MuxPost(UINT32 muxHandle);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* _LOS_MUX_H */

@ -0,0 +1,501 @@
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2020. All rights reserved.
* Description: LiteOS Performance Monitor Module Implementation
* Author: Huawei LiteOS Team
* Create: 2017-01-01
* 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_perf Perf
* @ingroup kernel
*/
#ifndef _LOS_PERF_H
#define _LOS_PERF_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_perf
* Perf max sample filter task number.
*/
#define PERF_MAX_FILTER_TSKS 32
/**
* @ingroup los_perf
* Perf max sample event counter's number.
*/
#define PERF_MAX_EVENT 7
/**
* @ingroup los_perf
* Perf max backtrace depth.
*/
#define PERF_MAX_CALLCHAIN_DEPTH 10
/**
* @ingroup los_perf
* Perf sample data buffer's water mark 1/N.
*/
#define PERF_BUFFER_WATERMARK_ONE_N 2
/**
* @ingroup los_perf
* Perf state.
*/
enum PerfStatus {
PERF_UNINIT, /**< perf isn't inited */
PERF_STARTED, /**< perf is started */
PERF_STOPED, /**< perf is stopped */
};
/*枚举类型 PerfStatus 包含了三个枚举常量:
PERF_UNINIT
PERF_STARTED
PERF_STOPED
使便*/
/**
* @ingroup los_perf
* Define the type of the perf sample data buffer water mark hook function.
*
*/
typedef VOID (*PERF_BUF_NOTIFY_HOOK)(VOID);
/**
* @ingroup los_perf
* Define the type of the perf sample data buffer flush hook function.
*
*/
typedef VOID (*PERF_BUF_FLUSH_HOOK)(VOID *addr, UINT32 size);
/**
* @ingroup los_perf
* Perf error code: Bad status.
*
* Value: 0x02002000
*
* Solution: Follow the perf state machine.
*/
#define LOS_ERRNO_PERF_STATUS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_PERF, 0x00)
/**
* @ingroup los_perf
* Perf error code: Hardware pmu init failed.
*
* Value: 0x02002001
*
* Solution: Check the pmu hwi irq.
*/
#define LOS_ERRNO_PERF_HW_INIT_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_PERF, 0x01)
/**
* @ingroup los_perf
* Perf error code: Hrtimer init failed for hrtimer timed pmu init.
*
* Value: 0x02002002
*
* Solution: Check the Hrtimer init.
*/
#define LOS_ERRNO_PERF_TIMED_INIT_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_PERF, 0x02)
/**
* @ingroup los_perf
* Perf error code: Software pmu init failed.
*
* Value: 0x02002003
*
* Solution: Check the Perf software events init.
*/
#define LOS_ERRNO_PERF_SW_INIT_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_PERF, 0x03)
/**
* @ingroup los_perf
* Perf error code: Perf buffer init failed.
*
* Value: 0x02002004
*
* Solution: Check the buffer init size.
*/
#define LOS_ERRNO_PERF_BUF_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_PERF, 0x04)
/**
* @ingroup los_perf
* Perf error code: Perf pmu type error.
*
* Value: 0x02002005
*
* Solution: Check whether the corresponding pmu is enabled in the menuconfig.
*/
#define LOS_ERRNO_PERF_INVALID_PMU LOS_ERRNO_OS_ERROR(LOS_MOD_PERF, 0x05)
/**
* @ingroup los_perf
* Perf error code: Perf pmu config error.
*
* Value: 0x02002006
*
* Solution: Check the config attr of event id and event period.
*/
#define LOS_ERRNO_PERF_PMU_CONFIG_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_PERF, 0x06)
/**
* @ingroup los_perf
* Perf error code: Perf pmu config attr is null.
*
* Value: 0x02002007
*
* Solution: Check if the input params of attr is null.
*/
#define LOS_ERRNO_PERF_CONFIG_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_PERF, 0x07)
/**
* @ingroup los_perf
* Perf types
*/
enum PerfEventType {
PERF_EVENT_TYPE_HW, /**< boards common hw events */
PERF_EVENT_TYPE_TIMED, /**< hrtimer timed events */
PERF_EVENT_TYPE_SW, /**< software trace events */
PERF_EVENT_TYPE_RAW, /**< boards special hw events, see enum PmuEventType in corresponding arch headfile */
PERF_EVENT_TYPE_MAX
};
/*枚举类型 PerfEventType 包含了四个枚举常量:
PERF_EVENT_TYPE_HW
PERF_EVENT_TYPE_TIMED
PERF_EVENT_TYPE_SW
PERF_EVENT_TYPE_RAW PmuEventType
使便便*/
/**
* @ingroup los_perf
* Common hardware pmu events
*/
enum PmuHwId {
PERF_COUNT_HW_CPU_CYCLES = 0, /**< cpu cycle event */
PERF_COUNT_HW_INSTRUCTIONS, /**< instruction event */
PERF_COUNT_HW_DCACHE_REFERENCES, /**< dcache access event */
PERF_COUNT_HW_DCACHE_MISSES, /**< dcache miss event */
PERF_COUNT_HW_ICACHE_REFERENCES, /**< icache access event */
PERF_COUNT_HW_ICACHE_MISSES, /**< icache miss event */
PERF_COUNT_HW_BRANCH_INSTRUCTIONS, /**< software change of pc event */
PERF_COUNT_HW_BRANCH_MISSES, /**< branch miss event */
PERF_COUNT_HW_MAX,
};
/*枚举类型 PmuHwId 包含了多个枚举常量,每个常量代表一个具体的硬件事件:
PERF_COUNT_HW_CPU_CYCLES CPU
PERF_COUNT_HW_INSTRUCTIONS
PERF_COUNT_HW_DCACHE_REFERENCES访
PERF_COUNT_HW_DCACHE_MISSES
PERF_COUNT_HW_ICACHE_REFERENCES访
PERF_COUNT_HW_ICACHE_MISSES
PERF_COUNT_HW_BRANCH_INSTRUCTIONS
PERF_COUNT_HW_BRANCH_MISSES
使便*/
/**
* @ingroup los_perf
* Common hrtimer timed events
*/
enum PmuTimedId {
PERF_COUNT_CPU_CLOCK = 0, /**< hrtimer timed event */
};
/**
* @ingroup los_perf
* Common software pmu events
*/
enum PmuSwId {
PERF_COUNT_SW_TASK_SWITCH = 1, /**< task switch event */
PERF_COUNT_SW_IRQ_RESPONSE, /**< irq response event */
PERF_COUNT_SW_MEM_ALLOC, /**< memory alloc event */
PERF_COUNT_SW_MUX_PEND, /**< mutex pend event */
PERF_COUNT_SW_MAX,
};
/*枚举类型 PmuSwId 包含了多个枚举常量,每个常量代表一个具体的软件事件:
PERF_COUNT_SW_TASK_SWITCH
PERF_COUNT_SW_IRQ_RESPONSE
PERF_COUNT_SW_MEM_ALLOC
PERF_COUNT_SW_MUX_PEND
使便*/
/**
* @ingroup los_perf
* perf sample data types
* Config it through PerfConfigAttr->sampleType.
*/
enum PerfSampleType {
PERF_RECORD_CPU = 1U << 0, /**< record current cpuid */
PERF_RECORD_TID = 1U << 1, /**< record current task id */
PERF_RECORD_TYPE = 1U << 2, /**< record event type */
PERF_RECORD_PERIOD = 1U << 3, /**< record event period */
PERF_RECORD_TIMESTAMP = 1U << 4, /**< record timestamp */
PERF_RECORD_IP = 1U << 5, /**< record instruction pointer */
PERF_RECORD_CALLCHAIN = 1U << 6, /**< record backtrace */
};
/*枚举类型 PerfSampleType 包含了多个枚举常量,每个常量代表一个具体的采样数据类型:
PERF_RECORD_CPU CPU ID
PERF_RECORD_TID ID
PERF_RECORD_TYPE
PERF_RECORD_PERIOD
PERF_RECORD_TIMESTAMP
PERF_RECORD_IP
PERF_RECORD_CALLCHAIN
使便便*/
/**
* @ingroup los_perf
* perf configuration sub event information
*
* This structure is used to config specific events attributes.
*/
typedef struct {
UINT32 type; /**< enum PerfEventType */
struct {
UINT32 eventId; /**< the specific event corresponds to the PerfEventType */
UINT32 period; /**< event period, for every "period"th occurrence of the event a
sample will be recorded */
} events[PERF_MAX_EVENT]; /**< perf event list */
UINT32 eventsNr; /**< total perf event number */
BOOL predivided; /**< whether to prescaler (once every 64 counts),
which only take effect on cpu cycle hardware event */
} PerfEventConfig;
/*type表示性能事件类型是一个 UINT32 类型的值,对应于 PerfEventType 枚举。
events
eventId UINT32
period UINT32
eventsNr UINT32
predivided64CPU BOOL */
/**
* @ingroup los_perf
* perf configuration main information
*
* This structure is used to set perf sampling attributes, including events, tasks and other information.
*/
typedef struct {
PerfEventConfig eventsCfg; /**< perf event config */
UINT32 taskIds[PERF_MAX_FILTER_TSKS]; /**< perf task filter list (whitelist) */
UINT32 taskIdsNr; /**< task numbers of task filter whiltelist,
if set 0 perf will sample all tasks */
UINT32 sampleType; /**< type of data to sample defined in PerfSampleType */
BOOL needSample; /**< whether to sample data */
BOOL taskFilterEnable; /**< whether to filter tasks */
} PerfConfigAttr;
extern VOID OsPerfHook(UINT32 event);
#if defined(LOSCFG_KERNEL_PERF) && defined(LOSCFG_PERF_SW_PMU)
#define LOS_PERF(EVENT) do { \
OsPerfHook(EVENT); \
} while (0)
#else
#define LOS_PERF(EVENT)
#endif
/*PerfConfigAttr 结构体包含以下成员变量:
eventsCfg PerfEventConfig
taskIds ID UINT32 PERF_MAX_FILTER_TSKS ID
taskIdsNr ID UINT32
sampleType UINT32 PerfSampleType
needSample BOOL
taskFilterEnable BOOL
OsPerfHook UINT32 event
LOS_PERF LOSCFG_KERNEL_PERF LOSCFG_PERF_SW_PMU OsPerfHook */
/**
* @ingroup los_perf
* @brief Init perf.
*
* @par Description:
* <ul>
* <li>Used to initialize the perf module, including initializing the PMU, allocating memory,
* etc.,which is called during the phase of system initialization.</li>
* </ul>
* @attention
* <ul>
* <li>If buf is not null, user must ensure size is not bigger than buf's length.</li>
* </ul>
*
* @param buf [IN] Pointer of sample data buffer;Use the dynamically allocated memory if the pointer is NULL.
* @param size [IN] Length of sample data buffer;
*
* @retval #LOS_ERRNO_PERF_STATUS_INVALID Perf in a wrong status.
* @retval #LOS_ERRNO_PERF_HW_INIT_ERROR Perf hardware pmu init fail.
* @retval #LOS_ERRNO_PERF_TIMED_INIT_ERROR Perf timed pmu init fail.
* @retval #LOS_ERRNO_PERF_SW_INIT_ERROR Perf software pmu init fail.
* @retval #LOS_ERRNO_PERF_BUF_ERROR Perf buffer init fail.
* @retval #LOS_OK Perf init success.
* @par Dependency:
* <ul>
* <li>los_perf.h: the header file that contains the API declaration.</li>
* </ul>
* @since Huawei LiteOS V200R005C00
*/
UINT32 LOS_PerfInit(VOID *buf, UINT32 size);
/**
* @ingroup los_perf
* @brief Start perf sampling.
*
* @par Description
* Start perf sampling.
* @attention
* None.
*
* @param sectionId [IN] Set the section id for marking this piece of data in the perf sample data buffer.
* @retval None.
* @par Dependency:
* <ul>
* <li>los_perf.h: the header file that contains the API declaration.</li>
* </ul>
* @since Huawei LiteOS V200R005C00
*/
VOID LOS_PerfStart(UINT32 sectionId);
/**
* @ingroup los_perf
* @brief Stop perf sampling.
*
* @par Description
* Stop perf sampling.
* @attention
* None.
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul>
* <li>los_perf.h: the header file that contains the API declaration.</li>
* </ul>
* @since Huawei LiteOS V200R005C00
*/
VOID LOS_PerfStop(VOID);
/**
* @ingroup los_perf
* @brief Config perf parameters.
*
* @par Description
* Config perf parameters before sample, for example, sample event, sample task, etc. it need to be called
* before LOS_PerfStart.
* @attention
* None.
*
* @param attr [IN] Address of a perf event attr struct.
*
* @retval #LOS_ERRNO_PERF_STATUS_INVALID Perf in a wrong status.
* @retval #LOS_ERRNO_PERF_CONFIG_NULL Attr is null.
* @retval #LOS_ERRNO_PERF_INVALID_PMU Config perf pmu with error type.
* @retval #LOS_ERRNO_PERF_PMU_CONFIG_ERROR Config perf events fail with invaild event id or event period.
* @retval #LOS_OK Config success.
* @par Dependency:
* <ul>
* <li>los_perf.h: the header file that contains the API declaration.</li>
* </ul>
* @since Huawei LiteOS V200R005C00
*/
UINT32 LOS_PerfConfig(PerfConfigAttr *attr);
/**
* @ingroup los_perf
* @brief Read data from perf sample data buffer.
*
* @par Description
* Because perf sample data buffer is a ringbuffer, the data may be covered after user read ringbuffer.
* @attention
* None.
*
* @param dest [IN] The destionation address.
* @param size [IN] Read size.
* @retval #UINT32 The really read bytes.
* @par Dependency:
* <ul>
* <li>los_perf.h: the header file that contains the API declaration.</li>
* </ul>
* @since Huawei LiteOS V200R005C00
*/
UINT32 LOS_PerfDataRead(CHAR *dest, UINT32 size);
/**
* @ingroup los_perf
* @brief Register perf sample data buffer water mark hook function.
*
* @par Description
* <ul>
* <li> Register perf sample data buffer water mark hook function.</li>
* <li> The registered hook will be called when buffer reaches the water mark./li>
* </ul>
* @attention
* None.
*
* @param func [IN] Buffer water mark hook function.
*
* @retval None.
* @par Dependency:
* <ul>
* <li>los_perf.h: the header file that contains the API declaration.</li>
* </ul>
* @since Huawei LiteOS V200R005C00
*/
VOID LOS_PerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func);
/**
* @ingroup los_perf
* @brief Register perf sample data buffer flush hook function.
*
* @par Description
* <ul>
* <li> Register perf sample data buffer flush hook function.</li>
* <li> The flush hook will be called when the buffer be read or written.</li>
* </ul>
* @attention
* None.
*
* @param func [IN] Buffer flush hook function.
*
* @retval None.
* @par Dependency:
* <ul>
* <li>los_perf.h: the header file that contains the API declaration.</li>
* </ul>
* @since Huawei LiteOS V200R005C00
*/
VOID LOS_PerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_PERF_H */

@ -0,0 +1,408 @@
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2013-2020. All rights reserved.
* Description: Los_printf HeadFile
* Author: Huawei LiteOS Team
* Create: 2013-01-01
* 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_printf Printf
* @ingroup kernel
*/
#ifndef _LOS_PRINTF_H
#define _LOS_PRINTF_H
#include "stdarg.h"
#include "los_config.h"
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_SHELL_LK
extern void LOS_LkPrint(int level, const char *func, int line, const char *fmt, ...);
#endif
/*LOS_LkPrint 函数接受以下参数:
level
func
line
fmt
...
*/
/**
* @ingroup los_printf
* log print level definition, LOS_EMG_LEVEL is set to 0, it means the log is emergency.
*/
#define LOS_EMG_LEVEL 0
/**
* @ingroup los_printf
* log print level definition, LOS_COMMOM_LEVEL is set to 1, it means the log is common.
*/
#define LOS_COMMOM_LEVEL (LOS_EMG_LEVEL + 1)
/**
* @ingroup los_printf
* log print level definition, LOS_ERR_LEVEL is set to 2, it means it is a error log.
*/
#define LOS_ERR_LEVEL (LOS_COMMOM_LEVEL + 1)
/**
* @ingroup los_printf
* log print level definition, LOS_WARN_LEVEL is set to 3, it means it is a warning log.
*/
#define LOS_WARN_LEVEL (LOS_ERR_LEVEL + 1)
/**
* @ingroup los_printf
* log print level definition, LOS_INFO_LEVEL is set to 4, it means the log is an information.
*/
#define LOS_INFO_LEVEL (LOS_WARN_LEVEL + 1)
/**
* @ingroup los_printf
* log print level definition, LOS_DEBUG_LEVEL is set to 5, it means it is a debug log.
*/
#define LOS_DEBUG_LEVEL (LOS_INFO_LEVEL + 1)
/**
* @ingroup los_printf
* The default log print level. PRINT_LEVEL is set to debug log level if
* LOSCFG_SHELL_LK is defined, otherwise PRINT_LEVEL is set to error log level.
* The default log print level means only print the log which its level value
* is lower than or equal to the PRINT_LEVEL.
*/
#ifdef LOSCFG_SHELL_LK
#define PRINT_LEVEL LOS_DEBUG_LEVEL
#else
#define PRINT_LEVEL LOS_ERR_LEVEL
#endif
typedef VOID (*pf_OUTPUT)(const CHAR *fmt, ...);
/*这段代码定义了一个名为 PRINT_LEVEL 的宏以及一个名为 pf_OUTPUT 的函数指针类型。
PRINT_LEVEL LOS_DEBUG_LEVEL LOS_ERR_LEVEL
LOSCFG_SHELL_LK PRINT_LEVEL LOS_DEBUG_LEVEL
PRINT_LEVEL LOS_ERR_LEVEL
pf_OUTPUT VOID
fmt ...使*/
/**
* @ingroup los_printf
* @brief Format and print data.
*
* @par Description:
* Print argument(s) according to fmt.
*
* @attention
* None.
*
* @param fmt [IN] Type char*. It controls the ouput format as in C printf.
*
* @retval None.
* @par Dependency:
* <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul>
* @see printf
* @since Huawei LiteOS V100R001C00
*/
extern void dprintf(const char *fmt, ...);
#define diag_printf dprintf
/**
* @ingroup los_printf
* @brief Format and print debug log.
*
* @par Description:
* Define function macros PRINT_DEBUG. The Function can print debug log according to fmt
* when the PRINT_LEVEL is set to LOS_DEBUG_LEVEL.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul>
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINT_DEBUG
#if PRINT_LEVEL < LOS_DEBUG_LEVEL
#define PRINT_DEBUG(fmt, ...)
#else
#ifdef LOSCFG_SHELL_LK
#define PRINT_DEBUG(fmt, ...) LOS_LkPrint(LOS_DEBUG_LEVEL, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#else
#define PRINT_DEBUG(fmt, ...) do { \
(dprintf("[DEBUG] "), dprintf(fmt, ##__VA_ARGS__)); \
} while (0)
#endif
#endif
#endif
/*当宏 PRINT_DEBUG 未被定义时,通过条件编译判断 PRINT_LEVEL 是否小于 LOS_DEBUG_LEVEL。如果是则将 PRINT_DEBUG 宏定义为空操作;否则,进入下一层条件编译。
LOSCFG_SHELL_LK PRINT_DEBUG LOS_LkPrint
[DEBUG] LOS_DEBUG_LEVEL
__FUNCTION__ __LINE__
fmt ...
PRINT_DEBUG [DEBUG] */
/**
* @ingroup los_printf
* @brief Format and print information log.
*
* @par Description:
* Define function macros PRINT_INFO. The Function can print information log according to fmt
* when the PRINT_LEVEL is greater than or equal to LOS_INFO_LEVEL.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul>
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINT_INFO
#if PRINT_LEVEL < LOS_INFO_LEVEL
#define PRINT_INFO(fmt, ...)
#else
#ifdef LOSCFG_SHELL_LK
#define PRINT_INFO(fmt, ...) LOS_LkPrint(LOS_INFO_LEVEL, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#else
#define PRINT_INFO(fmt, ...) do { \
(dprintf("[INFO] "), dprintf(fmt, ##__VA_ARGS__)); \
} while (0)
#endif
#endif
#endif
/*当宏 PRINT_INFO 未被定义时,通过条件编译判断 PRINT_LEVEL 是否小于 LOS_INFO_LEVEL。
PRINT_INFO
LOSCFG_SHELL_LK PRINT_INFO LOS_LkPrint
[INFO] LOS_INFO_LEVEL
__FUNCTION__ __LINE__
fmt ...
PRINT_INFO [INFO] */
/**
* @ingroup los_printf
* @brief Format and print warning log.
*
* @par Description:
* Define function macros PRINT_WARN. The Function can print warning log according to fmt
* when the PRINT_LEVEL is greater than or equal to LOS_WARN_LEVEL.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul>
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINT_WARN
#if PRINT_LEVEL < LOS_WARN_LEVEL
#define PRINT_WARN(fmt, ...)
#else
#ifdef LOSCFG_SHELL_LK
#define PRINT_WARN(fmt, ...) LOS_LkPrint(LOS_WARN_LEVEL, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#else
#define PRINT_WARN(fmt, ...) do { \
(dprintf("[WARN] "), dprintf(fmt, ##__VA_ARGS__)); \
} while (0)
#endif
#endif
#endif
/*当宏 PRINT_WARN 未被定义时,通过条件编译判断 PRINT_LEVEL 是否小于 LOS_WARN_LEVEL。如果是则将 PRINT_WARN 宏定义为空操作;否则,进入下一层条件编译。
LOSCFG_SHELL_LK PRINT_WARN LOS_LkPrint
[WARN] LOS_WARN_LEVEL
__FUNCTION__ __LINE__
fmt ...
PRINT_WARN [WARN] */
/**
* @ingroup los_printf
* @brief Format and print error log.
*
* @par Description:
* Define function macros PRINT_ERR. The Function can print error log according to fmt
* when the PRINT_LEVEL is greater than or equal to LOS_ERR_LEVEL.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul>
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINT_ERR
#if PRINT_LEVEL < LOS_ERR_LEVEL
#define PRINT_ERR(fmt, ...)
#else
#ifdef LOSCFG_SHELL_LK
#define PRINT_ERR(fmt, ...) LOS_LkPrint(LOS_ERR_LEVEL, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#else
#define PRINT_ERR(fmt, ...) do { \
(dprintf("[ERR] "), dprintf(fmt, ##__VA_ARGS__)); \
} while (0)
#endif
#endif
#endif
/*当宏 PRINT_ERR 未被定义时,通过条件编译判断 PRINT_LEVEL 是否小于 LOS_ERR_LEVEL。如果是则将 PRINT_ERR 宏定义为空操作;否则,进入下一层条件编译。
LOSCFG_SHELL_LK PRINT_ERR LOS_LkPrint
[ERR] LOS_ERR_LEVEL
__FUNCTION__ __LINE__
fmt ...
PRINT_ERR [ERR] */
/**
* @ingroup los_printf
* @brief Format and print common log.
*
* @par Description:
* Define function macros PRINTK. The Function can print common log according to fmt
* when the PRINT_LEVEL is greater than or equal to LOS_COMMOM_LEVEL.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul>
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINTK
#if PRINT_LEVEL < LOS_COMMOM_LEVEL
#define PRINTK(fmt, ...)
#else
#ifdef LOSCFG_SHELL_LK
#define PRINTK(fmt, ...) LOS_LkPrint(LOS_COMMOM_LEVEL, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#else
#define PRINTK(fmt, ...) dprintf(fmt, ##__VA_ARGS__)
#endif
#endif
#endif
/*这段代码定义了一个名为 PRINTK 的宏。
PRINTK PRINT_LEVEL LOS_COMMOM_LEVEL PRINTK
LOSCFG_SHELL_LK PRINTK LOS_LkPrint
[COMM] LOS_COMMOM_LEVEL
__FUNCTION__ __LINE__
fmt ...
PRINTK */
/**
* @ingroup los_printf
* @brief Format and print emergency log.
*
* @par Description:
* Define function macros PRINT_EMG. The Function can print emergency log according to fmt
* when the PRINT_LEVEL is greater than or equal to LOS_EMG_LEVEL.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul>
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINT_EMG
#if PRINT_LEVEL < LOS_EMG_LEVEL
#define PRINT_EMG(fmt, ...)
#else
#define PRINT_EMG(fmt, ...) do { \
(dprintf("[EMG] "), dprintf(fmt, ##__VA_ARGS__)); \
} while (0)
#endif
#endif
/*这段代码定义了一个名为 PRINT_EMG 的宏。
PRINT_EMG PRINT_LEVEL LOS_EMG_LEVEL PRINT_EMG
PRINT_LEVEL LOS_EMG_LEVEL PRINT_EMG [EMG] */
/**
* @ingroup los_printf
* @brief Format and print log.
*
* @par Description:
* Define function macros PRINT_RELEASE. The Function can print argument(s) according to fmt.
* It is same with dprintf function.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul>
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINT_RELEASE
#define PRINT_RELEASE(fmt, ...) dprintf(fmt, ##__VA_ARGS__)
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_PRINTF_H */

@ -0,0 +1,866 @@
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved.
* Description: Queue
* Author: Huawei LiteOS Team
* Create: 2013-01-01
* 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_base.h"
#include "los_list.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.
* @deprecated This error code is obsolete since LiteOS 5.0.0.
*/
#define LOS_ERRNO_QUEUE_MAXNUM_ZERO LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x00)
/*宏的定义使用了 LOS_ERRNO_OS_ERROR 宏,并指定了参数 LOS_MOD_QUE 和 0x00。根据上下文推测LOS_MOD_QUE 可能是表示与队列相关的模块。
*/
/**
* @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)
/*这段代码定义了一个名为 LOS_ERRNO_QUEUE_NO_MEMORY 的宏,用于表示队列分配内存失败时的错误码。
使 LOS_ERRNO_OS_ERROR LOS_MOD_QUE 0x01LOS_MOD_QUE
*/
/**
* @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)
/*这段代码定义了一个名为 LOS_ERRNO_QUEUE_CREATE_NO_MEMORY 的宏,用于表示创建队列时内存分配失败的错误码。
使 LOS_ERRNO_OS_ERROR LOS_MOD_QUE 0x02LOS_MOD_QUE
*/
/**
* @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)
/*宏的定义使用了 LOS_ERRNO_OS_ERROR 宏,并指定了参数 LOS_MOD_QUE 和 0x00。根据上下文推测LOS_MOD_QUE 可能是表示与队列相关的模块。
*/
/**
* @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)
/*这段代码定义了一个名为 LOS_ERRNO_QUEUE_NO_MEMORY 的宏,用于表示队列分配内存失败时的错误码。
使 LOS_ERRNO_OS_ERROR LOS_MOD_QUE 0x01LOS_MOD_QUE
*/
/**
* @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 too small or too big.
*
* Value: 0x02000610.
*
* Solution: Pass in a correct buffer size between [sizeof(CHAR*), OS_NULL_SHORT - sizeof(UINT32)].
*/
#define LOS_ERRNO_QUEUE_READSIZE_IS_INVALID 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
* Structure of the block for queue information query
*/
typedef struct tagQueueInfo {
UINT32 uwQueueID; /**< Queue ID */
UINT16 usQueueLen; /**< Queue length, that is the number of node in the queue */
UINT16 usQueueSize; /**< Node size in the queue */
UINT16 usQueueHead; /**< The position of queue header node, it is an array subscript */
UINT16 usQueueTail; /**< The position of queue tail node, it is an array subscript */
UINT16 usWritableCnt; /**< Count of writable resources */
UINT16 usReadableCnt; /**< Count of readable resources */
UINT64 uwWaitReadTask; /**< Tasks waiting for reading message. It is a 64-bit unsigned
integer, each bit represents a task ID. Therefore, 64 tasks
can be represented, and the maximum task ID is 63. For example,
0x0200060001002010 means there are 6 tasks whose IDs are 4,
13, 24, 41, 42, and 57. */
UINT64 uwWaitWriteTask; /**< Tasks waiting for writing message. It is a 64-bit unsigned
integer same with #uwWaitReadTask, each bit represents a task ID. */
UINT64 uwWaitMemTask; /**< Tasks waiting for memory used by the MailBox in the CMSIS-RTOS.
It is a 64-bit unsigned integer same with #uwWaitReadTask,
each bit represents a task ID. */
} QUEUE_INFO_S;
#ifdef LOSCFG_QUEUE_STATIC_ALLOCATION
/*这段代码定义了一个结构体 QUEUE_INFO_S用于描述队列Queue的信息。
uwQueueID ID
usQueueLen
usQueueSize
usQueueHead
usQueueTail
usWritableCnt
usReadableCnt
uwWaitReadTask 64 ID 64 ID 63
uwWaitWriteTask uwWaitReadTask
uwWaitMemTask uwWaitReadTask
LOSCFG_QUEUE_STATIC_ALLOCATION */
/**
* @ingroup los_queue
* @brief Create a message queue.
*
* @par Description:
* This API is used to create a message queue by transferring the static memory for the queue.
* The input parameter "queueMem" is the pointer to the static memory the API can use directly.
* The input parameter "memSize" is the static memory size.
* @attention
* <ul>
* <li>Threre are LOSCFG_BASE_IPC_QUEUE_LIMIT queues available, change it's value when necessory.</li>
* <li>This function is defined only when LOSCFG_QUEUE_STATIC_ALLOCATION is defined.</li>
* </ul>
* @param queueName [IN] Message queue name. Reserved parameter, not used for now.
* @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].
* @param queueMem [IN] Static queue memory. The value range is [0,0xffffffff].
* @param memSize [IN] Queue memory 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 | LOS_QueueCreate
* @since Huawei LiteOS V200R005C00
*/
extern UINT32 LOS_QueueCreateStatic(const CHAR *queueName,
UINT16 len,
UINT32 *queueId,
UINT32 flags,
UINT16 maxMsgSize,
VOID *queueMem,
UINT16 memSize);
#endif
/*该函数用于静态创建一个队列Queue具体参数如下
queueName const CHAR*
len UINT16
queueId UINT32 ID
flags UINT32
maxMsgSize UINT16
queueMem VOID*
memSize UINT16
ID*/
/**
* @ingroup los_queue
* @brief Create a message queue.
*
* @par Description:
* This API is used to create a message queue. Different from LOS_QueueCreateStatic,
* the user does not need to transfer the queue memory. In the API, system allocated
* the queue memory automatically.
* @attention
* There are LOSCFG_BASE_IPC_QUEUE_LIMIT queues available, change it's value when necessary.
* @param queueName [IN] Message queue name. Reserved parameter, not used for now.
* @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 usMaxMsgSize 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 | LOS_QueueCreateStatic
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_QueueCreate(const CHAR *queueName,
UINT16 len,
UINT32 *queueId,
UINT32 flags,
UINT16 maxMsgSize);
/*该函数用于动态创建一个队列Queue具体参数如下
queueName const CHAR*
len UINT16
queueId UINT32 ID
flags UINT32
maxMsgSize UINT16
ID*/
/**
* @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 Huawei LiteOS is initialized.</li>
* <li>The argument timeout is a relative time.</li>
* <li>Do not call this API in software timer callback. </li>
* </ul>
*
* @param queueId [IN] Queue ID created by LOS_QueueCreate or LOS_QueueCreateStatic.
* 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 wanted-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_IS_INVALID The buffer size passed in during queue reading is invalid.
* @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_QueueWriteHeadCopy | LOS_QueueCreate | LOS_QueueCreateStatic
* @since Huawei LiteOS V100R001C00
*/
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 Huawei LiteOS 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>
* <li>Do not call this API in software timer callback. </li>
* </ul>
*
* @param queueId [IN] Queue ID created by LOS_QueueCreate or LOS_QueueCreateStatic.
* 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_QueueWriteHeadCopy | LOS_QueueCreate | LOS_QueueCreateStatic
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_QueueWriteCopy(UINT32 queueId,
VOID *bufferAddr,
UINT32 bufferSize,
UINT32 timeout);
/*该函数用于向指定的队列中写入数据,具体参数如下:
queueId ID UINT32
bufferAddr VOID*
bufferSize UINT32
timeout Tick 0 LOS_WAIT_FOREVER UINT32
*/
/**
* @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 Huawei LiteOS 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>
* <li>Do not call this API in software timer callback. </li>
* </ul>
*
* @param queueId [IN] Queue ID created by LOS_QueueCreate or LOS_QueueCreateStatic.
* 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,The value range is
* [sizeof(CHAR*),OS_NULL_SHORT - sizeof(UINT32)].
* @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_IS_INVALID The buffer size passed in during queue reading is invalid.
* @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_QueueWriteHead | LOS_QueueCreate | LOS_QueueCreateStatic
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_QueueRead(UINT32 queueId,
VOID *bufferAddr,
UINT32 bufferSize,
UINT32 timeout);
/*该函数用于从指定的队列中读取数据,具体参数如下:
queueId ID UINT32
bufferAddr VOID*
bufferSize UINT32
timeout Tick 0 LOS_WAIT_FOREVER UINT32
*/
/**
* @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 Huawei LiteOS 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>
* <li>Do not call this API in software timer callback. </li>
* </ul>
*
* @param queueId [IN] Queue ID created by LOS_QueueCreate or LOS_QueueCreateStatic.
* 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] This parameter is not in use temporarily.
* @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_QueueWriteHead | LOS_QueueCreate | LOS_QueueCreateStatic
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_QueueWrite(UINT32 queueId,
VOID *bufferAddr,
UINT32 bufferSize,
UINT32 timeout);
/*该函数用于向指定的队列中写入数据,具体参数如下:
queueId ID UINT32
bufferAddr VOID*
bufferSize UINT32
timeout Tick 0 LOS_WAIT_FOREVER UINT32
*/
/**
* @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 Huawei LiteOS 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>
* <li>Do not call this API in software timer callback. </li>
* </ul>
*
* @param queueId [IN] Queue ID created by LOS_QueueCreate or LOS_QueueCreateStatic.
* 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] This parameter is not in use temporarily.
* @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. 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_QueueRead | LOS_QueueCreate | LOS_QueueCreateStatic
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_QueueWriteHead(UINT32 queueId,
VOID *bufferAddr,
UINT32 bufferSize,
UINT32 timeout);
/*该函数用于向指定队列的队首写入数据,具体参数如下:
queueId ID UINT32
bufferAddr VOID*
bufferSize UINT32
timeout Tick 0 LOS_WAIT_FOREVER UINT32
*/
/**
* @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 Huawei LiteOS 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>
* <li>Do not call this API in software timer callback. </li>
* </ul>
*
* @param queueId [IN] Queue ID created by LOS_QueueCreate or LOS_QueueCreateStatic.
* 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_QueueWriteCopy | LOS_QueueReadCopy
* @since Huawei LiteOS V100R001C00
*/
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 or LOS_QueueCreateStatic.
* The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
*
* @retval #LOS_OK The queue is successfully deleted.
* @retval #LOS_NOK Failed to release the queue memory.
* @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_QueueCreateStatic
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_QueueDelete(UINT32 queueId);
/**
* @ingroup los_queue
* @brief Obtain queue information.
*
* @par Description:
* This API is used to obtain queue information.
* @attention
* The specific queue should be created firstly before getting the queue information.
* @param queueId [IN] Queue ID created by LOS_QueueCreate or LOS_QueueCreateStatic.
* 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 | LOS_QueueCreateStatic
* @since Huawei LiteOS V100R001C00
*/
extern UINT32 LOS_QueueInfoGet(UINT32 queueId, QUEUE_INFO_S *queueInfo);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_QUEUE_H */

@ -0,0 +1,206 @@
/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2019-2019. All rights reserved.
* Description: Ring Buffer Public HeadFile
* Author: Huawei LiteOS Team
* Create: 2019-10-10
* 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_ringbuf RingBuffer
* @ingroup kernel
*/
#ifndef _LOS_RINGBUF_H
#define _LOS_RINGBUF_H
#include "los_typedef.h"
#include "los_spinlock.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_ringbuf
* Ringbuf Status.
*/
typedef enum {
RBUF_UNINIT, /**< Ringbuf is not inited. */
RBUF_INITED /**< Ringbuf is inited. */
} RingbufStatus;
/*这段代码定义了一个名为 RingbufStatus 的枚举类型,表示环形缓冲区的状态。
RBUF_UNINIT
RBUF_INITED
使便
使*/
/**
* @ingroup los_ringbuf
* Ringbuf information structure.
*
*/
typedef struct {
UINT32 startIdx; /**< Ringbuf read index */
UINT32 endIdx; /**< Ringbuf write index */
UINT32 size; /**< Ringbuf total size */
UINT32 remain; /**< Ringbuf free size */
SPIN_LOCK_S lock; /**< Lock for read and write */
RingbufStatus status; /**< Ringbuf status */
CHAR *fifo; /**< Buf to store data */
} Ringbuf;
/*这段代码定义了一个名为 Ringbuf 的结构体,用于表示环形缓冲区的属性和状态。
startIdx
endIdx
size
remain
lock
status RingbufStatus
fifo
便*/
/**
* @ingroup los_ringbuf
* @brief Init a ringbuf.
*
* @par Description:
* This API is used to init a ringbuf.
* @attention
* The size must not be bigger than the fifo's actual size.
*
* @param ringbuf [OUT] Ringbuf control block.
* @param fifo [IN] Data buf address.
* @param size [IN] Data buf size.
*
* @retval #LOS_NOK Init failed, check the legality of function parameters.
* @retval #LOS_OK Init success.
*
* @par Dependency:
* <ul><li>los_ringbuf.h: the header file that contains the API declaration.</li></ul>
* @see LOS_RingbufInit
* @since Huawei LiteOS V200R005C00
*/
extern UINT32 LOS_RingbufInit(Ringbuf *ringbuf, CHAR *fifo, UINT32 size);
/*该函数的作用是根据给定的参数初始化环形缓冲区对象,并分配必要的资源。通过调用这个函数,可以将一个已经定义的 Ringbuf
*/
/**
* @ingroup los_ringbuf
* @brief Reset a ringbuf.
*
* @par Description:
* This API is used to reset a ringbuf to the init status.
* @attention
* The specific ringbuf must be inited first.
*
* @param ringbuf [IN] Ringbuf created by LOS_RingbufInit.
*
* @retval None.
*
* @par Dependency:
* <ul><li>los_ringbuf.h: the header file that contains the API declaration.</li></ul>
* @see LOS_RingbufReset
* @since Huawei LiteOS V200R005C00
*/
extern VOID LOS_RingbufReset(Ringbuf *ringbuf);
/**
* @ingroup los_ringbuf
* @brief Write data to ringbuf.
*
* @par Description:
* This API is used to write data to ringbuf.
* @attention
* The specific ringbuf must be inited first.
*
* @param ringbuf [IN] The ringbuf write data to.
* @param buf [IN] The source buf address.
* @param size [IN] The source buf size.
*
* @retval #UINT32 The actual written size.
*
* @par Dependency:
* <ul><li>los_ringbuf.h: the header file that contains the API declaration.</li></ul>
* @see LOS_RingbufWrite
* @since Huawei LiteOS V200R005C00
*/
extern UINT32 LOS_RingbufWrite(Ringbuf *ringbuf, const CHAR *buf, UINT32 size);
/*该函数的作用是将指定大小的数据从源缓冲区写入到目标环形缓冲区中。写入操作会更新环形缓冲区的写入索引,并根据需要循环覆盖已有数据。如果环形缓冲区的空间不足以容纳全部数据,只会写入部分数据。
便*/
/**
* @ingroup los_ringbuf
* @brief Read data from ringbuf.
*
* @par Description:
* This API is used to get data from ringbuf.
* @attention
* The specific ringbuf must be inited first.
*
* @param ringbuf [IN] The ringbuf read data from.
* @param buf [OUT] The dest buf address.
* @param size [IN] The dest buf size.
*
* @retval #UINT32 The actual read size.
*
* @par Dependency:
* <ul><li>los_ring.h: the header file that contains the API declaration.</li></ul>
* @see LOS_RingbufRead
* @since Huawei LiteOS V200R005C00
*/
extern UINT32 LOS_RingbufRead(Ringbuf *ringbuf, CHAR *buf, UINT32 size);
/*该函数的作用是从指定大小的数据中读取数据,并将其存储到目标缓冲区。读取操作会更新环形缓冲区的读取索引,并根据需要循环读取已有数据。如果环形缓冲区中的数据不足以满足全部读取请求,只会读取部分数据。
便*/
/**
* @ingroup los_ringbuf
* @brief Get a ringbuf's used size.
*
* @par Description:
* This API is used to get a ringbuf's used size.
* @attention
* The specific ringbuf must be inited first.
*
* @param ringbuf [IN] The ringbuf address
*
* @retval #UINT32 The used size of ringbuf.
*
* @par Dependency:
* <ul><li>los_ringbuf.h: the header file that contains the API declaration.</li></ul>
* @see LOS_RingbufUsedSize
* @since Huawei LiteOS V200R005C00
*/
extern UINT32 LOS_RingbufUsedSize(Ringbuf *ringbuf);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_RINGBUF_H */

Binary file not shown.
Loading…
Cancel
Save