1 /* ----------------------------------------------------------------------------
2 * Copyright (c) Huawei Technologies Co., Ltd. 2013-2020. All rights reserved.
3 * Description: Hwi HeadFile
4 * Author: Huawei LiteOS Team
5 * Create: 2013-01-01
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
14 * to endorse or promote products derived from this software without specific prior written
15 * permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * --------------------------------------------------------------------------- */
28
29 /**
30 * @defgroup los_hwi Hardware interrupt
31 * @ingroup kernel
32 */
33 #ifndef _LOS_HWI_H
34 #define _LOS_HWI_H
35
36 #include "los_base.h"
37 #include "hal_hwi.h"
38 #include "arch/cpu.h"
39 #include "arch/interrupt.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif /* __cplusplus */
44
45 /**
46 * An interrupt is active.
47 */
48 extern size_t IntActive(VOID);
49
50 /**
51 * @ingroup los_hwi
52 * It is used to check whether there are active interrupts or not.
53 *
54 * @see OS_INT_INACTIVE
55 */
56 #define OS_INT_ACTIVE IntActive()
57
58 /**
59 * @ingroup los_hwi
60 * Check whether there are active interrupts or not.
61 * The API returns a boolean value. True means no active interrupts on the current CPU.
62 * False means that there are active interrupts on the current CPU.
63 *
64 * @see OS_INT_ACTIVE
65 */
66 #define OS_INT_INACTIVE (!(OS_INT_ACTIVE))
67
68 /**
69 * @ingroup los_hwi
70 * Highest priority of a hardware interrupt.This is an external parameter.
71 * The priority range is [OS_HWI_PRIO_HIGHEST, OS_HWI_PRIO_HIGHEST + LOSCFG_HWI_PRIO_LIMIT - 1].
72 */
73 #define OS_HWI_PRIO_HIGHEST 0
74
75 /**
76 * @ingroup los_hwi
77 * This represents the interrupt priority range, the larger number, the lower priority, the interrupt processor is
78 * modified uniformly.
79 */
80 #define OS_HWI_PRIO_LOWEST (LOSCFG_HWI_PRIO_LIMIT - 1)
81
82 /**
83 * @ingroup los_hwi
84 * The lower priority number, the higher priority, so OS_HWI_PRIO_LOWEST big than OS_HWI_PRIO_HIGHEST.
85 */
86 #if (OS_HWI_PRIO_HIGHEST == 0)
87 #define HWI_PRI_VALID(pri) ((pri) <= OS_HWI_PRIO_LOWEST)
88 #else
89 #define HWI_PRI_VALID(pri) (((pri) >= OS_HWI_PRIO_HIGHEST) && ((pri) <= OS_HWI_PRIO_LOWEST))
90 #endif
91
92 /**
93 * @ingroup los_hwi
94 * Hardware interrupt error code: Invalid interrupt number.
95 *
96 * Value: 0x02000900.
97 *
98 * Solution: Ensure that the interrupt number is valid.
99 * @attention
100 * <ul>
101 * <li>Please use macros starting with LOS, and macros starting with OS will not be supported.</li>
102 * </ul>
103 */
104 #define LOS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
105 #define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_HWI_NUM_INVALID
106
107 /**
108 * @ingroup los_hwi
109 * Hardware interrupt error code: Null hardware interrupt handling function.
110 *
111 * Value: 0x02000901.
112 *
113 * Solution: Pass in a valid non-null hardware interrupt handling function.
114 * @attention
115 * <ul>
116 * <li>Please use macros starting with LOS, and macros starting with OS will not be supported.</li>
117 * </ul>
118 */
119 #define LOS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
120 #define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_HWI_PROC_FUNC_NULL
121
122 /**
123 * @ingroup los_hwi
124 * Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation.
125 *
126 * Value: 0x02000902.
127 *
128 * Solution: This error code is not in use temporarily.
129 * @deprecated This error code is obsolete since LiteOS 5.0.0.
130 */
131 #define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
132
133 /**
134 * @ingroup los_hwi
135 * Hardware interrupt error code: Insufficient memory for hardware interrupt initialization.
136 *
137 * Value: 0x02000903.
138 *
139 * Solution: Expand the configured memory.
140 * @attention
141 * <ul>
142 * <li>Please use macros starting with LOS, and macros starting with OS will not be supported.</li>
143 * </ul>
144 */
145 #define LOS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
146 #define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_HWI_NO_MEMORY
147
148 /**
149 * @ingroup los_hwi
150 * Hardware interrupt error code: The interrupt has already been created.
151 *
152 * Value: 0x02000904.
153 *
154 * Solution: Check whether the interrupt specified by the passed-in interrupt number has
155 * already been created.
156 * @attention
157 * <ul>
158 * <li>Please use macros starting with LOS, and macros starting with OS will not be supported.</li>
159 * </ul>
160 */
161 #define LOS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
162 #define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_HWI_ALREADY_CREATED
163
164 /**
165 * @ingroup los_hwi
166 * Hardware interrupt error code: Invalid interrupt priority.
167 *
168 * Value: 0x02000905.
169 *
170 * Solution: Ensure that the interrupt priority is valid.
171 * @attention
172 * <ul>
173 * <li>Please use macros starting with LOS, and macros starting with OS will not be supported.</li>
174 * </ul>
175 */
176 #define LOS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
177 #define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_HWI_PRIO_INVALID
178
179 /**
180 * @ingroup los_hwi
181 * Hardware interrupt error code: Incorrect interrupt creation mode.
182 *
183 * Value: 0x02000906.
184 *
185 * Solution: This error code is not in use temporarily.
186 * @deprecated This error code is obsolete since LiteOS 5.0.0.
187 */
188 #define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
189
190 /**
191 * @ingroup los_hwi
192 * Hardware interrupt error code: The interrupt has already been created as a fast interrupt.
193 *
194 * Value: 0x02000907.
195 *
196 * Solution: This error code is not in use temporarily.
197 * @deprecated This error code is obsolete since LiteOS 5.0.0.
198 */
199 #define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
200
201 /**
202 * @ingroup los_hwi
203 * Hardware interrupt error code: The API is called during an interrupt, which is not allowed.
204 *
205 * Value: 0x02000908.
206 *
207 * Solution: This error code is not in use temporarily.
208 * @attention
209 * <ul>
210 * <li>Please use macros starting with LOS, and macros starting with OS will not be supported.</li>
211 * </ul>
212 */
213 #define LOS_ERRNO_HWI_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08)
214 #define OS_ERRNO_HWI_INTERR LOS_ERRNO_HWI_INTERR
215
216 /**
217 * @ingroup los_hwi
218 * Hardware interrupt error code: the hardware interrupt supports SHARED error.
219 *
220 * Value: 0x02000909.
221 *
222 * Solution: Check the input params hwiMode and irqParam of LOS_HwiCreate or
223 * LOS_HwiDelete whether adapt the current hardware interrupt.
224 * @attention
225 * <ul>
226 * <li>Please use macros starting with LOS, and macros starting with OS will not be supported.</li>
227 * </ul>
228 */
229 #define LOS_ERRNO_HWI_SHARED_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x09)
230 #define OS_ERRNO_HWI_SHARED_ERROR LOS_ERRNO_HWI_SHARED_ERROR
231
232 /**
233 * @ingroup los_hwi
234 * Hardware interrupt error code: Invalid interrupt Arg when interrupt mode is IRQF_SHARED.
235 *
236 * Value: 0x0200090a.
237 *
238 * Solution: This error code is not in use temporarily.
239 * @deprecated This error code is obsolete since LiteOS 5.0.0.
240 */
241 #define OS_ERRNO_HWI_ARG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0a)
242
243 /**
244 * @ingroup los_hwi
245 * Hardware interrupt error code: The interrupt corresponded to the hardware interrupt number
246 * or devid has not been created.
247 *
248 * Value: 0x0200090b.
249 *
250 * Solution: Check the irqParam->pDevId of LOS_HwiDelete, make sure the devid need to delete.
251 * @attention
252 * <ul>
253 * <li>Please use macros starting with LOS, and macros starting with OS will not be supported.</li>
254 * </ul>
255 */
256 #define LOS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0b)
257 #define OS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_HWI_HWINUM_UNCREATE
258
259 /**
260 * @ingroup los_hwi
261 * Hardware interrupt error code: Insufficient memory for cpup control block of hardware interrupt.
262 *
263 * Value: 0x0200090c.
264 *
265 * Solution: Expand the configured memory.
266 * @attention
267 * <ul>
268 * <li>None.</li>
269 * </ul>
270 */
271 #define LOS_ERRNO_HWI_NO_CPUP_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c)
272
273 /**
274 * @ingroup los_hwi
275 * interrupt bottom half error code: The caller is not in interrupt context.
276 *
277 * Value: 0x0200090d.
278 *
279 * Solution: Check the caller of LOS_HwiBhworkAdd, make sure the caller in interrupt context, rather than task context.
280 * @attention
281 * <ul>
282 * <li>None.</li>
283 * </ul>
284 */
285 #define LOS_ERRNO_HWI_NOT_INTERRUPT_CONTEXT LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0d)
286
287 /**
288 * @ingroup los_hwi
289 * Hardware interrupt error code: Null pointer.
290 *
291 * Value: 0x0200090e.
292 *
293 * Solution: Change the passed-in null pointer to a valid non-null pointer.
294 * @attention
295 * <ul>
296 * <li>None.</li>
297 * </ul>
298 */
299 #define LOS_ERRNO_HWI_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0e)
300
301 /**
302 * @ingroup los_hwi
303 * Hardware interrupt error code: create hwi with arg when LOSCFG_HWI_WITH_ARG not enabled.
304 *
305 * Value: 0x0200090f.
306 *
307 * Solution: Pass NULL to the last parameter of LOS_HwiCreate or enable LOSCFG_HWI_WITH_ARG.
308 * @attention
309 * <ul><li>None.</li></ul>
310 */
311 #define LOS_ERRNO_HWI_ARG_NOT_ENABLED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0f)
312
313 /**
314 * @ingroup los_hwi
315 * Define the type HWI_HANDLE_T for a hardware interrupt number, the type is an unsigned int.
316 */
317 typedef UINT32 HWI_HANDLE_T;
318
319 /**
320 * @ingroup los_hwi
321 * Define the type HWI_PRIOR_T for a hardware interrupt priority, the type is an unsigned short.
322 */
323 typedef UINT16 HWI_PRIOR_T;
324
325 /**
326 * @ingroup los_hwi
327 * Define the type HWI_MODE_T for hardware interrupt mode configurations, the type is an unsigned short.
328 */
329 typedef UINT16 HWI_MODE_T;
330
331 /**
332 * @ingroup los_hwi
333 * Define the type HWI_ARG_T for the parameter used for the hardware interrupt creation function.
334 * The function of this parameter varies among platforms.
335 */
336 typedef UINTPTR HWI_ARG_T;
337
338 /**
339 * @ingroup los_hwi
340 * @brief Define the type of a hardware interrupt handling function.
341 *
342 * @par Description:
343 * This definition is used to declare the type of a hardware interrupt handling function.
344 * It will be used when calling LOS_HwiCreate.
345 * @attention
346 * None.
347 *
348 * @param None.
349 *
350 * @retval None.
351 * @par Dependency:
352 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
353 * @see LOS_HwiCreate
354 * @since Huawei LiteOS V100R001C00
355 */
356 typedef VOID (*HWI_PROC_FUNC)(VOID);
357
358 /**
359 * @ingroup los_hwi
360 * @brief Define the type of an interrupt bottom half function.
361 *
362 * @par Description:
363 * This definition is used to declare the type of an interrupt bottom half handling function.
364 * It will be used when calling LOS_HwiBhworkAdd.
365 * @attention
366 * None.
367 *
368 * @param None.
369 *
370 * @retval None.
371 * @par Dependency:
372 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
373 * @see LOS_HwiBhworkAdd
374 * @since Huawei LiteOS 207.0.0
375 */
376 typedef VOID (*HWI_BOTTOM_HALF_FUNC)(VOID *);
377
378 /**
379 * @ingroup los_hwi
380 * The flag means the IRQ is allowed to share among several devices.
381 *
382 * The flag only used by the kernel as part of the IRQ handling routines.
383 */
384 #define IRQF_SHARED 0x8000U
385
386 /**
387 * @ingroup los_hwi
388 * The hardware interrupt parameter for #LOS_HwiDelete and interrupt handler in #LOS_HwiCreate.
389 */
390 typedef struct tagIrqParam {
391 int swIrq; /**< The interrupt number */
392 VOID *pDevId; /**< The pointer to the device ID that launches the interrupt */
393 const CHAR *pName; /**< The interrupt name */
394 } HWI_IRQ_PARAM_S;
395
396 /**
397 * @ingroup los_hwi
398 * @brief Disable all interrupts.
399 *
400 * @par Description:
401 * This API is used to disable all interrupts.
402 * @attention
403 * None.
404 *
405 * @param None.
406 *
407 * @retval #UINT32 Interrupt status before all interrupts are disabled.
408 * @par Dependency:
409 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
410 * @see LOS_IntRestore
411 * @since Huawei LiteOS V100R001C00
412 */
LOS_IntLock(VOID)413 STATIC INLINE UINT32 LOS_IntLock(VOID)
414 {
415 return ArchIntLock();
416 }
417
418 /**
419 * @ingroup los_hwi
420 * @brief Enable all interrupts.
421 *
422 * @par Description:
423 * This API is used to enable all interrupts.
424 * @attention
425 * None.
426 *
427 * @param None.
428 *
429 * @retval #UINT32 Interrupt status after all interrupts are enabled.
430 * @par Dependency:
431 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
432 * @see LOS_IntLock
433 */
LOS_IntUnLock(VOID)434 STATIC INLINE UINT32 LOS_IntUnLock(VOID)
435 {
436 return ArchIntUnlock();
437 }
438
439 /**
440 * @ingroup los_hwi
441 * @brief Restore interrupts.
442 *
443 * @par Description:
444 * This API is used to restore the interrupt status obtained before all interrupts are disabled by #LOS_IntLock.
445 * @attention
446 * This API can be called only after #LOS_IntLock, and the input parameter value should be
447 * the value returned by #LOS_IntLock.
448 *
449 * @param intSave [IN] Type #UINT32. Interrupt status before all interrupts are disabled.
450 *
451 * @retval None.
452 * @par Dependency:
453 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
454 * @see LOS_IntLock
455 * @since Huawei LiteOS V100R001C00
456 */
LOS_IntRestore(UINT32 intSave)457 STATIC INLINE VOID LOS_IntRestore(UINT32 intSave)
458 {
459 ArchIntRestore(intSave);
460 }
461
462 /**
463 * @ingroup los_hwi
464 * @brief Create a hardware interrupt.
465 *
466 * @par Description:
467 * This API is used to configure a hardware interrupt and register a hardware interrupt handling function.
468 *
469 * @attention
470 * <ul>
471 * <li>The hardware interrupt module is usable only when the configuration item for
472 * hardware interrupt tailoring is enabled.</li>
473 * <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
474 * <li>The parameter handler of this interface is a interrupt handler, it should be correct, otherwise,
475 * the system may be abnormal.</li>
476 * <li>The input irqParam could be NULL, if not, it should be address which point to a struct HWI_IRQ_PARAM_S,
477 * the parameter pDenId and pName should be constant.</li>
478 * <li>A smaller value indicates a higher interrupt priority, the interrupt processor is modified uniformly.</li>
479 * </ul>
480 *
481 * @param hwiNum [IN] Type #HWI_HANDLE_T. The hardware interrupt number. The value range is
482 [OS_USER_HWI_MIN, OS_USER_HWI_MAX].
483 * @param hwiPrio [IN] Type #HWI_PRIOR_T. The hardware interrupt priority. The value range is
484 * [OS_HWI_PRIO_HIGHEST, OS_HWI_PRIO_LOWEST].
485 * @param hwiMode [IN] Type #HWI_MODE_T. The hardware interrupt mode.
486 * @param hwiHandler [IN] Type #HWI_PROC_FUNC. The interrupt handler used when a hardware interrupt is triggered.
487 * @param irqParam [IN] Type #HWI_IRQ_PARAM_S. The input parameter of the interrupt handler used when
488 * a hardware interrupt is triggered.
489 *
490 * @retval #LOS_ERRNO_HWI_PROC_FUNC_NULL Null hardware interrupt handling function.
491 * @retval #LOS_ERRNO_HWI_NUM_INVALID Invalid interrupt number.
492 * @retval #LOS_ERRNO_HWI_NO_MEMORY Insufficient memory for hardware interrupt creation.
493 * @retval #LOS_ERRNO_HWI_ALREADY_CREATED The interrupt handler being created has already been created.
494 * @retval #LOS_ERRNO_HWI_SHARED_ERROR The interrupt can not be shared. The interrupt number has been
495 * registered as a non-shared interrupt, or a shared interrupt is
496 * specified to be created, but the device ID is empty.
497 * @retval #LOS_ERRNO_HWI_NO_CPUP_MEMORY No enough cpup control block resources for data record.
498 * @retval #LOS_ERRNO_HWI_ARG_NOT_ENABLED Passed non-NULL to irqParam and LOSCFG_HWI_WITH_ARG not enabled.
499 * @retval #LOS_OK The interrupt is successfully created.
500 * @par Dependency:
501 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
502 * @see LOS_HwiDelete
503 * @since Huawei LiteOS V100R001C00
504 */
505 extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
506 HWI_PRIOR_T hwiPrio,
507 HWI_MODE_T hwiMode,
508 HWI_PROC_FUNC hwiHandler,
509 HWI_IRQ_PARAM_S *irqParam);
510
511 /**
512 * @ingroup los_hwi
513 * @brief delete a hardware interrupt.
514 *
515 * @par Description:
516 * This API is used to delete a hardware interrupt.
517 *
518 * @attention
519 * <ul>
520 * <li>The hardware interrupt module is usable only when the configuration item for
521 * hardware interrupt tailoring is enabled.</li>
522 * <li>Hardware interrupt number value range: [OS_USER_HWI_MIN, OS_USER_HWI_MAX].</li>
523 * <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
524 * <li>Do not call this API in interrupt handler,
525 * otherwise, invalid memory may be accessed in interrupt share mode.</li>
526 * </ul>
527 *
528 * @param hwiNum [IN] Type #HWI_HANDLE_T. The hardware interrupt number.
529 * @param irqParam [IN] Type #HWI_IRQ_PARAM_S *. ID of hardware interrupt which will base on
530 * when delete the hardware interrupt.
531 *
532 * @retval #LOS_ERRNO_HWI_NUM_INVALID Invalid interrupt number.
533 * @retval #LOS_ERRNO_HWI_SHARED_ERROR The interrupt number is a shared interrupt, but the device ID of the
534 * shared interrupt to be deleted is not specified.
535 * @retval #LOS_ERRNO_HWI_HWINUM_UNCREATE The interrupt corresponded to the hwiNum(
536 * the hardware interrupt number) or
537 * irqParam->pDevId(the interrupt device id)
538 * has not been created.
539 * @retval #LOS_ERRNO_HWI_PROC_FUNC_NULL Not supported disable interrupt.
540 * @retval #LOS_OK The interrupt is successfully deleted.
541 *
542 * @par Dependency:
543 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
544 * @see LOS_HwiCreate
545 * @since Huawei LiteOS V100R001C00
546 */
547 extern UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S *irqParam);
548
549 /**
550 * @ingroup los_hwi
551 * @brief Trigger interrupts.
552 *
553 * @par Description:
554 * The generation of external hardware interrupts is simulated by writing
555 * the relevant registers of the interrupt controller.
556 * @attention
557 * This function depends on the hardware implementation of the interrupt controller.
558 *
559 * @param hwiNum [IN] Type #HWI_HANDLE_T. The hardware interrupt number.
560 *
561 * @retval #LOS_ERRNO_HWI_NUM_INVALID Invalid interrupt number.
562 * @retval #LOS_ERRNO_HWI_PROC_FUNC_NULL Not supported by the interrupt controller.
563 * @retval #LOS_OK The interrupt is successfully triggered.
564 *
565 * @par Dependency:
566 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
567 * @since Huawei LiteOS V200R005C00
568 */
569 extern UINT32 LOS_HwiTrigger(HWI_HANDLE_T hwiNum);
570
571 /**
572 * @ingroup los_hwi
573 * @brief clear interrupts.
574 *
575 * @par Description:
576 * Clear the status bit of the interrupt number corresponding to the interrupt controller.
577 * @attention
578 * This function depends on the hardware implementation of the interrupt controller.
579 *
580 * @param hwiNum [IN] Type #HWI_HANDLE_T. The hardware interrupt number.
581 *
582 * @retval #LOS_ERRNO_HWI_NUM_INVALID Invalid interrupt number.
583 * @retval #LOS_ERRNO_HWI_PROC_FUNC_NULL Not supported by the interrupt controller.
584 * @retval #LOS_OK The interrupt is successfully cleared.
585 *
586 * @par Dependency:
587 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
588 * @since Huawei LiteOS V200R005C00
589 */
590 extern UINT32 LOS_HwiClear(HWI_HANDLE_T hwiNum);
591
592 /**
593 * @ingroup los_hwi
594 * @brief Enable interrupts.
595 *
596 * @par Description:
597 * Enable the corresponding interrupt mask of the interrupt controller, so
598 * that the interrupt source can be sent to the CPU.
599 * @attention
600 * This function depends on the hardware implementation of the interrupt controller.
601 *
602 * @param hwiNum [IN] Type #HWI_HANDLE_T. The hardware interrupt number.
603 *
604 * @retval #LOS_ERRNO_HWI_NUM_INVALID Invalid interrupt number.
605 * @retval #LOS_ERRNO_HWI_PROC_FUNC_NULL Not supported by the interrupt controller.
606 * @retval #LOS_OK The interrupt is successfully enabled.
607 *
608 * @par Dependency:
609 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
610 * @see LOS_HwiDisable
611 * @since Huawei LiteOS V200R005C00
612 */
613 extern UINT32 LOS_HwiEnable(HWI_HANDLE_T hwiNum);
614
615 /**
616 * @ingroup los_hwi
617 * @brief Disable interrupts.
618 *
619 * @par Description:
620 * Disable the corresponding interrupt mask of the interrupt controller, so
621 * that the interrupt source can be sent to the CPU.
622 * @attention
623 * This function depends on the hardware implementation of the interrupt controller.
624 *
625 * @param hwiNum [IN] Type #HWI_HANDLE_T. The hardware interrupt number.
626 *
627 * @retval #LOS_ERRNO_HWI_NUM_INVALID Invalid interrupt number.
628 * @retval #LOS_ERRNO_HWI_PROC_FUNC_NULL Not supported by the interrupt controller.
629 * @retval #LOS_OK The interrupt is successfully disabled.
630 * @par Dependency:
631 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
632 * @see LOS_HwiEnable
633 * @since Huawei LiteOS V200R005C00
634 */
635 extern UINT32 LOS_HwiDisable(HWI_HANDLE_T hwiNum);
636
637 /**
638 * @ingroup los_hwi
639 * @brief create a interrupt bottom half work.
640 *
641 * @par Description:
642 * This API is used to configure a bottom half work and register a interrupt bottom half handling function.
643 * @attention
644 * <li>The input data could be NULL if it's not necessary for bhHandler</li>
645 * <li>This function is defined only when LOSCFG_HWI_BOTTOM_HALF is defined.</li>
646 *
647 * @param bhHandler [IN] Type #HWI_BOTTOM_HALF_FUNC. Bottom half interrupt handler.
648 * @param data [IN] Type #VOID *. The input parameter of the interrupt bottom half handler.
649 *
650 * @retval #LOS_ERRNO_HWI_PROC_FUNC_NULL Null hardware interrupt bottom half handling function.
651 * @retval #LOS_ERRNO_HWI_NOT_INTERRUPT_CONTEXT Not in interrupt context
652 * @retval #LOS_ERRNO_HWI_NO_MEMORY Insufficient memory for interrupt bottom half.
653 * @retval #LOS_OK The interrupt bottom half work is successfully registered.
654 *
655 * @par Dependency:
656 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
657 * @since Huawei LiteOS 207.0.0
658 */
659 extern UINT32 LOS_HwiBhworkAdd(HWI_BOTTOM_HALF_FUNC bhHandler, VOID *data);
660
661 /**
662 * @ingroup los_hwi
663 * @brief Send inter-core interrupts to designated cores.
664 *
665 * @par Description:
666 * Send inter-core interrupts to designated cores.
667 * @attention
668 * This function depends on the hardware implementation of the interrupt
669 * controller and CPU architecture, Only used in SMP architecture.
670 *
671 * @param hwiNum [IN] Type #HWI_HANDLE_T: hardware interrupt number.
672 * @param cpuMask [IN] Type #UINT32: CPU number.
673 *
674 * @retval #LOS_ERRNO_HWI_NUM_INVALID Invalid interrupt number.
675 * @retval #LOS_ERRNO_HWI_PROC_FUNC_NULL Not supported by the interrupt controller.
676 * @retval #LOS_OK Inter-core interrupt sent successfully.
677 *
678 * @par Dependency:
679 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
680 * @since Huawei LiteOS V200R005C00
681 */
682 extern UINT32 LOS_HwiSendIpi(HWI_HANDLE_T hwiNum, UINT32 cpuMask);
683
684 /**
685 * @ingroup los_hwi
686 * @brief Interrupt response specified CPU processing.
687 *
688 * @par Description:
689 * Interrupt response specified CPU processing.
690 * @attention
691 * This function depends on the hardware implementation of the interrupt
692 * controller and CPU architecture, Only used in SMP architecture.
693 *
694 * @param hwiNum [IN] Type #HWI_HANDLE_T. The hardware interrupt number.
695 * @param cpuMask [IN] Type #UINT32. The CPU number.
696 *
697 * @retval #LOS_ERRNO_HWI_NUM_INVALID Invalid interrupt number.
698 * @retval #LOS_ERRNO_HWI_PROC_FUNC_NULL Not supported by the interrupt controller.
699 * @retval #LOS_OK The interrupt is successfully set affinity.
700 *
701 * @par Dependency:
702 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
703 * @since Huawei LiteOS V200R005C00
704 */
705 extern UINT32 LOS_HwiSetAffinity(HWI_HANDLE_T hwiNum, UINT32 cpuMask);
706
707 /**
708 * @ingroup los_hwi
709 * @brief Set interrupts priority.
710 *
711 * @par Description:
712 * Set interrupts priority.
713 * @attention
714 * This function depends on the hardware implementation of the interrupt
715 * controller and CPU architecture.
716 *
717 * @param hwiNum [IN] Type #HWI_HANDLE_T: hardware interrupt number.
718 * @param priority [IN] Type #HWI_PRIOR_T: interrupt priority to be set.
719 *
720 * @retval #LOS_ERRNO_HWI_NUM_INVALID Invalid interrupt number.
721 * @retval #LOS_ERRNO_HWI_PRIO_INVALID Invalid interrupt priority.
722 * @retval #LOS_ERRNO_HWI_PROC_FUNC_NULL Not supported by the interrupt controller.
723 * @retval #LOS_OK The interrupt is successfully set priority.
724 *
725 * @par Dependency:
726 * <ul><li>los_hwi.h: the header file that contains the API
727 * declaration.</li></ul>
728 * @see None
729 * @since Huawei LiteOS V200R005C00
730 */
731 extern UINT32 LOS_HwiSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority);
732
733 /**
734 * @ingroup los_hwi
735 * @brief Get the number of interrupt responses.
736 *
737 * @par Description:
738 * Get the number of responses to a specified interrupt.
739 * @attention
740 * The number of interrupt responses is always changed, so this API just provides a reference value.
741 * The type of interrupt response is UINT32, which may cause data overflow.
742 *
743 * @param hwiNum [IN] Type #HWI_HANDLE_T: hardware interrupt number.
744 * @param respCount [OUT] Type #UINT32 *: A pointer is used to store the number of interrupt responses.
745 *
746 * @retval #LOS_ERRNO_HWI_PTR_NULL The passed-in respCount value is NULL.
747 * @retval #LOS_ERRNO_HWI_NUM_INVALID Invalid interrupt number.
748 * @retval #LOS_OK Number of times that interrupt responses are successfully obtained.
749 *
750 * @par Dependency:
751 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
752 * @see None
753 */
754 extern LITE_OS_SEC_TEXT UINT32 LOS_HwiRespCntGet(HWI_HANDLE_T hwiNum, UINT32 *respCount);
755
756 #ifdef LOSCFG_HWI_PRE_POST_PROCESS
757 /**
758 * @ingroup los_hwi
759 * @brief Define the interrupt function type.
760 *
761 * @par Description:
762 * This function ptr is used to define the interrupt pre/post-processing function type.
763 *
764 * @attention None.
765 *
766 * @param hwiNum [IN] The interrupt number.
767 *
768 * @retval None.
769 * @par Dependency:
770 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
771 * @see None.
772 * @since Huawei LiteOS 206.1.0
773 */
774 typedef VOID (*HWI_PROC_HOOK)(HWI_HANDLE_T hwiNum);
775
776 /**
777 * @ingroup los_hwi
778 * @brief Register a hook before interrupt handle.
779 *
780 * @par Description:
781 * This API is used to register a hook before interrupt handle.
782 *
783 * @attention
784 * This API is non-reentrant and thread-unsafe, and cannot be repeatedly registered, otherwise,
785 * the last one will be overrode by the new one.
786 * If lowpower feature is ON, OS will call this API to register a hook. Overriding need to be focused on,
787 * in case that the user also register another hook.
788 *
789 * @param intPreHook [IN] The pre-processing interrupt hook.
790 *
791 * @retval None.
792 * @par Dependency:
793 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
794 * @see None.
795 * @since Huawei LiteOS 206.1.0
796 */
797 extern VOID LOS_HwiPreHookReg(HWI_PROC_HOOK intPreHook);
798
799 /**
800 * @ingroup los_hwi
801 * @brief Register a hook after interrupt handle.
802 *
803 * @par Description:
804 * This API is used to register a hook after interrupt handle.
805 *
806 * @attention
807 * This API is non-reentrant and thread-unsafe, and cannot be repeatedly resgistered, otherwise,
808 * the last one will be overrided by the new one.
809 *
810 * @param intPostHook [IN] The post-processing interrupt hook.
811 *
812 * @retval None.
813 * @par Dependency:
814 * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
815 * @see None.
816 * @since Huawei LiteOS 206.1.0
817 */
818 extern VOID LOS_HwiPostHookReg(HWI_PROC_HOOK intPostHook);
819 #endif
820
821 #ifdef __cplusplus
822 }
823 #endif /* __cplusplus */
824
825 #endif /* _LOS_HWI_H */
826