BchGeneralDecoder constructor

BchGeneralDecoder(
  1. Logic codeword, {
  2. required BchCode code,
  3. required int correctionCapacity,
  4. String name = 'bch_general_decoder',
})

Creates a capacity-parameterized combinational BCH decoder.

Implementation

BchGeneralDecoder(
  Logic codeword, {
  required BchCode code,
  required int correctionCapacity,
  super.name = 'bch_general_decoder',
}) : super(
        definitionName:
            'BchGeneralDecoder_N${code.length}_K${code.messageBits}_T'
            '$correctionCapacity',
      ) {
  if (correctionCapacity < 1) {
    throw ArgumentError.value(correctionCapacity, 'correctionCapacity');
  }
  if (code.designedDistance - 1 < correctionCapacity * 2) {
    throw ArgumentError(
      'BCH designed distance must provide twice the correction capacity '
      'in consecutive syndromes.',
    );
  }
  if (codeword.width != code.length) {
    throw PortWidthMismatchException(codeword, code.length);
  }
  final localCodeword = addInput('codeword', codeword, width: code.length);
  final syndromeCalculator = BchSyndromeCalculator(localCodeword, code: code);
  final locator = BchBerlekampMassey(
    syndromeCalculator.syndromes,
    code: code,
    correctionCapacity: correctionCapacity,
  );
  final correction = BchCorrectionStage(
    localCodeword,
    locator.locator,
    locator.locatorDegree,
    code: code,
    correctionCapacity: correctionCapacity,
  );
  final detected = syndromeCalculator.syndromes.or();

  addOutput('correctedCodeword', width: code.length) <=
      correction.correctedCodeword;
  addOutput('message', width: code.messageBits) <= correction.message;
  addOutput('errorDetected') <= detected;
  addOutput('corrected') <= detected & locator.valid & correction.valid;
  addOutput('uncorrectable') <=
      detected & (~locator.valid | correction.uncorrectable);
}