ReedSolomonReadyValidDecoder<Input extends Logic, Output extends Logic> constructor

ReedSolomonReadyValidDecoder<Input extends Logic, Output extends Logic>({
  1. required ReedSolomonCode code,
  2. required int correctionCapacity,
  3. required ReadyValidCodecInterface<Input> upstream,
  4. required ReadyValidCodecInterface<Output> downstream,
  5. String name = 'reed_solomon_ready_valid_decoder',
})

Creates a framed ready/valid no-erasure RS decoder.

Implementation

ReedSolomonReadyValidDecoder({
  required ReedSolomonCode code,
  required int correctionCapacity,
  required ReadyValidCodecInterface<Input> upstream,
  required ReadyValidCodecInterface<Output> downstream,
  super.name = 'reed_solomon_ready_valid_decoder',
}) : super(
        definitionName: schemaQualifiedDefinitionName(
          'ReedSolomonReadyValidDecoder_${code.configurationSignature}_'
          'T${correctionCapacity}_',
          [upstream.data, downstream.data],
        ),
      ) {
  final width = code.field.degree;
  if (upstream.data.data.width != code.length * width) {
    throw PortWidthMismatchException(
      upstream.data.data,
      code.length * width,
    );
  }
  if (downstream.data.data.width != code.messageSymbols * width) {
    throw PortWidthMismatchException(
      downstream.data.data,
      code.messageSymbols * width,
    );
  }

  upstream.requireProviderComposableWith(downstream.contract,
      consumerName: name);
  this.upstream = addPairInterface(upstream, PairRole.consumer,
      uniquify: (original) => 'upstream_$original');
  this.downstream = addPairInterface(downstream, PairRole.provider,
      uniquify: (original) => 'downstream_$original');

  final decoder = ReedSolomonDecoder(
    this.upstream.data.data.packed,
    code: code,
    correctionCapacity: correctionCapacity,
  );
  this.upstream.ready <= this.downstream.ready;
  this.downstream.valid <= this.upstream.valid;
  connectPackedPayload(this.downstream.data.data, decoder.message);
  this.downstream.data.start <= this.upstream.data.start;
  this.downstream.data.last <= this.upstream.data.last;

  status = addTypedOutput(
    'status',
    CodecDecodeStatus(iterationWidth: code.length.bitLength).clone,
  );
  status.errorDetected <= decoder.errorDetected;
  status.corrected <= decoder.errorDetected & decoder.correctedValid;
  status.uncorrectable <= decoder.uncorrectable;
  status.frameDone <= this.downstream.data.last;
  status.iterationCount <= Const(0, width: status.iterationCount.width);
}