1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 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_ARCH_INTERRUPT_H 33 #define _LOS_ARCH_INTERRUPT_H 34 35 #include "los_config.h" 36 #include "los_compiler.h" 37 #include "los_interrupt.h" 38 39 #ifdef __cplusplus 40 #if __cplusplus 41 extern "C" { 42 #endif /* __cplusplus */ 43 #endif /* __cplusplus */ 44 45 typedef struct { 46 UINT32 pc; 47 UINT32 ps; 48 UINT32 regA[16]; 49 UINT32 sar; 50 UINT32 excCause; 51 UINT32 excVaddr; 52 UINT32 lbeg; 53 UINT32 lend; 54 UINT32 lcount; 55 #if (defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) 56 UINT32 temp; 57 UINT16 cpenable; 58 UINT16 cpstored; 59 UINT32 fcr; 60 UINT32 fsr; 61 UINT32 regF[16]; 62 #endif 63 UINT32 res[4]; 64 } EXC_CONTEXT_S; 65 66 #define VECTOR_START _init_start 67 extern CHAR *VECTOR_START; 68 #define INIT_VECTOR_START ((UINTPTR)&VECTOR_START) 69 70 /* * 71 * @ingroup los_arch_interrupt 72 * Maximum number of used hardware interrupts. 73 */ 74 #ifndef OS_HWI_MAX_NUM 75 #define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT 76 #endif 77 78 /* * 79 * @ingroup los_arch_interrupt 80 * Highest priority of a hardware interrupt. 81 */ 82 #ifndef OS_HWI_PRIO_HIGHEST 83 #define OS_HWI_PRIO_HIGHEST 0 84 #endif 85 86 /* * 87 * @ingroup los_arch_interrupt 88 * Lowest priority of a hardware interrupt. 89 */ 90 #ifndef OS_HWI_PRIO_LOWEST 91 #define OS_HWI_PRIO_LOWEST 7 92 #endif 93 94 #define OS_EXC_IN_INIT 0 95 #define OS_EXC_IN_TASK 1 96 #define OS_EXC_IN_HWI 2 97 98 /* * 99 * @ingroup los_arch_interrupt 100 * Define the type of a hardware interrupt vector table function. 101 */ 102 typedef VOID (**HWI_VECTOR_FUNC)(VOID); 103 104 /* * 105 * @ingroup los_arch_interrupt 106 * Count of interrupts. 107 */ 108 extern UINT32 g_intCount; 109 110 /* * 111 * @ingroup los_arch_interrupt 112 * Count of Xtensa system interrupt vector. 113 */ 114 #define OS_SYS_VECTOR_CNT 0 115 116 /* * 117 * @ingroup los_arch_interrupt 118 * Count of Xtensa interrupt vector. 119 */ 120 #define OS_VECTOR_CNT (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM) 121 122 /* * 123 * @ingroup los_arch_interrupt 124 * Hardware interrupt error code: Invalid interrupt number. 125 * 126 * Value: 0x02000900 127 * 128 * Solution: Ensure that the interrupt number is valid. 129 */ 130 #define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00) 131 132 /* * 133 * @ingroup los_arch_interrupt 134 * Hardware interrupt error code: Null hardware interrupt handling function. 135 * 136 * Value: 0x02000901 137 * 138 * Solution: Pass in a valid non-null hardware interrupt handling function. 139 */ 140 #define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01) 141 142 /* * 143 * @ingroup los_arch_interrupt 144 * Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation. 145 * 146 * Value: 0x02000902 147 * 148 * Solution: Increase the configured maximum number of supported hardware interrupts. 149 */ 150 #define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02) 151 152 /* * 153 * @ingroup los_arch_interrupt 154 * Hardware interrupt error code: Insufficient memory for hardware interrupt initialization. 155 * 156 * Value: 0x02000903 157 * 158 * Solution: Expand the configured memory. 159 */ 160 #define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03) 161 162 /* * 163 * @ingroup los_arch_interrupt 164 * Hardware interrupt error code: The interrupt has already been created. 165 * 166 * Value: 0x02000904 167 * 168 * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created. 169 */ 170 #define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04) 171 172 /* * 173 * @ingroup los_arch_interrupt 174 * Hardware interrupt error code: Invalid interrupt priority. 175 * 176 * Value: 0x02000905 177 * 178 * Solution: Ensure that the interrupt priority is valid. 179 */ 180 #define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05) 181 182 /* * 183 * @ingroup los_arch_interrupt 184 * Hardware interrupt error code: Incorrect interrupt creation mode. 185 * 186 * Value: 0x02000906 187 * 188 * Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST. 189 */ 190 #define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06) 191 192 /* * 193 * @ingroup los_arch_interrupt 194 * Hardware interrupt error code: The interrupt has already been created as a fast interrupt. 195 * 196 * Value: 0x02000907 197 * 198 * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created. 199 */ 200 #define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07) 201 202 #if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) 203 /* * 204 * @ingroup los_arch_interrupt 205 * Set interrupt vector table. 206 */ 207 extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg); 208 #else 209 /* * 210 * @ingroup los_arch_interrupt 211 * Set interrupt vector table. 212 */ 213 extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector); 214 #endif 215 216 VOID HalInterrupt(VOID); 217 VOID HalHwiDefaultHandler(VOID); 218 VOID HalExcHandleEntry(UINTPTR faultAddr, EXC_CONTEXT_S *excBufAddr, UINT32 type); 219 VOID HalHwiInit(VOID); 220 221 /** 222 * @ingroup los_exc 223 * Exception information structure 224 * 225 * Description: Exception information saved when an exception is triggered on the Xtensa platform. 226 * 227 */ 228 typedef struct TagExcInfo { 229 UINT16 phase; 230 UINT16 type; 231 UINT32 faultAddr; 232 UINT32 thrdPid; 233 UINT16 nestCnt; 234 UINT16 reserved; 235 EXC_CONTEXT_S *context; 236 } ExcInfo; 237 238 extern UINT32 g_curNestCount; 239 extern ExcInfo g_excInfo; 240 241 #define MAX_INT_INFO_SIZE (8 + 0x164) 242 243 #ifdef __cplusplus 244 #if __cplusplus 245 } 246 #endif /* __cplusplus */ 247 #endif /* __cplusplus */ 248 249 #endif /* _LOS_ARCH_INTERRUPT_H */ 250