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

Subversion Repositories tinycpu

[/] [tinycpu/] [trunk/] [testbench/] [carryover_tb.vhd] - Blame information for rev 21

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 earlz
LIBRARY ieee;
2
USE ieee.std_logic_1164.ALL;
3
USE ieee.numeric_std.ALL;
4
use work.tinycpu.all;
5
 
6
ENTITY carryover_tb IS
7
END carryover_tb;
8
 
9
ARCHITECTURE behavior OF carryover_tb IS
10
 
11
-- Component Declaration for the Unit Under Test (UUT)
12
 
13
  component carryover is
14
    port(
15
      EnableCarry: in std_logic;
16
      DataIn: in std_logic_vector(7 downto 0);
17
      SegmentIn: in std_logic_vector(7 downto 0);
18
      Addend: in std_logic_vector(7 downto 0); --How much to increase DataIn by (as a signed number). Believe it or not, that's the actual word for what we need.
19
      DataOut: out std_logic_vector(7 downto 0);
20 21 earlz
      SegmentOut: out std_logic_vector(7 downto 0);
21
      Clock: in std_logic
22 16 earlz
--      Debug: out std_logic_vector(8 downto 0)
23
    );
24
  end component;
25 21 earlz
  component registerfile is
26
  port(
27
    WriteEnable: in regwritetype;
28
    DataIn: in regdatatype;
29
    Clock: in std_logic;
30
    DataOut: out regdatatype
31
  );
32
  end component;
33 16 earlz
 
34
 
35
  --Inputs
36
  signal EnableCarry: std_logic := '0';
37
  signal DataIn: std_logic_vector(7 downto 0) := "00000000";
38
  signal Addend: std_logic_vector(7 downto 0) := "00000000";
39
  signal SegmentIn: std_logic_vector(7 downto 0) := "00000000";
40
  --Outputs
41
  signal DataOut: std_logic_vector(7 downto 0);
42
  signal SegmentOut: std_logic_vector(7 downto 0);
43
--  signal Debug: std_logic_vector(8 downto 0);
44 21 earlz
 
45
  signal regwe: regwritetype;
46
  signal regin: regdatatype;
47
  signal regout: regdatatype;
48 16 earlz
 
49
  signal Clock: std_logic;
50
  constant clock_period : time := 10 ns;
51
 
52
BEGIN
53
 
54
  -- Instantiate the Unit Under Test (UUT)
55
  uut: carryover PORT MAP (
56
    EnableCarry => EnableCarry,
57
    DataIn => DataIn,
58
    Addend => Addend,
59
    SegmentIn => SegmentIn,
60
    DataOut => DataOut,
61 21 earlz
    SegmentOut => SegmentOut,
62
    Clock => Clock
63 16 earlz
--    Debug => Debug
64
  );
65 21 earlz
  regfile: registerfile port map(
66
    WriteEnable => regwe,
67
    DataIn => regin,
68
    Clock => Clock,
69
    DataOut => regout
70
  );
71 16 earlz
 
72
  -- Clock process definitions
73
  clock_process :process
74
  begin
75
    Clock <= '0';
76
    wait for clock_period/2;
77
    Clock <= '1';
78
    wait for clock_period/2;
79
  end process;
80
 
81
 
82
  -- Stimulus process
83
  stim_proc: process
84
    variable err_cnt: integer :=0;
85
  begin
86
    -- hold reset state for 20 ns.
87
    wait for 20 ns;
88
 
89
    --wait for clock_period*10;
90
    EnableCarry <= '1';
91
    -- case 1
92
    DataIn <= x"10";
93
    Addend <= x"02";
94
    SegmentIn <= x"00";
95
    wait for 10 ns;
96
    assert (SegmentOut=x"00" and DataOut = x"12") report "Addition Carryover when not appropriate" severity error;
97
    --case 2
98
    DataIn <= x"10";
99
    Addend <= x"FE"; -- -2
100
    SegmentIn <= x"00";
101
    wait for 10 ns;
102
    assert (SegmentOut=x"00" and DataOut = x"0E") report "Subtraction Carryover when not appropriate" severity error;
103
 
104
    DataIn <= x"10";
105
    Addend <= x"EE"; -- -18 (-0x12)
106
    SegmentIn <= x"00";
107
    wait for 10 ns;
108
    assert (SegmentOut=x"FF" and DataOut = x"FE") report "Subtraction Carryover Error" severity error;
109
 
110
    DataIn <= x"FE";
111
    Addend <= x"04";
112
    SegmentIn <= x"00";
113
    wait for 10 ns;
114
    assert (SegmentOut=x"01" and DataOut = x"02") report "Addition Carryover Error" severity error;
115 17 earlz
 
116
    DataIn <= x"7F";
117
    Addend <= x"7F";
118
    SegmentIn <= x"00";
119
    wait for 10 ns;
120
    assert (SegmentOut=x"00" and DataOut = x"FE") report "Carryover when not appropriate case 1" severity error;
121 21 earlz
 
122
    --practical register test
123
    regin(0) <= x"10";
124
    regwe(0) <= '1';
125
    wait for 10 ns;
126
    regwe(0) <= '0';
127
    wait for 10 ns;
128
    regwe(0) <= '1';
129
    DataIn <= regout(0);
130
    Addend <= x"02";
131
    SegmentIn <= x"00";
132
    wait for 10 ns;
133
    regin(0) <= DataOut;
134
    wait for 10 ns;
135
    assert(DataOut = x"12") report "practical fail 1" severity error;
136
    DataIn <= regout(0);
137
    regin(0) <= DataOut;
138
    wait for 10 ns;
139
    assert(DataOut = x"14") report "practical fail 2" severity error;
140 16 earlz
 
141
    -- summary of testbench
142
    assert false
143
    report "Testbench of carryover completed successfully!"
144
    severity note;
145
 
146
    wait;
147
 
148
    -- insert stimulus here 
149
 
150
    wait;
151
  end process;
152
 
153
 
154
END;

powered by: WebSVN 2.1.0

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