CoeffBank constructor

CoeffBank(
  1. Logic tapIndex,
  2. LogicArray coefficients, {
  3. required int numTaps,
  4. required int dataWidth,
  5. String name = 'CoeffBank',
})

Creates a CoeffBank with numTaps taps at dataWidth bits.

coefficients is a LogicArray with one element per tap — registered as an input port via addInputArray. tapIndex selects the active coefficient.

Implementation

CoeffBank(
  Logic tapIndex,
  LogicArray coefficients, {
  required this.numTaps,
  required this.dataWidth,
  super.name = 'CoeffBank',
}) : super(definitionName: 'CoeffBank_T${numTaps}_W$dataWidth') {
  // Register ports
  tapIndex = addInput('tapIndex', tapIndex, width: tapIndex.width);
  final coeffArray = addInputArray(
    'coeffArray',
    coefficients,
    dimensions: [numTaps],
    elementWidth: dataWidth,
  );
  final coeffOut = addOutput('coeffOut', width: dataWidth);

  // Mux-chain ROM: priority-select coefficient by tap index.
  Logic selected = Const(0, width: dataWidth);
  for (var i = numTaps - 1; i >= 0; i--) {
    selected = mux(
      tapIndex.eq(Const(i, width: tapIndex.width)).named('tapMatch$i'),
      coeffArray.elements[i],
      selected,
    );
  }
  coeffOut <= selected;
}