Implement a simple blinker
Reimplemented the icebreaker top in nmigen_dg
This commit is contained in:
2
fpga/modules/__init__.py
Normal file
2
fpga/modules/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from .blinker import Blinker
|
||||
from .blinker import Pulser
|
||||
29
fpga/modules/blinker.dg
Normal file
29
fpga/modules/blinker.dg
Normal file
@@ -0,0 +1,29 @@
|
||||
import "/nmigen/cli/main"
|
||||
import "/nmigen_dg/*"
|
||||
|
||||
Blinker = subclass Elaboratable where
|
||||
__init__ = ncycles pulse: False ~> None where
|
||||
@ncycles = ncycles
|
||||
@pulse = pulse
|
||||
@out = Signal!
|
||||
|
||||
elaborate = platform ~> m where with m = Module! =>
|
||||
counter = Signal$ range (@ncycles + 1)
|
||||
|
||||
if @pulse =>
|
||||
sync$ drive @out LOW
|
||||
|
||||
when
|
||||
counter == 0 ,->
|
||||
sync$ drive @out (~ @out)
|
||||
sync$ drive counter @ncycles
|
||||
otherwise ,->
|
||||
sync$ drive counter (counter - 1)
|
||||
|
||||
|
||||
Pulser = bind Blinker pulse: True
|
||||
|
||||
|
||||
if __name__ == "__main__" =>
|
||||
blinker = Blinker ncycles: 10000000
|
||||
main blinker ports: [blinker.out]
|
||||
Reference in New Issue
Block a user