Ejemplo n.º 1
0
	def test_generate_arbitrators_simple(self):
		"""the project file is supposed to generate one file"""
		config_file_name = os.getenv("SAPLIB_BASE") + "/example_project/arb_example.json"
		result = self.project.read_config_file(config_file_name)
		self.assertEqual(result, True)
		result = self.project.read_template(self.project.project_tags["TEMPLATE"])
		self.assertEqual(result, True)
		self.project.filegen.set_tags(self.project.project_tags)
		#get the clock rate from the constraint file
		self.project.project_tags["CLOCK_RATE"] = saputils.read_clock_rate(self.project.project_tags["CONSTRAINTS"]["constraint_files"][0])
		#generate the project directories and files
		self.project.project_tags["BASE_DIR"] = "~/sandbox/test_syc"
		saputils.create_dir(self.project.project_tags["BASE_DIR"])		

		#print "Parent dir: " + self.project.project_tags["BASE_DIR"]
		for key in self.project.template_tags["PROJECT_TEMPLATE"]["files"]:
			self.project.recursive_structure_generator(
							self.project.template_tags["PROJECT_TEMPLATE"]["files"],
							key,
							self.project.project_tags["BASE_DIR"])

		arb_tags = saparbitrator.generate_arbitrator_tags(self.project.project_tags)
		self.project.project_tags["ARBITRATORS"] = arb_tags

		result = self.project.generate_arbitrators(debug = self.dbg)
		self.assertEqual(result, 1)
Ejemplo n.º 2
0
  def test_generate_arbitrators_simple(self):
    """the project file is supposed to generate one file"""
    #read in the configuration file
    config_file_name = os.getenv("SAPLIB_BASE") + "/example_project/arb_example.json"
    try:
      self.project.read_config_file(config_file_name, debug=self.dbg)
    except TypeError as err:
      print "Error reading JSON Config File: %s" % str(err)
      self.assertEqual(True, False)

    #read in the template
    #if there is an error an assertion will be raised
    self.project.read_template(self.project.project_tags["TEMPLATE"])

    self.project.filegen.set_tags(self.project.project_tags)
    #get the clock rate from the constraint file
    board_dict = saputils.get_board_config("sycamore1")
    cfiles = board_dict["default_constraint_files"]
    self.project.project_tags["CLOCK_RATE"] = saputils.read_clock_rate(cfiles[0])
    #generate the project directories and files
    self.project.project_tags["BASE_DIR"] = "~/sandbox/test_syc"
    saputils.create_dir(self.project.project_tags["BASE_DIR"])		

    #print "Parent dir: " + self.project.project_tags["BASE_DIR"]
    for key in self.project.template_tags["PROJECT_TEMPLATE"]["files"]:
      self.project.recursive_structure_generator(
              self.project.template_tags["PROJECT_TEMPLATE"]["files"],
              key,
              self.project.project_tags["BASE_DIR"])

    arb_tags = saparbitrator.generate_arbitrator_tags(self.project.project_tags)
    self.project.project_tags["ARBITRATORS"] = arb_tags

    result = self.project.generate_arbitrators(debug = self.dbg)
    self.assertEqual(result, 1)
Ejemplo n.º 3
0
    def test_generate_arbitrators_difficult(self):
        """the project calls for three arbitrators, but two are identical"""

        #read in the configuration file
        config_file_name = os.getenv(
            "SAPLIB_BASE") + "/example_project/arb_difficult_example.json"
        result = False
        try:
            self.project.read_config_file(config_file_name, debug=self.dbg)
        except TypeError as err:
            print "Error reading JSON Config File: %s" % str(err)
            self.assertEqual(True, False)

        #this will throw an exception if something failed
        self.project.read_template(self.project.project_tags["TEMPLATE"])

        board_dict = saputils.get_board_config(
            self.project.project_tags["board"])
        cfiles = board_dict["default_constraint_files"]
        self.project.filegen.set_tags(self.project.project_tags)
        #get the clock rate from the constraint file
        self.project.project_tags["CLOCK_RATE"] = saputils.read_clock_rate(
            cfiles[0])
        #generate the project directories and files
        self.project.project_tags["BASE_DIR"] = "~/sandbox/test_syc"
        saputils.create_dir(self.project.project_tags["BASE_DIR"])

        #print "Parent dir: " + self.project.project_tags["BASE_DIR"]
        for key in self.project.template_tags["PROJECT_TEMPLATE"]["files"]:
            self.project.recursive_structure_generator(
                self.project.template_tags["PROJECT_TEMPLATE"]["files"], key,
                self.project.project_tags["BASE_DIR"])

        arb_tags = saparbitrator.generate_arbitrator_tags(
            self.project.project_tags)
        self.project.project_tags["ARBITRATORS"] = arb_tags

        result = self.project.generate_arbitrators(debug=self.dbg)
        self.assertEqual(result, 2)
Ejemplo n.º 4
0
    def test_generate_arbitrators_simple(self):
        """the project file is supposed to generate one file"""
        #read in the configuration file
        config_file_name = os.getenv(
            "SAPLIB_BASE") + "/example_project/arb_example.json"
        try:
            self.project.read_config_file(config_file_name, debug=self.dbg)
        except TypeError as err:
            print "Error reading JSON Config File: %s" % str(err)
            self.assertEqual(True, False)

        #read in the template
        #if there is an error an assertion will be raised
        self.project.read_template(self.project.project_tags["TEMPLATE"])

        self.project.filegen.set_tags(self.project.project_tags)
        #get the clock rate from the constraint file
        board_dict = saputils.get_board_config("sycamore1")
        cfiles = board_dict["default_constraint_files"]
        self.project.project_tags["CLOCK_RATE"] = saputils.read_clock_rate(
            cfiles[0])
        #generate the project directories and files
        self.project.project_tags["BASE_DIR"] = "~/sandbox/test_syc"
        saputils.create_dir(self.project.project_tags["BASE_DIR"])

        #print "Parent dir: " + self.project.project_tags["BASE_DIR"]
        for key in self.project.template_tags["PROJECT_TEMPLATE"]["files"]:
            self.project.recursive_structure_generator(
                self.project.template_tags["PROJECT_TEMPLATE"]["files"], key,
                self.project.project_tags["BASE_DIR"])

        arb_tags = saparbitrator.generate_arbitrator_tags(
            self.project.project_tags)
        self.project.project_tags["ARBITRATORS"] = arb_tags

        result = self.project.generate_arbitrators(debug=self.dbg)
        self.assertEqual(result, 1)
Ejemplo n.º 5
0
  def test_generate_arbitrators_difficult(self):
    """the project calls for three arbitrators, but two are identical"""

    #read in the configuration file
    config_file_name = os.getenv("SAPLIB_BASE") + "/example_project/arb_difficult_example.json"
    result = False
    try:
      self.project.read_config_file(config_file_name, debug=self.dbg)
    except TypeError as err:
      print "Error reading JSON Config File: %s" % str(err)
      self.assertEqual(True, False)

    #this will throw an exception if something failed
    self.project.read_template(self.project.project_tags["TEMPLATE"])

    board_dict = saputils.get_board_config(self.project.project_tags["board"])
    cfiles = board_dict["default_constraint_files"]
    self.project.filegen.set_tags(self.project.project_tags)
    #get the clock rate from the constraint file
    self.project.project_tags["CLOCK_RATE"] = saputils.read_clock_rate(cfiles[0])
    #generate the project directories and files
    self.project.project_tags["BASE_DIR"] = "~/sandbox/test_syc"
    saputils.create_dir(self.project.project_tags["BASE_DIR"])		

    #print "Parent dir: " + self.project.project_tags["BASE_DIR"]
    for key in self.project.template_tags["PROJECT_TEMPLATE"]["files"]:
      self.project.recursive_structure_generator(
              self.project.template_tags["PROJECT_TEMPLATE"]["files"],
              key,
              self.project.project_tags["BASE_DIR"])

    arb_tags = saparbitrator.generate_arbitrator_tags(self.project.project_tags)
    self.project.project_tags["ARBITRATORS"] = arb_tags
	
    result = self.project.generate_arbitrators(debug = self.dbg)
    self.assertEqual(result, 2)
Ejemplo n.º 6
0
    def test_read_clk_with_timespec(self):

        filename = "lx9.ucf"
        clock_rate = saputils.read_clock_rate(filename, debug=self.dbg)
        self.assertEqual(len(clock_rate) > 0, True)
Ejemplo n.º 7
0
    def test_read_clk_with_period(self):

        filename = "sycamore_serial.ucf"
        clock_rate = saputils.read_clock_rate(filename, debug=self.dbg)
        self.assertEqual(len(clock_rate) > 0, True)
Ejemplo n.º 8
0
	def test_read_clk_with_timespec(self):
		import saputils
		filename = "Avt_S6LX9_MicroBoard_UCF_110804.ucf" 
		clock_rate = saputils.read_clock_rate(filename, debug = self.dbg)
		self.assertEqual(len(clock_rate) > 0, True)
Ejemplo n.º 9
0
	def test_read_clk_with_period(self):
		import saputils
		filename = "sycamore_serial.ucf" 
		clock_rate = saputils.read_clock_rate(filename, debug = self.dbg)
		self.assertEqual(len(clock_rate) > 0, True)
Ejemplo n.º 10
0
    def generate_project(self, config_file_name, debug=False):
        """Generate the folders and files for the project

    Using the project tags and template tags this function generates all
    the directories and files of the project. It will go through the template
    structure and determine what files need to be added and call either
    a generation script (in the case of \"top.v\") or simply copy the file
    over (in the case of a peripheral or memory module.

    Args:
      config_file_name: name of the JSON configuration file

    Return:
      True: Success
      False: Failure

    Raises:
      TypeError
      IOError
      SapError
    """
        #reading the project config data into the the project tags
        #XXX: This should be changed to an exception begin raised and not a True False statement
        self.read_config_file(config_file_name)

        board_dict = saputils.get_board_config(self.project_tags["board"])
        cfiles = []
        pt = self.project_tags
        if "constraint_files" in pt.keys():
            cfiles = pt["constraint_files"]

        #if the user didn't specify any constraint files
        #load the default
        if len(cfiles) == 0:
            cfiles = board_dict["default_constraint_files"]

        #extrapolate the bus template


#XXX: Need to check all the constraint files
        self.project_tags["CLOCK_RATE"] = saputils.read_clock_rate(cfiles[0])

        self.read_template(self.project_tags["TEMPLATE"])

        #set all the tags within the filegen structure
        if debug:
            print "set all tags wihin filegen structure"
        self.filegen.set_tags(self.project_tags)

        #generate the project directories and files
        saputils.create_dir(self.project_tags["BASE_DIR"])
        if debug:
            print "generated the first dir"

        #generate the arbitrator tags, this is important because the top
        #needs the arbitrator tags
        arb_tags = saparbitrator.generate_arbitrator_tags(
            self.project_tags, False)
        self.project_tags["ARBITRATORS"] = arb_tags

        #print "Parent dir: " + self.project_tags["BASE_DIR"]
        for key in self.template_tags["PROJECT_TEMPLATE"]["files"]:
            self.recursive_structure_generator(
                self.template_tags["PROJECT_TEMPLATE"]["files"], key,
                self.project_tags["BASE_DIR"])

        if debug:
            print "generating project directories finished"

        if debug:
            print "generate the arbitrators"

        self.generate_arbitrators()

        #Generate all the slaves
        for slave in self.project_tags["SLAVES"]:
            fdict = {"location": ""}
            file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/slave"
            fn = self.project_tags["SLAVES"][slave]["filename"]
            try:
                self.filegen.process_file(filename=fn,
                                          file_dict=fdict,
                                          directory=file_dest,
                                          debug=debug)
            except ModuleFactoryError as err:
                print "ModuleFactoryError while generating a slave: %s" % str(
                    err)

            #each slave

        if ("MEMORY" in self.project_tags):
            for mem in self.project_tags["MEMORY"]:
                fdict = {"location": ""}
                file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/slave"
                fn = self.project_tags["MEMORY"][mem]["filename"]
                try:
                    self.filegen.process_file(filename=fn,
                                              file_dict=fdict,
                                              directory=file_dest)
                except ModuleFactoryError as err:
                    print "ModuleFactoryError while generating a memory slave: %s" % str(
                        err)

        #Copy the user specified constraint files to the constraints directory
        for constraint_fname in cfiles:
            sap_abs_base = os.getenv("SAPLIB_BASE")
            abs_proj_base = saputils.resolve_linux_path(
                self.project_tags["BASE_DIR"])
            constraint_path = self.get_constraint_path(constraint_fname)
            if (len(constraint_path) == 0):
                print "Couldn't find constraint: " + constraint_fname + ", searched in current directory and " + sap_abs_base + " /hdl/" + self.project_tags[
                    "board"]
                continue
            shutil.copy(constraint_path,
                        abs_proj_base + "/constraints/" + constraint_fname)

        #Generate the IO handler
        interface_filename = self.project_tags["INTERFACE"]["filename"]
        fdict = {"location": ""}
        file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/interface"
        result = self.filegen.process_file(filename=interface_filename,
                                           file_dict=fdict,
                                           directory=file_dest)

        if debug:
            print "copy over the dependencies..."
            print "verilog files: "
            for f in self.filegen.verilog_file_list:
                print f
                print "dependent files: "
        for d in self.filegen.verilog_dependency_list:
            fdict = {"location": ""}
            file_dest = self.project_tags["BASE_DIR"] + "/dependencies"
            result = self.filegen.process_file(filename=d,
                                               file_dict=fdict,
                                               directory=file_dest)
            if debug:
                print d
        return True
Ejemplo n.º 11
0
  def generate_project(self, config_file_name, debug=False):
    """Generate the folders and files for the project

    Using the project tags and template tags this function generates all
    the directories and files of the project. It will go through the template
    structure and determine what files need to be added and call either
    a generation script (in the case of \"top.v\") or simply copy the file
    over (in the case of a peripheral or memory module.

    Args:
      config_file_name: name of the JSON configuration file

    Return:
      True: Success
      False: Failure

    Raises:
      TypeError
      IOError
      SapError
    """
    #reading the project config data into the the project tags
#XXX: This should be changed to an exception begin raised and not a True False statement
    self.read_config_file(config_file_name)

    board_dict = saputils.get_board_config(self.project_tags["board"])
    cfiles = []
    pt = self.project_tags
    if "constraint_files" in pt.keys():
      cfiles = pt["constraint_files"]

    #if the user didn't specify any constraint files
    #load the default
    if len(cfiles) == 0:
      cfiles = board_dict["default_constraint_files"]

    #extrapolate the bus template
#XXX: Need to check all the constraint files
    self.project_tags["CLOCK_RATE"] = saputils.read_clock_rate(cfiles[0])

    self.read_template(self.project_tags["TEMPLATE"])

    #set all the tags within the filegen structure
    if debug:
      print "set all tags wihin filegen structure"
    self.filegen.set_tags(self.project_tags)

    #generate the project directories and files
    saputils.create_dir(self.project_tags["BASE_DIR"])
    if debug:
      print "generated the first dir"

    #generate the arbitrator tags, this is important because the top
    #needs the arbitrator tags
    arb_tags = saparbitrator.generate_arbitrator_tags(self.project_tags, False)
    self.project_tags["ARBITRATORS"] = arb_tags


    #print "Parent dir: " + self.project_tags["BASE_DIR"]
    for key in self.template_tags["PROJECT_TEMPLATE"]["files"]:
      self.recursive_structure_generator(
              self.template_tags["PROJECT_TEMPLATE"]["files"],
              key,
              self.project_tags["BASE_DIR"])

    if debug:
      print "generating project directories finished"

    if debug:
      print "generate the arbitrators"

    self.generate_arbitrators()

    #Generate all the slaves
    for slave in self.project_tags["SLAVES"]:
      fdict = {"location":""}
      file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/slave"
      fn = self.project_tags["SLAVES"][slave]["filename"]
      try:
        self.filegen.process_file(filename = fn, file_dict = fdict, directory=file_dest, debug=debug)
      except ModuleFactoryError as err:
        print "ModuleFactoryError while generating a slave: %s" % str(err) 

      #each slave

    if ("MEMORY" in self.project_tags):
      for mem in self.project_tags["MEMORY"]:
        fdict = {"location":""}
        file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/slave"
        fn = self.project_tags["MEMORY"][mem]["filename"]
        try:
          self.filegen.process_file(filename = fn, file_dict = fdict, directory = file_dest)
        except ModuleFactoryError as err:
          print "ModuleFactoryError while generating a memory slave: %s" % str(err)

    #Copy the user specified constraint files to the constraints directory
    for constraint_fname in cfiles:
      sap_abs_base = os.getenv("SAPLIB_BASE")
      abs_proj_base = saputils.resolve_linux_path(self.project_tags["BASE_DIR"])
      constraint_path = self.get_constraint_path(constraint_fname)
      if (len(constraint_path) == 0):
        print "Couldn't find constraint: " + constraint_fname + ", searched in current directory and " + sap_abs_base + " /hdl/" + self.project_tags["board"]
        continue
      shutil.copy (constraint_path, abs_proj_base + "/constraints/" + constraint_fname)

    #Generate the IO handler
    interface_filename = self.project_tags["INTERFACE"]["filename"]
    fdict = {"location":""}
    file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/interface"
    result = self.filegen.process_file(filename = interface_filename, file_dict=fdict , directory=file_dest)

    if debug:
      print "copy over the dependencies..."
      print "verilog files: "
      for f in self.filegen.verilog_file_list:
        print f
        print "dependent files: "
    for d in self.filegen.verilog_dependency_list:
      fdict = {"location":""}
      file_dest = self.project_tags["BASE_DIR"] + "/dependencies"
      result = self.filegen.process_file(filename = d, file_dict = fdict, directory = file_dest)
      if debug:
        print d
    return True
Ejemplo n.º 12
0
 def test_read_clk_with_timespec(self):
   
   filename = "lx9.ucf" 
   clock_rate = saputils.read_clock_rate(filename, debug = self.dbg)
   self.assertEqual(len(clock_rate) > 0, True)
Ejemplo n.º 13
0
	def generate_project(self, config_file_name, debug=False):
		"""Recursively go through template structure and generate the folders and files"""
		#reading the project config data into the the project tags
		result = self.read_config_file(config_file_name)
		if (not result):
			if (debug):
				print "failed to read in project config file"
			return False
		
		#extrapolate the bus template
		self.project_tags["CLOCK_RATE"] = saputils.read_clock_rate(self.project_tags["CONSTRAINTS"]["constraint_files"][0])
		result = self.read_template(self.project_tags["TEMPLATE"])
		if (not result):
			if (debug):
				print "failed to read in template file"
			return False

		#set all the tags within the filegen structure
		if debug:
			print "set all tags wihin filegen structure"
		self.filegen.set_tags(self.project_tags)

		#generate the project directories and files
		saputils.create_dir(self.project_tags["BASE_DIR"])		
		if debug:
			print "generated the first dir"

		#generate the arbitrator tags, this is important because the top
		#needs the arbitrator tags
		arb_tags = saparbitrator.generate_arbitrator_tags(self.project_tags, False) 
		self.project_tags["ARBITRATORS"] = arb_tags


		#print "Parent dir: " + self.project_tags["BASE_DIR"]
		for key in self.template_tags["PROJECT_TEMPLATE"]["files"]:
			self.recursive_structure_generator(
							self.template_tags["PROJECT_TEMPLATE"]["files"],
							key,
							self.project_tags["BASE_DIR"])

		if debug:
			print "generating project directories finished"
	
		if debug:
			print "generate the arbitrators"
		
		self.generate_arbitrators()

		#Generate all the slaves
		for slave in self.project_tags["SLAVES"]:
			fdict = {"location":""}
			file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/slave"
			fn = self.project_tags["SLAVES"][slave]["filename"]
			result = self.filegen.process_file(filename = fn, file_dict = fdict, directory=file_dest)
			if (not result):
				print "Error: Failed to process the slave file: " + fn
			#each slave

		if ("MEMORY" in self.project_tags):
			for mem in self.project_tags["MEMORY"]:
				fdict = {"location":""}
				file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/slave"
				fn = self.project_tags["MEMORY"][mem]["filename"]
				result = self.filegen.process_file(filename = fn, file_dict = fdict, directory = file_dest, debug = True)
				if (not result):
					print "Error: Failed to proecess memory file!: " + mem

		#Copy the user specified constraint files to the constraints directory
		for constraint_fname in self.project_tags["CONSTRAINTS"]["constraint_files"]:
			sap_abs_base = os.getenv("SAPLIB_BASE")
			abs_proj_base = saputils.resolve_linux_path(self.project_tags["BASE_DIR"])
			constraint_path = self.get_constraint_path(constraint_fname)
			if (len(constraint_path) == 0):
				print "Couldn't find constraint: " + constraint_fname + ", searched in current directory and " + sap_abs_base + " /hdl/" + self.project_tags["CONSTRAINTS"]["board"]
				continue
			shutil.copy (constraint_path, abs_proj_base + "/constraints/" + constraint_fname)

		#Generate the IO handler
		interface_filename = self.project_tags["INTERFACE"]
		fdict = {"location":""}
		file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/interface"
		result = self.filegen.process_file(filename = interface_filename, file_dict=fdict , directory=file_dest)

		if debug:
			print "copy over the dependencies..."
		print "verilog files: "
		for f in self.filegen.verilog_file_list:
			print f
		print "dependent files: "
		for d in self.filegen.verilog_dependency_list:
			fdict = {"location":""}
			file_dest = self.project_tags["BASE_DIR"] + "/dependencies"
			result = self.filegen.process_file(filename = d, file_dict = fdict, directory = file_dest)
			print d
		return True