Skip to content

Commit

Permalink
Adjust Memory Model to use previousValue for sampling (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorbel1 authored Sep 27, 2023
1 parent d0eb0b1 commit 2cda892
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
13 changes: 10 additions & 3 deletions lib/src/models/apb_bfm/abp_completer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,24 @@ class ApbCompleterAgent extends Agent {
final bool dropWriteDataOnError;

/// Creates a new model [ApbCompleterAgent].
///
/// If no [storage] is provided, it will use a default [SparseMemoryStorage].
ApbCompleterAgent(
{required this.intf,
required this.storage,
required Component parent,
MemoryStorage? storage,
this.selectIndex = 0,
this.responseDelay,
this.respondWithError,
this.invalidReadDataOnError = true,
this.dropWriteDataOnError = true,
String name = 'apbCompleter'})
: super(name, parent);
: storage = storage ??
SparseMemoryStorage(
addrWidth: intf.addrWidth,
dataWidth: intf.dataWidth,
),
super(name, parent);

@override
Future<void> run(Phase phase) async {
Expand All @@ -77,7 +84,7 @@ class ApbCompleterAgent extends Agent {
}

/// Calculates a strobed version of data.
LogicValue _strobeData(
static LogicValue _strobeData(
LogicValue originalData, LogicValue newData, LogicValue strobe) =>
[
for (var i = 0; i < strobe.width; i++)
Expand Down
16 changes: 9 additions & 7 deletions lib/src/models/memory_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,36 @@ class MemoryModel extends Memory {

// on posedge of clock, sample write ports and save to memory
clk.posedge.listen((event) {
if (reset.value == LogicValue.one) {
if (reset.previousValue == LogicValue.one) {
storage.reset();
return;
}
for (final wrPort in wrPorts) {
if (!wrPort.en.value.isValid && !storage.isEmpty) {
if (!(wrPort.en.previousValue?.isValid ?? wrPort.en.value.isValid) &&
!storage.isEmpty) {
// storage doesnt have access to `en`, so check ourselves
storage.invalidWrite();
return;
}

if (wrPort.en.value == LogicValue.one) {
final addrValue = wrPort.addr.value;
if (wrPort.en.previousValue == LogicValue.one) {
final addrValue = wrPort.addr.previousValue!;

if (wrPort is MaskedDataPortInterface) {
storage.writeData(
addrValue,
[
for (var index = 0; index < dataWidth ~/ 8; index++)
wrPort.mask.value[index].toBool()
? wrPort.data.value.getRange(index * 8, (index + 1) * 8)
wrPort.mask.previousValue![index].toBool()
? wrPort.data.previousValue!
.getRange(index * 8, (index + 1) * 8)
: storage
.readData(addrValue)
.getRange(index * 8, (index + 1) * 8)
].rswizzle(),
);
} else {
storage.writeData(addrValue, wrPort.data.value);
storage.writeData(addrValue, wrPort.data.previousValue!);
}
}
}
Expand Down

0 comments on commit 2cda892

Please sign in to comment.