// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// SECDED macros generated by
// util/design/secded_gen.py from util/design/data/secded_cfg.hjson

// This macro instantiates a secded decoder for the given _TYPE and _WIDTH.
// The instance will be named _INST, the data input connected to _ENC_DATA,
// and the data output, syndrome, and error connected to _DATA, _SYND, and
// _ERR respectively.
`define SECDED_INST_DEC(_TYPE, _WIDTH, _INST, _ENC_DATA, _DATA, _SYND, _ERR) \
  case (_TYPE)                                                               \
    prim_secded_pkg::SecdedHsiao: begin : gen_dec_hsiao                      \
      case (_WIDTH)                                                          \
        16: begin : gen_dec_hsiao_16                                         \
          prim_secded_22_16_dec _INST(                                       \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        22: begin : gen_dec_hsiao_22                                         \
          prim_secded_28_22_dec _INST(                                       \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        32: begin : gen_dec_hsiao_32                                         \
          prim_secded_39_32_dec _INST(                                       \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        57: begin : gen_dec_hsiao_57                                         \
          prim_secded_64_57_dec _INST(                                       \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        64: begin : gen_dec_hsiao_64                                         \
          prim_secded_72_64_dec _INST(                                       \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        default: begin : gen_dec_hsiao_default                               \
        end                                                                  \
      endcase                                                                \
    end                                                                      \
    prim_secded_pkg::SecdedHamming: begin : gen_dec_hamming                  \
      case (_WIDTH)                                                          \
        16: begin : gen_dec_hamming_16                                       \
          prim_secded_hamming_22_16_dec _INST(                               \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        32: begin : gen_dec_hamming_32                                       \
          prim_secded_hamming_39_32_dec _INST(                               \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        64: begin : gen_dec_hamming_64                                       \
          prim_secded_hamming_72_64_dec _INST(                               \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        68: begin : gen_dec_hamming_68                                       \
          prim_secded_hamming_76_68_dec _INST(                               \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        default: begin : gen_dec_hamming_default                             \
        end                                                                  \
      endcase                                                                \
    end                                                                      \
    prim_secded_pkg::SecdedInvHsiao: begin : gen_dec_inv_hsiao               \
      case (_WIDTH)                                                          \
        16: begin : gen_dec_inv_hsiao_16                                     \
          prim_secded_inv_22_16_dec _INST(                                   \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        22: begin : gen_dec_inv_hsiao_22                                     \
          prim_secded_inv_28_22_dec _INST(                                   \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        32: begin : gen_dec_inv_hsiao_32                                     \
          prim_secded_inv_39_32_dec _INST(                                   \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        57: begin : gen_dec_inv_hsiao_57                                     \
          prim_secded_inv_64_57_dec _INST(                                   \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        64: begin : gen_dec_inv_hsiao_64                                     \
          prim_secded_inv_72_64_dec _INST(                                   \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        default: begin : gen_dec_inv_hsiao_default                           \
        end                                                                  \
      endcase                                                                \
    end                                                                      \
    prim_secded_pkg::SecdedInvHamming: begin : gen_dec_inv_hamming           \
      case (_WIDTH)                                                          \
        16: begin : gen_dec_inv_hamming_16                                   \
          prim_secded_inv_hamming_22_16_dec _INST(                           \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        32: begin : gen_dec_inv_hamming_32                                   \
          prim_secded_inv_hamming_39_32_dec _INST(                           \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        64: begin : gen_dec_inv_hamming_64                                   \
          prim_secded_inv_hamming_72_64_dec _INST(                           \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        68: begin : gen_dec_inv_hamming_68                                   \
          prim_secded_inv_hamming_76_68_dec _INST(                           \
            .data_i(_ENC_DATA),                                              \
            .data_o(_DATA),                                                  \
            .syndrome_o(_SYND),                                              \
            .err_o(_ERR));                                                   \
        end                                                                  \
        default: begin : gen_dec_inv_hamming_default                         \
        end                                                                  \
      endcase                                                                \
    end                                                                      \
  endcase

// This macro instantiates a secded encoder for the given _TYPE and _WIDTH.
// The instance is named _INST, the data input connects to _DATA, and the
// data output connects to _ENC_DATA.
`define SECDED_INST_ENC(_TYPE, _WIDTH, _INST, _DATA, _ENC_DATA) \
  case (_TYPE)                                                  \
    prim_secded_pkg::SecdedHsiao: begin : gen_enc_hsiao         \
      case (_WIDTH)                                             \
        16: begin : gen_enc_hsiao_16                            \
          prim_secded_22_16_enc _INST(                          \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        22: begin : gen_enc_hsiao_22                            \
          prim_secded_28_22_enc _INST(                          \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        32: begin : gen_enc_hsiao_32                            \
          prim_secded_39_32_enc _INST(                          \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        57: begin : gen_enc_hsiao_57                            \
          prim_secded_64_57_enc _INST(                          \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        64: begin : gen_enc_hsiao_64                            \
          prim_secded_72_64_enc _INST(                          \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        default: begin : gen_enc_hsiao_default                  \
        end                                                     \
      endcase                                                   \
    end                                                         \
    prim_secded_pkg::SecdedHamming: begin : gen_enc_hamming     \
      case (_WIDTH)                                             \
        16: begin : gen_enc_hamming_16                          \
          prim_secded_hamming_22_16_enc _INST(                  \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        32: begin : gen_enc_hamming_32                          \
          prim_secded_hamming_39_32_enc _INST(                  \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        64: begin : gen_enc_hamming_64                          \
          prim_secded_hamming_72_64_enc _INST(                  \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        68: begin : gen_enc_hamming_68                          \
          prim_secded_hamming_76_68_enc _INST(                  \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        default: begin : gen_enc_hamming_default                \
        end                                                     \
      endcase                                                   \
    end                                                         \
    prim_secded_pkg::SecdedInvHsiao: begin : gen_enc_inv_hsiao  \
      case (_WIDTH)                                             \
        16: begin : gen_enc_inv_hsiao_16                        \
          prim_secded_inv_22_16_enc _INST(                      \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        22: begin : gen_enc_inv_hsiao_22                        \
          prim_secded_inv_28_22_enc _INST(                      \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        32: begin : gen_enc_inv_hsiao_32                        \
          prim_secded_inv_39_32_enc _INST(                      \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        57: begin : gen_enc_inv_hsiao_57                        \
          prim_secded_inv_64_57_enc _INST(                      \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        64: begin : gen_enc_inv_hsiao_64                        \
          prim_secded_inv_72_64_enc _INST(                      \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        default: begin : gen_enc_inv_hsiao_default              \
        end                                                     \
      endcase                                                   \
    end                                                         \
    prim_secded_pkg::SecdedInvHamming: begin : gen_enc_inv_hamming \
      case (_WIDTH)                                             \
        16: begin : gen_enc_inv_hamming_16                      \
          prim_secded_inv_hamming_22_16_enc _INST(              \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        32: begin : gen_enc_inv_hamming_32                      \
          prim_secded_inv_hamming_39_32_enc _INST(              \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        64: begin : gen_enc_inv_hamming_64                      \
          prim_secded_inv_hamming_72_64_enc _INST(              \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        68: begin : gen_enc_inv_hamming_68                      \
          prim_secded_inv_hamming_76_68_enc _INST(              \
            .data_i(_DATA),                                     \
            .data_o(_ENC_DATA));                                \
        end                                                     \
        default: begin : gen_enc_inv_hamming_default            \
        end                                                     \
      endcase                                                   \
    end                                                         \
  endcase
