From 67a43c202a854508b78df9c41564f46b29841afb Mon Sep 17 00:00:00 2001 From: Michael Rogenmoser Date: Sat, 18 May 2024 16:34:46 +0200 Subject: [PATCH] Add minimum ecc requirement function --- rtl/hsiao_ecc/hsiao_ecc_cor.sv | 8 +++----- rtl/hsiao_ecc/hsiao_ecc_dec.sv | 8 +++----- rtl/hsiao_ecc/hsiao_ecc_enc.sv | 8 +++----- rtl/hsiao_ecc/hsiao_ecc_pkg.sv | 4 ++++ 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/rtl/hsiao_ecc/hsiao_ecc_cor.sv b/rtl/hsiao_ecc/hsiao_ecc_cor.sv index d277e4ac..91d08fbe 100644 --- a/rtl/hsiao_ecc/hsiao_ecc_cor.sv +++ b/rtl/hsiao_ecc/hsiao_ecc_cor.sv @@ -11,9 +11,9 @@ // Hsiao ECC decoder // Based in part on work by lowRISC -module hsiao_ecc_cor #( +module hsiao_ecc_cor import hsiao_ecc_pkg::*; #( parameter int unsigned DataWidth = 32, - parameter int unsigned ProtWidth = $clog2(DataWidth)+2, + parameter int unsigned ProtWidth = min_ecc(DataWidth), parameter int unsigned TotalWidth = DataWidth + ProtWidth, parameter bit PrintHsiao = 1'b0 ) ( @@ -23,9 +23,7 @@ module hsiao_ecc_cor #( output logic [ 1:0] err_o ); - import hsiao_ecc_pkg::*; - - if (ProtWidth < $clog2(DataWidth)+2) $error("ProtWidth must be greater than $clog2(DataWidth)+2"); + if (ProtWidth < min_ecc(DataWidth)) $error("ProtWidth must be greater than $clog2(DataWidth)+2"); localparam bit [MaxParityWidth-1:0][ MaxTotalWidth-1:0] HsiaoCodes = hsiao_matrix(DataWidth, ProtWidth); diff --git a/rtl/hsiao_ecc/hsiao_ecc_dec.sv b/rtl/hsiao_ecc/hsiao_ecc_dec.sv index b2582d57..29200412 100644 --- a/rtl/hsiao_ecc/hsiao_ecc_dec.sv +++ b/rtl/hsiao_ecc/hsiao_ecc_dec.sv @@ -11,9 +11,9 @@ // Hsiao ECC decoder // Based in part on work by lowRISC -module hsiao_ecc_dec #( +module hsiao_ecc_dec import hsiao_ecc_pkg::*; #( parameter int unsigned DataWidth = 32, - parameter int unsigned ProtWidth = $clog2(DataWidth)+2, + parameter int unsigned ProtWidth = min_ecc(DataWidth), parameter int unsigned TotalWidth = DataWidth + ProtWidth, parameter bit PrintHsiao = 1'b0 ) ( @@ -23,9 +23,7 @@ module hsiao_ecc_dec #( output logic [ 1:0] err_o ); - import hsiao_ecc_pkg::*; - - if (ProtWidth < $clog2(DataWidth)+2) $error("ProtWidth must be greater than $clog2(DataWidth)+2"); + if (ProtWidth < min_ecc(DataWidth)) $error("ProtWidth must be greater than $clog2(DataWidth)+2"); localparam bit [MaxParityWidth-1:0][ MaxTotalWidth-1:0] HsiaoCodes = hsiao_matrix(DataWidth, ProtWidth); diff --git a/rtl/hsiao_ecc/hsiao_ecc_enc.sv b/rtl/hsiao_ecc/hsiao_ecc_enc.sv index ea48a843..3f93e6d2 100644 --- a/rtl/hsiao_ecc/hsiao_ecc_enc.sv +++ b/rtl/hsiao_ecc/hsiao_ecc_enc.sv @@ -11,9 +11,9 @@ // Hsiao ECC encoder // Based in part on work by lowRISC -module hsiao_ecc_enc #( +module hsiao_ecc_enc import hsiao_ecc_pkg::*; #( parameter int unsigned DataWidth = 32, - parameter int unsigned ProtWidth = $clog2(DataWidth)+2, + parameter int unsigned ProtWidth = min_ecc(DataWidth), parameter int unsigned TotalWidth = DataWidth + ProtWidth, parameter bit PrintHsiao = 1'b0 ) ( @@ -21,9 +21,7 @@ module hsiao_ecc_enc #( output logic [TotalWidth-1:0] out ); - import hsiao_ecc_pkg::*; - - if (ProtWidth < $clog2(DataWidth)+2) $error("ProtWidth must be greater than $clog2(DataWidth)+2"); + if (ProtWidth < min_ecc(DataWidth)) $error("ProtWidth must be greater than $clog2(DataWidth)+2"); localparam bit [MaxParityWidth-1:0][MaxTotalWidth-1:0] HsiaoCodes = hsiao_matrix(DataWidth, ProtWidth); diff --git a/rtl/hsiao_ecc/hsiao_ecc_pkg.sv b/rtl/hsiao_ecc/hsiao_ecc_pkg.sv index e1c655e1..b2efdfac 100644 --- a/rtl/hsiao_ecc/hsiao_ecc_pkg.sv +++ b/rtl/hsiao_ecc/hsiao_ecc_pkg.sv @@ -13,6 +13,10 @@ package hsiao_ecc_pkg; + function automatic int unsigned min_ecc(int unsigned data_width); + min_ecc = $clog2(data_width)+2; + endfunction + /// Static parameters for synthesizability (avoiding dynamic arrays) /// Maximum reasonable Data Width localparam int unsigned MaxDataWidth = 1024;