Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting tasks to 'C using DPI

I have an verilog based test-bench, interfaced to 'C source using DPI. Now using DPI I am planning to write my whole firmware. To do this I need 3 things

  • Register Read
  • Register Write
  • Interrupt handler As I understand, register reads and writes are tasks that I need to export from the RTL test-bench. And Interrupt handler (I implemented by importing a function from 'C).

I checked most the cadence documentation and found no useful hints. I have also registered with cadence users community but it seems that I cannot ask question till they approve my registration.

Just in case someone is aware of this, would appreciate their help.

like image 518
Alphaneo Avatar asked Apr 07 '09 07:04

Alphaneo


2 Answers

Actually I figured it out something like this.

//--From RTL ---
export "DPI" task reg_read;

task reg_read;
   input int nAddr;
   output int nVal;

 // -- read implementation --

endtask

// -- From C code
extern void reg_read (int nAddr, int *pVal);

void test_read (void)
{
   int nRegVal;

   // Dummy checking !!
   reg_read (0x100, &nRegVal);
}

// -- Again in RTL --
import "DPI" context task test_read ();

This works for me using ncverilog.

like image 135
Alphaneo Avatar answered Sep 20 '22 12:09

Alphaneo


Cool...I actually wrote an article on this topic. link

The paper is actually exporting register reads and writes and stuff across the DPI and then adding a TCL interpreter to it so that you can use TCL to control your sim. This was something the lab dudes loved since all their tools are already in Tcl.

You can just follow the instructions to integrate your function calls from C to SV across the DPI, and then stop when the TCL stuff comes into play.

like image 43
SDGator Avatar answered Sep 19 '22 12:09

SDGator