Coverage for tsfpga/examples/example_env.py: 0%
16 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-31 20:01 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-31 20:01 +0000
1# --------------------------------------------------------------------------------------------------
2# Copyright (c) Lukas Vik. All rights reserved.
3#
4# This file is part of the tsfpga project, a project platform for modern FPGA development.
5# https://tsfpga.com
6# https://gitlab.com/tsfpga/tsfpga
7# --------------------------------------------------------------------------------------------------
9"""
10Common functions and definitions in the example build environment.
11"""
13# Import before others since it modifies PYTHONPATH. pylint: disable=unused-import
14import tsfpga.examples.example_pythonpath # noqa: F401
16# Third party libraries
17from hdl_registers.register_list import Register
19# First party libraries
20import tsfpga
21from tsfpga.module import get_modules
23TSFPGA_EXAMPLES_TEMP_DIR = tsfpga.TSFPGA_GENERATED
26def get_default_registers():
27 """
28 Default registers for tsfpga examples.
29 """
30 registers = [
31 Register("config", 0, "r_w", "Configuration register."),
32 Register(
33 "command",
34 1,
35 "wpulse",
36 "When this register is written, all '1's in the written word will be asserted for one "
37 "clock cycle in the FPGA logic.",
38 ),
39 Register("status", 2, "r", "Status register."),
40 Register(
41 "irq_status",
42 3,
43 "r_wpulse",
44 "Reading a '1' in this register means the corresponding interrupt has triggered.\n"
45 "Writing to this register will clear the interrupts where there is a '1' in the "
46 "written word.",
47 ),
48 Register(
49 "irq_mask",
50 4,
51 "r_w",
52 "A '1' in this register means that the corresponding interrupt is enabled.",
53 ),
54 ]
55 return registers
58def get_tsfpga_example_modules(names_include=None, names_avoid=None):
59 """
60 Wrapper of the regular :func:`.get_modules`. call with correct settings for tsfpga
61 example modules.
62 This will include the example tsfpga modules, but not the "real" modules.
64 Arguments will be passed on to :func:`.get_modules`.
65 """
66 return get_modules(
67 modules_folders=[tsfpga.TSFPGA_EXAMPLE_MODULES],
68 names_include=names_include,
69 names_avoid=names_avoid,
70 library_name_has_lib_suffix=False,
71 default_registers=get_default_registers(),
72 )
75def get_hdl_modules(names_include=None, names_avoid=None):
76 """
77 Wrapper of :func:`.get_modules` which returns the ``hdl_modules`` module objects.
79 If ``hdl_modules`` can not be found in the default repo checkout location,
80 the function will assert False.
82 Arguments will be passed on to :func:`.get_modules`.
84 Return:
85 :class:`.ModuleList`: The module objects.
86 """
87 # Presumed location of the hdl_modules repo
88 hdl_modules_repo_root = tsfpga.REPO_ROOT.parent.parent.resolve() / "hdl_modules" / "hdl_modules"
89 if (hdl_modules_repo_root / "modules").exists():
90 return get_modules(
91 modules_folders=[hdl_modules_repo_root / "modules"],
92 names_include=names_include,
93 names_avoid=names_avoid,
94 library_name_has_lib_suffix=False,
95 )
97 raise FileNotFoundError(
98 f"The hdl_modules modules could not be found. Searched in {hdl_modules_repo_root}"
99 )