1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _LOS_INTERRUPT_H 33 #define _LOS_INTERRUPT_H 34 35 #include "los_config.h" 36 #include "los_compiler.h" 37 38 #ifdef __cplusplus 39 #if __cplusplus 40 extern "C" { 41 #endif /* __cplusplus */ 42 #endif /* __cplusplus */ 43 44 typedef UINT32 HWI_HANDLE_T; 45 typedef UINT16 HWI_PRIOR_T; 46 typedef UINT16 HWI_MODE_T; 47 typedef UINT32 HWI_ARG_T; 48 49 #if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) 50 typedef VOID (*HWI_PROC_FUNC)(VOID *parm); 51 #else 52 typedef VOID (*HWI_PROC_FUNC)(void); 53 #endif 54 55 typedef struct tagIrqParam { 56 int swIrq; /**< The interrupt number */ 57 VOID *pDevId; /**< The pointer to the device ID that launches the interrupt */ 58 const CHAR *pName; /**< The interrupt name */ 59 } HwiIrqParam; 60 61 typedef struct { 62 UINT32 (*triggerIrq)(HWI_HANDLE_T hwiNum); 63 UINT32 (*clearIrq)(HWI_HANDLE_T hwiNum); 64 UINT32 (*enableIrq)(HWI_HANDLE_T hwiNum); 65 UINT32 (*disableIrq)(HWI_HANDLE_T hwiNum); 66 UINT32 (*setIrqPriority)(HWI_HANDLE_T hwiNum, UINT8 priority); 67 UINT32 (*getCurIrqNum)(VOID); 68 UINT32 (*createIrq)(HWI_HANDLE_T hwiNum, HWI_PRIOR_T hwiPrio); 69 } HwiControllerOps; 70 71 /* stack protector */ 72 extern UINT32 __stack_chk_guard; 73 extern VOID __stack_chk_fail(VOID); 74 #if (LOSCFG_DEBUG_TOOLS == 1) 75 extern UINT32 OsGetHwiFormCnt(UINT32 index); 76 extern CHAR *OsGetHwiFormName(UINT32 index); 77 extern BOOL OsHwiIsCreated(UINT32 index); 78 #endif 79 80 /** 81 * @ingroup los_interrupt 82 * @brief Delete hardware interrupt. 83 * 84 * @par Description: 85 * This API is used to delete hardware interrupt. 86 * 87 * @attention 88 * <ul> 89 * <li>The hardware interrupt module is usable only when the configuration item for hardware 90 * interrupt tailoring is enabled.</li> 91 * <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range 92 * applicable for a Cortex-A7 platform is [32,95].</li> 93 * <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li> 94 * <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li> 95 * </ul> 96 * 97 * @param hwiNum [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable 98 * for a Cortex-A7 platform is [32,95]. 99 * @param irqParam [IN] Type #HwiIrqParam *. ID of hardware interrupt which will base on 100 * when delete the hardware interrupt. 101 * @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number. 102 * @retval #LOS_OK 0 : The interrupt is successfully delete. 103 * @par Dependency: 104 * <ul><li>los_interrupt.h: the header file that contains the API declaration.</li></ul> 105 * @see None. 106 */ 107 UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam); 108 109 /** 110 * @ingroup los_interrupt 111 * @brief Create a hardware interrupt. 112 * 113 * @par Description: 114 * This API is used to configure a hardware interrupt and register a hardware interrupt handling function. 115 * 116 * @attention 117 * <ul> 118 * <li>The hardware interrupt module is usable only when the configuration item for hardware 119 * interrupt tailoring is enabled.</li> 120 * <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range 121 * applicable for a Cortex-A7 platform is [32,95].</li> 122 * <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li> 123 * <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li> 124 * </ul> 125 * 126 * @param hwiNum [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a 127 * Cortex-A7 platform is [32,95]. 128 * @param hwiPrio [IN] Type#HWI_PRIOR_T: hardware interrupt priority. Ignore this parameter temporarily. 129 * @param mode [IN] Type#HWI_MODE_T: hardware interrupt mode. Ignore this parameter temporarily. 130 * @param handler [IN] Type#HWI_PROC_FUNC: interrupt handler used when a hardware interrupt is triggered. 131 * @param irqParam [IN] Type#HwiIrqParam: input parameter of the interrupt 132 * handler used when a hardware interrupt is triggered. 133 * 134 * @retval #OS_ERRNO_HWI_PROC_FUNC_NULL 0x02000901: Null hardware interrupt handling function. 135 * @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number. 136 * @retval #OS_ERRNO_HWI_NO_MEMORY 0x02000903: Insufficient memory for hardware interrupt creation. 137 * @retval #OS_ERRNO_HWI_ALREADY_CREATED 0x02000904: The interrupt handler being created has 138 * already been created. 139 * @retval #LOS_OK 0 : The interrupt is successfully created. 140 * @par Dependency: 141 * <ul><li>los_interrupt.h: the header file that contains the API declaration.</li></ul> 142 * @see None. 143 */ 144 UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum, HWI_PRIOR_T hwiPrio, HWI_MODE_T mode, 145 HWI_PROC_FUNC handler, HwiIrqParam *irqParam); 146 UINT32 ArchIsIntActive(VOID); 147 UINT32 ArchIntLock(VOID); 148 UINT32 ArchIntUnLock(VOID); 149 VOID ArchIntRestore(UINT32 intSave); 150 UINT32 ArchIntTrigger(HWI_HANDLE_T hwiNum); 151 UINT32 ArchIntEnable(HWI_HANDLE_T hwiNum); 152 UINT32 ArchIntDisable(HWI_HANDLE_T hwiNum); 153 UINT32 ArchIntClear(HWI_HANDLE_T hwiNum); 154 UINT32 ArchIntSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority); 155 UINT32 ArchIntCurIrqNum(VOID); 156 HwiControllerOps *ArchIntOpsGet(VOID); 157 158 #define OS_INT_ACTIVE (ArchIsIntActive()) 159 #define OS_INT_INACTIVE (!(OS_INT_ACTIVE)) 160 #define LOS_IntLock ArchIntLock 161 #define LOS_IntRestore ArchIntRestore 162 #define LOS_IntUnLock ArchIntUnLock 163 #define LOS_HwiDelete ArchHwiDelete 164 #define LOS_HwiCreate ArchHwiCreate 165 #define LOS_HwiTrigger ArchIntTrigger 166 #define LOS_HwiEnable ArchIntEnable 167 #define LOS_HwiDisable ArchIntDisable 168 #define LOS_HwiClear ArchIntClear 169 #define LOS_HwiSetPriority ArchIntSetPriority 170 #define LOS_HwiCurIrqNum ArchIntCurIrqNum 171 #define LOS_HwiOpsGet ArchIntOpsGet 172 173 #ifdef __cplusplus 174 #if __cplusplus 175 } 176 #endif /* __cplusplus */ 177 #endif /* __cplusplus */ 178 179 #endif /* _LOS_INTERRUPT_H */ 180