Counter.upDown constructor

Counter.upDown({
  1. required Logic clk,
  2. required Logic reset,
  3. required Logic enableInc,
  4. required Logic enableDec,
  5. int by = 1,
  6. int minValue = 0,
  7. int? maxValue,
  8. int? width,
  9. Logic? restart,
  10. bool saturates = false,
  11. bool asyncReset = false,
  12. int resetValue = 0,
  13. String name = 'counter',
})

A simplified constructor for Counter that accepts a single fixed amount to count by along with much of the other available configuration in the default Counter constructor. And allows for both incrementing and decrementing the count.

Implementation

Counter.upDown({
  required Logic clk,
  required Logic reset,
  required Logic enableInc,
  required Logic enableDec,
  int by = 1,
  int minValue = 0,
  int? maxValue,
  int? width,
  Logic? restart,
  bool saturates = false,
  bool asyncReset = false,
  int resetValue = 0,
  String name = 'counter',
}) : this([
        SumInterface(
          width: width,
          fixedAmount: by,
          hasEnable: true,
        )..enable!.gets(enableInc),
        SumInterface(
            width: width, fixedAmount: by, hasEnable: true, increments: false)
          ..enable!.gets(enableDec),
      ],
          clk: clk,
          reset: reset,
          resetValue: resetValue,
          asyncReset: asyncReset,
          restart: restart,
          maxValue: maxValue,
          minValue: minValue,
          width: width,
          saturates: saturates,
          name: name);