1/**
2 * @file hi_men.h
3 *
4 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * @defgroup iot_mem  Memory
20 * @ingroup osa
21 */
22
23#ifndef __HI_MEM_H__
24#define __HI_MEM_H__
25#include <hi_types_base.h>
26
27/**
28 * @ingroup iot_mem
29 * Overall memory information.CNcomment:整体内存信息。CNend
30 */
31typedef struct {
32    hi_u32 total;                /**< Total space of the memory pool (unit: byte).
33                                    CNcomment:内存池总大小(单位:byte)CNend */
34    hi_u32 used;                 /**< Used space of the memory pool (unit: byte).
35                                    CNcomment:内存池已经使用大小(单位:byte)CNend */
36    hi_u32 free;                 /**< Free space of the memory pool (unit: byte).
37                                    CNcomment:内存池剩余空间(单位:byte)CNend */
38    hi_u32 free_node_num;        /**< Number of free nodes in the memory pool.
39                                    CNcomment:内存池剩余空间节点个数 CNend */
40    hi_u32 used_node_num;        /**< Number of used nodes in the memory pool.
41                                    CNcomment:内存池已经使用的节点个数 CNend */
42    hi_u32 max_free_node_size;   /**< Maximum size of the node in the free space of the memory pool (unit: byte).
43                                    CNcomment:内存池剩余空间节点中最大节点的大小(单位:byte)CNend */
44    hi_u32 malloc_fail_count;    /**< Number of memory application failures.CNcomment:内存申请失败计数 CNend */
45    hi_u32 peek_size;            /**< Peak memory usage of the memory pool.CNcomment:内存池使用峰值CNend */
46    hi_u32 total_lmp;            /**< Total space of the little memory pool (unit: byte).
47                                    CNcomment:小内存池总大小(单位:byte)CNend */
48    hi_u32 used_lmp;             /**< Used space of the little memory pool (unit: byte).
49                                    CNcomment:小内存池已经使用大小(单位:byte)CNend */
50    hi_u32 free_lmp;             /**< Free space of the little memory pool (unit: byte).
51                                    CNcomment:小内存池剩余空间(单位:byte)CNend */
52} hi_mdm_mem_info;
53
54typedef struct {
55    hi_u32 pool_addr;
56    hi_u32 pool_size;
57    hi_u32 fail_count;
58    hi_u32 peek_size;
59    hi_u32 cur_use_size;
60} hi_mem_pool_crash_info;
61
62/**
63* @ingroup  iot_mem
64* @brief  Dynamically applies for memory.CNcomment:动态申请内存。CNend
65*
66* @par 描述:
67*           Dynamically applies for memory.CNcomment:动态申请内存。CNend
68*
69* @attention None
70* @param  mod_id  [IN] type #hi_u32,ID of the called module.CNcomment:调用模块ID。CNend
71* @param  size    [IN] type #hi_u32,Requested memory size (unit: byte)
72CNcomment:申请内存大小(单位:byte)。CNend
73*
74* @retval #>0 Success
75* @retval #HI_NULL   Failure. The memory is insufficient.
76* @par 依赖:
77*            @li hi_mem.h:Describes memory APIs.CNcomment:文件用于描述内存相关接口。CNend
78* @see  hi_free。
79*/
80hi_pvoid hi_malloc(hi_u32 mod_id, hi_u32 size);
81
82/**
83* @ingroup  iot_mem
84* @brief  Releases the memory that is dynamically applied for.CNcomment:释放动态申请的内存。CNend
85*
86* @par 描述:
87*          Releases the memory that is dynamically applied for.CNcomment:释放动态申请的内存。CNend
88*
89* @attention None
90* @param  mod_id  [IN] type #hi_u32,ID of the called module.CNcomment:调用模块ID。CNend
91* @param  addr    [IN] type #hi_pvoid,Start address of the requested memory. The validity of the address is ensured
92*                 by the caller.CNcomment:所申请内存的首地址,地址合法性由调用者保证。CNend
93*
94* @retval None
95* @par 依赖:
96*            @li hi_mem.h:Describes memory APIs.CNcomment:文件用于描述内存相关接口。CNend
97* @see  hi_malloc。
98*/
99hi_void hi_free(hi_u32 mod_id, const hi_pvoid addr);
100
101/**
102* @ingroup  iot_mem
103* @brief  Obtains the memory information.CNcomment:获取内存信息。CNend
104*
105* @par 描述:
106*           Obtains the memory information.CNcomment:获取内存信息。CNend
107*
108* @attention None
109* @param  mem_inf [OUT] type #hi_mdm_mem_info*,Overall memory information.CNcomment:整体内存信息。CNend
110*
111* @retval #0      Success.
112* @retval #Other  Failure, for details, see hi_errno.h
113* @par 依赖:
114*            @li hi_mem.h:Describes memory APIs.CNcomment:文件用于描述内存相关接口。CNend
115* @see  None
116*/
117hi_u32 hi_mem_get_sys_info(HI_OUT hi_mdm_mem_info *mem_inf);
118
119/**
120* @ingroup  iot_mem
121* @brief  Obtains memory information, used in a crash process.
122CNcomment:获取内存信息,死机流程中使用。CNend
123*
124* @par 描述:
125*           Obtains memory information, used in a crash process. When the board is reset due to a memory exception,
126*           if hi_mem_get_sys_info is used to obtain memory information, another exception may occur. In this case,
127*           use hi_mem_get_sys_info_crash instead.CNcomment:获取内存信息,死机流程中使用。当内存异常导致单板复位时,
128如果通过hi_mem_get_sys_info获取内存信息可能再次产生异常,此时应该使用hi_mem_get_sys_info_crash。CNend
129*
130* @attention None
131*
132* @retval #hi_mem_pool_crash_info   Memory information.CNcomment:内存信息。CNend
133*
134* @par 依赖:
135*            @li hi_mem.h:Describes memory APIs.CNcomment:文件用于描述内存相关接口。CNend
136* @see  None
137*/
138HI_CONST hi_mem_pool_crash_info *hi_mem_get_sys_info_crash(hi_void);
139
140#endif
141