39 template<
typename Key,
typename Value>
45 template<
typename Key,
typename Value>
48 assert(!this->empty());
49 Key k = this->back().first;
50 Value v = this->back().second;
51 RemoveMinimumAndInsert(k, v);
55 template<
typename Key,
typename Value>
58 for(
unsigned i = 0; i < this->size(); i++)
60 std::pair<Key,Value> item = (*this)[i];
67 template<
typename Key,
typename Value>
70 for(
unsigned i = pos;;) {
71 unsigned parent = i/2;
72 if(parent == 0 || (*
this)[parent-1].first <= k) {
73 (*this)[i-1].first = k;
74 (*this)[i-1].second = v;
77 Key k_temp = (*this)[parent-1].first;
78 Value v_temp = (*this)[parent-1].second;
79 (*this)[i-1].first = k_temp;
80 (*this)[i-1].second = v_temp;
85 template<
typename Key,
typename Value>
88 assert(pos < this->size());
92 unsigned right = 2*i + 1;
93 unsigned smallest = i;
94 if(left-1 < this->size() && (*
this)[left-1].first < k)
96 if(right-1 < this->size() && (*
this)[right-1].first < k && (*
this)[right-1].first < (*
this)[left-1].first)
99 (*this)[smallest-1].first = k;
100 (*this)[smallest-1].second = v;
103 Key k_temp = (*this)[smallest-1].first;
104 Value v_temp = (*this)[smallest-1].second;
105 (*this)[i-1].first = k_temp;
106 (*this)[i-1].second = v_temp;
116 avr_error(
"Crazy problem: Second instance of SystemClock created!");
121 for(mi = syncMembers.begin(); mi != syncMembers.end(); mi++)
130 syncMembers.Insert(currentTime, dev);
134 asyncMembers.push_back(dev);
145 static vector<SimulationMember*>::iterator ami;
146 static vector<SimulationMember*>::iterator amiEnd;
148 if(syncMembers.begin() != syncMembers.end()) {
151 currentTime = syncMembers.begin()->first;
154 syncMembers.RemoveMinimum();
157 int rc = core->
Step(untilCoreStepFinished, &nextStepIn_ns);
161 if(nextStepIn_ns == 0) {
162 nextStepIn_ns = 1 + (syncMembers.IsEmpty() ? currentTime : syncMembers.front().first);
163 }
else if(nextStepIn_ns > 0)
164 nextStepIn_ns += currentTime;
168 if(nextStepIn_ns > 0)
169 syncMembers.Insert(nextStepIn_ns, core);
172 amiEnd = asyncMembers.end();
173 for(ami = asyncMembers.begin(); ami != amiEnd; ami++) {
174 bool untilCoreStepFinished =
false;
175 (*ami)->Step(untilCoreStepFinished, 0);
188 for(
unsigned i = 0; i < syncMembers.size(); i++) {
189 if(syncMembers[i].second == sm) {
190 syncMembers.RemoveAtPositionAndInsert(newTime+currentTime+1, sm, i);
195 syncMembers.Insert(newTime+currentTime+1, sm);
199 signal(SIGINT, SIG_DFL);
200 signal(SIGTERM, SIG_DFL);
210 asyncMembers.clear();
225 bool untilCoreStepFinished =
false;
226 Step(untilCoreStepFinished);
243 bool untilCoreStepFinished =
false;
244 if (Step(untilCoreStepFinished))
253 bool untilCoreStepFinished;
262 untilCoreStepFinished =
false;
263 if (Step(untilCoreStepFinished))
void Add(SimulationMember *dev)
Add a simulation member (normally a device)
Basic AVR device, contains the core functionality.
SystemClockOffset GetCurrentTime() const
Returns the current simulation time.
int Step(bool &untilCoreStepFinished)
Process one simulation step.
long Run(SystemClockOffset maxRunTime)
Run simulation till given time is arrived or signal is cached.
bool ContainsValue(Value v) const
void ResetClock(void)
Resets the simulation time and clears table for simulation members and async simulation members...
long Endless()
Run simulation endless till SIGINT or SIGTERM signal, return the number of CPU cycles.
long RunTimeRange(SystemClockOffset timeRange)
Like Run method, but stops on breakpoint or after given time offset.
void AddAsyncMember(SimulationMember *dev)
Add a async simulation member, this will be called every simulation step.
static SystemClock & Instance()
Returns the central SystemClock instance for the application.
long long SystemClockOffset
void Stop()
Stop Run/Endless or Step asynchronously.
void InsertInternal(Key k, Value v, unsigned pos)
SystemClock()
Do not this constructor from application code!
volatile bool breakMessage
Class to store and manage the central simulation time.
void SetTraceModeForAllMembers(int trace_on)
Switches trace mode for all current found simulation members.
virtual int Step(bool &trueHwStep, SystemClockOffset *timeToNextStepIn_ns=0)=0
Return nonzero if a breakpoint was hit.
void RemoveAtPositionAndInsertInternal(Key k, Value v, unsigned pos)
void Reschedule(SimulationMember *sm, SystemClockOffset newTime)
Moves the given simulation member to a new place in time table.