mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2024-12-12 09:24:26 -05:00
fpga: Add testcase for SPI access control
Add testcase that checks that access control is enabled and disabled as expected. Signed-off-by: Joachim Strömbergson <joachim@assured.se>
This commit is contained in:
parent
8c476e19c3
commit
148a8f0996
@ -61,6 +61,7 @@ module tb_tk1();
|
|||||||
localparam ADDR_SPI_EN = 8'h80;
|
localparam ADDR_SPI_EN = 8'h80;
|
||||||
localparam ADDR_SPI_XFER = 8'h81;
|
localparam ADDR_SPI_XFER = 8'h81;
|
||||||
localparam ADDR_SPI_DATA = 8'h82;
|
localparam ADDR_SPI_DATA = 8'h82;
|
||||||
|
localparam ADDR_SPI_CMD = 8'h83;
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
@ -86,9 +87,6 @@ module tb_tk1();
|
|||||||
wire [14 : 0] tb_ram_aslr;
|
wire [14 : 0] tb_ram_aslr;
|
||||||
wire [31 : 0] tb_ram_scramble;
|
wire [31 : 0] tb_ram_scramble;
|
||||||
|
|
||||||
reg tb_ram_access;
|
|
||||||
reg tb_rom_access;
|
|
||||||
|
|
||||||
wire tb_led_r;
|
wire tb_led_r;
|
||||||
wire tb_led_g;
|
wire tb_led_g;
|
||||||
wire tb_led_b;
|
wire tb_led_b;
|
||||||
@ -132,9 +130,6 @@ module tb_tk1();
|
|||||||
.cpu_valid(tb_cpu_valid),
|
.cpu_valid(tb_cpu_valid),
|
||||||
.force_trap(tb_force_trap),
|
.force_trap(tb_force_trap),
|
||||||
|
|
||||||
.ram_access(tb_ram_access),
|
|
||||||
.rom_access(tb_rom_access),
|
|
||||||
|
|
||||||
.ram_aslr(tb_ram_aslr),
|
.ram_aslr(tb_ram_aslr),
|
||||||
.ram_scramble(tb_ram_scramble),
|
.ram_scramble(tb_ram_scramble),
|
||||||
|
|
||||||
@ -283,9 +278,6 @@ module tb_tk1();
|
|||||||
tb_cpu_valid = 1'h0;
|
tb_cpu_valid = 1'h0;
|
||||||
tb_cpu_trap = 1'h0;
|
tb_cpu_trap = 1'h0;
|
||||||
|
|
||||||
tb_ram_access = 1'h0;
|
|
||||||
tb_rom_access = 1'h0;
|
|
||||||
|
|
||||||
tb_gpio1 = 1'h0;
|
tb_gpio1 = 1'h0;
|
||||||
tb_gpio2 = 1'h0;
|
tb_gpio2 = 1'h0;
|
||||||
|
|
||||||
@ -307,8 +299,7 @@ module tb_tk1();
|
|||||||
begin
|
begin
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
begin
|
begin
|
||||||
$display("--- Writing 0x%08x to 0x%02x.", word, address);
|
$display("--- Write word: 0x%08x to 0x%02x.", word, address);
|
||||||
$display("");
|
|
||||||
end
|
end
|
||||||
|
|
||||||
tb_address = address;
|
tb_address = address;
|
||||||
@ -371,13 +362,11 @@ module tb_tk1();
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
begin
|
begin
|
||||||
if (read_data == expected) begin
|
if (read_data == expected) begin
|
||||||
$display("--- Reading 0x%08x from 0x%02x.", read_data, address);
|
$display("--- Read word: 0x%08x from 0x%02x.", read_data, address);
|
||||||
end else begin
|
end else begin
|
||||||
$display("--- Error: Got 0x%08x when reading from 0x%02x, expected 0x%08x",
|
$display("--- Read word: Error. Got 0x%08x, expected 0x%08x", read_data, address, expected);
|
||||||
read_data, address, expected);
|
|
||||||
error_ctr = error_ctr + 1;
|
error_ctr = error_ctr + 1;
|
||||||
end
|
end
|
||||||
$display("");
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
endtask // read_check_word
|
endtask // read_check_word
|
||||||
@ -693,6 +682,13 @@ module tb_tk1();
|
|||||||
tb_monitor = 0;
|
tb_monitor = 0;
|
||||||
tb_spi_monitor = 0;
|
tb_spi_monitor = 0;
|
||||||
|
|
||||||
|
// We need to enable SPI access before testing.
|
||||||
|
dut.spi_access_ctrl_new = 1'h1;
|
||||||
|
dut.spi_access_ctrl_we = 1'h1;
|
||||||
|
#(CLK_PERIOD);
|
||||||
|
dut.spi_access_ctrl_new = 1'h0;
|
||||||
|
dut.spi_access_ctrl_we = 1'h0;
|
||||||
|
|
||||||
$display("");
|
$display("");
|
||||||
$display("--- test10: Loopback in SPI Master started.");
|
$display("--- test10: Loopback in SPI Master started.");
|
||||||
|
|
||||||
@ -711,7 +707,7 @@ module tb_tk1();
|
|||||||
end
|
end
|
||||||
$display("--- test10: Byte should have been sent.");
|
$display("--- test10: Byte should have been sent.");
|
||||||
|
|
||||||
// 0x58 is the inverse of 0xa7.
|
// Read back data. 0x58 is the inverse of 0xa7.
|
||||||
#(2 * CLK_PERIOD);
|
#(2 * CLK_PERIOD);
|
||||||
read_check_word(ADDR_SPI_DATA, 32'h58);
|
read_check_word(ADDR_SPI_DATA, 32'h58);
|
||||||
write_word(ADDR_SPI_EN, 32'h0);
|
write_word(ADDR_SPI_EN, 32'h0);
|
||||||
@ -737,32 +733,76 @@ module tb_tk1();
|
|||||||
$display("");
|
$display("");
|
||||||
$display("--- test11: SPI access control started.");
|
$display("--- test11: SPI access control started.");
|
||||||
|
|
||||||
// Read SPI ready. Access should be blocked after reset.
|
// Start by resetting and check if access is enabled.
|
||||||
$display("Status of access_ok_reg after reset: 0x%1x", dut.access_ok_reg);
|
$display("--- test11: Check that SPI access is disabled after reset.");
|
||||||
|
reset_dut();
|
||||||
read_word(ADDR_SPI_XFER, 32'h0);
|
read_word(ADDR_SPI_XFER, 32'h0);
|
||||||
|
$display("");
|
||||||
|
|
||||||
// Signal that we are performing access from ROM.
|
// Set the SPI command adress API to an address in ROM space.
|
||||||
// Then try to read SPI ready. This should be granted.
|
// Read it back to check that it has been set.
|
||||||
tb_rom_access = 1'h1;
|
$display("--- test11: Set and read SPI command address.");
|
||||||
|
write_word(ADDR_SPI_CMD, 32'h0000dead);
|
||||||
|
read_word(ADDR_SPI_CMD, 32'h0000dead);
|
||||||
|
$display("");
|
||||||
|
|
||||||
|
// Simulate CPU instruction read from the SPI command adress.
|
||||||
|
// And check that access has been enabled.
|
||||||
|
$display("--- test11: Perform CPU instruction read from SPI command address.");
|
||||||
|
$display("--- test11: Then check that SPI access is enabled.");
|
||||||
|
tb_cpu_addr = 32'h0000dead;
|
||||||
|
tb_cpu_instr = 1'h1;
|
||||||
|
tb_cpu_valid = 1'h1;
|
||||||
#(CLK_PERIOD);
|
#(CLK_PERIOD);
|
||||||
tb_rom_access = 1'h0;
|
tb_cpu_instr = 1'h0;
|
||||||
$display("Status of access_ok_reg after ROM access: 0x%1x", dut.access_ok_reg);
|
tb_cpu_valid = 1'h0;
|
||||||
read_word(ADDR_SPI_XFER, 32'h1);
|
read_word(ADDR_SPI_XFER, 32'h1);
|
||||||
|
$display("");
|
||||||
|
|
||||||
// Signal that we are performing access from RAM.
|
// Simulate CPU instruction read from a RAM address.
|
||||||
// Then try to read SPI ready. This should be blocked.
|
// And check that access has been disabled.
|
||||||
tb_ram_access = 1'h1;
|
$display("--- test11: Perform CPU instruction read from a RAM address.");
|
||||||
|
$display("--- test11: Then check that SPI access has been disabled.");
|
||||||
|
tb_cpu_addr = 32'h4000dead;
|
||||||
|
tb_cpu_instr = 1'h1;
|
||||||
|
tb_cpu_valid = 1'h1;
|
||||||
#(CLK_PERIOD);
|
#(CLK_PERIOD);
|
||||||
tb_ram_access = 1'h0;
|
tb_cpu_instr = 1'h0;
|
||||||
$display("Status of access_ok_reg after RAM access: 0x%1x", dut.access_ok_reg);
|
tb_cpu_valid = 1'h0;
|
||||||
read_word(ADDR_SPI_XFER, 32'h0);
|
read_word(ADDR_SPI_XFER, 32'h0);
|
||||||
|
$display("");
|
||||||
|
|
||||||
// Signal that we are performing access from ROM again.
|
|
||||||
// Then try to read SPI ready. This should be granted.
|
// Move the SPI command adress API to a new address in ROM space.
|
||||||
tb_rom_access = 1'h1;
|
// Read it back to check that it has been set.
|
||||||
|
$display("--- test11: Set SPI command address to a new address and read again.");
|
||||||
|
write_word(ADDR_SPI_CMD, 32'h0000cafe);
|
||||||
|
read_word(ADDR_SPI_CMD, 32'h0000cafe);
|
||||||
|
$display("");
|
||||||
|
|
||||||
|
// Simulate CPU instruction read from the old SPI command adress.
|
||||||
|
// And check that access is still been disabled.
|
||||||
|
$display("--- test11: Perform CPU instruction read from old SPI command address.");
|
||||||
|
$display("--- test11: Then check that SPI access is still disabled.");
|
||||||
|
tb_cpu_addr = 32'h0000dead;
|
||||||
|
tb_cpu_instr = 1'h1;
|
||||||
|
tb_cpu_valid = 1'h1;
|
||||||
#(CLK_PERIOD);
|
#(CLK_PERIOD);
|
||||||
tb_rom_access = 1'h0;
|
tb_cpu_instr = 1'h0;
|
||||||
$display("Status of access_ok_reg after ROM access: 0x%1x", dut.access_ok_reg);
|
tb_cpu_valid = 1'h0;
|
||||||
|
read_word(ADDR_SPI_XFER, 32'h0);
|
||||||
|
$display("");
|
||||||
|
|
||||||
|
// Simulate CPU instruction read from the new SPI command adress.
|
||||||
|
// And check that access is now enabled.
|
||||||
|
$display("--- test11: Perform CPU instruction read from new SPI command address.");
|
||||||
|
$display("--- test11: Then check that SPI access is now enabled.");
|
||||||
|
tb_cpu_addr = 32'h0000cafe;
|
||||||
|
tb_cpu_instr = 1'h1;
|
||||||
|
tb_cpu_valid = 1'h1;
|
||||||
|
#(CLK_PERIOD);
|
||||||
|
tb_cpu_instr = 1'h0;
|
||||||
|
tb_cpu_valid = 1'h0;
|
||||||
read_word(ADDR_SPI_XFER, 32'h1);
|
read_word(ADDR_SPI_XFER, 32'h1);
|
||||||
|
|
||||||
$display("--- test11: completed.");
|
$display("--- test11: completed.");
|
||||||
|
Loading…
Reference in New Issue
Block a user