soc/cores/spi/SPISlave: Minor cleanup.
This commit is contained in:
parent
75bb78a413
commit
5dc3ad3b29
|
@ -182,14 +182,13 @@ class SPISlave(Module):
|
||||||
self.pads = pads
|
self.pads = pads
|
||||||
self.data_width = data_width
|
self.data_width = data_width
|
||||||
|
|
||||||
self.start = Signal()
|
self.start = Signal() # o, Signal a start of SPI Xfer.
|
||||||
self.length = Signal(8)
|
self.length = Signal(8) # o, Signal the length of the SPI Xfer (in bits).
|
||||||
self.done = Signal()
|
self.done = Signal() # o, Signal that SPI Xfer is done/inactive.
|
||||||
self.irq = Signal()
|
self.irq = Signal() # o, Signal the end of a SPI Xfer.
|
||||||
self.mosi = Signal(data_width)
|
self.mosi = Signal(data_width) # i, Data to send on SPI MOSI.
|
||||||
self.miso = Signal(data_width)
|
self.miso = Signal(data_width) # o, Data received on SPI MISO.
|
||||||
self.cs = Signal()
|
self.loopback = Signal() # i, Loopback enable.
|
||||||
self.loopback = Signal()
|
|
||||||
|
|
||||||
# # #
|
# # #
|
||||||
|
|
||||||
|
@ -200,14 +199,14 @@ class SPISlave(Module):
|
||||||
|
|
||||||
# IOs <--> Internal (input resynchronization) ----------------------------------------------
|
# IOs <--> Internal (input resynchronization) ----------------------------------------------
|
||||||
self.specials += [
|
self.specials += [
|
||||||
MultiReg(pads.clk, clk),
|
MultiReg(pads.clk, clk),
|
||||||
MultiReg(~pads.cs_n, cs),
|
MultiReg(~pads.cs_n, cs),
|
||||||
MultiReg(pads.mosi, mosi),
|
MultiReg(pads.mosi, mosi),
|
||||||
]
|
]
|
||||||
self.comb += pads.miso.eq(miso)
|
self.comb += pads.miso.eq(miso)
|
||||||
|
|
||||||
# Clock detection --------------------------------------------------------------------------
|
# Clock detection --------------------------------------------------------------------------
|
||||||
clk_d = Signal()
|
clk_d = Signal()
|
||||||
clk_rise = Signal()
|
clk_rise = Signal()
|
||||||
clk_fall = Signal()
|
clk_fall = Signal()
|
||||||
self.sync += clk_d.eq(clk)
|
self.sync += clk_d.eq(clk)
|
||||||
|
@ -235,21 +234,24 @@ class SPISlave(Module):
|
||||||
|
|
||||||
# Master In Slave Out (MISO) generation (generated on spi_clk falling edge) ----------------
|
# Master In Slave Out (MISO) generation (generated on spi_clk falling edge) ----------------
|
||||||
miso_data = Signal(data_width)
|
miso_data = Signal(data_width)
|
||||||
self.sync += \
|
self.sync += [
|
||||||
If(self.start,
|
If(self.start,
|
||||||
miso_data.eq(self.miso)
|
miso_data.eq(self.miso)
|
||||||
).Elif(cs & clk_fall,
|
).Elif(cs & clk_fall,
|
||||||
miso_data.eq(Cat(Signal(), miso_data[:-1]))
|
miso_data.eq(Cat(Signal(), miso_data[:-1]))
|
||||||
)
|
)
|
||||||
self.comb += \
|
]
|
||||||
|
self.comb += [
|
||||||
If(self.loopback,
|
If(self.loopback,
|
||||||
miso.eq(mosi)
|
miso.eq(mosi)
|
||||||
).Else(
|
).Else(
|
||||||
miso.eq(miso_data[-1]),
|
miso.eq(miso_data[-1]),
|
||||||
)
|
)
|
||||||
|
]
|
||||||
|
|
||||||
# Master Out Slave In (MOSI) capture (captured on spi_clk rising edge) ---------------------
|
# Master Out Slave In (MOSI) capture (captured on spi_clk rising edge) ---------------------
|
||||||
self.sync += \
|
self.sync += [
|
||||||
If(cs & clk_rise,
|
If(cs & clk_rise,
|
||||||
self.mosi.eq(Cat(mosi, self.mosi[:-1]))
|
self.mosi.eq(Cat(mosi, self.mosi[:-1]))
|
||||||
)
|
)
|
||||||
|
]
|
||||||
|
|
Loading…
Reference in New Issue