source: rtems/c/src/lib/libcpu/powerpc/mpc55xx/irq/irq.c @ 3ce66aa

4.11
Last change on this file since 3ce66aa was 3ce66aa, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 19, 2012 at 8:02:12 AM

bsp/mpc55xx: Set PPC_EXC_CONFIG_USE_FIXED_HANDLER

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