ReadyValidReedSolomonEccAdapter<T extends Logic> constructor
- required ReedSolomonCode code,
- required int correctionCapacity,
- required ReadyValidInterface<
T> upstream, - required ReadyValidInterface<
T> downstream, - required Logic errorMask,
- String name = 'ready_valid_reed_solomon_ecc_adapter',
Creates a combinational Reed--Solomon reliability adapter.
Implementation
ReadyValidReedSolomonEccAdapter({
required ReedSolomonCode code,
required int correctionCapacity,
required ReadyValidInterface<T> upstream,
required ReadyValidInterface<T> downstream,
required Logic errorMask,
String name = 'ready_valid_reed_solomon_ecc_adapter',
}) : super(
definitionName: schemaQualifiedDefinitionName(
'ReadyValidReedSolomonEccAdapter_${code.configurationSignature}_'
'T${correctionCapacity}_',
[upstream.data, downstream.data],
),
name: name,
) {
final fieldWidth = code.field.degree;
final messageWidth = code.messageSymbols * fieldWidth;
final codewordWidth = code.length * fieldWidth;
if (upstream.data.width != messageWidth) {
throw PortWidthMismatchException(upstream.data, messageWidth);
}
if (downstream.data.width != messageWidth) {
throw PortWidthMismatchException(downstream.data, messageWidth);
}
if (!rohdPayloadsCompatible([upstream.data, downstream.data],
allowRenamedClones: true)) {
throw ArgumentError(
'Upstream and downstream payloads must be compatible.');
}
if (errorMask.width != codewordWidth) {
throw PortWidthMismatchException(errorMask, codewordWidth);
}
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 encoder = ReedSolomonEncoder(
this.upstream.data.packed,
code: code,
name: '${name}_tx',
);
final localErrorMask =
addInput('errorMask', errorMask, width: codewordWidth);
final injector = XorErrorInjector(
encoder.codeword,
localErrorMask,
name: '${name}_injector',
);
final decoder = ReedSolomonDecoder(
injector.result,
code: code,
correctionCapacity: correctionCapacity,
name: '${name}_rx',
);
this.upstream.ready <= this.downstream.ready;
this.downstream.valid <= this.upstream.valid;
connectPackedPayload(this.downstream.data, decoder.message);
decodeStatus = addTypedOutput(
'decodeStatus',
CodecDecodeStatus(iterationWidth: code.length.bitLength).clone,
);
decodeStatus.errorDetected <= decoder.errorDetected;
decodeStatus.corrected <= decoder.errorDetected & decoder.correctedValid;
decodeStatus.uncorrectable <= decoder.uncorrectable;
decodeStatus.frameDone <= this.downstream.valid;
decodeStatus.iterationCount <=
Const(
0,
width: decodeStatus.iterationCount.width,
);
}