ScheduledDeserializerCore<LogicType extends Logic> constructor

ScheduledDeserializerCore<LogicType extends Logic>({
  1. required Logic clk,
  2. required Logic reset,
  3. required LogicType element,
  4. required Logic write,
  5. required Logic last,
  6. required Logic clear,
  7. required Logic release,
  8. required int length,
  9. int outputNumUnpackedDimensions = 0,
  10. String name = 'scheduled_deserializer_core',
  11. String? definitionName,
})

Creates a protocol-neutral deserializer core.

Implementation

ScheduledDeserializerCore({
  required Logic clk,
  required Logic reset,
  required LogicType element,
  required Logic write,
  required Logic last,
  required Logic clear,
  required Logic release,
  required this.length,
  this.outputNumUnpackedDimensions = 0,
  String name = 'scheduled_deserializer_core',
  String? definitionName,
}) : super(
        definitionName: definitionName ??
            'ScheduledDeserializerCore_L${length}_'
                'U${outputNumUnpackedDimensions}_'
                'P${serializationPayloadShapeIdentity(element)}',
        name: name,
      ) {
  if (length < 1) {
    throw ArgumentError.value(length, 'length', 'Must be at least one.');
  }
  if (outputNumUnpackedDimensions < 0 || outputNumUnpackedDimensions > 1) {
    throw ArgumentError.value(
      outputNumUnpackedDimensions,
      'outputNumUnpackedDimensions',
      'Must be zero or one for a one-dimensional output frame.',
    );
  }
  final localClk = addInput('clk', clk);
  final localReset = addInput('reset', reset);
  final localElement = addTypedInput<LogicType>('element', element);
  final localWrite = addInput('write', write);
  final localLast = addInput('last', last);
  final localClear = addInput('clear', clear);
  final localRelease = addInput('frameRelease', release);
  final localOutputOccupied = Logic(name: '${name}_output_occupied');
  final writeAccepted = Logic(name: '${name}_write_accepted');
  final inputCompleted = Logic(name: '${name}_input_completed');
  final frameReleased = Logic(name: '${name}_frame_released');

  final engine = ScheduledDeserializerEngine<LogicType>(
    clk: localClk,
    reset: localReset,
    element: localElement,
    write: writeAccepted,
    last: localLast,
    clear: localClear,
    length: length,
    definitionName: '${this.definitionName}_engine',
    name: '${name}_engine',
  );

  addOutput('canWrite') <=
      ~localClear & (~localOutputOccupied | frameReleased);
  writeAccepted <= localWrite & canWrite;
  inputCompleted <= writeAccepted & (localLast | engine.index.eq(length - 1));
  frameReleased <= localRelease & localOutputOccupied & ~localClear;

  LogicType elementClone({String? name}) =>
      localElement.cloneTyped(name: name);
  TypedLogicArray<LogicType, LogicValue> dataClone({String? name}) =>
      TypedLogicArray<LogicType, LogicValue>(
        [length],
        elementClone,
        name: name ?? '${this.name}_data',
        numUnpackedDimensions: outputNumUnpackedDimensions,
      );
  data = addTypedOutput<TypedLogicArray<LogicType, LogicValue>>(
    'data',
    dataClone,
  );
  bridgeTypedFrameLayout(
    source: engine.data,
    destination: data,
    name: '${name}_output_layout_bridge',
  );
  addOutput('index', width: engine.index.width) <= engine.index;
  addOutput('complete') <= engine.complete;
  addOutput('outputOccupied') <= localOutputOccupied;
  addOutput('writeAccepted') <= writeAccepted;
  addOutput('inputCompleted') <= inputCompleted;
  addOutput('frameReleased') <= frameReleased;

  Sequential(localClk, reset: localReset, resetValues: {
    localOutputOccupied: 0,
  }, [
    If(localClear, then: [
      localOutputOccupied < 0,
    ], orElse: [
      If(inputCompleted, then: [
        localOutputOccupied < 1,
      ], orElse: [
        If(frameReleased, then: [
          localOutputOccupied < 0,
        ]),
      ]),
    ]),
  ]);
}