• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file hi_cpu.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_cpu CPU
20  * @ingroup osa
21  */
22 
23 #ifndef __HI_CPU_H__
24 #define __HI_CPU_H__
25 #include <hi_types.h>
26 
27 #define LOAD_SLEEP_TIME_DEFAULT   30
28 
29 /**
30  * @ingroup iot_cpu
31  *
32  * CPU usage information structure. CNcomment:cpu使用情况信息结构 CNend
33  */
34 typedef struct {
35     hi_u8 b_valid : 1;    /**< Whether the information is valid. HI_TRUE: yes; HI_FALSE: no.
36                              CNcomment:表示该条信息是否为有效信息,HI_TRUE:该条信息有效
37                              HI_FALSE:该条信息无效 CNend */
38     hi_u8 b_task : 1;     /**< Whether the message is a task or an interrupt. HI_TRUE: task; HI_FALSE: interrupt.
39                              CNcomment:表示该条信息是任务或中断,HI_TRUE:任务 HI_FALSE:中断 CNend */
40     hi_u8 pad0 : 6;       /**< Reserved. CNcomment:保留 CNend */
41     hi_u8 id;           /**< Task ID/Interrupt number. CNcomment:当该条信息表示任务时为任务ID,
42                            当该条信息为中断信息时表示中断号 CNend */
43     hi_u16 pad1;        /**< Reserved. CNcomment:保留 CNend */
44     hi_u32 permillage;  /**< CPU usage (per mil). CNcomment:cpu占用率,千分比 CNend */
45     hi_u64 cpu_time;    /**< CPU usage time (unit: cputick), where, cputick x 160000000 = 1s.
46                            CNcomment:cpu占用时间(单位:cputick),160000000个cputick等于1秒 CNend */
47 } hi_cpup_item;
48 
49 
50 typedef enum {
51     HI_CPU_CLK_80M,  /**< cpu clock:80M. CNcomment:CPU工作频率:80M CNend */
52     HI_CPU_CLK_120M, /**< cpu clock:120M. CNcomment:CPU工作频率:120M CNend */
53     HI_CPU_CLK_160M, /**< cpu clock:160M. CNcomment:CPU工作频率:160M CNend */
54     HI_CPU_CLK_MAX   /**< Maximum cpu clock, which cannot be used. CNcomment:CPU最大工作频率,
55                          不可使用CNend */
56 } hi_cpu_clk;
57 
58 /**
59 * @ingroup  iot_cpu
60 * @brief  Obtains the CPU usage. CNcomment:获取CPU使用情况。CNend
61 *
62 * @par 描述:
63 *         Obtains the CPU usage between the initialization of the CPU usage module is started or
64 *         the CPU usage statistics are reset to each task/interrupt.
65 CNcomment:获取cpu占用率模块初始化开始或cpu占用率统计信息重置开始统计到个各任务(中断)
66 CPU占用情况。CNend
67 *
68 * @attention
69 * @li A task/interrupt not scheduled after the CPU usage module is initialized or
70 *     the CPU usage statistics are reset is excluded.
71 CNcomment:cpu占用率模块初始化或cpu占用率统计信息重置之后没有调度到的任务或中断
72 不会被统计。CNend
73 *
74 * @param array_count [IN] type #hi_u32 Number of CPU usage records that can be stored
75 *                         in the space corresponding to cpup_items. CNcomment:表示p_cpup_items对应的空间可以
76 存储多少条cpu使用情况信息。CNend
77 * @param p_cpup_items [OUT] type #hi_cpup_item* CPU usage information space, applied by the caller.
78 CNcomment:cpu使用情况信息空间,由调用者申请。CNend
79 *
80 * @retval #0   Success.
81 * @retval #Other    Failure. For details, see hi_errno.h.
82 * @par Dependency:
83 *            @li hi_cpu.h: Describes CPU usage APIs.
84 CNcomment:文件用于描述cpu相关接口。CNend
85 * @see  None
86 */
87 hi_u32 hi_cpup_get_usage(hi_u32 array_count, hi_cpup_item *p_cpup_items);
88 
89 /**
90 * @ingroup  iot_cpu
91 * @brief  Resets CPU usage statistics. CNcomment:重置cpu使用情况信息。CNend
92 *
93 * @param None
94 *
95 * @retval #None
96 * @par 描述:
97 *         Resets CPU usage statistics. After the reset, the CPU usage statistics of all tasks and interrupts are
98 *         cleared. CNcomment:重置cpu使用情况信息,重置后所有任务和中断的cpu占用率清0。CNend
99 *
100 * @attention None
101 *
102 * @par Dependency:
103 *            @li hi_cpu.h: Describes CPU usage APIs.
104 CNcomment:文件用于描述cpu相关接口。CNend
105 * @see None
106 */
107 hi_void hi_cpup_reset_usage(hi_void);
108 
109 /**
110 * @ingroup  iot_cpu
111 * @brief  Set CPU clock. CNcomment:设置CPU的工作频率。CNend
112 *
113 * @par 描述:
114 *         Set CPU clock, such as 80M/120M/160M.
115 *         CNcomment:设置CPU的工作频率,如80M/120M/160M。CNend
116 *
117 * @attention Default CPU clock is 160M, if change CPU clock, Shoud config it
118 both in System Startup and DeepSleep Wakeup stage.CNcomment:CPU默认工作频率为160M,
119 如果改变CPU的工作频率,需要在系统启动和深睡唤醒阶段均进行配置。CNend
120 * @param  clk        [IN] type #hi_cpu_clk,cpu clk. CNcomment:CPU工作频率。CNend
121 *
122 * @retval #HI_ERR_SUCCESS  Success.
123 * @retval #HI_ERR_CPU_CLK_INVALID_PARAM  invalid clk. CNcomment:工作频率无效。CNend
124 *
125 * @par Dependency:
126 *            @li hi_cpu.h: Describes CPU usage APIs.
127 CNcomment:文件用于描述cpu相关接口。CNend
128 * @see None
129 */
130 hi_u32 hi_cpu_set_clk(hi_cpu_clk clk);
131 
132 /**
133 * @ingroup  iot_cpu
134 * @brief  Get CPU clock. CNcomment:获取CPU的工作频率。CNend
135 *
136 * @par 描述:
137 *         Get CPU clock, such as 80M/120M/160M.
138 *         CNcomment:获取CPU的工作频率,如80M/120M/160M。CNend
139 *
140 * @attention None
141 * @param  None
142 *
143 * @retval #hi_cpu_clk  cpu clk.
144 *
145 * @par Dependency:
146 *            @li hi_cpu.h: Describes CPU usage APIs.
147 CNcomment:文件用于描述cpu相关接口。CNend
148 * @see None
149 */
150 hi_cpu_clk hi_cpu_get_clk(hi_void);
151 
152 /**
153 * @ingroup  iot_cpu
154 * @brief  check cpu load percent and sleep. CNcomment:检查idle任务cpu占有率,
155 如果小于门限则对当前任务进行睡眠。CNend
156 *
157 * @par 描述:
158 *         check cpu load percent of idle task, if smaller than the threshold
159 (5%), Then sleep. CNcomment:检查idle任务cpu占有率,如果小于门限(5%)则对当前任务
160 进行睡眠。CNend
161 *
162 * @attention None
163 *
164 * @param  task_id  [IN] type #hi_u32,current task ID.
165 CNcomment:当前固定填写当前任务ID。CNend
166 * @param  ms       [IN] type #hi_u32,sleep time:当前任务睡眠时间。CNend
167 *
168 * @retval None
169 * @par Dependency:
170 *            @li hi_cpu.h: Describes CPU usage APIs.
171 CNcomment:文件用于描述cpu相关接口。CNend
172 * @see None
173 */
174 hi_void hi_cpup_load_check_proc(hi_u32 task_id, hi_u32 ms);
175 
176 /**
177 * @ingroup  iot_cpu
178 * @brief  Enable Dcache. CNcomment:使能DCache。CNend
179 *
180 *
181 * @par 描述:
182 *         Enable Dcache,system default Enable Dcache after startup.
183 CNcomment:使能DCache,系统启动默认使能。CNend
184 *
185 * @attention None
186 *
187 * @param None
188 *
189 * @retval #None
190 * @par Dependency:
191 *            @li hi_cpu.h: Describes CPU usage APIs.
192 CNcomment:文件用于描述cpu相关接口。CNend
193 * @see None
194 */
195 hi_void hi_cache_enable(hi_void);
196 
197 /**
198 * @ingroup  iot_cpu
199 * @brief  Disable Dcache. CNcomment:禁用DCache。CNend
200 *
201 * @par 描述:
202 *         Disable Dcache. CNcomment:禁用DCache。CNend
203 *
204 * @attention:
205 *         flush cache before disable. CNcomment:禁用Dcache前需要刷Cache。CNend
206 *
207 * @param None
208 *
209 * @retval #None
210 * @par Dependency:
211 *            @li hi_cpu.h: Describes CPU usage APIs.
212 CNcomment:文件用于描述cpu相关接口。CNend
213 * @see None
214 */
215 hi_void hi_cache_disable(hi_void);
216 
217 /**
218 * @ingroup  iot_cpu
219 * @brief  Flush Dcache. CNcomment:Flush DCache。CNend
220 *
221 * @par 描述:
222 *         Flush Dcache, synchronize Dcache and memory.
223 CNcomment:刷新DCache,维持DCache和memory同步。CNend
224 *
225 * @attention None
226 *
227 * @param None
228 *
229 * @retval #None
230 * @par Dependency:
231 *            @li hi_cpu.h: Describes CPU usage APIs.
232 CNcomment:文件用于描述cpu相关接口。CNend
233 * @see None
234 */
235 hi_void hi_cache_flush(hi_void);
236 
237 /**
238 * @ingroup  iot_cpu
239 * @brief  Flush Icache. CNcomment:Flush ICache。CNend
240 *
241 * @par 描述:
242 *         Flush Icache, synchronize Icache and memory.
243 CNcomment:刷新ICache,维持ICache和memory同步。CNend
244 *
245 * @attention None
246 *
247 * @param None
248 *
249 * @retval #None
250 * @par Dependency:
251 *            @li hi_cpu.h: Describes CPU usage APIs.
252 CNcomment:文件用于描述cpu相关接口。CNend
253 * @see None
254 */
255 hi_void hi_icache_flush(hi_void);
256 
257 #endif
258