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

Subversion Repositories pdp1

[/] [pdp1/] [trunk/] [rtl/] [vhdl/] [testtop.vhd] - Blame information for rev 17

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 yannv
--------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer:
4
--
5
-- Create Date:   00:00:04 08/14/2009
6
-- Design Name:   
7
-- Module Name:   /home/yann/fpga/work/pdp1-3/testtop.vhd
8
-- Project Name:  pdp1-3
9
-- Target Device:  
10
-- Tool versions:  
11
-- Description:   
12
-- 
13
-- VHDL Test Bench Created by ISE for module: top
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.numeric_std.ALL;
31 10 yannv
 
32 17 yannv
USE std.textio.ALL;
33 3 yannv
 
34
ENTITY testtop IS
35
END testtop;
36
 
37
ARCHITECTURE behavior OF testtop IS
38
 
39
    -- Component Declaration for the Unit Under Test (UUT)
40
 
41
    COMPONENT top
42
    PORT(
43
         CLK_50M : IN  std_logic;
44 10 yannv
         CLK_AUX : IN  std_logic;
45 3 yannv
         LED : OUT  std_logic_vector(7 downto 0);
46
         SW : IN  std_logic_vector(3 downto 0);
47
         AWAKE : OUT  std_logic;
48
         SPI_MOSI : OUT  std_logic;
49
         DAC_CS : OUT  std_logic;
50
         SPI_SCK : OUT  std_logic;
51
         DAC_CLR : OUT  std_logic;
52
         DAC_OUT : IN  std_logic;
53
                        RS232_DCE_RXD : IN std_logic;
54
                        RS232_DCE_TXD : OUT std_logic
55
        );
56
    END COMPONENT;
57
 
58
 
59
   --Inputs
60
   signal CLK_50M : std_logic := '0';
61 10 yannv
   signal CLK_AUX : std_logic := '0';
62 3 yannv
   signal SW : std_logic_vector(3 downto 0) := (others => '0');
63
   signal DAC_OUT : std_logic := '0';
64
 
65
        --Outputs
66
   signal LED : std_logic_vector(7 downto 0);
67
   signal AWAKE : std_logic;
68
   signal SPI_MOSI : std_logic;
69
   signal DAC_CS : std_logic;
70
   signal SPI_SCK : std_logic;
71
   signal DAC_CLR : std_logic;
72
        signal TXD, RXD : std_logic;
73 10 yannv
 
74
        -- UART interface
75
        COMPONENT Minimal_UART_CORE
76
        PORT(
77
                CLOCK : IN std_logic;
78
                RXD : IN std_logic;
79
                INP : IN std_logic_vector(7 downto 0);
80
                WR : IN std_logic;
81
                OUTP : INOUT std_logic_vector(7 downto 0);
82
                EOC : OUT std_logic;
83
                TXD : OUT std_logic;
84
                EOT : OUT std_logic;
85
                READY : OUT std_logic
86
                );
87
        END COMPONENT;
88
        signal received_byte, old_received_byte, tx_ready, wrote, byte_request,
89
                eot : std_logic := '0';
90
        signal read_byte, write_byte: std_logic_vector(7 downto 0);
91
 
92
 
93 3 yannv
   constant CLK_50M_period : time := 20ns;
94 10 yannv
   constant CLK_AUX_period : time := 7.5ns;
95
 
96 3 yannv
        constant bittime : time := 8.680555us; --1s/115200;
97 10 yannv
        constant waittime : time := 20*bittime;
98
 
99
   procedure send_byte (bytetosend : in std_logic_vector(7 downto 0);
100
                                                                signal tx_ready : in std_logic;
101
                                                                signal eot : in std_logic;
102
                                                                signal write_byte : out std_logic_vector(7 downto 0);
103
                                                                signal wrote : out std_logic)
104
        is
105
      -- subprogram_declarative_items (constant declarations, variable declarations, etc.)
106
   begin
107
--              wait for 100ns;
108
                wait until rising_edge(CLK_50M) and tx_ready = '1' and eot='0';
109
                write_byte <= bytetosend;
110
                wrote <= '1';
111
                wait until rising_edge(CLK_50M);
112
                wrote <= '0';
113
--              wait until eot='0' and tx_ready='1';
114
 
115
                -- Without UART, it was something like:
116
--              RXD <= '0'; wait for bittime;
117
--              RXD <= bytetosend(0); wait for bittime;
118
--              RXD <= bytetosend(1); wait for bittime;
119
--              RXD <= bytetosend(2); wait for bittime;
120
--              RXD <= bytetosend(3); wait for bittime;
121
--              RXD <= bytetosend(4); wait for bittime;
122
--              RXD <= bytetosend(5); wait for bittime;
123
--              RXD <= bytetosend(6); wait for bittime;
124
--              RXD <= bytetosend(7); wait for bittime;
125
--              RXD <= '1'; wait for bittime;           -- first sixbit 000101
126
--              wait for waittime;
127
   end send_byte;
128
 
129 3 yannv
BEGIN
130
 
131
        -- Instantiate the Unit Under Test (UUT)
132
   uut: top PORT MAP (
133
          CLK_50M => CLK_50M,
134 10 yannv
                         CLK_AUX => CLK_AUX,
135 3 yannv
          LED => LED,
136
          SW => SW,
137
          AWAKE => AWAKE,
138
          SPI_MOSI => SPI_MOSI,
139
          DAC_CS => DAC_CS,
140
          SPI_SCK => SPI_SCK,
141
          DAC_CLR => DAC_CLR,
142
          DAC_OUT => DAC_OUT,
143
                        RS232_DCE_RXD => RXD,
144
                        RS232_DCE_TXD => TXD
145
        );
146
 
147
   -- No clocks detected in port list. Replace CLK_50M below with 
148
   -- appropriate port name 
149
 
150
   CLK_50M_process :process
151
   begin
152
                CLK_50M <= '0';
153
                wait for CLK_50M_period/2;
154
                CLK_50M <= '1';
155
                wait for CLK_50M_period/2;
156
   end process;
157
 
158 10 yannv
   CLK_AUX_process :process
159
   begin
160
                CLK_AUX <= '0';
161
                wait for CLK_AUX_period/2;
162
                CLK_AUX <= '1';
163
                wait for CLK_AUX_period/2;
164
   end process;
165
 
166
        -- UART for talking to UUT
167
        Inst_Minimal_UART_CORE: Minimal_UART_CORE PORT MAP(
168
                CLOCK => CLK_50M,
169
 
170
                EOC => received_byte,   -- end of character; rising edge indicates valid data in OUTP
171
                OUTP => read_byte,
172
 
173
                RXD => TXD,
174
                TXD => RXD,
175 3 yannv
 
176 10 yannv
                EOT => eot,     -- end of transmit; indicates a character has been sent
177
                INP => write_byte,
178
                READY => tx_ready,      -- indicates that we may write
179
                WR => wrote
180
        );
181
 
182 17 yannv
 
183 3 yannv
   -- Stimulus process
184
   stim_proc: process
185 17 yannv
                type bytefile is file of integer;  -- TODO: assert 32-bit?
186
                file rimfile : bytefile;
187
                variable tapefileword : integer;
188
                variable tapebytes : signed(31 downto 0);
189 3 yannv
   begin
190 17 yannv
                file_open(rimfile, "tapefile.rim", READ_MODE);
191
                while not endfile(rimfile) loop
192
                        --wait for bittime*12;
193
                        wait until received_byte='1';
194
                        -- I seem to be getting 32-bit signed little endian numbers.
195
                        -- Which naturally don't fit in a byte. 
196
                        read (rimfile, tapefileword);
197
                        tapebytes := to_signed(tapefileword, 32);
198
                        --report "Read a word, value: " & integer'image(tapefileword);
199
 
200
                        send_byte(std_logic_vector(tapebytes(7 downto 0)), tx_ready, eot, write_byte, wrote);
201
                        wait until received_byte='1';
202
                        send_byte(std_logic_vector(tapebytes(15 downto 8)), tx_ready, eot, write_byte, wrote);
203
                        wait until received_byte='1';
204
                        send_byte(std_logic_vector(tapebytes(23 downto 16)), tx_ready, eot, write_byte, wrote);
205
                        wait until received_byte='1';
206
                        send_byte(std_logic_vector(tapebytes(31 downto 24)), tx_ready, eot, write_byte, wrote);
207
 
208
--                      send_byte(conv(tapebyte), tx_ready, eot, write_byte, wrote);
209
--                      send_byte(std_logic_vector(to_signed(integer(tapebyte(0)),8)), tx_ready, eot, write_byte, wrote);
210
--                      send_byte("10000101", tx_ready, eot, write_byte, wrote);
211
--                      send_byte("00111111", tx_ready, eot, write_byte, wrote);  -- ignored, as bit 7 is not set
212
--                      send_byte("10000110", tx_ready, eot, write_byte, wrote);
213
--                      send_byte("10111000", tx_ready, eot, write_byte, wrote);  -- Together 050670
214 3 yannv
                -- TODO: show reply data
215 17 yannv
                end loop;
216
                file_close(rimfile);
217
                report "Reached end of RIM (paper tape) file";
218 3 yannv
 
219
      wait for CLK_50M_period*10;
220
 
221
      -- insert stimulus here 
222
 
223
      wait;
224
   end process;
225
 
226
END;

powered by: WebSVN 2.1.0

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