2010年12月30日星期四

dump_wave.sv

`ifndef FSDB_DUMP_TOP
`define FSDB_DUMP_TOP dump_top
`endif
`timescale 1ns/1ps
module dump_wave;
integer  fsdbdumpstart, fsdbdumpend, fsdb_size;
integer  vpd_dump_level, vpddumpstart, vpddumpend;
reg      fsdb_en, vcd_en, vpd_en;
integer  fsdb_dump_level;
reg[8*100-1:0]   fsdb_no_dump, fsdbfile, dump_top, vpdfile;
integer  plusargs_status;
/// vcd config
integer  vcddumpstart, vcddumpend;
reg[8*100-1:0]   vcdfile;
initial begin
  // print time format as timeunit in ns
  $timeformat(-9, 0, " ns", 20);
  /// fsdb
  `ifndef DUMP_WAVE_DISABLE
  fsdb_en       = 1'b0;
  fsdbdumpstart = 0;
  fsdbdumpend   = 0;
  fsdb_size     = 0;
  fsdbfile      = "wave.fsdb";
  dump_top      = "";
  fsdb_dump_level = 0;
  fsdb_no_dump  = "";
  /// vpd
  vpd_en         = 1'b0;
  vpddumpstart   = 0;
  vpddumpend     = 0;
  vpdfile        = "wave.vpd";
  vpd_dump_level = 0;
  /// vcd
  vcd_en       = 1'b0;
  vcdfile      = "wave.vcd";
  vcddumpstart = 0;
  vcddumpend   = 0;
  ////// wave for fsdb format
  if ($test$plusargs("fsdb")) begin
    fsdb_en = 1'b1;
    plusargs_status = $value$plusargs("fsdb=%d",fsdbdumpstart);
    if($test$plusargs("fsdboff")) plusargs_status = $value$plusargs("fsdboff=%d",fsdbdumpend);
    if($test$plusargs("fsdbfile")) plusargs_status = $value$plusargs("fsdbfile=%s",fsdbfile);
    if($test$plusargs("fsdblevel")) plusargs_status = $value$plusargs("fsdblevel=%d",fsdb_dump_level);
    if($test$plusargs("fsdbsize")) plusargs_status = $value$plusargs("fsdblimit=%d",fsdb_size);
    if($test$plusargs("fsdbnodump")) plusargs_status = $value$plusargs("fsdbsupress=%s",fsdb_no_dump);
    if($test$plusargs("fsdbtop")) plusargs_status = $value$plusargs("fsdbtop=%s",dump_top);
  end
  ////// wave for vcd format
  else if ($test$plusargs("vcd")) begin
    vcd_en = 1'b1;
    plusargs_status = $value$plusargs("vcd=%d",vcddumpstart);
    if($test$plusargs("vcdoff")) plusargs_status = $value$plusargs("vcdoff=%d",vcddumpend);
    if($test$plusargs("vcdfile")) plusargs_status = $value$plusargs("vcdfile=%s",vcdfile);
  end
  ////// wave for vpd format
  else if ($test$plusargs("vpd")) begin
    vpd_en = 1'b1;
    plusargs_status = $value$plusargs("vpd=%d",vpddumpstart);
    if($test$plusargs("vpdoff")) plusargs_status = $value$plusargs("vpdoff=%d",vpddumpend);
    if($test$plusargs("vpdfile")) plusargs_status = $value$plusargs("vpdfile=%s", vpdfile);
  end
  ////// dump wave
  ////// dump wave for fsdb format
  if (fsdb_en) begin
    #(fsdbdumpstart);
    /// $fsdbDumplimit
    if (fsdb_size > 0) begin
      if (fsdb_size < 10 || fsdb_size > 1843) begin
$display("Error: The file size you can set for $fsdbDumplimit should be more than 10MB and less than 1.8GB");
      end
      else begin
$fsdbDumplimit(fsdb_size);
      end
    end
    $fsdbDumpfile(fsdbfile);
    /// fsdbSuppress
    if (fsdb_no_dump != "") begin
      $fsdbSuppress(fsdb_no_dump);
    end
    $fsdbDumpon();
    /// fsdbDumpvars
    if (dump_top != "") begin
        $fsdbDumpvars("level=", fsdb_dump_level, `FSDB_DUMP_TOP);
    end
    else if (fsdb_dump_level > 0) begin
      $fsdbDumpvars("level=", fsdb_dump_level);
    end
    else begin
      $fsdbDumpvars();
      //$fsdbDumpvars("+all");  // add "+all" to dump dynamic array and memory.
    end
    if(fsdbdumpend > 0) begin
      #(fsdbdumpend);
      $fsdbDumpoff();
    end
  end
  ////// dump wave for vcd format
  else if(vcd_en) begin
    #(vcddumpstart);
    $dumpfile(vcdfile);
    $dumpon;
    $dumpvars;
    if(vcddumpend > 0) begin
      #(vcddumpend);
      $dumpoff;
    end
  end
  ////// dump wave for vpd format
  else if (vpd_en) begin
    #(vpddumpstart);
    //$vcdplusfile(vpdfile);
    $vcdpluson;
    if(vpddumpend > 0) begin
      #(vpddumpend);
      $vcdplusoff;
    end
  end
`endif
end
endmodule

*enable wave dump by adding "-fsdb" at compile time and setting DEBUSSY_HOME correctly.

2010年11月23日星期二

vim matchit for systemverilog

1, in ~/.vimrc
source $VIMRUNTIME/macros/matchit.vim
filetype plugin indent on

2, edit file ~/.vim/ftplugin/verilog_systemverilog_matchit.vim:

if exists("loaded_verilog_systemverilog_matchit")
   finish
endif
let loaded_verilog_systemverilog_matchit = 1

let b:match_words = '\<begin\>:\<end\>,'
let b:match_words .= '\<module\>:\<endmodule\>,'
let b:match_words .= '\<interface\>:\<endinterface\>,'
let b:match_words .= '\<class\>:\<endclass\>,'
let b:match_words .= '\<task\>:\<endtask\>,'
let b:match_words .= '\<function\>:\<endfunction\>,'
let b:match_words .= '\<package\>:\<endpackage\>,'
let b:match_words .= '\<ifndef\>:\<endif\>,'
let b:match_words .= '\<ifdef\>:\<endif\>,'

2010年9月17日星期五

Makefile example

#***************************************************************************
#
# Author:      $SVF TG (auto generated)$
# File:        $Makefile$
# Revision:    $Revision:$
# Date:        $Date:$
#
#****************************************************************************/
## Variables and scripts
VIP    = ../../vips
APB    = $(VIP)/apb
APB_INC    = $(APB)/include
APB_SRC    = $(APB)/src
AXI    = $(VIP)/axi
AXI_INC    = $(AXI)/include
AXI_SRC    = $(AXI)/src
FWD    = $(VIP)/fwd
FWD_INC    = $(FWD)/include
FWD_SRC    = $(FWD)/src
MAC    = $(VIP)/mac
MAC_INC    = $(MAC)/include
MAC_SRC    = $(MAC)/src
ENV    = ../env
COMMON    = ../../common
COMMON_INC   = ../../common/include
COMMON_SRC   = ../../common/src
TEST_DIR   = .
# USER - Change this to point to your actual RTL code.
#   Also, for MTI, uncomment the vlog line in the run_mti section
#   once there is actual RTL code to run
DUT    = ../../../../../rtl
DUT_SRC    =
INC    = +incdir+$(COMMON_INC) \
      +incdir+$(COMMON_SRC) \
      +incdir+$(APB_INC) \
      +incdir+$(APB_SRC) \
      +incdir+$(AXI_INC) \
      +incdir+$(AXI_SRC) \
      +incdir+$(FWD_INC) \
      +incdir+$(FWD_SRC) \
      +incdir+$(MAC_INC) \
      +incdir+$(MAC_SRC) \
      +incdir+$(ENV) \
      +incdir+$(TEST_DIR)/basic \
      +incdir+$(TEST_DIR)/advanced \
      +incdir+$(TEST_DIR)
# If UVM_HOME is not set, then attempt to determine if it is distributed with
# the simulator.
ifeq ($(strip $(UVM_HOME)),)
  ifeq (test_mti,$(findstring test_mti,$(MAKECMDGOALS)))
    ERROR_MSG := Unable to determine UVM_HOME for Modelsim, please set UVM_HOME or MTI_HOME environment variable
    ifneq ($(strip $(MTI_HOME)),)
      UVM_HOME := /usr/proj/work/svf/nguo/uvm
      ifneq (${UVM_HOME},$(shell ls -d ${UVM_HOME} 2>&1))
        $(error $(ERROR_MSG))
      endif
    else
      $(error $(ERROR_MSG))
    endif
  endif
  ifeq (test_ius,$(findstring test_ius,$(MAKECMDGOALS)))
    ERROR_MSG := Unable to determine UVM_HOME for IUS, please set UVM_HOME environment variable
    NCROOT    := $(shell ncroot)
    UVM_HOME  := $(NCROOT)/tools/uvm
    ifneq (${UVM_HOME},$(shell ls -d ${UVM_HOME} 2>&1))
      $(error $(ERROR_MSG))
    endif
  endif
endif
ifneq ($(strip $(UVM_HOME)),)
UVM               = $(UVM_HOME)
else
UVM               = "<UVM_HOME UNDEFINED>"
endif
UVM_SRC_DIR   = $(UVM)/src
UVM_SRC       = $(UVM_SRC_DIR)/uvm_pkg.sv
UVM_MACRO_SRC = $(UVM_SRC_DIR)/uvm_macros.svh
UVM_VERSION   = "1_0"
ifneq ($(strip $(USE_SV_PACKAGE)),)
USE_SV_PACKAGE = 1
PKG_OPT     =   +define+USE_SV_PACKAGE
PKG_LIST    =   $(UVM_SRC) \
                $(COMMON_INC)/common_pkg.sv \
             $(APB_INC)/apb_pkg.sv \
             $(AXI_INC)/axi_pkg.sv \
             $(FWD_INC)/fwd_pkg.sv \
             $(MAC_INC)/mac_pkg.sv \
                $(ENV)/txd_pkg.sv
IUS_OPT     =
else
PKG_OPT     =
PKG_LIST    =
IUS_OPT     = $(UVM)/src/uvm.svh $(UVM_MACROS_SRC)
endif
TESTNAME          = test_example
SEED              = 1
TB_FILENAME       = $(ENV)/txd_tb_top.sv
VERBOSITY         = UVM_FULL
IUS_OPTIONS    =  \
      $(IUS_OPT) \
      +svseed=$(SEED) \
      +incdir+$(UVM_SRC_DIR) \
             $(INC) \
             -nowarn IGNFMT \
             +UVM_TESTNAME=$(TESTNAME) \
             +UVM_MSG_DETAIL=$(VERBOSITY) \
             $(PKG_OPT) \
             $(PKG_LIST) \
      +incdir+$(DUT) $(DUT_SRC) \
             $(TB_FILENAME)
VCS_OPTIONS   = -q +warn=noISALS \
  -sverilog \
  -timescale=1ns/100ps \
  $(INC) \
  +incdir+$(UVM_SRC_DIR) \
  +incdir+$(DUT) $(DUT_SRC) \
  $(COMPILE_OPT) \
  -Mdir=./csrc \
  -o simv \
                -Mupdate \
                -debug_pp \
         +libext+.sv+.v+.vh+.vmd+.vo+.bv+.lmcds \
                +v2k \
                +define+UVM_VERSION_STRING=$(UVM_VERSION) \
         +error+100 +lint=TMR
VCS_RUN_OPTIONS = +wc \
                  +notimingchecks \
                  +ntb_random_seed=$(SEED) \
           +UVM_TESTNAME=$(TESTNAME) \
    +UVM_MSG_DETAIL=$(VERBOSITY)

#******************************************************************************#
# Targets
#******************************************************************************#
help :
 @echo " ----------------------------------------------------------------";
 @echo "|             PW TEMPLATE GENERATOR EXAMPLE MAKEFILE             |";
 @echo " ----------------------------------------------------------------";
 @echo "|                                                                |";
 @echo "| Usage:                                                         |";
 @echo "|                                                                |";
 @echo "| make <target> [ TESTNAME=<testname> SEED=<num> USE_SV_PACKAGE  |";
 @echo "|               VERBOSITY=<verbosity_level> OPT=<user options> ] |";
 @echo "|                                                                |";
 @echo "| Mandatory Arguments:                                           |";
 @echo "| Available targets                                              |";
 @echo "|   test_ius    : Execute a test using cadence simulator.        |";
 @echo "|   test_mti    : Execute a test using mentor simulator.         |";
 @echo "|   test_vcs    : Execute a test using synopsys simulator.       |";
 @echo "|   clean       : Remove simulation files and directories.       |";
 @echo "|                                                                |";
 @echo "| Optional Arguments:                                            |";
 @echo "| To compile using SystemVerilog Packages use the following:     |";
 @echo "|  USE_SV_PACKAGE=1                                              |"
 @echo "|                                                                |";
 @echo "| Available verbosity_level for VERBOSITY                        |";
 @echo "|  UVM_NONE, UVM_LOW, UVM_MEDIUM, UVM_HIGH, UVM_FULL, or integer |";
 @echo "|  default is UVM_FULL                                           |";
 @echo "|                                                                |";
 @echo " ----------------------------------------------------------------";
test_ius   : clean run_ius check_test_ius
test_mti : clean run_mti check_test_mti
test_vcs : clean run_vcs check_test_vcs
clean:
 -rm -rf *.log *.df waves.shm INCA_libs *~ assertion_summary *.trn *.vcd simvision verilog.dump waves.shm irun.key irun.log* work transcript svp_work vsim.wlf csrc simv simv.daidir simv.vdb
run_ius :
 @echo "PKG LIST =  $(PKG_LIST)"
 @echo "USE_SV_PACKAGE =  $(USE_SV_PACKAGE)"
 irun $(IUS_OPTIONS) $(OPT)
run_mti:
 rm -rf work
 @echo "PKG LIST =  $(PKG_LIST)"
 @echo "USE_SV_PACKAGE =  $(USE_SV_PACKAGE)"
 vlib work
# vlog +incdir+$(DUT) $(DUT_SRC)
 vlog +incdir+$(UVM_SRC_DIR) \
        $(INC) \
        $(PKG_OPT) \
        $(PKG_LIST) \
 $(ENV)/txd_tb_top.sv
 vsim -do vsim.do -c -suppress 3829 -sv_seed $(SEED) +UVM_TESTNAME=$(TESTNAME) +UVM_MSG_DETAIL=$(VERBOSITY) $(OPT) txd_tb_top
run_vcs :
 @echo "PKG LIST =  $(PKG_LIST)"
 @echo "USE_SV_PACKAGE =  $(USE_SV_PACKAGE)"
 vcs +vcs+lic+wait $(VCS_OPTIONS) $(COMPILE_OPT) $(OPT) -l $(TESTNAME).log $(TB_FILENAME)
 ./simv $(VCS_RUN_OPTIONS) $(OPT) $(PKG_OPT) $(PKG_LIST) -l vrun.log
check_test_ius:
 @if test -f irun.log; then \
 if ( (grep "ERR" irun.log|grep -v "0">/dev/null) || (grep "WARN" irun.log|grep -v "0">/dev/null) || (grep "FATAL" irun.log|grep -v "0">/dev/null) ); then \
 echo "TEST FAILED - check irun.log file for details."; \
 else \
 echo "TEST PASSED";\
 fi; \
 else \
 echo "TEST FAILED - logfile irun.log does not exist."; \
 exit -1; \
 fi; \
 if test -f INCA_libs/svpplib/assertion_summary; then \
 mv INCA_libs/svpplib/assertion_summary .; \
 fi
check_test_mti:
 @if test -f transcript; then \
 if ( (grep "ERR" transcript|grep -v "0">/dev/null) || (grep "WARN" transcript|grep -v "0">/dev/null) || (grep "FATAL" transcript|grep -v "0">/dev/null) ); then \
 echo "TEST FAILED - check transcript file for details."; \
 else \
 echo "TEST PASSED";\
 fi; \
 else \
 echo "TEST FAILED - logfile transcript does not exist."; \
 exit -1; \
 fi;
check_test_vcs:
 @if test -f vrun.log; then \
 if ( (grep "ERR" vrun.log|grep -q "1") || (grep "WARN" vrun.log|grep -q "1") || (grep "FATAL" vrun.log|grep -q "1") ); then \
 echo "TEST FAILED - check vrun.log file for details."; \
 else \
 echo "TEST PASSED";\
 fi; \
 else \
 echo "TEST FAILED - logfile vrun.log does not exist."; \
 exit -1; \
 fi;

2010年9月13日星期一

enable 'emacs verilog mode autos' for gvim

1,enable auto filetype detection

"~/.vim/filetype.vim
au BufNewFile,BufRead *.v,*.vh setf verilog
au BufNewFile,BufRead *.sv,*.svh setf verilog_systemverilog

download
"~/.vim/syntax/verilg_systemverilog.vim
"verilog.vim could be found at VIM's install path

"~/.vimrc
syntax on

2,download
~/elisp/verilog-mode.el

3, download
~/.vim/ftplugin/verilog_emacsauto.vim
~/.vim/ftplugin/verilog_systemverilog_emacsauto.vim " make a copy for sv
*modify the keymap if you want

4,
"~/.vimrc
filetype plugin indent on

5, you are ready to use the autos in both .v and .sv
put ./module_a.v ./module_b.v
edit ./tb_top.v:
module tb_top;
module_a u_a(/*AUTOINST*/
);
module_b u_b(/*AUTOINST*/
);
endmodule

*use keymap Ctrl-A to extract /*AUTOINST*/ and Ctrl-D to delete

2010年9月10日星期五

SystemVerilog - connect multiple clients by interface modport

// Bus interface with parameterized number of client modports
interface intf_t #(num_clients = 0);
bit [num_clients-1:0] req;

// Similar with the 'generate statement' in Verilog
// The instance name will be mps[i].client_mp
for (genvar i=0; i++) begin: mps
modport client_mp (output .client_req( req[i] ));
end
endinterface

// A generic client that attaches to the bus
module client_m (interface client_ifc);
// ... code will drive client_ifc.client_req
endmodule

// The bus system with N clients
module bus #(N = 0);
intf_t #(.num_clients(N)) intf();
// Similar with the 'generate statement' in Verilog
// Similarly, the instance names will be clients[n].client
for (genvar j=0; j++) begin: clients
client_m client (.client_ifc (intf.mps[j].client_mp));
end

endmodule

**This feature is NOT yet supported by NCVLOG

2010年9月9日星期四

another example of .vimrc

Sample .vimrc
When vim is run by default it will look for a vimrc file that contains configuration info and scripts that it can use while it is running. The file can also be found here.

"
" .vimrc
"
" Vim configuration resource file. Specifies desired
" behavior for the vim editor.
"
:set showmode " Tell you if you're in insert mode
:set tabstop=4 " Set the tabstop to 4 spaces
:set shiftwidth=4 " Shiftwidth should match tabstop
:set expandtab " Convert tabs to number of spaces
:set nowrap " Do not wrap lines longer than the window
:set wrapscan " Wrap to the top of the file while searching
:set ruler " Show the cursor position all the time
:set showmatch " Show matching [] () {} etc...
:set smartindent " Let vim help you with your code indention
:set formatoptions+=ro " Automatically insert the comment character when
" you hit (r) or o/O (o) in a block comment.
:set backspace=2 " makes backspace work like you expect
:set nohlsearch " Don't highlight strings you're searching for
:set incsearch " Do highlight as you type your search
:set ignorecase " makes searches case-insensitive

" Disable paren highlighting
"let loaded_matchparen = 1

" Switch syntax highlighting on, when the terminal can support colors
" if # of terminal colors > 2 OR you're using Gvim
if &t_Co > 2 has("gui_running")
:syntax on
" Change the highlight color for Comment and Special
" to Cyan. Blue is too dark for a black background.
:highlight Comment term=bold ctermfg=cyan guifg=cyan
:highlight Special term=bold ctermfg=cyan guifg=cyan
:highlight Constant term=bold ctermfg=red guifg=cyan
endif

" Make vim turn *off* expandtab for files named Makefile or makefile
" We need the tab literal
:autocmd BufNewFile,BufRead [Mm]akefile* set noexpandtab

" Make vim recognize a file ending in ".template" be a C++ source file
:autocmd BufNewFile,BufRead *.template set ft=cpp

" Make vim tab 2 spaces for HTML files
:autocmd BufNewFile,BufRead *.htm* set tabstop=2
:autocmd BufNewFile,BufRead *.htm* set shiftwidth=2
" Make vin tab 2 spaces for PHP files
:autocmd BufNewFile,BufRead *.php set tabstop=2
:autocmd BufNewFile,BufRead *.php set shiftwidth=2

" Make vim recognize Y86 assembly files
:autocmd BufNewFile,BufRead *.ys set ft=asm
:autocmd BufNewFile,BufRead *.ys set nosmartindent

" Make vim recognize R files
:autocmd BufNewFile,BufRead *.[Rr] set ft=r

" Make vim recognize Prolog files
:autocmd BufNewFile,BufRead *.pl set ft=prolog
" Turn off paren matching for Prolog files
:autocmd BufNewFile,BufRead *.pl NoMatchParen

" Adds main program heading from Program Style Guidelines
function FileHeading()
let s:line=line(".")
call setline( s:line,"// Program: ")
call append( s:line,"// Author: Derrick")
call append(s:line+1,"// Date: ".strftime("%b %d %Y"))
call append(s:line+2,"// Assignment: ")
call append(s:line+3,"// Purpose: ")
call append(s:line+4,"// ")
call append(s:line+5,"// Input: ")
call append(s:line+6,"// Output: ")
call append(s:line+7,"// Related")
call append(s:line+8,"// Files: ")
call append(s:line+9,"// Functions: ")
call append(s:line+10,"// ")
call append(s:line+11,"")
unlet s:line
endfunction

" Adds class heading from Program Style Guidelines
function ClassHeading()
let s:line=line(".")
call setline( s:line,"// Program Name: ")
call append( s:line,"// Author: Derrick")
call append(s:line+1,"// Date: ".strftime("%b %d %Y"))
call append(s:line+2,"// Assignment: ")
call append(s:line+3,"// Purpose: ")
call append(s:line+4,"// ")
call append(s:line+5,"// Public class variables")
call append(s:line+6,"// ")
call append(s:line+7,"// Public functions:")
call append(s:line+8,"// ")
call append(s:line+9,"// Related files:")
call append(s:line+10,"// ")
call append(s:line+11,"")
unlet s:line
endfunction

" Adds function heading from Program Style Guidelines
function FunctionHeading()
let s:line=line(".")
call setline( s:line,"//****************************************************************************")
call append( s:line,"// Function name: ")
call append(s:line+1,"// Author: Derrick")
call append(s:line+2,"// Date: ".strftime("%b %d %Y"))
call append(s:line+3,"// Purpose: ")
call append(s:line+4,"// Params: ")
call append(s:line+5,"// ")
call append(s:line+6,"// Returns: ")
call append(s:line+7,"//****************************************************************************")
unlet s:line
endfunction

" Adds HTML skeleton to file
function HTMLFrame()
let s:line=line(".")
call setline( s:line,"")
call append( s:line," ")
call append(s:line+1," ")
call append(s:line+2," ")
call append(s:line+3," ")
call append(s:line+4," ")
call append(s:line+5," ")
call append(s:line+6,"")
unlet s:line
endfunction

" Adds Unix shebang line to beginning of
" any new Ruby script
function RubyFile()
let s:line=line(".")
call setline( s:line,"#!/usr/bin/env ruby")
call append( s:line,"")
unlet s:line
endfunction

" If opening new file with these file extentions
" then execute corresponding functions
:autocmd BufNewFile *.C,*.c execute FileHeading()
:autocmd BufNewFile *.h execute ClassHeading()
:autocmd BufNewFile *.htm* execute HTMLFrame()
:autocmd BufNewFile *.php execute HTMLFrame()
:autocmd BufNewFile *.rb execute RubyFile()

" Map keys to perform series of key strokes and functions
" Ex, If F2 is pressed then execute FileHeading function,
" and move cursor to first line of comments
imap mz:execute FileHeading()`zA
imap mz:execute FunctionHeading()'zjA
imap mz:execute ClassHeading()'zA