Fifo<LogicType extends Logic> constructor
- Logic clk,
- Logic reset, {
- required Logic writeEnable,
- required LogicType writeData,
- required Logic readEnable,
- required int depth,
- bool generateError = false,
- bool generateOccupancy = false,
- bool generateBypass = false,
- String name = 'fifo',
- bool reserveName = false,
- bool reserveDefinitionName = false,
- String? definitionName,
- 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();
}