Exemple #1
0
def export_sim_ise(args, simdir, link, thread):
	prj = args.prj
	simdir = simdir if simdir is not None else prj.basedir + ".sim" + "." + thread.lower()

	log.info("Generating testbench for thread " + thread + " to '" + simdir + "'")

	threads = [_ for _ in prj.threads if _.name == thread]
	if (len(threads) == 1):
		thread = threads[0]

		if thread.hwsource is None:
			log.error("No hardware source specified")
	else:
		log.error("Thread '" + thread  + "' not found")
		return

	tmp = tempfile.TemporaryDirectory()
	reconos.scripts.hw.export.export_hw_thread(args, tmp.name, link, thread.name)

	dictionary = {}
	dictionary["THREAD"] = thread.name.lower()
	srcs = shutil2.join(tmp.name, "rt_" + thread.name.lower() + "_v1_00_a", "hdl", "vhdl")
	dictionary["SOURCES"] = [srcs]
	files = shutil2.listfiles(srcs, True)
	dictionary["FILES"] = [{"File": _} for _ in files]

	log.info("Generating export files ...")
	tmpl = "sim_testbench_" + prj.impinfo.xil[1]
	prj.apply_template(tmpl, dictionary, simdir, link)
Exemple #2
0
def export_hls_ise(args, hlsdir, link, thread):
	prj = args.prj
	hlsdir = hlsdir if hlsdir is not None else prj.basedir + ".hls" + "." + thread.lower()

	log.info("Generating hls project for thread " + thread + " to '" + hlsdir + "'")

	threads = [_ for _ in prj.threads if _.name == thread]
	if (len(threads) == 1):
		thread = threads[0]

		if thread.hwsource is None or not thread.hwsource == "hls":
			log.error("No hardware source specified")
	else:
		log.error("Thread '" + thread  + "' not found")
		return

	dictionary = {}
	dictionary["PART"] = prj.impinfo.part
	dictionary["NAME"] = thread.name.lower()
	dictionary["CLKPRD"] = min([_.clock.get_periodns() for _ in thread.slots])
	srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(), thread.hwsource)
	dictionary["SOURCES"] = [srcs]
	files = shutil2.listfiles(srcs, True)
	dictionary["FILES"] = [{"File": _} for _ in files]
	dictionary["HLSDIR"] = hlsdir
	dictionary["MEM"] = thread.mem
	dictionary["MEM_N"] = not thread.mem
	dictionary["RESOURCES"] = []
	for i, r in enumerate(thread.resources):
		d = {}
		d["Id"] = r.id
		d["NameUpper"] = (r.group + "_" + r.name).upper()
		d["NameLower"] = (r.group + "_" + r.name).lower()
		d["LocalId"] = i
		d["HexLocalId"] =  "%08x" % i
		d["Type"] = r.type
		d["TypeUpper"] = r.type.upper()
		dictionary["RESOURCES"].append(d)

	log.info("Generating export files ...")
	prj.apply_template("thread_hls_prj", dictionary, hlsdir)
Exemple #3
0
def _export_hw_thread_ise_vivado(prj, hwdir, link, thread):
    ''' 
	Generates sources for one hardware thread for ReconOS in an ISE/XPS or Vivado project.
	
	It checks whether vhdl or hls sources shall be used and generates the hardware thread
	from the source templates. 
	
	hwdir gives the name of the project directory
	link boolean; if true files will be linked instead of copied
	thread is the name of the hardware thread to generate
	'''
    hwdir = hwdir if hwdir is not None else prj.basedir + ".hw" + "." + thread.lower(
    )

    log.info("Exporting thread " + thread + " to directory '" + hwdir + "'")

    threads = [_ for _ in prj.threads if _.name == thread]
    if (len(threads) == 1):
        thread = threads[0]

        if thread.hwsource is None:
            log.info("No hardware source specified")
    else:
        log.error("Thread '" + thread + "' not found")
        return

    if thread.hwsource == "vhdl":
        dictionary = {}
        dictionary["ID"] = thread.id
        dictionary["NAME"] = thread.name.lower()
        dictionary["MEM"] = thread.mem
        dictionary["MEM_N"] = not thread.mem
        dictionary["CLKPRD"] = min(
            [_.clock.get_periodns() for _ in thread.slots])
        srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(),
                            thread.hwsource)
        dictionary["SOURCES"] = [srcs]
        incls = shutil2.listfiles(srcs, True)
        dictionary["INCLUDES"] = [{"File": shutil2.trimext(_)} for _ in incls]
        dictionary["RESOURCES"] = []
        for i, r in enumerate(thread.resources):
            d = {}
            d["NameUpper"] = (r.group + "_" + r.name).upper()
            d["NameLower"] = (r.group + "_" + r.name).lower()
            d["LocalId"] = i
            d["HexLocalId"] = "%08x" % i
            dictionary["RESOURCES"].append(d)
        dictionary["PORTS"] = thread.ports

        log.info("Generating export files ...")
        prj.apply_template("thread_vhdl_pcore", dictionary, hwdir, link)

    elif thread.hwsource == "hls":
        tmp = tempfile.TemporaryDirectory()

        dictionary = {}
        dictionary["PART"] = prj.impinfo.part
        dictionary["NAME"] = thread.name.lower()
        dictionary["MEM"] = thread.mem
        dictionary["MEM_N"] = not thread.mem
        dictionary["CLKPRD"] = min(
            [_.clock.get_periodns() for _ in thread.slots])
        srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(),
                            thread.hwsource)
        dictionary["SOURCES"] = [srcs]
        files = shutil2.listfiles(srcs, True)
        dictionary["FILES"] = [{"File": _} for _ in files]
        dictionary["RESOURCES"] = []
        for i, r in enumerate(thread.resources):
            d = {}
            d["NameUpper"] = (r.group + "_" + r.name).upper()
            d["NameLower"] = (r.group + "_" + r.name).lower()
            d["LocalId"] = i
            d["HexLocalId"] = "%08x" % i
            d["Type"] = r.type
            d["TypeUpper"] = r.type.upper()
            dictionary["RESOURCES"].append(d)

        log.info("Generating temporary HLS project in " + tmp.name + " ...")
        prj.apply_template("thread_hls_build", dictionary, tmp.name)

        log.info("Starting Vivado HLS ...")
        if "bbd" in thread.hwoptions:
            if "vivado" in thread.hwoptions:
                subprocess.call("""
				  source /opt/Xilinx/Vivado/{1}/settings64.sh;
				  cd {0};
				  vivado_hls -f script_csynth.tcl;
				  vivado -mode batch -notrace -nojournal -nolog -source script_vivado_edn.tcl;"""
                                .format(tmp.name, prj.impinfo.hls[1]),
                                shell=True,
                                executable='/bin/bash')

                dictionary = {}
                dictionary["NAME"] = thread.name.lower()
                dictionary["MEM"] = thread.mem
                dictionary["MEM_N"] = not thread.mem
                srcs = shutil2.join(tmp.name, "rt_imp.edn")
                dictionary["SOURCES"] = [srcs]
                incls = ["rt_imp.edn"]
                dictionary["INCLUDES"] = [{"File": _} for _ in incls]
            else:
                log.error("No bbd tool found")
                return

            log.info("Generating export files ...")
            prj.apply_template("thread_hls_pcore_bbd", dictionary, hwdir)

        else:
            subprocess.call("""
			  source /opt/Xilinx/Vivado/{1}/settings64.sh;
			  cd {0};
			  vivado_hls -f script_csynth.tcl;""".format(tmp.name, prj.impinfo.hls[1]),
                            shell=True,
                            executable='/bin/bash')

            dictionary = {}
            dictionary["NAME"] = thread.name.lower()
            dictionary["MEM"] = thread.mem
            dictionary["MEM_N"] = not thread.mem
            srcs = shutil2.join(tmp.name, "hls", "sol", "syn", "vhdl")
            dictionary["SOURCES"] = [srcs]
            incls = shutil2.listfiles(srcs, True)
            dictionary["INCLUDES"] = [{
                "File": shutil2.trimext(_)
            } for _ in incls]

            log.info("Generating export files ...")
            prj.apply_template("thread_hls_pcore_vhdl", dictionary, hwdir)

        shutil2.rmtree("/tmp/test")
        shutil2.mkdir("/tmp/test")
        shutil2.copytree(tmp.name, "/tmp/test")
Exemple #4
0
def export_sw(args, swdir, link):
	prj = args.prj
	swdir = swdir if swdir is not None else prj.basedir + ".sw"

	log.info("Export software to project directory '" + prj.dir + "'")

	dictionary = {}
	dictionary["NAME"] = prj.name.lower()
	dictionary["CFLAGS"] = prj.impinfo.cflags
	dictionary["LDFLAGS"] = prj.impinfo.ldflags
	dictionary["THREADS"] = []
	for t in prj.threads:
		d = {}
		d["Name"] = t.name.lower()
		d["Slots"] = ",".join([str(_.id) for _ in t.slots])
		d["SlotCount"] = len(t.slots)
		d["Resources"] = ",".join(["&" + (_.group + "_" + _.name).lower() + "_res" for _ in t.resources])
		d["ResourceCount"] = len(t.resources)
		d["HasHw"] = t.hwsource is not None
		d["HasSw"] = t.swsource is not None
		dictionary["THREADS"].append(d)
	dictionary["RESOURCES"] = []
	for r in prj.resources:
		d = {}
		d["Id"] = r.id
		d["NameUpper"] = (r.group + "_" + r.name).upper()
		d["NameLower"] = (r.group + "_" + r.name).lower()
		d["Type"] = r.type
		d["TypeUpper"] = r.type.upper()
		d["Args"] = ", ".join(r.args)
		d["Id"] = r.id
		dictionary["RESOURCES"].append(d)
	dictionary["CLOCKS"] = []
	for c in prj.clocks:
		d = {}
		d["NameLower"] = c.name.lower()
		d["Id"] = c.id
		param = c.get_pllparam(800000000, 1600000000, 100000000)
		d["M"] = param[0]
		d["O"] = param[1]
		dictionary["CLOCKS"].append(d)

	srcs = shutil2.join(prj.dir, "src", "application")
	dictionary["SOURCES"] = [srcs]

	log.info("Generating export files ...")
	templ = "app_" + prj.impinfo.os
	prj.apply_template(templ, dictionary, swdir, link)

	log.info("Generating threads ...")
	for t in prj.threads:
		export_sw_thread(args, swdir, link, t.name)

	dictionary = {}
	dictionary["OS"] = prj.impinfo.os.lower()
	dictionary["BOARD"] = "_".join(prj.impinfo.board)
	dictionary["REPO_REL"] = shutil2.relpath(prj.impinfo.repo, swdir)
	dictionary["OBJS"] = [{"Source": shutil2.trimext(_) + ".o"}
	                       for _ in shutil2.listfiles(swdir, True, "c[p]*$")]

	template.preproc(shutil2.join(swdir, "Makefile"), dictionary, "overwrite", force=True)
Exemple #5
0
def main():
    prj = project.Project()
    prjfiles = shutil2.listfiles(".", ext="cfg$", rel=True)
    if not prjfiles:
        log.error("Project file not found")
        sys.exit(1)
    elif len(prjfiles) > 1:
        print("Multiple project files found. Please select:")
        for i, f in enumerate(prjfiles):
            print("  [" + str(i) + "] " + f)
        prjfile = prjfiles[int(input())]
        print("Selected '" + prjfile + "'")
    else:
        prjfile = prjfiles[0]

    prj.open(prjfile)

    pkgs = pkgutil.walk_packages(reconos.scripts.__path__,
                                 reconos.scripts.__name__ + ".")
    cmds = {}
    for m in [importlib.import_module(m) for f, m, p in pkgs if not p]:
        try:
            if getattr(m, "get_cmd")(None) is not None:
                cmd = getattr(m, "get_cmd")(prj)
                call = getattr(m, "get_call")(prj)
                parser = getattr(m, "get_parser")(prj)
                parser.set_defaults(prj=prj)
                cmds[cmd] = (call, parser)
        except AttributeError:
            log.warning("Could not import Module " + str(m))

    parser = argparse.ArgumentParser(prog="rdk",
                                     description="""
	  ReconOS Development Kit - Toolchain integrating different
	  scripts into an extendable development environment for
	  hardware software codesigns.""")
    parser.add_argument("-l",
                        "--log",
                        help="log level",
                        choices=["debug", "warning", "error"],
                        default="warning")
    subparsers = parser.add_subparsers(title="commands", dest="cmd")
    for cmd, attr in cmds.items():
        c = subparsers.add_parser(cmd, add_help=False, parents=[attr[1]])
        c.set_defaults(func=attr[0])

    args = parser.parse_args()

    if args.log == "debug":
        logging.getLogger().setLevel(level=logging.DEBUG)
    elif args.log == "warning":
        logging.getLogger().setLevel(level=logging.WARNING)
    else:
        logging.getLogger().setLevel(level=logging.ERROR)

    if args.cmd == None:
        exit = ["exit"]

        def _complete(text, state):
            if " " in readline.get_line_buffer():
                return None

            comp = [_ + " " for _ in cmds.keys() if _.startswith(text)]
            return comp[state] if state < len(comp) else None

        readline.parse_and_bind("tab: complete")
        readline.set_completer(_complete)

        while (True):
            try:
                if args.log == "debug":
                    i = input("ReconOS Toolchain [" + prjfile + "]> ")
                else:
                    i = input("ReconOS Toolchain> ")
            except KeyboardInterrupt:
                print()
                continue
            except EOFError:
                print()
                sys.exit(0)

            if i in exit:
                sys.exit(0)

            cmd = i.split()[0]
            if cmd in cmds.keys():
                cmd = cmds[cmd]
                try:
                    cmd[0](cmd[1].parse_args(i.split()[1:]))
                except SystemExit:
                    pass
                except Exception:
                    log.error("Executing command '" + i + "' failed")

            else:
                print("Command not found")
    else:
        args.func(args)
Exemple #6
0
def _export_hw_thread_vivado(prj, hwdir, link, thread):
    ''' 
	Generates sources for one hardware thread for ReconOS in an ISE/XPS or Vivado project.
	
	It checks whether vhdl or hls sources shall be used and generates the hardware thread
	from the source templates. 
	
	hwdir gives the name of the project directory
	link boolean; if true files will be linked instead of copied
	thread is the name of the hardware thread to generate
	'''
    hwdir = hwdir if hwdir is not None else prj.basedir + ".hw" + "." + thread.lower(
    )

    log.info("Exporting thread " + thread + " to directory '" + hwdir + "'")

    threads = [_ for _ in prj.threads if _.name == thread]
    if (len(threads) == 1):
        thread = threads[0]

        if thread.hwsource is None:
            log.info("No hardware source specified")
    else:
        log.error("Thread '" + thread + "' not found")
        return

    if thread.hwsource == "vhdl":
        dictionary = {}
        dictionary["ID"] = thread.id
        dictionary["NAME"] = thread.name.lower()
        dictionary["MEM"] = thread.mem
        dictionary["MEM_N"] = not thread.mem
        dictionary["CLKPRD"] = min(
            [_.clock.get_periodns() for _ in thread.slots])
        dictionary["HWSOURCE"] = thread.hwsource

        # "reconf" thread for partial reconfiguration is taken from template directory
        if prj.impinfo.pr == "true" and thread.name.lower() == "reconf":
            srcs = shutil2.join(prj.get_template("thread_rt_reconf"),
                                thread.hwsource)
        else:
            srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(),
                                thread.hwsource)

        dictionary["SOURCES"] = [srcs]
        incls = shutil2.listfiles(srcs, True)
        dictionary["INCLUDES"] = [{"File": shutil2.trimext(_)} for _ in incls]
        dictionary["RESOURCES"] = []
        for i, r in enumerate(thread.resources):
            d = {}
            d["NameUpper"] = (r.group + "_" + r.name).upper()
            d["NameLower"] = (r.group + "_" + r.name).lower()
            d["LocalId"] = i
            d["HexLocalId"] = "%08x" % i
            dictionary["RESOURCES"].append(d)
        dictionary["PORTS"] = thread.ports

        log.info("Generating export files ...")
        prj.apply_template("thread_vhdl_pcore", dictionary, hwdir, link)

        #For each slot: Generate .prj file listing sources for PR flow
        if thread.slots[0].reconfigurable == "true":
            for _ in thread.slots:
                dictionary["SLOTID"] = _.id
                prj.apply_template("thread_prj", dictionary, hwdir, link)

    elif thread.hwsource == "hls":
        tmp = tempfile.TemporaryDirectory()

        dictionary = {}

        #Added
        dictionary["MSGINCLUDEDIR"] = ""

        msg_install_path = prj.dir + "/build.msg/install/"
        if shutil2.exists(msg_install_path):
            msg_packages = [
                f for f in listdir(msg_install_path)
                if isdir(join(msg_install_path, f))
            ]
            #print(msg_packages)
            for msg_pack in msg_packages:
                dictionary[
                    "MSGINCLUDEDIR"] += "-I" + msg_install_path + msg_pack + "/include/ "

        #End Added

        dictionary["PART"] = prj.impinfo.part
        dictionary["NAME"] = thread.name.lower()
        dictionary["MEM"] = thread.mem
        dictionary["MEM_N"] = not thread.mem
        dictionary["HWSOURCE"] = thread.hwsource
        dictionary["CLKPRD"] = min(
            [_.clock.get_periodns() for _ in thread.slots])
        # "reconf" thread for partial reconfiguration is taken from template directory
        if prj.impinfo.pr == "true" and thread.name.lower() == "reconf":
            srcs = shutil2.join(prj.get_template("thread_rt_reconf"),
                                thread.hwsource)
        else:
            srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(),
                                thread.hwsource)
        dictionary["SOURCES"] = [srcs]
        files = shutil2.listfiles(srcs, True)
        dictionary["FILES"] = [{"File": _} for _ in files]
        dictionary["RESOURCES"] = []
        for i, r in enumerate(thread.resources):
            d = {}
            d["NameUpper"] = (r.group + "_" + r.name).upper()
            d["NameLower"] = (r.group + "_" + r.name).lower()
            d["LocalId"] = i
            d["HexLocalId"] = "%08x" % i
            d["Type"] = r.type
            d["TypeUpper"] = r.type.upper()
            dictionary["RESOURCES"].append(d)

        log.info("Generating temporary HLS project in " + tmp.name + " ...")
        prj.apply_template("thread_hls_build", dictionary, tmp.name)

        log.info("Starting Vivado HLS ...")
        if "bbd" in thread.hwoptions:
            if "vivado" in thread.hwoptions:
                subprocess.call("""
				  source /opt/Xilinx/Vivado/{1}/settings64.sh;
				  cd {0};
				  vivado_hls -f script_csynth.tcl;
				  vivado -mode batch -notrace -nojournal -nolog -source script_vivado_edn.tcl;"""
                                .format(tmp.name, prj.impinfo.hls[1]),
                                shell=True)

                dictionary = {}
                dictionary["NAME"] = thread.name.lower()
                dictionary["MEM"] = thread.mem
                dictionary["MEM_N"] = not thread.mem
                srcs = shutil2.join(tmp.name, "rt_imp.edn")
                dictionary["SOURCES"] = [srcs]
                incls = ["rt_imp.edn"]
                dictionary["INCLUDES"] = [{"File": _} for _ in incls]
            else:
                log.error("No bbd tool found")
                return

            log.info("Generating export files ...")
            prj.apply_template("thread_hls_pcore_bbd", dictionary, hwdir)

        else:
            subprocess.call("""
			  source /opt/Xilinx/Vivado/{1}/settings64.sh;
			  cd {0};
			  vivado_hls -f script_csynth.tcl;""".format(tmp.name, prj.impinfo.hls[1]),
                            shell=True)

            dictionary = {}
            dictionary["NAME"] = thread.name.lower()
            dictionary["MEM"] = thread.mem
            dictionary["MEM_N"] = not thread.mem
            srcs = shutil2.join(tmp.name, "hls", "sol", "syn", "vhdl")
            #HLS instantiates subcores (e.g. floating point units) in VHDL form during the export step
            #The path above contains only .tcl instantiations, which our IP Packager flow doesn't understand
            #So we add extract the convenient .vhd definitions from the following path:
            srcs2 = shutil2.join(tmp.name, "hls", "sol", "impl", "ip", "hdl",
                                 "ip")
            dictionary["SOURCES"] = [srcs, srcs2]
            incls = shutil2.listfiles(srcs, True)
            incls += shutil2.listfiles(srcs2, True)
            dictionary["INCLUDES"] = [{
                "File": shutil2.trimext(_)
            } for _ in incls]

            log.info("Generating export files ...")
            if thread.videoout == 0:
                prj.apply_template("thread_hls_pcore_vhdl", dictionary, hwdir)
            else:
                print("Found Video Out! \n")
                prj.apply_template("thread_hls_pcore_video_vhdl", dictionary,
                                   hwdir)

            #For each slot: Generate .prj file listing sources for PR flow
            if thread.slots[0].reconfigurable == "true":
                for _ in thread.slots:
                    dictionary["SLOTID"] = _.id
                    prj.apply_template("thread_prj", dictionary, hwdir, link)

        #Save temporary HLS project directory for analysis:
        shutil2.mkdir("/tmp/test")
        save_dir_hls_prj = shutil2.join(hwdir, "..",
                                        "tmp_hls_prj_" + thread.name.lower())
        shutil2.copytree(tmp.name, "/tmp/test")
        shutil2.rmtree(save_dir_hls_prj)
        shutil2.mkdir(save_dir_hls_prj)
        shutil2.copytree(tmp.name, save_dir_hls_prj)
Exemple #7
0
def _export_hw_thread_ise_vivado(prj, hwdir, link, thread):
	''' 
	Generates sources for one hardware thread for ReconOS in an ISE/XPS or Vivado project.
	
	It checks whether vhdl or hls sources shall be used and generates the hardware thread
	from the source templates. 
	
	hwdir gives the name of the project directory
	link boolean; if true files will be linked instead of copied
	thread is the name of the hardware thread to generate
	'''
	hwdir = hwdir if hwdir is not None else prj.basedir + ".hw" + "." + thread.lower()

	log.info("Exporting thread " + thread + " to directory '" + hwdir + "'")

	threads = [_ for _ in prj.threads if _.name == thread]
	if (len(threads) == 1):
		thread = threads[0]

		if thread.hwsource is None:
			log.info("No hardware source specified")
	else:
		log.error("Thread '" + thread  + "' not found")
		return

	if thread.hwsource == "vhdl":
		dictionary = {}
		dictionary["ID"] = thread.id
		dictionary["NAME"] = thread.name.lower()
		dictionary["MEM"] = thread.mem
		dictionary["MEM_N"] = not thread.mem
		dictionary["CLKPRD"] = min([_.clock.get_periodns() for _ in thread.slots])
		srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(), thread.hwsource)
		dictionary["SOURCES"] = [srcs]
		incls = shutil2.listfiles(srcs, True)
		dictionary["INCLUDES"] = [{"File": shutil2.trimext(_)} for _ in incls]
		dictionary["RESOURCES"] = []
		for i, r in enumerate(thread.resources):
			d = {}
			d["NameUpper"] = (r.group + "_" + r.name).upper()
			d["NameLower"] = (r.group + "_" + r.name).lower()
			d["LocalId"] = i
			d["HexLocalId"] =  "%08x" % i
			dictionary["RESOURCES"].append(d)
		dictionary["PORTS"] = thread.ports

		log.info("Generating export files ...")
		prj.apply_template("thread_vhdl_pcore", dictionary, hwdir, link)

	elif thread.hwsource == "hls":
		tmp = tempfile.TemporaryDirectory()

		dictionary = {}
		dictionary["PART"] = prj.impinfo.part
		dictionary["NAME"] = thread.name.lower()
		dictionary["MEM"] = thread.mem
		dictionary["MEM_N"] = not thread.mem
		dictionary["CLKPRD"] = min([_.clock.get_periodns() for _ in thread.slots])
		srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(), thread.hwsource)
		dictionary["SOURCES"] = [srcs]
		files = shutil2.listfiles(srcs, True)
		dictionary["FILES"] = [{"File": _} for _ in files]
		dictionary["RESOURCES"] = []
		for i, r in enumerate(thread.resources):
			d = {}
			d["NameUpper"] = (r.group + "_" + r.name).upper()
			d["NameLower"] = (r.group + "_" + r.name).lower()
			d["LocalId"] = i
			d["HexLocalId"] =  "%08x" % i
			d["Type"] = r.type
			d["TypeUpper"] = r.type.upper()
			dictionary["RESOURCES"].append(d)

		log.info("Generating temporary HLS project in " + tmp.name + " ...")
		prj.apply_template("thread_hls_build", dictionary, tmp.name)

		log.info("Starting Vivado HLS ...")
		if "bbd" in thread.hwoptions:
			if "vivado" in thread.hwoptions:
				subprocess.call("""
				  source /opt/Xilinx/Vivado/{1}/settings64.sh;
				  cd {0};
				  vivado_hls -f script_csynth.tcl;
				  vivado -mode batch -notrace -nojournal -nolog -source script_vivado_edn.tcl;""".format(tmp.name, prj.impinfo.hls[1]),
				  shell=True)

				dictionary = {}
				dictionary["NAME"] = thread.name.lower()
				dictionary["MEM"] = thread.mem
				dictionary["MEM_N"] = not thread.mem
				srcs = shutil2.join(tmp.name, "rt_imp.edn")
				dictionary["SOURCES"] = [srcs]
				incls = ["rt_imp.edn"]
				dictionary["INCLUDES"] = [{"File": _} for _ in incls]
			else:
				log.error("No bbd tool found")
				return

			log.info("Generating export files ...")
			prj.apply_template("thread_hls_pcore_bbd", dictionary, hwdir)

		else:
			subprocess.call("""
			  source /opt/Xilinx/Vivado/{1}/settings64.sh;
			  cd {0};
			  vivado_hls -f script_csynth.tcl;""".format(tmp.name, prj.impinfo.hls[1]),
			  shell=True)

			dictionary = {}
			dictionary["NAME"] = thread.name.lower()
			dictionary["MEM"] = thread.mem
			dictionary["MEM_N"] = not thread.mem
			srcs = shutil2.join(tmp.name, "hls", "sol", "syn", "vhdl")
			dictionary["SOURCES"] = [srcs]
			incls = shutil2.listfiles(srcs, True)
			dictionary["INCLUDES"] = [{"File": shutil2.trimext(_)} for _ in incls]

			log.info("Generating export files ...")
			prj.apply_template("thread_hls_pcore_vhdl", dictionary, hwdir)

		shutil2.rmtree("/tmp/test")
		shutil2.mkdir("/tmp/test")
		shutil2.copytree(tmp.name, "/tmp/test")
Exemple #8
0
def export_sw(args, swdir, link):
    prj = args.prj
    swdir = swdir if swdir is not None else prj.basedir + ".sw"

    log.info("Export software to project directory '" + prj.dir + "'")

    dictionary = {}
    dictionary["NAME"] = prj.name.lower()
    dictionary["CFLAGS"] = prj.impinfo.cflags
    dictionary["LDFLAGS"] = prj.impinfo.ldflags
    dictionary["THREADS"] = []
    dictionary["ROSMsgHeader"] = ""
    for t in prj.threads:
        d = {}
        d["Name"] = t.name.lower()
        d["Slots"] = ",".join([str(_.id) for _ in t.slots])
        d["SlotCount"] = len(t.slots)
        d["Resources"] = ",".join([
            "&" + (_.group + "_" + _.name).lower() + "_res"
            for _ in t.resources
        ])
        d["ResourceCount"] = len(t.resources)
        d["HasHw"] = t.hwsource is not None
        d["HasSw"] = t.swsource is not None
        dictionary["THREADS"].append(d)
    dictionary["RESOURCES"] = []
    for r in prj.resources:
        d = {}

        d["Group"] = r.group.lower()
        d["Id"] = r.id
        d["NameUpper"] = (r.group + "_" + r.name).upper()
        d["NameLower"] = (r.group + "_" + r.name).lower()
        d["Type"] = r.type
        d["TypeUpper"] = r.type.upper()
        if r.type == "rossub":
            for msg in prj.resources:
                if msg.name == r.args[1]:
                    d["Args"] = r.args[
                        0] + "," + "rosidl_typesupport_c__get_message_type_support_handle__" + msg.args[
                            0] + "__" + msg.args[1] + "__" + msg.args[
                                2] + "(), " + r.args[2] + ", " + r.args[3]
                    break

        elif r.type == "rospub":
            for msg in prj.resources:
                if msg.name == r.args[1]:
                    d["Args"] = r.args[
                        0] + "," + "rosidl_typesupport_c__get_message_type_support_handle__" + msg.args[
                            0] + "__" + msg.args[1] + "__" + msg.args[
                                2] + "(), " + r.args[2]
                    break

        elif r.type == "rossrvs":
            for msg in prj.resources:
                print(msg.name.replace('_req', '') + ";" + r.args[1] + ";")
                if msg.name.replace('_req', '') == r.args[1]:
                    d["Args"] = r.args[
                        0] + "," + "rosidl_typesupport_c__get_service_type_support_handle__" + msg.args[
                            0] + "__" + msg.args[1] + "__" + msg.args[
                                2] + "(), " + r.args[2] + ", " + r.args[3]
                    print(d["Args"])
                    break
        elif r.type == "rossrvc":
            for msg in prj.resources:
                print(msg.name.replace('_req', '') + ";" + r.args[1] + ";")
                if msg.name.replace('_req', '') == r.args[1]:
                    d["Args"] = r.args[
                        0] + "," + "rosidl_typesupport_c__get_service_type_support_handle__" + msg.args[
                            0] + "__" + msg.args[1] + "__" + msg.args[
                                2] + "(), " + r.args[2] + ", " + r.args[3]
                    print(d["Args"])
                    break
        elif r.type == "rosactions":
            for msg in prj.resources:
                print(
                    msg.name.replace('_goal_req', '') + ";" + r.args[1] + ";")
                if msg.name.replace('_goal_req', '') == r.args[1]:
                    d["Args"] = r.args[
                        0] + "," + "rosidl_typesupport_c__get_action_type_support_handle__" + msg.args[
                            0] + "__" + msg.args[1] + "__" + msg.args[
                                2] + "(), " + r.args[2] + ", " + r.args[3]
                    print(d["Args"])
                    break
        elif r.type == "rosactionc":
            for msg in prj.resources:
                print(
                    msg.name.replace('_goal_req', '') + ";" + r.args[1] + ";")
                if msg.name.replace('_goal_req', '') == r.args[1]:
                    d["Args"] = r.args[
                        0] + "," + "rosidl_typesupport_c__get_action_type_support_handle__" + msg.args[
                            0] + "__" + msg.args[1] + "__" + msg.args[
                                2] + "(), " + r.args[2] + ", " + r.args[3]
                    print(d["Args"])
                    break
        else:
            d["Args"] = ", ".join(r.args)
        d["Id"] = r.id
        if r.type == "rosmsg":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2]
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "
                dictionary["ROSMsgHeader"] += ("#include <" + r.args[0] + "/" +
                                               r.args[1] + "/" + r.args[2] +
                                               ".h>\n").lower()
            elif len(r.args) == 4:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "__Sequence"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "__Sequence__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "__Sequence__destroy"
                d["ROSDataTypeSequenceLength"] = r.args[3]
        if r.type == "rossrvmsgreq":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Request"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Request" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Request" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "
                dictionary["ROSMsgHeader"] += ("#include <" + r.args[0] + "/" +
                                               r.args[1] + "/" + r.args[2] +
                                               ".h>\n").lower()
        if r.type == "rossrvmsgres":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Response"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Response" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Response" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "

        if r.type == "rosactionmsggoalreq":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_SendGoal_Request"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_SendGoal_Request" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_SendGoal_Request" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "
                dictionary["ROSMsgHeader"] += ("#include <" + r.args[0] + "/" +
                                               r.args[1] + "/" + r.args[2] +
                                               ".h>\n").lower()
        if r.type == "rosactionmsggoalres":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Response"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Response" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Response" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "

        if r.type == "rosactionmsgresultreq":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Request"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Request" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Request" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "

        if r.type == "rosactionmsgresultres":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_GetResult_Response"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_GetResult_Response" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_GetResult_Response" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "

        if r.type == "rosactionmsgfeedback":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_FeedbackMessage"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_FeedbackMessage" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_FeedbackMessage" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "

        dictionary["RESOURCES"].append(d)
    dictionary["CLOCKS"] = []
    for c in prj.clocks:
        d = {}
        d["NameLower"] = c.name.lower()
        d["Id"] = c.id
        param = c.get_pllparam(800000000, 1600000000, 100000000)
        d["M"] = param[0]
        d["O"] = param[1]
        dictionary["CLOCKS"].append(d)

    srcs = shutil2.join(prj.dir, "src", "application")
    dictionary["SOURCES"] = [srcs]

    log.info("Generating export files ...")
    templ = "app_" + prj.impinfo.os
    prj.apply_template(templ, dictionary, swdir, link)

    log.info("Generating threads ...")
    for t in prj.threads:
        export_sw_thread(args, swdir, link, t.name)

    dictionary = {}
    dictionary["OS"] = prj.impinfo.os.lower()
    dictionary["BOARD"] = "_".join(prj.impinfo.board)
    dictionary["REPO_REL"] = shutil2.relpath(prj.impinfo.repo, swdir)
    dictionary["OBJS"] = [{
        "Source": shutil2.trimext(_) + ".o"
    } for _ in shutil2.listfiles(swdir, True, "c[cp]*$")]

    template.preproc(shutil2.join(swdir, "Makefile"),
                     dictionary,
                     "overwrite",
                     force=True)