Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed Dec 7, 2023
1 parent 45fb572 commit 1c08e42
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
5 changes: 2 additions & 3 deletions tutorial/exercise_1.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import magma as m
# import mantle


class ConfigReg(m.Circuit):
io = m.IO(D=m.In(m.Bits[2]), Q=m.Out(m.Bits[2])) + \
m.ClockIO(has_ce=True)

reg = mantle.Register(2, has_ce=True, name="config_reg")
reg = m.Register(m.Bits[2], has_enable=True)(name="config_reg")
io.Q <= reg(io.D, CE=io.CE)


Expand All @@ -19,5 +18,5 @@ class SimpleALU(m.Circuit):
) + m.ClockIO()

opcode = ConfigReg(name="opcode_reg")(io.config_data, CE=io.config_en)
io.c <= mantle.mux(
io.c <= m.mux(
[io.a + io.b, io.a - io.b, io.a * io.b, io.b - io.a], opcode)
11 changes: 5 additions & 6 deletions tutorial/exercise_2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import magma as m
# import mantle
import fault
from reset_tester import ResetTester

Expand All @@ -18,11 +17,11 @@ class ROM(m.Circuit):
CLK=m.In(m.Clock)
)

regs = [mantle.Register(data_width, init=int(init[i]))
regs = [m.Register(m.Bits[data_width], init=int(init[i]))()
for i in range(1 << addr_width)]
for reg in regs:
reg.I <= reg.O
io.RDATA <= mantle.mux([reg.O for reg in regs], io.RADDR)
io.RDATA <= m.mux([reg.O for reg in regs], io.RADDR)


class RAM(m.Circuit):
Expand All @@ -36,10 +35,10 @@ class RAM(m.Circuit):
RESET=m.In(m.Reset)
)

regs = [mantle.Register(data_width, init=int(init[i]), has_ce=True,
has_reset=True)
regs = [m.Register(m.Bits[data_width], init=int(init[i]), has_enable=True,
reset_type=m.Reset)
for i in range(1 << addr_width)]
for i, reg in enumerate(regs):
reg.I <= io.WDATA
reg.CE <= (io.WADDR == m.bits(i, addr_width)) & io.WE
io.RDATA <= mantle.mux([reg.O for reg in regs], io.RADDR)
io.RDATA <= m.mux([reg.O for reg in regs], io.RADDR)

0 comments on commit 1c08e42

Please sign in to comment.