Thursday, February 2, 2017

SystemVerilog DPI in irun

module real_test ();

// map the C function name to the Verilog function name
import "DPI-C" context get_real_c = function real get_real_v ();
import "DPI-C" context put_real_c = function void put_real_v (real x);     

real pi;

initial
begin
$display("real_test");

pi = get_real_v();        // get a real number from the C code
$display("pi = %f", pi);  // display it

put_real_v(pi);           // send the real number back to C code  
  
end

endmodule
#include "svdpi.h"
// since we are using math functions, include the math library
#include <math.h>

// can use io_printf() instead of printf() to put into ncsim.log file
double get_real_c() {  // imported SV function
  // exercise DPI function - get calling scope
  printf("Function Calling HDL scope is %s \n", svGetNameFromScope(svGetScope() ) );
  return 3.14159;
}

void put_real_c(double n) {  // imported SV function
  // exercise DPI function - get calling scope
  printf("Function Calling HDL scope is %s \n", svGetNameFromScope(svGetScope() ) );
  printf("pi + 5.0 = %f\n", n+5.0);      
}
gcc -fPIC -g -shared -o libdpi.so  real_dpi.c  -I/`ncroot`/tools/include
irun -64 real_test.sv
or
ncvlog real_test.v -sv
ncelab -dpiheader dpi.h worklib.real_test:module
ncsim worklib.real_test:module -sv_lib libdpi.so  -sv_root .

Configuring ctags for Python and Vim

http://www.held.org.il/blog/2011/02/configuring-ctags-for-python-and-vim/

  1. Install ctags
  2. Configure ctags.
    Add to ~/.ctags the following, one option per line:
    1. --python-kinds=-i
    2. optional: --exclude=<partial names of bad files/directories>. e.g. --exclude=*/build/* to exclude all files inside 'build/' directories
  3. Add a cron to rebuild tags, for instance:
    1 * * * * ctags -R -o ~/mytags ~/src
  4. Configure vim:
    add to ~/.vimrc: :set tags=~/mytags
  5. Use Vim:
    1. vim -t <tag name> to open vim straight on the tag
    2. Ctrl+] to jump to tag when over a word
    3. Ctrl+T to pop back
    4. :tselect or :stselect to open
    5. :tnext, :tprev to go to next/prev tag finding
    6. :help tags for more ðŸ™‚

Setting up a MinGW-w64 build environment

http://ascend4.org/Setting_up_a_MinGW-w64_build_environment



    First steps


    MSYS


    Switchable 32- and 64-bit modes


    MinGW-w64


    SWIG

    • Download a pre-compiled 'swigwin' copy of SWIG We used swingwin-x.x.xx.zip.
    • Create a folder c:\mingw\msys\opt using Windows Explorer, then copy the 'swigwin-2.0.10' folder out of the Zip archive and into the new location c:\mingw\msys\opt\swigwin-2.0.10
    • In MSYS, type gedit ~/.profile, then add the SWIG directory to your PATH in your profile, by adding the following line at the bottom of that file:
    export PATH=$PATH:/opt/swigwin-2.0.10
    
    • Close your MSYS window and reopen it, so that the ~/.profile will be re-read.
    • Test that SWIG is accessible by typing swig -version. You should see the version number and some other information output.
    As SWIG is a code pre-processor, it doesn't matter whether it's 32-bit or 64-bit, they will be perfectly equivalent. That is the reason that we install SWIG under msys rather than in mingw\32 or mingw\64. Note that SWIG version 2.0.5 was known to cause problems with MinGW-w64.