simulavr  1.1.0
irqsystem.h
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
5  * Copyright (C) 2001, 2002, 2003 Klaus Rudolph
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  ****************************************************************************
22  *
23  * $Id$
24  */
25 
26 #ifndef HWIRQSYSTEM
27 #define HWIRQSYSTEM
28 
29 #include <vector>
30 
31 #include "hardware.h"
32 #include "funktor.h"
33 #include "printable.h"
34 #include "avrdevice.h"
35 #include "traceval.h"
36 
38 extern bool enableIRQStatistic;
39 
40 #ifndef SWIG
41 
43 
44  public:
49 
54 
55 
57  flagSet(0),
58  flagCleared(0),
59  handlerStarted(0),
60  handlerFinished(0),
61  setClear(0),
62  setStarted(0),
63  setFinished(0),
64  startedFinished(0) {}
65  void CalcDiffs();
66 };
67 
69 
70  protected:
73 
76 
79 
82 
83  friend std::ostream& operator<<(std::ostream &os, const IrqStatisticPerVector &ispv);
84 
85  public:
86 
89 
90  void CalculateStatistic();
91  void CheckComplete();
92 
94 };
95 
96 std::ostream& operator<<(std::ostream &, const IrqStatisticEntry&);
97 std::ostream& operator<<(std::ostream &, const IrqStatisticPerVector&);
98 
99 class IrqStatistic: public Printable {
100 
101  protected:
102  AvrDevice *core; //only used to get the (file) name of the core device
103 
104  public:
105  std::map<unsigned int, IrqStatisticPerVector> entries;
107  void operator()();
108 
109  virtual ~IrqStatistic() {}
110 
111  friend std::ostream& operator<<(std::ostream &, const IrqStatistic&);
112 };
113 
114 std::ostream& operator<<(std::ostream &, const IrqStatistic&);
115 
116 #endif // ifndef SWIG
117 
119 
120  protected:
122  unsigned int vectorTableSize;
124  std::vector<TraceValue*> irqTrace;
125 
127  std::vector<Hardware*> irqStack;
128  unsigned int irqStackSize;
131  std::vector<const Hardware*> debugInterruptTable;
132 
133  public:
134  HWIrqSystem (AvrDevice* _core, int bytes_per_vector, int number_of_vectors);
135  virtual ~HWIrqSystem();
136 
137  bool IsIrqPending();
139  unsigned int GetNewPc(unsigned int &vector_index);
140  void SetIrqFlag(Hardware *, unsigned int vector_index);
141  void ClearIrqFlag(unsigned int vector_index);
142  void IrqHandlerStarted(unsigned int vector_index);
143  void IrqHandlerFinished(unsigned int vector_index);
145  void DebugVerifyInterruptVector(unsigned int vector_index, const Hardware* source);
146  void DebugDumpTable();
147 };
148 
149 #ifndef SWIG
150 
151 class IrqFunktor: public Funktor {
152 
153  protected:
155  void (HWIrqSystem::*fp)(unsigned int);
156  unsigned int vectorNo;
157 
158  public:
159  IrqFunktor(HWIrqSystem *i, void (HWIrqSystem::*_fp)(unsigned int), unsigned int _vector):
160  irqSystem(i),
161  fp(_fp),
162  vectorNo(_vector) {}
163  void operator()() { (irqSystem->*fp)(vectorNo); }
164  Funktor* clone() { return new IrqFunktor(*this); }
165 };
166 
167 #endif // ifndef SWIG
168 
169 #endif
170 
std::ostream & operator<<(std::ostream &, const IrqStatisticEntry &)
Definition: irqsystem.cpp:143
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
SystemClockOffset handlerFinished
Definition: irqsystem.h:48
AvrDevice * core
Definition: irqsystem.h:102
SystemClockOffset handlerStarted
Definition: irqsystem.h:47
SystemClockOffset flagSet
Definition: irqsystem.h:45
unsigned int irqStackSize
Definition: irqsystem.h:128
HWIrqSystem * irqSystem
Definition: irqsystem.h:154
IrqStatisticEntry long_SetClear
Definition: irqsystem.h:71
IrqStatisticEntry long_StartedFinished
Definition: irqsystem.h:80
Funktor * clone()
Definition: irqsystem.h:164
HWSreg * status
Definition: irqsystem.h:123
SystemClockOffset startedFinished
Definition: irqsystem.h:53
IrqStatistic irqStatistic
Definition: irqsystem.h:130
SystemClockOffset setClear
Definition: irqsystem.h:50
Definition: hwsreg.h:52
SystemClockOffset setStarted
Definition: irqsystem.h:51
IrqFunktor(HWIrqSystem *i, void(HWIrqSystem::*_fp)(unsigned int), unsigned int _vector)
Definition: irqsystem.h:159
virtual ~IrqStatistic()
Definition: irqsystem.h:109
Build a register for TraceValue&#39;s.
Definition: traceval.h:442
bool enableIRQStatistic
global switch to enable irq statistic (default is disabled)
Definition: irqsystem.cpp:42
void operator()()
Definition: irqsystem.h:163
unsigned int vectorTableSize
number of entries supported by the device, not bytes
Definition: irqsystem.h:122
IrqStatisticEntry short_StartedFinished
Definition: irqsystem.h:81
unsigned int vectorNo
Definition: irqsystem.h:156
long long SystemClockOffset
std::vector< Hardware * > irqStack
priority queue of pending interrupts (i.e. waiting to be processed)
Definition: irqsystem.h:127
SystemClockOffset setFinished
Definition: irqsystem.h:52
IrqStatisticEntry long_SetFinished
Definition: irqsystem.h:77
IrqStatisticEntry short_SetStarted
Definition: irqsystem.h:75
std::vector< TraceValue * > irqTrace
Definition: irqsystem.h:124
SystemClockOffset flagCleared
Definition: irqsystem.h:46
IrqStatisticEntry actual
Definition: irqsystem.h:87
AvrDevice * core
Definition: irqsystem.h:129
IrqStatisticEntry long_SetStarted
Definition: irqsystem.h:74
std::map< unsigned int, IrqStatisticPerVector > entries
Definition: irqsystem.h:105
IrqStatisticEntry short_SetFinished
Definition: irqsystem.h:78
IrqStatisticEntry next
Definition: irqsystem.h:88
IrqStatisticEntry short_SetClear
Definition: irqsystem.h:72
int bytesPerVector
Definition: irqsystem.h:121
std::vector< const Hardware * > debugInterruptTable
Definition: irqsystem.h:131