diff options
author | Wojciech Kosior <kwojtus@protonmail.com> | 2020-11-03 19:16:12 +0100 |
---|---|---|
committer | Wojciech Kosior <kwojtus@protonmail.com> | 2020-11-03 19:16:12 +0100 |
commit | cd0c787bcfc89a0a1e14f4404a59cb4697854621 (patch) | |
tree | ea96fd360441b7c6f171b642016b68039283cc8a /tests | |
parent | 33f05839b7815a5a18a2b920dba4549d2bd7ce16 (diff) | |
download | AGH-engineering-thesis-cd0c787bcfc89a0a1e14f4404a59cb4697854621.tar.gz AGH-engineering-thesis-cd0c787bcfc89a0a1e14f4404a59cb4697854621.zip |
add spi wishbone slave with a simplified flash memory chip model and a test bench
Diffstat (limited to 'tests')
-rw-r--r-- | tests/spi_slave/Makefile | 9 | ||||
-rw-r--r-- | tests/spi_slave/operations.memv | 62 | ||||
-rw-r--r-- | tests/spi_slave/rom.mem | 258 | ||||
-rw-r--r-- | tests/spi_slave/test.v | 141 |
4 files changed, 470 insertions, 0 deletions
diff --git a/tests/spi_slave/Makefile b/tests/spi_slave/Makefile new file mode 100644 index 0000000..8a8d3e8 --- /dev/null +++ b/tests/spi_slave/Makefile @@ -0,0 +1,9 @@ +DEPENDS = operations.mem master.v spi_slave.v flash_memory.v messages.vh rom.mem + +IVFLAGS = \ + -DMASTER_OPERATIONS_COUNT=$(call FILE_LINES,operations.mem) \ + -DROM_WORDS_COUNT=$(call FILE_LINES,rom.mem) + +TOP = spi_test + +include ../../Makefile.test diff --git a/tests/spi_slave/operations.memv b/tests/spi_slave/operations.memv new file mode 100644 index 0000000..084353b --- /dev/null +++ b/tests/spi_slave/operations.memv @@ -0,0 +1,62 @@ +`include "macroasm.vh" // look into macroasm.vh for more info + +// power up flash ship +`WRITE (00100, 0001) // set bytes_to_output to 1 +`WRITE (00101, 0000) // set bytes_to_receive to 0 + +`WRITE (00000, 00AB) // release power-down spi command + +`WRITE (00102, 1111) // start spi operation + + +// reading this reg during operation should yield 1's +`READ (00102, FFFF) + + +// the completions of first write after spi operation has been started +// will be delayed until the operations has finished. This is of no concern +// here, since the master will just gently wait for ACK from slave. + + +// read contents at addresses h3A through h4A +`WRITE (00101, 0010) // set bytes_to_receive to 16 (h10) +`READ (00102, 0000) // see, that operation indeed finished + +`WRITE (00000, 000B) // fast read spi command + 8 high address bits +`WRITE (00001, 3A00) // 16 low address bits +`WRITE (00002, 0000) // dummy byte + +`WRITE (00100, 0005) // set bytes_to_output to 5 + +// Cause delay b4 starting operation - chip's power-up takes 3000ns +`DESELECT +`DESELECT +`WAIT +`DESELECT +`WAIT +`DESELECT + +`WRITE (00102, 1111) // start spi operation (bits written to h102 don't matter) + +`WRITE (00100, 0000) // force wait for operation completion + +// check the data we've just read +`READ (00000, 00CB) +`READ (00001, 00D2) +`READ (00002, 00D9) +`READ (00003, 00E0) +`READ (00004, 00E7) +`READ (00005, 00EE) +`READ (00006, 00F5) +`READ (00007, 00FC) + +// how about reading a single byte? +`WRITE (00100, 0005) // set bytes_to_output to 5 +`WRITE (00101, 0001) // set bytes_to_receive to 1 +`WRITE (00000, 000B) // fast read spi command + 8 high address bits +`WRITE (00001, E400) // 16 low address bits +//`WRITE (00002, 0000) // dummy byte +`WRITE (00102, BEEF) // start spi operation +`WRITE (00100, 0000) // force wait for operation completion + +`READ (00000, xx1E) // check the byte we've just read diff --git a/tests/spi_slave/rom.mem b/tests/spi_slave/rom.mem new file mode 100644 index 0000000..06fff24 --- /dev/null +++ b/tests/spi_slave/rom.mem @@ -0,0 +1,258 @@ +// numbers 0, 7, 2*7, 3*7, ..., 256*7 in hex (2 LE bytes for each number) +0 0 +7 0 +e 0 +15 0 +1c 0 +23 0 +2a 0 +31 0 +38 0 +3f 0 +46 0 +4d 0 +54 0 +5b 0 +62 0 +69 0 +70 0 +77 0 +7e 0 +85 0 +8c 0 +93 0 +9a 0 +a1 0 +a8 0 +af 0 +b6 0 +bd 0 +c4 0 +cb 0 +d2 0 +d9 0 +e0 0 +e7 0 +ee 0 +f5 0 +fc 0 +3 1 +a 1 +11 1 +18 1 +1f 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+2e 6 +35 6 +3c 6 +43 6 +4a 6 +51 6 +58 6 +5f 6 +66 6 +6d 6 +74 6 +7b 6 +82 6 +89 6 +90 6 +97 6 +9e 6 +a5 6 +ac 6 +b3 6 +ba 6 +c1 6 +c8 6 +cf 6 +d6 6 +dd 6 +e4 6 +eb 6 +f2 6 +f9 6 +0 7 diff --git a/tests/spi_slave/test.v b/tests/spi_slave/test.v new file mode 100644 index 0000000..f489fee --- /dev/null +++ b/tests/spi_slave/test.v @@ -0,0 +1,141 @@ +`default_nettype none +`timescale 1ns/1ns + +`include "messages.vh" + +`ifndef MASTER_OPERATIONS_COUNT + `error_MASTER_OPERATIONS_COUNT_must_be_defined +; /* Cause syntax error */ +`endif + +`ifndef ROM_WORDS_COUNT + `error_ROM_WORDS_COUNT_must_be_defined +; /* Cause syntax error */ +`endif + +`ifndef SIMULATION + `error_SIMULATION_not_defined +; /* Cause syntax error */ +`endif + +module spi_test(); + wire M_ACK_I; + wire M_CLK_I; + wire [19:0] M_ADR_O; + wire [15:0] M_DAT_I; + wire [15:0] M_DAT_O; + wire M_SEL_O; /* Ignored, assumed always high */ + wire M_RST_I; + wire M_STB_O; + wire M_CYC_O; + wire M_WE_O; + wire M_STALL_I; + + wire S_ACK_O; + wire S_CLK_I; + wire [8:0] S_ADR_I; + wire [15:0] S_DAT_I; + wire [15:0] S_DAT_O; + wire S_RST_I; + wire S_STB_I; + wire S_WE_I; + wire S_STALL_O; + + /* Non-wishbone */ + wire sdo; + wire sdi; + wire sck; + wire ss_n; + + wire M_finished; + + master_model + #( + .MASTER_NR(0), + .OPERATIONS_FILE("operations.mem"), + .OPERATIONS_COUNT(`MASTER_OPERATIONS_COUNT) + ) master + ( + .ACK_I(M_ACK_I), + .CLK_I(M_CLK_I), + .ADR_O(M_ADR_O), + .DAT_I(M_DAT_I), + .DAT_O(M_DAT_O), + .SEL_O(M_SEL_O), + .RST_I(M_RST_I), + .STB_O(M_STB_O), + .CYC_O(M_CYC_O), + .WE_O(M_WE_O), + .STALL_I(M_STALL_I), + + .finished(M_finished) + ); + + spi_slave slave + ( + .ACK_O(S_ACK_O), + .CLK_I(S_CLK_I), + .ADR_I(S_ADR_I), + .DAT_I(S_DAT_I), + .DAT_O(S_DAT_O), + .RST_I(S_RST_I), + .STB_I(S_STB_I), + .WE_I(S_WE_I), + .STALL_O(S_STALL_O), + + .sdo(sdo), + .sdi(sdi), + .sck(sck), + .ss_n(ss_n) + ); + + W25Q16BV_flash + #( + .BYTES_TO_INITIALIZE(`ROM_WORDS_COUNT * 2), + .INITIAL_CONTENTS_FILE("rom.mem") + ) flash + ( + .sdo(sdo), + .sdi(sdi), + .sck(sck), + .ss_n(ss_n) + ); + + reg CLK; + reg RST; + + assign M_ACK_I = S_ACK_O; + assign M_CLK_I = CLK; + assign M_DAT_I = S_DAT_O; + assign M_RST_I = RST; + assign M_STALL_I = S_STALL_O; + + assign S_CLK_I = CLK; + assign S_ADR_I = M_ADR_O[8:0]; /* Ignore 11 topmost bits */ + assign S_DAT_I = M_DAT_O; + assign S_RST_I = RST; + assign S_STB_I = M_STB_O && M_CYC_O; + assign S_WE_I = M_WE_O; + + integer i; + + initial begin + CLK <= 0; + RST <= 1; + + for (i = 0; i < 600; i++) begin + #100; /* longer wait time so that power-up requires less idle ticks */ + + CLK <= ~CLK; + + if (CLK) + RST <= 0; + + if (M_finished) + $finish; + end + + $display("error: master hasn't finished its operations in 300 ticks"); + $finish; + end +endmodule // spi_test |