2020-03-26 06:03:43 -04:00
|
|
|
#!/usr/bin/env python3
|
2020-02-04 07:45:08 -05:00
|
|
|
|
2020-08-23 09:52:08 -04:00
|
|
|
#
|
|
|
|
# This file is part of LiteDRAM.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2020 Antmicro <www.antmicro.com>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
2020-02-04 07:45:08 -05:00
|
|
|
import random
|
|
|
|
import argparse
|
|
|
|
|
2020-02-04 10:37:26 -05:00
|
|
|
def main():
|
2020-03-26 06:03:43 -04:00
|
|
|
description = """
|
|
|
|
Generate random access pattern for LiteDRAM Pattern Generator/Checker.
|
|
|
|
|
|
|
|
Each address in range [base, base+length) will be accessed only once, but in random order.
|
|
|
|
This ensures that no data will be overwritten.
|
2020-02-04 10:37:26 -05:00
|
|
|
"""
|
2020-03-26 06:03:43 -04:00
|
|
|
parser = argparse.ArgumentParser(description=description)
|
|
|
|
parser.add_argument("base", help="Base address")
|
|
|
|
parser.add_argument("length", help="Number of (address, data) pairs")
|
|
|
|
parser.add_argument("data_width", help="Width of data (used to determine max value)")
|
|
|
|
parser.add_argument("--seed", help="Use given random seed (int)")
|
2020-02-04 10:37:26 -05:00
|
|
|
args = parser.parse_args()
|
2020-02-04 07:45:08 -05:00
|
|
|
|
2020-02-04 10:37:26 -05:00
|
|
|
if args.seed:
|
|
|
|
random.seed(int(args.seed, 0))
|
2020-02-04 07:45:08 -05:00
|
|
|
|
2020-03-26 06:03:43 -04:00
|
|
|
base = int(args.base, 0)
|
|
|
|
length = int(args.length, 0)
|
2020-02-04 10:37:26 -05:00
|
|
|
data_width = int(args.data_width, 0)
|
2020-02-04 07:45:08 -05:00
|
|
|
|
2020-02-04 10:37:26 -05:00
|
|
|
address = list(range(length))
|
|
|
|
random.shuffle(address)
|
|
|
|
data = [random.randrange(0, 2**data_width) for _ in range(length)]
|
2020-02-04 07:45:08 -05:00
|
|
|
|
2020-02-04 10:37:26 -05:00
|
|
|
for a, d in zip(address, data):
|
2020-03-26 06:03:43 -04:00
|
|
|
print("0x{:08x}, 0x{:08x}".format(a, d))
|
2020-02-04 10:37:26 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|