ReedSolomonCorrection constructor

ReedSolomonCorrection(
  1. Logic received,
  2. Logic magnitudes,
  3. Logic errorMask, {
  4. required ReedSolomonCode code,
  5. String name = 'reed_solomon_correction',
})

Creates a packed Reed--Solomon correction stage.

Implementation

ReedSolomonCorrection(
  Logic received,
  Logic magnitudes,
  Logic errorMask, {
  required ReedSolomonCode code,
  super.name = 'reed_solomon_correction',
}) : super(
        definitionName:
            'ReedSolomonCorrection_N${code.length}_K${code.messageSymbols}',
      ) {
  final width = code.field.degree;
  final packedWidth = code.length * width;
  if (received.width != packedWidth) {
    throw PortWidthMismatchException(received, packedWidth);
  }
  if (magnitudes.width != packedWidth) {
    throw PortWidthMismatchException(magnitudes, packedWidth);
  }
  if (errorMask.width != code.length) {
    throw PortWidthMismatchException(errorMask, code.length);
  }
  final localReceived = addInput('received', received, width: packedWidth);
  final localMagnitudes =
      addInput('magnitudes', magnitudes, width: packedWidth);
  final localMask = addInput('errorMask', errorMask, width: code.length);
  final correctedValue = localReceived ^ localMagnitudes;
  addOutput('corrected', width: packedWidth) <= correctedValue;
  addOutput('message', width: code.messageSymbols * width) <=
      correctedValue.slice(packedWidth - 1, code.paritySymbols * width);
  addOutput('valid') <= localMask.or();
}