diff options
-rw-r--r-- | src/rtl/keywrap_mkmif.v | 142 | ||||
-rw-r--r-- | src/tb/tb_keywrap_mkmif.v | 42 |
2 files changed, 131 insertions, 53 deletions
diff --git a/src/rtl/keywrap_mkmif.v b/src/rtl/keywrap_mkmif.v index 88af6f8..2f7bebf 100644 --- a/src/rtl/keywrap_mkmif.v +++ b/src/rtl/keywrap_mkmif.v @@ -63,13 +63,16 @@ module keywrap_mkmif ( //---------------------------------------------------------------- // Paramenters and local defines. //---------------------------------------------------------------- - localparam CTRL_IDLE = 3'h0; - localparam CTRL_WAIT = 3'h1; - localparam CTRL_READ_STATUS_WAIT = 3'h2; - localparam CTRL_READ_KEY = 3'h3; - localparam CTRL_READ_KEY_WAIT = 3'h4; - localparam CTRL_WRITE_KEY = 3'h5; - localparam CTRL_WRITE_KEY_WAIT = 3'h6; + localparam CTRL_IDLE = 4'h0; + localparam CTRL_WAIT = 4'h1; + localparam CTRL_INIT = 4'h2; + localparam CTRL_READ = 4'h3; + localparam CTRL_READ_STATUS_WAIT = 4'h4; + localparam CTRL_READ_KEY = 4'h5; + localparam CTRL_READ_KEY_WAIT = 4'h6; + localparam CTRL_WRITE = 4'h8; + localparam CTRL_WRITE_KEY = 4'h9; + localparam CTRL_WRITE_KEY_WAIT = 4'ha; // Addresses for storage in the mkm localparam MKM_STATUS_WORD = 16'h00; @@ -106,10 +109,14 @@ module keywrap_mkmif ( reg ready_new; reg ready_we; - reg [2 : 0] keywrap_mkmif_ctrl_reg; - reg [2 : 0] keywrap_mkmif_ctrl_new; + reg [3 : 0] keywrap_mkmif_ctrl_reg; + reg [3 : 0] keywrap_mkmif_ctrl_new; reg keywrap_mkmif_ctrl_we; + reg init_op_reg; + reg read_op_reg; + reg write_op_reg; + //---------------------------------------------------------------- // Wires. @@ -136,9 +143,9 @@ module keywrap_mkmif ( .spi_do(mkm_spi_do), .spi_di(mkm_spi_di), - .init_op(mkm_init_op), - .read_op(mkm_read_op), - .write_op(mkm_write_op), + .init_op(init_op_reg), + .read_op(read_op_reh), + .write_op(write_op_reg), .ready(mkm_ready), .valid(mkm_valid), @@ -178,11 +185,18 @@ module keywrap_mkmif ( mkm_addr_reg <= 16'h0; mkm_write_data_reg <= 32'h0; key_word_ctr_reg <= 3'h0; + init_op_reg <= 1'h0; + read_op_reg <= 1'h0; + write_op_reg <= 1'h0; keywrap_mkmif_ctrl_reg <= CTRL_IDLE; end else begin + init_op_reg <= mkm_init_op; + read_op_reg <= mkm_read_op; + write_op_reg <= mkm_write_op; + if (ready_we) ready_reg <= ready_new; @@ -259,52 +273,50 @@ module keywrap_mkmif ( mkm_init_op = 1'h1; ready_new = 1'h0; ready_we = 1'h1; - keywrap_mkmif_ctrl_new = CTRL_WAIT; + keywrap_mkmif_ctrl_new = CTRL_INIT; keywrap_mkmif_ctrl_we = 1'h1; end if (read) begin - ready_new = 1'h0; - ready_we = 1'h1; - - if (key_status) - begin - key_word_ctr_rst = 1'h1; - keywrap_mkmif_ctrl_new = CTRL_READ_KEY; - keywrap_mkmif_ctrl_we = 1'h1; - end - else - begin - mkm_read_op = 1'h1; - mkm_addr_new = MKM_STATUS_WORD; - mkm_addr_we = 1'h1; - keywrap_mkmif_ctrl_new = CTRL_READ_STATUS_WAIT; - keywrap_mkmif_ctrl_we = 1'h1; - end + ready_new = 1'h0; + ready_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_READ; + keywrap_mkmif_ctrl_we = 1'h1; end if (write) begin - ready_new = 1'h0; - ready_we = 1'h1; - - if (key_status) - begin - key_word_ctr_rst = 1'h1; - keywrap_mkmif_ctrl_new = CTRL_WRITE_KEY; - keywrap_mkmif_ctrl_we = 1'h1; - end - else - begin - mkm_write_op = 1'h1; - mkm_addr_new = MKM_STATUS_WORD; - mkm_addr_we = 1'h1; - mkm_write_data_new = wr_status; - mkm_write_data_we = 1'h1; - keywrap_mkmif_ctrl_new = CTRL_WAIT; - keywrap_mkmif_ctrl_we = 1'h1; - end + ready_new = 1'h0; + ready_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WRITE; + keywrap_mkmif_ctrl_we = 1'h1; + end + end + + + CTRL_INIT: + begin + keywrap_mkmif_ctrl_new = CTRL_WAIT; + keywrap_mkmif_ctrl_we = 1'h1; + end + + + CTRL_READ: + begin + if (key_status) + begin + key_word_ctr_rst = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_READ_KEY; + keywrap_mkmif_ctrl_we = 1'h1; + end + else + begin + mkm_read_op = 1'h1; + mkm_addr_new = MKM_STATUS_WORD; + mkm_addr_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_READ_STATUS_WAIT; + keywrap_mkmif_ctrl_we = 1'h1; end end @@ -320,8 +332,13 @@ module keywrap_mkmif ( end end + CTRL_READ_STATUS_WAIT: begin + ready_new = 1'h1; + ready_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_IDLE; + keywrap_mkmif_ctrl_we = 1'h1; if (mkm_ready) begin status_we = 1'h1; @@ -332,6 +349,7 @@ module keywrap_mkmif ( end end + CTRL_READ_KEY: begin if (key_word_ctr_reg < 8) @@ -351,6 +369,7 @@ module keywrap_mkmif ( end end + CTRL_READ_KEY_WAIT: begin if (mkm_ready) @@ -362,6 +381,28 @@ module keywrap_mkmif ( end end + + CTRL_WRITE: + begin + if (key_status) + begin + key_word_ctr_rst = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WRITE_KEY; + keywrap_mkmif_ctrl_we = 1'h1; + end + else + begin + mkm_write_op = 1'h1; + mkm_addr_new = MKM_STATUS_WORD; + mkm_addr_we = 1'h1; + mkm_write_data_new = wr_status; + mkm_write_data_we = 1'h1; + keywrap_mkmif_ctrl_new = CTRL_WAIT; + keywrap_mkmif_ctrl_we = 1'h1; + end + end + + CTRL_WRITE_KEY: begin if (key_word_ctr_reg < 8) @@ -383,6 +424,7 @@ module keywrap_mkmif ( end end + CTRL_WRITE_KEY_WAIT: begin if (mkm_ready) @@ -393,9 +435,9 @@ module keywrap_mkmif ( end end + default: begin - end endcase // case (keywrap_mkmif_ctrl_reg) end // keywrap_mkmif_ctrl diff --git a/src/tb/tb_keywrap_mkmif.v b/src/tb/tb_keywrap_mkmif.v index 3289a77..b275499 100644 --- a/src/tb/tb_keywrap_mkmif.v +++ b/src/tb/tb_keywrap_mkmif.v @@ -215,7 +215,7 @@ module tb_keywrap_mkmif(); tc_ctr = 0; show_spi = 0; - show_dut_state = 1; + show_dut_state = 0; show_mem_state = 0; show_mkm_state = 0; @@ -303,7 +303,7 @@ module tb_keywrap_mkmif(); tc_ctr = tc_ctr + 1; $display("TEST WRITE-STATUS START"); - $display("Check that we can write the key status word."); + $display("Check that we can write the status word."); // Observe SPI for a number of cycles. Reset the DUT during observation. show_spi = 0; @@ -337,6 +337,41 @@ module tb_keywrap_mkmif(); //---------------------------------------------------------------- + // test_read_status + // Note: This test should be called after test_write_status. + // If not the contents of the memort will be undefined. + //---------------------------------------------------------------- + task test_read_status; + begin + tc_ctr = tc_ctr + 1; + + $display("TEST READ-STATUS START"); + $display("Check that we can read the status word."); + + // Observe SPI for a number of cycles. Reset the DUT during observation. + show_spi = 0; + show_dut_state = 1; + #(10 * CLK_PERIOD); + + $display("Trying to read 0xdeadbeef from the status address."); + tb_key_status = 1'h0; + tb_read = 1'h1; + + #(CLK_PERIOD); + tb_read = 1'h0; + + wait_ready(); + show_spi = 0; + + $display("The word read: 0x%04x", tb_rd_status); + + $display("TEST READ-STATUS END"); + $display(""); + end + endtask // test_read_status + + + //---------------------------------------------------------------- // test_write_key //---------------------------------------------------------------- task test_write_key; @@ -383,7 +418,8 @@ module tb_keywrap_mkmif(); dump_mem(); test_init_mem(); test_write_status(); - test_write_key(); +// test_read_status(); +// test_write_key(); dump_mem(); $display(""); |