12
12
13
13
14
14
class Xsim (Edatool ):
15
+ """
16
+ Vivado Xsim backend
17
+ * Standard design sources
18
+ * IP: Supply the IP core xci file with file_type=xci and other files (like .prj) as file_type=user .
19
+ you also have to specify xilinx part number in tools/xsim/part
15
20
16
- argtypes = ["plusarg" , "vlogdefine" , "vlogparam" , "generic" ]
17
-
18
- MAKEFILE_TEMPLATE = """#Auto generated by Edalize
19
- include config.mk
20
-
21
- all: xsim.dir/$(TARGET)/xsimk
22
-
23
- xsim.dir/$(TARGET)/xsimk:
24
- xelab $(TOPLEVEL) -prj $(TARGET).prj -snapshot $(TARGET) $(VLOG_DEFINES) $(VLOG_INCLUDES) $(GEN_PARAMS) $(XELAB_OPTIONS)
25
-
26
- run: xsim.dir/$(TARGET)/xsimk
27
- xsim -R $(XSIM_OPTIONS) $(TARGET) $(EXTRA_OPTIONS)
21
+ * you can also set tools/xsim/default_run to "run_vcd" in order to automatically generate vcd file during simulation
22
+ """
28
23
29
- run-gui: xsim.dir/$(TARGET)/xsimk
30
- xsim --gui $(XSIM_OPTIONS) $(TARGET) $(EXTRA_OPTIONS)
31
- """
32
-
33
- CONFIG_MK_TEMPLATE = """#Auto generated by Edalize
34
- TARGET = {target}
35
- TOPLEVEL = {toplevel}
24
+ argtypes = ["plusarg" , "vlogdefine" , "vlogparam" , "generic" ]
36
25
37
- VLOG_DEFINES = {vlog_defines}
38
- VLOG_INCLUDES = {vlog_includes}
39
- GEN_PARAMS = {gen_params}
40
26
41
- XELAB_OPTIONS = {xelab_options}
42
- XSIM_OPTIONS = {xsim_options}
27
+ VCD_TCL = """#tcl script that runs simulation with vcd output
28
+ open_vcd xsim_dump.vcd
29
+ log_vcd *
30
+ run all
31
+ close_vcd
32
+ quit
43
33
"""
44
-
45
34
@classmethod
46
35
def get_doc (cls , api_ver ):
47
36
if api_ver == 0 :
48
37
return {
49
38
"description" : "XSim simulator from the Xilinx Vivado suite" ,
50
39
"members" : [
40
+ {
41
+ "name" : "part" ,
42
+ "type" : "String" ,
43
+ "desc" : "xilinx part if using xci ip" ,
44
+ },
45
+ {
46
+ "name" : "default_run" ,
47
+ "type" : "String" ,
48
+ "desc" : "default target to run for makefile. use 'run-vcd' for automatic vcd generation" ,
49
+ },
51
50
{
52
51
"name" : "compilation_mode" ,
53
52
"type" : "String" ,
@@ -81,6 +80,8 @@ def _write_config_files(self):
81
80
with open (os .path .join (self .work_root , self .name + ".prj" ), "w" ) as f :
82
81
mfcu = []
83
82
(src_files , self .incdirs ) = self ._get_fileset_files ()
83
+ src_list = []
84
+ xci_list = []
84
85
for src_file in src_files :
85
86
cmd = ""
86
87
if src_file .file_type .startswith ("verilogSource" ):
@@ -96,10 +97,15 @@ def _write_config_files(self):
96
97
cmd = "sv"
97
98
elif src_file .file_type in ["user" ]:
98
99
pass
100
+ elif src_file .file_type in ["data" ]:
101
+ os .system ("ln -s %s %s" % (src_file .name , os .path .join (self .work_root , os .path .basename (src_file .name ))));
102
+ elif src_file .file_type in ["xci" ]:
103
+ xci_list .append (src_file .name )
99
104
else :
100
105
_s = "{} has unknown file type '{}'"
101
106
logger .warning (_s .format (src_file .name , src_file .file_type ))
102
107
if cmd :
108
+ src_list .append (src_file .name )
103
109
if src_file .logical_name :
104
110
lib = src_file .logical_name
105
111
else :
@@ -108,7 +114,7 @@ def _write_config_files(self):
108
114
if mfc :
109
115
f .write ("sv work " + " " .join (mfcu ))
110
116
111
- with open ( os . path . join ( self . work_root , "config.mk" ), "w" ) as f :
117
+ if 1 :
112
118
vlog_defines = " " .join (
113
119
[
114
120
"--define {}={}" .format (k , self ._param_value_str (v ))
@@ -135,20 +141,31 @@ def _write_config_files(self):
135
141
xelab_options = " " .join (self .tool_options .get ("xelab_options" , []))
136
142
xsim_options = " " .join (self .tool_options .get ("xsim_options" , []))
137
143
138
- f .write (
139
- self .CONFIG_MK_TEMPLATE .format (
144
+ if xci_list :
145
+ xci_part = self .tool_options .get ("part" , "dflt_part" )
146
+ if xci_part == "dflt_part" :
147
+ logger .error ("When using xci, you must define tools/xsim/part value" )
148
+ self .render_template ("xci.tcl.j2" , os .path .join (self .work_root , "xci.tcl" ), dict (
149
+ xci_list = xci_list ,
150
+ xci_part = xci_part
151
+ ))
152
+ self .render_template ("config.mk.j2" , os .path .join (self .work_root , "config.mk" ), dict (
140
153
target = self .name ,
141
154
toplevel = self .toplevel ,
142
155
vlog_defines = vlog_defines ,
143
156
vlog_includes = vlog_includes ,
144
157
gen_params = gen_param_args ,
145
158
xelab_options = xelab_options ,
146
159
xsim_options = xsim_options ,
147
- )
148
- )
149
-
150
- with open (os .path .join (self .work_root , "Makefile" ), "w" ) as f :
151
- f .write (self .MAKEFILE_TEMPLATE )
160
+ src_list = src_list ,
161
+ ))
162
+
163
+ self .render_template ("Makefile.j2" ,os .path .join (self .work_root , "Makefile" ),dict (
164
+ default_run = self .tool_options .get ("default_run" , "run-dflt" ),
165
+ xci_list = xci_list
166
+ ))
167
+ with open (os .path .join (self .work_root , "vcd.tcl" ), "w" ) as f :
168
+ f .write (self .VCD_TCL )
152
169
153
170
def run_main (self ):
154
171
args = ["run" ]
0 commit comments