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