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

4.11
Last change on this file since bd75e58 was bd75e58, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 13, 2012 at 11:20:59 AM

bsp/mpc55xx: Fix INTC initialization

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