2022-01-09 15:12:27 +01:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
from amaranth import *
|
|
|
|
from amaranth.back import verilog
|
2022-01-09 17:07:56 +01:00
|
|
|
from amaranth.build.plat import Platform
|
2022-01-09 15:12:27 +01:00
|
|
|
from amaranth.sim import Simulator
|
2022-01-09 22:42:14 +01:00
|
|
|
from amaranth_boards.icebreaker import *
|
2022-01-09 15:12:27 +01:00
|
|
|
|
2022-01-09 22:42:14 +01:00
|
|
|
from ExiClock import ExiClock
|
2022-01-22 19:28:29 +01:00
|
|
|
from ExiRequest import ExiRequest
|
|
|
|
from Debouncer import Debouncer
|
|
|
|
from ExiDecoder import ExiDecoder
|
2022-01-09 17:07:56 +01:00
|
|
|
|
|
|
|
class ReBba(Elaboratable):
|
|
|
|
def __init__(self):
|
2022-01-09 15:12:27 +01:00
|
|
|
pass
|
|
|
|
|
2022-01-09 17:07:56 +01:00
|
|
|
def elaborate(self, platform: Platform):
|
|
|
|
m = Module()
|
|
|
|
|
2022-01-22 19:28:29 +01:00
|
|
|
uledg = platform.request("led_g", 0)
|
|
|
|
uledr = platform.request("led_r", 0)
|
|
|
|
|
2022-01-09 17:07:56 +01:00
|
|
|
led1 = platform.request("led_g", 1)
|
|
|
|
led2 = platform.request("led_g", 4)
|
|
|
|
led3 = platform.request("led_g", 2)
|
|
|
|
led4 = platform.request("led_g", 3)
|
|
|
|
led5 = platform.request("led_r", 1)
|
|
|
|
|
|
|
|
btn1 = platform.request("button", 1)
|
|
|
|
btn2 = platform.request("button", 2)
|
|
|
|
btn3 = platform.request("button", 3)
|
|
|
|
|
2022-01-22 19:28:29 +01:00
|
|
|
debounce1 = Debouncer(10000)
|
|
|
|
m.submodules += debounce1
|
|
|
|
|
|
|
|
m.d.comb += debounce1.input.eq(btn3)
|
|
|
|
|
2022-01-09 22:42:14 +01:00
|
|
|
exiClk = ExiClock()
|
|
|
|
m.submodules += exiClk
|
2022-01-22 19:28:29 +01:00
|
|
|
|
|
|
|
m.d.comb += exiClk.exiClk.eq(debounce1.output)
|
|
|
|
|
|
|
|
exiReq = ExiRequest()
|
|
|
|
m.submodules += exiReq
|
|
|
|
|
|
|
|
m.d.comb += exiReq.exiClkState.eq(exiClk.exiClkState)
|
|
|
|
m.d.comb += exiReq.exiIn.eq(btn1)
|
|
|
|
m.d.comb += exiReq.rst.eq(btn2)
|
|
|
|
|
|
|
|
m.d.comb += led1.eq(exiReq.request[0])
|
|
|
|
m.d.comb += led2.eq(exiReq.request[1])
|
|
|
|
m.d.comb += led3.eq(exiReq.request[2])
|
|
|
|
m.d.comb += led4.eq(exiReq.request[3])
|
2022-01-09 17:07:56 +01:00
|
|
|
|
2022-01-22 19:28:29 +01:00
|
|
|
m.d.comb += led5.eq(exiReq.requestComplete)
|
2022-01-09 17:07:56 +01:00
|
|
|
|
2022-01-22 19:28:29 +01:00
|
|
|
exiDec = ExiDecoder()
|
|
|
|
m.submodules += exiDec
|
2022-01-09 22:42:14 +01:00
|
|
|
|
2022-01-22 19:28:29 +01:00
|
|
|
m.d.comb += exiDec.request.eq(exiReq.request)
|
|
|
|
m.d.comb += uledr.eq(exiDec.request_type[0])
|
|
|
|
m.d.comb += uledg.eq(exiReq.requestComplete)
|
2022-01-09 17:07:56 +01:00
|
|
|
|
|
|
|
return m
|
|
|
|
|
2022-01-09 15:12:27 +01:00
|
|
|
class TestBench:
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def simulate(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def main():
|
|
|
|
if(len(sys.argv) == 2):
|
|
|
|
|
|
|
|
if sys.argv[1] == "s":
|
|
|
|
bench = TestBench()
|
|
|
|
bench.simulate()
|
|
|
|
|
|
|
|
if sys.argv[1] == "v":
|
|
|
|
mod = ReBba()
|
|
|
|
with open(os.path.dirname(os.path.abspath(__file__)) + "/bba.v", "w") as f:
|
2022-01-09 17:07:56 +01:00
|
|
|
f.write(verilog.convert(mod, ports=[]))
|
2022-01-09 15:12:27 +01:00
|
|
|
|
|
|
|
if sys.argv[1] == "p":
|
|
|
|
mod = ReBba()
|
2022-01-09 17:07:56 +01:00
|
|
|
platform = ICEBreakerPlatform()
|
|
|
|
platform.add_resources(platform.break_off_pmod)
|
|
|
|
platform.build(mod, do_program=True)
|
2022-01-09 15:12:27 +01:00
|
|
|
|
|
|
|
else:
|
|
|
|
bench = TestBench()
|
|
|
|
bench.simulate()
|
|
|
|
|
|
|
|
|
|
|
|
#####
|
|
|
|
# Main portion
|
|
|
|
#####
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|