1
+ /*
2
+ * Copyright (c) 2006-2025 RT-Thread Development Team
3
+ *
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ *
6
+ * Change Logs:
7
+ * Date Author Notes
8
+ * 2018/10/01 Bernard The first version
9
+ * 2018/12/27 Jesven Change irq enable/disable to cpu0
10
+ */
11
+ #include <plic.h>
12
+ #include "encoding.h"
13
+ #include "riscv.h"
14
+ #include "interrupt.h"
15
+
16
+ struct rt_irq_desc irq_desc [MAX_HANDLERS ];
17
+
18
+ static rt_isr_handler_t rt_hw_interrupt_handle (rt_uint32_t vector , void * param )
19
+ {
20
+ rt_kprintf ("UN-handled interrupt %d occurred!!!\n" , vector );
21
+ return RT_NULL ;
22
+ }
23
+
24
+ int rt_hw_plic_irq_enable (int irq_number )
25
+ {
26
+ plic_irq_enable (irq_number );
27
+ return 0 ;
28
+ }
29
+
30
+ int rt_hw_plic_irq_disable (int irq_number )
31
+ {
32
+ plic_irq_disable (irq_number );
33
+ return 0 ;
34
+ }
35
+
36
+ /**
37
+ * This function will un-mask a interrupt.
38
+ * @param vector the interrupt number
39
+ */
40
+ void rt_hw_interrupt_umask (int vector )
41
+ {
42
+ plic_set_priority (vector , 1 );
43
+
44
+ rt_hw_plic_irq_enable (vector );
45
+ }
46
+
47
+ /**
48
+ * This function will install a interrupt service routine to a interrupt.
49
+ * @param vector the interrupt number
50
+ * @param new_handler the interrupt service routine to be installed
51
+ * @param old_handler the old interrupt service routine
52
+ */
53
+ rt_isr_handler_t rt_hw_interrupt_install (int vector , rt_isr_handler_t handler ,
54
+ void * param , const char * name )
55
+ {
56
+ rt_isr_handler_t old_handler = RT_NULL ;
57
+
58
+ if (vector < MAX_HANDLERS )
59
+ {
60
+ old_handler = irq_desc [vector ].handler ;
61
+ if (handler != RT_NULL )
62
+ {
63
+ irq_desc [vector ].handler = (rt_isr_handler_t )handler ;
64
+ irq_desc [vector ].param = param ;
65
+ #ifdef RT_USING_INTERRUPT_INFO
66
+ rt_snprintf (irq_desc [vector ].name , RT_NAME_MAX - 1 , "%s" , name );
67
+ irq_desc [vector ].counter = 0 ;
68
+ #endif
69
+ }
70
+ }
71
+
72
+ return old_handler ;
73
+ }
74
+
75
+ void rt_hw_interrupt_init ()
76
+ {
77
+ /* Enable machine external interrupts. */
78
+ /* set_csr(sie, SIP_SEIP); */
79
+ int idx = 0 ;
80
+ /* init exceptions table */
81
+ for (idx = 0 ; idx < MAX_HANDLERS ; idx ++ )
82
+ {
83
+ irq_desc [idx ].handler = (rt_isr_handler_t )rt_hw_interrupt_handle ;
84
+ irq_desc [idx ].param = RT_NULL ;
85
+ #ifdef RT_USING_INTERRUPT_INFO
86
+ rt_snprintf (irq_desc [idx ].name , RT_NAME_MAX - 1 , "default" );
87
+ irq_desc [idx ].counter = 0 ;
88
+ #endif
89
+ }
90
+ /*init plic*/
91
+ plic_init ();
92
+ }
0 commit comments