xref: /nrf52832-nimble/rt-thread/libcpu/arm/AT91SAM7X/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  * 2006-08-23     Bernard      first version
9  * 2013-03-29     aozima       Modify the interrupt interface implementations.
10  */
11 
12 #include <rtthread.h>
13 #include <rthw.h>
14 #include "AT91SAM7X256.h"
15 
16 #define MAX_HANDLERS	32
17 
18 /* exception and interrupt handler table */
19 struct rt_irq_desc irq_desc[MAX_HANDLERS];
20 
21 extern rt_uint32_t rt_interrupt_nest;
22 
23 rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
24 rt_uint32_t rt_thread_switch_interrupt_flag;
25 
26 /**
27  * @addtogroup AT91SAM7
28  */
29 /*@{*/
30 
rt_hw_interrupt_handler(int vector,void * param)31 static void rt_hw_interrupt_handler(int vector, void *param)
32 {
33 	rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
34 }
35 
36 /**
37  * This function will initialize hardware interrupt
38  */
rt_hw_interrupt_init(void)39 void rt_hw_interrupt_init(void)
40 {
41 	rt_base_t index;
42 
43     /* init exceptions table */
44     for(index=0; index < MAX_HANDLERS; index++)
45     {
46         irq_desc[index].handler = (rt_isr_handler_t)rt_hw_interrupt_handler;
47         irq_desc[index].param = RT_NULL;
48     }
49 
50 	for (index = 0; index < MAX_HANDLERS; index ++)
51 	{
52 		AT91C_BASE_AIC->AIC_SVR[index] = (rt_uint32_t)rt_hw_interrupt_handler;
53 	}
54 
55 	/* init interrupt nest, and context in thread sp */
56 	rt_interrupt_nest = 0;
57 	rt_interrupt_from_thread = 0;
58 	rt_interrupt_to_thread = 0;
59 	rt_thread_switch_interrupt_flag = 0;
60 }
61 
62 /**
63  * This function will mask a interrupt.
64  * @param vector the interrupt number
65  */
rt_hw_interrupt_mask(int vector)66 void rt_hw_interrupt_mask(int vector)
67 {
68 	/* disable interrupt */
69 	AT91C_BASE_AIC->AIC_IDCR = 1 << vector;
70 
71 	/* clear interrupt */
72 	AT91C_BASE_AIC->AIC_ICCR = 1 << vector;
73 }
74 
75 /**
76  * This function will un-mask a interrupt.
77  * @param vector the interrupt number
78  */
rt_hw_interrupt_umask(int vector)79 void rt_hw_interrupt_umask(int vector)
80 {
81 	AT91C_BASE_AIC->AIC_IECR = 1 << vector;
82 }
83 
84 /**
85  * This function will install a interrupt service routine to a interrupt.
86  * @param vector the interrupt number
87  * @param handler the interrupt service routine to be installed
88  * @param param the parameter for interrupt service routine
89  * @name unused.
90  *
91  * @return the old handler
92  */
rt_hw_interrupt_install(int vector,rt_isr_handler_t handler,void * param,const char * name)93 rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
94 									void *param, const char *name)
95 {
96 	rt_isr_handler_t old_handler = RT_NULL;
97 	if(vector >= 0 && vector < MAX_HANDLERS)
98 	{
99 		old_handler = irq_desc[vector].handler;
100 		if (handler != RT_NULL)
101 		{
102 			irq_desc[vector].handler = (rt_isr_handler_t)handler;
103 			irq_desc[vector].param = param;
104 		}
105 	}
106 
107 	return old_handler;
108 }
109 
110 /*@}*/
111