[21242c2] | 1 | /** |
---|
| 2 | * @file rtems/irq.h |
---|
[e01c480d] | 3 | * |
---|
[21242c2] | 4 | * This include file describe the data structure and the functions implemented |
---|
| 5 | * by rtems to write interrupt handlers. |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[e01c480d] | 9 | * CopyRight (C) 1998 valette@crf.canon.fr |
---|
| 10 | * |
---|
| 11 | * This code is heavilly inspired by the public specification of STREAM V2 |
---|
| 12 | * that can be found at : |
---|
| 13 | * |
---|
| 14 | * <http://www.chorus.com/Documentation/index.html> by following |
---|
| 15 | * the STREAM API Specification Document link. |
---|
| 16 | * |
---|
| 17 | * The license and distribution terms for this file may be |
---|
[dcf3687] | 18 | * found in the file LICENSE in this distribution or at |
---|
[e01c480d] | 19 | * http://www.rtems.com/license/LICENSE. |
---|
| 20 | * |
---|
[1a585016] | 21 | * $Id$ |
---|
[e01c480d] | 22 | */ |
---|
| 23 | |
---|
| 24 | #ifndef _RTEMS_IRQ_H |
---|
| 25 | #define _RTEMS_IRQ_H |
---|
| 26 | |
---|
| 27 | #ifndef ASM |
---|
| 28 | |
---|
| 29 | #ifdef __cplusplus |
---|
| 30 | extern "C" { |
---|
| 31 | #endif |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | /* |
---|
| 35 | * Type definition for RTEMS managed interrupts |
---|
| 36 | */ |
---|
| 37 | typedef unsigned char rtems_irq_prio; |
---|
| 38 | struct __rtems_irq_connect_data__; /* forward declaratiuon */ |
---|
| 39 | |
---|
[33c3b54d] | 40 | typedef unsigned int rtems_irq_number; |
---|
[e01c480d] | 41 | typedef void *rtems_irq_hdl_param; |
---|
| 42 | typedef void (*rtems_irq_hdl) (rtems_irq_hdl_param); |
---|
| 43 | typedef void (*rtems_irq_enable) (const struct __rtems_irq_connect_data__*); |
---|
| 44 | typedef void (*rtems_irq_disable) (const struct __rtems_irq_connect_data__*); |
---|
| 45 | typedef int (*rtems_irq_is_enabled) (const struct __rtems_irq_connect_data__*); |
---|
| 46 | |
---|
| 47 | typedef struct __rtems_irq_connect_data__ { |
---|
| 48 | /* |
---|
| 49 | * IRQ line |
---|
| 50 | */ |
---|
| 51 | rtems_irq_number name; |
---|
| 52 | /* |
---|
| 53 | * handler. See comment on handler properties below in function prototype. |
---|
| 54 | */ |
---|
| 55 | rtems_irq_hdl hdl; |
---|
| 56 | /* |
---|
| 57 | * Handler handle to store private data |
---|
| 58 | */ |
---|
| 59 | rtems_irq_hdl_param handle; |
---|
| 60 | /* |
---|
| 61 | * function for enabling interrupts at device level (ONLY!). |
---|
| 62 | * The BSP code will automatically enable it at i8259s level. |
---|
| 63 | * RATIONALE : anyway such code has to exist in current driver code. |
---|
| 64 | * It is usually called immediately AFTER connecting the interrupt handler. |
---|
| 65 | * RTEMS may well need such a function when restoring normal interrupt |
---|
| 66 | * processing after a debug session. |
---|
| 67 | * |
---|
| 68 | */ |
---|
| 69 | rtems_irq_enable on; |
---|
| 70 | /* |
---|
| 71 | * function for disabling interrupts at device level (ONLY!). |
---|
| 72 | * The code will disable it at i8259s level. RATIONALE : anyway |
---|
| 73 | * such code has to exist for clean shutdown. It is usually called |
---|
| 74 | * BEFORE disconnecting the interrupt. RTEMS may well need such |
---|
| 75 | * a function when disabling normal interrupt processing for |
---|
| 76 | * a debug session. May well be a NOP function. |
---|
| 77 | */ |
---|
| 78 | rtems_irq_disable off; |
---|
| 79 | /* |
---|
| 80 | * function enabling to know what interrupt may currently occur |
---|
| 81 | * if someone manipulates the i8259s interrupt mask without care... |
---|
| 82 | */ |
---|
[aad65583] | 83 | rtems_irq_is_enabled isOn; |
---|
[e01c480d] | 84 | |
---|
| 85 | #ifdef BSP_SHARED_HANDLER_SUPPORT |
---|
| 86 | /* |
---|
| 87 | * Set to -1 for vectors forced to have only 1 handler |
---|
| 88 | */ |
---|
| 89 | void *next_handler; |
---|
| 90 | #endif |
---|
| 91 | |
---|
| 92 | } rtems_irq_connect_data; |
---|
| 93 | |
---|
| 94 | typedef struct { |
---|
| 95 | /* |
---|
| 96 | * size of all the table fields (*Tbl) described below. |
---|
| 97 | */ |
---|
| 98 | unsigned int irqNb; |
---|
| 99 | /* |
---|
| 100 | * Default handler used when disconnecting interrupts. |
---|
| 101 | */ |
---|
| 102 | rtems_irq_connect_data defaultEntry; |
---|
| 103 | /* |
---|
| 104 | * Table containing initials/current value. |
---|
| 105 | */ |
---|
| 106 | rtems_irq_connect_data* irqHdlTbl; |
---|
| 107 | /* |
---|
| 108 | * actual value of BSP_ISA_IRQ_VECTOR_BASE... |
---|
| 109 | */ |
---|
| 110 | rtems_irq_number irqBase; |
---|
| 111 | /* |
---|
| 112 | * software priorities associated with interrupts. |
---|
| 113 | * if (*irqPrio [i] > intrPrio [j] it means that |
---|
| 114 | * interrupt handler hdl connected for interrupt name i |
---|
| 115 | * will not be interrupted by the handler connected for interrupt j |
---|
| 116 | * The interrupt source will be physically masked at i8259 level. |
---|
| 117 | */ |
---|
| 118 | rtems_irq_prio* irqPrioTbl; |
---|
[1a585016] | 119 | } rtems_irq_global_settings; |
---|
[e01c480d] | 120 | |
---|
| 121 | /*-------------------------------------------------------------------------+ |
---|
| 122 | | Function Prototypes. |
---|
| 123 | +--------------------------------------------------------------------------*/ |
---|
| 124 | /* |
---|
[aad65583] | 125 | * -------------------- RTEMS Single Irq Handler Mngt Routines ---------------- |
---|
[e01c480d] | 126 | */ |
---|
| 127 | /* |
---|
| 128 | * function to connect a particular irq handler. This hanlder will NOT be called |
---|
| 129 | * directly as the result of the corresponding interrupt. Instead, a RTEMS |
---|
| 130 | * irq prologue will be called that will : |
---|
| 131 | * |
---|
| 132 | * 1) save the C scratch registers, |
---|
| 133 | * 2) switch to a interrupt stack if the interrupt is not nested, |
---|
| 134 | * 3) store the current i8259s' interrupt masks |
---|
| 135 | * 4) modify them to disable the current interrupt at 8259 level (and may |
---|
| 136 | * be others depending on software priorities) |
---|
| 137 | * 5) aknowledge the i8259s', |
---|
| 138 | * 6) demask the processor, |
---|
| 139 | * 7) call the application handler |
---|
| 140 | * |
---|
| 141 | * As a result the hdl function provided |
---|
| 142 | * |
---|
| 143 | * a) can perfectly be written is C, |
---|
[aad65583] | 144 | * b) may also well directly call the part of the RTEMS API that can be |
---|
| 145 | * used from interrupt level, |
---|
[e01c480d] | 146 | * c) It only responsible for handling the jobs that need to be done at |
---|
[aad65583] | 147 | * the device level including (aknowledging/re-enabling the interrupt at |
---|
| 148 | * device level, getting the data,...) |
---|
[e01c480d] | 149 | * |
---|
| 150 | * When returning from the function, the following will be performed by |
---|
| 151 | * the RTEMS irq epilogue : |
---|
| 152 | * |
---|
| 153 | * 1) masks the interrupts again, |
---|
| 154 | * 2) restore the original i8259s' interrupt masks |
---|
| 155 | * 3) switch back on the orinal stack if needed, |
---|
| 156 | * 4) perform rescheduling when necessary, |
---|
| 157 | * 5) restore the C scratch registers... |
---|
| 158 | * 6) restore initial execution flow |
---|
| 159 | * |
---|
| 160 | */ |
---|
| 161 | int BSP_install_rtems_irq_handler (const rtems_irq_connect_data*); |
---|
| 162 | /* |
---|
| 163 | * function to get the current RTEMS irq handler for ptr->name. It enables to |
---|
| 164 | * define hanlder chain... |
---|
| 165 | */ |
---|
| 166 | int BSP_get_current_rtems_irq_handler (rtems_irq_connect_data* ptr); |
---|
| 167 | /* |
---|
| 168 | * function to get disconnect the RTEMS irq handler for ptr->name. |
---|
| 169 | * This function checks that the value given is the current one for safety reason. |
---|
| 170 | * The user can use the previous function to get it. |
---|
| 171 | */ |
---|
| 172 | int BSP_remove_rtems_irq_handler (const rtems_irq_connect_data*); |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | /* |
---|
[aad65583] | 176 | * ----------------- RTEMS Shared Irq Handler Mngt Routines ---------------- |
---|
[e01c480d] | 177 | */ |
---|
| 178 | #ifdef BSP_SHARED_HANDLER_SUPPORT |
---|
| 179 | int BSP_install_rtems_shared_irq_handler (const rtems_irq_connect_data*); |
---|
| 180 | #endif |
---|
| 181 | |
---|
| 182 | /* |
---|
[aad65583] | 183 | * ----------------- RTEMS Global Irq Handler Mngt Routines ---------------- |
---|
[e01c480d] | 184 | */ |
---|
| 185 | /* |
---|
| 186 | * (Re) Initialize the RTEMS interrupt management. |
---|
| 187 | * |
---|
| 188 | * The result of calling this function will be the same as if each individual |
---|
| 189 | * handler (config->irqHdlTbl[i].hdl) different from "config->defaultEntry.hdl" |
---|
| 190 | * has been individualy connected via |
---|
| 191 | * BSP_install_rtems_irq_handler(&config->irqHdlTbl[i]) |
---|
| 192 | * And each handler currently equal to config->defaultEntry.hdl |
---|
| 193 | * has been previously disconnected via |
---|
| 194 | * BSP_remove_rtems_irq_handler (&config->irqHdlTbl[i]) |
---|
| 195 | * |
---|
| 196 | * This is to say that all information given will be used and not just |
---|
| 197 | * only the space. |
---|
| 198 | * |
---|
| 199 | * CAUTION : the various table address contained in config will be used |
---|
| 200 | * directly by the interrupt mangement code in order to save |
---|
| 201 | * data size so they must stay valid after the call => they should |
---|
| 202 | * not be modified or declared on a stack. |
---|
| 203 | */ |
---|
| 204 | |
---|
| 205 | int BSP_rtems_irq_mngt_set(rtems_irq_global_settings* config); |
---|
[aad65583] | 206 | |
---|
[e01c480d] | 207 | /* |
---|
| 208 | * (Re) get info on current RTEMS interrupt management. |
---|
| 209 | */ |
---|
| 210 | int BSP_rtems_irq_mngt_get(rtems_irq_global_settings**); |
---|
| 211 | |
---|
| 212 | #ifdef __cplusplus |
---|
| 213 | } |
---|
| 214 | #endif |
---|
| 215 | |
---|
[1a585016] | 216 | #endif /* ASM */ |
---|
[e01c480d] | 217 | #endif /* _RTEMS_IRQ_H */ |
---|