• 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_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                    7
67 #endif
68 
69 
70 /* *
71  * @ingroup  los_arch_interrupt
72  * Define the type of a hardware interrupt vector table function.
73  */
74 typedef VOID (**HWI_VECTOR_FUNC)(void);
75 
76 /* *
77  * @ingroup los_arch_interrupt
78  * Count of interrupts.
79  */
80 extern UINT32 g_intCount;
81 
82 /* *
83  * @ingroup los_arch_interrupt
84  * Count of arm9 system interrupt vector.
85  */
86 #define OS_SYS_VECTOR_CNT                     0
87 
88 /* *
89  * @ingroup los_arch_interrupt
90  * Count of arm9 interrupt vector.
91  */
92 #define OS_VECTOR_CNT                         (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM)
93 
94 /* *
95  * @ingroup los_arch_interrupt
96  * Hardware interrupt error code: Invalid interrupt number.
97  *
98  * Value: 0x02000900
99  *
100  * Solution: Ensure that the interrupt number is valid.
101  * The value range of the interrupt number applicable for a arm9 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
102  */
103 #define OS_ERRNO_HWI_NUM_INVALID              LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
104 
105 /* *
106  * @ingroup los_arch_interrupt
107  * Hardware interrupt error code: Null hardware interrupt handling function.
108  *
109  * Value: 0x02000901
110  *
111  * Solution: Pass in a valid non-null hardware interrupt handling function.
112  */
113 #define OS_ERRNO_HWI_PROC_FUNC_NULL           LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
114 
115 /* *
116  * @ingroup los_arch_interrupt
117  * Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation.
118  *
119  * Value: 0x02000902
120  *
121  * Solution: Increase the configured maximum number of supported hardware interrupts.
122  */
123 #define OS_ERRNO_HWI_CB_UNAVAILABLE           LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
124 
125 /* *
126  * @ingroup los_arch_interrupt
127  * Hardware interrupt error code: Insufficient memory for hardware interrupt initialization.
128  *
129  * Value: 0x02000903
130  *
131  * Solution: Expand the configured memory.
132  */
133 #define OS_ERRNO_HWI_NO_MEMORY                LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
134 
135 /* *
136  * @ingroup los_arch_interrupt
137  * Hardware interrupt error code: The interrupt has already been created.
138  *
139  * Value: 0x02000904
140  *
141  * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
142  */
143 #define OS_ERRNO_HWI_ALREADY_CREATED          LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
144 
145 /* *
146  * @ingroup los_arch_interrupt
147  * Hardware interrupt error code: Invalid interrupt priority.
148  *
149  * Value: 0x02000905
150  *
151  * Solution: Ensure that the interrupt priority is valid.
152  * The value range of the interrupt priority applicable for a arm9 platform is [0,15].
153  */
154 #define OS_ERRNO_HWI_PRIO_INVALID             LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
155 
156 /* *
157  * @ingroup los_arch_interrupt
158  * Hardware interrupt error code: Incorrect interrupt creation mode.
159  *
160  * Value: 0x02000906
161  *
162  * Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or
163  * OS_HWI_MODE_FAST of which the value can be 0 or 1.
164  */
165 #define OS_ERRNO_HWI_MODE_INVALID             LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
166 
167 /* *
168  * @ingroup los_arch_interrupt
169  * Hardware interrupt error code: The interrupt has already been created as a fast interrupt.
170  *
171  * Value: 0x02000907
172  *
173  * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
174  */
175 #define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
176 
177 #if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
178 /* *
179  * @ingroup los_hwi
180  * Set interrupt vector table.
181  */
182 extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg);
183 #else
184 /* *
185  * @ingroup los_hwi
186  * Set interrupt vector table.
187  */
188 extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
189 #endif
190 
191 /* *
192  * @ingroup  los_arch_interrupt
193  * @brief: Hardware interrupt entry function.
194  *
195  * @par Description:
196  * This API is used as all hardware interrupt handling function entry.
197  *
198  * @attention:
199  * <ul><li>None.</li></ul>
200  *
201  * @param:None.
202  *
203  * @retval:None.
204  * @par Dependency:
205  * <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
206  * @see None.
207  */
208 extern VOID HalInterrupt(VOID);
209 
210 /* *
211  * @ingroup  los_arch_interrupt
212  * @brief: Default vector handling function.
213  *
214  * @par Description:
215  * This API is used to configure interrupt for null function.
216  *
217  * @attention:
218  * <ul><li>None.</li></ul>
219  *
220  * @param:None.
221  *
222  * @retval:None.
223  * @par Dependency:
224  * <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li
225 ></ul>
226  * @see None.
227  */
228 extern VOID HalHwiDefaultHandler(VOID);
229 
230 #define OS_EXC_IN_INIT                      0
231 #define OS_EXC_IN_TASK                      1
232 #define OS_EXC_IN_HWI                       2
233 
234 #define OS_EXC_FLAG_FAULTADDR_VALID         0x01
235 #define OS_EXC_FLAG_IN_HWI                  0x02
236 
237 #define OS_EXC_IMPRECISE_ACCESS_ADDR        0xABABABAB
238 
239 /**
240  * @ingroup los_exc
241  * the struct of register files
242  *
243  * description: the register files that saved when exception triggered
244  *
245  * notes:the following register with prefix 'uw'  correspond to the registers in the cpu  data sheet.
246  */
247 typedef struct TagExcContext {
248     UINT32 spsr;
249     UINT32 r0;
250     UINT32 r1;
251     UINT32 r2;
252     UINT32 r3;
253     UINT32 r4;
254     UINT32 r5;
255     UINT32 r6;
256     UINT32 r7;
257     UINT32 r8;
258     UINT32 r9;
259     UINT32 r10;
260     UINT32 r11;
261     UINT32 r12;
262     UINT32 sp;
263     UINT32 lr;
264     UINT32 pc;
265 } EXC_CONTEXT_S;
266 
267 typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *);
268 VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr);
269 VOID HalHwiInit(VOID);
270 
271 /**
272  * @ingroup los_exc
273  * exception types: undefined instruction exception.
274  */
275 #define OS_EXCEPT_UNDEF_INSTR           1
276 
277 /**
278  * @ingroup los_exc
279  * exception types: software interrupt.
280  */
281 #define OS_EXCEPT_SWI                   2
282 
283 /**
284  * @ingroup los_exc
285  * exception types: prefetch abort exception.
286  */
287 #define OS_EXCEPT_PREFETCH_ABORT        3
288 
289 /**
290  * @ingroup los_exc
291  * exception types: data abort exception.
292  */
293 #define OS_EXCEPT_DATA_ABORT            4
294 
295 /**
296  * @ingroup los_exc
297  * exception types: FIQ exception.
298  */
299 #define OS_EXCEPT_FIQ                   5
300 
301 /**
302  * @ingroup los_exc
303  * Exception information structure
304  *
305  * Description: Exception information saved when an exception is triggered on the Cortex-M4 platform.
306  *
307  */
308 typedef struct TagExcInfo {
309     /**< Exception occurrence phase: 0 means that an exception occurs in initialization,
310      * 1 means that an exception occurs in a task, and 2 means that an exception occurs in an interrupt */
311     UINT16 phase;
312     /**< Exception type. When exceptions occur, check the numbers 1 - 19 listed above */
313     UINT16 type;
314     /**< If the exact address access error indicates the wrong access address when the exception occurred */
315     UINT32 faultAddr;
316     /**< An exception occurs in an interrupt, indicating the interrupt number.
317      * An exception occurs in the task, indicating the task ID, or 0xFFFFFFFF if it occurs during initialization */
318     UINT32 thrdPid;
319     /**< Number of nested exceptions. Currently only registered hook functions are supported
320      * when an exception is entered for the first time */
321     UINT16 nestCnt;
322     /**< reserve */
323     UINT16 reserved;
324     /**< Hardware context at the time an exception to the automatic stack floating-point register occurs */
325     EXC_CONTEXT_S *context;
326 } ExcInfo;
327 
328 extern UINT32 g_intCount;
329 extern ExcInfo g_excInfo;
330 
331 #ifdef __cplusplus
332 #if __cplusplus
333 }
334 #endif /* __cplusplus */
335 #endif /* __cplusplus */
336 
337 #endif /* _LOS_ARCH_INTERRUPT_H */
338