system-verilog

How do I read an environment variable in Verilog/System Verilog?

天涯浪子 提交于 2019-12-06 00:26:15
问题 How do I read an environment variable in Verilog ? (Running on a VCS simulator) I am trying to accomplish File=$fopen("$PATH/FileName","r"); $PATH is an environment variable. 回答1: You can simply use SystemVerilog DPI for getting environment. And because getenv is a standard C library for every POSIX platform, so you do not need to implement your own getenv() equivalent function for the function definition again. Example code in SV. import "DPI-C" function string getenv(input string env_name);

How to parameterize a case statement with don't cares?

こ雲淡風輕ζ 提交于 2019-12-05 21:32:13
I have a wire called input and I want to detect the number of leading I am trying to create a module which uses the case statement below to change the output data depending on the number of leading zeros. However the size of the input is parameterizable. If X was a fixed value of 4, I would just create a case statement, case (input) 4'b0001 : o_data = {i_data[0]}; 4'b001x : o_data = {i_data[1],1'b0}; 4'b01xx : o_data = {i_data[2],2'b0}; 4'b1xxx : o_data = {i_data[3],3'b0}; default : o_data = 4'b0000; endcase But with variable X, how do I define all cases? This question is similar to this one:

Instantiate Modules in Generate For Loop in Verilog

余生颓废 提交于 2019-12-05 14:23:29
I'm trying to instantiate some modules in Verilog using a generate block since I'm going to be instantiating a variable amount of them. genvar i; generate for (i=1; i<=10; i=i+1) begin status whatever_status ( .clk(clk), .reset_n(reset_n), .a(a[i]), .b(b[i]), .out(out[i]) ); end endgenerate a & b are declared as input arrays to the parent module and out is declared as a array of wires. What am I doing wrong here? Is this not allowed in Verilog? Quartus is telling me: Error (10644): Verilog HDL error at driver.v(63): this block requires a name Line 63 is the for loop above. Any help is

Automatic SystemVerilog variable size using interface width and $size?

我的未来我决定 提交于 2019-12-05 00:47:51
问题 I am trying to make a module (a DSP in my case) with a standardized memory interface in SystemVerilog, and would like the variables in the module to size automatically based on the bus widths in the attached interface. My rationale: this makes the code more portable by allowing it to auto-size to any connected interface, instead of requiring an HDL coder to pass in parameters that tell the module the widths of all the interface busses that will connect to it (not that this would be terrible,

create read/write environment using named pipes

二次信任 提交于 2019-12-04 21:18:41
I am using RedHat EL 4. I am using Bash 3.00.15. I am writing SystemVerilog and I want to emulate stdin and stdout. I can only use files as the normal stdin and stdout is not supported in the environment. I would like to use named pipes to emulate stdin and stdout. I understand how to create a to_sv and from_sv file using mkpipe, and how to open them and use them in SystemVerilog. By using "cat > to_sv" I can output strings to the SystemVerilog simulation. But that also outputs what I'm typing in the shell. I would like, if possible, a single shell where it acts almost like a UART terminal.

How to define and initialize a vector containing only ones in Verilog?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 18:53:13
问题 If I want to declare a 128 bit vector of all ones, which one of these methods is always correct? wire [127:0] mywire; assign mywire = 128'b1; assign mywire = {128{1'b1}}; assign mywire = 128'hFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; 回答1: As a quick simulation would prove, assign mywire = 128'b1; does not assign all bits of mywire to 1. Only bit 0 is assigned 1. Both of the following always assign all 128 bits to 1: assign mywire = {128{1'b1}}; assign mywire = 128'hFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;

TAP (Test Anything Protocol) module for Verilog or SystemVerilog

﹥>﹥吖頭↗ 提交于 2019-12-04 15:00:04
Is there a TAP ( Test Anything Protocol ) implementation for Verilog? It would be nice because then I could use prove to check my results automatically. Update: 10/9/09: It was asked why not use assertions. Partly TAP gives me some good reporting such as number of files and number of tests. It also can be used with smolder for reporting of progress over time. 10/12/09: I'm looking for a minimal implentation with number of tests at the beginning and end and the ok, diag and fail functions. is() would really nice, but not necessary. DaveParillo I don't think there is a native TAP implementation

Are SystemVerilog arrays passed by value or reference?

☆樱花仙子☆ 提交于 2019-12-04 13:28:07
问题 By default, does SystemVerilog pass arrays by value or reference? For example: int array[5] = '{0,1,2,3,4}; some_function(array); // <-- value or reference? 回答1: By default, SystemVerilog passes arrays by value, copying the entire array. It is recommended to pass arrays by reference whenever possible for performance reasons. If you want your function to modify the array, use ref . If you want your function to read the array, use const ref . Example: function void pass_by_value(int array[5],

UVM: illegal combination of driver and procedural assignment warning

旧城冷巷雨未停 提交于 2019-12-04 11:49:56
I have a UVM testbench for a small block in my chip. In this there is an agent with a driver that drives data on a virtual interface which looks something like this: interface my_if (input bit clk); logic [3:0] opcode; // Clocking block for the driver clocking drvClk @(posedge clk); output opcode; endclocking // Clocking block for the monitor clocking monClk @(posedge clk); input opcode; endclocking endinterface I use this interface in my driver like this: class my_driver extends uvm_driver #(my_tr); my_if vif; ... virtual task run_phase(uvm_phase phase); super.run_phase(phase); forever begin

Connecting hierarchical modules: struct vs interface in SystemVerilog

做~自己de王妃 提交于 2019-12-04 11:23:22
In SystemVerilog hierarchical modules can be connected by simple data types, complex data types (structs, unions, etc), or interfaces. The feature that I am interested in is aggregating all signals between two modules in one place which simplifies maintenance of the code. For example in the following one change s_point's definition without changing the declarations of m1, m2, and top: typedef struct { logic [7:0] x; logic [7:0] y; } s_point; // named structure module m1 (output s_point outPoint); // endmodule module m2 (input s_point inPoint); // endmodule module top (); s_point point; m1 m1