ReedSolomonDecoder constructor
- Logic received, {
- required ReedSolomonCode code,
- required int correctionCapacity,
- String name = 'reed_solomon_decoder',
Creates a no-erasure combinational Reed--Solomon decoder.
Implementation
ReedSolomonDecoder(
Logic received, {
required ReedSolomonCode code,
required int correctionCapacity,
super.name = 'reed_solomon_decoder',
}) : super(
definitionName:
'ReedSolomonDecoder_N${code.length}_K${code.messageSymbols}_T'
'$correctionCapacity',
) {
if (correctionCapacity < 1) {
throw ArgumentError.value(correctionCapacity, 'correctionCapacity');
}
if (code.paritySymbols < correctionCapacity * 2) {
throw ArgumentError(
'The parity-symbol count must provide twice the correction capacity.',
);
}
final width = code.field.degree;
final packedWidth = code.length * width;
if (received.width != packedWidth) {
throw PortWidthMismatchException(received, packedWidth);
}
final localReceived = addInput('received', received, width: packedWidth);
final syndrome = ReedSolomonSyndromeCalculator(
localReceived,
code: code,
);
final locator = ReedSolomonBerlekampMassey(
syndrome.syndromes,
field: code.field,
correctionCapacity: correctionCapacity,
);
final chien = ReedSolomonChienSearch(
locator.locator,
locator.locatorDegree,
code: code,
correctionCapacity: correctionCapacity,
);
final magnitude = ReedSolomonForneyMagnitude(
locator.locator,
syndrome.syndromes,
chien.errorMask,
code: code,
correctionCapacity: correctionCapacity,
);
final correction = ReedSolomonCorrection(
localReceived,
magnitude.magnitudes,
chien.errorMask,
code: code,
);
addOutput('corrected', width: packedWidth) <= correction.corrected;
addOutput('message', width: code.messageSymbols * width) <=
correction.message;
addOutput('errorDetected') <= syndrome.syndromes.or();
final clean = ~syndrome.syndromes.or();
addOutput('correctedValid') <= (locator.valid & chien.valid) | clean;
addOutput('uncorrectable') <= locator.valid & chien.uncorrectable;
}