• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2009-12-22
13  * Description: hwi模块内部头文件。
14  */
15 #ifndef PRT_HWI_INTERNAL_H
16 #define PRT_HWI_INTERNAL_H
17 
18 #include "prt_hwi_external.h"
19 #include "prt_sys_external.h"
20 #include "prt_irq_external.h"
21 
22 /*
23  * 模块内宏定义
24  */
25 #define OS_EXC_RESET                                1
26 #define OS_EXC_NMI                                  2
27 #define OS_EXC_HARD_FAULT                           3
28 #define OS_EXC_MPU_FAULT                            4
29 #define OS_EXC_BUS_FAULT                            5
30 #define OS_EXC_USAGE_FAULT                          6
31 #define OS_EXC_SVC_CALL                             11
32 #define OS_EXC_PEND_SV                              14
33 #define OS_EXC_SYS_TICK                             15
34 
35 #define OS_SYS_HWI_NUM                              16
36 #define OS_HWI_NUM_SHIFT_BIT                        5
37 #define OS_NVIC_AIRCR_REG_ACCESS_PSW                0x05FA0000U
38 #define OS_NVIC_AIRCR_PRIGOUP_BIT_OFFSET            8  /* [10:8]位标识优先级分组 */
39 
40 #define OS_HWI_ENABLE 1 /* HW使能标识 */
41 #define OS_HWI_CLRPEND_REG_NUM (((OS_MX_IRQ_VECTOR_CNT + 31) / 32) << 2) /* 清除PEND位寄存器数 */
42 #define OS_SET_VECTOR(num, vector) (g_hwiTable[(num)] = (vector))
43 #define OS_GET_HWI_REG_OFFSET(hwiNum) (((hwiNum) >> OS_HWI_NUM_SHIFT_BIT) << 2)
44 
45 /*
46  * 模块间函数声明
47  */
48 extern void OsExcNmi(void);
49 extern void OsExcMemFault(void);
50 extern void OsExcBusFault(void);
51 extern void OsExcUsageFault(void);
52 extern void OsExcSvcCall(void);
53 extern void OsExcHardFault(void);
54 extern void OsSvchandler(void);
55 extern void OsResetVector(void);
56 extern void OsPendSv(void);
57 extern void OsInterrupt(void);
58 
59 /* ** 向量表偏移量寄存器 VTOR */
60 #define OS_NVIC_VTOR 0xE000ED08UL
61 
62 /* ** 中断优先级寄存器阵列 */
63 #define OS_NVIC_PRI_BASE 0xE000E400UL
64 
65 /* ** 中断使能寄存器族 SETENA 0xE000E100-0xE000E11C */
66 #define OS_NVIC_SETENA_BASE 0xE000E100UL
67 
68 /* ** 中断除能寄存器族 CLRENA 0xE000E180-0xE000E19C */
69 #define OS_NVIC_CLRENA_BASE 0xE000E180UL
70 
71 /* ** 系统异常优先级寄存器阵列 */
72 #define OS_NVIC_EXCPRI_BASE 0xE000ED18UL
73 
74 /* *** 中断控制及状态寄存器 ICSR */
75 #define OS_NVIC_INT_CTRL 0xE000ED04UL
76 
77 /* ** 中断悬起清除寄存器(CLRPEND) 0xE000E280 - 0xE000_E29C */
78 #define OS_NVIC_CLRPEND_BASE 0xE000E280UL
79 
80 /* ** 中断设置悬起寄存器(SETPEND) 0xE000_E200 –0xE000_E21C */
81 #define OS_NVIC_SETPEND_BASE 0xE000E200UL
82 
83 /* 应用程序中断及复位控制寄存器 AIRCR */
84 #define OS_NVIC_AIRCR 0xE000ED0CUL
85 
86 /* 使能中断位,寄存器置1有效,置0情况下不影响 */
87 #define NVIC_SET_IRQ(hwiNum)                                                                                     \
88     do {                                                                                                         \
89         *(volatile U32 *)((uintptr_t)OS_NVIC_SETENA_BASE + (((hwiNum) >> 5) << 2)) = 1UL << ((hwiNum) & 0x1FUL); \
90     } while (0)
91 
92 /* 清除中断位,寄存器置1有效,置0情况下不影响 */
93 #define NVIC_CLR_IRQ(hwiNum)                                                                                     \
94     do {                                                                                                         \
95         *(volatile U32 *)((uintptr_t)OS_NVIC_CLRENA_BASE + (((hwiNum) >> 5) << 2)) = 1UL << ((hwiNum) & 0x1FUL); \
96     } while (0)
97 
98 /* 设置中断优先级 */
99 #define NVIC_SET_IRQ_PRI(hwiNum, pri)                                         \
100     do {                                                                      \
101         *(volatile U8 *)((uintptr_t)OS_NVIC_PRI_BASE + (hwiNum)) = (U8)(pri); \
102     } while (0)
103 
104 /* 设置异常优先级 */
105 #define NVIC_SET_EXC_PRI(excNum, pri)                                                  \
106     do {                                                                               \
107         *(volatile U8 *)((uintptr_t)OS_NVIC_EXCPRI_BASE + ((excNum) - 4)) = (U8)(pri); \
108     } while (0)
109 
110 /* 清除悬起中断位 */
111 #define NVIC_CLR_IRQ_PEND(hwiNum)                                                                                 \
112     do {                                                                                                          \
113         *(volatile U32 *)((uintptr_t)OS_NVIC_CLRPEND_BASE + (((hwiNum) >> 5) << 2)) = 1UL << ((hwiNum) & 0x1FUL); \
114     } while (0)
115 
116 /* 设置悬起中断位 */
117 #define NVIC_SET_IRQ_PEND(hwiNum)                                                                                 \
118     do {                                                                                                          \
119         *(volatile U32 *)((uintptr_t)OS_NVIC_SETPEND_BASE + (((hwiNum) >> 5) << 2)) = 1UL << ((hwiNum) & 0x1FUL); \
120     } while (0)
121 
122 #endif /* PRT_HWI_INTERNAL_H */
123