Origen-SDK / origen_sim

Plugin to enable Origen patterns to be run in a dynamic Verilog simulation
MIT License
1 stars 4 forks source link

task execution capability #58

Open redxeth opened 1 year ago

redxeth commented 1 year ago

Add ability to OrignSim to be able to execute a task from the compiled RTL.

e.g.

def call_my_func
  tester.call "test.dut.my_ip.my_block.my_func", 1
end

I dont mind helping to work on it- just wondering if anyone has any advice or particulars they care about.

ginty commented 1 year ago

There's no way to do that so elegantly I'm afraid. Origen Sim uses the Verilog VPI interface to communicate with the DUT and there is no way to call a task from that. There is another interface called the DPI which gets closer - you can't call a task directly from that but it will let you call a C function on the design side which in turn calls the task. However the work on the OrigenSim side to enable that is likely not trivial and I have no experience of using the DPI.

So even with the DPI you would need to create a C wrapper, but you could also create a Verilog wrapper and use that with existing Origen Sim. Basically the VPI only allows you to peek and poke at netlist nodes and so I would create a wrapper like this (in pidgin RTL):

reg call_my_task;
reg [15:0] my_task_arg;

always @ posedge call_my_task {
  #my_task(my_task_arg);
}

I haven't written RTL in a while and I forget if you can pass args to tasks like that, hopefully you can.

Then in your Origen code you could do:

def call_my_func(my_arg)
  tester.poke "my_task_arg", my_arg
  tester.poke "call_my_task", 0
  tester.poke "call_my_task", 1
end

call_my_func(0x55)

I would put the Verilog wrappers in their own file and include that into the Origen Sim build, I forget how but I'm sure Origen Sim supports that already.

You can imagine if you had a list of task signatures (like a header file) you could create a script to automatically generate the Verilog and Ruby wrappers for them.

@coreyeng may have other thoughts/experience on this...

coreyeng commented 1 year ago

I have on my to-do list to add this to O2's version. Essentially, it'd work like CATI where there's known functions built in and signals are toggled to kick off the commands.

In the meantime, you can build a task in with an always block to repeatedly monitor a signal and poke that signal (poking arg values beforehand) and launch that way.

The only downside is the tasks must be compiled in during the snapshot build. No adding tasks dynamically. The DPI had the illusion of that but I when I looked further into it, it still needed to be compiled at the outset. It was closer to linking a static library than what it let on (at least back in 2017 when I was looking into it and discussing solely with Cadence - maybe its better now).

As said though, this is on my to-do list for O2.

redxeth commented 1 year ago

Thanks @ginty and @coreyeng ! I'm still trying to get my head around how OrigenSim even works-- didn't know that there were 2 things, DPI vs VPI. I thought I saw something online about being able to execute tasks. Anyway, I think having the task in the snapshot build is fine.