Skip to content

Commit c972092

Browse files
Qinghao ShiQinghao Shi
authored andcommitted
refactoring on load and run function
* store loaded image in member variable * check model states before running model * add delicate reset function
1 parent d24cf8f commit c972092

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

fm_agent/fm_agent.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def start_simulator(self):
110110
terminal = self.model.get_target('fvp_mps2.telnetterminal0')
111111
self.port = terminal.read_register('Port')
112112
self.host = "localhost"
113+
self.image = None
113114
return True
114115
else:
115116
raise SimulatorError("fastmodel product was NOT installed correctly")
@@ -118,15 +119,39 @@ def load_simulator(self,image):
118119
""" Load a launched fastmodel with given image(full path)"""
119120
if self.is_simulator_alive():
120121
cpu = self.model.get_cpus()[0]
121-
cpu.load_application(os.path.normpath(image))
122+
app = os.path.normpath(image)
123+
if os.path.exists(app):
124+
cpu.load_application(app)
125+
self.image = os.path.normpath(app)
126+
else:
127+
self.logger.prn_err("Image %s not exist while loading to Fast Models" % app)
128+
return False
122129
return True
123130
else:
124131
return False
125-
132+
126133
def run_simulator(self):
127134
""" Start running a launched fastmodel and connect terminal """
128135
if self.is_simulator_alive():
129-
self.model.run(blocking=False,timeout=1)
136+
cpu = self.model.get_cpus()[0]
137+
if cpu.is_running:
138+
self.logger.prn_err("Fast Model already in running state")
139+
else:
140+
self.model.run(blocking=False)
141+
self.__connect_terminal()
142+
return True
143+
else:
144+
return False
145+
146+
def reset_simulator(self):
147+
""" reset a launched fastmodel and connect terminal """
148+
if self.is_simulator_alive():
149+
self.model.stop()
150+
cpu = self.model.get_cpus()[0]
151+
cpu.reset()
152+
if self.image:
153+
cpu.load_application(self.image)
154+
self.model.run(blocking=False)
130155
self.__connect_terminal()
131156
return True
132157
else:

0 commit comments

Comments
 (0)