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 /* * 46 * @ingroup los_arch_interrupt 47 * Maximum number of used hardware interrupts. 48 */ 49 #ifndef OS_HWI_MAX_NUM 50 #define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT 51 #endif 52 53 /* * 54 * @ingroup los_arch_interrupt 55 * Highest priority of a hardware interrupt. 56 */ 57 #ifndef OS_HWI_PRIO_HIGHEST 58 #define OS_HWI_PRIO_HIGHEST 0 59 #endif 60 61 /* * 62 * @ingroup los_arch_interrupt 63 * Lowest priority of a hardware interrupt. 64 */ 65 #ifndef OS_HWI_PRIO_LOWEST 66 #define OS_HWI_PRIO_LOWEST 3 67 #endif 68 69 /* * 70 * @ingroup los_arch_interrupt 71 * Check the interrupt priority. 72 */ 73 #define HWI_PRI_VALID(pri) (((pri) >= OS_HWI_PRIO_HIGHEST) && ((pri) <= OS_HWI_PRIO_LOWEST)) 74 75 /* * 76 * @ingroup los_arch_interrupt 77 * Define the type of a hardware interrupt vector table function. 78 */ 79 typedef VOID (**HWI_VECTOR_FUNC)(VOID); 80 81 /* * 82 * @ingroup los_arch_interrupt 83 * Count of interrupts. 84 */ 85 extern volatile UINT32 g_intCount; 86 87 /* * 88 * @ingroup los_arch_interrupt 89 * Count of C-sky system interrupt vector. 90 */ 91 #define OS_SYS_VECTOR_CNT 32 92 93 /* * 94 * @ingroup los_arch_interrupt 95 * Count of C-sky interrupt vector. 96 */ 97 #define OS_VECTOR_CNT (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM) 98 99 #define PSR_VEC_OFFSET 16U 100 #define VIC_REG_BASE 0xE000E100UL 101 102 typedef struct { 103 UINT32 ISER[4U]; 104 UINT32 RESERVED0[12U]; 105 UINT32 IWER[4U]; 106 UINT32 RESERVED1[12U]; 107 UINT32 ICER[4U]; 108 UINT32 RESERVED2[12U]; 109 UINT32 IWDR[4U]; 110 UINT32 RESERVED3[12U]; 111 UINT32 ISPR[4U]; 112 UINT32 RESERVED4[12U]; 113 UINT32 ISSR[4U]; 114 UINT32 RESERVED5[12U]; 115 UINT32 ICPR[4U]; 116 UINT32 RESERVED6[12U]; 117 UINT32 ICSR[4U]; 118 UINT32 RESERVED7[12U]; 119 UINT32 IABR[4U]; 120 UINT32 RESERVED8[60U]; 121 UINT32 IPR[32U]; 122 UINT32 RESERVED9[480U]; 123 UINT32 ISR; 124 UINT32 IPTR; 125 UINT32 TSPEND; 126 UINT32 TSABR; 127 UINT32 TSPR; 128 } VIC_TYPE; 129 130 extern VIC_TYPE *VIC_REG; 131 /* * 132 * @ingroup los_arch_interrupt 133 * Hardware interrupt error code: Invalid interrupt number. 134 * 135 * Value: 0x02000900 136 * 137 * Solution: Ensure that the interrupt number is valid. 138 */ 139 #define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00) 140 141 /* * 142 * @ingroup los_arch_interrupt 143 * Hardware interrupt error code: Null hardware interrupt handling function. 144 * 145 * Value: 0x02000901 146 * 147 * Solution: Pass in a valid non-null hardware interrupt handling function. 148 */ 149 #define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01) 150 151 /* * 152 * @ingroup los_arch_interrupt 153 * Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation. 154 * 155 * Value: 0x02000902 156 * 157 * Solution: Increase the configured maximum number of supported hardware interrupts. 158 */ 159 #define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02) 160 161 /* * 162 * @ingroup los_arch_interrupt 163 * Hardware interrupt error code: Insufficient memory for hardware interrupt initialization. 164 * 165 * Value: 0x02000903 166 * 167 * Solution: Expand the configured memory. 168 */ 169 #define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03) 170 171 /* * 172 * @ingroup los_arch_interrupt 173 * Hardware interrupt error code: The interrupt has already been created. 174 * 175 * Value: 0x02000904 176 * 177 * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created. 178 */ 179 #define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04) 180 181 /* * 182 * @ingroup los_arch_interrupt 183 * Hardware interrupt error code: Invalid interrupt priority. 184 * 185 * Value: 0x02000905 186 * 187 * Solution: Ensure that the interrupt priority is valid. 188 */ 189 #define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05) 190 191 /* * 192 * @ingroup los_arch_interrupt 193 * Hardware interrupt error code: Incorrect interrupt creation mode. 194 * 195 * Value: 0x02000906 196 * 197 * Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST. 198 */ 199 #define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06) 200 201 /* * 202 * @ingroup los_arch_interrupt 203 * Hardware interrupt error code: The interrupt has already been created as a fast interrupt. 204 * 205 * Value: 0x02000907 206 * 207 * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created. 208 */ 209 #define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07) 210 211 /* * 212 * @ingroup los_arch_interrupt 213 * Hardware interrupt error code: Invalid interrupt number. 214 * 215 * Value: 0x02000900 216 * 217 * Solution: Ensure that the interrupt number is valid. 218 */ 219 #define LOS_ERRNO_HWI_NUM_INVALID OS_ERRNO_HWI_NUM_INVALID 220 221 #if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) 222 /* * 223 * @ingroup los_arch_interrupt 224 * Set interrupt vector table. 225 */ 226 extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg); 227 #else 228 /* * 229 * @ingroup los_arch_interrupt 230 * Set interrupt vector table. 231 */ 232 extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector); 233 #endif 234 235 /* * 236 * @ingroup los_arch_interrupt 237 * @brief: Hardware interrupt entry function. 238 * 239 * @par Description: 240 * This API is used as all hardware interrupt handling function entry. 241 * 242 * @attention: 243 * <ul><li>None.</li></ul> 244 * 245 * @param:None. 246 * 247 * @retval:None. 248 * @par Dependency: 249 * <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul> 250 * @see None. 251 */ 252 extern VOID HalInterrupt(VOID); 253 254 /* * 255 * @ingroup los_arch_interrupt 256 * @brief: Default vector handling function. 257 * 258 * @par Description: 259 * This API is used to configure interrupt for null function. 260 * 261 * @attention: 262 * <ul><li>None.</li></ul> 263 * 264 * @param:None. 265 * 266 * @retval:None. 267 * @par Dependency: 268 * <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul> 269 * @see None. 270 */ 271 extern VOID HalHwiDefaultHandler(VOID); 272 273 #define OS_EXC_IN_INIT 0 274 #define OS_EXC_IN_TASK 1 275 #define OS_EXC_IN_HWI 2 276 277 #define OS_VIC_INT_ENABLE_SIZE 0x4 278 #define OS_VIC_INT_WAKER_SIZE 0x4 279 #define OS_VIC_INT_ICER_SIZE 0x4 280 #define OS_VIC_INT_ISPR_SIZE 0x4 281 #define OS_VIC_INT_IABR_SIZE 0x4 282 #define OS_VIC_INT_IPR_SIZE 0x4 283 #define OS_VIC_INT_ISR_SIZE 0x4 284 #define OS_VIC_INT_IPTR_SIZE 0x4 285 286 #define OS_EXC_FLAG_FAULTADDR_VALID 0x01 287 288 #define OS_EXC_IMPRECISE_ACCESS_ADDR 0xABABABAB 289 290 /** 291 * @ingroup los_exc 292 * the struct of register files 293 * 294 * description: the register files that saved when exception triggered 295 * 296 * notes:the following register with prefix 'uw' correspond to the registers in the cpu data sheet. 297 */ 298 typedef struct TagExcContext { 299 UINT32 R0; 300 UINT32 R1; 301 UINT32 R2; 302 UINT32 R3; 303 UINT32 R4; 304 UINT32 R5; 305 UINT32 R6; 306 UINT32 R7; 307 UINT32 R8; 308 UINT32 R9; 309 UINT32 R10; 310 UINT32 R11; 311 UINT32 R12; 312 UINT32 R13; 313 UINT32 R14; 314 UINT32 R15; 315 UINT32 EPSR; 316 UINT32 EPC; 317 } EXC_CONTEXT_S; 318 319 /* * 320 * @ingroup los_arch_interrupt 321 * @brief: Exception handler function. 322 * 323 * @par Description: 324 * This API is used to handle Exception. 325 * 326 * @attention: 327 * <ul><li>None.</li></ul> 328 * 329 * @param excBufAddr [IN] The address of stack pointer at which the error occurred. 330 * @param faultAddr [IN] The address at which the error occurred. 331 * 332 * @retval:None. 333 * @par Dependency: 334 * <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul> 335 * @see None. 336 */ 337 LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(EXC_CONTEXT_S *excBufAddr, UINT32 faultAddr); 338 339 VOID IrqEntry(VOID); 340 341 VOID HandleEntry(VOID); 342 343 VOID HalHwiInit(VOID); 344 345 /** 346 * @ingroup los_exc 347 * Exception information structure 348 * 349 * Description: Exception information saved when an exception is triggered on the Csky platform. 350 * 351 */ 352 typedef struct TagExcInfo { 353 UINT16 phase; 354 UINT16 type; 355 UINT32 faultAddr; 356 UINT32 thrdPid; 357 UINT16 nestCnt; 358 UINT16 reserved; 359 EXC_CONTEXT_S *context; 360 } ExcInfo; 361 362 extern ExcInfo g_excInfo; 363 364 #define MAX_INT_INFO_SIZE (8 + 0x164) 365 366 #ifdef __cplusplus 367 #if __cplusplus 368 } 369 #endif /* __cplusplus */ 370 #endif /* __cplusplus */ 371 372 #endif /* _LOS_ARCH_INTERRUPT_H */ 373