source: rtems/c/src/lib/libcpu/arm/at91rm9200/irq/irq.c @ 359e537

4.104.11
Last change on this file since 359e537 was 359e537, checked in by Ralf Corsepius <ralf.corsepius@…>, on Nov 30, 2009 at 5:09:41 AM

Whitespace removal.

  • Property mode set to 100644
File size: 2.3 KB
Line 
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 */
23static 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 */
34int 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    rtems_interrupt_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    rtems_interrupt_enable(level);
72
73    return 1;
74}
75
76/*
77 * Remove and interrupt handler
78 */
79int 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    rtems_interrupt_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    rtems_interrupt_enable(level);
113
114    return 1;
115}
Note: See TracBrowser for help on using the repository browser.