1 /*
2  * Copyright (c) 2006-2019, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2019-12-04     Jiaxun Yang  Initial version
9  */
10 
11 /**
12  * @addtogroup mipssim
13  */
14 
15 /*@{*/
16 
17 #include <rtthread.h>
18 #include <rthw.h>
19 #include <exception.h>
20 
21 #define MAX_INTR 32
22 
23 static struct rt_irq_desc irq_handle_table[MAX_INTR];
24 
rt_hw_interrupt_handler(int vector,void * param)25 static void rt_hw_interrupt_handler(int vector, void *param)
26 {
27     rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
28 }
29 
30 /**
31  * This function will initialize hardware interrupt
32  */
rt_hw_interrupt_init(void)33 void rt_hw_interrupt_init(void)
34 {
35     rt_uint32_t idx;
36     rt_memset(irq_handle_table, 0x00, sizeof(irq_handle_table));
37     for (idx = 0; idx < MAX_INTR; idx ++)
38     {
39         irq_handle_table[idx].handler = rt_hw_interrupt_handler;
40     }
41 }
42 
rt_hw_interrupt_install(int vector,rt_isr_handler_t handler,void * param,const char * name)43 rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
44                                          void *param, const char *name)
45 {
46     rt_isr_handler_t old_handler = RT_NULL;
47 
48     if (vector >= 0 && vector < MAX_INTR)
49     {
50         old_handler = irq_handle_table[vector].handler;
51 
52 #ifdef RT_USING_INTERRUPT_INFO
53         rt_strncpy(irq_handle_table[vector].name, name, RT_NAME_MAX);
54 #endif /* RT_USING_INTERRUPT_INFO */
55         irq_handle_table[vector].handler = handler;
56         irq_handle_table[vector].param = param;
57     }
58 
59     return old_handler;
60 }
61 
62 void rt_hw_timer_handler(void);
63 
rt_do_mips_cpu_irq(rt_uint32_t ip)64 void rt_do_mips_cpu_irq(rt_uint32_t ip)
65 {
66     void *param;
67     rt_isr_handler_t irq_func;
68 
69     if (ip == 7) {
70         rt_hw_timer_handler();
71     } else {
72         irq_func = irq_handle_table[ip].handler;
73                 param = irq_handle_table[ip].param;
74 
75                 /* do interrupt */
76                 irq_func(ip, param);
77     }
78 }
79 
rt_hw_interrupt_umask(int irq)80 void rt_hw_interrupt_umask(int irq)
81 {
82     mips_unmask_cpu_irq(irq);
83 }
84 
rt_hw_interrupt_mask(int irq)85 void rt_hw_interrupt_mask(int irq)
86 {
87     mips_mask_cpu_irq(irq);
88 }
89 /*@}*/
90