Line 4... |
Line 4... |
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- File : opb_spi_slave_tb.vhd
|
-- File : opb_spi_slave_tb.vhd
|
-- Author :
|
-- Author :
|
-- Company :
|
-- Company :
|
-- Created : 2007-09-02
|
-- Created : 2007-09-02
|
-- Last update: 2007-11-18
|
-- Last update: 2007-12-03
|
-- Platform :
|
-- Platform :
|
-- Standard : VHDL'87
|
-- Standard : VHDL'87
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- Description:
|
-- Description:
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
Line 27... |
Line 27... |
library work;
|
library work;
|
use work.opb_spi_slave_pack.all;
|
use work.opb_spi_slave_pack.all;
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
|
|
entity opb_spi_slave_tb is
|
entity opb_spi_slave_tb is
|
|
generic (
|
|
-- 0: simple transfer 1 byte transmit/receive
|
|
-- 1: transfer 4 bytes and check flags
|
|
-- 2: write until TX-FIFO asserts full, read until RX-FIFO asserts full, read
|
|
-- and compare data
|
|
-- 3: check FIFO Reset form underflow condition
|
|
-- 4: check FIFO Flags IRQ Generation
|
|
-- 5: check Slave select IRQ Generation
|
|
-- 6: test opb Master Transfer
|
|
test : std_logic_vector(7 downto 0) := "11111111");
|
end opb_spi_slave_tb;
|
end opb_spi_slave_tb;
|
|
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
|
|
architecture behavior of opb_spi_slave_tb is
|
architecture behavior of opb_spi_slave_tb is
|
Line 142... |
Line 151... |
signal miso : std_logic;
|
signal miso : std_logic;
|
|
|
signal opb_read_data : std_logic_vector(31 downto 0);
|
signal opb_read_data : std_logic_vector(31 downto 0);
|
signal spi_value_in : std_logic_vector(C_SR_WIDTH-1 downto 0);
|
signal spi_value_in : std_logic_vector(C_SR_WIDTH-1 downto 0);
|
|
|
|
signal OPB_Transfer_Abort : boolean;
|
|
|
begin -- behavior
|
begin -- behavior
|
|
|
-- component instantiation
|
-- component instantiation
|
DUT : opb_spi_slave
|
DUT : opb_spi_slave
|
generic map (
|
generic map (
|
Line 216... |
Line 227... |
process(OPB_Rst, OPB_Clk)
|
process(OPB_Rst, OPB_Clk)
|
begin
|
begin
|
if (OPB_Rst = '1') then
|
if (OPB_Rst = '1') then
|
MOPB_MGrant <= '0';
|
MOPB_MGrant <= '0';
|
MOPB_xferAck <= '0';
|
MOPB_xferAck <= '0';
|
|
MOPB_errAck <= '0';
|
elsif rising_edge(OPB_Clk) then
|
elsif rising_edge(OPB_Clk) then
|
-- arbiter
|
-- arbiter
|
if (M_request = '1') then
|
if (M_request = '1') then
|
MOPB_MGrant <= '1';
|
MOPB_MGrant <= '1';
|
else
|
else
|
MOPB_MGrant <= '0';
|
MOPB_MGrant <= '0';
|
end if;
|
end if;
|
|
|
-- xfer_Ack
|
-- xfer_Ack
|
if (M_select = '1') then
|
if (M_select = '1') then
|
|
if (OPB_Transfer_Abort) then
|
|
MOPB_errAck <= '1';
|
|
else
|
MOPB_xferAck <= not MOPB_xferAck;
|
MOPB_xferAck <= not MOPB_xferAck;
|
|
end if;
|
|
|
|
|
else
|
else
|
|
MOPB_errAck <= '0';
|
MOPB_xferAck <= '0';
|
MOPB_xferAck <= '0';
|
end if;
|
end if;
|
|
|
end if;
|
end if;
|
end process;
|
end process;
|
Line 320... |
Line 339... |
OPB_RNW <= '0';
|
OPB_RNW <= '0';
|
OPB_select <= '0';
|
OPB_select <= '0';
|
OPB_seqAddr <= '0';
|
OPB_seqAddr <= '0';
|
|
|
-- int opb_master
|
-- int opb_master
|
MOPB_errAck <= '0';
|
|
MOPB_retry <= '0';
|
MOPB_retry <= '0';
|
MOPB_timeout <= '0';
|
MOPB_timeout <= '0';
|
|
|
|
OPB_Transfer_Abort <= false;
|
|
|
-- reset active
|
-- reset active
|
OPB_Rst <= '1';
|
OPB_Rst <= '1';
|
wait for 100 ns;
|
wait for 100 ns;
|
-- reset inactive
|
-- reset inactive
|
OPB_Rst <= '0';
|
OPB_Rst <= '0';
|
Line 348... |
Line 368... |
opb_write(C_ADR_RX_THRESH, 16#0006000C#);
|
opb_write(C_ADR_RX_THRESH, 16#0006000C#);
|
|
|
|
|
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
-- simple transfer 1 byte transmit/receive
|
-- simple transfer 1 byte transmit/receive
|
|
if (test(0) = '1') then
|
-- write transmit data
|
-- write transmit data
|
opb_write(C_ADR_TX_DATA, 16#78#);
|
opb_write(C_ADR_TX_DATA, 16#78#);
|
|
|
-- enable GDE and TX_EN and RX_EN
|
-- enable GDE and TX_EN and RX_EN
|
opb_write(C_ADR_CTL, 16#7#);
|
opb_write(C_ADR_CTL, 16#7#);
|
Line 367... |
Line 387... |
opb_read(C_ADR_RX_DATA);
|
opb_read(C_ADR_RX_DATA);
|
|
|
-- compare receive data
|
-- compare receive data
|
assert (opb_read_data = conv_std_logic_vector(16#B5#,C_SR_WIDTH)) report "Master Transfer Failure" severity failure;
|
assert (opb_read_data = conv_std_logic_vector(16#B5#,C_SR_WIDTH)) report "Master Transfer Failure" severity failure;
|
|
|
|
end if;
|
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
-- transfer 4 bytes and check flags
|
-- transfer 4 bytes and check flags
|
|
if (test(1) = '1') then
|
opb_read(C_ADR_STATUS);
|
opb_read(C_ADR_STATUS);
|
-- only empty Bit and prog_empty set
|
-- only empty Bit and prog_empty set
|
|
|
temp := (others => '0');
|
temp := (others => '0');
|
temp(SPI_SR_Bit_TX_Prog_empty) := '1';
|
temp(SPI_SR_Bit_TX_Prog_empty) := '1';
|
Line 393... |
Line 415... |
temp(SPI_SR_Bit_RX_Prog_empty) := '1';
|
temp(SPI_SR_Bit_RX_Prog_empty) := '1';
|
temp(SPI_SR_Bit_RX_Empty) := '1';
|
temp(SPI_SR_Bit_RX_Empty) := '1';
|
temp(SPI_SR_Bit_SS_n) := '1';
|
temp(SPI_SR_Bit_SS_n) := '1';
|
|
|
assert (opb_read_data = temp) report "Check Status Bits: TX: 1, RX:0" severity failure;
|
assert (opb_read_data = temp) report "Check Status Bits: TX: 1, RX:0" severity failure;
|
|
end if;
|
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
|
-- write until TX-FIFO asserts full, read until RX-FIFO asserts full, read an
|
|
-- compare data
|
|
if (test(2) = '1') then
|
for i in 2 to 255 loop
|
for i in 2 to 255 loop
|
opb_write(C_ADR_TX_DATA, i);
|
opb_write(C_ADR_TX_DATA, i);
|
opb_read(C_ADR_STATUS);
|
opb_read(C_ADR_STATUS);
|
-- check TX prog_empty deassert
|
-- check TX prog_empty deassert
|
if ((opb_read_data(SPI_SR_Bit_TX_Prog_empty) = '0') and first(0) = '0') then
|
if ((opb_read_data(SPI_SR_Bit_TX_Prog_empty) = '0') and first(0) = '0') then
|
Line 481... |
Line 506... |
first(7) := '1';
|
first(7) := '1';
|
exit;
|
exit;
|
end if;
|
end if;
|
end loop; -- i
|
end loop; -- i
|
|
|
|
|
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
-- read data from fifo
|
-- read data from fifo
|
first := (others => '0');
|
first := (others => '0');
|
|
|
for i in 1 to 255 loop
|
for i in 1 to 255 loop
|
Line 520... |
Line 546... |
assert (false) report "RX empty assert after " & integer'image(i) & " transfers." severity warning;
|
assert (false) report "RX empty assert after " & integer'image(i) & " transfers." severity warning;
|
first(3) := '1';
|
first(3) := '1';
|
exit;
|
exit;
|
end if;
|
end if;
|
end loop; -- i
|
end loop; -- i
|
|
end if;
|
|
|
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
|
-- check FIFO Reset form underflow condition
|
|
if (test(3) = '1') then
|
-- add transfer to go in underflow condition
|
-- add transfer to go in underflow condition
|
spi_transfer(conv_std_logic_vector(0, C_SR_WIDTH));
|
spi_transfer(conv_std_logic_vector(0, C_SR_WIDTH));
|
|
|
-- reset core (Bit 4)
|
-- reset core (Bit 4)
|
opb_write(C_ADR_CTL, 16#F#);
|
opb_write(C_ADR_CTL, 16#F#);
|
Line 538... |
Line 566... |
temp(SPI_SR_Bit_RX_Prog_empty) := '1';
|
temp(SPI_SR_Bit_RX_Prog_empty) := '1';
|
temp(SPI_SR_Bit_RX_Empty) := '1';
|
temp(SPI_SR_Bit_RX_Empty) := '1';
|
temp(SPI_SR_Bit_SS_n) := '1';
|
temp(SPI_SR_Bit_SS_n) := '1';
|
|
|
assert (opb_read_data = temp) report "Status Bits after Reset failure" severity failure;
|
assert (opb_read_data = temp) report "Status Bits after Reset failure" severity failure;
|
|
end if;
|
|
-------------------------------------------------------------------------------
|
|
-- check FIFO Flags IRQ Generation
|
|
if (test(4) = '1') then
|
-- enable all IRQ except Chip select
|
-- enable all IRQ except Chip select
|
opb_write(C_ADR_IER, 16#3F#);
|
opb_write(C_ADR_IER, 16#3F#);
|
-- global irq enable
|
-- global irq enable
|
opb_write(C_ADR_DGIE, 16#1#);
|
opb_write(C_ADR_DGIE, 16#1#);
|
|
|
Line 621... |
Line 652... |
end if;
|
end if;
|
|
|
end if;
|
end if;
|
|
|
end loop; -- i
|
end loop; -- i
|
|
end if;
|
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
-- check Chip select irq
|
-- check slave select irq
|
|
if (test(5) = '1') then
|
-- reset core
|
-- reset core
|
opb_write(C_ADR_CTL, 16#F#);
|
opb_write(C_ADR_CTL, 16#F#);
|
|
|
-- eable Chip select fall/rise IRQ
|
-- eable Chip select fall/rise IRQ
|
opb_write(C_ADR_IER, 16#C0#);
|
opb_write(C_ADR_IER, 16#C0#);
|
Line 659... |
Line 691... |
opb_write(C_ADR_ISR, 2**SPI_ISR_Bit_SS_Rise);
|
opb_write(C_ADR_ISR, 2**SPI_ISR_Bit_SS_Rise);
|
wait until rising_edge(OPB_Clk);
|
wait until rising_edge(OPB_Clk);
|
assert (opb_irq = '0') report "SS_Rise IRQ not cleared" severity warning;
|
assert (opb_irq = '0') report "SS_Rise IRQ not cleared" severity warning;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
end if;
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- test opb Master Transfer
|
-- test opb Master Transfer
|
|
if (test(6) = '1') then
|
-- write TX Threshold
|
-- write TX Threshold
|
-- Bit [15:00] Prog Full Threshold
|
-- Bit [15:00] Prog Full Threshold
|
-- Bit [31:16] Prog Empty Threshold
|
-- Bit [31:16] Prog Empty Threshold
|
opb_write(C_ADR_TX_THRESH, 16#0005000B#);
|
opb_write(C_ADR_TX_THRESH, 16#0005000B#);
|
|
|
Line 708... |
Line 742... |
opb_write(C_ADR_RX_DMA_CTL, 16#1#);
|
opb_write(C_ADR_RX_DMA_CTL, 16#1#);
|
|
|
-- emulate DDR-Memory Controller
|
-- emulate DDR-Memory Controller
|
wait until M_select = '1';
|
wait until M_select = '1';
|
for i in 0 to 15 loop
|
for i in 0 to 15 loop
|
|
if (i = 15) then
|
|
OPB_Transfer_Abort <= true;
|
|
wait until falling_edge(MOPB_errAck);
|
|
OPB_Transfer_Abort <= false;
|
|
exit;
|
|
end if;
|
wait until falling_edge(MOPB_xferAck);
|
wait until falling_edge(MOPB_xferAck);
|
assert (conv_integer(M_ABus) = 16#25000000#+i*4) report "DMA transfer 1 write adr failure" severity failure;
|
assert (conv_integer(M_ABus) = 16#25000000#+i*4) report "DMA transfer 1 write adr failure" severity failure;
|
assert (conv_integer(M_DBus) = i) report "DMA transfer 1 write data failure" severity failure;
|
assert (conv_integer(M_DBus) = i) report "DMA transfer 1 write data failure" severity failure;
|
end loop; -- i
|
end loop; -- i
|
|
|
|
|
|
|
-- transfer second 16 bytes
|
-- transfer second 16 bytes
|
for i in 16 to 31 loop
|
for i in 16 to 31 loop
|
spi_transfer(conv_std_logic_vector(i, C_SR_WIDTH));
|
spi_transfer(conv_std_logic_vector(i, C_SR_WIDTH));
|
-- disabled because simultaneous controller emulation and SPI Transfer impossible
|
-- disabled because simultaneous controller emulation and SPI Transfer impossible
|
-- assert (conv_integer(spi_value_in) = i) report "DMA Transfer 2 read data failure" severity failure;
|
-- assert (conv_integer(spi_value_in) = i) report "DMA Transfer 2 read data failure" severity failure;
|
end loop; -- i
|
end loop; -- i
|
|
|
|
|
wait for 1 us;
|
wait for 1 us;
|
|
end if;
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
assert false report "Simulation sucessful" severity failure;
|
assert false report "Simulation sucessful" severity failure;
|
end process WaveGen_Proc;
|
end process WaveGen_Proc;
|