-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gated counter and toggle gate (#111)
- Loading branch information
Showing
22 changed files
with
1,595 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ tmp* | |
confapp/.vscode/* | ||
*tracker.json | ||
*tracker.log | ||
devtools_options.yaml | ||
*.sv | ||
|
||
# Exceptions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Toggle Gate | ||
|
||
The `ToggleGate` component is intended to help save power by avoiding unnecessary toggles through combinational logic. It accomplishes this by flopping the previous value of data and muxing the previous value to the `gatedData` output if the `enable` is low. By default, the flops within the `ToggleGate` are also clock gated for extra power savings, but it can be controlled via a `ClockGateControlInterface`. | ||
|
||
As an example use case, if you have a large arithmetic unit but only care about the result when a `valid` bit is high, you could use a `ToggleGate` so that the inputs to that combinational logic do not change unless `valid` is high. | ||
|
||
```dart | ||
final toggleGate = ToggleGate( | ||
clk: clk, | ||
reset: reset, | ||
enable: arithmeticDataValid, | ||
data: arithmeticData, | ||
); | ||
BigArithmeticUnit(dataIn: toggleGate.gatedData); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
// 2024 August 26 | ||
// Author: Max Korbel <[email protected]> | ||
|
||
import 'package:meta/meta.dart'; | ||
import 'package:rohd/rohd.dart'; | ||
import 'package:rohd_hcl/rohd_hcl.dart'; | ||
import 'package:rohd_hcl/src/summation/summation_base.dart'; | ||
|
@@ -17,6 +18,19 @@ class Counter extends SummationBase { | |
/// The output value of the counter. | ||
Logic get count => output('count'); | ||
|
||
/// The main clock signal. | ||
@visibleForTesting | ||
@protected | ||
late final Logic clk; | ||
|
||
/// The reset signal. | ||
@protected | ||
late final Logic reset; | ||
|
||
/// The restart signal. | ||
@protected | ||
late final Logic? restart; | ||
|
||
/// Creates a counter that increments according to the provided [interfaces]. | ||
/// | ||
/// The [width] can be either explicitly provided or inferred from other | ||
|
@@ -50,39 +64,54 @@ class Counter extends SummationBase { | |
super.saturates, | ||
super.name = 'counter', | ||
}) : super(initialValue: resetValue) { | ||
clk = addInput('clk', clk); | ||
reset = addInput('reset', reset); | ||
this.clk = addInput('clk', clk); | ||
this.reset = addInput('reset', reset); | ||
|
||
if (restart != null) { | ||
restart = addInput('restart', restart); | ||
this.restart = addInput('restart', restart); | ||
} else { | ||
this.restart = null; | ||
} | ||
|
||
addOutput('count', width: width); | ||
|
||
final sum = Sum( | ||
interfaces, | ||
initialValue: | ||
restart != null ? mux(restart, initialValueLogic, count) : count, | ||
maxValue: maxValueLogic, | ||
minValue: minValueLogic, | ||
width: width, | ||
saturates: saturates, | ||
); | ||
_buildLogic(); | ||
} | ||
|
||
/// The internal [Sum] that is used to keep track of the count. | ||
@protected | ||
late final Sum summer = Sum( | ||
interfaces, | ||
initialValue: | ||
restart != null ? mux(restart!, initialValueLogic, count) : count, | ||
maxValue: maxValueLogic, | ||
minValue: minValueLogic, | ||
width: width, | ||
saturates: saturates, | ||
); | ||
|
||
/// Builds the internal logic for the counter. | ||
void _buildLogic() { | ||
buildFlops(); | ||
|
||
// need to flop these since value is flopped | ||
overflowed <= flop(clk, summer.overflowed, reset: reset); | ||
underflowed <= flop(clk, summer.underflowed, reset: reset); | ||
|
||
equalsMax <= count.eq(maxValueLogic); | ||
equalsMin <= count.eq(minValueLogic); | ||
} | ||
|
||
/// Builds the flops that store the [count]. | ||
@protected | ||
void buildFlops() { | ||
count <= | ||
flop( | ||
clk, | ||
sum.sum, | ||
summer.sum, | ||
reset: reset, | ||
resetValue: initialValueLogic, | ||
); | ||
|
||
// need to flop these since value is flopped | ||
overflowed <= flop(clk, sum.overflowed, reset: reset); | ||
underflowed <= flop(clk, sum.underflowed, reset: reset); | ||
|
||
equalsMax <= count.eq(maxValueLogic); | ||
equalsMin <= count.eq(minValueLogic); | ||
} | ||
|
||
/// A simplified constructor for [Counter] that accepts a single fixed amount | ||
|
Oops, something went wrong.