Search code examples
vhdlsystem-verilogquestasim

Which SystemVerilog construct corresponds to VHDL string?


I'm trying to create a SystemVerilog module that I could connect to a VHDL string. However, I cannot find a corresponding type in SystemVerilog. Using type "string" results in elaboration error in Questa.

VHDL code:

library IEEE;
use IEEE.std_logic_1164.all;

entity tb_serdes_support is    
end entity;

architecture beh of tb_serdes_support is    
    component serdes_support is port (    
        cmd         : in string    
    );
    end component;

    signal cmd  : string(1 to 100);

begin    
    i_srds_support: serdes_support port map (
        cmd         => cmd    
    );

    process
    begin    
        cmd(1 to 12) <= "hello world!";    
        wait for 10 ns;    
        cmd(1 to 18) <= "hello world again!";    
        wait;    
    end process;    

end architecture;

SV code:

module serdes_support (cmd);

import uvm_pkg::*;

input string cmd;

always_comb begin    
    $display(cmd);    
end

endmodule

Edit: Error message (Questa):

** Error: (vsim-3059) Cannot connect a VHDL array signal to Verilog scalar port 'cmd'.


Solution

  • You can convert the VHDL string in an appropriate "bit-vector" and use this "bit-vector" in the Verilog environment. In Verilog you can interprete it then however you want e.g. with %s.

    mov_vhd.vhd:

    LIBRARY ieee;
    USE ieee.std_logic_1164.ALL;
    USE ieee.numeric_std.ALL;
    
    ENTITY mod_vhd IS
        PORT
            (
                clk : IN std_ulogic;
                str_out : OUT string
            );
    END ENTITY mod_vhd;
    
    ARCHITECTURE sim OF mod_vhd IS
    
    BEGIN
    
        clock_out_string: PROCESS IS
    
    
        BEGIN
            FOR i IN 0 TO 9 loop
                WAIT UNTIL rising_edge(clk);
                str_out <= "Hallo    "&integer'IMAGE(i);
            END LOOP;
    
        END PROCESS clock_out_string;
    
    END ARCHITECTURE sim;
    

    mod_ver.sv:

    module mod_ver (
        input [79:0] my_string
    );
    
    initial begin
       forever @my_string
          $display ("see %s",my_string);
    end
    
    
    endmodule // mod_ver
    

    top_vhd.vhd

    LIBRARY ieee;
    USE ieee.std_logic_1164.ALL;
    USE ieee.numeric_std.ALL;
    
    ENTITY top_vhd IS
    END ENTITY top_vhd;
    
    ARCHITECTURE sim OF top_vhd IS
    
    SIGNAL clk: std_ulogic := '0';
    SIGNAL str_out : string (1 TO 10);
    SIGNAL str_out_ver : std_logic_vector (79 DOWNTO 0);
    
    BEGIN
    
        clk <= NOT clk AFTER 10 ns;
    
        mod_vhd_i: ENTITY work.mod_vhd
            PORT MAP (
                clk     => clk,
                str_out => str_out
            );
    
        gen_vec: for i in str_out'range generate
            str_out_ver((11-i)*8-1 downto (11-i)*8-8) <= std_logic_vector(to_unsigned(character'pos(str_out(i)), 8));
        end generate;    
    
        mod_ver_i: ENTITY work.mod_ver
            PORT MAP (
                my_string => str_out_ver
            );
    
    
    END ARCHITECTURE sim;