• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file hi_isr.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_isr Interruption
20  * @ingroup osa
21  */
22 
23 #ifndef __HI_ISR_H__
24 #define __HI_ISR_H__
25 #include "hi_types.h"
26 
27 #define HI_EXC_FLAG_NO_FLOAT                0x10000000
28 #define HI_EXC_FLAG_FAULTADDR_VALID         0x01
29 #define HI_EXC_FLAG_IN_HWI                  0x02
30 
31 typedef struct {
32     /* handler save */
33     hi_u32 r4;
34     hi_u32 r5;
35     hi_u32 r6;
36     hi_u32 r7;
37     hi_u32 r8;
38     hi_u32 r9;
39     hi_u32 r10;
40     hi_u32 r11;
41     hi_u32 pri_mask;
42     /* auto save */
43     hi_u32 sp;
44     hi_u32 r0;
45     hi_u32 r1;
46     hi_u32 r2;
47     hi_u32 r3;
48     hi_u32 r12;
49     hi_u32 lr;
50     hi_u32 pc;
51     hi_u32 xpsr;
52 } hi_exc_context;
53 
54 /**
55 * @ingroup  iot_isr
56 * @brief  HISR callback function type.CNcomment:HISR中断回调函数的类型。CNend
57 *
58 * @par 描述:
59 *           HISR callback function type.CNcomment:HISR中断回调函数的类型。CNend
60 *
61 * @attention None
62 * @param  param [IN] type #hi_u32,Callback input parameter.CNcomment:回调入参。CNend
63 *
64 * @retval None
65 * @par 依赖:
66 *            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
67 * @see None
68 */
69 typedef hi_void (*irq_routine)(hi_u32 param);
70 
71 /**
72 * @ingroup  iot_isr
73 * @brief  Interrupt off.CNcomment:关中断。CNend
74 *
75 * @par 描述:
76 *           Interrupt off.CNcomment:关中断。CNend
77 *
78 * @attention
79 *           @li A function that causes scheduling cannot be executed in an interrupt off context, for example,
80 *               hi_sleep and other blocked APIs.
81 *               CNcomment:关中断后不能执行引起调度的函数,如hi_sleep或其他阻塞接口。CNend
82 *           @li Interrupt off only protects short-time operations that can be expected. Otherwise, the interrupt
83 *               response and the performance may be affected.
84 *               CNcomment:关中断仅保护可预期的短时间的操作,否则影响中断响应,可能引起性能问题。CNend
85 *
86 * @param  None
87 *
88 * @retval #hi_u32 Interruption status value  Interrupt status before interrupt off.
89 CNcomment:中断状态值  关中断前的中断状态。CNend
90 *
91 * @par 依赖:
92 *            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
93 * @see  hi_int_restore。
94 */
95 hi_u32 hi_int_lock(hi_void);
96 
97 /**
98 * @ingroup  iot_isr
99 * @brief  Restores the status before interrupt off.CNcomment:恢复关中断前的状态。CNend
100 *
101 * @par 描述:
102 *           Restores the status before interrupt off.CNcomment:恢复关中断前的状态。CNend
103 *
104 * @attention The input argument must be the value of CPSR that is saved before interrupt off.
105 CNcomment:入参必须是与之对应的关中断时保存的关中断之前的CPSR的值。CNend
106 *
107 * @param  int_value [IN] type #hi_u32,Interrupt status.CNcomment:中断状态。CNend
108 *
109 * @retval None
110 * @par 依赖:
111 *            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
112 * @see  hi_int_lock。
113 */
114 hi_void hi_int_restore(hi_u32 int_value);
115 
116 /**
117 * @ingroup  iot_isr
118 * @brief  Enables a specified interrupt.CNcomment:使能指定中断。CNend
119 *
120 * @par 描述:
121 *           Enables a specified interrupt.CNcomment:使能指定中断。CNend
122 *
123 * @attention None
124 *
125 * @param  vector [IN] type #hi_u32,Interrupt ID.CNcomment:中断号。CNend
126 *
127 * @retval #0       Success.
128 * @retval #Other   Failure. For details, see hi_errno.h
129 * @par 依赖:
130 *            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
131 * @see  hi_irq_disable。
132 */
133 hi_u32 hi_irq_enable(hi_u32 vector);
134 
135 /**
136 * @ingroup  iot_isr
137 * @brief  Disables a specified interrupt.CNcomment:去使能指定中断。CNend
138 *
139 * @par 描述:
140 *           Disables a specified interrupt.CNcomment:去使能指定中断。CNend
141 *
142 * @attention None
143 * @param  vector [IN] type #hi_u32,Interrupt ID.CNcomment:中断号。CNend
144 *
145 * @retval None
146 * @par 依赖:
147 *            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
148 * @see  hi_irq_enable。
149 */
150 hi_void hi_irq_disable(hi_u32 vector);
151 
152 /* 由于不支持中断嵌套,仅当中断同时触发的场景下有效。 */
153 #define HI_IRQ_FLAG_PRI1    1
154 #define HI_IRQ_FLAG_PRI2    2
155 #define HI_IRQ_FLAG_PRI3    3
156 #define HI_IRQ_FLAG_PRI4    4
157 #define HI_IRQ_FLAG_PRI5    5
158 #define HI_IRQ_FLAG_PRI6    6
159 #define HI_IRQ_FLAG_PRI7    7
160 #define HI_IRQ_FLAG_PRI_MASK  0x7
161 #define HI_IRQ_FLAG_NOT_IN_FLASH 0x10
162 
163 #define HI_IRQ_FLAG_DEFAULT    HI_IRQ_FLAG_NOT_IN_FLASH
164 
165 /**
166 * @ingroup  iot_isr
167 * @brief  Registers an interrupt.CNcomment:注册中断。CNend
168 *
169 * @par 描述:
170 *           Registers an interrupt.CNcomment:注册中断。CNend
171 *
172 * @attention The interruption handling program cannot take too long a time, which affects the timely response of the
173 *            CPU to the interrupt.CNcomment:中断处理程序耗时不能过长,影响CPU对中断的及时响应。CNend
174 *
175 * @param  vector [IN] type #hi_u32,Interrupt ID.CNcomment:中断号。CNend
176 * @param  flag [IN]   type #hi_u32, attributes like priority,etc.CNcomment:中断优先级等属性。CNend
177 * @param  routine  [IN] type #irq_routine,Interrupt callback function.CNcomment:中断回调函数。CNend
178 * @param  param    [IN] type #hi_u32,Parameter transferred to the callback function.
179 CNcomment:中断回调函数的入参。CNend
180 *
181 * @retval #0       Success.
182 * @retval #Other   Failure. For details, see hi_errno.h
183 * @par 依赖:
184 *            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
185 * @see  hi_irq_free。
186 */
187 hi_u32 hi_irq_request(hi_u32 vector, hi_u32 flags, irq_routine routine, hi_u32 param);
188 
189 /**
190 * @ingroup  iot_isr
191 * @brief  Clears a registered interrupt.CNcomment:清除注册中断。CNend
192 *
193 * @par 描述:
194 *           Clears a registered interrupt.CNcomment:清除注册中断。CNend
195 *
196 * @attention None
197 * @param  vector [IN] type #hi_u32,Interrupt ID.CNcomment:中断号。CNend
198 *
199 * @retval #0       Success.
200 * @retval #Other   Failure. For details, see hi_errno.h
201 * @par 依赖:
202 *            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
203 * @see  hi_irq_request。
204 */
205 hi_u32 hi_irq_free(hi_u32 vector);
206 
207 /**
208 * @ingroup  iot_isr
209 * @brief  Checks whether it is in the interrupt context.CNcomment:检查是否在中断上下文中。CNend
210 *
211 * @par 描述:
212 *           Checks whether it is in the interrupt context.CNcomment:检查是否在中断上下文中。CNend
213 *
214 * @attention None
215 * @param  None
216 *
217 * @retval #HI_FALSE     Not in the interrupt context.CNcomment:不在中断上下文中。CNend
218 * @retval #HI_TRUE     In the interrupt context.CNcomment:在中断上下文中。CNend
219 * @par 依赖:
220 *            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
221 * @see  无。
222 */
223 hi_bool hi_is_int_context(hi_void);
224 
225 #endif
226 
227