ReedSolomonErasureDecoder constructor
Creates a fixed-count erasure-aware decoder.
Implementation
ReedSolomonErasureDecoder(
Logic received,
Logic erasureMask, {
required ReedSolomonCode code,
required int erasureCount,
required int unknownErrorCapacity,
super.name = 'reed_solomon_erasure_decoder',
}) : super(
definitionName: 'ReedSolomonErasureDecoder_N${code.length}_K'
'${code.messageSymbols}_E$erasureCount'
'_T$unknownErrorCapacity',
) {
if (erasureCount < 0 || unknownErrorCapacity < 0) {
throw ArgumentError('Decoder capacities cannot be negative.');
}
if (erasureCount + 2 * unknownErrorCapacity > code.paritySymbols) {
throw ArgumentError(
'The erasure and unknown-error capacities exceed the parity budget.',
);
}
final width = code.field.degree;
final packedWidth = code.length * width;
if (received.width != packedWidth) {
throw PortWidthMismatchException(received, packedWidth);
}
if (erasureMask.width != code.length) {
throw PortWidthMismatchException(erasureMask, code.length);
}
final localReceived = addInput('received', received, width: packedWidth);
final localMask = addInput('erasureMask', erasureMask, width: code.length);
final syndrome = ReedSolomonSyndromeCalculator(
localReceived,
code: code,
);
final erasureLocator = ReedSolomonErasureLocator(
localMask,
code: code,
erasureCount: erasureCount,
);
final modified = ReedSolomonModifiedSyndrome(
syndrome.syndromes,
erasureLocator.locator,
code: code,
erasureCount: erasureCount,
);
final errorLocator = ReedSolomonBerlekampMassey(
modified.modifiedSyndromes,
field: code.field,
correctionCapacity: unknownErrorCapacity,
);
final totalCapacity = erasureCount + unknownErrorCapacity;
final combined = ReedSolomonCombinedLocator(
erasureLocator.locator,
errorLocator.locator,
code: code,
erasureCount: erasureCount,
errorCapacity: unknownErrorCapacity,
);
final degreeWidth = max(
errorLocator.locatorDegree.width,
(totalCapacity + 1).bitLength,
);
final chien = ReedSolomonChienSearch(
combined.locator,
errorLocator.locatorDegree.zeroExtend(degreeWidth) +
Const(erasureCount, width: degreeWidth),
code: code,
correctionCapacity: totalCapacity,
);
final magnitude = ReedSolomonForneyMagnitude(
combined.locator,
syndrome.syndromes,
chien.errorMask,
code: code,
correctionCapacity: totalCapacity,
);
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') <= chien.errorMask.or();
addOutput('correctedValid') <= errorLocator.valid & chien.valid;
addOutput('uncorrectable') <= errorLocator.valid & chien.uncorrectable;
}