Skip to content

Commit 0e7111c

Browse files
committed
Add firreg example
1 parent a01d3a7 commit 0e7111c

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

pycde_example/fir_example.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import pycde
2+
3+
from pycde import Clock, Module, Reset, Input, Output, generator, ir
4+
from pycde.types import Bits
5+
from pycde.circt.dialects import seq
6+
from pycde import support
7+
from pycde.signals import _FromCirctValue
8+
9+
def unknown_location():
10+
return ir.Location.unknown()
11+
support.get_user_loc.__code__ = unknown_location.__code__
12+
13+
# 替换support模块中的函数对象
14+
15+
class CaseExample(Module):
16+
""" A simple example of using CaseOp in PyCDE."""
17+
18+
module_name = "case_example"
19+
clk = Clock()
20+
rst = Reset()
21+
22+
data_i = Input(Bits(32))
23+
data_o = Output(Bits(32))
24+
25+
@generator
26+
def construct(ports):
27+
re = seq.FirRegOp(
28+
ports.data_i.value,
29+
clk=ports.clk.value,
30+
name="result_reg",
31+
preset=ir.IntegerAttr.get(ir.IntegerType.get_signless(32), 0x12345678),
32+
reset=ports.rst.value,
33+
resetValue=Bits(32)(0).value,
34+
isAsync=True
35+
)
36+
ports.data_o = _FromCirctValue(re.data)
37+
38+
if __name__ == "__main__":
39+
40+
s = pycde.System(CaseExample,
41+
name="case_example",
42+
output_directory="build/case_example",)
43+
s.compile()

0 commit comments

Comments
 (0)