-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cores/time/timer: add a timer capable of multiple delays
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# 2024 - LambdaConcept - [email protected] | ||
|
||
from amaranth import * | ||
from amaranth.sim import * | ||
|
||
from ..cores.time.timer import * | ||
|
||
|
||
def test_timer(): | ||
cycles = 100 | ||
timer = WaitTimer(cycles) | ||
sim = Simulator(timer) | ||
|
||
def bench(): | ||
for i in range(15): | ||
yield | ||
yield timer.wait.eq(1) | ||
for i in range(200): | ||
yield | ||
expect = (i >= cycles) | ||
result = (yield timer.done) | ||
# print(result, expect) | ||
assert(result == expect) | ||
|
||
sim.add_clock(1e-6) | ||
sim.add_sync_process(bench) | ||
with sim.write_vcd("tests/test_time_timer.vcd"): | ||
sim.run() | ||
|
||
|
||
def test_ntimer(): | ||
cycles_1 = 100 | ||
cycles_2 = 200 | ||
timer = WaitNTimer([cycles_1, cycles_2]) | ||
sim = Simulator(timer) | ||
|
||
def bench(): | ||
for i in range(15): | ||
yield | ||
|
||
|
||
for i, cyc in enumerate(timer.ts): | ||
yield timer.wait[i].eq(1) | ||
for i in range(400): | ||
yield | ||
expect = (i >= cyc) | ||
result = (yield timer.done) | ||
# print(result, expect, cyc) | ||
assert(result == expect) | ||
|
||
yield timer.wait.eq(0) | ||
yield | ||
|
||
sim.add_clock(1e-6) | ||
sim.add_sync_process(bench) | ||
with sim.write_vcd("tests/test_time_timer.vcd"): | ||
sim.run() | ||
|
||
|
||
if __name__ == "__main__": | ||
test_timer(); print() | ||
test_ntimer(); print() |