Skip to content

Commit 7514ba9

Browse files
committed
led-fsm
1 parent d6c4b8e commit 7514ba9

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

sample/led-fsm/Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
TARGET=led.py
2+
ARGS=
3+
4+
PYTHON=python3
5+
#PYTHON=python
6+
#OPT=-m pdb
7+
#OPT=-m cProfile -s time
8+
#OPT=-m cProfile -o profile.rslt
9+
10+
.PHONY: all
11+
all: run
12+
13+
.PHONY: run
14+
run:
15+
$(PYTHON) $(OPT) $(TARGET) $(ARGS)
16+
17+
.PHONY: check
18+
check:
19+
$(PYTHON) $(OPT) $(TARGET) $(ARGS) > tmp.v
20+
iverilog -tnull -Wall tmp.v
21+
rm -f tmp.v
22+
23+
.PHONY: clean
24+
clean:
25+
rm -rf *.pyc __pycache__ parsetab.py *.out

sample/led-fsm/led.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import sys
2+
import os
3+
4+
from veriloggen import *
5+
6+
def mkLed():
7+
m = Module('blinkled')
8+
width = m.Parameter('WIDTH', 8)
9+
clk = m.Input('CLK')
10+
rst = m.Input('RST')
11+
led = m.OutputReg('LED', width)
12+
count = m.Reg('count', 32)
13+
14+
fsm = lib.FSM(m, '')
15+
fsm_contents = []
16+
fsm_contents.append( fsm(count(count + 1), fsm.next()) )
17+
fsm_contents.append( fsm(count(count + 2), fsm.next()) )
18+
fsm_contents.append( fsm(count(count + 3), fsm.next()) )
19+
fsm_contents.append( fsm(If(count < 1024)( fsm.next(0) ).els( fsm.next() )) )
20+
fsm_contents.append( fsm(led(led + 1), fsm.next(0)) )
21+
22+
m.Always(Posedge(clk))(
23+
If(rst)(
24+
count(0),
25+
led(0),
26+
fsm.next(0)
27+
).els(
28+
tuple(fsm_contents)
29+
))
30+
31+
return m
32+
33+
led = mkLed()
34+
verilog = led.toVerilog()
35+
print(verilog)

sample/led-fsm/veriloggen

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../veriloggen

veriloggen/lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, m, name, width=32):
1111

1212
def next(self, index=None):
1313
if index is None:
14-
return self.state( self.state + 1 )
14+
return self.state( len(self) )
1515
return self.state(index)
1616

1717
def cond(self, name='fsm_label'):

0 commit comments

Comments
 (0)