[0074691a] | 1 | /* |
---|
| 2 | ------------------------------------------------------------------------ |
---|
| 3 | $Id$ |
---|
| 4 | ------------------------------------------------------------------------ |
---|
| 5 | |
---|
| 6 | COPYRIGHT (c) 1997 |
---|
| 7 | Objective Design Systems Ltd Pty (ODS) |
---|
| 8 | All rights reserved (R) Objective Design Systems Ltd Pty |
---|
| 9 | |
---|
| 10 | The license and distribution terms for this file may be found in the |
---|
| 11 | file LICENSE in this distribution or at |
---|
| 12 | http://www.OARcorp.com/rtems/license.html. |
---|
| 13 | |
---|
| 14 | ------------------------------------------------------------------------ |
---|
| 15 | |
---|
| 16 | See header file. |
---|
| 17 | |
---|
| 18 | ------------------------------------------------------------------------ |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #include <rtems++/rtemsInterrupt.h> |
---|
| 22 | |
---|
| 23 | /* ---- |
---|
| 24 | Interrupt Table |
---|
| 25 | |
---|
| 26 | This table is used to re-direct the call from RTEMS to a user |
---|
| 27 | object |
---|
| 28 | */ |
---|
| 29 | |
---|
[f692d7e0] | 30 | static rtemsInterrupt **interrupt_table; |
---|
[0074691a] | 31 | |
---|
| 32 | // has the table been initialised |
---|
| 33 | static bool initialised = false; |
---|
| 34 | |
---|
| 35 | /* ---- |
---|
| 36 | rtemsInterrupt |
---|
| 37 | */ |
---|
| 38 | |
---|
[f692d7e0] | 39 | #include <stdlib.h> /* for malloc */ |
---|
| 40 | |
---|
[0074691a] | 41 | rtemsInterrupt::rtemsInterrupt() |
---|
| 42 | : vector(0), |
---|
| 43 | caught(false), |
---|
| 44 | old_handler(0), |
---|
| 45 | old_interrupt(0) |
---|
| 46 | { |
---|
| 47 | if (!initialised) |
---|
| 48 | { |
---|
[f692d7e0] | 49 | interrupt_table = (rtemsInterrupt **) |
---|
| 50 | malloc(sizeof(rtemsInterrupt *) * CPU_INTERRUPT_NUMBER_OF_VECTORS); |
---|
[0074691a] | 51 | for (rtems_vector_number vec = 0; |
---|
| 52 | vec < CPU_INTERRUPT_NUMBER_OF_VECTORS; |
---|
| 53 | vec++) |
---|
| 54 | { |
---|
| 55 | interrupt_table[vector] = 0; |
---|
| 56 | } |
---|
| 57 | initialised = true; |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
[bf4cdb70] | 61 | rtemsInterrupt::~rtemsInterrupt() |
---|
| 62 | { |
---|
| 63 | release(); |
---|
| 64 | } |
---|
| 65 | |
---|
[0074691a] | 66 | const rtems_status_code rtemsInterrupt::isr_catch(const rtems_vector_number vec) |
---|
| 67 | { |
---|
| 68 | if (vec >= CPU_INTERRUPT_NUMBER_OF_VECTORS) |
---|
| 69 | return set_status_code(RTEMS_INVALID_NUMBER); |
---|
| 70 | |
---|
| 71 | if (caught) |
---|
| 72 | return set_status_code(RTEMS_RESOURCE_IN_USE); |
---|
| 73 | |
---|
| 74 | old_interrupt = interrupt_table[vector]; |
---|
| 75 | interrupt_table[vector] = this; |
---|
| 76 | vector = vec; |
---|
| 77 | |
---|
| 78 | set_status_code(rtems_interrupt_catch(redirector, |
---|
| 79 | vector, |
---|
| 80 | &old_handler)); |
---|
| 81 | |
---|
| 82 | if (successful()) |
---|
| 83 | caught = true; |
---|
| 84 | else |
---|
| 85 | { |
---|
| 86 | interrupt_table[vector] = old_interrupt; |
---|
| 87 | old_interrupt = 0; |
---|
| 88 | old_handler = 0; |
---|
| 89 | vector = 0; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | return last_status_code(); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | const rtems_status_code rtemsInterrupt::release(void) |
---|
| 96 | { |
---|
| 97 | if (caught) |
---|
| 98 | { |
---|
| 99 | set_status_code(rtems_interrupt_catch(old_handler, |
---|
| 100 | vector, |
---|
| 101 | &old_handler)); |
---|
| 102 | |
---|
| 103 | interrupt_table[vector] = old_interrupt; |
---|
| 104 | old_interrupt = 0; |
---|
| 105 | old_handler = 0; |
---|
| 106 | vector = 0; |
---|
| 107 | caught = false; |
---|
| 108 | } |
---|
| 109 | else |
---|
| 110 | set_status_code(RTEMS_SUCCESSFUL); |
---|
| 111 | |
---|
| 112 | return last_status_code(); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | void rtemsInterrupt::redirector(rtems_vector_number vector) |
---|
| 116 | { |
---|
| 117 | if (interrupt_table[vector]) |
---|
| 118 | interrupt_table[vector]->handler(); |
---|
| 119 | } |
---|