User guide

18-65
DirectC Interface
So type vec32 has two members, c and d, for control and data
information. This routine always copies to the 0 element of the array.
For example:
extern void mem_elem_copier (inout reg [] array [] memX);
module test;
reg [127:0] mem1 [127:0];
reg [7:0] mem2 [64:0];
initial
begin
mem1 [0] = 999;
mem2 [0] = 8’b0000000z;
$display("mem1[0]=%0d",mem1[0]);
$display("mem2[0]=%0d",mem2[0]);
mem_elem_copier(mem1);
mem_elem_copier(mem2);
$display("mem1[32]=%0d",mem1[32]);
$display("mem2[32]=%0d",mem2[32]);
$finish;
end
endmodule
In the Verilog code a C/C++ function is declared that is called twice.
Notice the value assigned to mem2 [0]. The C/C++ function copies
the values to another element in the memory.
#include <stdio.h>
#include "DirectC.h"
void mem_elem_copier(vc_handle h)
{
vec32 holder[1];
vc_get4stMemoryVector(h,0,holder);
vc_put4stMemoryVector(h,32,holder);
printf(" holder[0].d is %d holder[0].c is %d\n\n",
holder[0].d,holder[0].c);
}