1 | /* |
---|
2 | * Atmel AT91RM9200 Interrupt handler |
---|
3 | * |
---|
4 | * Copyright (c) 2004 by Jay Monkman <jtm@lopingdog.com> |
---|
5 | * |
---|
6 | * The license and distribution terms for this file may be |
---|
7 | * found in the file LICENSE in this distribution or at |
---|
8 | * |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | #include <bsp.h> |
---|
14 | #include <irq.h> |
---|
15 | #include <rtems/score/thread.h> |
---|
16 | #include <rtems/score/apiext.h> |
---|
17 | #include <at91rm9200.h> |
---|
18 | |
---|
19 | /* |
---|
20 | * This function check that the value given for the irq line |
---|
21 | * is valid. |
---|
22 | */ |
---|
23 | static int isValidInterrupt(int irq) |
---|
24 | { |
---|
25 | if ( (irq < 0) || (irq >= AT91RM9200_MAX_INT)) { |
---|
26 | return 0; |
---|
27 | } |
---|
28 | return 1; |
---|
29 | } |
---|
30 | |
---|
31 | /* |
---|
32 | * Installs the interrupt handler. |
---|
33 | */ |
---|
34 | int BSP_install_rtems_irq_handler (const rtems_irq_connect_data* irq) |
---|
35 | { |
---|
36 | rtems_interrupt_level level; |
---|
37 | |
---|
38 | if (!isValidInterrupt(irq->name)) { |
---|
39 | return 0; |
---|
40 | } |
---|
41 | |
---|
42 | /* |
---|
43 | * Check if default handler is actually connected. If not, issue |
---|
44 | * an error. Note: irq->name is a number corresponding to the |
---|
45 | * sources PID (see the at91rm9200_pid for this mapping). We |
---|
46 | * convert it to a long word offset to get source's vector register |
---|
47 | */ |
---|
48 | if (AIC_SVR_REG(irq->name * 4) != (uint32_t) default_int_handler) { |
---|
49 | return 0; |
---|
50 | } |
---|
51 | |
---|
52 | _CPU_ISR_Disable(level); |
---|
53 | |
---|
54 | /* |
---|
55 | * store the new handler |
---|
56 | */ |
---|
57 | AIC_SVR_REG(irq->name * 4) = (uint32_t) irq->hdl; |
---|
58 | |
---|
59 | /* |
---|
60 | * unmask interrupt |
---|
61 | */ |
---|
62 | AIC_CTL_REG(AIC_IECR) = 1 << irq->name; |
---|
63 | |
---|
64 | /* |
---|
65 | * Enable interrupt on device |
---|
66 | */ |
---|
67 | if(irq->on) { |
---|
68 | irq->on(irq); |
---|
69 | } |
---|
70 | |
---|
71 | _CPU_ISR_Enable(level); |
---|
72 | |
---|
73 | return 1; |
---|
74 | } |
---|
75 | |
---|
76 | /* |
---|
77 | * Remove and interrupt handler |
---|
78 | */ |
---|
79 | int BSP_remove_rtems_irq_handler (const rtems_irq_connect_data* irq) |
---|
80 | { |
---|
81 | rtems_interrupt_level level; |
---|
82 | |
---|
83 | if (!isValidInterrupt(irq->name)) { |
---|
84 | return 0; |
---|
85 | } |
---|
86 | |
---|
87 | /* |
---|
88 | * Check if the handler is actually connected. If not, issue an error. |
---|
89 | */ |
---|
90 | if (AIC_SVR_REG(irq->name * 4) != (uint32_t) irq->hdl) { |
---|
91 | return 0; |
---|
92 | } |
---|
93 | _CPU_ISR_Disable(level); |
---|
94 | |
---|
95 | /* |
---|
96 | * mask interrupt |
---|
97 | */ |
---|
98 | AIC_CTL_REG(AIC_IDCR) = 1 << irq->name; |
---|
99 | |
---|
100 | /* |
---|
101 | * Disable interrupt on device |
---|
102 | */ |
---|
103 | if(irq->off) { |
---|
104 | irq->off(irq); |
---|
105 | } |
---|
106 | |
---|
107 | /* |
---|
108 | * restore the default irq value |
---|
109 | */ |
---|
110 | AIC_SVR_REG(irq->name * 4) = (uint32_t) default_int_handler; |
---|
111 | |
---|
112 | _CPU_ISR_Enable(level); |
---|
113 | |
---|
114 | return 1; |
---|
115 | } |
---|