source: rtems/c/src/lib/libcpu/powerpc/mpc55xx/irq/irq.c @ 0f31fddc

4.11
Last change on this file since 0f31fddc was 0f31fddc, checked in by Sebastian Huber <sebastian.huber@…>, on Mar 24, 2012 at 9:01:08 PM

bsps: Add shared default IRQ handler

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup mpc55xx
5 *
6 * @brief Source file for MPC55XX interrupt support.
7 */
8
9/*
10 * Copyright (c) 2008
11 * Embedded Brains GmbH
12 * Obere Lagerstr. 30
13 * D-82178 Puchheim
14 * Germany
15 * rtems@embedded-brains.de
16 *
17 * The license and distribution terms for this file may be found in the file
18 * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
19 */
20
21#include <mpc55xx/regs.h>
22
23#include <libcpu/powerpc-utility.h>
24
25#include <bsp/irq.h>
26#include <bsp/vectors.h>
27#include <bsp/irq-generic.h>
28
29#define RTEMS_STATUS_CHECKS_USE_PRINTK
30
31#include <rtems/status-checks.h>
32
33/**
34 * @brief Returns the priority @a priority of IRQ @a vector from the INTC.
35 */
36rtems_status_code mpc55xx_intc_get_priority( rtems_vector_number vector, unsigned *priority)
37{
38        if (MPC55XX_IRQ_IS_VALID( vector)) {
39                *priority = INTC.PSR [vector].B.PRI;
40                return RTEMS_SUCCESSFUL;
41        } else {
42                *priority = MPC55XX_INTC_INVALID_PRIORITY;
43                return RTEMS_INVALID_NUMBER;
44        }
45}
46
47/**
48 * @brief Sets the priority of IRQ @a vector to @a priority at the INTC.
49 */
50rtems_status_code mpc55xx_intc_set_priority( rtems_vector_number vector, unsigned priority)
51{
52        if (MPC55XX_IRQ_IS_VALID( vector) && MPC55XX_INTC_IS_VALID_PRIORITY( priority)) {
53                INTC.PSR [vector].B.PRI = priority;
54                if (INTC.PSR [vector].B.PRI == priority) {
55                        return RTEMS_SUCCESSFUL;
56                } else {
57                        return RTEMS_IO_ERROR;
58                }
59        } else {
60                return RTEMS_INVALID_NUMBER;
61        }
62}
63
64/**
65 * @brief Raises the software IRQ with number @a vector.
66 */
67rtems_status_code mpc55xx_intc_raise_software_irq( rtems_vector_number vector)
68{
69        if (MPC55XX_IRQ_IS_SOFTWARE( vector)) {
70                INTC.SSCIR [vector].B.SET = 1;
71                return RTEMS_SUCCESSFUL;
72        } else {
73                return RTEMS_INVALID_NUMBER;
74        }
75}
76
77/**
78 * @brief Clears the software IRQ with number @a vector.
79 */
80rtems_status_code mpc55xx_intc_clear_software_irq( rtems_vector_number vector)
81{
82        if (MPC55XX_IRQ_IS_SOFTWARE( vector)) {
83                INTC.SSCIR [vector].B.CLR = 1;
84                return RTEMS_SUCCESSFUL;
85        } else {
86                return RTEMS_INVALID_NUMBER;
87        }
88}
89
90/**
91 * @brief Installs interrupt handler and sets priority.
92 */
93rtems_status_code mpc55xx_interrupt_handler_install(
94        rtems_vector_number vector,
95        const char *info,
96        rtems_option options,
97        unsigned priority,
98        rtems_interrupt_handler handler,
99        void *arg
100)
101{
102        if (MPC55XX_IRQ_IS_VALID( vector) && MPC55XX_INTC_IS_VALID_PRIORITY( priority)) {
103                rtems_status_code sc = RTEMS_SUCCESSFUL;
104
105                sc = rtems_interrupt_handler_install( vector, info, options, handler, arg);
106                RTEMS_CHECK_SC( sc, "Install interrupt handler");
107
108                return mpc55xx_intc_set_priority( vector, priority);
109        } else {
110                return RTEMS_INVALID_NUMBER;
111        }
112}
113
114/**
115 * @brief External exception handler.
116 */
117static int mpc55xx_external_exception_handler( BSP_Exception_frame *frame, unsigned exception_number)
118{
119        /* Acknowlege interrupt request */
120        rtems_vector_number vector = INTC.IACKR.B.INTVEC;
121
122        /* Save machine state and enable external exceptions */
123        uint32_t msr = ppc_external_exceptions_enable();
124
125        /* Dispatch interrupt handlers */
126        bsp_interrupt_handler_dispatch( vector);
127
128        /* Restore machine state */
129        ppc_external_exceptions_disable( msr);
130
131        /* End of interrupt */
132        INTC.EOIR.R = 1;
133
134        return 0;
135}
136
137rtems_status_code bsp_interrupt_facility_initialize()
138{
139        /* Install exception handler */
140        if (ppc_exc_set_handler( ASM_EXT_VECTOR, mpc55xx_external_exception_handler)) {
141                return RTEMS_IO_ERROR;
142        }
143
144        /* Initialize interrupt controller */
145
146        /* Software vector mode */
147        INTC.MCR.B.VTES = 0;
148        INTC.MCR.B.HVEN = 0;
149
150        /* Set current priority to 0 */
151        INTC.CPR.B.PRI = 0;
152
153        return RTEMS_SUCCESSFUL;
154}
155
156rtems_status_code bsp_interrupt_vector_enable( rtems_vector_number vector)
157{
158        if (MPC55XX_IRQ_IS_VALID( vector)) {
159                return mpc55xx_intc_set_priority( vector, MPC55XX_INTC_DEFAULT_PRIORITY);
160        } else {
161                return RTEMS_SUCCESSFUL;
162        }
163}
164
165rtems_status_code bsp_interrupt_vector_disable( rtems_vector_number vector)
166{
167        if (MPC55XX_IRQ_IS_VALID( vector)) {
168                return mpc55xx_intc_set_priority( vector, MPC55XX_INTC_DISABLED_PRIORITY);
169        } else {
170                return RTEMS_SUCCESSFUL;
171        }
172}
Note: See TracBrowser for help on using the repository browser.