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-03-13 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 "s3c24x0.h"
15
16 #define MAX_HANDLERS 32
17
18 extern rt_uint32_t rt_interrupt_nest;
19
20 /* exception and interrupt handler table */
21 struct rt_irq_desc isr_table[MAX_HANDLERS];
22 rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
23 rt_uint32_t rt_thread_switch_interrupt_flag;
24
25 /**
26 * @addtogroup S3C24X0
27 */
28 /*@{*/
29
rt_hw_interrupt_handle(int vector,void * param)30 static void rt_hw_interrupt_handle(int vector, void *param)
31 {
32 rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
33 }
34
35 /**
36 * This function will initialize hardware interrupt
37 */
rt_hw_interrupt_init(void)38 void rt_hw_interrupt_init(void)
39 {
40 register rt_uint32_t idx;
41
42 /* all clear source pending */
43 SRCPND = 0x0;
44
45 /* all clear sub source pending */
46 SUBSRCPND = 0x0;
47
48 /* all=IRQ mode */
49 INTMOD = 0x0;
50
51 /* all interrupt disabled include global bit */
52 INTMSK = BIT_ALLMSK;
53
54 /* all sub interrupt disable */
55 INTSUBMSK = BIT_SUB_ALLMSK;
56
57 /* all clear interrupt pending */
58 INTPND = BIT_ALLMSK;
59
60 /* init exceptions table */
61 rt_memset(isr_table, 0x00, sizeof(isr_table));
62 for(idx=0; idx < MAX_HANDLERS; idx++)
63 {
64 isr_table[idx].handler = rt_hw_interrupt_handle;
65 }
66
67 /* init interrupt nest, and context in thread sp */
68 rt_interrupt_nest = 0;
69 rt_interrupt_from_thread = 0;
70 rt_interrupt_to_thread = 0;
71 rt_thread_switch_interrupt_flag = 0;
72 }
73
74 /**
75 * This function will mask a interrupt.
76 * @param vector the interrupt number
77 */
rt_hw_interrupt_mask(int vector)78 void rt_hw_interrupt_mask(int vector)
79 {
80 INTMSK |= 1 << vector;
81 }
82
83 /**
84 * This function will un-mask a interrupt.
85 * @param vector the interrupt number
86 */
rt_hw_interrupt_umask(int vector)87 void rt_hw_interrupt_umask(int vector)
88 {
89 if (vector == INTNOTUSED6)
90 {
91 rt_kprintf("Interrupt vec %d is not used!\n", vector);
92 // while(1);
93 }
94 else if (vector == INTGLOBAL)
95 INTMSK = 0x0;
96 else
97 INTMSK &= ~(1 << vector);
98 }
99
100 /**
101 * This function will install a interrupt service routine to a interrupt.
102 * @param vector the interrupt number
103 * @param new_handler the interrupt service routine to be installed
104 * @param old_handler the old interrupt service routine
105 */
rt_hw_interrupt_install(int vector,rt_isr_handler_t handler,void * param,const char * name)106 rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
107 void *param, const char *name)
108 {
109 rt_isr_handler_t old_handler = RT_NULL;
110
111 if(vector < MAX_HANDLERS)
112 {
113 old_handler = isr_table[vector].handler;
114
115 if (handler != RT_NULL)
116 {
117 #ifdef RT_USING_INTERRUPT_INFO
118 rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX);
119 #endif /* RT_USING_INTERRUPT_INFO */
120 isr_table[vector].handler = handler;
121 isr_table[vector].param = param;
122 }
123 }
124
125 return old_handler;
126 }
127
128 /*@}*/
129