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

4.104.11
Last change on this file since d374492 was d374492, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on Jul 21, 2009 at 8:38:04 AM

Update for MPC55XX changes

  • Property mode set to 100644
File size: 4.1 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/raw_exception.h>
24#include <libcpu/powerpc-utility.h>
25
26#include <bsp/irq.h>
27#include <bsp/irq-generic.h>
28#include <bsp/ppc_exc_bspsupp.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()
139{
140        /* Install exception handler */
141        if (ppc_exc_set_handler( ASM_EXT_VECTOR, mpc55xx_external_exception_handler)) {
142                return RTEMS_IO_ERROR;
143        }
144
145        /* Initialize interrupt controller */
146
147        /* Software vector mode */
148        INTC.MCR.B.VTES = 0;
149        INTC.MCR.B.HVEN = 0;
150
151        /* Set current priority to 0 */
152        INTC.CPR.B.PRI = 0;
153
154        return RTEMS_SUCCESSFUL;
155}
156
157rtems_status_code bsp_interrupt_vector_enable( rtems_vector_number vector)
158{
159        if (MPC55XX_IRQ_IS_VALID( vector)) {
160                return mpc55xx_intc_set_priority( vector, MPC55XX_INTC_DEFAULT_PRIORITY);
161        } else {
162                return RTEMS_SUCCESSFUL;
163        }
164}
165
166rtems_status_code bsp_interrupt_vector_disable( rtems_vector_number vector)
167{
168        if (MPC55XX_IRQ_IS_VALID( vector)) {
169                return mpc55xx_intc_set_priority( vector, MPC55XX_INTC_DISABLED_PRIORITY);
170        } else {
171                return RTEMS_SUCCESSFUL;
172        }
173}
174
175void bsp_interrupt_handler_default( rtems_vector_number vector)
176{
177        /* Do nothing */
178}
Note: See TracBrowser for help on using the repository browser.