diff --git a/hdl/src/message_build.sv b/hdl/src/message_build.sv index 2d530b02884bd5d7aef6f570126dc411e7ead9ba..631e167002d312b8e894f88d77520282ccd110cf 100644 --- a/hdl/src/message_build.sv +++ b/hdl/src/message_build.sv @@ -30,7 +30,7 @@ module message_build ( logic [2:0] state, next_state; // State Machine State logic [53:0] data_word_count, next_data_word_count; - logic next_data_in_ready, next_cfg_ready, next_data_out_valid; + logic next_data_in_ready, next_cfg_ready, next_data_out_valid, next_data_out_last; logic [511:0] next_data_out; logic [511:0] last_word_mask; @@ -62,6 +62,7 @@ module message_build ( cfg_size_reg <= 64'd0; data_word_rem <= 9'd0; data_out_valid <= 1'b0; + data_out_last <= 1'b0; data_out <= 512'd0; data_word_count <= 54'd0; end else begin @@ -71,6 +72,7 @@ module message_build ( cfg_size_reg <= next_cfg_size; data_word_rem <= next_data_word_rem; data_out_valid <= next_data_out_valid; + data_out_last <= next_data_out_last; data_out <= next_data_out; data_word_count <= next_data_word_count; end @@ -84,6 +86,7 @@ module message_build ( next_cfg_size = cfg_size_reg; next_data_word_rem = data_word_rem; next_data_out_valid = data_out_valid; + next_data_out_last = data_out_last; next_data_out = data_out; next_data_word_count = data_word_count; @@ -95,6 +98,12 @@ module message_build ( end 3'd1: begin // Initial Config Read + if (!(data_out_valid && !data_out_ready)) begin + // If data out handshake has been seen, drop valid + next_data_out_valid = 1'b0; + next_data_out_last = 1'b0; + end + // If there is no Valid data at the output or there is a valid transfer happening on this clock cycle if (cfg_valid == 1'b1) begin // Handshake to Acknowledge Config Has been Read next_cfg_size = cfg_size; @@ -120,6 +129,7 @@ module message_build ( // These can be overloaded later if data is written to the outputs next_data_out_valid = 1'b0; next_data_in_ready = 1'b1; + next_data_out_last = 1'b0; // Check Inputs have data if (data_in_valid && data_in_ready) begin // Valid Handshake and data can be processed @@ -153,6 +163,7 @@ module message_build ( // If can't fit size in last word next_data_out = last_data_word; next_data_out_valid = 1'b1; + next_data_out_last = 1'b0; // NEXT STATE: Generate Additional Word next_state = 3'd4; next_data_in_ready = 1'b0; @@ -160,6 +171,7 @@ module message_build ( // Size can fit in last data word next_data_out = last_data_word | {448'd0, cfg_size_reg}; next_data_out_valid = 1'b1; + next_data_out_last = 1'b1; // NEXT STATE: Read Next Config next_state = 3'd1; next_data_in_ready = 1'b0; @@ -179,6 +191,7 @@ module message_build ( // Size can fit in last data word next_data_out = {~|data_word_rem, 447'd0, cfg_size_reg}; next_data_out_valid = 1'b1; + next_data_out_last = 1'b1; // NEXT STATE: Read Next Config next_state = 3'd1; next_data_in_ready = 1'b0; diff --git a/hdl/verif/tb_engine.sv b/hdl/verif/tb_engine.sv index a7ceaab323fb577cf0a46924ac745aaf5eace083..ec1bd0a45a011a02f6d6d464d431ac85fcac50be 100644 --- a/hdl/verif/tb_engine.sv +++ b/hdl/verif/tb_engine.sv @@ -8,9 +8,9 @@ // // Copyright 2022, SoC Labs (www.soclabs.org) //----------------------------------------------------------------------------- - `timescale 1ns/1ns `include "message_build.sv" + module tb_engine; logic clk; @@ -74,16 +74,16 @@ module tb_engine; logic [511:0] temp_data ; + int fd; // File descriptor handle + string str1,str2,str3,str4,str5; + initial begin $dumpfile("engine_sim.vcd"); $dumpvars(0, tb_engine); - - // for (int idx = 0; idx < 4; idx = idx + 1) begin - // $dumpvars(0, uut.data_in_fifo [idx]); - // $dumpvars(0, uut.cfg_size_fifo [idx]); - // $dumpvars(0, uut.cfg_scheme_fifo[idx]); - // end - + fd = $fopen("input_builder_stim.csv", "r"); + + $fscanf(fd, "%s,%s,%s,%s,%s", str1, str2, str3, str4, str5); + $fclose(fd); data_in_drive_en = 0; for (int idx_1 = 0; idx_1 < 20; idx_1 = idx_1 + 1) begin diff --git a/model/py/builder.py b/model/py/builder.py new file mode 100644 index 0000000000000000000000000000000000000000..0ea1e2b9b44a59bb80a9a8fa5e3c841eba1a59e4 --- /dev/null +++ b/model/py/builder.py @@ -0,0 +1,89 @@ +#----------------------------------------------------------------------------- +# SoC Labs Basic SHA-2 Message Builder Python Reference +# A joint work commissioned on behalf of SoC Labs, under Arm Academic Access license. +# +# Contributors +# +# David Mapstone (d.a.mapstone@soton.ac.uk) +# +# Copyright 2022, SoC Labs (www.soclabs.org) +#----------------------------------------------------------------------------- + +import sys, random, math, csv + +def main(argv): + # Read in Descriptor File + # - contains number of packets of data to generate and random seed + # input_file = argv[1] + seed = 1 # Needs to be loaded in from file + packets = 1 + random.seed(seed) + + for i in range(packets): + # Generate expected output in 512 bit chunks + cfg_size = random.randint(0,pow(2,14)) + print(cfg_size) + 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) + # Generate Random Data using Size + data = "{0:b}".format(random.getrandbits(cfg_size)) + + chunked_data_words = chunkstring(str(data),512) + print(len(chunked_data_words)) + print(len(chunked_data_words[-1])) + in_data_words = chunked_data_words.copy() + in_data_words[-1] = in_data_words[-1] + "0"*(512-len(in_data_words[-1])) + print(in_data_words[-1]) + in_data_words_last = [] + out_data_words = chunked_data_words.copy() + out_data_words_last = [] + last_len = len(chunked_data_words[-1]) + print(last_len) + if (last_len == 512): + out_data_words.append("1" + "0"*447 + cfg_size_str) + else: + out_data_words[-1] = out_data_words[-1] + "1" + if last_len > 447: # Size can't fit in last word + # Pad last word to 512 bits + out_data_words[-1] = out_data_words[-1] + "0"*(512 - len(out_data_words[-1])) + # Create New word with Size at the end + out_data_words.append("0"*448 + cfg_size_str) + else: + out_data_words[-1] = out_data_words[-1] + "0"*(512 - 64- len(out_data_words[-1])) + cfg_size_str + + for i in range(len(in_data_words) - 1): + in_data_words_last.append("0") + in_data_words_last.append("1") + + for i in range(len(out_data_words) - 1): + out_data_words_last.append("0") + out_data_words_last.append("1") + + # Ouptut Input Data Stimulus to Text File + input_header = ["cfg_size", "cfg_scheme", "cfg_last", "data_in", "data_in_last"] + with open("input_builder_stim.csv", "w", encoding="UTF8", newline='') as f: + writer = csv.writer(f) + # Write Header Row + writer.writerow(input_header) + for idx, word in enumerate(in_data_words): + writer.writerow([cfg_size_str, "00", "1", word, in_data_words_last[idx]]) + + # Output Expected output to text file + output_header = ["data_in", "data_in_last"] + with open("output_builder_stim.csv", "w", encoding="UTF8", newline='') as f: + writer = csv.writer(f) + # Write Header Row + writer.writerow(output_header) + for idx, word in enumerate(out_data_words): + writer.writerow([word, out_data_words_last[idx]]) + +def chunkstring(string, length): + array_len = math.ceil(len(string)/length) + array = [] + for i in range(array_len): + array.append(string[i*length:i*length + length]) + return array + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/model/py/input_builder_stim.csv b/model/py/input_builder_stim.csv new file mode 100644 index 0000000000000000000000000000000000000000..c66aaf0ebc34b93e7c319c932739880654753cd7 --- /dev/null +++ b/model/py/input_builder_stim.csv @@ -0,0 +1,10 @@ +cfg_size,cfg_scheme,cfg_last,data_in,data_in_last +0000000000000000000000000000000000000000000000000001000100110010,00,1,11001001010110001110101110000011100010000011111101000010101011100001110000100010000101001111010000010000110100100110001110100100000000011111000110001101110100001011000100001010110000010001010000011110100010101101010011110110000001000000001100111000001011111110010100001011000010110001000101011110101111001010111111110110010001001100011111011110011111011101100000101000010101100101010110001101001101011110001101001110101001011110110001011001111111010011110101010011111100001111110101011100111010111100011000111111,0 +0000000000000000000000000000000000000000000000000001000100110010,00,1,00001001101001111010111011111101111010011110100010010110001001010001101101001100010101010001011001010000110101111011010100001000001111011011101010110011101111111011011001011110111001100001000101010111101011000101111100110010100100001110011000011111000100100001101001110001101111010111100000010011110111100000010001101011010101111010101111101101001110001000101000100100010010110110010001101101000011001011001001011001011010010101111001000000101011010010001111100010111110000110111111011010010100101110110001010000,0 +0000000000000000000000000000000000000000000000000001000100110010,00,1,00110010011011111011111111101011000110001000101101110000111101010001001001100010011111001001101000001110001101000100101100110101110101110101000010100100010111110101010110001001101001101101010011000111100011101001100001001100111111101111101011010101110011001001001010100101011101001000000011110001101011100110101000111110100111000000011011000000111111001110000011111011001101100000011110011010001011001111101111001101100010111101011101110111110111010100100011111110010000000001101000110100010110110101101100001000,0 +0000000000000000000000000000000000000000000000000001000100110010,00,1,01010100111110111111110010010011100001111010011101011100010110011001100111010100011100101010001000110110111010100010101010010101110000010111101101011111000111110110111000000101000011110111100101010010011110000010010111110000000111101101100001101110000100101011101001011110110111001010000000110011111101101111111100001011101010011001100001010000100011101010001011001101000101111100101111000110110000111000110011001100110011110001111111010010001101101011001110101001111101100000101001000110010110100100011100111001,0 +0000000000000000000000000000000000000000000000000001000100110010,00,1,11100101001000111111010101001000010101000111100001101011001101011100000101001111001101010100010101100010010111010000001011000000001011001011101011110110100101111100010011101100101001010001011110010000010101010111100111100011001001010111101110111010110101000100100101001010011000010110011010111100010011010001110000000001000001000101010011010110101000101111100100011110100111011000110100001000111011111010110000111111111010010100000000011101110101011011011000011100110001101100010000011010010001010011111101110110,0 +0000000000000000000000000000000000000000000000000001000100110010,00,1,11000110100010100111100000110110100111111111011110111000000011001011001101010000011000011100000011110100010001111001110001100000011001000111111011000011100010010101110001011110000000111011011110011011110000111101110011101000101111001111000000110110000001111110101001111010111111000000100110000110001000010001101110111001100001110110111111010111110111101011001111111100101100001100101101001100111001111111000011001100010001010110110011111000001101100000101000100101000000010010110110100000100111111100010101001101,0 +0000000000000000000000000000000000000000000000000001000100110010,00,1,00000001000011110101001100100100010100111110111010000011010000011100111101011100100000101101101101110011011100011000001111101010010111110110111000101000101000011000100011001001111100110110000111111001100111001000110100010101110001111000111111111000111111101010000101010001010010111010101011101010011000001001110101001000000101001001100011100110101000100011111100011010110111000101101101101100011111110010001000010111000111101010000110111001000000100111001010010110110110010001000100001101001011000000000001000101,0 +0000000000000000000000000000000000000000000000000001000100110010,00,1,00000010110100110110001000110010001110001010110011100001100100100110010011000010110011011100000010000111001110110011011101100100111010010100001100110001111001010100000101000110111010101111101001011001110110010111001001011000001101100111001100000011101000001110001111010100001111100111001000010110010000010000110000000011100101110100011000011010110111111100110010010110111001001111010011100011000010110011000010010111001110110100101101010011011001110110011000001101101111000111001010001000001100001011100110001000,0 +0000000000000000000000000000000000000000000000000001000100110010,00,1,11101100010100011110000101100111001101111010001000111111011010100110101010111101100011110001011111110101110001001010000010100110000110100001111000001000000100111110001001101000111000011100001101011101111000100110011010110000100111110001100001101100011110001011010101101111110010001101101110101100001001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,1 diff --git a/model/py/output_builder_stim.csv b/model/py/output_builder_stim.csv new file mode 100644 index 0000000000000000000000000000000000000000..2274bb2fc01e466d576f1b30d522620c6eeefb3b --- /dev/null +++ b/model/py/output_builder_stim.csv @@ -0,0 +1,10 @@ +data_in,data_in_last +11001001010110001110101110000011100010000011111101000010101011100001110000100010000101001111010000010000110100100110001110100100000000011111000110001101110100001011000100001010110000010001010000011110100010101101010011110110000001000000001100111000001011111110010100001011000010110001000101011110101111001010111111110110010001001100011111011110011111011101100000101000010101100101010110001101001101011110001101001110101001011110110001011001111111010011110101010011111100001111110101011100111010111100011000111111,0 +00001001101001111010111011111101111010011110100010010110001001010001101101001100010101010001011001010000110101111011010100001000001111011011101010110011101111111011011001011110111001100001000101010111101011000101111100110010100100001110011000011111000100100001101001110001101111010111100000010011110111100000010001101011010101111010101111101101001110001000101000100100010010110110010001101101000011001011001001011001011010010101111001000000101011010010001111100010111110000110111111011010010100101110110001010000,0 +00110010011011111011111111101011000110001000101101110000111101010001001001100010011111001001101000001110001101000100101100110101110101110101000010100100010111110101010110001001101001101101010011000111100011101001100001001100111111101111101011010101110011001001001010100101011101001000000011110001101011100110101000111110100111000000011011000000111111001110000011111011001101100000011110011010001011001111101111001101100010111101011101110111110111010100100011111110010000000001101000110100010110110101101100001000,0 +01010100111110111111110010010011100001111010011101011100010110011001100111010100011100101010001000110110111010100010101010010101110000010111101101011111000111110110111000000101000011110111100101010010011110000010010111110000000111101101100001101110000100101011101001011110110111001010000000110011111101101111111100001011101010011001100001010000100011101010001011001101000101111100101111000110110000111000110011001100110011110001111111010010001101101011001110101001111101100000101001000110010110100100011100111001,0 +11100101001000111111010101001000010101000111100001101011001101011100000101001111001101010100010101100010010111010000001011000000001011001011101011110110100101111100010011101100101001010001011110010000010101010111100111100011001001010111101110111010110101000100100101001010011000010110011010111100010011010001110000000001000001000101010011010110101000101111100100011110100111011000110100001000111011111010110000111111111010010100000000011101110101011011011000011100110001101100010000011010010001010011111101110110,0 +11000110100010100111100000110110100111111111011110111000000011001011001101010000011000011100000011110100010001111001110001100000011001000111111011000011100010010101110001011110000000111011011110011011110000111101110011101000101111001111000000110110000001111110101001111010111111000000100110000110001000010001101110111001100001110110111111010111110111101011001111111100101100001100101101001100111001111111000011001100010001010110110011111000001101100000101000100101000000010010110110100000100111111100010101001101,0 +00000001000011110101001100100100010100111110111010000011010000011100111101011100100000101101101101110011011100011000001111101010010111110110111000101000101000011000100011001001111100110110000111111001100111001000110100010101110001111000111111111000111111101010000101010001010010111010101011101010011000001001110101001000000101001001100011100110101000100011111100011010110111000101101101101100011111110010001000010111000111101010000110111001000000100111001010010110110110010001000100001101001011000000000001000101,0 +00000010110100110110001000110010001110001010110011100001100100100110010011000010110011011100000010000111001110110011011101100100111010010100001100110001111001010100000101000110111010101111101001011001110110010111001001011000001101100111001100000011101000001110001111010100001111100111001000010110010000010000110000000011100101110100011000011010110111111100110010010110111001001111010011100011000010110011000010010111001110110100101101010011011001110110011000001101101111000111001010001000001100001011100110001000,0 +11101100010100011110000101100111001101111010001000111111011010100110101010111101100011110001011111110101110001001010000010100110000110100001111000001000000100111110001001101000111000011100001101011101111000100110011010110000100111110001100001101100011110001011010101101111110010001101101110101100001001010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000100110010,1