• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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 interrupt tailoring is enabled.</li>
111  * <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range applicable for a Cortex-A7 platform is [32,95].</li>
112  * <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
113  * <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
114  * </ul>
115  *
116  * @param  hwiNum   [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a Cortex-A7 platform is [32,95].
117  * @param  irqParam [IN] Type #HwiIrqParam *. ID of hardware interrupt which will base on
118  *                                                when delete the hardware interrupt.
119  * @retval #OS_ERRNO_HWI_NUM_INVALID              0x02000900: Invalid interrupt number.
120  * @retval #LOS_OK                                0         : The interrupt is successfully delete.
121  * @par Dependency:
122  * <ul><li>los_interrupt.h: the header file that contains the API declaration.</li></ul>
123  * @see None.
124  */
125 UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam);
126 
127 /**
128  * @ingroup  los_interrupt
129  * @brief Create a hardware interrupt.
130  *
131  * @par Description:
132  * This API is used to configure a hardware interrupt and register a hardware interrupt handling function.
133  *
134  * @attention
135  * <ul>
136  * <li>The hardware interrupt module is usable only when the configuration item for hardware interrupt tailoring is enabled.</li>
137  * <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range applicable for a Cortex-A7 platform is [32,95].</li>
138  * <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
139  * <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
140  * </ul>
141  *
142  * @param  hwiNum   [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a Cortex-A7 platform is [32,95].
143  * @param  hwiPrio  [IN] Type#HWI_PRIOR_T: hardware interrupt priority. Ignore this parameter temporarily.
144  * @param  mode     [IN] Type#HWI_MODE_T: hardware interrupt mode. Ignore this parameter temporarily.
145  * @param  handler  [IN] Type#HWI_PROC_FUNC: interrupt handler used when a hardware interrupt is triggered.
146  * @param  irqParam [IN] Type#HwiIrqParam: input parameter of the interrupt
147  *                                         handler used when a hardware interrupt is triggered.
148  *
149  * @retval #OS_ERRNO_HWI_PROC_FUNC_NULL               0x02000901: Null hardware interrupt handling function.
150  * @retval #OS_ERRNO_HWI_NUM_INVALID                  0x02000900: Invalid interrupt number.
151  * @retval #OS_ERRNO_HWI_NO_MEMORY                    0x02000903: Insufficient memory for hardware interrupt creation.
152  * @retval #OS_ERRNO_HWI_ALREADY_CREATED              0x02000904: The interrupt handler being created has already been created.
153  * @retval #LOS_OK                                    0         : The interrupt is successfully created.
154  * @par Dependency:
155  * <ul><li>los_interrupt.h: the header file that contains the API declaration.</li></ul>
156  * @see None.
157  */
158 UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
159                      HWI_PRIOR_T hwiPrio,
160                      HWI_MODE_T mode,
161                      HWI_PROC_FUNC handler,
162                      HwiIrqParam *irqParam);
163 
ArchIntTrigger(HWI_HANDLE_T hwiNum)164 STATIC INLINE UINT32 ArchIntTrigger(HWI_HANDLE_T hwiNum)
165 {
166     if (g_archHwiOps.triggerIrq == NULL) {
167         return LOS_NOK;
168     }
169     return g_archHwiOps.triggerIrq(hwiNum);
170 }
171 
ArchIntEnable(HWI_HANDLE_T hwiNum)172 STATIC INLINE UINT32 ArchIntEnable(HWI_HANDLE_T hwiNum)
173 {
174     if (g_archHwiOps.enableIrq == NULL) {
175         return LOS_NOK;
176     }
177     return g_archHwiOps.enableIrq(hwiNum);
178 }
179 
ArchIntDisable(HWI_HANDLE_T hwiNum)180 STATIC INLINE UINT32 ArchIntDisable(HWI_HANDLE_T hwiNum)
181 {
182     if (g_archHwiOps.disableIrq == NULL) {
183         return LOS_NOK;
184     }
185     return g_archHwiOps.disableIrq(hwiNum);
186 }
187 
ArchIntClear(HWI_HANDLE_T hwiNum)188 STATIC INLINE UINT32 ArchIntClear(HWI_HANDLE_T hwiNum)
189 {
190     if (g_archHwiOps.clearIrq == NULL) {
191         return LOS_NOK;
192     }
193     return g_archHwiOps.clearIrq(hwiNum);
194 }
195 
ArchIntSetPriority(HWI_HANDLE_T hwiNum,HWI_PRIOR_T priority)196 STATIC INLINE UINT32 ArchIntSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority)
197 {
198     if (g_archHwiOps.setIrqPriority == NULL) {
199         return LOS_NOK;
200     }
201     return g_archHwiOps.setIrqPriority(hwiNum, priority);
202 }
203 
ArchIntCurIrqNum(VOID)204 STATIC INLINE UINT32 ArchIntCurIrqNum(VOID)
205 {
206     if (g_archHwiOps.getCurIrqNum == NULL) {
207         return LOS_NOK;
208     }
209     return g_archHwiOps.getCurIrqNum();
210 }
211 
ArchIntOpsGet(VOID)212 STATIC INLINE HwiControllerOps *ArchIntOpsGet(VOID)
213 {
214     return &g_archHwiOps;
215 }
216 
217 #ifdef __cplusplus
218 #if __cplusplus
219 }
220 #endif /* __cplusplus */
221 #endif /* __cplusplus */
222 
223 #endif /* _LOS_INTERRUPT_H */
224