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

Subversion Repositories saturn

[/] [saturn/] [trunk/] [IPCommunication/] [test_spi.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 DavidRAMBA
--------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer:
4
--
5
-- Create Date:   09:40:33 12/03/2012
6
-- Design Name:   
7
-- Module Name:   R:/CONCERTO/LP/IP Communication/test_spi.vhd
8
-- Project Name:  fpga_mio10s
9
-- Target Device:  
10
-- Tool versions:  
11
-- Description:   
12
-- 
13
-- VHDL Test Bench Created by ISE for module: if_spi
14
-- 
15
-- Dependencies:
16
-- 
17
-- Revision:
18
-- Revision 0.01 - File Created
19
-- Additional Comments:
20
--
21
-- Notes: 
22
-- This testbench has been automatically generated using types std_logic and
23
-- std_logic_vector for the ports of the unit under test.  Xilinx recommends
24
-- that these types always be used for the top-level I/O of a design in order
25
-- to guarantee that the testbench will bind correctly to the post-implementation 
26
-- simulation model.
27
--------------------------------------------------------------------------------
28
LIBRARY IEEE;
29
USE IEEE.STD_LOGIC_1164.ALL;
30
USE IEEE.STD_LOGIC_ARITH.ALL;
31
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
32
 
33
-- Uncomment the following library declaration if using
34
-- arithmetic functions with Signed or Unsigned values
35
--USE ieee.numeric_std.ALL;
36
 
37
ENTITY test_spi IS
38
END test_spi;
39
 
40
ARCHITECTURE behavior OF test_spi IS
41
 CONSTANT adreg_loadfpga: STD_LOGIC_VECTOR(6 DOWNTO 0) := CONV_STD_LOGIC_VECTOR(124, 7);
42
   CONSTANT adreg_spinbr: STD_LOGIC_VECTOR(6 DOWNTO 0) := CONV_STD_LOGIC_VECTOR(125, 7);
43
   CONSTANT adreg_spictl: STD_LOGIC_VECTOR(6 DOWNTO 0) := CONV_STD_LOGIC_VECTOR(126, 7);
44
   CONSTANT adreg_spidat: STD_LOGIC_VECTOR(6 DOWNTO 0) := CONV_STD_LOGIC_VECTOR(127, 7);
45
    -- Component Declaration for the Unit Under Test (UUT)
46
 
47
    COMPONENT if_spi
48
       GENERIC (
49
      div_rate : INTEGER := 2;      -- Diviseur d'horloge système pour obtenir le débit SPI = 2^div_rate
50
      spiclk_freq : INTEGER := 12
51
      );
52
    PORT(
53
         clk_sys : IN  std_logic;
54
         rst_n : IN  std_logic;
55
         spi_csn : OUT  std_logic;
56
         spi_wpn : OUT  std_logic;
57
         spi_sdo : OUT  std_logic;
58
         spi_sdi : IN  std_logic;
59
         spi_clk : OUT  std_logic;
60
         tx_dat : IN  std_logic_vector(7 downto 0);
61
         tx_val : IN  std_logic;
62
         rx_dat : OUT  std_logic_vector(7 downto 0);
63
         rx_val : OUT  std_logic;
64
         rx_next : IN  std_logic;
65
         type_com : IN  std_logic;
66
         exec_com : IN  std_logic;
67
         spi_busy : OUT  std_logic;
68
         nb_read : IN  std_logic_vector(7 downto 0)
69
        );
70
    END COMPONENT;
71
 
72
   COMPONENT m25p80
73
   PORT (
74
      c : IN std_logic;
75
      data_in : IN std_logic;
76
      s : IN std_logic;
77
      w : IN std_logic;
78
      hold : IN std_logic;
79
      data_out : OUT std_logic
80
      );
81
   END COMPONENT;
82
 
83
   --Inputs
84
   signal clk_sys : std_logic := '0';
85
   signal rst_n : std_logic := '0';
86
   signal spi_sdi : std_logic := '0';
87
   signal tx_dat : std_logic_vector(7 downto 0) := (others => '0');
88
   signal tx_val : std_logic := '0';
89
   signal rx_next : std_logic := '0';
90
   signal type_com : std_logic := '0';
91
   signal exec_com : std_logic := '0';
92
   signal nb_read : std_logic_vector(7 downto 0) := (others => '0');
93
 
94
        --Outputs
95
   signal spi_csn : std_logic;
96
   signal spi_wpn : std_logic;
97
   signal spi_sdo : std_logic;
98
   signal spi_clk : std_logic;
99
   signal rx_dat : std_logic_vector(7 downto 0);
100
   signal rx_val : std_logic;
101
   signal spi_busy : std_logic;
102
 
103
   -- Clock period definitions
104
   constant clk_sys_period : time := 22 ns;
105
 
106
BEGIN
107
   rst_n <= '0', '1' after 10 ns;
108
        -- Instantiate the Unit Under Test (UUT)
109
   uut: if_spi
110
      GENERIC MAP (
111
         div_rate => 2,
112
         spiclk_freq => 12)
113
      PORT MAP (
114
 
115
          clk_sys => clk_sys,
116
          rst_n => rst_n,
117
          spi_csn => spi_csn,
118
          spi_wpn => spi_wpn,
119
          spi_sdo => spi_sdo,
120
          spi_sdi => spi_sdi,
121
          spi_clk => spi_clk,
122
          tx_dat => tx_dat,
123
          tx_val => tx_val,
124
          rx_dat => rx_dat,
125
          rx_val => rx_val,
126
          rx_next => rx_next,
127
          type_com => type_com,
128
          exec_com => exec_com,
129
          spi_busy => spi_busy,
130
          nb_read => nb_read
131
        );
132
 
133
   instflash : m25p80
134
   PORT MAP(
135
      c => spi_clk,
136
      data_in => spi_sdo,
137
      s => spi_csn,
138
      w => spi_wpn,
139
      hold => '1',
140
      data_out => spi_sdi
141
      );
142
 
143
   -- Clock process definitions
144
   clk_sys_process :process
145
   begin
146
                clk_sys <= '0';
147
                wait for clk_sys_period/2;
148
                clk_sys <= '1';
149
                wait for clk_sys_period/2;
150
   end process;
151
 
152
 
153
   -- Stimulus process
154
   stim_proc: process
155
   begin
156
      wait for 100 ns;
157
      -- Commande 06h (WREN)
158
      wait until rising_edge(clk_sys);
159
      tx_dat <= x"06";
160
      tx_val <= '1';
161
      wait until rising_edge(clk_sys);
162
      tx_val <= '0';
163
      wait until rising_edge(clk_sys);
164
      wait until rising_edge(clk_sys);
165
      wait until rising_edge(clk_sys);
166
      type_com <= '0';
167
      exec_com <= '1';
168
      wait until spi_busy = '0';
169
 
170
      -- Commande D8h (SE)
171
      wait until rising_edge(clk_sys);
172
      tx_dat <= x"D8";
173
      nb_read <= x"14";
174
      tx_val <= '1';
175
      wait until rising_edge(clk_sys);
176
      tx_dat <= x"01";
177
      wait until rising_edge(clk_sys);
178
      tx_dat <= x"02";
179
      wait until rising_edge(clk_sys);
180
      tx_dat <= x"03";
181
      wait until rising_edge(clk_sys);
182
      tx_val <= '0';
183
      wait until rising_edge(clk_sys);
184
      wait until rising_edge(clk_sys);
185
      wait until rising_edge(clk_sys);
186
      type_com <= '0';
187
      exec_com <= '1';
188
      wait until spi_busy = '0';
189
 
190
      -- Commande 06h (WREN)
191
      wait until rising_edge(clk_sys);
192
      tx_dat <= x"06";
193
      tx_val <= '1';
194
      wait until rising_edge(clk_sys);
195
      tx_val <= '0';
196
      wait until rising_edge(clk_sys);
197
      wait until rising_edge(clk_sys);
198
      wait until rising_edge(clk_sys);
199
      type_com <= '0';
200
      exec_com <= '1';
201
      wait until spi_busy = '0';
202
 
203
      -- Commande PP
204
      wait until rising_edge(clk_sys);
205
      tx_dat <= x"02";
206
      tx_val <= '1';
207
      wait until rising_edge(clk_sys);
208
      tx_dat <= x"01";
209
      wait until rising_edge(clk_sys);
210
      tx_dat <= x"02";
211
      wait until rising_edge(clk_sys);
212
      tx_dat <= x"03";
213
      FOR i IN 0 TO 124 LOOP
214
         wait until rising_edge(clk_sys);
215
         tx_dat <= conv_std_logic_vector(i, 8);
216
      END LOOP;
217
      wait until rising_edge(clk_sys);
218
      tx_val <= '0';
219
      wait until rising_edge(clk_sys);
220
      wait until rising_edge(clk_sys);
221
      wait until rising_edge(clk_sys);
222
      type_com <= '0';
223
      exec_com <= '1';
224
      wait until spi_busy = '0';
225
      wait;
226
   end process;
227
 
228
END;

powered by: WebSVN 2.1.0

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