BchTwoErrorDecoder constructor

BchTwoErrorDecoder(
  1. Logic codeword, {
  2. required BchCode code,
  3. String name = 'bch_two_error_decoder',
})

Creates a bounded two-error BCH decoder.

Implementation

BchTwoErrorDecoder(
  Logic codeword, {
  required BchCode code,
  super.name = 'bch_two_error_decoder',
}) : super(
        definitionName:
            'BchTwoErrorDecoder_N${code.length}_K${code.messageBits}',
      ) {
  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: 2,
  );
  final correction = BchCorrectionStage(
    localCodeword,
    locator.locator,
    locator.locatorDegree,
    code: code,
    correctionCapacity: 2,
  );
  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;
  addOutput('uncorrectable') <= detected & ~locator.valid;
}