def reset(self, path: str = None, mips_type: str = None) -> object: """ Reloads board configuration from static file :param path: absolute path to static file. Uses from default file if None. :param mips_type: version of SchoolMIPS core. Mips won't be added in project if None """ configs = Loader.load(path or self._static_path) self._qpf = configs.get("qpf", {}) self._qsf = configs.get("qsf", {}) self._sdc = configs.get("sdc", {}) v = configs.get("v", {}) self._v = v.get("assignments", {}) self._func = v.get("func", {}) self._functions = tuple( self.func_path(f) for f in FUNCTIONS.ITEMS.keys()) self._reset_mips(Loader.get_static_path(MIPS.CONFIG), mips_type) quartus_version = self._qpf['quartus_version'] if not self._qsf.get("original_quartus_version"): self._qsf['original_quartus_version'] = quartus_version if not self._qsf.get("last_quartus_version"): self._qsf['last_quartus_version'] = quartus_version if not self._qsf.get("project_output_directory"): self._qsf['project_output_directory'] = DESTINATIONS.OUTPUT return self
def generate(self, project_name: str = None, **kwargs) -> object: """ Generates FPGA configs """ if project_name or kwargs: self.setup(project_name=project_name, **kwargs) self.configs = {'LICENSE': Loader.load_static("LICENSE")} self.configs.update( dict( zip( map(lambda x: f"{self.project_name}.{x}", ("v", "qpf", "qsf", "sdc")), (Render.v(self.project_name, assignments=self._v, **self._mips_v), Render.qpf(self.project_name, **self._qpf), Render.qsf(self.project_name, func=self._functions, mips=self._mips_qsf, **self._qsf), Render.sdc(self.project_name, mips=self._mips_type, **self._sdc))))) # NOTE additional modules are placed in separate folder 'functions' self.configs.update( dict( zip( map(lambda x: x + ".v", self._functions), # file paths map(lambda x: Render.functions(x, **self._func), self._functions)))) if self._mips_type: # Generate additional configs for SchoolMIPS program_hex = os.path.join(PATHS.MIPS, "program.hex") self.configs['program.hex'] = Loader.load_static(program_hex) mips_path = os.path.join(PATHS.MIPS, self._mips_type) files = os.listdir(mips_path) self.configs.update( dict( zip( map(lambda x: os.path.join(DESTINATIONS.MIPS, x), files), map(lambda x: Loader.load_static(x, mips_path), files)))) return self
def __init__(self, board_name: str) -> NoReturn: """ :param board_name - name of existing board """ board_name = board_name.lower() if board_name not in BOARDS: logging.error("Incorrect board name: %s", board_name) raise ValueError("Incorrect board name: {}".format(board_name)) super(Board, self).__init__(Loader.get_static_path(board_name))
def _reset_mips(self, config_path: str, mips_type: str) -> NoReturn: self._mips_qsf = {} self._mips_v = {} if mips_type and mips_type not in MIPS.VERSIONS: logging.error("Unsupportable mips type: %s", mips_type) mips_type = None if mips_type: mips_configs = Loader.load(config_path) self._mips_qsf = mips_configs.get("qsf", {}) self._mips_v = mips_configs.get("v", {}) self._mips_type = mips_type
def test_get_static_path(self) -> NoReturn: def _test_static_path(filename: str) -> NoReturn: path = Loader.get_static_path(filename, self.path) assert path and isinstance(path, str) assert os.path.exists(path) for filename in ("__tmp", self.filename + ".tmp"): assert Loader.get_static_path(filename, self.path) is None _test_static_path(self.filename) _test_static_path(self.fullname) _test_static_path(self.fullpath)
def setup_class(self) -> NoReturn: self.config = Loader.load(MOCK_CONFIG)
def _test_static_path(filename: str) -> NoReturn: path = Loader.get_static_path(filename, self.path) assert path and isinstance(path, str) assert os.path.exists(path)
def test_load_static(self) -> NoReturn: params = {'encoding': None} for res in (Loader.load_static(self.fullpath, **params), Loader.load_static(self.filename, self.path, **params), Loader.load_static(self.fullname, self.path, **params)): _test_static_content(res)
def test_load(self) -> NoReturn: for res in (Loader.load(self.fullpath, fmt="yml"), Loader.load(self.fullpath)): _test_static_content(res)