2014-12-14 04:45:26 -05:00
|
|
|
from lib.sata.common import *
|
2014-12-12 16:26:04 -05:00
|
|
|
from lib.sata.link import SATALink
|
|
|
|
from lib.sata.transport import SATATransport
|
|
|
|
from lib.sata.command import SATACommand
|
|
|
|
|
2014-12-14 10:20:22 -05:00
|
|
|
from lib.sata.test.hdd import *
|
2014-12-12 16:26:04 -05:00
|
|
|
from lib.sata.test.common import *
|
|
|
|
|
2014-12-14 06:49:35 -05:00
|
|
|
class CommandTXPacket(list):
|
2014-12-23 12:26:07 -05:00
|
|
|
def __init__(self, write=0, read=0, sector=0, count=0, data=[]):
|
2014-12-14 06:49:35 -05:00
|
|
|
self.ongoing = False
|
|
|
|
self.done = False
|
|
|
|
self.write = write
|
|
|
|
self.read = read
|
2014-12-15 07:26:53 -05:00
|
|
|
self.sector = sector
|
|
|
|
self.count = count
|
2014-12-14 06:49:35 -05:00
|
|
|
for d in data:
|
|
|
|
self.append(d)
|
|
|
|
|
2014-12-18 07:15:39 -05:00
|
|
|
class CommandStreamer(PacketStreamer):
|
2014-12-14 06:49:35 -05:00
|
|
|
def __init__(self):
|
2014-12-18 07:15:39 -05:00
|
|
|
PacketStreamer.__init__(self, command_tx_description(32), CommandTXPacket)
|
2014-12-14 06:49:35 -05:00
|
|
|
|
|
|
|
def do_simulation(self, selfp):
|
2014-12-18 07:15:39 -05:00
|
|
|
PacketStreamer.do_simulation(self, selfp)
|
2014-12-14 06:49:35 -05:00
|
|
|
selfp.source.write = self.packet.write
|
|
|
|
selfp.source.read = self.packet.read
|
2014-12-15 07:26:53 -05:00
|
|
|
selfp.source.sector = self.packet.sector
|
|
|
|
selfp.source.count = self.packet.count
|
2014-12-14 06:49:35 -05:00
|
|
|
|
|
|
|
class CommandRXPacket(list):
|
|
|
|
def __init__(self):
|
|
|
|
self.ongoing = False
|
|
|
|
self.done = False
|
|
|
|
self.write = 0
|
|
|
|
self.read = 0
|
|
|
|
self.success = 0
|
|
|
|
self.failed = 0
|
|
|
|
|
2014-12-18 07:15:39 -05:00
|
|
|
class CommandLogger(PacketLogger):
|
2014-12-14 06:49:35 -05:00
|
|
|
def __init__(self):
|
2014-12-18 07:15:39 -05:00
|
|
|
PacketLogger.__init__(self, command_rx_description(32), CommandRXPacket)
|
2014-12-14 06:49:35 -05:00
|
|
|
|
|
|
|
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.sucess = selfp.sink.success
|
2014-12-14 06:59:02 -05:00
|
|
|
self.packet.failed = selfp.sink.failed
|
2014-12-14 06:49:35 -05:00
|
|
|
self.packet.append(selfp.sink.data)
|
|
|
|
elif selfp.sink.stb:
|
|
|
|
self.packet.append(selfp.sink.data)
|
2014-12-18 07:15:39 -05:00
|
|
|
if selfp.sink.stb == 1 and selfp.sink.eop == 1:
|
2014-12-14 06:49:35 -05:00
|
|
|
self.packet.done = True
|
|
|
|
|
2014-12-12 16:26:04 -05:00
|
|
|
class TB(Module):
|
|
|
|
def __init__(self):
|
2014-12-18 19:35:18 -05:00
|
|
|
self.hdd = HDD(
|
2014-12-15 07:26:53 -05:00
|
|
|
link_debug=False, link_random_level=50,
|
2014-12-14 10:20:22 -05:00
|
|
|
transport_debug=False, transport_loopback=False,
|
2014-12-14 14:30:21 -05:00
|
|
|
hdd_debug=True)
|
2014-12-18 19:35:18 -05:00
|
|
|
self.link = SATALink(self.hdd.phy)
|
|
|
|
self.transport = SATATransport(self.link)
|
|
|
|
self.command = SATACommand(self.transport)
|
2014-12-12 16:26:04 -05:00
|
|
|
|
2014-12-18 19:35:18 -05:00
|
|
|
self.streamer = CommandStreamer()
|
|
|
|
self.streamer_randomizer = Randomizer(command_tx_description(32), level=50)
|
|
|
|
|
|
|
|
self.logger = CommandLogger()
|
|
|
|
self.logger_randomizer = Randomizer(command_rx_description(32), level=50)
|
|
|
|
|
|
|
|
self.pipeline = Pipeline(
|
|
|
|
self.streamer,
|
|
|
|
self.streamer_randomizer,
|
|
|
|
self.command,
|
|
|
|
self.logger_randomizer,
|
|
|
|
self.logger
|
|
|
|
)
|
2014-12-14 06:49:35 -05:00
|
|
|
|
2014-12-12 16:26:04 -05:00
|
|
|
def gen_simulation(self, selfp):
|
2014-12-15 07:26:53 -05:00
|
|
|
hdd = self.hdd
|
|
|
|
hdd.malloc(0, 64)
|
2015-01-06 10:48:19 -05:00
|
|
|
write_data = [i for i in range(sectors2dwords(2))]
|
|
|
|
write_len = dwords2sectors(len(write_data))
|
2014-12-15 07:26:53 -05:00
|
|
|
write_packet = CommandTXPacket(write=1, sector=2, count=write_len, data=write_data)
|
2014-12-14 10:20:22 -05:00
|
|
|
yield from self.streamer.send(write_packet)
|
2014-12-14 09:32:00 -05:00
|
|
|
yield from self.logger.receive()
|
2014-12-15 07:26:53 -05:00
|
|
|
read_packet = CommandTXPacket(read=1, sector=2, count=write_len)
|
2014-12-14 10:20:22 -05:00
|
|
|
yield from self.streamer.send(read_packet)
|
2014-12-14 06:49:35 -05:00
|
|
|
yield from self.logger.receive()
|
2014-12-14 10:20:22 -05:00
|
|
|
read_data = self.logger.packet
|
|
|
|
|
|
|
|
# check results
|
|
|
|
s, l, e = check(write_data, read_data)
|
|
|
|
print("shift "+ str(s) + " / length " + str(l) + " / errors " + str(e))
|
2014-12-12 16:26:04 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2014-12-15 07:26:53 -05:00
|
|
|
run_simulation(TB(), ncycles=2048, vcd_name="my.vcd", keep_files=True)
|