User guide
18-19
DirectC Interface
Solution 2: Perform the conversion on the Verilog side. This requires
some additional effort, as the memory space for a C string has to be
allocated as follows:
extern "C" string malloc(int);
extern "C" void vc_ConvertToString(reg [], int, string);
// this function comes from DirectC library
reg [31:0] sptr;
.
.
.
// allocate memory for a C-string
sptr = malloc(8*100+1);
//100 is the width of 'message', +1 is for NULL terminator
// perform conversion
vc_ConvertToString(message, 800, sptr);
WriteReport(sptr, ...);
Avoiding a Naming Problem
In a module definition do not call an external C/C++ function with the
same name as the module definition. The following is an example of
the type of source code you should avoid:
extern void receive_string (input string r5);
.
.
.
module receive_string;
.
.
.
always @ r5
begin
.
.
.
receive_string(r5);
.
.
.
end
endmodule