FPGA: Add CPU instruction address SPI access control

Add logic that checks if the CPU is reading an instruction
      to execute from ROM or not. If instructions are read
      from ROM, access to the SPI from the API is granted, and
      signals between the SPI master and a slave are allowed.

      If instructions are not read from ROM, any API access
      is blocked. and between the SPI master and a
      slave are disabled.

Signed-off-by: Joachim Strömbergson <joachim@assured.se>
This commit is contained in:
Joachim Strömbergson 2024-06-24 15:13:10 +02:00 committed by dehanj
parent d297514e7e
commit 82c0c1459b
No known key found for this signature in database
GPG Key ID: 3707A9DBF4BB8F1A

View File

@ -106,6 +106,8 @@ module tk1(
localparam FW_RAM_FIRST = 32'hd0000000; localparam FW_RAM_FIRST = 32'hd0000000;
localparam FW_RAM_LAST = 32'hd00007ff; localparam FW_RAM_LAST = 32'hd00007ff;
localparam ROM_PREFIX = 2'h0;
//---------------------------------------------------------------- //----------------------------------------------------------------
// Registers including update variables and write enable. // Registers including update variables and write enable.
@ -156,6 +158,8 @@ module tk1(
reg force_trap_reg; reg force_trap_reg;
reg force_trap_set; reg force_trap_set;
reg spi_access_ok;
//---------------------------------------------------------------- //----------------------------------------------------------------
// Wires. // Wires.
@ -223,13 +227,13 @@ module tk1(
.clk(clk), .clk(clk),
.reset_n(reset_n), .reset_n(reset_n),
.spi_ss(spi_ss), .spi_ss((spi_ss & ~spi_access_ok)),
.spi_sck(spi_sck), .spi_sck((spi_sck & spi_access_ok)),
.spi_mosi(spi_mosi), .spi_mosi((spi_mosi & spi_access_ok)),
.spi_miso(spi_miso), .spi_miso((spi_miso & spi_access_ok)),
.spi_enable(spi_enable), .spi_enable((spi_enable & spi_access_ok)),
.spi_enable_vld(spi_enable_vld), .spi_enable_vld((spi_enable_vld & spi_access_ok)),
.spi_start(spi_start), .spi_start(spi_start),
.spi_tx_data(spi_tx_data), .spi_tx_data(spi_tx_data),
.spi_tx_data_vld(spi_tx_data_vld), .spi_tx_data_vld(spi_tx_data_vld),
@ -373,6 +377,23 @@ module tk1(
end end
//----------------------------------------------------------------
// spi_access_control
//
// Logic thar controls if any access to the SPI master is done
// by FW-code.
//----------------------------------------------------------------
always @*
begin : spi_access_control
if ((cpu_valid & cpu_instr) & (cpu_addr[31 : 30] == ROM_PREFIX)) begin
spi_access_ok = 1'h1;
end
else begin
spi_access_ok = 1'h0;
end
end
//---------------------------------------------------------------- //----------------------------------------------------------------
// security_monitor // security_monitor
// //