def move_slave(self, slave_name = None, from_slave_type = SlaveType.PERIPHERAL, from_slave_index = 0, to_slave_type = SlaveType.PERIPHERAL, to_slave_index = 0): """Move slave from one place to another, the slave can be moved from one bus to another and the index position can be moved.""" if to_slave_type == SlaveType.PERIPHERAL and to_slave_index == 0: return if slave_name is None: gm.SlaveError("a slave name must be specified") if from_slave_type == to_slave_type: # Simple move call. self.sgm.move_slave(from_slave_index, to_slave_index, from_slave_type) return sname = self.sgm.get_slave_name_at(from_slave_index, from_slave_type) node = self.sgm.get_node(sname) tags = self.sgm.get_parameters(sname) # moving to the other bus, need to sever connections. self.remove_slave(from_slave_type, from_slave_index) filename = saputils.find_module_filename(tags["module"]) filename = saputils.find_rtl_file_location(filename) self.add_slave(slave_name, filename, to_slave_type, to_slave_index)
def move_slave(self, slave_name=None, from_slave_type=SlaveType.PERIPHERAL, from_slave_index=0, to_slave_type=SlaveType.PERIPHERAL, to_slave_index=0): """Move slave from one place to another, the slave can be moved from one bus to another and the index position can be moved.""" if to_slave_type == SlaveType.PERIPHERAL and to_slave_index == 0: return if slave_name is None: gm.SlaveError("a slave name must be specified") if from_slave_type == to_slave_type: # Simple move call. self.sgm.move_slave(from_slave_index, to_slave_index, from_slave_type) return sname = self.sgm.get_slave_name_at(from_slave_index, from_slave_type) node = self.sgm.get_node(sname) tags = self.sgm.get_parameters(sname) # moving to the other bus, need to sever connections. self.remove_slave(from_slave_type, from_slave_index) filename = saputils.find_module_filename(tags["module"]) filename = saputils.find_rtl_file_location(filename) self.add_slave(slave_name, filename, to_slave_type, to_slave_index)
def resolve_dependencies(self, filename, debug=True): """resolve_dependencies given a filename determine if there are any modules it depends on, recursively search for any files found in order to extrapolate all dependencies Args: filename: The filename to resolve dependencies for Return: Nothing Raises: ModuleFactoryError """ result = True ldebug = debug if debug: print "in resolve dependencies" local_file_list = [] if debug: print "working on filename: " + filename if (self.has_dependencies(filename, debug=ldebug)): if debug: print "found dependencies!" deps = self.get_list_of_dependencies(filename, debug=ldebug) for d in deps: try: dep_filename = saputils.find_module_filename(d, debug=ldebug) except ModuleNotFound as ex: print "Dependency Warning: %s" % (str(ex)) print "Module Name: %s" % (d) print "This warning may be due to:" print "\tIncluding a simulation only module" print "\tIncluding a vendor specific module" print "\tA module that was not found" continue if debug: print "found the filename: " + dep_filename #check this file out for dependecies, then append that on to the local list self.resolve_dependencies(dep_filename, debug=ldebug) if debug: print "found all sub dependencies for: " + dep_filename local_file_list.append(dep_filename) #go through the local file list and add anything found to the list of dependencies or verilog files for f in local_file_list: if (not self.verilog_dependency_list.__contains__(f) and not self.verilog_file_list.__contains__(f)): if debug: print "found dependency: " + f self.verilog_dependency_list.append(f) return
def set_host_interface(self, host_interface_name, debug = False): """Sets the host interface type. If host_interface_name is not a valid module name (or cannot be found for whatever reason), throws a ModuleNotFound exception.""" hi_name = self.get_unique_name("Host Interface", NodeType.HOST_INTERFACE) node_names = self.sgm.get_node_names() if hi_name not in node_names: self.sgm.add_node("Host Interface", NodeType.HOST_INTERFACE) # Check if the host interface is valid. file_name = saputils.find_module_filename(host_interface_name) file_name = saputils.find_rtl_file_location(file_name) # If the host interface is valid then get all the tags ... parameters = saputils.get_module_tags(filename = file_name, bus = self.get_bus_type()) # ... and set them up. self.sgm.set_parameters(hi_name, parameters) return True
def set_host_interface(self, host_interface_name, debug=False): """Sets the host interface type. If host_interface_name is not a valid module name (or cannot be found for whatever reason), throws a ModuleNotFound exception.""" hi_name = self.get_unique_name("Host Interface", NodeType.HOST_INTERFACE) node_names = self.sgm.get_node_names() if hi_name not in node_names: self.sgm.add_node("Host Interface", NodeType.HOST_INTERFACE) # Check if the host interface is valid. file_name = saputils.find_module_filename(host_interface_name) file_name = saputils.find_rtl_file_location(file_name) # If the host interface is valid then get all the tags ... parameters = saputils.get_module_tags(filename=file_name, bus=self.get_bus_type()) # ... and set them up. self.sgm.set_parameters(hi_name, parameters) return True
def test_find_module_filename(self): module_name = "uart" result = saputils.find_module_filename(module_name, debug=self.dbg) # result = saputils.find_module_filename(module_name, debug = True) self.assertEqual(len(result) > 0, True)
def process_file(self, filename="", file_dict={}, directory="", debug=False): """process_file read in a file, modify it (if necessary), then write it to the location specified by the directory variable Args: filename: the name of the file to process file_dict: dictionary associated with this file directory: output directory Return: Raises: ModuleFactoryError IOError """ if (len(filename) == 0): raise ModuleFactoryError("No filename specified") if (len(directory) == 0): raise ModuleFactoryError("No output directory specified") if (filename.endswith(".v")): self.verilog_file_list.append(filename) if debug: print "in process file" print "\t%s" % filename #maybe load a tags?? #using the location value in the file_dict find the file and #pull it into a buf self.buf = "" file_location = "" #There are two types of files #ones that are copied over from a location #ones that are generated by scripts #The file is specified by a location and basically needs to be copied over if file_dict.has_key("location"): file_location = os.getenv( "SAPLIB_BASE") + "/" + file_dict["location"] if (debug): print("getting file: " + filename + " from location: " + file_location) found_file = False try: filein = open( saputils.resolve_linux_path(file_location + "/" + filename)) self.buf = filein.read() filein.close() found_file = True except IOError as err: pass if not found_file: if debug: print "searching for file...", try: absfilename = saputils.find_rtl_file_location(filename) filein = open(absfilename) self.buf = filein.read() filein.close() except: if debug: print "Failed to find file" raise ModuleFactoryError("File %s not found searched %s and in the HDL dir \n \ (%s)" % (filename, \ file_location, \ os.getenv("SAPLIB_BASE") + "/hdl/rtl")) if debug: print "found file!" print "file content: " + self.buf #File is generated by a script elif (not file_dict.has_key("gen_script")): raise ModuleFactoryError( "File %s does not declare a location or a script! Check the template file" % filename) if (debug): print "Project name: " + self.tags["PROJECT_NAME"] #if the generation flag is set in the dictionary if (file_dict.has_key("gen_script")): if (debug): print "found the generation script" print "run generation script: " + file_dict["gen_script"] #open up the new gen module cl = __import__("gen") if debug: print "cl: " + str(cl) Gen = getattr(cl, "Gen") if debug: print "Gen: " + str(Gen) self.gen_module = __import__(file_dict["gen_script"]) gen_success_flag = False #find the script and dynamically add it for name in dir(self.gen_module): obj = getattr(self.gen_module, name) # print "object type: " + str(obj) #XXX: debug section start if debug: print "name: " + name if isclass(obj): if debug: print "\tobject type: " + str(obj) print "\tis class" if issubclass(obj, cl.Gen): if debug: print "\t\tis subclass" #XXX: debug section end if isclass(obj) and issubclass(obj, Gen) and obj is not Gen: self.gen = obj() if debug: print "obj = " + str(self.gen) self.buf = self.gen.gen_script(tags=self.tags, buf=self.buf) gen_success_flag = True if not gen_success_flag: raise ModuleFactoryError( "Failed to execute the generation script %s" % file_dict["gen_script"]) else: #no script to execute, just tags self.apply_tags() if debug: print self.buf #write the file to the specified directory if (len(self.buf) > 0): result = self.write_file(directory, filename) if (self.has_dependencies(filename)): deps = self.get_list_of_dependencies(filename) for d in deps: try: result = saputils.find_module_filename(d) if (len(result) == 0): print "Error: couldn't find dependency filename" continue f = saputils.find_module_filename(d) if (f not in self.verilog_dependency_list and f not in self.verilog_file_list): if debug: print "found dependency: " + f self.verilog_dependency_list.append(f) except ModuleNotFound as err: continue
def apply_slave_tags_to_project(self, debug=False): """Apply the slave tags to the project tags.""" # Get all the slaves. p_count = self.get_number_of_slaves(SlaveType.PERIPHERAL) m_count = self.get_number_of_slaves(SlaveType.MEMORY) # bind_dict = self.get_master_bind_dict() for i in range(0, p_count): sc_slave = self.sgm.get_slave_at(i, SlaveType.PERIPHERAL) uname = sc_slave.unique_name name = sc_slave.name # print "name: " + str(name) if name == "DRT": continue if name not in self.project_tags["SLAVES"].keys(): self.project_tags["SLAVES"][name] = {} pt_slave = self.project_tags["SLAVES"][name] if "bind" not in pt_slave.keys(): pt_slave["bind"] = {} # Overwrite the current arbitrator dictionary. if "BUS" in pt_slave.keys(): pt_slave["BUS"] = {} if "arbitrator_masters" in sc_slave.parameters.keys(): ams = sc_slave.parameters["arbitrator_masters"] if len(ams) > 0: # Add the BUS keyword to the arbitrator master. pt_slave["BUS"] = {} # Add all the items from the sc version. for a in ams: if debug: print "arbitrator name: %s" % a arb_slave = self.get_connected_arbitrator_slave( uname, a) arb_name = self.sgm.get_node(arb_slave).name if arb_slave is not None: pt_slave["BUS"][a] = arb_name # pt_slave["BUS"] # Clear the current bindings in the project tags. pt_slave["bind"] = {} bindings = self.sgm.get_node_bindings(uname) # bind = sc_slave.bindings # print "bind id: " + str(id(bindings)) if debug: print "bind contents: " + str(bindings) for p in bindings.keys(): pt_slave["bind"][p] = {} pt_slave["bind"][p]["port"] = bindings[p]["pin"] pt_slave["bind"][p]["direction"] = bindings[p]["direction"] # Add filenames. module = sc_slave.parameters["module"] filename = saputils.find_module_filename(module) pt_slave["filename"] = filename # Memory BUS for i in range(0, m_count): sc_slave = self.sgm.get_slave_at(i, SlaveType.MEMORY) uname = sc_slave.unique_name name = sc_slave.name # print "name: " + str(name) if name not in self.project_tags["MEMORY"].keys(): self.project_tags["MEMORY"][name] = {} pt_slave = self.project_tags["MEMORY"][name] if "bind" not in pt_slave.keys(): pt_slave["bind"] = {} # Overwrite the current arbitrator dictionary. if "BUS" in pt_slave.keys(): pt_slave["BUS"] = {} if "arbitrator_masters" in sc_slave.parameters.keys(): ams = sc_slave.parameters["arbitrator_masters"] if len(ams) > 0: # Add the BUS keyword to the arbitrator master. pt_slave["BUS"] = {} # Add all the items from the sc version. for a in ams: if debug: print "arbitrator name: %s" % a arb_slave = self.get_connected_arbitrator_slave( uname, a) arb_name = self.sgm.get_node(arb_slave).name if arb_slave is not None: pt_slave["BUS"][a] = arb_name # pt_slave["BUS"] # Clear the current bindings in the project tags. pt_slave["bind"] = {} bindings = self.sgm.get_node_bindings(uname) # print "bind id: " + str(id(bindings)) if debug: print "bind contents: " + str(bindings) for p in bindings.keys(): pt_slave["bind"][p] = {} pt_slave["bind"][p]["port"] = bindings[p]["pin"] pt_slave["bind"][p]["direction"] = bindings[p]["direction"]
def apply_slave_tags_to_project(self, debug = False): """Apply the slave tags to the project tags.""" # Get all the slaves. p_count = self.get_number_of_slaves(SlaveType.PERIPHERAL) m_count = self.get_number_of_slaves(SlaveType.MEMORY) # bind_dict = self.get_master_bind_dict() for i in range(0, p_count): sc_slave = self.sgm.get_slave_at(i, SlaveType.PERIPHERAL) uname = sc_slave.unique_name name = sc_slave.name # print "name: " + str(name) if name == "DRT": continue if name not in self.project_tags["SLAVES"].keys(): self.project_tags["SLAVES"][name] = {} pt_slave = self.project_tags["SLAVES"][name] if "bind" not in pt_slave.keys(): pt_slave["bind"] = {} # Overwrite the current arbitrator dictionary. if "BUS" in pt_slave.keys(): pt_slave["BUS"] = {} if "arbitrator_masters" in sc_slave.parameters.keys(): ams = sc_slave.parameters["arbitrator_masters"] if len(ams) > 0: # Add the BUS keyword to the arbitrator master. pt_slave["BUS"] = {} # Add all the items from the sc version. for a in ams: if debug: print "arbitrator name: %s" % a arb_slave = self.get_connected_arbitrator_slave(uname, a) arb_name = self.sgm.get_node(arb_slave).name if arb_slave is not None: pt_slave["BUS"][a] = arb_name # pt_slave["BUS"] # Clear the current bindings in the project tags. pt_slave["bind"] = {} bindings = self.sgm.get_node_bindings(uname) # bind = sc_slave.bindings # print "bind id: " + str(id(bindings)) if debug: print "bind contents: " + str(bindings) for p in bindings.keys(): pt_slave["bind"][p] = {} pt_slave["bind"][p]["port"] = bindings[p]["pin"] pt_slave["bind"][p]["direction"] = bindings[p]["direction"] # Add filenames. module = sc_slave.parameters["module"] filename = saputils.find_module_filename(module) pt_slave["filename"] = filename # Memory BUS for i in range(0, m_count): sc_slave = self.sgm.get_slave_at(i, SlaveType.MEMORY) uname = sc_slave.unique_name name = sc_slave.name # print "name: " + str(name) if name not in self.project_tags["MEMORY"].keys(): self.project_tags["MEMORY"][name] = {} pt_slave = self.project_tags["MEMORY"][name] if "bind" not in pt_slave.keys(): pt_slave["bind"] = {} # Overwrite the current arbitrator dictionary. if "BUS" in pt_slave.keys(): pt_slave["BUS"] = {} if "arbitrator_masters" in sc_slave.parameters.keys(): ams = sc_slave.parameters["arbitrator_masters"] if len(ams) > 0: # Add the BUS keyword to the arbitrator master. pt_slave["BUS"] = {} # Add all the items from the sc version. for a in ams: if debug: print "arbitrator name: %s" % a arb_slave = self.get_connected_arbitrator_slave(uname, a) arb_name = self.sgm.get_node(arb_slave).name if arb_slave is not None: pt_slave["BUS"][a] = arb_name # pt_slave["BUS"] # Clear the current bindings in the project tags. pt_slave["bind"] = {} bindings = self.sgm.get_node_bindings(uname) # print "bind id: " + str(id(bindings)) if debug: print "bind contents: " + str(bindings) for p in bindings.keys(): pt_slave["bind"][p] = {} pt_slave["bind"][p]["port"] = bindings[p]["pin"] pt_slave["bind"][p]["direction"] = bindings[p]["direction"]
def test_find_module_filename(self): module_name = "uart" result = saputils.find_module_filename(module_name, debug = self.dbg) # result = saputils.find_module_filename(module_name, debug = True) self.assertEqual(len(result) > 0, True)