diff --git a/hw/application_fpga/core/tk1/rtl/tk1.v b/hw/application_fpga/core/tk1/rtl/tk1.v index 2dc6dfb..8bd4732 100644 --- a/hw/application_fpga/core/tk1/rtl/tk1.v +++ b/hw/application_fpga/core/tk1/rtl/tk1.v @@ -547,7 +547,9 @@ module tk1 #( end if (address == ADDR_SYSTEM_RESET) begin - system_reset_new = 1'h1; + if (!app_mode) begin + system_reset_new = 1'h1; + end end if ((address >= ADDR_CDI_FIRST) && (address <= ADDR_CDI_LAST)) begin diff --git a/hw/application_fpga/core/tk1/tb/tb_tk1.v b/hw/application_fpga/core/tk1/tb/tb_tk1.v index 1422701..83dd943 100644 --- a/hw/application_fpga/core/tk1/tb/tb_tk1.v +++ b/hw/application_fpga/core/tk1/tb/tb_tk1.v @@ -56,6 +56,8 @@ module tb_tk1 (); localparam ADDR_CPU_MON_FIRST = 8'h61; localparam ADDR_CPU_MON_LAST = 8'h62; + localparam ADDR_SYSTEM_RESET = 8'h70; + localparam ADDR_SPI_EN = 8'h80; localparam ADDR_SPI_XFER = 8'h81; localparam ADDR_SPI_DATA = 8'h82; @@ -84,6 +86,7 @@ module tb_tk1 (); reg tb_cpu_instr; reg tb_cpu_valid; wire tb_force_trap; + wire tb_system_reset; wire [14 : 0] tb_ram_addr_rand; wire [31 : 0] tb_ram_data_rand; @@ -132,6 +135,7 @@ module tb_tk1 (); .cpu_instr (tb_cpu_instr), .cpu_valid (tb_cpu_valid), .force_trap(tb_force_trap), + .system_reset(tb_system_reset), .ram_addr_rand(tb_ram_addr_rand), .ram_data_rand(tb_ram_data_rand), @@ -1120,6 +1124,45 @@ module tb_tk1 (); endtask // test12 + //---------------------------------------------------------------- + // test13() + // System reset + //---------------------------------------------------------------- + task test13; + begin + tc_ctr = tc_ctr + 1; + + $display(""); + $display("--- test13: Reset allowed from firmware mode."); + tb_syscall = 0; + reset_dut(); + + write_word(ADDR_SYSTEM_RESET, 32'h1); + check_equal(tb_system_reset, 1); + + $display("--- test13: Reset not allowed from app mode."); + reset_dut(); + fetch_instruction(APP_RAM_START); + + write_word(ADDR_SYSTEM_RESET, 32'h1); + check_equal(tb_system_reset, 0); + + $display("--- test13: Reset allowed from syscall."); + reset_dut(); + fetch_instruction(APP_RAM_START); + tb_syscall = 1; + + write_word(ADDR_SYSTEM_RESET, 32'h1); + check_equal(tb_system_reset, 1); + + tb_syscall = 0; + + $display("--- test13: completed."); + $display(""); + end + endtask // test13 + + //---------------------------------------------------------------- // exit_with_error_code() // @@ -1161,6 +1204,7 @@ module tb_tk1 (); test10(); test11(); test12(); + test13(); display_test_result(); $display(""); diff --git a/hw/application_fpga/fw/testapp/main.c b/hw/application_fpga/fw/testapp/main.c index bff3d9c..2bae8c8 100644 --- a/hw/application_fpga/fw/testapp/main.c +++ b/hw/application_fpga/fw/testapp/main.c @@ -20,6 +20,7 @@ volatile uint32_t *uds = (volatile uint32_t *)TK1_MMIO_UDS_FIRST; volatile uint32_t *cdi = (volatile uint32_t *)TK1_MMIO_TK1_CDI_FIRST; volatile uint32_t *udi = (volatile uint32_t *)TK1_MMIO_TK1_UDI_FIRST; volatile uint8_t *fw_ram = (volatile uint8_t *)TK1_MMIO_FW_RAM_BASE; +volatile uint32_t *system_reset = (volatile uint32_t *)TK1_MMIO_TK1_SYSTEM_RESET; volatile uint32_t *timer = (volatile uint32_t *)TK1_MMIO_TIMER_TIMER; volatile uint32_t *timer_prescaler = (volatile uint32_t *)TK1_MMIO_TIMER_PRESCALER; volatile uint32_t *timer_status = (volatile uint32_t *)TK1_MMIO_TIMER_STATUS; @@ -192,6 +193,11 @@ int main(void) anyfailed = 1; } + // Should NOT be able to reset Tkey from app mode + puts("\r\nTesting system reset..."); + *system_reset = 1; + puts("done.\r\n"); + // Test FW_RAM. *fw_ram = 0x21; if (*fw_ram == 0x21) { diff --git a/hw/application_fpga/fw/testfw/main.c b/hw/application_fpga/fw/testfw/main.c index 4613e14..04ca1d1 100644 --- a/hw/application_fpga/fw/testfw/main.c +++ b/hw/application_fpga/fw/testfw/main.c @@ -17,6 +17,7 @@ volatile uint32_t *uds = (volatile uint32_t *)TK1_MMIO_UDS_FIRST; volatile uint32_t *cdi = (volatile uint32_t *)TK1_MMIO_TK1_CDI_FIRST; volatile uint32_t *udi = (volatile uint32_t *)TK1_MMIO_TK1_UDI_FIRST; volatile uint8_t *fw_ram = (volatile uint8_t *)TK1_MMIO_FW_RAM_BASE; +volatile uint32_t *system_reset = (volatile uint32_t *)TK1_MMIO_TK1_SYSTEM_RESET; volatile uint32_t *timer = (volatile uint32_t *)TK1_MMIO_TIMER_TIMER; volatile uint32_t *timer_prescaler = (volatile uint32_t *)TK1_MMIO_TIMER_PRESCALER; volatile uint32_t *timer_status = (volatile uint32_t *)TK1_MMIO_TIMER_STATUS; @@ -355,9 +356,12 @@ int main(void) } puts("\r\n"); - puts("Now echoing what you type...\r\n"); + puts("Now echoing what you type...Type + to reset device\r\n"); for (;;) { in = readbyte(&mode, &mode_bytes_left); + if (in == '+') { + *system_reset = 1; + } writebyte(MODE_CDC); writebyte(1);