2020-08-23 09:40:21 -04:00
|
|
|
#
|
|
|
|
# This file is part of LiteX.
|
|
|
|
#
|
2021-10-04 11:22:57 -04:00
|
|
|
# Copyright (c) 2019-2021 Florent Kermarrec <florent@enjoy-digital.fr>
|
2020-08-23 09:40:21 -04:00
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
2019-07-05 12:30:34 -04:00
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
|
2021-10-04 08:14:03 -04:00
|
|
|
from litex.soc.cores.icap import *
|
2019-07-05 12:30:34 -04:00
|
|
|
|
2021-10-04 11:22:57 -04:00
|
|
|
# References ---------------------------------------------------------------------------------------
|
|
|
|
|
2021-10-04 08:41:38 -04:00
|
|
|
iprog_sequence = [
|
|
|
|
# csib rdwrb data
|
|
|
|
"0 0 0xaa995566",
|
|
|
|
"0 0 0x20000000",
|
|
|
|
"0 0 0x20000000",
|
|
|
|
"0 0 0x30008001",
|
|
|
|
"0 0 0x0000000f",
|
|
|
|
"0 0 0x20000000",
|
|
|
|
"0 0 0x20000000",
|
|
|
|
"0 0 0x30008001",
|
|
|
|
"0 0 0x0000000d",
|
|
|
|
"0 0 0x20000000",
|
|
|
|
"0 0 0x20000000",
|
|
|
|
]
|
2019-07-05 12:30:34 -04:00
|
|
|
|
2021-10-04 11:22:57 -04:00
|
|
|
bootsts_sequence = [
|
|
|
|
# csib rdwrb data
|
|
|
|
"0 0 0xaa995566",
|
|
|
|
"0 0 0x20000000",
|
|
|
|
"0 0 0x20000000",
|
|
|
|
"0 0 0x2802c001",
|
|
|
|
"0 0 0x20000000",
|
|
|
|
"0 0 0x20000000",
|
|
|
|
"1 1 0x20000000",
|
|
|
|
"0 1 0x20000000",
|
|
|
|
"0 1 0x20000000",
|
|
|
|
"0 1 0x20000000",
|
|
|
|
"0 1 0x20000000",
|
|
|
|
"0 0 0x30008001",
|
|
|
|
"0 0 0x0000000d",
|
|
|
|
"0 0 0x20000000",
|
|
|
|
"0 0 0x20000000",
|
|
|
|
]
|
|
|
|
|
|
|
|
# Test ICAP ----------------------------------------------------------------------------------------
|
|
|
|
|
2019-07-05 12:30:34 -04:00
|
|
|
class TestICAP(unittest.TestCase):
|
2019-10-01 15:30:14 -04:00
|
|
|
def test_icap_command_reload(self):
|
2019-07-05 12:30:34 -04:00
|
|
|
def generator(dut):
|
2021-10-04 11:22:57 -04:00
|
|
|
# Send IPROG Write Sequence.
|
2021-10-04 08:14:03 -04:00
|
|
|
yield dut.addr.eq(ICAPRegisters.CMD)
|
2021-10-04 11:22:57 -04:00
|
|
|
yield dut.write_data.eq(ICAPCMDs.IPROG)
|
|
|
|
yield dut.write.eq(1)
|
|
|
|
# Wait.
|
|
|
|
while not (yield dut.done):
|
|
|
|
yield
|
|
|
|
yield dut.write.eq(0)
|
|
|
|
|
|
|
|
# Delay
|
|
|
|
for i in range(16):
|
2019-07-05 12:30:34 -04:00
|
|
|
yield
|
2021-10-04 11:22:57 -04:00
|
|
|
|
|
|
|
# Send BOOTSTS Read Sequence.
|
|
|
|
yield dut.addr.eq(ICAPRegisters.BOOTSTS)
|
|
|
|
yield dut.read.eq(1)
|
|
|
|
# Wait.
|
|
|
|
while not (yield dut.done):
|
|
|
|
yield
|
|
|
|
yield dut.read.eq(0)
|
2019-07-05 12:30:34 -04:00
|
|
|
yield
|
2021-10-04 11:22:57 -04:00
|
|
|
|
2021-10-04 08:41:38 -04:00
|
|
|
|
|
|
|
def check(dut):
|
2021-10-04 11:22:57 -04:00
|
|
|
# Check IPROG Write Sequence.
|
2021-10-04 08:41:38 -04:00
|
|
|
while (yield dut._i) != ICAP_SYNC:
|
|
|
|
yield
|
|
|
|
for ref_w in iprog_sequence:
|
|
|
|
cur_w = f"{(yield dut._csib)} {(yield dut._rdwrb)} 0x{(yield dut._i):08x}"
|
|
|
|
self.assertEqual(ref_w, cur_w)
|
2021-10-04 09:06:03 -04:00
|
|
|
#print(cur_w)
|
2019-07-05 12:30:34 -04:00
|
|
|
yield
|
|
|
|
|
2021-10-04 11:22:57 -04:00
|
|
|
# Check BOOTSTS Read Sequence.
|
|
|
|
while (yield dut._i) != ICAP_SYNC:
|
|
|
|
yield
|
|
|
|
for ref_w in bootsts_sequence:
|
|
|
|
cur_w = f"{(yield dut._csib)} {(yield dut._rdwrb)} 0x{(yield dut._i):08x}"
|
|
|
|
self.assertEqual(ref_w, cur_w)
|
|
|
|
#print(cur_w)
|
|
|
|
yield
|
2021-10-04 08:41:38 -04:00
|
|
|
|
2020-10-07 06:36:08 -04:00
|
|
|
dut = ICAP(with_csr=False, simulation=True)
|
2021-10-04 08:14:03 -04:00
|
|
|
clocks = {"sys": 10, "icap": 10}
|
2021-10-04 08:41:38 -04:00
|
|
|
run_simulation(dut, [generator(dut), check(dut)], clocks, vcd_name="icap.vcd")
|
2019-10-01 15:30:14 -04:00
|
|
|
|
|
|
|
def test_icap_bitstream_syntax(self):
|
|
|
|
dut = ICAPBitstream(simulation=True)
|