Skip to content

Commit

Permalink
Merge pull request #31 from pulp-platform/min_ecc_function
Browse files Browse the repository at this point in the history
Add minimum ecc requirement function
  • Loading branch information
micprog authored Aug 19, 2024
2 parents 74749bd + 67a43c2 commit d924bd6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
8 changes: 3 additions & 5 deletions rtl/hsiao_ecc/hsiao_ecc_cor.sv
Original file line number Diff line number Diff line change
Expand Up @@ -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
) (
Expand All @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions rtl/hsiao_ecc/hsiao_ecc_dec.sv
Original file line number Diff line number Diff line change
Expand Up @@ -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
) (
Expand All @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions rtl/hsiao_ecc/hsiao_ecc_enc.sv
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@
// 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
) (
input logic [ DataWidth-1:0] in,
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);
Expand Down
4 changes: 4 additions & 0 deletions rtl/hsiao_ecc/hsiao_ecc_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d924bd6

Please sign in to comment.