BchIterativeEncoderCore<Input extends Logic, Output extends Logic> constructor
- required Logic clk,
- required Logic reset,
- required BchCode code,
- required Logic accept,
- required CodecFrame<
Input> inputFrame, - required CodecFrame<
Output> resultSchema, - StaticOrRuntimeParameter? consumeResult,
- String name = 'bch_iterative_encoder',
Creates a registered BCH encoder.
Implementation
BchIterativeEncoderCore({
required Logic clk,
required Logic reset,
required BchCode code,
required super.accept,
required super.inputFrame,
required super.resultSchema,
super.consumeResult,
super.name = 'bch_iterative_encoder',
}) : super(
definitionName: schemaQualifiedDefinitionName(
'BchIterativeEncoderCore_${code.configurationSignature}_',
[inputFrame, resultSchema],
),
) {
if (inputFrame.data.width != code.messageBits) {
throw PortWidthMismatchException(inputFrame.data, code.messageBits);
}
if (result.data.width != code.length) {
throw PortWidthMismatchException(result.data, code.length);
}
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
final processing = Logic(name: 'processing');
final outputValid = Logic(name: 'outputValid');
final exponentWidth = code.fullLength.bitLength;
final exponent = Logic(name: 'exponent', width: exponentWidth);
final remainder = Logic(name: 'remainder', width: code.fullLength);
final shiftedMessage =
Logic(name: 'shiftedMessage', width: code.fullLength);
final outputData = Logic(name: 'outputData', width: code.length);
final outputStart = Logic(name: 'outputStart');
final outputLast = Logic(name: 'outputLast');
final shiftedInput =
inputFrame.data.packed.zeroExtend(code.fullLength) << code.parityBits;
final generator = Const(
code.generatorPolynomial.coefficients,
width: code.fullLength,
);
final divisionRemainder = mux(remainder[exponent],
remainder ^ (generator << (exponent - code.parityBits)), remainder);
final completed =
processing & exponent.eq(Const(code.parityBits, width: exponentWidth));
final outputAccepted = outputValid & resultReady;
canAccept <= ~processing & ~outputValid;
resultValid <= outputValid;
connectPackedPayload(result.data, outputData);
result.start <= outputStart;
result.last <= outputLast;
Sequential(localClk, reset: localReset, resetValues: {
processing: 0,
outputValid: 0,
exponent: code.fullLength - 1,
}, [
If(outputAccepted, then: [
outputValid < 0,
]),
If(accepted, then: [
shiftedMessage < shiftedInput,
remainder < shiftedInput,
exponent < code.fullLength - 1,
outputStart < inputFrame.start,
outputLast < inputFrame.last,
processing < 1,
]),
If(processing, then: [
remainder < divisionRemainder,
If(completed, then: [
outputData <
(shiftedMessage | divisionRemainder).slice(code.length - 1, 0),
outputValid < 1,
processing < 0,
], orElse: [
exponent < exponent - 1,
]),
]),
]);
}