User guide
18-56
DirectC Interface
UB *vc_MemoryRef(vc_handle)
Returns a pointer of type UB that points to a memory in Verilog. For
example:
extern void mem_doer ( input reg [1:0] array [3:0]
memory1, output reg [1:0] array
[31:0] memory2);
module top;
reg [1:0] memory1 [3:0];
reg [1:0] memory2 [31:0];
initial
begin
memory1 [3] = 2’b11;
memory1 [2] = 2’b10;
memory1 [1] = 2’b01;
memory1 [0] = 2’b00;
mem_doer(memory1,memory2);
$display("memory2[31]=%0d",memory2[31]);
end
endmodule
Here we declare two memories, one with 4 addresses, memory1, the
other with 32 addresses, memory2. We assign values to the
addresses of memory1, and then pass both memories to the C/C++
function mem_doer.
#include <stdio.h>
#include "DirectC.h"
void mem_doer(vc_handle h1, vc_handle h2)
{
UB *p1, *p2;
int i;
p1 = vc_MemoryRef(h1);
p2 = vc_MemoryRef(h2);