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

4.104.115
Last change on this file since d374492 was d374492, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 07/21/09 at 08:38:04

Update for MPC55XX changes

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[574fb67]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>
[d374492]24#include <libcpu/powerpc-utility.h>
[574fb67]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/**
[d374492]35 * @brief Returns the priority @a priority of IRQ @a vector from the INTC.
[574fb67]36 */
[d374492]37rtems_status_code mpc55xx_intc_get_priority( rtems_vector_number vector, unsigned *priority)
[574fb67]38{
[d374492]39        if (MPC55XX_IRQ_IS_VALID( vector)) {
40                *priority = INTC.PSR [vector].B.PRI;
[574fb67]41                return RTEMS_SUCCESSFUL;
42        } else {
[d374492]43                *priority = MPC55XX_INTC_INVALID_PRIORITY;
[574fb67]44                return RTEMS_INVALID_NUMBER;
45        }             
46}
47
48/**
[d374492]49 * @brief Sets the priority of IRQ @a vector to @a priority at the INTC.
[574fb67]50 */
[d374492]51rtems_status_code mpc55xx_intc_set_priority( rtems_vector_number vector, unsigned priority)
[574fb67]52{
[d374492]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) {
[574fb67]56                        return RTEMS_SUCCESSFUL;
57                } else {
58                        return RTEMS_IO_ERROR;
59                }
60        } else {
61                return RTEMS_INVALID_NUMBER;
62        }             
63}
64
65/**
[d374492]66 * @brief Raises the software IRQ with number @a vector.
[574fb67]67 */
[d374492]68rtems_status_code mpc55xx_intc_raise_software_irq( rtems_vector_number vector)
[574fb67]69{
[d374492]70        if (MPC55XX_IRQ_IS_SOFTWARE( vector)) {
71                INTC.SSCIR [vector].B.SET = 1;
[574fb67]72                return RTEMS_SUCCESSFUL;
73        } else {
74                return RTEMS_INVALID_NUMBER;
75        }             
76}
77
78/**
[d374492]79 * @brief Clears the software IRQ with number @a vector.
[574fb67]80 */
[d374492]81rtems_status_code mpc55xx_intc_clear_software_irq( rtems_vector_number vector)
[574fb67]82{
[d374492]83        if (MPC55XX_IRQ_IS_SOFTWARE( vector)) {
84                INTC.SSCIR [vector].B.CLR = 1;
[574fb67]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,
[d374492]98        unsigned priority,
[574fb67]99        rtems_interrupt_handler handler,
100        void *arg
101)
102{
103        if (MPC55XX_IRQ_IS_VALID( vector) && MPC55XX_INTC_IS_VALID_PRIORITY( priority)) {
[d374492]104                rtems_status_code sc = RTEMS_SUCCESSFUL;
105
[574fb67]106                sc = rtems_interrupt_handler_install( vector, info, options, handler, arg);
[602aee20]107                RTEMS_CHECK_SC( sc, "Install interrupt handler");
[d374492]108
[574fb67]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 */
[d374492]121        rtems_vector_number vector = INTC.IACKR.B.INTVEC;
[574fb67]122
[d374492]123        /* Save machine state and enable external exceptions */
124        uint32_t msr = ppc_external_exceptions_enable();
[574fb67]125
126        /* Dispatch interrupt handlers */
[d374492]127        bsp_interrupt_handler_dispatch( vector);
[574fb67]128
[d374492]129        /* Restore machine state */
130        ppc_external_exceptions_disable( msr);
[574fb67]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.