Can I call a VHDL function inside Verilog
Asked Answered
M

2

7

I am currently trying to use certain legacy VHDL codes into my Verilog design. While it is possible to instantiate VHDL modules within Verilog, I could not find a way to call VHDL functions within Verilog. (Apart from wrapping it around in a VHDL module and instantiating the module). Is there anyway to directly call VHDL functions within Verilog?

Mer answered 21/4, 2016 at 2:25 Comment(7)
What tool are you using?Breastsummer
Cadence Incisive Enterprise simulatorMer
Btb why the downvote?Mer
Oh sorry @Paebbels. I didn't actually mean you. Just wanted to ask the person who did. A comment would be appreciated. :)Mer
Where are the functions located? In a package? Or are they part of some particular entity/architecture pair? The only mechanism I can think of is to write a PLI/VPI/DPI function to traverse the hierarchy and find the function and get a handle to it. But I'm not even sure it is possible to call a VHDL function/procedure from the VHPI/VPI.Novelia
They are part of a package. Mostly common functions that are used across multiple modules. Thanks for the infoMer
I think your solution of instantiating a VHDL component that contains just the function(s) would be easiest. Or, if those functions are relatively small, or there are just a few that you need from the package, maybe re-write them in SV and use them directly from your new package... "the politics of re-use", notwithstanding.Kilo
D
0

It probably depends on the simulator. In Modelsim PE v10.2c for example, directly calling VHDL functions from a Verilog/SystemVerilog is not supported

Hierarchical References to a VHDL Object from a Verilog/SystemVerilog Scope

Supported Objects

The only VHDL object types that can be referenced are: signals, shared variables, constants, and generics not declared within processes. VHDL functions, procedures, and types are not supported, and you cannot read VHDL process variables

Modelsim PE User's Manual v10.2c, p.297

You can use a common package between SystemVerilog / VHDL modules with an import keyword, but again VHDL functions are not supported.

You better refer to your simulator's manual to see if it is supported or not, because apparently there's no universally accepted way to do it.

Disburden answered 28/9, 2016 at 13:8 Comment(0)
R
-2

As @Ivoudour noted, The support for this feature is depended on simulator. However, for those that do, the usage should be largely the same. This means that you can simply treat a VHDL based component as just another module. This assumes that you compile the design to the same library.

The below example uses ModelSim Altera Edition v10.4b with the following structure: and_tb (VHDL) -> and_bits (verilog) -> and2 (VHDL)

and2.vhd

library ieee ;
use ieee.std_logic_1164.all ;

entity and2 is
    port (
        a   : in    std_logic;
        b   : in    std_logic;
        c   : out   std_logic
    );
end and2;

architecture behavior of and2 is
begin
    c <= a and b;
end behavior ;

and_bits.v

`default_nettype none
`timescale       1ns/1ns

module and_bits #(
    parameter W                     = 5           
) (   
    input wire  [W-1:0]  a,
    input wire  [W-1:0]  b,
    output wire [W-1:0]  c
);
    genvar i;
    for (i=0; i<=W-1; i=i+1) begin: AND_GENERATE
        and2 u_and2 (            
            .a (a[i]),
            .b (b[i]),
            .c (c[i])
        );
    end

endmodule

`resetall

and_tb.vhd

library ieee ;
use ieee.std_logic_1164.all ;

entity and_tb is
end and_tb;

architecture tb of and_tb is
    signal a : std_logic_vector(3 downto 0) := "0110";
    signal b : std_logic_vector(3 downto 0) := "1111";
    signal c : std_logic_vector(3 downto 0);


    component and_bits
        generic ( W : integer );
        port (
            a : in  std_logic_vector(W-1 downto 0);
            b : in  std_logic_vector(W-1 downto 0);
            c : out std_logic_vector(W-1 downto 0)
        );
    end component;

begin
    dut: and_bits
    generic map (W => 4)
    PORT MAP(a=>a, b=>b, c=>c);
end tb ;

Simulation

Type the following in ModelSim console

vlib work
vcom and2.vhd
vlog and_bits.v
vcom and_tb.vhd

and simulate as normal.

Retrogressive answered 3/12, 2017 at 0:16 Comment(2)
Please read the (1.5 year old) question. He already knows how to instantiate VHDL modules in Verilog. He wants to know how to directly instantiate functions written in VHDL in Verilog modulesMeagre
You're right. Thanks. Now, how can I remove my answer?Retrogressive

© 2022 - 2024 — McMap. All rights reserved.