Project

General

Profile

Download (4.47 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_19_join-b.vhd,v 1.3 2001-10-26 16:29:36 paw Exp $
23
-- $Revision: 1.3 $
24
--
25
-- ---------------------------------------------------------------------
26

    
27
library qsim;
28

    
29
architecture behavior of join is
30

    
31
begin
32

    
33
  joiner : process
34

    
35
    use qsim.token_fifo_adt.all;
36

    
37
    variable source : positive range in_arc'range;
38
    variable token_fifo : fifo_type := new_fifo;
39
    variable current_fifo_size : natural := 0;
40
    variable head_token : token_type;
41
    variable number_of_tokens_joined : natural := 0;
42
    type counter_array is array (positive range in_arc'range) of natural;
43
    variable number_joined_from_source : counter_array := (others => 0);
44

    
45
    use std.textio.all;
46
    file info_file : text;
47
    variable L : line;
48

    
49
--  Modeltech bug mt043 workaround
50
    variable in_arc_last_value : arc_vector(in_arc'range) := in_arc;
51
--
52

    
53
    procedure write_summary is
54
    begin
55
      write(L, string'("Summary information for join "));
56
      write(L, name);
57
      write(L, string'(" up to time "));
58
      write(L, now, unit => time_unit);
59
      writeline(info_file, L);
60
      write(L, string'("  Number of tokens joined = "));
61
      write(L, natural(number_of_tokens_joined));
62
      writeline(info_file, L);
63
      for source in in_arc'range loop
64
        write(L, string'("    Number from input("));
65
        write(L, source);
66
        write(L, string'(") = "));
67
        write(L, natural(number_joined_from_source(source)));
68
        write(L, string'(" ("));
69
        write(L, real(number_joined_from_source(source))
70
              / real(number_of_tokens_joined),
71
              digits => 4);
72
        write(L, ')');
73
        writeline(info_file, L);
74
      end loop;
75
      writeline(info_file, L);
76
    end write_summary;
77

    
78
    procedure write_trace is
79
    begin
80
      write(L, string'("Join "));
81
      write(L, name);
82
      write(L, string'(": at "));
83
      write(L, now, unit => time_unit);
84
      write(L, string'(" joined from input "));
85
      write(L, source);
86
      write(L, ' ');
87
      write(L, in_arc(source).token, time_unit);
88
      writeline(info_file, L);
89
    end write_trace;
90

    
91
    procedure accept_new_tokens is
92
    begin
93
      for index in 1 to in_arc'length loop
94
--  Modeltech bug mt043 workaround
95
--      if in_arc(index).transaction /= in_arc'last_value(index).transaction then
96
        if in_arc(index).transaction /= in_arc_last_value(index).transaction then
97
--
98
          source := index;
99
          insert(token_fifo, in_arc(source).token);
100
          current_fifo_size := current_fifo_size + 1;
101
          number_of_tokens_joined := number_of_tokens_joined + 1;
102
          number_joined_from_source(source) := number_joined_from_source(source) + 1;
103
          if info_detail = trace then
104
            write_trace;
105
          end if;
106
        end if;
107
      end loop;
108
--  Modeltech bug mt043 workaround
109
      in_arc_last_value := in_arc;
110
--
111
    end procedure accept_new_tokens;
112

    
113
  begin
114
    file_open(info_file, info_file_name, write_mode);
115
    loop
116
      wait on info_detail'transaction, in_arc;
117
      if info_detail'active and info_detail = summary then
118
        write_summary;
119
      end if;
120
      if in_arc'event then
121
	accept_new_tokens;
122
        while current_fifo_size > 0 loop
123
          remove(token_fifo, head_token);
124
          current_fifo_size := current_fifo_size - 1;
125
	  out_arc <= arc_type'( transaction => not out_arc.transaction'driving_value,
126
			        token => head_token );
127
          wait for 0 fs;  -- delta delay before next output token
128
          if info_detail'active and info_detail = summary then
129
            write_summary;
130
          end if;
131
          if in_arc'event then
132
	    accept_new_tokens;
133
	  end if;
134
        end loop;
135
      end if;
136
    end loop;
137
  end process joiner;
138

    
139
end behavior;
(430-430/510)