PrbsChecker constructor

PrbsChecker({
  1. required Logic clk,
  2. required Logic? reset,
  3. required Logic dataIn,
  4. required PrbsConfiguration configuration,
  5. int bitsPerCycle = 1,
  6. int lockThreshold = 4,
  7. int errorCountWidth = 32,
  8. Logic? clearErrors,
  9. Logic? enable,
  10. bool asyncReset = false,
  11. int radix = 2,
  12. String name = 'prbs_checker',
  13. bool reserveName = false,
  14. bool reserveDefinitionName = false,
  15. String? definitionName,
})

Creates a seed-aligned PRBS checker.

Implementation

PrbsChecker({
  required super.clk,
  required super.reset,
  required Logic dataIn,
  required this.configuration,
  int bitsPerCycle = 1,
  this.lockThreshold = 4,
  this.errorCountWidth = 32,
  Logic? clearErrors,
  Logic? enable,
  super.asyncReset,
  super.radix,
  super.name = 'prbs_checker',
  super.reserveName,
  super.reserveDefinitionName,
  String? definitionName,
}) : super(
        lfsrDescriptor: configuration.lfsrDescriptor,
        stepsPerCycle: bitsPerCycle,
        initialState: configuration.seed,
        enable: enable,
        definitionName: definitionName ??
            'PrbsChecker_${configuration.configurationSignature}_'
                'P${bitsPerCycle}_L${lockThreshold}_C${errorCountWidth}_'
                'R${radix}_A${asyncReset ? 1 : 0}_'
                'E${enable == null ? 0 : 1}_'
                'X${clearErrors == null ? 0 : 1}',
      ) {
  if (lockThreshold <= 0) {
    throw RohdHclException('PRBS lock threshold must be positive.');
  }
  if (errorCountWidth <= 0) {
    throw RohdHclException('PRBS error count width must be positive.');
  }
  if (dataIn.width != bitsPerCycle) {
    throw PortWidthMismatchException(dataIn, bitsPerCycle);
  }

  dataIn = addInput('data_in', dataIn, width: bitsPerCycle);
  if (clearErrors != null) {
    clearErrors = addInput('clear_errors', clearErrors);
  }

  final mismatchBits = addOutput('mismatch_bits', width: bitsPerCycle);
  final mismatch = addOutput('mismatch');
  final locked = addOutput('locked');
  final errorCount = addOutput('error_count', width: errorCountWidth);
  mismatchBits <= dataIn ^ expectedData;
  mismatch <= mismatchBits.or();

  final matchCountWidth = max(1, (lockThreshold + 1).log2Ceil);
  final mismatchCount = Count(mismatchBits).count;
  final localEnable = enable == null ? Const(1) : input('enable');
  final localClearErrors = clearErrors ?? Const(0);
  final matchAccumulator = Accumulator(
    Const(1),
    clk: input('clk'),
    reset: input('reset'),
    width: matchCountWidth,
    enable: localEnable & ~mismatch & ~locked,
    clear: localEnable & mismatch,
    asyncReset: asyncReset,
    name: 'matchAccumulator',
  );
  final matchCount = matchAccumulator.value;
  final errorAccumulator = Accumulator(
    mismatchCount,
    clk: input('clk'),
    reset: input('reset'),
    width: errorCountWidth,
    enable: localEnable & mismatch,
    clear: localClearErrors,
    saturates: true,
    asyncReset: asyncReset,
    name: 'errorAccumulator',
  );
  errorCount <= errorAccumulator.value;

  Sequential(
    input('clk'),
    reset: input('reset'),
    asyncReset: asyncReset,
    resetValues: {locked: 0},
    [
      If(localEnable, then: [
        If(mismatch, then: [
          locked < 0,
        ], orElse: [
          If(~locked, then: [
            If(matchCount.eq(lockThreshold - 1), then: [
              locked < 1,
            ]),
          ]),
        ]),
      ]),
    ],
  );
}