simulavr  1.1.0
SystemClock Class Reference

Class to store and manage the central simulation time. More...

#include <systemclock.h>

Public Member Functions

SystemClockOffset GetCurrentTime () const
 Returns the current simulation time. More...
 
void SetCurrentTime (SystemClockOffset of)
 Set the simulation time to a dedicated value. More...
 
void IncrTime (SystemClockOffset of)
 Increments the current simulation time with a offset. More...
 
void Add (SimulationMember *dev)
 Add a simulation member (normally a device) More...
 
void AddAsyncMember (SimulationMember *dev)
 Add a async simulation member, this will be called every simulation step. More...
 
int Step (bool &untilCoreStepFinished)
 Process one simulation step. More...
 
long Endless ()
 Run simulation endless till SIGINT or SIGTERM signal, return the number of CPU cycles. More...
 
long Run (SystemClockOffset maxRunTime)
 Run simulation till given time is arrived or signal is cached. More...
 
long RunTimeRange (SystemClockOffset timeRange)
 Like Run method, but stops on breakpoint or after given time offset. More...
 
void Reschedule (SimulationMember *sm, SystemClockOffset newTime)
 Moves the given simulation member to a new place in time table. More...
 
void SetTraceModeForAllMembers (int trace_on)
 Switches trace mode for all current found simulation members. More...
 
void Stop ()
 Stop Run/Endless or Step asynchronously. More...
 
void ResetClock (void)
 Resets the simulation time and clears table for simulation members and async simulation members. More...
 

Static Public Member Functions

static SystemClockInstance ()
 Returns the central SystemClock instance for the application. More...
 

Protected Attributes

SystemClockOffset currentTime
 time in [ns] since start of simulation More...
 
MinHeap< SystemClockOffset, SimulationMember * > syncMembers
 earliest first More...
 
std::vector< SimulationMember * > asyncMembers
 List of asynchron working simulation members, will be called every step! More...
 

Private Member Functions

 SystemClock ()
 Do not this constructor from application code! More...
 
 SystemClock (const SystemClock &)
 Do not this constructor from application code! More...
 

Detailed Description

Class to store and manage the central simulation time.

This acts as a time table, a simulation member gets a place on this ordered table, where it should be called next time, the placement depends on the results of Step method call Step on this simulation member.

Todo:
In multiple core simulations which uses also gdb with single stepping we need a other solution to fit the time accurate behaviour. Currently on a single step from gdb the simulation runs until the command is completly executed which is NOT correct. Some commands need up to 4 cycles and the actual implementation do up to 4 steps for one step so the other cores run slower then in normal operation. This is not a problem today because we are not able to run multiple cores with gdb but this will be implementated later. So this version is only made for running the regression tests and stepping in gdb. Normal operation/simulation is not affected. (taken over from systemclock.cpp, but to check!)

Definition at line 82 of file systemclock.h.

Constructor & Destructor Documentation

◆ SystemClock() [1/2]

SystemClock::SystemClock ( )
private

Do not this constructor from application code!

Definition at line 111 of file systemclock.cpp.

References avr_error.

◆ SystemClock() [2/2]

SystemClock::SystemClock ( const SystemClock )
private

Do not this constructor from application code!

Member Function Documentation

◆ Add()

void SystemClock::Add ( SimulationMember dev)

Add a simulation member (normally a device)

Definition at line 129 of file systemclock.cpp.

Referenced by HWUSI::doCount(), HWUSI::PinStateHasChanged(), and HWTimerTinyX5::SetPrescalerClock().

◆ AddAsyncMember()

void SystemClock::AddAsyncMember ( SimulationMember dev)

Add a async simulation member, this will be called every simulation step.

Definition at line 133 of file systemclock.cpp.

◆ Endless()

long SystemClock::Endless ( )

Run simulation endless till SIGINT or SIGTERM signal, return the number of CPU cycles.

Definition at line 215 of file systemclock.cpp.

References breakMessage, and OnBreak().

◆ GetCurrentTime()

◆ IncrTime()

void SystemClock::IncrTime ( SystemClockOffset  of)
inline

Increments the current simulation time with a offset.

Attention! Use this method with care, if you don't want crazy results

Definition at line 101 of file systemclock.h.

◆ Instance()

◆ Reschedule()

void SystemClock::Reschedule ( SimulationMember sm,
SystemClockOffset  newTime 
)

Moves the given simulation member to a new place in time table.

The next time, simulation member will be called, is calculated as a given offset to current simulation time + 1.

Todo:
This method is possibly obsolete!

Definition at line 186 of file systemclock.cpp.

◆ ResetClock()

void SystemClock::ResetClock ( void  )

Resets the simulation time and clears table for simulation members and async simulation members.

Definition at line 208 of file systemclock.cpp.

References breakMessage.

◆ Run()

long SystemClock::Run ( SystemClockOffset  maxRunTime)

Run simulation till given time is arrived or signal is cached.

Definition at line 232 of file systemclock.cpp.

References breakMessage, Instance(), and OnBreak().

◆ RunTimeRange()

long SystemClock::RunTimeRange ( SystemClockOffset  timeRange)

Like Run method, but stops on breakpoint or after given time offset.

Definition at line 251 of file systemclock.cpp.

References breakMessage, GetCurrentTime(), Instance(), and OnBreak().

◆ SetCurrentTime()

void SystemClock::SetCurrentTime ( SystemClockOffset  of)
inline

Set the simulation time to a dedicated value.

Attention! Use this method with care, if you don't want crazy results

Definition at line 98 of file systemclock.h.

Referenced by avr_set_time_tf().

◆ SetTraceModeForAllMembers()

void SystemClock::SetTraceModeForAllMembers ( int  trace_on)

Switches trace mode for all current found simulation members.

Definition at line 119 of file systemclock.cpp.

References AvrDevice::trace_on.

◆ Step()

int SystemClock::Step ( bool &  untilCoreStepFinished)

Process one simulation step.

Definition at line 139 of file systemclock.cpp.

References breakMessage, and SimulationMember::Step().

◆ Stop()

void SystemClock::Stop ( )

Stop Run/Endless or Step asynchronously.

Definition at line 204 of file systemclock.cpp.

References breakMessage.

Referenced by AvrDevice::Step().

Member Data Documentation

◆ asyncMembers

std::vector<SimulationMember*> SystemClock::asyncMembers
protected

List of asynchron working simulation members, will be called every step!

Definition at line 91 of file systemclock.h.

◆ currentTime

SystemClockOffset SystemClock::currentTime
protected

time in [ns] since start of simulation

Definition at line 89 of file systemclock.h.

◆ syncMembers

MinHeap<SystemClockOffset, SimulationMember *> SystemClock::syncMembers
protected

earliest first

Definition at line 90 of file systemclock.h.


The documentation for this class was generated from the following files: