2014-09-23 17:03:32 -04:00
|
|
|
from migen.fhdl.std import *
|
2014-09-24 08:28:52 -04:00
|
|
|
from migen.flow.actor import Sink, Source
|
2014-09-23 17:03:32 -04:00
|
|
|
|
|
|
|
from lib.sata.k7sataphy.std import *
|
2014-09-27 09:34:28 -04:00
|
|
|
from lib.sata.k7sataphy.gtx import K7SATAPHYGTX
|
|
|
|
from lib.sata.k7sataphy.crg import K7SATAPHYCRG
|
2014-09-24 08:28:52 -04:00
|
|
|
from lib.sata.k7sataphy.ctrl import K7SATAPHYHostCtrl, K7SATAPHYDeviceCtrl
|
2014-09-27 09:34:28 -04:00
|
|
|
from lib.sata.k7sataphy.datapath import K7SATAPHYRXAlign
|
|
|
|
from lib.sata.k7sataphy.datapath import K7SATAPHYRXConvert, K7SATAPHYTXConvert
|
2014-09-23 17:03:32 -04:00
|
|
|
|
|
|
|
class K7SATAPHY(Module):
|
2014-09-27 07:33:43 -04:00
|
|
|
def __init__(self, pads, clk_freq, host=True,):
|
2014-09-24 07:56:32 -04:00
|
|
|
self.sink = Sink([("d", 32)], True)
|
|
|
|
self.source = Source([("d", 32)], True)
|
2014-09-23 17:03:32 -04:00
|
|
|
|
2014-09-25 08:52:16 -04:00
|
|
|
gtx = K7SATAPHYGTX(pads, "SATA3")
|
2014-09-26 05:36:28 -04:00
|
|
|
self.comb += [
|
2014-09-26 15:52:32 -04:00
|
|
|
gtx.rxrate.eq(0b000),
|
|
|
|
gtx.txrate.eq(0b000),
|
2014-09-26 05:36:28 -04:00
|
|
|
]
|
2014-09-27 09:34:28 -04:00
|
|
|
clocking = K7SATAPHYCRG(pads, gtx, clk_freq)
|
2014-09-25 08:52:16 -04:00
|
|
|
rxalign = K7SATAPHYRXAlign()
|
|
|
|
rxconvert = K7SATAPHYRXConvert()
|
|
|
|
txconvert = K7SATAPHYTXConvert()
|
|
|
|
self.submodules += gtx, clocking, rxalign, rxconvert, txconvert
|
|
|
|
self.comb += [
|
|
|
|
rxalign.rxdata_i.eq(gtx.rxdata),
|
|
|
|
rxalign.rxcharisk_i.eq(gtx.rxcharisk),
|
|
|
|
rxconvert.rxdata.eq(rxalign.rxdata_o),
|
|
|
|
rxconvert.rxcharisk.eq(rxalign.rxcharisk_o),
|
|
|
|
|
|
|
|
gtx.txdata.eq(txconvert.txdata),
|
|
|
|
gtx.txcharisk.eq(txconvert.txcharisk)
|
|
|
|
]
|
|
|
|
|
2014-09-24 07:56:32 -04:00
|
|
|
if host:
|
2014-09-25 08:52:16 -04:00
|
|
|
ctrl = K7SATAPHYHostCtrl(gtx)
|
2014-09-24 07:56:32 -04:00
|
|
|
else:
|
2014-09-25 08:52:16 -04:00
|
|
|
ctrl = K7SATAPHYDeviceCtrl(gtx)
|
|
|
|
self.submodules += ctrl
|
2014-09-24 07:56:32 -04:00
|
|
|
self.comb += [
|
2014-09-25 08:52:16 -04:00
|
|
|
If(ctrl.link_up,
|
|
|
|
txconvert.sink.stb.eq(self.sink.stb),
|
|
|
|
txconvert.sink.data.eq(self.sink.d),
|
|
|
|
txconvert.sink.charisk.eq(0),
|
|
|
|
self.sink.ack.eq(txconvert.sink.ack),
|
2014-09-24 07:56:32 -04:00
|
|
|
).Else(
|
2014-09-25 08:52:16 -04:00
|
|
|
txconvert.sink.stb.eq(1),
|
|
|
|
txconvert.sink.data.eq(ctrl.txdata),
|
|
|
|
txconvert.sink.charisk.eq(ctrl.txcharisk)
|
2014-09-24 08:28:52 -04:00
|
|
|
),
|
2014-09-25 08:52:16 -04:00
|
|
|
self.source.stb.eq(rxconvert.source.stb),
|
|
|
|
self.source.payload.eq(rxconvert.source.payload),
|
|
|
|
rxconvert.source.ack.eq(self.source.ack),
|
|
|
|
ctrl.rxdata.eq(rxconvert.source.data)
|
2014-09-24 07:56:32 -04:00
|
|
|
]
|