1 /*
2  * Copyright (c) 2006-2022, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2022-08-24     GuEe-GUI     first version
9  */
10 
11 #include <rtthread.h>
12 #include <rtdevice.h>
13 
14 /**
15  * This function will initialize hardware interrupt
16  */
rt_hw_interrupt_init(void)17 void rt_hw_interrupt_init(void)
18 {
19     /* initialize pic */
20     rt_pic_irq_init();
21 }
22 
23 /**
24  * This function will mask a interrupt.
25  * @param vector the interrupt number
26  */
rt_hw_interrupt_mask(int vector)27 void rt_hw_interrupt_mask(int vector)
28 {
29     rt_pic_irq_mask(vector);
30 }
31 
32 /**
33  * This function will un-mask a interrupt.
34  * @param vector the interrupt number
35  */
rt_hw_interrupt_umask(int vector)36 void rt_hw_interrupt_umask(int vector)
37 {
38     rt_pic_irq_unmask(vector);
39 }
40 
41 /**
42  * This function will install a interrupt service routine to a interrupt.
43  * @param vector the interrupt number
44  * @param new_handler the interrupt service routine to be installed
45  * @param old_handler the old interrupt service routine
46  */
rt_hw_interrupt_install(int vector,rt_isr_handler_t handler,void * param,const char * name)47 rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
48         void *param, const char *name)
49 {
50     rt_pic_attach_irq(vector, handler, param, name, RT_IRQ_F_NONE);
51 
52     return RT_NULL;
53 }
54 
55 /**
56  * This function will install a interrupt service routine to a interrupt.
57  * @param vector the interrupt number
58  * @param new_handler the interrupt service routine to be installed
59  * @param old_handler the old interrupt service routine
60  */
rt_hw_interrupt_uninstall(int vector,rt_isr_handler_t handler,void * param)61 void rt_hw_interrupt_uninstall(int vector, rt_isr_handler_t handler, void *param)
62 {
63     rt_pic_detach_irq(vector, param);
64 }
65 
66 #if defined(RT_USING_SMP) || defined(RT_USING_AMP)
rt_hw_ipi_send(int ipi_vector,unsigned int cpu_mask)67 void rt_hw_ipi_send(int ipi_vector, unsigned int cpu_mask)
68 {
69     RT_BITMAP_DECLARE(cpu_masks, RT_CPUS_NR) = { cpu_mask };
70 
71     rt_pic_irq_send_ipi(ipi_vector, cpu_masks);
72 }
73 
rt_hw_ipi_handler_install(int ipi_vector,rt_isr_handler_t ipi_isr_handler)74 void rt_hw_ipi_handler_install(int ipi_vector, rt_isr_handler_t ipi_isr_handler)
75 {
76     /* note: ipi_vector maybe different with irq_vector */
77     rt_hw_interrupt_install(ipi_vector, ipi_isr_handler, 0, "IPI_HANDLER");
78 }
79 #endif
80