command_tb: add streamer and logger

This commit is contained in:
Florent Kermarrec 2014-12-14 12:49:35 +01:00
parent b6d5e23264
commit a0cb0c6474
2 changed files with 108 additions and 32 deletions

View File

@ -109,7 +109,7 @@ class SATACommandTX(Module):
class SATACommandRX(Module):
def __init__(self, transport):
self.source = source = Source(command_tx_description(32))
self.source = source = Source(command_rx_description(32))
self.to_tx = Source(from_rx)
###

View File

@ -12,51 +12,127 @@ from lib.sata.command import SATACommand
from lib.sata.test.bfm import *
from lib.sata.test.common import *
class CommandTXPacket(list):
def __init__(self, write=0, read=0, identify=0, address=0, length=0, data=[]):
self.ongoing = False
self.done = False
self.write = write
self.read = read
self.identify = identify
self.address = address
self.length = length
for d in data:
self.append(d)
class CommandStreamer(Module):
def __init__(self):
self.source = Source(command_tx_description(32))
###
self.packets = []
self.packet = CommandTXPacket()
self.packet.done = 1
self.length = 0
def send(self, packet, blocking=True):
self.packets.append(packet)
if blocking:
while packet.done == 0:
yield
def do_simulation(self, selfp):
if len(self.packets) and self.packet.done:
self.packet = self.packets.pop(0)
selfp.source.write = self.packet.write
selfp.source.read = self.packet.read
selfp.source.identify = self.packet.identify
selfp.source.address = self.packet.address
selfp.source.length = self.packet.length
if not self.packet.ongoing and not self.packet.done:
selfp.source.stb = 1
selfp.source.sop = 1
if len(self.packet) > 0:
selfp.source.data = self.packet.pop(0)
self.packet.ongoing = True
elif selfp.source.stb == 1 and selfp.source.ack == 1:
selfp.source.sop = 0
selfp.source.eop = (len(self.packet) == 1)
if len(self.packet) > 0:
selfp.source.stb = 1
selfp.source.data = self.packet.pop(0)
else:
self.packet.done = 1
selfp.source.stb = 0
class CommandRXPacket(list):
def __init__(self):
self.ongoing = False
self.done = False
self.write = 0
self.read = 0
self.identify = 0
self.success = 0
self.failed = 0
class CommandLogger(Module):
def __init__(self):
self.sink = Sink(command_rx_description(32))
###
self.packet = CommandRXPacket()
def receive(self):
self.packet.done = 0
while self.packet.done == 0:
yield
def do_simulation(self, selfp):
selfp.sink.ack = 1
if selfp.sink.stb == 1 and selfp.sink.sop == 1:
self.packet = CommandRXPacket()
self.packet.write = selfp.sink.write
self.packet.read = selfp.sink.read
self.packet.identify = selfp.sink.identify
self.packet.sucess = selfp.sink.success
self.paclet.failed = selfp.sink.failed
self.packet.append(selfp.sink.data)
elif selfp.sink.stb:
self.packet.append(selfp.sink.data)
if (selfp.sink.stb ==1 and selfp.sink.eop ==1):
self.packet.done = True
class TB(Module):
def __init__(self):
self.submodules.bfm = BFM(phy_debug=False,
link_random_level=0, transport_debug=True, transport_loopback=False)
link_random_level=0, link_debug=False,
transport_debug=True, transport_loopback=False,
command_debug=False,
hdd_debug=False)
self.submodules.link = SATALink(self.bfm.phy)
self.submodules.transport = SATATransport(self.link)
self.submodules.command = SATACommand(self.transport)
self.submodules.streamer = CommandStreamer()
self.submodules.logger = CommandLogger()
self.comb += [
Record.connect(self.streamer.source, self.command.sink),
Record.connect(self.command.source, self.logger.sink)
]
def gen_simulation(self, selfp):
self.bfm.hdd.allocate_mem(0x00000000, 64*1024*1024)
selfp.command.source.ack = 1
for i in range(100):
yield
for i in range(32):
selfp.command.sink.stb = 1
selfp.command.sink.sop = (i==0)
selfp.command.sink.eop = (i==31)
selfp.command.sink.write = 1
selfp.command.sink.address = 1024
selfp.command.sink.length = 32
selfp.command.sink.data = i
yield
while selfp.command.sink.ack == 0:
yield
selfp.command.sink.stb = 0
streamer_packet = CommandTXPacket(write=1, address=1024, length=32, data=[i for i in range(32)])
yield from self.streamer.send(streamer_packet)
for i in range(32):
yield
selfp.command.sink.stb = 1
selfp.command.sink.sop = 1
selfp.command.sink.eop = 1
selfp.command.sink.write = 0
selfp.command.sink.read = 1
selfp.command.sink.address = 1024
selfp.command.sink.length = 32
yield
while selfp.command.sink.ack == 0:
yield
selfp.command.sink.stb = 0
while True:
if selfp.command.source.stb:
print("%08x" %selfp.command.source.data)
yield
#dma_dump = self.bfm.command.dma_read(1024, 32*4)
#for d in dma_dump:
# print("%08x" %d)
streamer_packet = CommandTXPacket(read=1, address=1024, length=32)
yield from self.streamer.send(streamer_packet)
yield from self.logger.receive()
for d in self.logger.packet:
print("%08x" %d)
if __name__ == "__main__":
run_simulation(TB(), ncycles=512, vcd_name="my.vcd", keep_files=True)