aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/vests/vhdl-93/ashenden/compliant/ch_14_fg_14_01.vhd
blob: 74fa3e4e51d0f2f5d213775a1d45bfd3b521d6b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc

-- This file is part of VESTs (Vhdl tESTs).

-- VESTs is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation; either version 2 of the License, or (at
-- your option) any later version. 

-- VESTs is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-- for more details. 

-- You should have received a copy of the GNU General Public License
-- along with VESTs; if not, write to the Free Software Foundation,
-- Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 

-- ---------------------------------------------------------------------
--
-- $Id: ch_14_fg_14_01.vhd,v 1.2 2001-10-26 16:29:35 paw Exp $
-- $Revision: 1.2 $
--
-- ---------------------------------------------------------------------

library ieee;  use ieee.std_logic_1164.all;

               entity D_flipflop is
                 port ( clk : in std_logic;  d : in std_logic;
                 q : out std_logic );
               end entity D_flipflop;


               architecture synthesized of D_flipflop is
               begin
                 q <= d when not clk'stable and (To_X01(clk) = '1') and 
                      (To_X01(clk'last_value) = '0');
               end architecture synthesized;


               library ieee;  use ieee.std_logic_1164.all;

               entity tristate_buffer is
                 port ( a : in std_logic;
                        en : in std_logic;
                        y : out std_logic );
               end entity tristate_buffer;


               architecture synthesized of tristate_buffer is
               begin
                 y <= 'X' when is_X(en) else
                      a  when To_X01(en) = '1' else
                      'Z';
               end architecture synthesized;



-- code from book (in Figure 14-1)

               library ieee;  use ieee.std_logic_1164.all;

               entity register_tristate is
                 generic ( width : positive );
                 port ( clock : in std_logic;
                        out_enable : in std_logic;
                        data_in : in std_logic_vector(0 to width - 1);
                        data_out : out std_logic_vector(0 to width - 1) );
               end entity register_tristate;

--------------------------------------------------

               architecture cell_level of register_tristate is

                 component D_flipflop is
                                        port ( clk : in std_logic;  d : in std_logic;
                                        q : out std_logic );
                 end component D_flipflop;

                 component tristate_buffer is
                                             port ( a : in std_logic;
                                                    en : in std_logic;
                                                    y : out std_logic );
                 end component tristate_buffer;

               begin

                 cell_array : for bit_index in 0 to width - 1 generate

                   signal data_unbuffered : std_logic;

                 begin

                   cell_storage : component D_flipflop
                     port map ( clk => clock, d => data_in(bit_index),
                                q => data_unbuffered );

                   cell_buffer : component tristate_buffer
                     port map ( a => data_unbuffered, en => out_enable,
                                y => data_out(bit_index) );

                 end generate cell_array;

               end architecture cell_level;

-- end code from book (in Figure 14-1)


-- code from book (in Figure 14-11)

               library cell_lib;

               configuration identical_cells of register_tristate is

                 for cell_level

                   for cell_array

                   for cell_storage : D_flipflop
                   use entity cell_lib.D_flipflop(synthesized);
               end for;

               for cell_buffer : tristate_buffer
                 use entity cell_lib.tristate_buffer(synthesized);
               end for;

               end for;

               end for;

               end configuration identical_cells;

-- code from book (in Figure 14-11)



               library ieee;  use ieee.std_logic_1164.all;

               entity fg_14_01 is
               end entity fg_14_01;


               architecture test of fg_14_01 is

                 signal clk, en : std_logic;
                 signal d_in, d_out : std_logic_vector(0 to 3);

               begin

                 dut : configuration work.identical_cells
                   generic map ( width => d_in'length )
                   port map ( clock => clk, out_enable => en,
                              data_in => d_in, data_out => d_out );

                 stimulus : process is
                 begin
                   wait for 10 ns;
                   d_in <= "0000";  en <= '0';  clk <= '0';  wait for 10 ns;
                   clk <= '1', '0' after 5 ns;  wait for 10 ns;
                   en <= '1', '0' after 5 ns;   wait for 10 ns;
                   d_in <= "0101";              wait for 10 ns;
                   clk <= '1', '0' after 5 ns;  wait for 10 ns;
                   en <= 'H', '0' after 5 ns;   wait for 10 ns;

                   wait;
                 end process stimulus;

               end architecture test;

-- end not in book