Fifo<LogicType extends Logic> constructor

Fifo<LogicType extends Logic>(
  1. Logic clk,
  2. Logic reset, {
  3. required Logic writeEnable,
  4. required LogicType writeData,
  5. required Logic readEnable,
  6. required int depth,
  7. bool generateError = false,
  8. bool generateOccupancy = false,
  9. bool generateBypass = false,
  10. String name = 'fifo',
  11. bool reserveName = false,
  12. bool reserveDefinitionName = false,
  13. String? definitionName,
  14. List? initialValues,
})

Constructs a Fifo with RegisterFile-based storage.

If initialValues is provided, the Fifo will contain those values after reset. The length of initialValues must fit in the depth. The values may be either Logics or constants compatible with LogicValue.of.

Implementation

Fifo(Logic clk, Logic reset,
    {required Logic writeEnable,
    required LogicType writeData,
    required Logic readEnable,
    required this.depth,
    this.generateError = false,
    this.generateOccupancy = false,
    this.generateBypass = false,
    super.name = 'fifo',
    super.reserveName,
    super.reserveDefinitionName,
    String? definitionName,
    List<dynamic>? initialValues})
    : dataWidth = writeData.width,
      _addrWidth = max(1, log2Ceil(depth)),
      super(
          definitionName:
              definitionName ?? 'Fifo_D${depth}_W${writeData.width}') {
  if (depth <= 0) {
    throw RohdHclException('Depth must be at least 1.');
  }
  if (_addrWidth <= 0) {
    throw RohdHclException(
        'Assumption that address width is non-zero in implementation');
  }

  addInput('clk', clk);
  addInput('reset', reset);

  // set up read/write ports
  addInput('writeEnable', writeEnable);
  addTypedInput('writeData', writeData);
  addInput('readEnable', readEnable);
  readData = addTypedOutput(
      'readData', writeData.clone as LogicType Function({String? name}));

  // set up info ports
  addOutput('full');
  addOutput('empty');

  if (generateError) {
    addOutput('error');
  }

  if (generateOccupancy) {
    addOutput('occupancy', width: log2Ceil(depth + 1));
  }

  if (initialValues == null) {
    _initialValues = [];
  } else {
    if (initialValues.length > depth) {
      throw RohdHclException('Initial values length (${initialValues.length})'
          ' exceeds depth ($depth)');
    }

    _initialValues = initialValues
        .mapIndexed((i, e) => e is Logic
            ? addTypedInput('initialValue_$i', e)
            : Const(e, width: dataWidth))
        .toList();

    if (_initialValues.any((e) => e.width != dataWidth)) {
      throw RohdHclException('All initial values must have width of'
          ' $dataWidth, but found:'
          ' ${_initialValues.map((e) => e.width).toList()}');
    }
  }

  _buildLogic();
}