11import 'dart:async' ;
2- import 'dart:io' ;
32
43import 'package:rohd/rohd.dart' ;
54import 'package:rohd_hcl/rohd_hcl.dart' ;
@@ -14,8 +13,6 @@ void coreTest(
1413 Map <Register , int > regStates,
1514 RiverCore config, {
1615 Map <Register , int > initRegisters = const {},
17- int maxSimTime = 1200 ,
18- int cycleCount = 8 ,
1916 int nextPc = 4 ,
2017 int latency = 0 ,
2118}) async {
@@ -33,9 +30,7 @@ void coreTest(
3330 alignAddress: (addr) => addr,
3431 onInvalidRead: (addr, dataWidth) =>
3532 LogicValue .filled (dataWidth, LogicValue .zero),
36- )..loadMemString (memString);
37-
38- print (storage.getData (LogicValue .ofInt (0 , config.mxlen.size)));
33+ );
3934
4035 final mem = MemoryModel (
4136 clk,
@@ -46,8 +41,6 @@ void coreTest(
4641 storage: storage,
4742 );
4843
49- print (mem.storage.dumpMemString ());
50-
5144 final core = RiverCoreHDL (
5245 config,
5346 clk,
@@ -60,13 +53,9 @@ void coreTest(
6053
6154 await core.build ();
6255
63- WaveDumper (core, outputPath: 'waves_${config .mxlen .size }.vcd' );
64-
6556 reset.inject (1 );
6657 enable.inject (0 );
6758
68- //File('core_${config.mxlen.size}.sv').writeAsStringSync(core.generateSynth());
69-
7059 Simulator .registerAction (20 , () {
7160 reset.put (0 );
7261
@@ -77,21 +66,34 @@ void coreTest(
7766 );
7867 }
7968
69+ storage.loadMemString (memString);
70+
8071 enable.put (1 );
8172 });
8273
83- Simulator .setMaxSimTime (maxSimTime * ((latency ~ / 36 ) + 1 ));
8474 unawaited (Simulator .run ());
8575
86- for (var i = 0 ; i < cycleCount; i++ ) {
76+ await clk.nextPosedge;
77+
78+ while (reset.value.toBool ()) {
79+ await clk.nextPosedge;
80+ }
81+
82+ while (core.pipeline.nextPc.value.toInt () != nextPc) {
8783 await clk.nextPosedge;
8884 }
8985
90- await Simulator .simulationEnded ;
86+ await Simulator .endSimulation () ;
9187
9288 expect (core.pipeline.done.value.toBool (), isTrue);
9389 expect (core.pipeline.nextPc.value.toInt (), nextPc);
9490
91+ for (var i = 0 ; i < 32 ; i++ ) {
92+ final reg = Register .values[i];
93+ final value = core.regs.getData (LogicValue .ofInt (reg.value, 5 ))! .toInt ();
94+ print ('$reg : $value ' );
95+ }
96+
9597 for (final regState in regStates.entries) {
9698 expect (
9799 core.regs.getData (LogicValue .ofInt (regState.key.value, 5 ))! .toInt (),
@@ -111,12 +113,17 @@ void main() {
111113 () => coreTest (
112114 '''@${config .resetVector .toRadixString (16 )}
11311593 00 80 3E 13 81 00 7D 93 01 81 C1 13 82 01 83
114- 93 02 82 3E
116+ 93 02 82 3E 13 00 00 00
115117''' ,
116- {},
118+ {
119+ Register .x1: 0x3E8 ,
120+ Register .x2: 0xBB8 ,
121+ Register .x3: 0x7D0 ,
122+ Register .x4: 0 ,
123+ Register .x5: 0x3E8 ,
124+ },
117125 config,
118- // FIXME TODO: the memory isn't working correctly
119- nextPc: 2 ,
126+ nextPc: 0x1A ,
120127 ),
121128 );
122129 });
0 commit comments