4Copyright (c) 2011-2018 ARM Limited
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations under the License.
20from .conn_primitive
import ConnectorPrimitive, ConnectorPrimitiveException
25 ConnectorPrimitive.__init__(self, name)
45 def __fastmodel_init(self):
46 """! Initialize models using fm_agent APIs """
47 self.
logger.prn_inf(
"Initializing FastModel...")
51 except ImportError
as e:
52 self.
logger.prn_err(
"unable to load mbed-fastmodel-agent module. Check if the module install correctly.")
54 self.
logger.prn_err(
"Importing failed : %s" % str(e))
62 self.
logger.prn_err(
"module fm_agent, create() failed: %s"% str(e))
67 def __fastmodel_launch(self):
68 """! launch the FastModel"""
69 self.
logger.prn_inf(
"Launching FastModel...")
71 if not self.
resource.start_simulator():
74 self.
logger.prn_err(
"start_simulator() failed: %s"% str(e))
77 def __fastmodel_run(self):
78 """! Use fm_agent API to run the FastModel """
79 self.
logger.prn_inf(
"Running FastModel...")
81 if not self.
resource.run_simulator():
84 self.
logger.prn_err(
"run_simulator() failed: %s"% str(e))
87 def __fastmodel_load(self, filename):
88 """! Use fm_agent API to load image to FastModel, this is functional equivalent to flashing DUT"""
89 self.
logger.prn_inf(
"loading FastModel with image '%s'..."% filename)
91 if not self.
resource.load_simulator(filename):
94 self.
logger.prn_err(
"run_simulator() failed: %s"% str(e))
97 def __resource_allocated(self):
98 """! Check whether FastModel resource been allocated
99 @return True or throw an exception
104 self.
logger.prn_err(
"FastModel resource not available!")
108 """! Read data from DUT, count is not used for FastModel"""
114 self.
logger.prn_err(
"FastmodelConnectorPrimitive.read() failed: %s"% str(e))
119 def write(self, payload, log=False):
120 """! Write 'payload' to DUT"""
123 self.
logger.prn_txd(payload)
127 self.
logger.prn_err(
"FastmodelConnectorPrimitive.write() failed: %s"% str(e))
134 """! flush not supported in FastModel_module"""
138 """! return whether FastModel is connected """
139 if self.__resource_allocated():
140 return self.resource.is_simulator_alive
145 """! shutdown the FastModel and release the allocation """
151 self.
logger.prn_err(
"FastmodelConnectorPrimitive.finish() failed: %s"% str(e))
156 if not self.
resource.reset_simulator():
157 self.
logger.prn_err(
"FastModel reset failed, reset_simulator() return False!")
159 self.
logger.prn_err(
"FastmodelConnectorPrimitive.reset() failed: %s"% str(e))
finish(self)
Handle DUT dtor like (close resource) operations here.
__init__(self, name, config)
reset(self)
Reset the dut.
__fastmodel_load(self, filename)
read(self, count)
Read data from DUT, count is not used for FastModel.
__resource_allocated(self)
connected(self)
return whether FastModel is connected
flush(self)
flush not supported in FastModel_module
finish(self)
shutdown the FastModel and release the allocation
write(self, payload, log=False)
Write 'payload' to DUT.