ScheduledFragmenterEngine<InputLogicType extends Logic, OutputLogicType extends Logic> constructor

ScheduledFragmenterEngine<InputLogicType extends Logic, OutputLogicType extends Logic>({
  1. required Logic clk,
  2. required Logic reset,
  3. required InputLogicType transaction,
  4. required Logic fragmentCount,
  5. required Logic load,
  6. required Logic advance,
  7. required Logic clear,
  8. required int maximumFragments,
  9. required FragmentPayloadGenerator<InputLogicType, OutputLogicType> fragmentGenerator,
  10. required String generatorName,
  11. String name = 'scheduled_fragmenter_engine',
})

Creates an explicitly scheduled typed fragmenter.

generatorName must be a stable SystemVerilog identifier unique to the generator's behavior and output schema.

Implementation

ScheduledFragmenterEngine({
  required Logic clk,
  required Logic reset,
  required InputLogicType transaction,
  required Logic fragmentCount,
  required Logic load,
  required Logic advance,
  required Logic clear,
  required this.maximumFragments,
  required FragmentPayloadGenerator<InputLogicType, OutputLogicType>
      fragmentGenerator,
  required String generatorName,
  String name = 'scheduled_fragmenter_engine',
}) : super(
        definitionName: 'ScheduledFragmenterEngine_M$maximumFragments'
            '_C${fragmentCount.width}_G${generatorName}_'
            '${payloadShapeIdentity(transaction)}',
        name: name,
      ) {
  if (maximumFragments < 1) {
    throw ArgumentError.value(
      maximumFragments,
      'maximumFragments',
      'Must be at least one.',
    );
  }
  if (!RegExp(r'^[A-Za-z][A-Za-z0-9_]*$').hasMatch(generatorName)) {
    throw ArgumentError.value(generatorName, 'generatorName',
        'Must be a valid SystemVerilog identifier fragment.');
  }
  final requiredCountWidth = widthFor(maximumFragments + 1);
  if (fragmentCount.width < requiredCountWidth) {
    throw ArgumentError.value(
      fragmentCount.width,
      'fragmentCount',
      'Must represent every count through $maximumFragments.',
    );
  }

  clk = addInput('clk', clk);
  reset = addInput('reset', reset);
  this.transaction = addTypedInput('transaction', transaction);
  this.fragmentCount = addInput(
    'fragmentCount',
    fragmentCount,
    width: fragmentCount.width,
  );
  this.load = addInput('load', load);
  this.advance = addInput('advance', advance);
  this.clear = addInput('clear', clear);
  addOutput('active');
  addOutput(
    'fragmentIndex',
    width: widthFor(maximumFragments),
  );
  addOutput('last');
  addOutput('invalidFragmentCount');

  final storedInput =
      this.transaction.cloneTyped(name: '${name}_stored_input');
  final storedCount = Logic(
    name: '${name}_stored_count',
    width: requiredCountWidth,
  );
  final countIsValid =
      this.fragmentCount.neq(0) & this.fragmentCount.lte(maximumFragments);
  final validLoad =
      (this.load & countIsValid & ~this.clear).named('${name}_valid_load');
  final localLast = active &
      fragmentIndex.eq(
        (storedCount - Const(1, width: storedCount.width))
            .getRange(0, fragmentIndex.width),
      );
  final generated = fragmentGenerator(storedInput, fragmentIndex);
  data = addTypedPayloadOutput(this, 'data', generated);

  data <= generated;
  last <= localLast;
  invalidFragmentCount <= this.load & ~countIsValid;

  Sequential(clk, reset: reset, resetValues: {
    active: 0,
    fragmentIndex: 0,
    storedCount: 0,
  }, [
    If(this.clear, then: [
      active < 0,
      fragmentIndex < 0,
      storedCount < 0,
    ], orElse: [
      If(validLoad, then: [
        storedInput < this.transaction,
        storedCount < this.fragmentCount.getRange(0, requiredCountWidth),
        fragmentIndex < 0,
        active < 1,
      ]),
      If(this.advance & active & ~validLoad, then: [
        If(localLast, then: [
          active < 0,
          fragmentIndex < 0,
        ], orElse: [
          fragmentIndex <
              fragmentIndex + Const(1, width: fragmentIndex.width),
        ]),
      ]),
    ]),
  ]);
}