[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> |
---|
| 24 | |
---|
| 25 | #include <bsp/irq.h> |
---|
| 26 | #include <bsp/irq-generic.h> |
---|
| 27 | #include <bsp/ppc_exc_bspsupp.h> |
---|
| 28 | |
---|
| 29 | #define RTEMS_STATUS_CHECKS_USE_PRINTK |
---|
| 30 | |
---|
| 31 | #include <rtems/status-checks.h> |
---|
| 32 | |
---|
| 33 | /** |
---|
| 34 | * @brief Returns the priority @a p of IRQ @a i from the INTC. |
---|
| 35 | */ |
---|
| 36 | rtems_status_code mpc55xx_intc_get_priority( int i, int *p) |
---|
| 37 | { |
---|
| 38 | if (MPC55XX_IRQ_IS_VALID( i)) { |
---|
| 39 | *p = INTC.PSR [i].B.PRI; |
---|
| 40 | return RTEMS_SUCCESSFUL; |
---|
| 41 | } else { |
---|
| 42 | *p = MPC55XX_INTC_INVALID_PRIORITY; |
---|
| 43 | return RTEMS_INVALID_NUMBER; |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | * @brief Sets the priority of IRQ @a i to @a p at the INTC. |
---|
| 49 | */ |
---|
| 50 | rtems_status_code mpc55xx_intc_set_priority( int i, int p) |
---|
| 51 | { |
---|
| 52 | if (MPC55XX_IRQ_IS_VALID( i) && MPC55XX_INTC_IS_VALID_PRIORITY( p)) { |
---|
| 53 | INTC.PSR [i].B.PRI = p; |
---|
| 54 | if (INTC.PSR [i].B.PRI == p) { |
---|
| 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 i. |
---|
| 66 | */ |
---|
| 67 | rtems_status_code mpc55xx_intc_raise_software_irq( int i) |
---|
| 68 | { |
---|
| 69 | if (MPC55XX_IRQ_IS_SOFTWARE( i)) { |
---|
| 70 | INTC.SSCIR [i].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 i. |
---|
| 79 | */ |
---|
| 80 | rtems_status_code mpc55xx_intc_clear_software_irq( int i) |
---|
| 81 | { |
---|
| 82 | if (MPC55XX_IRQ_IS_SOFTWARE( i)) { |
---|
| 83 | INTC.SSCIR [i].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 | */ |
---|
| 93 | rtems_status_code mpc55xx_interrupt_handler_install( |
---|
| 94 | rtems_vector_number vector, |
---|
| 95 | int priority, |
---|
| 96 | const char *info, |
---|
| 97 | rtems_option options, |
---|
| 98 | rtems_interrupt_handler handler, |
---|
| 99 | void *arg |
---|
| 100 | ) |
---|
| 101 | { |
---|
| 102 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
| 103 | |
---|
| 104 | if (MPC55XX_IRQ_IS_VALID( vector) && MPC55XX_INTC_IS_VALID_PRIORITY( priority)) { |
---|
| 105 | sc = rtems_interrupt_handler_install( vector, info, options, handler, arg); |
---|
[602aee20] | 106 | RTEMS_CHECK_SC( sc, "Install interrupt handler"); |
---|
[574fb67] | 107 | return mpc55xx_intc_set_priority( vector, priority); |
---|
| 108 | } else { |
---|
| 109 | return RTEMS_INVALID_NUMBER; |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | /** |
---|
| 114 | * @brief External exception handler. |
---|
| 115 | */ |
---|
| 116 | static int mpc55xx_external_exception_handler( BSP_Exception_frame *frame, unsigned exception_number) |
---|
| 117 | { |
---|
| 118 | /* Acknowlege interrupt request */ |
---|
| 119 | rtems_vector_number vector_number = INTC.IACKR.B.INTVEC; |
---|
| 120 | |
---|
| 121 | /* Save current interrupt level */ |
---|
| 122 | uint32_t level = _ISR_Get_level(); |
---|
| 123 | |
---|
| 124 | /* Enable all interrupts */ |
---|
| 125 | _ISR_Set_level( 0); |
---|
| 126 | |
---|
| 127 | /* Dispatch interrupt handlers */ |
---|
| 128 | bsp_interrupt_handler_dispatch( vector_number); |
---|
| 129 | |
---|
| 130 | /* Restore interrupt level */ |
---|
| 131 | _ISR_Set_level( level); |
---|
| 132 | |
---|
| 133 | /* End of interrupt */ |
---|
| 134 | INTC.EOIR.R = 1; |
---|
| 135 | |
---|
| 136 | return 0; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | rtems_status_code bsp_interrupt_facility_initialize() |
---|
| 140 | { |
---|
| 141 | /* Install exception handler */ |
---|
| 142 | if (ppc_exc_set_handler( ASM_EXT_VECTOR, mpc55xx_external_exception_handler)) { |
---|
| 143 | return RTEMS_IO_ERROR; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | /* Initialize interrupt controller */ |
---|
| 147 | |
---|
| 148 | /* Software vector mode */ |
---|
| 149 | INTC.MCR.B.VTES = 0; |
---|
| 150 | INTC.MCR.B.HVEN = 0; |
---|
| 151 | |
---|
| 152 | /* Set current priority to 0 */ |
---|
| 153 | INTC.CPR.B.PRI = 0; |
---|
| 154 | |
---|
| 155 | return RTEMS_SUCCESSFUL; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | rtems_status_code bsp_interrupt_vector_enable( rtems_vector_number vector) |
---|
| 159 | { |
---|
| 160 | if (MPC55XX_IRQ_IS_VALID( vector)) { |
---|
| 161 | return mpc55xx_intc_set_priority( vector, MPC55XX_INTC_DEFAULT_PRIORITY); |
---|
| 162 | } else { |
---|
| 163 | return RTEMS_SUCCESSFUL; |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | rtems_status_code bsp_interrupt_vector_disable( rtems_vector_number vector) |
---|
| 168 | { |
---|
| 169 | if (MPC55XX_IRQ_IS_VALID( vector)) { |
---|
| 170 | return mpc55xx_intc_set_priority( vector, MPC55XX_INTC_DISABLED_PRIORITY); |
---|
| 171 | } else { |
---|
| 172 | return RTEMS_SUCCESSFUL; |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | void bsp_interrupt_handler_default( rtems_vector_number vector) |
---|
| 177 | { |
---|
| 178 | /* Do nothing */ |
---|
| 179 | } |
---|