Skip to content

Commit e88ff13

Browse files
committed
docs/start: update to track changes in the language.
1 parent 8678d5f commit e88ff13

File tree

3 files changed

+50
-47
lines changed

3 files changed

+50
-47
lines changed

docs/_code/up_counter.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from amaranth import *
2+
from amaranth.lib import wiring
3+
from amaranth.lib.wiring import In, Out
24

35

4-
class UpCounter(Elaboratable):
6+
class UpCounter(wiring.Component):
57
"""
68
A 16-bit up counter with a fixed limit.
79
@@ -18,16 +20,16 @@ class UpCounter(Elaboratable):
1820
ovf : Signal, out
1921
``ovf`` is asserted when the counter reaches its limit.
2022
"""
21-
def __init__(self, limit):
22-
self.limit = limit
2323

24-
# Ports
25-
self.en = Signal()
26-
self.ovf = Signal()
24+
en: In(1)
25+
ovf: Out(1)
2726

28-
# State
27+
def __init__(self, limit):
28+
self.limit = limit
2929
self.count = Signal(16)
3030

31+
super().__init__()
32+
3133
def elaborate(self, platform):
3234
m = Module()
3335

@@ -76,4 +78,4 @@ def bench():
7678

7779
top = UpCounter(25)
7880
with open("up_counter.v", "w") as f:
79-
f.write(verilog.convert(top, ports=[top.en, top.ovf]))
81+
f.write(verilog.convert(top))

docs/_code/up_counter.v

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,49 @@
11
(* 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" *)
2+
module top(ovf, clk, rst, en);
3+
reg \$auto$verilog_backend.cc:2255:dump_module$1 = 0;
4+
(* src = "up_counter.py:36" *)
165
wire \$1 ;
17-
(* src = "up_counter.py:41" *)
6+
(* src = "up_counter.py:42" *)
187
wire [16:0] \$3 ;
19-
(* src = "up_counter.py:41" *)
8+
(* src = "up_counter.py:42" *)
209
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;
10+
(* src = "<site-packages>/amaranth/hdl/ir.py:509" *)
11+
input clk;
12+
wire clk;
13+
(* src = "up_counter.py:29" *)
14+
reg [15:0] count = 16'h0000;
15+
(* src = "up_counter.py:29" *)
16+
reg [15:0] \count$next ;
17+
(* src = "<site-packages>/amaranth/lib/wiring.py:1647" *)
18+
input en;
19+
wire en;
20+
(* src = "<site-packages>/amaranth/lib/wiring.py:1647" *)
21+
output ovf;
22+
wire ovf;
23+
(* src = "<site-packages>/amaranth/hdl/ir.py:509" *)
24+
input rst;
25+
wire rst;
26+
assign \$1 = count == (* src = "up_counter.py:36" *) 5'h19;
27+
assign \$4 = count + (* src = "up_counter.py:42" *) 1'h1;
2328
always @(posedge clk)
24-
count <= \count$next ;
29+
count <= \count$next ;
2530
always @* begin
31+
if (\$auto$verilog_backend.cc:2255:dump_module$1 ) begin end
2632
\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
33+
(* src = "up_counter.py:38" *)
34+
if (en) begin
35+
(* full_case = 32'd1 *)
36+
(* src = "up_counter.py:39" *)
37+
if (ovf) begin
38+
\count$next = 16'h0000;
39+
end else begin
40+
\count$next = \$4 [15:0];
41+
end
42+
end
43+
(* src = "<site-packages>/amaranth/hdl/xfrm.py:534" *)
44+
if (rst) begin
45+
\count$next = 16'h0000;
46+
end
4647
end
4748
assign \$3 = \$4 ;
4849
assign ovf = \$1 ;

docs/start.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ A 16-bit up counter with enable input, overflow output, and a limit fixed at des
2727
:lineno-match:
2828
:end-before: # --- TEST ---
2929

30-
The reusable building block of Amaranth designs is an ``Elaboratable``: a Python class that includes HDL signals (``en`` and ``ovf``, in this case) as a part of its interface, and provides the ``elaborate`` method that defines its behavior.
30+
The reusable building block of Amaranth designs is a ``Component``: a Python class declares its interface (``en`` and ``ovf``, in this case) and implements the ``elaborate`` method that defines its behavior.
3131

3232
.. TODO: link to Elaboratable reference
3333

0 commit comments

Comments
 (0)