1 /*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2022 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 #include "los_config.h"
35 #include "los_compiler.h"
36
37 #ifdef __cplusplus
38 #if __cplusplus
39 extern "C" {
40 #endif /* __cplusplus */
41 #endif /* __cplusplus */
42
43 typedef UINT32 HWI_HANDLE_T;
44
45 typedef UINT16 HWI_PRIOR_T;
46
47 typedef UINT16 HWI_MODE_T;
48
49 typedef UINT32 HWI_ARG_T;
50
51 #if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
52 typedef VOID (*HWI_PROC_FUNC)(VOID *parm);
53 #else
54 typedef VOID (*HWI_PROC_FUNC)(void);
55 #endif
56 typedef struct tagIrqParam {
57 int swIrq; /**< The interrupt number */
58 VOID *pDevId; /**< The pointer to the device ID that launches the interrupt */
59 const CHAR *pName; /**< The interrupt name */
60 } HwiIrqParam;
61
62 typedef struct {
63 UINT32 (*triggerIrq)(HWI_HANDLE_T hwiNum);
64 UINT32 (*clearIrq)(HWI_HANDLE_T hwiNum);
65 UINT32 (*enableIrq)(HWI_HANDLE_T hwiNum);
66 UINT32 (*disableIrq)(HWI_HANDLE_T hwiNum);
67 UINT32 (*setIrqPriority)(HWI_HANDLE_T hwiNum, UINT8 priority);
68 UINT32 (*getCurIrqNum)(VOID);
69 } HwiControllerOps;
70
71 extern HwiControllerOps g_archHwiOps;
72
73 /* stack protector */
74 extern UINT32 __stack_chk_guard;
75
76 extern VOID __stack_chk_fail(VOID);
77
78 UINT32 ArchIsIntActive(VOID);
79 #define OS_INT_ACTIVE (ArchIsIntActive())
80 #define OS_INT_INACTIVE (!(OS_INT_ACTIVE))
81 #define LOS_HwiCreate ArchHwiCreate
82 #define LOS_HwiDelete ArchHwiDelete
83 #define LOS_HwiTrigger ArchIntTrigger
84 #define LOS_HwiEnable ArchIntEnable
85 #define LOS_HwiDisable ArchIntDisable
86 #define LOS_HwiClear ArchIntClear
87 #define LOS_HwiSetPriority ArchIntSetPriority
88 #define LOS_HwiCurIrqNum ArchIntCurIrqNum
89
90 UINT32 ArchIntLock(VOID);
91 #define LOS_IntLock ArchIntLock
92
93 VOID ArchIntRestore(UINT32 intSave);
94 #define LOS_IntRestore ArchIntRestore
95
96 UINT32 ArchIntUnLock(VOID);
97 #define LOS_IntUnLock ArchIntUnLock
98
99 #define LOS_HwiOpsGet ArchIntOpsGet
100
101 /**
102 * @ingroup los_interrupt
103 * @brief Delete hardware interrupt.
104 *
105 * @par Description:
106 * This API is used to delete hardware interrupt.
107 *
108 * @attention
109 * <ul>
110 * <li>The hardware interrupt module is usable only when the configuration item for hardware
111 * interrupt tailoring is enabled.</li>
112 * <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range
113 * applicable for a Cortex-A7 platform is [32,95].</li>
114 * <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
115 * <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
116 * </ul>
117 *
118 * @param hwiNum [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable
119 * for a Cortex-A7 platform is [32,95].
120 * @param irqParam [IN] Type #HwiIrqParam *. ID of hardware interrupt which will base on
121 * when delete the hardware interrupt.
122 * @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number.
123 * @retval #LOS_OK 0 : The interrupt is successfully delete.
124 * @par Dependency:
125 * <ul><li>los_interrupt.h: the header file that contains the API declaration.</li></ul>
126 * @see None.
127 */
128 UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam);
129
130 /**
131 * @ingroup los_interrupt
132 * @brief Create a hardware interrupt.
133 *
134 * @par Description:
135 * This API is used to configure a hardware interrupt and register a hardware interrupt handling function.
136 *
137 * @attention
138 * <ul>
139 * <li>The hardware interrupt module is usable only when the configuration item for hardware
140 * interrupt tailoring is enabled.</li>
141 * <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range
142 * applicable for a Cortex-A7 platform is [32,95].</li>
143 * <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
144 * <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
145 * </ul>
146 *
147 * @param hwiNum [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a
148 * Cortex-A7 platform is [32,95].
149 * @param hwiPrio [IN] Type#HWI_PRIOR_T: hardware interrupt priority. Ignore this parameter temporarily.
150 * @param mode [IN] Type#HWI_MODE_T: hardware interrupt mode. Ignore this parameter temporarily.
151 * @param handler [IN] Type#HWI_PROC_FUNC: interrupt handler used when a hardware interrupt is triggered.
152 * @param irqParam [IN] Type#HwiIrqParam: input parameter of the interrupt
153 * handler used when a hardware interrupt is triggered.
154 *
155 * @retval #OS_ERRNO_HWI_PROC_FUNC_NULL 0x02000901: Null hardware interrupt handling function.
156 * @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number.
157 * @retval #OS_ERRNO_HWI_NO_MEMORY 0x02000903: Insufficient memory for hardware interrupt creation.
158 * @retval #OS_ERRNO_HWI_ALREADY_CREATED 0x02000904: The interrupt handler being created has
159 * already been created.
160 * @retval #LOS_OK 0 : The interrupt is successfully created.
161 * @par Dependency:
162 * <ul><li>los_interrupt.h: the header file that contains the API declaration.</li></ul>
163 * @see None.
164 */
165 UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
166 HWI_PRIOR_T hwiPrio,
167 HWI_MODE_T mode,
168 HWI_PROC_FUNC handler,
169 HwiIrqParam *irqParam);
170
ArchIntTrigger(HWI_HANDLE_T hwiNum)171 STATIC INLINE UINT32 ArchIntTrigger(HWI_HANDLE_T hwiNum)
172 {
173 if (g_archHwiOps.triggerIrq == NULL) {
174 return LOS_NOK;
175 }
176 return g_archHwiOps.triggerIrq(hwiNum);
177 }
178
ArchIntEnable(HWI_HANDLE_T hwiNum)179 STATIC INLINE UINT32 ArchIntEnable(HWI_HANDLE_T hwiNum)
180 {
181 if (g_archHwiOps.enableIrq == NULL) {
182 return LOS_NOK;
183 }
184 return g_archHwiOps.enableIrq(hwiNum);
185 }
186
ArchIntDisable(HWI_HANDLE_T hwiNum)187 STATIC INLINE UINT32 ArchIntDisable(HWI_HANDLE_T hwiNum)
188 {
189 if (g_archHwiOps.disableIrq == NULL) {
190 return LOS_NOK;
191 }
192 return g_archHwiOps.disableIrq(hwiNum);
193 }
194
ArchIntClear(HWI_HANDLE_T hwiNum)195 STATIC INLINE UINT32 ArchIntClear(HWI_HANDLE_T hwiNum)
196 {
197 if (g_archHwiOps.clearIrq == NULL) {
198 return LOS_NOK;
199 }
200 return g_archHwiOps.clearIrq(hwiNum);
201 }
202
ArchIntSetPriority(HWI_HANDLE_T hwiNum,HWI_PRIOR_T priority)203 STATIC INLINE UINT32 ArchIntSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority)
204 {
205 if (g_archHwiOps.setIrqPriority == NULL) {
206 return LOS_NOK;
207 }
208 return g_archHwiOps.setIrqPriority(hwiNum, priority);
209 }
210
ArchIntCurIrqNum(VOID)211 STATIC INLINE UINT32 ArchIntCurIrqNum(VOID)
212 {
213 if (g_archHwiOps.getCurIrqNum == NULL) {
214 return LOS_NOK;
215 }
216 return g_archHwiOps.getCurIrqNum();
217 }
218
ArchIntOpsGet(VOID)219 STATIC INLINE HwiControllerOps *ArchIntOpsGet(VOID)
220 {
221 return &g_archHwiOps;
222 }
223
224 #if (LOSCFG_DEBUG_TOOLS == 1)
225 extern UINT32 OsGetHwiFormCnt(UINT32 index);
226 extern CHAR *OsGetHwiFormName(UINT32 index);
227 extern BOOL OsGetHwiCreated(UINT32 index);
228 #endif
229
230 #ifdef __cplusplus
231 #if __cplusplus
232 }
233 #endif /* __cplusplus */
234 #endif /* __cplusplus */
235
236 #endif /* _LOS_INTERRUPT_H */
237