OpenCores
URL https://opencores.org/ocsvn/spi_slave/spi_slave/trunk

Subversion Repositories spi_slave

[/] [spi_slave/] [trunk/] [bench/] [vhdl/] [crc_core_tb.vhd] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 dkoethe
-------------------------------------------------------------------------------
2
-- Title      : Testbench for design "crc_core"
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : crc_core_tb.vhd
6
-- Author     : 
7
-- Company    : 
8
-- Created    : 2008-03-23
9
-- Last update: 2008-03-23
10
-- Platform   : 
11
-- Standard   : VHDL'87
12
-------------------------------------------------------------------------------
13
-- Description: 
14
-------------------------------------------------------------------------------
15
-- Copyright (c) 2008 
16
-------------------------------------------------------------------------------
17
-- Revisions  :
18
-- Date        Version  Author  Description
19
-- 2008-03-23  1.0      d.koethe        Created
20
-------------------------------------------------------------------------------
21
library ieee;
22
use ieee.std_logic_1164.all;
23
use ieee.std_logic_unsigned.all;
24
use ieee.std_logic_arith.all;
25
-------------------------------------------------------------------------------
26
 
27
entity crc_core_tb is
28
  generic (
29
    C_SR_WIDTH : integer := 32);
30
 
31
end crc_core_tb;
32
 
33
-------------------------------------------------------------------------------
34
 
35
architecture behavior of crc_core_tb is
36
  component crc_core
37
    generic (
38
      C_SR_WIDTH : integer);
39
    port (
40
      rst              : in  std_logic;
41
      opb_clk          : in  std_logic;
42
      crc_en           : in  std_logic;
43
      crc_clr          : in  std_logic;
44
      opb_m_last_block : in  std_logic;
45
      fifo_rx_en       : in  std_logic;
46
      fifo_rx_data     : in  std_logic_vector(C_SR_WIDTH-1 downto 0);
47
      opb_rx_crc_value : out std_logic_vector(C_SR_WIDTH-1 downto 0);
48
      fifo_tx_en       : in  std_logic;
49
      fifo_tx_data     : in  std_logic_vector(C_SR_WIDTH-1 downto 0);
50
      tx_crc_insert    : out std_logic;
51
      opb_tx_crc_value : out std_logic_vector(C_SR_WIDTH-1 downto 0));
52
  end component;
53
 
54
  signal rst              : std_logic;
55
  signal opb_clk          : std_logic;
56
  signal crc_en           : std_logic;
57
  signal crc_clr          : std_logic;
58
  signal opb_m_last_block : std_logic;
59
  signal fifo_rx_en       : std_logic;
60
  signal fifo_rx_data     : std_logic_vector(C_SR_WIDTH-1 downto 0);
61
  signal opb_rx_crc_value : std_logic_vector(C_SR_WIDTH-1 downto 0);
62
  signal fifo_tx_en       : std_logic;
63
  signal fifo_tx_data     : std_logic_vector(C_SR_WIDTH-1 downto 0);
64
  signal tx_crc_insert    : std_logic;
65
  signal opb_tx_crc_value : std_logic_vector(C_SR_WIDTH-1 downto 0);
66
 
67
  constant C_CLK_PERIOD : time := 10 ns;
68
 
69
begin  -- behavior
70
 
71
  -- component instantiation
72
  DUT : crc_core
73
    generic map (
74
      C_SR_WIDTH => C_SR_WIDTH)
75
    port map (
76
      rst              => rst,
77
      opb_clk          => opb_clk,
78
      crc_en           => crc_en,
79
      crc_clr          => crc_clr,
80
      opb_m_last_block => opb_m_last_block,
81
      fifo_rx_en       => fifo_rx_en,
82
      fifo_rx_data     => fifo_rx_data,
83
      opb_rx_crc_value => opb_rx_crc_value,
84
      fifo_tx_en       => fifo_tx_en,
85
      fifo_tx_data     => fifo_tx_data,
86
      tx_crc_insert    => tx_crc_insert,
87
      opb_tx_crc_value => opb_tx_crc_value);
88
 
89
  -- clock generation
90
  process
91
  begin
92
    opb_clk <= '0';
93
    wait for C_CLK_PERIOD/2;
94
    opb_clk <= '1';
95
    wait for C_CLK_PERIOD/2;
96
  end process;
97
 
98
  -- waveform generation
99
  WaveGen_Proc : process
100
  begin
101
    rst              <= '1';
102
    crc_en           <= '0';
103
    crc_clr          <= '0';
104
    opb_m_last_block <= '0';
105
    fifo_rx_en       <= '0';
106
    fifo_rx_data     <= (others => '0');
107
    fifo_tx_en       <= '0';
108
    fifo_tx_data     <= (others => '0');
109
    wait for 100 ns;
110
    rst              <= '0';
111
 
112
    -- clear crc
113
    wait until rising_edge(opb_clk);
114
    crc_clr <= '1';
115
    wait until rising_edge(opb_clk);
116
    crc_clr <= '0';
117
    crc_en  <= '1';
118
 
119
 
120
 
121
    -- generate data block
122
    opb_m_last_block <= '0';
123
 
124
    for i in 0 to 15 loop
125
      wait until rising_edge(opb_clk);
126
      -- RX
127
      fifo_rx_en   <= '1';
128
      fifo_rx_data <= conv_std_logic_vector(i, fifo_rx_data'length);
129
      -- TX
130
      fifo_tx_en   <= '1';
131
      fifo_tx_data <= conv_std_logic_vector(i, fifo_tx_data'length);
132
    end loop;  -- i
133
    wait until rising_edge(opb_clk);
134
    fifo_rx_en   <= '0';
135
    fifo_rx_data <= (others => '0');
136
    fifo_tx_en   <= '0';
137
    fifo_tx_data <= (others => '0');
138
    wait until rising_edge(opb_clk);
139
 
140
    if (C_SR_WIDTH = 32) then
141
      assert (conv_integer(opb_rx_crc_value) = 16#eb99fa90#) report"RX_CRC_Failure" severity failure;
142
      assert (conv_integer(opb_tx_crc_value) = 16#eb99fa90#) report"RX_CRC_Failure" severity failure;
143
    end if;
144
 
145
 
146
    -- generate crc_block
147
    opb_m_last_block <= '1';
148
 
149
    for i in 0 to 15 loop
150
      wait until rising_edge(opb_clk);
151
      -- RX
152
      fifo_rx_en   <= '1';
153
      fifo_rx_data <= (others => '1');
154
      -- TX
155
      fifo_tx_en   <= '1';
156
      fifo_tx_data <= (others => '1');
157
    end loop;  -- i
158
    wait until rising_edge(opb_clk);
159
    fifo_rx_en   <= '0';
160
    fifo_rx_data <= (others => '0');
161
    fifo_tx_en   <= '0';
162
    fifo_tx_data <= (others => '0');
163
    wait until rising_edge(opb_clk);
164
    -- same value, no changes in last block
165
    if (C_SR_WIDTH = 32) then
166
      assert (conv_integer(opb_rx_crc_value) = 16#eb99fa90#) report"RX_CRC_Failure" severity failure;
167
      assert (conv_integer(opb_tx_crc_value) = 16#eb99fa90#) report"RX_CRC_Failure" severity failure;
168
    end if;
169
    opb_m_last_block <= '0';
170
 
171
 
172
    wait for 100 ns;
173
 
174
 
175
 
176
    assert false report "Simulation Sucessful" severity failure;
177
 
178
  end process WaveGen_Proc;
179
 
180
 
181
 
182
end behavior;
183
 
184
-------------------------------------------------------------------------------
185
 
186
configuration crc_core_tb_behavior_cfg of crc_core_tb is
187
  for behavior
188
  end for;
189
end crc_core_tb_behavior_cfg;
190
 
191
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.