ReadyValidFragmenter<InputLogicType extends Logic, OutputLogicType extends Logic> constructor

ReadyValidFragmenter<InputLogicType extends Logic, OutputLogicType extends Logic>({
  1. required Logic clk,
  2. required Logic reset,
  3. required ReadyValidInterface<InputLogicType> upstream,
  4. required ReadyValidInterface<Frame<OutputLogicType>> downstream,
  5. required Logic fragmentCount,
  6. required int maximumFragments,
  7. required ReadyValidFragmentPayloadGenerator<InputLogicType, OutputLogicType> fragmentGenerator,
  8. required String generatorName,
  9. String name = 'ready_valid_fragmenter',
})

Creates a semantic typed fragmenter.

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

Implementation

ReadyValidFragmenter({
  required Logic clk,
  required Logic reset,
  required ReadyValidInterface<InputLogicType> upstream,
  required ReadyValidInterface<Frame<OutputLogicType>> downstream,
  required Logic fragmentCount,
  required this.maximumFragments,
  required ReadyValidFragmentPayloadGenerator<InputLogicType, OutputLogicType>
      fragmentGenerator,
  required String generatorName,
  String name = 'ready_valid_fragmenter',
}) : super(
        definitionName: 'ReadyValidFragmenter_M${maximumFragments}_'
            'C${fragmentCount.width}_G${generatorName}_'
            '${payloadShapesIdentity([upstream.data, downstream.data])}',
        name: name,
      ) {
  if (maximumFragments < 1) {
    throw ArgumentError.value(
      maximumFragments,
      'maximumFragments',
      'Must be at least one.',
    );
  }
  final requiredCountWidth = widthFor(maximumFragments + 1);
  if (fragmentCount.width < requiredCountWidth) {
    throw ArgumentError.value(
      fragmentCount.width,
      'fragmentCount',
      'Must represent every count through $maximumFragments.',
    );
  }

  final localClk = addInput('clk', clk);
  final localReset = addInput('reset', reset);
  final localFragmentCount = addInput(
    'fragmentCount',
    fragmentCount,
    width: fragmentCount.width,
  );
  addOutput('active');
  addOutput(
    'fragmentIndex',
    width: widthFor(maximumFragments),
  );
  addOutput('invalidFragmentCount');
  _upstream = addPairInterface(
    upstream,
    PairRole.consumer,
    uniquify: (original) => 'upstream_$original',
  );
  _downstream = addPairInterfaceFrom(
    IrrevocableReadyValidInterface<Frame<OutputLogicType>>(
      downstream.data.cloneTyped(),
    ),
    downstream,
    PairRole.provider,
    uniquify: (original) => 'downstream_$original',
  );

  final inputAccepted = Logic(name: '${name}_input_accepted');
  final outputAccepted = Logic(name: '${name}_output_accepted');
  final input = cloneTypedPayload(_upstream.data, name: '${name}_input');
  final core = ScheduledFragmenterEngine<InputLogicType, OutputLogicType>(
    clk: localClk,
    reset: localReset,
    transaction: input,
    fragmentCount: localFragmentCount,
    load: inputAccepted,
    advance: outputAccepted,
    clear: Const(0),
    maximumFragments: maximumFragments,
    fragmentGenerator: fragmentGenerator,
    generatorName: generatorName,
    name: '${name}_core',
  );
  if (!rohdPayloadsCompatible([core.data, _downstream.data.data],
      ignoreConstantNames: true)) {
    throw ArgumentError('Generated and output fragment payloads must match.');
  }

  ReadyValidIngressAttachmentPolicy<InputLogicType>(
    supportsSameCycleReplacement: true,
  ).attach(
    upstream: _upstream,
    canAccept: ~core.active | (outputAccepted & core.last),
    accept: inputAccepted,
    payload: input,
  );
  final offer = cloneTypedPayload(_downstream.data, name: '${name}_offer');
  offer.data <= core.data;
  offer.last <= core.last;
  ReadyValidEgressAttachmentPolicy<Frame<OutputLogicType>>().attach(
    downstream: _downstream,
    offerValid: core.active,
    payload: offer,
    transfer: outputAccepted,
  );
  active <= core.active;
  fragmentIndex <= core.fragmentIndex;
  invalidFragmentCount <= core.invalidFragmentCount;
}