xref: /nrf52832-nimble/rt-thread/libcpu/arm/cortex-r4/interrupt.c (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  * Copyright (c) 2006-2018, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2008-12-11     XuXinming    first version
9  * 2013-03-29     aozima       Modify the interrupt interface implementations.
10  */
11 
12 #include <rtthread.h>
13 #include <rthw.h>
14 
15 #include <sys_vim.h>
16 #include <system.h>
17 
18 #include "armv7.h"
19 
20 #define MAX_HANDLERS	96
21 
22 /* exception and interrupt handler table */
23 struct rt_irq_desc irq_desc[MAX_HANDLERS];
24 
25 extern volatile rt_uint8_t rt_interrupt_nest;
26 
27 /* exception and interrupt handler table */
28 rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
29 rt_uint32_t rt_thread_switch_interrupt_flag;
30 
31 /**
32  * @addtogroup RM48x50
33  */
34 
35 /*@{*/
36 
rt_hw_int_not_handle(int vector,void * param)37 static void rt_hw_int_not_handle(int vector, void *param)
38 {
39 	rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
40 }
41 
42 #define vimRAM (0xFFF82000U)
43 
rt_hw_interrupt_init(void)44 void rt_hw_interrupt_init(void)
45 {
46 	register int i;
47 
48 	rt_uint32_t *vect_addr;
49 
50     /* the initialization is done in sys_startup.c */
51 
52     /* init exceptions table */
53     rt_memset(irq_desc, 0x00, sizeof(irq_desc));
54     for(i=0; i < MAX_HANDLERS; i++)
55     {
56         irq_desc[i].handler = rt_hw_int_not_handle;
57 
58 		vect_addr  = (rt_uint32_t *)(vimRAM + i*4);
59 		*vect_addr = (rt_uint32_t)&irq_desc[i];
60     }
61 
62 	/* init interrupt nest, and context in thread sp */
63 	rt_interrupt_nest = 0;
64 	rt_interrupt_from_thread = 0;
65 	rt_interrupt_to_thread = 0;
66 	rt_thread_switch_interrupt_flag = 0;
67 }
68 
rt_hw_interrupt_mask(int vector)69 void rt_hw_interrupt_mask(int vector)
70 {
71     vimDisableInterrupt(vector);
72 }
73 
rt_hw_interrupt_umask(int vector)74 void rt_hw_interrupt_umask(int vector)
75 {
76     vimEnableInterrupt(vector, SYS_IRQ);
77 }
78 
79 /**
80  * This function will install a interrupt service routine to a interrupt.
81  * @param vector the interrupt number
82  * @param handler the interrupt service routine to be installed
83  * @param param the parameter for interrupt service routine
84  * @name unused.
85  *
86  * @return the old handler
87  */
rt_hw_interrupt_install(int vector,rt_isr_handler_t handler,void * param,const char * name)88 rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
89 									void *param, const char *name)
90 {
91 	rt_isr_handler_t old_handler = RT_NULL;
92 
93 	if(vector >= 0 && vector < MAX_HANDLERS)
94 	{
95 		old_handler = irq_desc[vector].handler;
96 		if (handler != RT_NULL)
97 		{
98 			irq_desc[vector].handler = handler;
99 			irq_desc[vector].param = param;
100 		}
101 	}
102 
103 	return old_handler;
104 }
105 
106 /*@}*/
107