link: wip bfm

This commit is contained in:
Florent Kermarrec 2014-11-12 18:20:34 +01:00
parent b423c1df4b
commit 2b7779d3b6
3 changed files with 64 additions and 11 deletions

View File

@ -77,7 +77,7 @@ class SATAScrambler(Module):
self.submodules.scrambler = Scrambler() self.submodules.scrambler = Scrambler()
ongoing = Signal() ongoing = Signal()
self.sync += [ self.sync += \
If(sink.stb & sink.ack, If(sink.stb & sink.ack,
If(sink.eop, If(sink.eop,
ongoing.eq(0) ongoing.eq(0)
@ -85,10 +85,9 @@ class SATAScrambler(Module):
ongoing.eq(1) ongoing.eq(1)
) )
) )
]
self.comb += [ self.comb += [
self.scrambler.ce.eq(sink.stb & (sink.sop | ongoing)), self.scrambler.ce.eq(sink.stb & sink.ack & (sink.sop | ongoing)),
self.scrambler.reset.eq(~ongoing), self.scrambler.reset.eq(~(sink.sop | ongoing)),
Record.connect(sink, source), Record.connect(sink, source),
source.d.eq(sink.d ^ self.scrambler.value) source.d.eq(sink.d ^ self.scrambler.value)
] ]

View File

@ -1,3 +1,5 @@
import subprocess
from migen.fhdl.std import * from migen.fhdl.std import *
from lib.sata.std import * from lib.sata.std import *
@ -32,7 +34,7 @@ class BFMSource(Module):
if v == self.dword.dat: if v == self.dword.dat:
selfp.source.charisk = 0b0001 selfp.source.charisk = 0b0001
selfp.source.data = self.dword.dat selfp.source.data = self.dword.dat
elif selfp.source.stb == 1 and selfp.source.ack == 1: if selfp.source.stb == 1 and selfp.source.ack == 1:
self.dword.done = 1 self.dword.done = 1
selfp.source.stb = 0 selfp.source.stb = 0
@ -81,8 +83,60 @@ class BFM(Module):
### ###
self.submodules.phy = BFMPHY(dw) self.submodules.phy = BFMPHY(dw)
self.get_scrambler_ref()
self.rx_packet_ongoing = False
self.rx_packet = []
def get_scrambler_ref(self):
p = subprocess.Popen(["./scrambler"], stdout=subprocess.PIPE)
out, err = p.communicate()
self.scrambler_ref = [int(e, 16) for e in out.decode("utf-8").split("\n")[:-1]]
def descramble(self, packet):
p = []
for i in range(len(packet)):
v = packet[i] ^ self.scrambler_ref[i]
p.append(v)
return p
def check_crc(self, packet):
# Todo from C Code or Python Code
return packet[:-1]
def packet_callback(self, packet):
packet = self.descramble(packet)
packet = self.check_crc(packet)
for v in packet:
print("%08x" %v)
def dword_callback(self, dword):
print("%08x " %dword, end="")
for k, v in primitives.items():
if dword == v:
print(k, end="")
print("")
# X_RDY / WTRM response
if dword == primitives["X_RDY"]:
self.phy.bfm_source.dwords.append(BFMDword(primitives["R_RDY"]))
if dword == primitives["WTRM"]:
self.phy.bfm_source.dwords.append(BFMDword(primitives["R_OK"]))
# packet capture
if dword == primitives["EOF"]:
self.rx_packet_ongoing = False
self.packet_callback(self.rx_packet)
if self.rx_packet_ongoing:
self.rx_packet.append(dword)
if dword == primitives["SOF"]:
self.rx_packet_ongoing = True
self.rx_packet = []
def gen_simulation(self, selfp): def gen_simulation(self, selfp):
self.phy.bfm_source.dwords.append(BFMDword(primitives["SYNC"]))
while True: while True:
yield from self.phy.receive() yield from self.phy.receive()
print("%08x" %(self.phy.rx_dword)) self.dword_callback(self.phy.rx_dword)

View File

@ -76,15 +76,15 @@ class TB(Module):
self.submodules.streamer = LinkStreamer(32) self.submodules.streamer = LinkStreamer(32)
self.submodules.logger = LinkLogger(32) self.submodules.logger = LinkLogger(32)
self.comb += [ self.comb += [
self.link_layer.sink.eq(self.streamer.source), Record.connect(self.streamer.source, self.link_layer.sink),
self.logger.sink.eq(self.link_layer.source) Record.connect(self.link_layer.source, self.logger.sink)
] ]
def gen_simulation(self, selfp): def gen_simulation(self, selfp):
for i in range(200): for i in range(200):
yield yield
yield from self.bfm.phy.send(BFMDword(primitives["R_RDY"]), False) for i in range(8):
yield from self.streamer.send(LinkPacket([0, 1, 2, 3])) yield from self.streamer.send(LinkPacket([0, 1, 2, 3]))
if __name__ == "__main__": if __name__ == "__main__":
run_simulation(TB(), ncycles=5000, vcd_name="my.vcd", keep_files=True) run_simulation(TB(), ncycles=512, vcd_name="my.vcd", keep_files=True)