From d2aff1340291fa83b69b853d2f0ed15f37025e4b Mon Sep 17 00:00:00 2001 From: David Stanford Date: Thu, 2 Feb 2023 20:51:23 -0600 Subject: [PATCH] Commentary: Add some more details to the vpi example (#3925) --- docs/guide/connecting.rst | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/guide/connecting.rst b/docs/guide/connecting.rst index a774d1ae0..f278150b9 100644 --- a/docs/guide/connecting.rst +++ b/docs/guide/connecting.rst @@ -374,9 +374,11 @@ changed on the specified clock edge. .. code-block:: bash cat >our.v <<'EOF' - module our (input clk); - reg readme /*verilator public_flat_rd*/; - reg writeme /*verilator public_flat_rw @(posedge clk) */; + module our #( + parameter WIDTH /*verilator public_flat_rd*/ = 32 + ) (input clk); + reg [WIDTH-1:0] readme /*verilator public_flat_rd*/; + reg [WIDTH-1:0] writeme /*verilator public_flat_rw @(posedge clk) */; initial $finish; endmodule EOF @@ -398,12 +400,14 @@ accesses the above signal "readme" would be: vpiHandle vh1 = vpi_handle_by_name((PLI_BYTE8*)"TOP.our.readme", NULL); if (!vh1) vl_fatal(__FILE__, __LINE__, "sim_main", "No handle found"); const char* name = vpi_get_str(vpiName, vh1); - printf("Module name: %s\n", name); // Prints "readme" + const char* type = vpi_get_str(vpiType, vh1); + const int size = vpi_get(vpiSize, vh1); + printf("register name: %s, type: %s, size: %d\n", name, type, size); // Prints "register name: readme, type: vpiReg, size: 32" s_vpi_value v; v.format = vpiIntVal; vpi_get_value(vh1, &v); - printf("Value of v: %d\n", v.value.integer); // Prints "readme" + printf("Value of %s: %d\n", name, v.value.integer); // Prints "Value of readme: 0" } int main(int argc, char** argv) {