diff --git a/README.md b/README.md index e6cd410209799bdafcfe3435dfe96b27092a6946..d913a32d0270132a5d5dcfa2d8dbd4194075b53e 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,26 @@ To be able to simulate in this repository, you will first need to source the sou ``` % source sourceme ``` + +## Stimulus Generation +Under `model/py`, there is `hash_model.py` which is a python model of the hashing accelerator. This produces numerous `.csv` files which can be fed in testbenches. These files are seperated into two types: +- stimiulus +- reference + +Stimulus files are used to stimulate the DUT by feeding into the inputs of the module. Reference files are used to compare to the output of the DUT to check whether it is behaving correctly. + +These files are present in the `simulate/stimulus/unit/` or `simulate/stimulus/system/` directories. Unit contains stimulus and reference files for unit tests - internal wrapper engine verification. System contains stimulus and reference files for System and Wrapper tests. + +The `simulate/stimulus/model/` directory contains a hand-written stimulus file which is used to seed and constrain the python model. There are `5` values in this file and are listed as follows: +- Seed - random seed used to seed python model +- Payload Number - Number of payloads to generate +- Payload Size (Bits) - Number of bits a payload is comprised of. If set to 0, this is randomised each payload. If non-zero, each payload will have a size of this value. +- Gap Limit - Maximum number of clock cycles to gap on the input (cycles to wait before asserting valid on the input data) +- Stall Limit - Maximum number of clock cycles to stall on the output (cycles to wait before asseting ready on the output) + +To generate the stimulus and reference, ensure the `sourceme` in the root of this repo has been sourced and then run `python3 hash_model.py` within the `model/py` directory. This will populate the directories with the `.csv` files in the `simulate/stimulus` directory. + +## Simulation Setup This will set up the environment variables and will set the simulator used. Defaultly, this is set to ivlog - Icarus Verilog. This can be overloaded from the command line with the following command: ``` % SIMULATOR=yoursimulator diff --git a/model/py/hash_model.py b/model/py/hash_model.py index ce88343708093bf89d870404d0b933b1413901b9..712a831c097929cd32ca888b62bfcc83c34a77ad 100644 --- a/model/py/hash_model.py +++ b/model/py/hash_model.py @@ -19,19 +19,20 @@ def main(): print("Sourceme file at root of repository has not been sourced. Please source this file and try again.") quit() # Read in Descriptor File - # - contains number of packets of data to generate and random seed + # - contains number of payloads of data to generate and random seed stim_file = os.environ["SHA_2_ACC_DIR"] + "/simulate/stimulus/model/" + "model_stim.csv" with open(stim_file, "r") as stim: csvreader = csv.reader(stim, delimiter=",") stim_list = list(csvreader) - seed = int(stim_list[0][0]) - packets = int(stim_list[0][1]) - gap_limit = int(stim_list[0][2]) - stall_limit = int(stim_list[0][3]) + seed = int(stim_list[0][0]) + payloads = int(stim_list[0][1]) + payload_size_bits = int(stim_list[0][2]) + gap_limit = int(stim_list[0][3]) + stall_limit = int(stim_list[0][4]) random.seed(seed) - print(f"Generating {packets} packets using seed: {seed}") + print(f"Generating {payloads} payloads using seed: {seed}") in_cfg_words_list = [] in_cfg_words_gap_list = [] sync_cfg_size_list = [] @@ -73,9 +74,9 @@ def main(): id_validator_hash_stall_list = [] val_hash_list = [] - prev_packet_hash_err = False + prev_payload_hash_err = False - for i in range(packets): + for i in range(payloads): # Generate Gapping and Stalling Values # Gapping - Period to wait before taking Input Valid High # Stalling - Period to wait before taking Output Read High @@ -95,7 +96,10 @@ def main(): sync_cfg_stall_list.append(0) # Generate expected output in 512 bit chunks - cfg_size = math.ceil(random.randint(0,pow(2,14))/8)*8 + if payload_size_bits == 0: + cfg_size = math.ceil(random.randint(0,pow(2,14))/8)*8 + else: + cfg_size = payload_size_bits cfg_size_bin = "{0:b}".format(cfg_size) # Pad Size to 64 bits cfg_size_str = "0"*(64-len(cfg_size_bin)) + str(cfg_size_bin) diff --git a/simulate/stimulus/model/model_stim.csv b/simulate/stimulus/model/model_stim.csv index 17ed18b583ffe61644a7bd372898bb18bf0a8c24..38e50e20950399b5e34462d65bbade1573ff8bdf 100644 --- a/simulate/stimulus/model/model_stim.csv +++ b/simulate/stimulus/model/model_stim.csv @@ -1 +1 @@ -4048473887,100,3,3 \ No newline at end of file +4048473887,100,0,3,3 \ No newline at end of file