Cocotb: A tcl based flow ?

Created on 26 Feb 2020  路  3Comments  路  Source: cocotb/cocotb

We could now make a simple tcl based flow.

A Modelsim script for adder example (vsim -c -do run.do):

# run.do

# General cocotb settings
exec cocotb-config --prefix > /tmp/cocotb-prefix
set COCOTB_DIR [string trim [read [open "/tmp/cocotb-prefix" r]]]
set VPI_LIB $COCOTB_DIR/cocotb/libs/modelsim/libcocotbvpi.so
set ::env(COCOTB_SIM) 1
set ::env(PYTHONPATH) ${COCOTB_DIR}/cocotb/libs/modelsim

# This test settings
set ::env(MODULE) test_adder
set ::env(PYTHONPATH) ./:../model:$::env(PYTHONPATH)

# Compile and run
vlog ../hdl/adder.v
vsim  -pli $VPI_LIB adder
run -all

Should we add such flow under examples (can use Icarus in CI) or document it?

question

Most helpful comment

You can get the output of exec directly, btw.
Also using file commands is platform agnostic:

if {[catch {set COCOTB_DIR [file normalize [exec cocotb-config --prefix]]}]} {
    puts "cocotb-config failed to execute"
    puts "  $::errorInfo"
    exit -code 1
    }
set VPI_LIB [file join $COCOTB_DIR cocotb libs modelsim libcocotbvpi.so]
...

All 3 comments

I ended up making a tcl package with some helper procedures that set the ::env vars and launch simulation with the right library.
Using TCLLIBPATH envar to point to the package folder, your script can then use package require cocotb and call the procedures. Keeps the script clean, and less brittle if the underlying details change.

You can get the output of exec directly, btw.
Also using file commands is platform agnostic:

if {[catch {set COCOTB_DIR [file normalize [exec cocotb-config --prefix]]}]} {
    puts "cocotb-config failed to execute"
    puts "  $::errorInfo"
    exit -code 1
    }
set VPI_LIB [file join $COCOTB_DIR cocotb libs modelsim libcocotbvpi.so]
...

@garmin-mjames thank you for the hint.

I close in favor of https://github.com/cocotb/cocotb/issues/1718

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marlonjames picture marlonjames  路  3Comments

imphil picture imphil  路  7Comments

chiggs picture chiggs  路  6Comments

ktbarrett picture ktbarrett  路  7Comments

ktbarrett picture ktbarrett  路  4Comments