2021年3月10日 星期三

Icarus Verilog (iVerilog) setup

 ref.[iverilog]
https://bleyer.org/icarus/
ref. [bash] 
https://www.baeldung.com/linux/use-command-line-arguments-in-bash-script
https://daniel-sc.github.io/bash-shell-to-bat-converter/

[Win10]
01. https://bleyer.org/icarus/iverilog-v11-20210204-x64_setup.exe
02. set PATH, "控制台\系統及安全性\系統" -> 進階系統設定 -> 環境變數 -> 變數 Path -> Edit -> 新增 "C:\iverilog\bin" "C:\iverilog\gtkwave\bin"
03. open a text editor -> copy the following content and save as "v2w.sh"

#!/bin/bash
# define parameters
wavext=".vcd"
outfolder="output"
currentdir=$PWD

# main program
# info 
  #filename=$1    
  read filename
# fetch basename
  basename=$(echo "$filename" | cut -f 1 -d '.')
  outname="$basename$wavext"
  echo "veriolog(*.v) to waveform(*.vcd): $filename to $outname"
# create sim folder if not exist
  mkdir -p $outfolder
# iverilog commands
  iverilog -o wave -y $PWD $filename
  vvp -n wave -lxt2
  rm wave
  mv wave.vcd $PWD/output/$outname
  gtkwave $PWD/output/$outname &

PS1. in your verilog file, the content should be included
/*iverilog */
initial begin
    $dumpfile("wave.vcd");        //生成的vcd文件名称
    $dumpvars(0, LED_demo_tb);    //tb模块名称
end
/*iverilog */

PS2. if you don't like the bash method, the website converts bash script to bat file
https://daniel-sc.github.io/bash-shell-to-bat-converter/
Here is the result:
@echo off
SET wavext=%CD%vcd
SET outfolder=output
SET currentdir=%PWD%
read filename
SET basename=%undefined%
SET outname="%basename%%wavext%"
echo "veriolog(*%CD%v) to waveform(*%CD%vcd): %filename% to %outname%"
mkdir -p %outfolder%
iverilog -o wave -y %PWD% %filename%
vvp -n wave -lxt2
DEL  wave
mv wave.vcd %PWD%\output\%outname%
gtkwave %PWD%\output\%outname%


04. place "*.v" & v2w.sh in the same folder and double-click on "v2w.sh". Then, fill in the main test bench *.v

[linux] Raspberry pi OS
01. >> apt-get install iverilog gtkwave shc
02. >> vi v2w.sh

#!/bin/bash
# define parameters
wavext=".vcd"
outfolder="output"
currentdir=$PWD

# main program
# info 
  #filename=$1    
  read filename
# fetch basename
  basename=$(echo "$filename" | cut -f 1 -d '.')
  outname="$basename$wavext"
  echo "veriolog(*.v) to waveform(*.vcd): $filename to $outname"
# create sim folder if not exist
  mkdir -p $outfolder
# iverilog commands
  iverilog -o wave -y $PWD $filename
  vvp -n wave -lxt2
  rm wave
  mv wave.vcd $PWD/output/$outname
  gtkwave $PWD/output/$outname &

03.
>> shc -f v2w.sh 
>> mv v2w.sh.x ~/bin/v2w
>> vi ~/.bashrc
PATH=$PATH:~/bin

04. in the folder of all the *.v
>> v2w testbench.v