Example of Constant Functions - Example of Constant Functions - 2022.2 English - UG901

Vivado Design Suite User Guide: Synthesis (UG901)

Document ID
UG901
Release Date
2022-11-16
Version
2022.2 English

Filename: functions_contant.v

// A function that computes and returns a constant value

//

// functions_constant.v

//

module functions_constant (clk, we, a, di, do);

parameter ADDRWIDTH = 8;

parameter DATAWIDTH = 4;

input clk;

input we;

input  [ADDRWIDTH-1:0] a;

input  [DATAWIDTH-1:0] di;

output [DATAWIDTH-1:0] do;

function integer getSize;

input addrwidth;

begin

getSize = 2**addrwidth;

end

endfunction

reg [DATAWIDTH-1:0] ram [getSize(ADDRWIDTH)-1:0];

always @(posedge clk) begin

if (we)

ram[a] <= di;

end

assign do = ram[a];

endmodule