sim_loop.h Source File

yasimavr: sim_loop.h Source File
yasimavr
Loading...
Searching...
No Matches
sim_loop.h
Go to the documentation of this file.
1/*
2 * sim_loop.h
3 *
4 * Copyright 2021 Clement Savergne <csavergne@yahoo.com>
5
6 This file is part of yasim-avr.
7
8 yasim-avr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 yasim-avr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with yasim-avr. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22//=======================================================================================
23
24#ifndef __YASIMAVR_LOOP_H__
25#define __YASIMAVR_LOOP_H__
26
27#include "../core/sim_types.h"
28#include "../core/sim_device.h"
29#include <vector>
30#include <mutex>
31#include <condition_variable>
32
34
35
36//=======================================================================================
37
42
43public:
44
52
53 explicit AbstractSimLoop(Device& device);
54 virtual ~AbstractSimLoop() = default;
55
56 AbstractSimLoop::State state() const;
57 cycle_count_t cycle() const;
58 CycleManager& cycle_manager();
59 const Device& device() const;
60 Logger& logger();
61
62protected:
63
68
69 cycle_count_t run_device(cycle_count_t final_cycle);
70 void set_state(AbstractSimLoop::State state);
71
72};
73
75{
76 return m_state;
77}
78
80{
81 m_state = state;
82}
83
85{
86 return m_cycle_manager.cycle();
87}
88
93
94inline const Device& AbstractSimLoop::device() const
95{
96 return m_device;
97}
98
100{
101 return m_logger;
102}
103
104
105//=======================================================================================
116
117public:
118
119 explicit SimLoop(Device& device);
120
121 void set_fast_mode(bool fast);
122
123 void run(cycle_count_t count = 0);
124
125private:
126
127 bool m_fast_mode;
128
129};
130
132inline void SimLoop::set_fast_mode(bool fast)
133{
134 m_fast_mode = fast;
135}
136
137//=======================================================================================
150
151public:
152
153 explicit AsyncSimLoop(Device& device);
154 void set_fast_mode(bool fast);
155
156 void run();
157
158 bool start_transaction();
159 void end_transaction();
160
161 void loop_continue();
162 void loop_pause();
163 void loop_step();
164 void loop_kill();
165
166private:
167
168 std::mutex m_cycle_mutex;
169 std::condition_variable m_cycle_cv;
170 std::condition_variable m_sync_cv;
171 bool m_cycling_enabled;
172 bool m_cycle_wait;
173 bool m_fast_mode;
174
175};
176
177
179
180#endif //__YASIMAVR_LOOP_H__
Common base class for simulation loops.
Definition sim_loop.h:41
State m_state
Definition sim_loop.h:65
CycleManager m_cycle_manager
Definition sim_loop.h:66
AbstractSimLoop::State state() const
Definition sim_loop.h:74
void set_state(AbstractSimLoop::State state)
Definition sim_loop.h:79
cycle_count_t cycle() const
Definition sim_loop.h:84
virtual ~AbstractSimLoop()=default
const Device & device() const
Definition sim_loop.h:94
Logger m_logger
Definition sim_loop.h:67
Logger & logger()
Definition sim_loop.h:99
Device & m_device
Definition sim_loop.h:64
State
Definition sim_loop.h:45
@ State_Step
Definition sim_loop.h:47
@ State_Running
Definition sim_loop.h:46
@ State_Stopped
Definition sim_loop.h:49
@ State_Standby
Definition sim_loop.h:48
CycleManager & cycle_manager()
Definition sim_loop.h:89
Asynchronous simulation loop It is designed when simulation need to interact with code running in ano...
Definition sim_loop.h:149
Definition sim_cycle_timer.h:134
cycle_count_t cycle() const
Returns the current cycle.
Definition sim_cycle_timer.h:184
Basic AVR device model.
Definition sim_device.h:61
Definition sim_logger.h:91
Synchronous simulation loop Basic synchronous simulation loop. It is designed for "fast" simulations ...
Definition sim_loop.h:115
void set_fast_mode(bool fast)
Set the simulation running mode: false=real-time, true=fast.
Definition sim_loop.h:132
#define YASIMAVR_BEGIN_NAMESPACE
Definition sim_globals.h:58
#define AVR_CORE_PUBLIC_API
Definition sim_globals.h:46
#define YASIMAVR_END_NAMESPACE
Definition sim_globals.h:59
YASIMAVR_BEGIN_NAMESPACE typedef long long cycle_count_t
Definition sim_types.h:40