OpenCores
URL https://opencores.org/ocsvn/radiohdl/radiohdl/trunk

Subversion Repositories radiohdl

[/] [radiohdl/] [trunk/] [doc/] [radiohdl_user_guide.md] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 danv
# RadioHDL User Guide
2
 
3
### *Speed up HDL development*
4
 
5
---
6
#### Document history:
7
|Revision|Date|Author|Affiliation|Modification|
8
|:---|:---|:---|:---|:---|
9
|0.5|11 dec 2018|R. Overeem |ASTRON|Initial HDL user manual docx.|
10
|1.0|27 jan 2020|E. Kooistra|ASTRON|Created, based on HDL user manual docx and hdltool_readme.txt.|
11
 
12
---
13
#### Contents:
14
1 Introduction
15
2 Quick start using simulation in Modelsim
16
2.1 Preconditions
17
2.2 Setup RadioHDL
18
2.3 Create Modelsim Project files
19
2.4 Simulate the HDL test bench in Modelsim
20
2.5 Utilities
21
2.5.1 check_config
22
2.5.2 modify_configfiles
23
3 Setting up the RadioHDL environment
24
3.1 Environment variables
25
3.2 Configuration files kinds
26
3.2.1 hdl_buildset_.cfg
27
3.2.2 hdl_tool_.cfg
28
3.2.3 hdllib.cfg
29
4 RadioHDL concepts and features
30
4.1 Clean enviroment
31
4.2 Copy files
32
4.3 Top level design library
33
4.4 Design revisions
34
5 Adding your own tools
35
5.1 New hdl_tool_.cfg file
36
5.2 New  directory
37
5.3 Extend generate_ip_libs
38
6 Appendix: RadioHDL configuration file schema basics
39
 
40
---
41
#### Terminology:
42
 
43
- FPGA = Field Programmable Gate Array
44
- GUI = Graphical User Interface
45
- HDL = Hardware Description Language
46
- IP = Intellectual Property
47
- MPF = Modelsim Project File
48
 
49
---
50
#### References:
51
[1] radiohdl_hdl_buildset_key_descriptions.md
52
[2] radiohdl_hdl_buildset_uniboard1.md
53
[3] radiohdl_hdl_tool_modelsim.md
54
[4] radiohdl_hdl_tool_quartus.md
55
[5] radiohdl_hdl_library_key_descriptions.md
56
[6] radiohdl_programmer_guide.md
57
 
58
---
59
## 1 Introduction
60
The RadioHDL package offers tools for setting up, automating and maintaining the HDL source code, IP code and tools for programming FPGAs. The RadioHDL package consists of a set of scripts that interpret configuration files and that setup or run other tools. Currently RadioHDL supports vendor tools like Modelsim and Quartus, but other vendor tools can be added easily to the package.
61
 
62
The parameters for the HDL source libraries, the vendor IP blocks, the build tools and the target FPGA are kept in configuration files. The configuration files and source files are the inputs for the RadioHDL tools. The output is a build target that depends on which build tool is used. The build target can e.g. be a project file for Modelsim to simulate the HDL, a project file for Quartus to synthesize the HDL, a report log from a regression test that simulated the HDL. Figure 1 shows how RadioHDL fits in the build flow from source to target. The configuration files and source files are kept in one or more source directory trees that can be under version control, while the target files are built in a separate build directory tree. The RadioHDL is configured using three different kinds of configuration files:
63
 
64
- one central hdl_buildset_.cfg configuration file per set of FPGA technology and tools and tool versions,
65
- one central hdl_tool_.cfg configuration file per vendor tool,
66
- multiple local hdllib.cfg configuration files, one per HDL library.
67
 
68
After setting up the configuration files for the tools and the source files, RadioHDL can create for the selected buildset all libraries for simulation, create all IP libraries, find out dependencies, generate project files and do a lot more of these labour-intensive tasks automatically.
69
 
70
![Figure 1](./radiohdl_work_flow.jpg "radiohdl_work_flow.jpg")
71
Figure 1: RadioHDL flow from source to target
72
 
73
The main benefit of RadioHDL is that it speeds up HDL development by providing a uniform and automated way of using tools and building code. The disadvantage of using RadioHDL is that it requires an initial effort to support a vendor tool and to maintain this support with changes in vendor tool versions. However in practice it has appeared worth the effort to use and maintain RadioHDL.
74
 
75
RadioHDL is open source, see [LICENSE.md](../LICENSE.md). The name RadioHDL reflects that it was first used for HDL development in FPGA projects for radio astronomy, see [NOTICE.md](../NOTICE.md) and [CREDITS.md](../CREDITS.md), but it can be applied for any HDL development project. This user guide focusses on how to use RadioHDL. The internal working of the RadioHDL scripts is described in the RadioHDL gear programmer guide [6].
76
 
77
---
78
## 2 Quick start using simulation in Modelsim
79
 
80
This quick start uses the following RadioHDL tools for Mentor/Modelsim:
81
 
82
* **modelsim_config** : to create Modelsim project files (mpf) for simulation of HDL code
83
* **run_modelsim** : to start the Modelsim GUI and make and compile HDL code in Modelsim and hierarchically add signals to the Modelsim wave window
84
 
85
See [1] for more detailed information on using RadioHDL with Modelsim.
86
See [2] for more a more advanced example of using RadioHDL with Modelsim and Quartus, so including synthesis
87
 
88
 
89
### 2.1 Preconditions
90
 
91
RadioHDL uses Python3 and bash. Python3 is used to interpret the configuration files nad to create target files, bash is used to setup and invoke tools.
92
 
93
Install a version of Modelsim in $MENTOR_DIR/ (version 6.6c and 10.4 and Questasim have been used) and take care of all vendor specific environment variables in your own .bashrc or local .profile file. For example Altera and Modelsim needs the key LM_LICENSE_FILE to be defined. So the .bashrc file contains the lines:
94
 
95
> export MENTOR_DIR=
96
> export LM_LICENSE_FILE=:
97
 
98
### 2.2 Set up RadioHDL
99
 
100
Create a directory at some location $QS_DIR to store the quick start (QS) example. Copy the example init_qs.sh from the RadioHDL installation directory to $QS_DIR and download the common_pkg, dp_pkg and dp_repack_data HDL libraries from OpenCores and put them in $QS_DIR.
101
 
102
> ls
103
$QS_DIR/init_qs.sh
104
$QS_DIR/cores/common/common_pkg
105
$QS_DIR/cores/dp/dp_pkg
106
$QS_DIR/cores/dp/dp_repack_data
107
 
108
Source init_qs.sh from within $QS_DIR to set the RadioHDL environment variables RADIOHDL_WORK and RADIOHDL_BUILD_DIR for the quick start (qs) project.
109
 
110
> \> . ./init_qs.sh
111
 
112
The example hdl_buildset_qs.cfg in the RADIOHDL_GEAR/config directory of RadioHDL installation directory defines which Modelsim version should be used. The sim_tool_version key in the hdl_buildset_qs.cfg defines the subdirectory of the installation of the Modelsim simulation tool in $MENTOR_DIR. In the example hdl_buildset_qs.cfg the sim_tool_version = 6.6c, indicating that the Modelsim tool version is installed at $MENTOR_DIR/6.6c/. If necessary change this to your sim_tool_version =  and $MENTOR_DIR/.
113
 
114
Source init_radiohdl.sh to create $RADIOHDL_GEAR that points to  and to add search paths within $RADIOHDL_GEAR to $PATH and to $PYTHONPATH
115
 
116
> \> . .//init_radiohdl.sh
117
 
118
Now the environment variables that are important for using RadioHDL and that are also depicted in Figure 1) have been defined.
119
 
120
### 2.3 Create Modelsim project files
121
 
122
Use RadioHDL to build Modelsim simulation project files (*.mpf) for the quick start HDL libraries
123
 
124
> \> modelsim_config qs
125
 
126
The modelsim_config script puts the created files and copied files in the build directory, at:
127
 
128
> $RADIOHDL_BUILD_DIR/qs/modelsim
129
 
130
### 2.4 Simulate the HDL test bench in Modelsim
131
 
132
Start the Modelsim simulation GUI using:
133
 
134
> \> run_modelsim qs &
135
 
136
The run_modelsim also sources a commands.do script in Modelsim that adds the following
137
useful Modelsim Transcript command line commands:
138
 
139
* lp = load project
140
* mk = make project
141
* as = add signals hierarchically to the wave window
142
* ds = delete signals from wave window
143
 
144
To compile the HDL code do in the Modelsim Transcript window:
145
 
146
> ModelSim> lp dp_repack_data
147
> ModelSim> mk all
148
 
149
To simulate the HDL code first double click tb_dp_repack_data icon in the Modelsim Project window to load the test bench (tb) into the simulator and then in the Modelsim Transcript window do.
150
 
151
> ModelSim> as 10
152
> ModelSim> run -a
153
 
154
The signals in this tb_dp_repack_data.vhd test bench can be observed visually in Modelsim Wave window, see Figure 2.
155
 
156
![Figure 2](./wave_tb_dp_repack_data.jpg "wave_tb_dp_repack_data.jpg")
157
Figure 2: Modelsim wave window with hierarchical signals view using 'as' command
158
 
159
### 2.5 Utilities
160
 
161
### 2.5.1 check_config
162
The utility **check_config** checks key-value dependencies between the hdl_buildset configuration file and the hdl_tool configuration files.
163
 
164
### 2.5.2 modify_configfiles
165
The utility **modify_configfiles** implements a tiny menu system that enables you to add, remove or change keys in all hdllib.cfg files of a certain buildset.
166
 
167
---
168
## 3 Setting up RadioHDL environment
169
 
170
### 3.1 Environment variables
171
 
172
The following environment variables are important for RadioHDL:
173
 
174
* RADIOHDL_GEAR : Points to the main directory where your checked out the RadioHDL package. This is the location where this init_radiohdl.sh file is located. Do not change this variable.
175
* RADIOHDL_BUILD_DIR : Points to the directory where RadioHDL will store all its result files. If this variable is not already set when init_radiohdl.sh is run, then it will be set to point to $RADIOHDL_WORK/build.
176
* RADIOHDL_CONFIG : Points to the directory where RadioHDL expects the hdl_buildset and hdl_tool configuration files. If this variable is not already set when init_radiohdl.sh is run, then it will be set to point to $RADIOHDL_GEAR/config.
177
* RADIOHDL_WORK : Points to the root directory of the your project that will use RadioHDL.
178
 
179
 
180
### 3.2 Configuration files kinds
181
 
182
The configuration files define key-value pairs, see the appendix for the details of the schema. There are three different kinds of configuration files in RadioHDL. The hdl_buildset configurations file and hdl_tool configuration file are central and define the global keys that hold for the whole HDL project. The hdllib configuration files define keys that apply per HDL library. The key values from the hdl_buildset configuration file can be used in the hdllib configuration files by referring to the hdl_build set key as . An HDL project in RadioHDL typically targets a certain FPGA board and has an hdl_buildset configuration file for that board. The hdl_buildset configuration file identifies the hdl_tool configuration files for the tools that are needed to build HDL and it points to the directory tree(s) that contain the HDL libraries that are needed for the HDL application(s) that can run on the FPGA board.
183
 
184
 
185
#### 3.2.1 hdl_buildset_.cfg
186
 
187
An hdl_buildset_.cfg configuration file defines the combination of FPGA type, tools, IP libraries and versions that are needed to build a target. The buildset_name is used as command line option in RadioHDL scripts to identify the buildset. The buildset_name is typically an abbreviation that identifies the target FPGA board hardware and a version, e.g. 'unb1' for a version 1 of an FPGA board called 'UniBoard'. If the same board is used, but with another set of tool versions, then that could be identified by e.g. 'unb1_a' and have a buildset file called hdl_buildset_unb1_a.cfg. The hdl_buildset configuration files are kept centrally at $RADIOHDL_CONFIG. To structure the hdl_buildset configuration file it can be divided into sections that group keys per included tool. The section headers are identified between square brackets [tool_name]
188
 
189
#### 3.2.2 hdl_tool_.cfg
190
 
191
RadioHDL looks for '*_tool_name' keys in the hdl_buildset configuration file to find the tool names that the buildset uses for e.g. simulation and synthesis. In this way RadioHDL knows which hdl_tool_ configuration file it needs to use to setup these tools. Typically there is one tool configuration file that covers multiple versions of that tool. The hdl_tool configuration files are kept centrally at $RADIOHDL_CONFIG.
192
 
193
Although most keys in a hdl_tool configuration file are tool specific, there are some keys RadioHDL will always search for in a hdl_tool configuration file. RadioHDL will always search for keys ending in '_paths' and '_environment_variables' for keys that begin with:
194
 
195
- the tool_name of that hdl_tool configuration file (e.g. quartus_paths and quartus_environment_variables)
196
- the block_design_names you mentioned in your hdl_buildset configuration file (e.g. sopc, qsys)
197
- the word 'user', so you can always add your own paths and environment variables with the keys user_paths and user_environment_variables.
198
 
199
#### 3.2.3 hdllib.cfg
200
 
201
The HDL code is organised in one or more (can be many) HDL libraries. Each HDL Library has a local hdllib.cfg configuration file that defines the sources and supported tools. All HDL files are grouped into libraries. The rule is that each HDL file is compiled in only one HDL library. If a component is used in another library, then it is instantiated in VHDL using ., where the hdl_library_clause_name is defined in the hdllib.cfg. Although the creation of these hdllib.cfg files may take some time, you will definitely save time on the long run. An HDL library can define a:
202
 
203
* module library with HDL that is reused in other libraries
204
* top level library with a top level entity that maps on the IO of the FPGA.
205
 
206
For RadioHDL there is no difference in HDL libraries. A top level library that is used for synthesis has a synth_top_level_entity key. RadioHDL search for all hdllib.cfg files in the directory tree(s) that are specified by the lib_root_dirs key in the hdl_buildset configuration file. Typically the hdllib configuration points to sources that are located in the same directory as where the hdllib.cfg is located or in its sub directories, however relative or absolute paths to sources elsewhere are also allowed.
207
 
208
The hdllib can distinguish between source HDL that can be synthesized (at synth_files key),  HDL code that is used only in test benches for simulation (at test_bench_files key) and test benches that are selected to be part of a simulation regression test (at regression_test_vhdl key)..
209
 
210
The hdllib.cfg files are used by many utilities from the RadioHDL package. To structure the hdllib.cfg file, it can be divided into sections that group keys that are used for a specific target. The section headers are identified between square brackets [target_name]. The first part of an hdllib.cfg file has no section header as these keys are available for all target scripts. The keys within a section are applicable to the corresponding tool script. For example:
211
 
212
- section [modelsim_project_file]       contains key-value pairs for modelsim_config
213
- section [quartus_project_file] contains key-value pairs for quartus_config
214
- section [generate_ip_libs] contains key-value pairs for generate_ip_libs
215
 
216
Future target scripts can have their own [target_name] header in the hdllib.cfg to keep the files more organised.
217
 
218
---
219
## 4 RadioHDL concepts and features
220
 
221
### 4.1 Clean environment
222
 
223
The RadioHDL settings are only active in the terminal where RadioHDL was started. Therefore it is possible to run different buildsets in different terminals on the same machine. When the terminal is closed, then also all RadioHDL settings vanish as well.
224
 
225
### 4.2 Copy files
226
 
227
RadioHDL has _copy_files keys that can be used to copy files from the source directory tree to anywhere in the build directory tree. The file may also be copied to multiple locations in the build tree. This can be useful if different tools need the same source file, but at different locations.
228
 
229
A file may also be copied to another file. This can be useful to keep several variants of a file in the source tree, but only use one variant with a fixed filename in the build tree. The hdllib.cfg configuration can then refer to the file in the build tree.
230
 
231
### 4.3 Top level design library
232
 
233
A synth_top_level_entity key in the hdllib.cfg of an HDL library indicates that the HDL library is a design library that can be synthesized to yield an FPGA image. A design library should not depend on another design library, because then there may occur conflicting or double design constraints for Quartus. Therefore it is not advised to directly use VHDL from a design library in other libraries. A proper solution is to put these VHDL files in a separate library and then use them from that library. Another solution (i.e. work around) is to break the rule that an HDL file should only be compiled once in one library and then also compile it in the design library that needs to reuse it.
234
 
235
### 4.4 Design revisions
236
 
237
A design in this context is a top level entity in a HDL library that can be synthesized to create a FPGA image that can run on an FPGA. Within a design, several design revisions can be made that all use the same HDL source code from the base design, but with different generic settings at the top level entity. To keep these design revisions separate, add a directory 'revisions/' in the base design directory, which contains a list of subdirectories. Each subdirectory is a revision. The base design 'unb1_minimal' can be uses as an example:
238
 
239
> designs/unb1_minimal/hdllib.cfg
240
> designs/unb1_minimal/revisions/unb1_minimal_sopc/hdllib.cfg
241
> designs/unb1_minimal/revisions/unb1_minimal_qsys/hdllib.cfg
242
 
243
The base design library unb1_minimal/hdllib.cfg contains the source code. Each design revision library also has a hdllib.cfg  file and a top level VHDL file that wraps the top level VHDL file from unb1_minimal. The wrapper file makes the generic settings for the specific revision. In addition it is useful to specify a 'g_design_name' generic that can be used to store a string in the FPGA that can be read out to know which design revision runs on the FPGA. In this example for UniBoard1 the 'g_design_name' for the revisions is 'unb1_minimal_qsys' or 'unb1_minimal_qsys'.
244
 
245
When a design library has revisions, then the base library should not include keys for synthesis. Instead the synthesis is only done for the revisions. The base library contains all the VHDL source files. The revision hdllib.cfg should not refer to these base library VHDL files (i.e. using a relative path via ../../), but instead it should instantiate the top level base entity using the base design library name. This to follow the rule that a HDL file is only compiled in one HDL library.
246
 
247
---
248
## 5 Adding your own tools
249
 
250
The RadioHDL package as described in this user guide is based on the tools Modelsim and Quartus. If you are using the same tools, then everything should work in your environment after you checked/modified the configuration files in $RADIOHDL_CONFIG. But what if you are using others tool like e.g. Xilinx Vivado? In that case you have to create some new configuration files, some directories and (unfortunately) extend one script. This chapter guides you through this process.
251
 
252
### 5.1 New hdl_tool_.cfg file
253
 
254
Assume you want to add Vivado to RadioHDL, then create in $RADIOHDL_CONFIG a file named hdl_tool_vivado.cfg and put in that file Vivado specific paths and environment variables. There are no required keys in configuration files of the type hdl_tool, so you are free to choose your own key names. Note: the script you create in the following section uses the definitions you create in the hdl_tool file.
255
 
256
### 5.2 New  directory
257
 
258
Every tool has its own directory in $RADIOHDL_GEAR. In this directory we expect a script named set_ to be present, that accepts the buildset_name as an argument. That script sets up the whole environment, so that the tool can be used, e.g. extend paths, setup environment variables, etc. Look in e.g. set_modelsim and set_quartus how to get access to the information that is stored in your configuration files in the $RADIOHDL_CONFIG. So to add e.g. to add Vivado:
259
 
260
- create a directory $RADIOHDL_GEAR/vivado
261
- inside this directory make a script set_vivado that sets up the Vivado environment using the information that is configured in the hdl_buildset and hdl_tool files.
262
 
263
### 5.3 Extend generate_ip_libs
264
 
265
Currently generate_ip_libs supports three IP generation tools from Altera: qmegawiz, qsys-generate and quartus_sh. These IP tools are configured in the hdl_tool_quartus.cfg file (key ip_tools) and implemented as special functions in generate_ip_libs. If you need different IP generation tools you should add them to the ip_tools key and add an extra function in generate_ip_libs. This generate_ip_libs script is the one place (left) where tool specific code is part of a RadioHDL script. In a future release of RadioHDL this should be solved in a more generic way, but for now you have to add a function to generate_ip_libs, when you are using a tool other than qmegawiz, qsys-generate or quartus_sh for creating your IP libraries.
266
 
267
The main flow of generate_ip_libs is:
268
 
269
- read the hdl_buildset file of the buildset you started the program with.
270
- search for hdllib.cfg files in all directories mentioned in the key lib_root_dirs
271
- read the hdl_tool_.cfg file where tool_name is the value of the key synth_tool_name in your buildset file.
272
- read the value of the key ip_tools in this hdl_tool file which is a list of tools you use for creating the IP libraries. Each of these ip_tools have their own _default_options key to configure the default options of that command.
273
- finally it loops over all buildset.technology_names, all tool.ip_tools and all hdllibs that where read in, to see if there is a match in technology and ip_tool with the information in the hdllibs.
274
- for each match found in these nested loops it calls a function called run_ that is part of the generate_ip_libs program.
275
 
276
So if you are using other ip_tools then the three mentioned above you have to add a run_ function to generate_ip_libs and extend the if-then-else construction in the main loop with a call to that function. And you have to setup your configuration files in the right way of course. Take a look at the other run_ functions in generate_ip_libs for what to implement. Basically it constructs a shell script that runs the IP tool and analyses the exit-code of the execution. No rocket science.
277
 
278
---
279
## 6 Appendix: RadioHDL configuration file schema basics
280
 
281
A RadioHDL configuration file is a collection of key-value pairs. Key and value are separated with the assignment char '='. Everything after (and including) a '#' char till the end of the line is treated as comment and is skipped in the interpretation of the files.
282
```
283
    this_is_a_key = and this is the value    # except for this comment.
284
```
285
The files can be divided into sections. A section marker is a line that starts with '[', contains a string and ends with ']'. Sections can be used to group keys that are only used by certain tool scripts and may be ignored by other tool scripts. Key names in different sections must still be unique in the entire configuration file.
286
```
287
    [start of a new section]
288
    key = value
289
```
290
To make the files easier to read and maintain for humans each value can be defined in more than one line where spacing is trivial. This makes is easy to define values that consist of more than one item. Actually, the concept of 'value' is implemented as 'being everything between the assignment char and the start of the next key or the start of a section. Newline characters are translated into a single space.
291
```
292
    invitationlist = John & Marry,
293
                     Robert,
294
                     Sandra and Naomi,
295
```
296
This is equivalent with:
297
```
298
    invitationlist = John & Marry, Robert, Sandra and Naomi,
299
```
300
You can use environment variables in values:
301
```
302
    lib_root_dirs = ${RADIOHDL_WORK}
303
```
304
Keys are always in lowercase even when the name of the key will be used as environment variable. RadioHDL takes care that the key names are converted to uppercase in these cases.
305
 
306
You can refer to a value of another key by placing the name of that key between '<' and '>'. Key word substitution can happen local within a file or global between files:
307
 
308
- Local: A key name can be used for key value substitution in other key values within the same cfg file at .
309
- Global: A key name in the hdl_buildset cfg file can be used to substitute in key values in hdllib cfg files: e.g. 
310
 
311
For example:
312
```
313
    tool_name     = quartus
314
    tool_version  = 12.3
315
    tool_location = /home/software/\/\/bin
316
```
317
 
318
Key values can be e.g.:
319
 
320
* Single value : e.g 'hdl_lib_name' key
321
* List of values : e.g. 'synth_files' key
322
* List of value pairs : e.g '*_copy_files' key
323
 
324
The pairs in '*_copy_files' are separated by a space and therfore the values can not contain a space.

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.