orca-sim
Engine.hpp
Go to the documentation of this file.
1 /******************************************************************************
2  * This file is part of project ORCA. More information on the project
3  * can be found at the following repositories at GitHub's website.
4  *
5  * http://https://github.com/andersondomingues/orca-sim
6  * http://https://github.com/andersondomingues/orca-software
7  * http://https://github.com/andersondomingues/orca-mpsoc
8  * http://https://github.com/andersondomingues/orca-tools
9  *
10  * Copyright (C) 2018-2020 Anderson Domingues, <ti.andersondomingues@gmail.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 ******************************************************************************/
26 #ifndef ORCASIM_BASE_INCLUDE_ENGINE_HPP_
27 #define ORCASIM_BASE_INCLUDE_ENGINE_HPP_
28 
29 // lib dependencies
30 #include <iostream>
31 #include <array>
32 #include <queue>
33 #include <string>
34 
35 // own api dependencies
36 #include "Event.hpp"
37 #include "SimulationTime.hpp"
38 
39 namespace orcasim::base {
40 
46 class Engine{
47  private:
50 
52  std::priority_queue<Event> _queue;
53 
56 
59 
61  void executeNext();
62 
63  public:
67  Engine();
68 
69  /* run the simulation for <time> cycles. */
75  SimulationTime Run(SimulationTime time = 100000);
76 
82 
89 
96 
101  void Schedule(const Event& e);
102 
106  ~Engine();
107 };
108 
109 } // namespace orcasim::base
110 #endif // ORCASIM_BASE_INCLUDE_ENGINE_HPP_
SimulationTime Run(SimulationTime time=100000)
Executes the simulator until the internal clock reaches <time> cycles.
Definition: Engine.cpp:46
SimulationTime GetGlobalTime()
Gets the current global time.
Definition: Engine.cpp:110
This class models a discrete event.
Definition: Event.hpp:39
std::priority_queue< Event > _queue
queue that stores all events
Definition: Engine.hpp:52
SimulationTime _timeout
max time the simulation can reach
Definition: Engine.hpp:58
SimulationTime NextEpoch()
Resets the simulation clock and advance simulation to the next epoch.
Definition: Engine.cpp:81
SimulationTime _globalTime
The global clock, stores current simulation time.
Definition: Engine.hpp:55
uint32_t SimulationTime
~Engine()
Destructor.
Definition: Engine.cpp:135
SimulationTime _epochs
number of cycles to simulate before reseting the queue
Definition: Engine.hpp:49
This class implements an event queue to schedule and execute hardware modules.
Definition: Engine.hpp:46
Engine()
Default constructor, takes no parameters.
Definition: Engine.cpp:34
void Schedule(const Event &e)
Adds an event to the simulation queue.
Definition: Engine.cpp:122
SimulationTime GetEpochs()
Gets the number of cycles to simulate before reseting the simulation clock.
Definition: Engine.cpp:115
void executeNext()
execute event at top of event queue