Skip to content
Snippets Groups Projects
Commit 68b6dee6 authored by David Mapstone's avatar David Mapstone
Browse files

Generate FRI File from Python

parent e0680b96
Branches
No related tags found
No related merge requests found
import csv, os import csv, os, tabulate
soclabs_header = """;#-----------------------------------------------------------------------------
;# SoC Labs Basic Hashing Accelerator Wrapper Input Stimulus File
;# A joint work commissioned on behalf of SoC Labs, under Arm Academic Access license.
;#
;# Contributors
;#
;# David Mapstone (d.a.mapstone@soton.ac.uk)
;#
;# Copyright 2023, SoC Labs (www.soclabs.org)
;#-----------------------------------------------------------------------------"""
class InputBlockStruct: class InputBlockStruct:
def __init__(self): def __init__(self):
...@@ -22,8 +33,32 @@ class WordStruct: ...@@ -22,8 +33,32 @@ class WordStruct:
self.packet_num = packet_num self.packet_num = packet_num
self.block_num = block_num self.block_num = block_num
def stimulus_generation(in_file, start_address, size): def fri_output(out_file, word_list):
"""
This function takes a list of 32 bit words and addresses and formats
the data into .fri format to be fed into fml2conv.pl script to stimulate
testbench
"""
# Column Names
col_names = ["Transaction", "Address", "Data"]
data = []
for word in word_list:
data.append([str(word.trans), str(hex(word.addr)), str(hex(word.data))])
table_str = tabulate.tabulate(data, headers=col_names, colalign=("center",), tablefmt="plain")
with open(out_file, "w", encoding="UTF8", newline='') as f:
f.write(soclabs_header + "\n;")
f.write(table_str)
def stimulus_generation(in_file, start_address, size):
"""
This function takes 32 bit input stimulus file from accelerator model,
calculates write addresses for each word and generates a .fri file which
can be used to stimulate an AHB testbench
"""
# Calculate End Address # Calculate End Address
end_address = start_address + size - 0x4 end_address = start_address + size - 0x4
# print(f"End Address is {hex(end_address)}") # print(f"End Address is {hex(end_address)}")
...@@ -76,7 +111,7 @@ def stimulus_generation(in_file, start_address, size): ...@@ -76,7 +111,7 @@ def stimulus_generation(in_file, start_address, size):
# Increment Address # Increment Address
write_addr += 0x4 write_addr += 0x4
# for word in output_word_list: # Test Print Out
prev_block_num = 0 prev_block_num = 0
for word in output_word_list: for word in output_word_list:
if (word.packet_num > 0): if (word.packet_num > 0):
...@@ -86,9 +121,13 @@ def stimulus_generation(in_file, start_address, size): ...@@ -86,9 +121,13 @@ def stimulus_generation(in_file, start_address, size):
print(f"{hex(word.addr)} {hex(word.data)} {word.trans}") print(f"{hex(word.addr)} {hex(word.data)} {word.trans}")
prev_block_num = word.block_num prev_block_num = word.block_num
# Generate FRI File with Write Transactions
out_file = os.environ["WRAP_ACC_DIR"] + "/simulate/stimulus/" + "ahb_input_hash_stim.fri"
fri_output(out_file, output_word_list)
if __name__ == "__main__": if __name__ == "__main__":
accelerator_address = 0x6001_0000 accelerator_input_address = 0x6001_0000
accelerator_size = 0x0000_8000 accelerator_input_size = 0x0000_8000
in_file = os.environ["SHA_2_ACC_DIR"] + "/simulate/stimulus/system/" + "input_data_32bit_stim.csv" in_file = os.environ["SHA_2_ACC_DIR"] + "/simulate/stimulus/system/" + "input_data_32bit_stim.csv"
stimulus_generation(in_file, accelerator_address, accelerator_size) stimulus_generation(in_file, accelerator_input_address, accelerator_input_size)
\ No newline at end of file \ No newline at end of file
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment