marauder-register 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. marauder_register-1.2.0/LICENSE.txt +21 -0
  2. marauder_register-1.2.0/PKG-INFO +222 -0
  3. marauder_register-1.2.0/README.md +182 -0
  4. marauder_register-1.2.0/marauder_register/__init__.py +30 -0
  5. marauder_register-1.2.0/marauder_register/__main__.py +231 -0
  6. marauder_register-1.2.0/marauder_register/_version.py +10 -0
  7. marauder_register-1.2.0/marauder_register/bitfield.py +357 -0
  8. marauder_register-1.2.0/marauder_register/cocotb_bench.py +834 -0
  9. marauder_register-1.2.0/marauder_register/config.py +132 -0
  10. marauder_register-1.2.0/marauder_register/enum.py +110 -0
  11. marauder_register-1.2.0/marauder_register/exceptions.py +14 -0
  12. marauder_register-1.2.0/marauder_register/generators.py +745 -0
  13. marauder_register-1.2.0/marauder_register/reg.py +241 -0
  14. marauder_register-1.2.0/marauder_register/regmap.py +354 -0
  15. marauder_register-1.2.0/marauder_register/templates/amm2lb_verilog.j2 +84 -0
  16. marauder_register-1.2.0/marauder_register/templates/amm2lb_vhdl.j2 +127 -0
  17. marauder_register-1.2.0/marauder_register/templates/apb2lb_verilog.j2 +60 -0
  18. marauder_register-1.2.0/marauder_register/templates/apb2lb_vhdl.j2 +77 -0
  19. marauder_register-1.2.0/marauder_register/templates/axil2lb_verilog.j2 +162 -0
  20. marauder_register-1.2.0/marauder_register/templates/axil2lb_vhdl.j2 +195 -0
  21. marauder_register-1.2.0/marauder_register/templates/c_header.j2 +117 -0
  22. marauder_register-1.2.0/marauder_register/templates/cocotb_bench.j2 +56 -0
  23. marauder_register-1.2.0/marauder_register/templates/regmap_asciidoc.j2 +102 -0
  24. marauder_register-1.2.0/marauder_register/templates/regmap_md.j2 +94 -0
  25. marauder_register-1.2.0/marauder_register/templates/regmap_py.j2 +94 -0
  26. marauder_register-1.2.0/marauder_register/templates/regmap_verilog.j2 +476 -0
  27. marauder_register-1.2.0/marauder_register/templates/regmap_vhdl.j2 +601 -0
  28. marauder_register-1.2.0/marauder_register/templates/sv_package.j2 +44 -0
  29. marauder_register-1.2.0/marauder_register/templates/verilog_header.j2 +41 -0
  30. marauder_register-1.2.0/marauder_register/utils.py +219 -0
  31. marauder_register-1.2.0/marauder_register.egg-info/PKG-INFO +222 -0
  32. marauder_register-1.2.0/marauder_register.egg-info/SOURCES.txt +43 -0
  33. marauder_register-1.2.0/marauder_register.egg-info/dependency_links.txt +1 -0
  34. marauder_register-1.2.0/marauder_register.egg-info/entry_points.txt +2 -0
  35. marauder_register-1.2.0/marauder_register.egg-info/requires.txt +9 -0
  36. marauder_register-1.2.0/marauder_register.egg-info/top_level.txt +1 -0
  37. marauder_register-1.2.0/pyproject.toml +75 -0
  38. marauder_register-1.2.0/setup.cfg +4 -0
  39. marauder_register-1.2.0/tests/test_bitfield.py +290 -0
  40. marauder_register-1.2.0/tests/test_config.py +49 -0
  41. marauder_register-1.2.0/tests/test_enum.py +90 -0
  42. marauder_register-1.2.0/tests/test_examples.py +103 -0
  43. marauder_register-1.2.0/tests/test_generators.py +249 -0
  44. marauder_register-1.2.0/tests/test_reg.py +190 -0
  45. marauder_register-1.2.0/tests/test_regmap.py +279 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 esynr3z
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,222 @@
1
+ Metadata-Version: 2.4
2
+ Name: marauder-register
3
+ Version: 1.2.0
4
+ Summary: Control and status register (CSR) map generator for HDL projects
5
+ Author: Marauder Maintainer, esynr3z
6
+ Maintainer: Atech1
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/Atech1/Marauder_Registers
9
+ Project-URL: Documentation, https://github.com/Atech1/Marauder_Registers/tree/master/docs
10
+ Project-URL: Source, https://github.com/Atech1/Marauder_Registers
11
+ Project-URL: Issues, https://github.com/Atech1/Marauder_Registers/issues
12
+ Project-URL: Changelog, https://github.com/Atech1/Marauder_Registers/blob/master/CHANGELOG.md
13
+ Keywords: fpga,hdl,verilog,vhdl,csr,register-map,bitfield
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Programming Language :: Python :: 3.14
26
+ Classifier: Topic :: Software Development :: Embedded Systems
27
+ Classifier: Topic :: Software Development :: Code Generators
28
+ Requires-Python: >=3.8
29
+ Description-Content-Type: text/markdown
30
+ License-File: LICENSE.txt
31
+ Requires-Dist: pyyaml>=5.1
32
+ Requires-Dist: jinja2
33
+ Requires-Dist: wavedrom
34
+ Provides-Extra: test
35
+ Requires-Dist: pytest; extra == "test"
36
+ Requires-Dist: pytest-xdist; extra == "test"
37
+ Requires-Dist: cocotb>=2.0; extra == "test"
38
+ Requires-Dist: ruff; extra == "test"
39
+ Dynamic: license-file
40
+
41
+ # Marauder
42
+
43
+ > ### 🏴‍☠️ This is Marauder — a maintained fork of Corsair
44
+ >
45
+ > The [original Corsair project](https://github.com/esynr3z/corsair) has been **archived on GitHub**, and upstream froze the 1.x line (see the [release 2.x roadmap](https://github.com/esynr3z/corsair/discussions/97)). The planned 2.x rewrite **stalled on the archived `dev2` branch and never reached PyPI** — `1.0.4` is still the newest installable Corsair, so the 1.x line is where the working tool lives.
46
+ >
47
+ > I like this tool far too much to let it stagnate, so I've forked it as **Marauder**, which **continues the 1.x line**. The goal is straightforward: **keep Corsair alive and moving** — take on support for existing users, fix bugs, and add new features and generators. If Corsair was part of your flow, Marauder is intended to be a drop-in continuation of it.
48
+ >
49
+ > Bug reports, feature requests and pull requests are all welcome here. Huge thanks to [@esynr3z](https://github.com/esynr3z) for building Corsair in the first place — Marauder exists entirely on that foundation, and the original MIT license and attribution are retained.
50
+
51
+ ![marauder_logo](https://raw.githubusercontent.com/Atech1/Marauder_Registers/master/docs/img/logo.png)
52
+
53
+
54
+ Marauder is a tool that makes it easy to create and maintain control and status register (CSR) map for any HDL project. It allows you to describe your register map in a single file and then generate HDL code, headers, documentation and other things. This effectively eliminates any mismatches between hardware, software and documentation of your IP-core.
55
+
56
+ ![marauder_flow](https://raw.githubusercontent.com/Atech1/Marauder_Registers/master/docs/img/marauder_flow.png)
57
+
58
+ ## Features
59
+
60
+ - Various human-readable input formats: JSON, YAML or plain text table
61
+ - HDL code generation: Verilog or VHDL module with register map, Verilog header or SystemVerilog package with parameters and definitions
62
+ - Multi-protocol support: APB, AXI-Lite, Avalon-MM
63
+ - Documentation generation: Markdown, AsciiDoc
64
+ - Generation of software-related files: C header, Python module
65
+ - Extensibility: support of external file generators
66
+ - API: creation of custom workflow with Marauder API
67
+ - Verification: generated cocotb testbench with per-register tests
68
+
69
+ The documentation is in the [docs](https://github.com/Atech1/Marauder_Registers/blob/master/docs/index.rst) directory of this repository (Sphinx sources).
70
+
71
+ ## Install
72
+
73
+ Depending on your system, Python 3 executable might be `python` or `python3`.
74
+ If there any permissions issues, add `--user` key to the installation scripts.
75
+
76
+ To install the latest stable release:
77
+
78
+ ```sh
79
+ python3 -m pip install -U marauder-register
80
+ ```
81
+
82
+ ## Quick start
83
+
84
+ The best way to start is to create templates. You can create one for a register map in a format you like (choose onе from `json`, `yaml`, `txt`) :
85
+
86
+ ```sh
87
+ Marauder-register -t yaml
88
+ ```
89
+
90
+ This generates two files: one for register map in the format specified `regs.yaml`, and other for configuration - `csrconfig`.
91
+
92
+ Register map consists of a collection of memory mapped registers (also referred as CSRs), and registers are made up of bit fields. For example, register map of one register looks like this in YAML:
93
+
94
+ ```yaml
95
+ regmap:
96
+ - name: CTRL
97
+ description: Control register
98
+ address: 8
99
+ bitfields:
100
+ - name: BAUD
101
+ description: Baudrate value
102
+ reset: 0
103
+ width: 2
104
+ lsb: 0
105
+ access: rw
106
+ hardware: o
107
+ enums:
108
+ - name: B9600
109
+ description: 9600 baud
110
+ value: 0
111
+ - name: B38400
112
+ description: 38400 baud
113
+ value: 1
114
+ - name: B115200
115
+ description: 115200 baud
116
+ value: 2
117
+ ```
118
+
119
+ To know more about registers, bit fields and their attributes please check the [Register map](https://github.com/Atech1/Marauder_Registers/blob/master/docs/regmap.rst) documentation page.
120
+
121
+ Marauder is configuration-file-oriented tool. By default, it uses INI configuration file `csrconfig`. It specifies all the things needed for generation - input register map file, global parameters and output files (also called targets). It may looks like this:
122
+
123
+ ```ini
124
+ [globcfg]
125
+ data_width = 32
126
+ address_width = 16
127
+ register_reset = sync_pos
128
+
129
+ [v_module]
130
+ path = regs.v
131
+ interface = axil
132
+ generator = Verilog
133
+
134
+ [c_header]
135
+ path = regs.h
136
+ generator = CHeader
137
+ ```
138
+
139
+ Check the [Configuration file](https://github.com/Atech1/Marauder_Registers/blob/master/docs/config.rst) page to get more details about `csrconfig` and the [Introduction](https://github.com/Atech1/Marauder_Registers/blob/master/docs/introduction.rst) page to get general information about workflow.
140
+
141
+ `csrconfig` also acts like a build script for Marauder, so just run in the directory with `csrconfig` file:
142
+
143
+ ```sh
144
+ Marauder-register
145
+ ```
146
+
147
+ And then all the magic happens.
148
+
149
+ There are some additional options for overriding working directory, register map or configuration file - to get help simply run
150
+
151
+ ```sh
152
+ Marauder-register -h
153
+ ```
154
+
155
+ If you looking for some more examples please check `examples` folder.
156
+
157
+ ## Testbench generation
158
+
159
+ Marauder can also generate a cocotb testbench for the register map. Add a
160
+ `CocotbBench` target to `csrconfig`:
161
+
162
+ ```ini
163
+ [regs_tb]
164
+ path = tb/regs_tb.py
165
+ interface = axil
166
+ generator = CocotbBench
167
+ ```
168
+
169
+ Then run `Marauder-register` as usual. The generated module contains one cocotb test
170
+ per register and can be run with the cocotb runner or a cocotb Makefile.
171
+ See the [Generated testbenches](https://github.com/Atech1/Marauder_Registers/blob/master/docs/cocotb.rst) documentation for the full
172
+ workflow and limitations.
173
+
174
+ ## Development
175
+
176
+ Please follow the [Developer's Guide](https://github.com/Atech1/Marauder_Registers/blob/master/docs/contributing.rst).
177
+
178
+ ### HDL bench tests (cocotb)
179
+
180
+ The HDL benches in `tests/hdl` run under [cocotb](https://www.cocotb.org/).
181
+ Install the test extras and a VHDL simulator:
182
+
183
+ ```sh
184
+ python3 -m pip install -e ".[test]"
185
+
186
+ # Debian/Ubuntu
187
+ sudo apt-get install -y ghdl
188
+ ```
189
+
190
+ NVC is also supported and is the default VHDL simulator on Windows. See the
191
+ [NVC releases](https://github.com/nickg/nvc/releases) if it is not available
192
+ from your package manager.
193
+
194
+ Run the VHDL benches with GHDL or NVC:
195
+
196
+ ```sh
197
+ SIM=ghdl pytest -v tests/hdl -k vhdl
198
+ SIM=nvc pytest -v tests/hdl -k vhdl
199
+ ```
200
+
201
+ Without `SIM`, VHDL uses GHDL on Linux/macOS and NVC on Windows. Add
202
+ `-n auto` to run the matrix in parallel, or narrow it with pytest keywords.
203
+ For example, to run only the APB register-map tests:
204
+
205
+ ```sh
206
+ SIM=ghdl pytest -v tests/hdl -k "vhdl and apb and test_rmap"
207
+ ```
208
+
209
+ The matrix covers the Local Bus, APB, AXI-Lite and Avalon-MM register-map
210
+ interfaces, the APB/AXI-Lite/Avalon-MM to Local Bus bridges, and all four
211
+ reset styles. The cocotb test modules live in `tests/hdl/cocotb`; the pytest
212
+ wrappers generate the RTL and invoke the cocotb runner.
213
+
214
+ Verilog benches require Icarus Verilog (`iverilog`) and are skipped
215
+ automatically when it is not installed. Current validation is done with
216
+ GHDL and NVC for VHDL.
217
+
218
+ ## License
219
+
220
+ Marauder is licensed under [MIT License](https://github.com/Atech1/Marauder_Registers/blob/master/LICENSE.txt).
221
+
222
+ Corsair, the tool Marauder is forked from, was created by [@esynr3z](https://github.com/esynr3z) and is licensed under the MIT license as well.
@@ -0,0 +1,182 @@
1
+ # Marauder
2
+
3
+ > ### 🏴‍☠️ This is Marauder — a maintained fork of Corsair
4
+ >
5
+ > The [original Corsair project](https://github.com/esynr3z/corsair) has been **archived on GitHub**, and upstream froze the 1.x line (see the [release 2.x roadmap](https://github.com/esynr3z/corsair/discussions/97)). The planned 2.x rewrite **stalled on the archived `dev2` branch and never reached PyPI** — `1.0.4` is still the newest installable Corsair, so the 1.x line is where the working tool lives.
6
+ >
7
+ > I like this tool far too much to let it stagnate, so I've forked it as **Marauder**, which **continues the 1.x line**. The goal is straightforward: **keep Corsair alive and moving** — take on support for existing users, fix bugs, and add new features and generators. If Corsair was part of your flow, Marauder is intended to be a drop-in continuation of it.
8
+ >
9
+ > Bug reports, feature requests and pull requests are all welcome here. Huge thanks to [@esynr3z](https://github.com/esynr3z) for building Corsair in the first place — Marauder exists entirely on that foundation, and the original MIT license and attribution are retained.
10
+
11
+ ![marauder_logo](https://raw.githubusercontent.com/Atech1/Marauder_Registers/master/docs/img/logo.png)
12
+
13
+
14
+ Marauder is a tool that makes it easy to create and maintain control and status register (CSR) map for any HDL project. It allows you to describe your register map in a single file and then generate HDL code, headers, documentation and other things. This effectively eliminates any mismatches between hardware, software and documentation of your IP-core.
15
+
16
+ ![marauder_flow](https://raw.githubusercontent.com/Atech1/Marauder_Registers/master/docs/img/marauder_flow.png)
17
+
18
+ ## Features
19
+
20
+ - Various human-readable input formats: JSON, YAML or plain text table
21
+ - HDL code generation: Verilog or VHDL module with register map, Verilog header or SystemVerilog package with parameters and definitions
22
+ - Multi-protocol support: APB, AXI-Lite, Avalon-MM
23
+ - Documentation generation: Markdown, AsciiDoc
24
+ - Generation of software-related files: C header, Python module
25
+ - Extensibility: support of external file generators
26
+ - API: creation of custom workflow with Marauder API
27
+ - Verification: generated cocotb testbench with per-register tests
28
+
29
+ The documentation is in the [docs](https://github.com/Atech1/Marauder_Registers/blob/master/docs/index.rst) directory of this repository (Sphinx sources).
30
+
31
+ ## Install
32
+
33
+ Depending on your system, Python 3 executable might be `python` or `python3`.
34
+ If there any permissions issues, add `--user` key to the installation scripts.
35
+
36
+ To install the latest stable release:
37
+
38
+ ```sh
39
+ python3 -m pip install -U marauder-register
40
+ ```
41
+
42
+ ## Quick start
43
+
44
+ The best way to start is to create templates. You can create one for a register map in a format you like (choose onе from `json`, `yaml`, `txt`) :
45
+
46
+ ```sh
47
+ Marauder-register -t yaml
48
+ ```
49
+
50
+ This generates two files: one for register map in the format specified `regs.yaml`, and other for configuration - `csrconfig`.
51
+
52
+ Register map consists of a collection of memory mapped registers (also referred as CSRs), and registers are made up of bit fields. For example, register map of one register looks like this in YAML:
53
+
54
+ ```yaml
55
+ regmap:
56
+ - name: CTRL
57
+ description: Control register
58
+ address: 8
59
+ bitfields:
60
+ - name: BAUD
61
+ description: Baudrate value
62
+ reset: 0
63
+ width: 2
64
+ lsb: 0
65
+ access: rw
66
+ hardware: o
67
+ enums:
68
+ - name: B9600
69
+ description: 9600 baud
70
+ value: 0
71
+ - name: B38400
72
+ description: 38400 baud
73
+ value: 1
74
+ - name: B115200
75
+ description: 115200 baud
76
+ value: 2
77
+ ```
78
+
79
+ To know more about registers, bit fields and their attributes please check the [Register map](https://github.com/Atech1/Marauder_Registers/blob/master/docs/regmap.rst) documentation page.
80
+
81
+ Marauder is configuration-file-oriented tool. By default, it uses INI configuration file `csrconfig`. It specifies all the things needed for generation - input register map file, global parameters and output files (also called targets). It may looks like this:
82
+
83
+ ```ini
84
+ [globcfg]
85
+ data_width = 32
86
+ address_width = 16
87
+ register_reset = sync_pos
88
+
89
+ [v_module]
90
+ path = regs.v
91
+ interface = axil
92
+ generator = Verilog
93
+
94
+ [c_header]
95
+ path = regs.h
96
+ generator = CHeader
97
+ ```
98
+
99
+ Check the [Configuration file](https://github.com/Atech1/Marauder_Registers/blob/master/docs/config.rst) page to get more details about `csrconfig` and the [Introduction](https://github.com/Atech1/Marauder_Registers/blob/master/docs/introduction.rst) page to get general information about workflow.
100
+
101
+ `csrconfig` also acts like a build script for Marauder, so just run in the directory with `csrconfig` file:
102
+
103
+ ```sh
104
+ Marauder-register
105
+ ```
106
+
107
+ And then all the magic happens.
108
+
109
+ There are some additional options for overriding working directory, register map or configuration file - to get help simply run
110
+
111
+ ```sh
112
+ Marauder-register -h
113
+ ```
114
+
115
+ If you looking for some more examples please check `examples` folder.
116
+
117
+ ## Testbench generation
118
+
119
+ Marauder can also generate a cocotb testbench for the register map. Add a
120
+ `CocotbBench` target to `csrconfig`:
121
+
122
+ ```ini
123
+ [regs_tb]
124
+ path = tb/regs_tb.py
125
+ interface = axil
126
+ generator = CocotbBench
127
+ ```
128
+
129
+ Then run `Marauder-register` as usual. The generated module contains one cocotb test
130
+ per register and can be run with the cocotb runner or a cocotb Makefile.
131
+ See the [Generated testbenches](https://github.com/Atech1/Marauder_Registers/blob/master/docs/cocotb.rst) documentation for the full
132
+ workflow and limitations.
133
+
134
+ ## Development
135
+
136
+ Please follow the [Developer's Guide](https://github.com/Atech1/Marauder_Registers/blob/master/docs/contributing.rst).
137
+
138
+ ### HDL bench tests (cocotb)
139
+
140
+ The HDL benches in `tests/hdl` run under [cocotb](https://www.cocotb.org/).
141
+ Install the test extras and a VHDL simulator:
142
+
143
+ ```sh
144
+ python3 -m pip install -e ".[test]"
145
+
146
+ # Debian/Ubuntu
147
+ sudo apt-get install -y ghdl
148
+ ```
149
+
150
+ NVC is also supported and is the default VHDL simulator on Windows. See the
151
+ [NVC releases](https://github.com/nickg/nvc/releases) if it is not available
152
+ from your package manager.
153
+
154
+ Run the VHDL benches with GHDL or NVC:
155
+
156
+ ```sh
157
+ SIM=ghdl pytest -v tests/hdl -k vhdl
158
+ SIM=nvc pytest -v tests/hdl -k vhdl
159
+ ```
160
+
161
+ Without `SIM`, VHDL uses GHDL on Linux/macOS and NVC on Windows. Add
162
+ `-n auto` to run the matrix in parallel, or narrow it with pytest keywords.
163
+ For example, to run only the APB register-map tests:
164
+
165
+ ```sh
166
+ SIM=ghdl pytest -v tests/hdl -k "vhdl and apb and test_rmap"
167
+ ```
168
+
169
+ The matrix covers the Local Bus, APB, AXI-Lite and Avalon-MM register-map
170
+ interfaces, the APB/AXI-Lite/Avalon-MM to Local Bus bridges, and all four
171
+ reset styles. The cocotb test modules live in `tests/hdl/cocotb`; the pytest
172
+ wrappers generate the RTL and invoke the cocotb runner.
173
+
174
+ Verilog benches require Icarus Verilog (`iverilog`) and are skipped
175
+ automatically when it is not installed. Current validation is done with
176
+ GHDL and NVC for VHDL.
177
+
178
+ ## License
179
+
180
+ Marauder is licensed under [MIT License](https://github.com/Atech1/Marauder_Registers/blob/master/LICENSE.txt).
181
+
182
+ Corsair, the tool Marauder is forked from, was created by [@esynr3z](https://github.com/esynr3z) and is licensed under the MIT license as well.
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """Marauder is a control and status register (CSR) map generator for HDL projects.
5
+ It generates HDL code, documentation and other artifacts from CSR map description file.
6
+ """
7
+
8
+ __title__ = "Marauder-register"
9
+ __description__ = "Control and status register (CSR) map generator for HDL projects."
10
+
11
+ __all__ = [
12
+ "__version__",
13
+ "config",
14
+ "MarauderError",
15
+ "EnumValue",
16
+ "BitField",
17
+ "Register",
18
+ "RegisterMap",
19
+ "generators",
20
+ ]
21
+
22
+ from ._version import version as __version__
23
+
24
+ from . import config
25
+ from .exceptions import MarauderError
26
+ from .enum import EnumValue
27
+ from .bitfield import BitField
28
+ from .reg import Register
29
+ from .regmap import RegisterMap
30
+ from . import generators
@@ -0,0 +1,231 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """Run Marauder from command line with arguments.
5
+ """
6
+
7
+ import sys
8
+ import os
9
+ import argparse
10
+ from pathlib import Path
11
+ import marauder_register
12
+ from . import utils
13
+ from .exceptions import MarauderError
14
+ from contextlib import contextmanager
15
+ import importlib.util
16
+
17
+ __all__ = ['main']
18
+
19
+
20
+ @contextmanager
21
+ def cwd(path):
22
+ oldpwd = os.getcwd()
23
+ os.chdir(path)
24
+ try:
25
+ yield
26
+ finally:
27
+ os.chdir(oldpwd)
28
+
29
+
30
+ class ArgumentParser(argparse.ArgumentParser):
31
+ """Inherit ArgumentParser to override the behaviour of error method."""
32
+
33
+ def error(self, message):
34
+ self.print_help(sys.stderr)
35
+ self.exit(2, '\n%s: error: %s\n' % (self.prog, message))
36
+
37
+
38
+ def parse_arguments():
39
+ """Parse and validate arguments."""
40
+ parser = ArgumentParser(prog=marauder_register.__title__,
41
+ description=marauder_register.__description__)
42
+ parser.add_argument('-v', '--version',
43
+ action='version',
44
+ version='%(prog)s v' + marauder_register.__version__)
45
+ parser.add_argument(metavar='WORKDIR',
46
+ nargs='?',
47
+ dest='workdir_path',
48
+ default=os.getcwd(),
49
+ help='working directory (default is the current directory)')
50
+ parser.add_argument('-r',
51
+ metavar='REGMAP',
52
+ dest='regmap_path',
53
+ help='read register map from file')
54
+ parser.add_argument('-c',
55
+ metavar='CONFIG',
56
+ dest='config_path',
57
+ help='read configuration from file')
58
+ template_choices = ['json', 'yaml', 'txt']
59
+ parser.add_argument('-t',
60
+ metavar='FORMAT',
61
+ choices=template_choices,
62
+ dest='template_format',
63
+ help='create templates (choose from %s)' % ', '.join(template_choices))
64
+ return parser.parse_args()
65
+
66
+
67
+ def generate_templates(format):
68
+ print("... templates format: '%s'" % format)
69
+ # global configuration
70
+ globcfg = marauder_register.config.default_globcfg()
71
+ globcfg['data_width'] = 32
72
+ globcfg['address_width'] = 16
73
+ globcfg['register_reset'] = 'sync_pos'
74
+
75
+ # targets
76
+ targets = {}
77
+ targets.update(marauder_register.generators.Verilog(path="hw/regs.v").make_target('v_module'))
78
+ targets.update(marauder_register.generators.Vhdl(path="hw/regs.vhd").make_target('vhdl_module'))
79
+ targets.update(marauder_register.generators.VerilogHeader(path="hw/regs.vh").make_target('v_header'))
80
+ targets.update(marauder_register.generators.SystemVerilogPackage(path="hw/regs_pkg.sv").make_target('sv_pkg'))
81
+ targets.update(marauder_register.generators.Python(path="sw/regs.py").make_target('py'))
82
+ targets.update(marauder_register.generators.CHeader(path="sw/regs.h").make_target('c_header'))
83
+ targets.update(marauder_register.generators.Markdown(path="doc/regs.md", image_dir="md_img").make_target('md_doc'))
84
+ targets.update(marauder_register.generators.Asciidoc(
85
+ path="doc/regs.adoc", image_dir="adoc_img").make_target('asciidoc_doc'))
86
+ targets.update(marauder_register.generators.CocotbBench(
87
+ path="tb/regs_tb.py", interface="axil").make_target('regs_tb'))
88
+
89
+ # create templates
90
+ if format == 'txt':
91
+ rmap = marauder_register.utils.create_template_simple(globcfg)
92
+ else:
93
+ rmap = marauder_register.utils.create_template(globcfg)
94
+ # register map template
95
+ if format == 'json':
96
+ gen = marauder_register.generators.Json(rmap, path='regs.json', globcfg=globcfg)
97
+ regmap_path = 'regs.json'
98
+ elif format == 'yaml':
99
+ gen = marauder_register.generators.Yaml(rmap, path='regs.yaml', globcfg=globcfg)
100
+ regmap_path = 'regs.yaml'
101
+ elif format == 'txt':
102
+ gen = marauder_register.generators.Txt(rmap, path='regs.txt', globcfg=globcfg)
103
+ regmap_path = 'regs.txt'
104
+ print("... generate register map file '%s'" % regmap_path)
105
+ gen.generate()
106
+ # configuration file template
107
+ config_path = 'csrconfig'
108
+ globcfg['regmap_path'] = regmap_path
109
+ print("... generate configuration file '%s'" % config_path)
110
+ marauder_register.config.write_csrconfig(config_path, globcfg, targets)
111
+
112
+
113
+ def die(msg):
114
+ print("Error: %s" % msg)
115
+ exit(1)
116
+
117
+
118
+ def finish():
119
+ print('Success!')
120
+ exit(0)
121
+
122
+
123
+ def app(args):
124
+ print("... set working directory '%s'" % args.workdir_path)
125
+
126
+ # check if teplates are needed
127
+ if args.template_format:
128
+ generate_templates(args.template_format)
129
+ finish()
130
+
131
+ # check if configuration file path was provided
132
+ if args.config_path:
133
+ config_path = Path(args.config_path)
134
+ else:
135
+ config_path = Path('csrconfig')
136
+ # check it existance
137
+ if not config_path.is_file():
138
+ die("Can't find configuration file '%s'!" % config_path)
139
+ # try to read it
140
+ print("... read configuration file '%s'" % config_path)
141
+ try:
142
+ globcfg, targets = marauder_register.config.read_csrconfig(config_path)
143
+ except MarauderError as e:
144
+ die(e)
145
+
146
+ # check if regiter map file path was provided
147
+ if args.regmap_path:
148
+ regmap_path = Path(args.regmap_path)
149
+ globcfg['regmap_path'] = regmap_path
150
+ elif 'regmap_path' in globcfg.keys():
151
+ regmap_path = Path(globcfg['regmap_path'])
152
+ else:
153
+ regmap_path = None
154
+ print("Warning: No register map file was specified!")
155
+
156
+ if regmap_path:
157
+ # check it existance
158
+ if not regmap_path.is_file():
159
+ die("Can't find register map file '%s'!" % regmap_path)
160
+ # try to read it
161
+ print("... read register map file '%s'" % regmap_path)
162
+ rmap = marauder_register.RegisterMap(globcfg)
163
+ try:
164
+ rmap.read_file(regmap_path)
165
+ print("... validate register map")
166
+ rmap.validate()
167
+ except MarauderError as e:
168
+ die(e)
169
+ else:
170
+ rmap = None
171
+
172
+ # make targets
173
+ if not targets:
174
+ die("No targets were specified! Nothing to do!")
175
+ for t in targets:
176
+ print("... make '%s': " % t, end='')
177
+ if 'generator' not in targets[t].keys():
178
+ die("No generator was specified for the target!")
179
+
180
+ if '.py::' in targets[t]['generator']:
181
+ custom_module_path, custom_generator_name = targets[t]['generator'].split('::')
182
+ custom_module_name = utils.get_file_name(custom_module_path)
183
+ if not Path(custom_module_path).is_file():
184
+ die("Can't find custom generator module file '%s'!" % custom_module_path)
185
+ spec = importlib.util.spec_from_file_location(custom_module_name, custom_module_path)
186
+ custom_module = importlib.util.module_from_spec(spec)
187
+ try:
188
+ spec.loader.exec_module(custom_module)
189
+ except MarauderError as e:
190
+ die(e)
191
+ try:
192
+ gen_obj = getattr(custom_module, custom_generator_name)
193
+ gen_name = custom_generator_name
194
+ except AttributeError:
195
+ die("Generator '%s' from module '%s' does not exist!" % (custom_generator_name, custom_module_path))
196
+ else:
197
+ gen_name = targets[t]['generator']
198
+ try:
199
+ gen_obj = getattr(marauder_register.generators, gen_name)
200
+ except AttributeError:
201
+ die("Generator '%s' does not exist!" % gen_name)
202
+
203
+ gen_args = dict(targets[t])
204
+ print("%s -> '%s': " % (gen_name, gen_args['path']))
205
+ # a global configuration is passed to all generators explicitly;
206
+ # per-target 'globcfg' value from a configuration file is not supported and is ignored
207
+ gen_args.pop('globcfg', None)
208
+ try:
209
+ gen_obj(rmap, globcfg=globcfg, **gen_args).generate()
210
+ except MarauderError as e:
211
+ die(e)
212
+ except ValueError as e:
213
+ die(e)
214
+ except TypeError as e:
215
+ die("Generator '%s' was called with wrong arguments: %s" % (gen_name, e))
216
+
217
+
218
+ def main():
219
+ """Program main"""
220
+ # parse arguments
221
+ args = parse_arguments()
222
+
223
+ # do all the things inside working directory
224
+ args.workdir_path = str(Path(args.workdir_path).absolute())
225
+ with cwd(args.workdir_path):
226
+ app(args)
227
+ finish()
228
+
229
+
230
+ if __name__ == '__main__':
231
+ main()