docs/start: update to track changes in the language.
This commit is contained in:
parent
8678d5fa14
commit
e88ff1335e
|
@ -1,7 +1,9 @@
|
||||||
from amaranth import *
|
from amaranth import *
|
||||||
|
from amaranth.lib import wiring
|
||||||
|
from amaranth.lib.wiring import In, Out
|
||||||
|
|
||||||
|
|
||||||
class UpCounter(Elaboratable):
|
class UpCounter(wiring.Component):
|
||||||
"""
|
"""
|
||||||
A 16-bit up counter with a fixed limit.
|
A 16-bit up counter with a fixed limit.
|
||||||
|
|
||||||
|
@ -18,16 +20,16 @@ class UpCounter(Elaboratable):
|
||||||
ovf : Signal, out
|
ovf : Signal, out
|
||||||
``ovf`` is asserted when the counter reaches its limit.
|
``ovf`` is asserted when the counter reaches its limit.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
en: In(1)
|
||||||
|
ovf: Out(1)
|
||||||
|
|
||||||
def __init__(self, limit):
|
def __init__(self, limit):
|
||||||
self.limit = limit
|
self.limit = limit
|
||||||
|
|
||||||
# Ports
|
|
||||||
self.en = Signal()
|
|
||||||
self.ovf = Signal()
|
|
||||||
|
|
||||||
# State
|
|
||||||
self.count = Signal(16)
|
self.count = Signal(16)
|
||||||
|
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
def elaborate(self, platform):
|
def elaborate(self, platform):
|
||||||
m = Module()
|
m = Module()
|
||||||
|
|
||||||
|
@ -76,4 +78,4 @@ from amaranth.back import verilog
|
||||||
|
|
||||||
top = UpCounter(25)
|
top = UpCounter(25)
|
||||||
with open("up_counter.v", "w") as f:
|
with open("up_counter.v", "w") as f:
|
||||||
f.write(verilog.convert(top, ports=[top.en, top.ovf]))
|
f.write(verilog.convert(top))
|
||||||
|
|
|
@ -1,48 +1,49 @@
|
||||||
(* generator = "Amaranth" *)
|
(* generator = "Amaranth" *)
|
||||||
module top(clk, rst, en, ovf);
|
module top(ovf, clk, rst, en);
|
||||||
(* src = "<amaranth-root>/amaranth/hdl/ir.py:526" *)
|
reg \$auto$verilog_backend.cc:2255:dump_module$1 = 0;
|
||||||
input clk;
|
(* src = "up_counter.py:36" *)
|
||||||
(* src = "<amaranth-root>/amaranth/hdl/ir.py:526" *)
|
|
||||||
input rst;
|
|
||||||
(* src = "up_counter.py:26" *)
|
|
||||||
input en;
|
|
||||||
(* src = "up_counter.py:27" *)
|
|
||||||
output ovf;
|
|
||||||
(* src = "up_counter.py:30" *)
|
|
||||||
reg [15:0] count = 16'h0000;
|
|
||||||
(* src = "up_counter.py:30" *)
|
|
||||||
reg [15:0] \count$next ;
|
|
||||||
(* src = "up_counter.py:35" *)
|
|
||||||
wire \$1 ;
|
wire \$1 ;
|
||||||
(* src = "up_counter.py:41" *)
|
(* src = "up_counter.py:42" *)
|
||||||
wire [16:0] \$3 ;
|
wire [16:0] \$3 ;
|
||||||
(* src = "up_counter.py:41" *)
|
(* src = "up_counter.py:42" *)
|
||||||
wire [16:0] \$4 ;
|
wire [16:0] \$4 ;
|
||||||
assign \$1 = count == (* src = "up_counter.py:35" *) 5'h19;
|
(* src = "<site-packages>/amaranth/hdl/ir.py:509" *)
|
||||||
assign \$4 = count + (* src = "up_counter.py:41" *) 1'h1;
|
input clk;
|
||||||
|
wire clk;
|
||||||
|
(* src = "up_counter.py:29" *)
|
||||||
|
reg [15:0] count = 16'h0000;
|
||||||
|
(* src = "up_counter.py:29" *)
|
||||||
|
reg [15:0] \count$next ;
|
||||||
|
(* src = "<site-packages>/amaranth/lib/wiring.py:1647" *)
|
||||||
|
input en;
|
||||||
|
wire en;
|
||||||
|
(* src = "<site-packages>/amaranth/lib/wiring.py:1647" *)
|
||||||
|
output ovf;
|
||||||
|
wire ovf;
|
||||||
|
(* src = "<site-packages>/amaranth/hdl/ir.py:509" *)
|
||||||
|
input rst;
|
||||||
|
wire rst;
|
||||||
|
assign \$1 = count == (* src = "up_counter.py:36" *) 5'h19;
|
||||||
|
assign \$4 = count + (* src = "up_counter.py:42" *) 1'h1;
|
||||||
always @(posedge clk)
|
always @(posedge clk)
|
||||||
count <= \count$next ;
|
count <= \count$next ;
|
||||||
always @* begin
|
always @* begin
|
||||||
|
if (\$auto$verilog_backend.cc:2255:dump_module$1 ) begin end
|
||||||
\count$next = count;
|
\count$next = count;
|
||||||
(* src = "up_counter.py:37" *)
|
(* src = "up_counter.py:38" *)
|
||||||
casez (en)
|
if (en) begin
|
||||||
/* src = "up_counter.py:37" */
|
(* full_case = 32'd1 *)
|
||||||
1'h1:
|
(* src = "up_counter.py:39" *)
|
||||||
(* src = "up_counter.py:38" *)
|
if (ovf) begin
|
||||||
casez (ovf)
|
\count$next = 16'h0000;
|
||||||
/* src = "up_counter.py:38" */
|
end else begin
|
||||||
1'h1:
|
\count$next = \$4 [15:0];
|
||||||
\count$next = 16'h0000;
|
end
|
||||||
/* src = "up_counter.py:40" */
|
end
|
||||||
default:
|
(* src = "<site-packages>/amaranth/hdl/xfrm.py:534" *)
|
||||||
\count$next = \$3 [15:0];
|
if (rst) begin
|
||||||
endcase
|
\count$next = 16'h0000;
|
||||||
endcase
|
end
|
||||||
(* src = "<amaranth-root>/amaranth/hdl/xfrm.py:518" *)
|
|
||||||
casez (rst)
|
|
||||||
1'h1:
|
|
||||||
\count$next = 16'h0000;
|
|
||||||
endcase
|
|
||||||
end
|
end
|
||||||
assign \$3 = \$4 ;
|
assign \$3 = \$4 ;
|
||||||
assign ovf = \$1 ;
|
assign ovf = \$1 ;
|
||||||
|
|
|
@ -27,7 +27,7 @@ A 16-bit up counter with enable input, overflow output, and a limit fixed at des
|
||||||
:lineno-match:
|
:lineno-match:
|
||||||
:end-before: # --- TEST ---
|
:end-before: # --- TEST ---
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
.. TODO: link to Elaboratable reference
|
.. TODO: link to Elaboratable reference
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue