Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue#137]: Add mechanism for reset all flop of Sequential #302

Merged
merged 21 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d71b57f
[issue#137]: Add mechanism for reset all flop of Sequential
RPG-coder-intc Mar 7, 2023
326f5ac
[issue#137] resetting flipflops for sequential via _Always constructor
RPG-coder-intc Mar 16, 2023
ca846e0
[issue#137] fixing reset arg for sequential and passing args to _always
RPG-coder-intc Mar 16, 2023
f086a4e
[issue#137] reordering args in _always
RPG-coder-intc Mar 16, 2023
a080a95
[issue#137] resolving override errors
RPG-coder-intc Mar 16, 2023
bf24cba
fix: resolving code conflict
RPG-coder-intc Mar 21, 2023
12fea90
Merge branch 'intel:main' into fix-issue-137
RPG-coder-intc Mar 21, 2023
c86e902
Merge branch 'intel:main' into fix-issue-137
RPG-coder-intc Apr 4, 2023
a229135
counter test for reset flipflops
RPG-coder-intc Apr 6, 2023
20127c2
resolving code_review
RPG-coder-intc Apr 6, 2023
94a99ea
transfering reset flipflop test cases to wintf
RPG-coder-intc Apr 13, 2023
d7f8ca6
[issue#137] resolving code reviews
RPG-coder-intc Apr 20, 2023
e4c4651
updating wintf tests for resetFlipflop
RPG-coder-intc Apr 20, 2023
48b9314
maintaining code quality
RPG-coder-intc Apr 20, 2023
fe7dc43
[issue-137] refining counter test
RPG-coder-intc Apr 20, 2023
ce86966
Merge branch 'intel:main' into fix-issue-137
RPG-coder-intc May 18, 2023
8e75df8
Resolving code reviews
RPG-coder-intc May 18, 2023
65bc5e3
Merge branch 'fix-issue-137' of https://github.com/RPG-coder-intc/roh…
RPG-coder-intc May 18, 2023
97c76d1
replace getReceiver() to receiver for perf boost
RPG-coder-intc May 18, 2023
f38e4d2
removing unused import
RPG-coder-intc May 18, 2023
9064935
removing unused class var
RPG-coder-intc May 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions lib/src/modules/conditional.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import 'package:rohd/src/utilities/uniquifier.dart';
/// Represents a block of logic, similar to `always` blocks in SystemVerilog.
abstract class _Always extends Module with CustomSystemVerilog {
/// A [List] of the [Conditional]s to execute.
final List<Conditional> conditionals;
late final List<Conditional> conditionals;

/// A mapping from internal receiver signals to designated [Module] outputs.
final Map<Logic, Logic> _assignedReceiverToOutputMap = {};
Expand All @@ -30,9 +30,41 @@ abstract class _Always extends Module with CustomSystemVerilog {

final Uniquifier _portUniquifier = Uniquifier();

_Always(this.conditionals, {super.name = 'always'}) {
/// Accepts [conditionals] and set maps receivers to output
RPG-coder-intc marked this conversation as resolved.
Show resolved Hide resolved
///
/// If [reset] is set then For a receiver assign default reset value
/// as `0` unless a reset value for is present [resetValues]
_Always(List<Conditional> conditionals,
RPG-coder-intc marked this conversation as resolved.
Show resolved Hide resolved
{Logic? reset, Map<Logic, dynamic>? resetValues, super.name = 'always'}) {
// create a registration of all inputs and outputs of this module
var idx = 0;

// Get all Receivers
final allReceivers =
RPG-coder-intc marked this conversation as resolved.
Show resolved Hide resolved
conditionals.map((e) => e.getReceivers()).expand((e) => e).toList();
mkorbel1 marked this conversation as resolved.
Show resolved Hide resolved

// This will reset the conditionals on setting the `reset` flag
if (reset != null) {
conditionals = [
If(
reset,
then: [
...allReceivers.map((rec) {
final driver = resetValues?[rec] ?? 0;
return rec < driver;
// If resetValue for a receiver is defined,
mkorbel1 marked this conversation as resolved.
Show resolved Hide resolved
// then use it for assigning receiver
// else assign zero as resetValue
})
],
orElse: conditionals,
),
];
}

// ignore: prefer_initializing_formals
this.conditionals = conditionals;
mkorbel1 marked this conversation as resolved.
Show resolved Hide resolved

for (final conditional in conditionals) {
for (final driver in conditional.getDrivers()) {
if (!_assignedDriverToInputMap.containsKey(driver)) {
Expand Down Expand Up @@ -267,15 +299,23 @@ class Sequential extends _Always {
/// The input clocks used in this block.
final List<Logic> _clks = [];

/// This sets the Sequential conditions to reset
mkorbel1 marked this conversation as resolved.
Show resolved Hide resolved
// ignore: overridden_fields
Logic? reset;

/// This sets a particular Sequential conditions receiver to resetValues
Map<Logic, dynamic>? resetValues = {};

/// Constructs a [Sequential] single-triggered by [clk].
Sequential(Logic clk, List<Conditional> conditionals,
{String name = 'sequential'})
: this.multi([clk], conditionals, name: name);
{Logic? reset, String name = 'sequential'})
RPG-coder-intc marked this conversation as resolved.
Show resolved Hide resolved
RPG-coder-intc marked this conversation as resolved.
Show resolved Hide resolved
: this.multi([clk], conditionals, name: name, reset: reset);

/// Constructs a [Sequential] multi-triggered by any of [clks].
Sequential.multi(List<Logic> clks, List<Conditional> conditionals,
{String name = 'sequential'})
: super(conditionals, name: name) {
{this.reset, this.resetValues, String name = 'sequential'})
mkorbel1 marked this conversation as resolved.
Show resolved Hide resolved
: super(conditionals,
name: name, reset: reset, resetValues: resetValues) {
for (var i = 0; i < clks.length; i++) {
final clk = clks[i];
if (clk.width > 1) {
Expand Down
50 changes: 50 additions & 0 deletions test/conditionals_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,35 @@ import 'package:rohd/src/exceptions/sim_compare/sim_compare_exceptions.dart';
import 'package:rohd/src/utilities/simcompare.dart';
import 'package:test/test.dart';

import 'counter_wintf_test.dart';

class ResetFlipflops extends Module {
mkorbel1 marked this conversation as resolved.
Show resolved Hide resolved
late final CounterInterface intf;
ResetFlipflops(CounterInterface intf) : super(name: 'shorthandmodule') {
this.intf = CounterInterface(intf.width)
..connectIO(this, intf,
inputTags: {CounterDirection.inward},
outputTags: {CounterDirection.outward});

// this should do nothing
this.intf.connectIO(this, intf);

_buildLogic();
}
void _buildLogic() {
final nextVal = Logic(name: 'nextVal', width: intf.width);

nextVal <= intf.val + 1;

Sequential(
SimpleClockGenerator(10).clk,
[
If(intf.en, then: [intf.val < nextVal])
],
reset: intf.reset);
}
}

class ShorthandAssignModule extends Module {
ShorthandAssignModule(
Logic preIncr, Logic preDecr, Logic mulAssign, Logic divAssign, Logic b)
Expand Down Expand Up @@ -594,4 +623,25 @@ void main() {
final simResult = SimCompare.iverilogVector(mod, vectors);
expect(simResult, equals(true));
});

test('resetFlipflop', () async {
mkorbel1 marked this conversation as resolved.
Show resolved Hide resolved
final mod = ResetFlipflops(CounterInterface(8));
await mod.build();
final vectors = [
Vector({'en': 0, 'reset': 1}, {}),
Vector({'en': 0, 'reset': 1}, {'val': 0}),
Vector({'en': 1, 'reset': 1}, {'val': 0}),
Vector({'en': 1, 'reset': 0}, {'val': 0}),
Vector({'en': 1, 'reset': 0}, {'val': 1}),
Vector({'en': 1, 'reset': 0}, {'val': 2}),
Vector({'en': 1, 'reset': 0}, {'val': 3}),
Vector({'en': 0, 'reset': 0}, {'val': 4}),
Vector({'en': 0, 'reset': 0}, {'val': 4}),
Vector({'en': 1, 'reset': 0}, {'val': 4}),
Vector({'en': 0, 'reset': 0}, {'val': 5}),
];
await SimCompare.checkFunctionalVector(mod, vectors);
final simResult = SimCompare.iverilogVector(mod, vectors);
expect(simResult, equals(true));
});
}