11bd4fe43Sopenharmony_ci/**
21bd4fe43Sopenharmony_ci * @file hi_isr.h
31bd4fe43Sopenharmony_ci *
41bd4fe43Sopenharmony_ci * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
51bd4fe43Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
61bd4fe43Sopenharmony_ci * you may not use this file except in compliance with the License.
71bd4fe43Sopenharmony_ci * You may obtain a copy of the License at
81bd4fe43Sopenharmony_ci *
91bd4fe43Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
101bd4fe43Sopenharmony_ci *
111bd4fe43Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
121bd4fe43Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
131bd4fe43Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141bd4fe43Sopenharmony_ci * See the License for the specific language governing permissions and
151bd4fe43Sopenharmony_ci * limitations under the License.
161bd4fe43Sopenharmony_ci */
171bd4fe43Sopenharmony_ci
181bd4fe43Sopenharmony_ci/**
191bd4fe43Sopenharmony_ci * @defgroup iot_isr Interruption
201bd4fe43Sopenharmony_ci * @ingroup osa
211bd4fe43Sopenharmony_ci */
221bd4fe43Sopenharmony_ci
231bd4fe43Sopenharmony_ci#ifndef __HI_ISR_H__
241bd4fe43Sopenharmony_ci#define __HI_ISR_H__
251bd4fe43Sopenharmony_ci#include "hi_types.h"
261bd4fe43Sopenharmony_ci
271bd4fe43Sopenharmony_ci#define HI_EXC_FLAG_NO_FLOAT                0x10000000
281bd4fe43Sopenharmony_ci#define HI_EXC_FLAG_FAULTADDR_VALID         0x01
291bd4fe43Sopenharmony_ci#define HI_EXC_FLAG_IN_HWI                  0x02
301bd4fe43Sopenharmony_ci
311bd4fe43Sopenharmony_citypedef struct {
321bd4fe43Sopenharmony_ci    /* handler save */
331bd4fe43Sopenharmony_ci    hi_u32 r4;
341bd4fe43Sopenharmony_ci    hi_u32 r5;
351bd4fe43Sopenharmony_ci    hi_u32 r6;
361bd4fe43Sopenharmony_ci    hi_u32 r7;
371bd4fe43Sopenharmony_ci    hi_u32 r8;
381bd4fe43Sopenharmony_ci    hi_u32 r9;
391bd4fe43Sopenharmony_ci    hi_u32 r10;
401bd4fe43Sopenharmony_ci    hi_u32 r11;
411bd4fe43Sopenharmony_ci    hi_u32 pri_mask;
421bd4fe43Sopenharmony_ci    /* auto save */
431bd4fe43Sopenharmony_ci    hi_u32 sp;
441bd4fe43Sopenharmony_ci    hi_u32 r0;
451bd4fe43Sopenharmony_ci    hi_u32 r1;
461bd4fe43Sopenharmony_ci    hi_u32 r2;
471bd4fe43Sopenharmony_ci    hi_u32 r3;
481bd4fe43Sopenharmony_ci    hi_u32 r12;
491bd4fe43Sopenharmony_ci    hi_u32 lr;
501bd4fe43Sopenharmony_ci    hi_u32 pc;
511bd4fe43Sopenharmony_ci    hi_u32 xpsr;
521bd4fe43Sopenharmony_ci} hi_exc_context;
531bd4fe43Sopenharmony_ci
541bd4fe43Sopenharmony_ci/**
551bd4fe43Sopenharmony_ci* @ingroup  iot_isr
561bd4fe43Sopenharmony_ci* @brief  HISR callback function type.CNcomment:HISR中断回调函数的类型。CNend
571bd4fe43Sopenharmony_ci*
581bd4fe43Sopenharmony_ci* @par 描述:
591bd4fe43Sopenharmony_ci*           HISR callback function type.CNcomment:HISR中断回调函数的类型。CNend
601bd4fe43Sopenharmony_ci*
611bd4fe43Sopenharmony_ci* @attention None
621bd4fe43Sopenharmony_ci* @param  param [IN] type #hi_u32,Callback input parameter.CNcomment:回调入参。CNend
631bd4fe43Sopenharmony_ci*
641bd4fe43Sopenharmony_ci* @retval None
651bd4fe43Sopenharmony_ci* @par 依赖:
661bd4fe43Sopenharmony_ci*            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
671bd4fe43Sopenharmony_ci* @see None
681bd4fe43Sopenharmony_ci*/
691bd4fe43Sopenharmony_citypedef hi_void (*irq_routine)(hi_u32 param);
701bd4fe43Sopenharmony_ci
711bd4fe43Sopenharmony_ci/**
721bd4fe43Sopenharmony_ci* @ingroup  iot_isr
731bd4fe43Sopenharmony_ci* @brief  Interrupt off.CNcomment:关中断。CNend
741bd4fe43Sopenharmony_ci*
751bd4fe43Sopenharmony_ci* @par 描述:
761bd4fe43Sopenharmony_ci*           Interrupt off.CNcomment:关中断。CNend
771bd4fe43Sopenharmony_ci*
781bd4fe43Sopenharmony_ci* @attention
791bd4fe43Sopenharmony_ci*           @li A function that causes scheduling cannot be executed in an interrupt off context, for example,
801bd4fe43Sopenharmony_ci*               hi_sleep and other blocked APIs.
811bd4fe43Sopenharmony_ci*               CNcomment:关中断后不能执行引起调度的函数,如hi_sleep或其他阻塞接口。CNend
821bd4fe43Sopenharmony_ci*           @li Interrupt off only protects short-time operations that can be expected. Otherwise, the interrupt
831bd4fe43Sopenharmony_ci*               response and the performance may be affected.
841bd4fe43Sopenharmony_ci*               CNcomment:关中断仅保护可预期的短时间的操作,否则影响中断响应,可能引起性能问题。CNend
851bd4fe43Sopenharmony_ci*
861bd4fe43Sopenharmony_ci* @param  None
871bd4fe43Sopenharmony_ci*
881bd4fe43Sopenharmony_ci* @retval #hi_u32 Interruption status value  Interrupt status before interrupt off.
891bd4fe43Sopenharmony_ciCNcomment:中断状态值  关中断前的中断状态。CNend
901bd4fe43Sopenharmony_ci*
911bd4fe43Sopenharmony_ci* @par 依赖:
921bd4fe43Sopenharmony_ci*            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
931bd4fe43Sopenharmony_ci* @see  hi_int_restore。
941bd4fe43Sopenharmony_ci*/
951bd4fe43Sopenharmony_cihi_u32 hi_int_lock(hi_void);
961bd4fe43Sopenharmony_ci
971bd4fe43Sopenharmony_ci/**
981bd4fe43Sopenharmony_ci* @ingroup  iot_isr
991bd4fe43Sopenharmony_ci* @brief  Restores the status before interrupt off.CNcomment:恢复关中断前的状态。CNend
1001bd4fe43Sopenharmony_ci*
1011bd4fe43Sopenharmony_ci* @par 描述:
1021bd4fe43Sopenharmony_ci*           Restores the status before interrupt off.CNcomment:恢复关中断前的状态。CNend
1031bd4fe43Sopenharmony_ci*
1041bd4fe43Sopenharmony_ci* @attention The input argument must be the value of CPSR that is saved before interrupt off.
1051bd4fe43Sopenharmony_ciCNcomment:入参必须是与之对应的关中断时保存的关中断之前的CPSR的值。CNend
1061bd4fe43Sopenharmony_ci*
1071bd4fe43Sopenharmony_ci* @param  int_value [IN] type #hi_u32,Interrupt status.CNcomment:中断状态。CNend
1081bd4fe43Sopenharmony_ci*
1091bd4fe43Sopenharmony_ci* @retval None
1101bd4fe43Sopenharmony_ci* @par 依赖:
1111bd4fe43Sopenharmony_ci*            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
1121bd4fe43Sopenharmony_ci* @see  hi_int_lock。
1131bd4fe43Sopenharmony_ci*/
1141bd4fe43Sopenharmony_cihi_void hi_int_restore(hi_u32 int_value);
1151bd4fe43Sopenharmony_ci
1161bd4fe43Sopenharmony_ci/**
1171bd4fe43Sopenharmony_ci* @ingroup  iot_isr
1181bd4fe43Sopenharmony_ci* @brief  Enables a specified interrupt.CNcomment:使能指定中断。CNend
1191bd4fe43Sopenharmony_ci*
1201bd4fe43Sopenharmony_ci* @par 描述:
1211bd4fe43Sopenharmony_ci*           Enables a specified interrupt.CNcomment:使能指定中断。CNend
1221bd4fe43Sopenharmony_ci*
1231bd4fe43Sopenharmony_ci* @attention None
1241bd4fe43Sopenharmony_ci*
1251bd4fe43Sopenharmony_ci* @param  vector [IN] type #hi_u32,Interrupt ID.CNcomment:中断号。CNend
1261bd4fe43Sopenharmony_ci*
1271bd4fe43Sopenharmony_ci* @retval #0       Success.
1281bd4fe43Sopenharmony_ci* @retval #Other   Failure. For details, see hi_errno.h
1291bd4fe43Sopenharmony_ci* @par 依赖:
1301bd4fe43Sopenharmony_ci*            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
1311bd4fe43Sopenharmony_ci* @see  hi_irq_disable。
1321bd4fe43Sopenharmony_ci*/
1331bd4fe43Sopenharmony_cihi_u32 hi_irq_enable(hi_u32 vector);
1341bd4fe43Sopenharmony_ci
1351bd4fe43Sopenharmony_ci/**
1361bd4fe43Sopenharmony_ci* @ingroup  iot_isr
1371bd4fe43Sopenharmony_ci* @brief  Disables a specified interrupt.CNcomment:去使能指定中断。CNend
1381bd4fe43Sopenharmony_ci*
1391bd4fe43Sopenharmony_ci* @par 描述:
1401bd4fe43Sopenharmony_ci*           Disables a specified interrupt.CNcomment:去使能指定中断。CNend
1411bd4fe43Sopenharmony_ci*
1421bd4fe43Sopenharmony_ci* @attention None
1431bd4fe43Sopenharmony_ci* @param  vector [IN] type #hi_u32,Interrupt ID.CNcomment:中断号。CNend
1441bd4fe43Sopenharmony_ci*
1451bd4fe43Sopenharmony_ci* @retval None
1461bd4fe43Sopenharmony_ci* @par 依赖:
1471bd4fe43Sopenharmony_ci*            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
1481bd4fe43Sopenharmony_ci* @see  hi_irq_enable。
1491bd4fe43Sopenharmony_ci*/
1501bd4fe43Sopenharmony_cihi_void hi_irq_disable(hi_u32 vector);
1511bd4fe43Sopenharmony_ci
1521bd4fe43Sopenharmony_ci/* 由于不支持中断嵌套,仅当中断同时触发的场景下有效。 */
1531bd4fe43Sopenharmony_ci#define HI_IRQ_FLAG_PRI1    1
1541bd4fe43Sopenharmony_ci#define HI_IRQ_FLAG_PRI2    2
1551bd4fe43Sopenharmony_ci#define HI_IRQ_FLAG_PRI3    3
1561bd4fe43Sopenharmony_ci#define HI_IRQ_FLAG_PRI4    4
1571bd4fe43Sopenharmony_ci#define HI_IRQ_FLAG_PRI5    5
1581bd4fe43Sopenharmony_ci#define HI_IRQ_FLAG_PRI6    6
1591bd4fe43Sopenharmony_ci#define HI_IRQ_FLAG_PRI7    7
1601bd4fe43Sopenharmony_ci#define HI_IRQ_FLAG_PRI_MASK  0x7
1611bd4fe43Sopenharmony_ci#define HI_IRQ_FLAG_NOT_IN_FLASH 0x10
1621bd4fe43Sopenharmony_ci
1631bd4fe43Sopenharmony_ci#define HI_IRQ_FLAG_DEFAULT    HI_IRQ_FLAG_NOT_IN_FLASH
1641bd4fe43Sopenharmony_ci
1651bd4fe43Sopenharmony_ci/**
1661bd4fe43Sopenharmony_ci* @ingroup  iot_isr
1671bd4fe43Sopenharmony_ci* @brief  Registers an interrupt.CNcomment:注册中断。CNend
1681bd4fe43Sopenharmony_ci*
1691bd4fe43Sopenharmony_ci* @par 描述:
1701bd4fe43Sopenharmony_ci*           Registers an interrupt.CNcomment:注册中断。CNend
1711bd4fe43Sopenharmony_ci*
1721bd4fe43Sopenharmony_ci* @attention The interruption handling program cannot take too long a time, which affects the timely response of the
1731bd4fe43Sopenharmony_ci*            CPU to the interrupt.CNcomment:中断处理程序耗时不能过长,影响CPU对中断的及时响应。CNend
1741bd4fe43Sopenharmony_ci*
1751bd4fe43Sopenharmony_ci* @param  vector [IN] type #hi_u32,Interrupt ID.CNcomment:中断号。CNend
1761bd4fe43Sopenharmony_ci* @param  flag [IN]   type #hi_u32, attributes like priority,etc.CNcomment:中断优先级等属性。CNend
1771bd4fe43Sopenharmony_ci* @param  routine  [IN] type #irq_routine,Interrupt callback function.CNcomment:中断回调函数。CNend
1781bd4fe43Sopenharmony_ci* @param  param    [IN] type #hi_u32,Parameter transferred to the callback function.
1791bd4fe43Sopenharmony_ciCNcomment:中断回调函数的入参。CNend
1801bd4fe43Sopenharmony_ci*
1811bd4fe43Sopenharmony_ci* @retval #0       Success.
1821bd4fe43Sopenharmony_ci* @retval #Other   Failure. For details, see hi_errno.h
1831bd4fe43Sopenharmony_ci* @par 依赖:
1841bd4fe43Sopenharmony_ci*            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
1851bd4fe43Sopenharmony_ci* @see  hi_irq_free。
1861bd4fe43Sopenharmony_ci*/
1871bd4fe43Sopenharmony_cihi_u32 hi_irq_request(hi_u32 vector, hi_u32 flags, irq_routine routine, hi_u32 param);
1881bd4fe43Sopenharmony_ci
1891bd4fe43Sopenharmony_ci/**
1901bd4fe43Sopenharmony_ci* @ingroup  iot_isr
1911bd4fe43Sopenharmony_ci* @brief  Clears a registered interrupt.CNcomment:清除注册中断。CNend
1921bd4fe43Sopenharmony_ci*
1931bd4fe43Sopenharmony_ci* @par 描述:
1941bd4fe43Sopenharmony_ci*           Clears a registered interrupt.CNcomment:清除注册中断。CNend
1951bd4fe43Sopenharmony_ci*
1961bd4fe43Sopenharmony_ci* @attention None
1971bd4fe43Sopenharmony_ci* @param  vector [IN] type #hi_u32,Interrupt ID.CNcomment:中断号。CNend
1981bd4fe43Sopenharmony_ci*
1991bd4fe43Sopenharmony_ci* @retval #0       Success.
2001bd4fe43Sopenharmony_ci* @retval #Other   Failure. For details, see hi_errno.h
2011bd4fe43Sopenharmony_ci* @par 依赖:
2021bd4fe43Sopenharmony_ci*            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
2031bd4fe43Sopenharmony_ci* @see  hi_irq_request。
2041bd4fe43Sopenharmony_ci*/
2051bd4fe43Sopenharmony_cihi_u32 hi_irq_free(hi_u32 vector);
2061bd4fe43Sopenharmony_ci
2071bd4fe43Sopenharmony_ci/**
2081bd4fe43Sopenharmony_ci* @ingroup  iot_isr
2091bd4fe43Sopenharmony_ci* @brief  Checks whether it is in the interrupt context.CNcomment:检查是否在中断上下文中。CNend
2101bd4fe43Sopenharmony_ci*
2111bd4fe43Sopenharmony_ci* @par 描述:
2121bd4fe43Sopenharmony_ci*           Checks whether it is in the interrupt context.CNcomment:检查是否在中断上下文中。CNend
2131bd4fe43Sopenharmony_ci*
2141bd4fe43Sopenharmony_ci* @attention None
2151bd4fe43Sopenharmony_ci* @param  None
2161bd4fe43Sopenharmony_ci*
2171bd4fe43Sopenharmony_ci* @retval #HI_FALSE     Not in the interrupt context.CNcomment:不在中断上下文中。CNend
2181bd4fe43Sopenharmony_ci* @retval #HI_TRUE     In the interrupt context.CNcomment:在中断上下文中。CNend
2191bd4fe43Sopenharmony_ci* @par 依赖:
2201bd4fe43Sopenharmony_ci*            @li hi_isr.h:Describes ISR APIs.CNcomment:文件用于描述ISR相关接口。CNend
2211bd4fe43Sopenharmony_ci* @see  无。
2221bd4fe43Sopenharmony_ci*/
2231bd4fe43Sopenharmony_cihi_bool hi_is_int_context(hi_void);
2241bd4fe43Sopenharmony_ci
2251bd4fe43Sopenharmony_ci#endif
2261bd4fe43Sopenharmony_ci
227