Skip to content

Commit 7c1bde0

Browse files
committed
Deploying to main from @ amaranth-lang/amaranth@4d1c4fc 🚀
1 parent 4bbc5a7 commit 7c1bde0

File tree

166 files changed

+23160
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+23160
-0
lines changed

docs/amaranth/v0.4.5/.buildinfo

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: 65a4c9018945d5210bf5f45a5c4cbb89
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7
134 KB
Binary file not shown.
27.9 KB
Binary file not shown.
2.82 KB
Binary file not shown.
Binary file not shown.
3.12 KB
Binary file not shown.
48.1 KB
Binary file not shown.
27.4 KB
Binary file not shown.
205 KB
Binary file not shown.
3.27 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
28.3 KB
Binary file not shown.
8.05 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8.81 KB
Binary file not shown.

docs/amaranth/v0.4.5/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_build/
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from amaranth import *
2+
3+
4+
class LEDBlinker(Elaboratable):
5+
def elaborate(self, platform):
6+
m = Module()
7+
8+
led = platform.request("led")
9+
10+
half_freq = int(platform.default_clk_frequency // 2)
11+
timer = Signal(range(half_freq + 1))
12+
13+
with m.If(timer == half_freq):
14+
m.d.sync += led.eq(~led)
15+
m.d.sync += timer.eq(0)
16+
with m.Else():
17+
m.d.sync += timer.eq(timer + 1)
18+
19+
return m
20+
# --- BUILD ---
21+
from amaranth_boards.icestick import ICEStickPlatform
22+
23+
24+
ICEStickPlatform().build(LEDBlinker(), do_program=True)
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from amaranth import *
2+
3+
4+
class UpCounter(Elaboratable):
5+
"""
6+
A 16-bit up counter with a fixed limit.
7+
8+
Parameters
9+
----------
10+
limit : int
11+
The value at which the counter overflows.
12+
13+
Attributes
14+
----------
15+
en : Signal, in
16+
The counter is incremented if ``en`` is asserted, and retains
17+
its value otherwise.
18+
ovf : Signal, out
19+
``ovf`` is asserted when the counter reaches its limit.
20+
"""
21+
def __init__(self, limit):
22+
self.limit = limit
23+
24+
# Ports
25+
self.en = Signal()
26+
self.ovf = Signal()
27+
28+
# State
29+
self.count = Signal(16)
30+
31+
def elaborate(self, platform):
32+
m = Module()
33+
34+
m.d.comb += self.ovf.eq(self.count == self.limit)
35+
36+
with m.If(self.en):
37+
with m.If(self.ovf):
38+
m.d.sync += self.count.eq(0)
39+
with m.Else():
40+
m.d.sync += self.count.eq(self.count + 1)
41+
42+
return m
43+
# --- TEST ---
44+
from amaranth.sim import Simulator
45+
46+
47+
dut = UpCounter(25)
48+
def bench():
49+
# Disabled counter should not overflow.
50+
yield dut.en.eq(0)
51+
for _ in range(30):
52+
yield
53+
assert not (yield dut.ovf)
54+
55+
# Once enabled, the counter should overflow in 25 cycles.
56+
yield dut.en.eq(1)
57+
for _ in range(25):
58+
yield
59+
assert not (yield dut.ovf)
60+
yield
61+
assert (yield dut.ovf)
62+
63+
# The overflow should clear in one cycle.
64+
yield
65+
assert not (yield dut.ovf)
66+
67+
68+
sim = Simulator(dut)
69+
sim.add_clock(1e-6) # 1 MHz
70+
sim.add_sync_process(bench)
71+
with sim.write_vcd("up_counter.vcd"):
72+
sim.run()
73+
# --- CONVERT ---
74+
from amaranth.back import verilog
75+
76+
77+
top = UpCounter(25)
78+
with open("up_counter.v", "w") as f:
79+
f.write(verilog.convert(top, ports=[top.en, top.ovf]))
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
(* generator = "Amaranth" *)
2+
module top(clk, rst, en, ovf);
3+
(* src = "<amaranth-root>/amaranth/hdl/ir.py:526" *)
4+
input clk;
5+
(* src = "<amaranth-root>/amaranth/hdl/ir.py:526" *)
6+
input rst;
7+
(* src = "up_counter.py:26" *)
8+
input en;
9+
(* src = "up_counter.py:27" *)
10+
output ovf;
11+
(* src = "up_counter.py:30" *)
12+
reg [15:0] count = 16'h0000;
13+
(* src = "up_counter.py:30" *)
14+
reg [15:0] \count$next ;
15+
(* src = "up_counter.py:35" *)
16+
wire \$1 ;
17+
(* src = "up_counter.py:41" *)
18+
wire [16:0] \$3 ;
19+
(* src = "up_counter.py:41" *)
20+
wire [16:0] \$4 ;
21+
assign \$1 = count == (* src = "up_counter.py:35" *) 5'h19;
22+
assign \$4 = count + (* src = "up_counter.py:41" *) 1'h1;
23+
always @(posedge clk)
24+
count <= \count$next ;
25+
always @* begin
26+
\count$next = count;
27+
(* src = "up_counter.py:37" *)
28+
casez (en)
29+
/* src = "up_counter.py:37" */
30+
1'h1:
31+
(* src = "up_counter.py:38" *)
32+
casez (ovf)
33+
/* src = "up_counter.py:38" */
34+
1'h1:
35+
\count$next = 16'h0000;
36+
/* src = "up_counter.py:40" */
37+
default:
38+
\count$next = \$3 [15:0];
39+
endcase
40+
endcase
41+
(* src = "<amaranth-root>/amaranth/hdl/xfrm.py:518" *)
42+
casez (rst)
43+
1'h1:
44+
\count$next = 16'h0000;
45+
endcase
46+
end
47+
assign \$3 = \$4 ;
48+
assign ovf = \$1 ;
49+
endmodule
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from amaranth import *
2+
3+
4+
class UpCounter(Elaboratable):
5+
"""
6+
A 16-bit up counter with a fixed limit.
7+
8+
Parameters
9+
----------
10+
limit : int
11+
The value at which the counter overflows.
12+
13+
Attributes
14+
----------
15+
en : Signal, in
16+
The counter is incremented if ``en`` is asserted, and retains
17+
its value otherwise.
18+
ovf : Signal, out
19+
``ovf`` is asserted when the counter reaches its limit.
20+
"""
21+
def __init__(self, limit):
22+
self.limit = limit
23+
24+
# Ports
25+
self.en = Signal()
26+
self.ovf = Signal()
27+
28+
# State
29+
self.count = Signal(16)
30+
31+
def elaborate(self, platform):
32+
m = Module()
33+
34+
m.d.comb += self.ovf.eq(self.count == self.limit)
35+
36+
with m.If(self.en):
37+
with m.If(self.ovf):
38+
m.d.sync += self.count.eq(0)
39+
with m.Else():
40+
m.d.sync += self.count.eq(self.count + 1)
41+
42+
return m
43+
# --- TEST ---
44+
from amaranth.sim import Simulator
45+
46+
47+
dut = UpCounter(25)
48+
def bench():
49+
# Disabled counter should not overflow.
50+
yield dut.en.eq(0)
51+
for _ in range(30):
52+
yield
53+
assert not (yield dut.ovf)
54+
55+
# Once enabled, the counter should overflow in 25 cycles.
56+
yield dut.en.eq(1)
57+
for _ in range(25):
58+
yield
59+
assert not (yield dut.ovf)
60+
yield
61+
assert (yield dut.ovf)
62+
63+
# The overflow should clear in one cycle.
64+
yield
65+
assert not (yield dut.ovf)
66+
67+
68+
sim = Simulator(dut)
69+
sim.add_clock(1e-6) # 1 MHz
70+
sim.add_sync_process(bench)
71+
with sim.write_vcd("up_counter.vcd"):
72+
sim.run()
73+
# --- CONVERT ---
74+
from amaranth.back import verilog
75+
76+
77+
top = UpCounter(25)
78+
with open("up_counter.v", "w") as f:
79+
f.write(verilog.convert(top, ports=[top.en, top.ovf]))
Loading
Loading

0 commit comments

Comments
 (0)