This may well be a case of my not being able to see the wood for the trees or generally doing something stupid, but I thought I'd ask anyway.
I'm trying to interface a bus driver with some DPI code and thought that using a queue would be the best way. What I have on the DPI side is a function that is called when new data is available to be pushed onto the queue. On the RTL side, I've got a module with a FIFO interface and data is popped off the queue as it is loaded into the receiving downstream flop. So something like the following:
bit [31:0] queue[$];
function push_back;
input bit [31:0] value;
queue.push_back(value);
endfunction
always_ff@(posedge clk) begin
if(fifo_pop)
queue.pop_front();
end
assign din = queue[0];
always_ff@(posedge clk) begin
if (fifo_pop)
capture_r <= din;
end
What I'm seeing is that the queue is updated before din has been captured in the receiving flop. Is that expected and if so, what should I be doing here? I've not done a load of DPI work before and haven't seen too many examples of how to cleanly drive an interface like this.
Thanks.