SharedDataBus constructor

SharedDataBus(
  1. LogicNet dataBusNet,
  2. Logic writeEnable,
  3. Logic clk,
  4. Logic reset, {
  5. required int dataWidth,
  6. String name = 'SharedDataBus',
})

Creates a SharedDataBus with a dataWidth-bit bidirectional port.

dataBusNet is the external LogicNet to connect. writeEnable controls bus direction: 1 = module drives bus, 0 = external drives bus (module reads). clk and reset provide synchronous storage.

Implementation

SharedDataBus(
  LogicNet dataBusNet,
  Logic writeEnable,
  Logic clk,
  Logic reset, {
  required this.dataWidth,
  super.name = 'SharedDataBus',
}) : super(definitionName: 'SharedDataBus') {
  final bus = addInOut('dataBus', dataBusNet, width: dataWidth);
  writeEnable = addInput('writeEnable', writeEnable);
  clk = addInput('clk', clk);
  reset = addInput('reset', reset);

  final storedValue = addOutput('storedValue', width: dataWidth);

  // Latch the bus value on clock edge when the external side is driving.
  storedValue <=
      flop(
        clk,
        bus,
        reset: reset,
        en: ~writeEnable,
        resetValue: Const(0, width: dataWidth),
      );

  // Drive the latched value back onto the bus when writeEnable is high.
  // TriStateBuffer drives its out (a LogicNet) with storedValue when
  // enabled; otherwise it outputs high-Z.  Joining out↔bus makes the
  // two nets share the same wire.
  TriStateBuffer(
    storedValue,
    enable: writeEnable,
    name: 'busDriver',
  ).out.gets(bus);
}