source: rtems/c/src/librtems++/src/rtemsInterrupt.cc @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2  ------------------------------------------------------------------------
3
4  COPYRIGHT (c) 1997
5  Objective Design Systems Ltd Pty (ODS)
6  All rights reserved (R) Objective Design Systems Ltd Pty
7 
8  The license and distribution terms for this file may be found in the
9  file LICENSE in this distribution or at
10  http://www.rtems.org/license/LICENSE.
11
12  ------------------------------------------------------------------------
13
14  See header file.
15
16  ------------------------------------------------------------------------
17*/
18
19#include <rtems++/rtemsInterrupt.h>
20
21#if (CPU_SIMPLE_VECTORED_INTERRUPTS == TRUE)
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
30static rtemsInterrupt **interrupt_table;
31
32// has the table been initialised
33static bool initialised = false;
34
35/* ----
36   rtemsInterrupt
37*/
38
39#include <cstdlib>
40
41rtemsInterrupt::rtemsInterrupt()
42  : vector(0),
43    caught(false),
44    old_handler(0),
45    old_interrupt(0)
46{
47  if (!initialised)
48  {
49    interrupt_table = (rtemsInterrupt **)
50        malloc(sizeof(rtemsInterrupt *) * CPU_INTERRUPT_NUMBER_OF_VECTORS);
51    for (rtems_vector_number vec = 0;
52         vec < CPU_INTERRUPT_NUMBER_OF_VECTORS;
53         vec++)
54    {
55      interrupt_table[vec] = 0;
56    }
57    initialised = true;
58  }
59}
60
61rtemsInterrupt::~rtemsInterrupt()
62{
63  release();
64}
65
66const 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[vec];
75  interrupt_table[vec] = this;
76  vector = vec;
77 
78#if (CPU_SIMPLE_VECTORED_INTERRUPTS == TRUE)
79  set_status_code(rtems_interrupt_catch(redirector,
80                                        vector,
81                                        &old_handler));
82#else
83  set_status_code(RTEMS_NOT_DEFINED);
84#endif
85  if (successful())
86    caught = true;
87  else
88  {
89    interrupt_table[vector] = old_interrupt;
90    old_interrupt = 0;
91    old_handler = 0;
92    vector = 0;
93  }
94 
95  return last_status_code();
96}
97
98const rtems_status_code rtemsInterrupt::release(void)
99{
100  if (caught)
101  {
102#if (CPU_SIMPLE_VECTORED_INTERRUPTS == TRUE)
103    set_status_code(rtems_interrupt_catch(old_handler,
104                                          vector,
105                                          &old_handler));
106#else
107  set_status_code(RTEMS_NOT_DEFINED);
108#endif
109    interrupt_table[vector] = old_interrupt;
110    old_interrupt = 0;
111    old_handler = 0;
112    vector = 0;
113    caught = false;
114  }
115  else
116    set_status_code(RTEMS_SUCCESSFUL);
117 
118  return last_status_code();
119}
120
121void rtemsInterrupt::redirector(rtems_vector_number vector)
122{
123  if (interrupt_table[vector])
124    interrupt_table[vector]->handler();
125}
126#endif
Note: See TracBrowser for help on using the repository browser.