Project

General

Profile

Download (4.39 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc
3

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

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

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

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

    
20
-- ---------------------------------------------------------------------
21
--
22
-- $Id: ch_17_fg_17_11.vhd,v 1.2 2001-10-26 16:29:36 paw Exp $
23
-- $Revision: 1.2 $
24
--
25
-- ---------------------------------------------------------------------
26

    
27
package body bounded_buffer_adt is
28

    
29
  function new_bounded_buffer ( size : in positive ) return bounded_buffer is
30
  begin
31
    return new bounded_buffer_object'(
32
      byte_count => 0, head_index => 0, tail_index => 0,
33
      store => new store_array(0 to size - 1) );
34
  end function new_bounded_buffer;
35

    
36
  procedure test_empty ( variable the_bounded_buffer : in bounded_buffer;
37
                         is_empty : out boolean ) is
38
  begin
39
    is_empty := the_bounded_buffer.byte_count = 0;
40
  end procedure test_empty;
41

    
42
  procedure test_full ( variable the_bounded_buffer : in bounded_buffer;
43
                        is_full : out boolean ) is
44
  begin
45
    is_full := the_bounded_buffer.byte_count = the_bounded_buffer.store'length;
46
  end procedure test_full;
47

    
48
  procedure write ( the_bounded_buffer : inout bounded_buffer;  data : in byte ) is
49
    variable buffer_full : boolean;
50
  begin
51
    test_full(the_bounded_buffer, buffer_full);
52
    if buffer_full then
53
      report "write to full bounded buffer" severity failure;
54
    else
55
      the_bounded_buffer.store(the_bounded_buffer.tail_index) := data;
56
      the_bounded_buffer.tail_index := (the_bounded_buffer.tail_index + 1)
57
                                       mod the_bounded_buffer.store'length;
58
      the_bounded_buffer.byte_count := the_bounded_buffer.byte_count + 1;
59
    end if;
60
  end procedure write;
61

    
62
  procedure read ( the_bounded_buffer : inout bounded_buffer;  data : out byte ) is
63
    variable buffer_empty : boolean;
64
  begin
65
    test_empty(the_bounded_buffer, buffer_empty);
66
    if buffer_empty then
67
      report "read from empty bounded buffer" severity failure;
68
    else
69
      data := the_bounded_buffer.store(the_bounded_buffer.head_index);
70
      the_bounded_buffer.head_index := (the_bounded_buffer.head_index + 1)
71
                                       mod the_bounded_buffer.store'length;
72
      the_bounded_buffer.byte_count := the_bounded_buffer.byte_count - 1;
73
    end if;
74
  end procedure read;
75

    
76
end package body bounded_buffer_adt;
77

    
78

    
79

    
80
-- not in book
81

    
82
entity fg_17_11 is
83
end entity fg_17_11;
84

    
85

    
86
architecture test of fg_17_11 is
87
begin
88

    
89
  process is
90

    
91
            use work.bounded_buffer_adt.all;
92

    
93
          variable buf : bounded_buffer := new_bounded_buffer(4);
94
          variable empty, full : boolean;
95
          variable d : byte;
96

    
97
  begin
98
    test_empty(buf, empty);
99
    assert empty;
100
    test_full(buf, full);
101
    assert not full;
102

    
103
    write(buf, X"01");
104
    write(buf, X"02");
105

    
106
    test_empty(buf, empty);
107
    assert not empty;
108
    test_full(buf, full);
109
    assert not full;
110

    
111
    write(buf, X"03");
112
    write(buf, X"04");
113

    
114
    test_empty(buf, empty);
115
    assert not empty;
116
    test_full(buf, full);
117
    assert full;
118

    
119
    write(buf, X"05");
120

    
121
    read(buf, d);
122
    read(buf, d);
123

    
124
    test_empty(buf, empty);
125
    assert not empty;
126
    test_full(buf, full);
127
    assert not full;
128

    
129
    read(buf, d);
130
    read(buf, d);
131

    
132
    test_empty(buf, empty);
133
    assert empty;
134
    test_full(buf, full);
135
    assert not full;
136

    
137
    read(buf, d);
138

    
139
    write(buf, X"06");
140
    write(buf, X"07");
141
    write(buf, X"08");
142
    read(buf, d);
143
    read(buf, d);
144
    write(buf, X"09");
145
    read(buf, d);
146
    write(buf, X"0A");
147
    read(buf, d);
148
    write(buf, X"0B");
149
    read(buf, d);
150
    write(buf, X"0C");
151
    read(buf, d);
152
    write(buf, X"0D");
153
    read(buf, d);
154
    write(buf, X"0E");
155
    read(buf, d);
156
    write(buf, X"0F");
157
    read(buf, d);
158

    
159
    wait;
160
  end process;
161

    
162
end architecture test;
163

    
164
-- end not in book
(370-370/510)