litex/misoc/cores/gpio.py

33 lines
893 B
Python
Raw Normal View History

2015-09-22 12:36:47 -04:00
from migen import *
2013-05-16 11:43:20 -04:00
from migen.genlib.cdc import MultiReg
2015-09-29 06:13:59 -04:00
from misoc.interconnect.csr import *
2013-05-16 11:43:20 -04:00
2015-04-13 10:47:22 -04:00
2013-05-16 11:43:20 -04:00
class GPIOIn(Module, AutoCSR):
def __init__(self, signal):
2015-09-26 06:50:11 -04:00
self._in = CSRStatus(len(signal))
self.specials += MultiReg(signal, self._in.status)
2013-05-16 11:43:20 -04:00
2015-04-13 10:47:22 -04:00
2013-05-16 11:43:20 -04:00
class GPIOOut(Module, AutoCSR):
def __init__(self, signal):
2015-09-26 06:50:11 -04:00
self._out = CSRStorage(len(signal))
self.comb += signal.eq(self._out.storage)
2013-05-16 11:43:20 -04:00
2015-04-13 10:47:22 -04:00
2013-12-05 18:06:53 -05:00
class GPIOInOut(Module):
def __init__(self, in_signal, out_signal):
self.submodules.gpio_in = GPIOIn(in_signal)
self.submodules.gpio_out = GPIOOut(out_signal)
2013-12-05 18:06:53 -05:00
def get_csrs(self):
return self.gpio_in.get_csrs() + self.gpio_out.get_csrs()
2013-12-05 18:06:53 -05:00
2015-04-13 10:47:22 -04:00
2013-05-16 11:43:20 -04:00
class Blinker(Module):
def __init__(self, signal, divbits=26):
counter = Signal(divbits)
self.comb += signal.eq(counter[divbits-1])
self.sync += counter.eq(counter + 1)