In a previous post I wrote about using SVN with HDL designs and how to do it most effectively. Here I want to write about having your peripheral cores automatically generate the netlists they use when the project is compiled, for example when you build the bitstream of an XPS project. Firstly I’ll give you an example where it would be useful.

Let’s say I have a peripheral that contains a FIFO. I generated that FIFO using Core Generator. So I have a netlist file that I place in the “netlist” folder of my peripheral, plus I have created a .bbd file in my “data” folder containing the name of the netlist file.

Now as discussed earlier, we don’t commit netlists, we only commit sources. The sources for my FIFO are the .xco and .cgp files that Coregen created. These are the files necessary to re-generate the netlist using Coregen so I should copy them to the “netlist” folder and commit them to my SVN.

Normally from this point, Jill starting from a clean slate, will need to generate the netlist by opening Coregen, opening the .cgp file, right-clicking the FIFO core and selecting “regenerate”.

In the case that our core uses multiple netlists, Jill’s job becomes tedious. It becomes even more tedious when she wants to use several other peripherals that have their own netlists to generate. Now we get to the point of this post: the automated way to regenerate your netlists using a TCL script. This is the basic idea:

  1. We create a .tcl file in the “data” folder that contains a function to execute Coregen and regenerate our netlist.
  2. We add a line into the .mpd file of the peripheral that calls the TCL function when the core is being compiled as part of a hardware project.

Here is an example .tcl file with the function that runs Coregen and generates our netlist file:

proc run_coregen {mhsinst} {
 set ngcfolder "./pcores/my_peripheral_v1_00_a/netlist"
 set ngcfile $ngcfolder/my_fifo.ngc
 set cgpfile $ngcfolder/coregen.cgp
 set xcofile $ngcfolder/my_fifo.xco
 set ngcexists [file exists $ngcfile]
 if {$ngcexists != 1} {
  puts "my_peripheral: Generating netlists using Coregen\n"
  set result [catch {exec coregen -p $cgpfile -b $xcofile -intstyle xflow}]
 }
}

 

Here is an example .mpd file with a line that calls the TCL function:

 

###################################################################
 ##
 ## Name     : my_peripheral
 ## Desc     : Microprocessor Peripheral Description
 ##          : Automatically generated by PsfUtility
 ##
 ###################################################################
 BEGIN my_peripheral

 ## Peripheral Options
 OPTION IPTYPE = PERIPHERAL
 OPTION IMP_NETLIST = TRUE
 OPTION RUN_NGCBUILD = TRUE
 OPTION STYLE = MIX

 OPTION PLATGEN_SYSLEVEL_UPDATE_PROC = run_coregen

 ## Bus Interfaces

 ## Generics for VHDL or Parameters for Verilog

 ## Ports
 PORT Clk     = "",   DIR = I
 PORT Rst     = "",   DIR = I
 PORT DataIn  = "",   DIR = I, VEC = [7:0]
 PORT DataOut = "",   DIR = O, VEC = [7:0]

END

Now when you build your XPS project containing my_peripheral, you will see the line “my_peripheral: Generating netlists using Coregen” appear at some point in the message console. If you have used Coregen before you would know that it can take some time to generate a netlist, so be patient!

To conclude all this, dont forget to commit all the sources of your peripheral. That includes:

  • \data\*.mpd
  • \data\*.pao
  • \data\*.tcl
  • \data\*.bbd
  • \netlist\*.cgp
  • \netlist\*.xco
  • \hdl\* (obviously all your sources .vhd and .v)

If you have questions please leave them in the comments below.

Jeff is passionate about FPGAs, SoCs and high-performance computing, and has been writing the FPGA Developer blog since 2008. As the owner of Opsero, he leads a small team of FPGA all-stars providing start-ups and tech companies with FPGA design capability that they can call on when needed.

Facebook Twitter LinkedIn