litex/lib/sata/bist.py

131 lines
3.0 KiB
Python
Raw Normal View History

2014-12-15 10:44:12 -05:00
from lib.sata.common import *
from lib.sata.link.scrambler import Scrambler
from migen.bank.description import *
2015-01-07 16:15:57 -05:00
class SATABIST(Module):
def __init__(self, sata_con):
2015-01-07 16:15:57 -05:00
self.write = Signal()
self.read = Signal()
2014-12-15 10:44:12 -05:00
self.sector = Signal(48)
2015-01-06 10:48:19 -05:00
self.count = Signal(16)
2015-01-07 16:15:57 -05:00
self.loops = Signal(8)
2014-12-15 10:44:12 -05:00
self.done = Signal()
2015-01-07 16:15:57 -05:00
self.errors = Signal(32)
###
sink = sata_con.source
source = sata_con.sink
2014-12-15 10:44:12 -05:00
self.counter = counter = Counter(bits_sign=32)
2015-01-07 16:15:57 -05:00
self.loops_counter = loops_counter = Counter(bits_sign=8)
self.error_counter = Counter(self.errors, bits_sign=32)
self.scrambler = scrambler = InsertReset(Scrambler())
self.comb += [
scrambler.reset.eq(counter.reset),
scrambler.ce.eq(counter.ce)
]
2014-12-15 10:44:12 -05:00
self.fsm = fsm = FSM(reset_state="IDLE")
2014-12-15 10:44:12 -05:00
fsm.act("IDLE",
self.done.eq(1),
counter.reset.eq(1),
2015-01-07 16:15:57 -05:00
loops_counter.reset.eq(1),
If(self.write,
self.error_counter.reset.eq(1),
NextState("SEND_WRITE_CMD_AND_DATA")
).Elif(self.read,
self.error_counter.reset.eq(1),
NextState("SEND_READ_CMD")
2014-12-15 10:44:12 -05:00
)
)
fsm.act("SEND_WRITE_CMD_AND_DATA",
source.stb.eq(1),
2015-01-07 16:15:57 -05:00
source.sop.eq(counter.value == 0),
source.eop.eq(counter.value == (logical_sector_size//4*self.count)-1),
2014-12-15 10:44:12 -05:00
source.write.eq(1),
source.sector.eq(self.sector),
2014-12-15 13:48:22 -05:00
source.count.eq(self.count),
source.data.eq(scrambler.value),
2015-01-07 16:15:57 -05:00
If(source.stb & source.ack,
counter.ce.eq(1),
If(source.eop,
NextState("WAIT_WRITE_ACK")
)
2014-12-15 10:44:12 -05:00
)
)
fsm.act("WAIT_WRITE_ACK",
sink.ack.eq(1),
If(sink.stb,
2015-01-07 16:15:57 -05:00
loops_counter.ce.eq(1),
If(loops_counter.value == (self.loops-1),
NextState("IDLE")
).Else(
2015-01-07 16:15:57 -05:00
counter.reset.eq(1),
NextState("SEND_WRITE_CMD_AND_DATA")
)
2014-12-15 10:44:12 -05:00
)
)
fsm.act("SEND_READ_CMD",
source.stb.eq(1),
source.sop.eq(1),
source.eop.eq(1),
source.read.eq(1),
source.sector.eq(self.sector),
2014-12-15 13:48:22 -05:00
source.count.eq(self.count),
2014-12-15 10:44:12 -05:00
If(source.ack,
2015-01-06 10:48:19 -05:00
counter.reset.eq(1),
2014-12-15 10:44:12 -05:00
NextState("WAIT_READ_ACK")
)
)
fsm.act("WAIT_READ_ACK",
If(sink.stb & sink.read,
NextState("RECEIVE_READ_DATA")
)
)
fsm.act("RECEIVE_READ_DATA",
sink.ack.eq(1),
If(sink.stb,
counter.ce.eq(1),
If(sink.data != scrambler.value,
2015-01-07 16:15:57 -05:00
self.error_counter.ce.eq(1)
),
If(sink.eop,
2015-01-06 10:48:19 -05:00
If(sink.last,
2015-01-07 16:15:57 -05:00
loops_counter.ce.eq(1),
If(loops_counter.value == (self.loops-1),
NextState("IDLE")
).Else(
NextState("SEND_READ_CMD")
)
2015-01-06 10:48:19 -05:00
).Else(
NextState("WAIT_READ_ACK")
)
)
2014-12-15 10:44:12 -05:00
)
)
2015-01-07 16:15:57 -05:00
class SATABISTControl(Module, AutoCSR):
def __init__(self, sata_bist):
self._write = CSR()
self._read = CSR()
self._sector = CSRStorage(48)
self._count = CSRStorage(16)
2015-01-07 16:15:57 -05:00
self._loops = CSRStorage(8)
2015-01-07 16:15:57 -05:00
self._done = CSRStatus()
self._errors = CSRStatus(32)
self.comb += [
2015-01-07 16:15:57 -05:00
sata_bist.write.eq(self._write.r & self._write.re),
sata_bist.read.eq(self._read.r & self._read.re),
sata_bist.sector.eq(self._sector.storage),
sata_bist.count.eq(self._count.storage),
sata_bist.loops.eq(self._loops.storage),
self._done.status.eq(sata_bist.done),
self._errors.status.eq(sata_bist.errors)
]