Project

General

Profile

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

    
27
library math;
28

    
29
architecture behavior of source is
30

    
31
begin
32

    
33
  token_generator : process is
34

    
35
                              variable source_name : string(1 to name_max_length) := (others => ' ');
36
                            variable source_name_length : natural;
37
                            variable next_token_id : token_id_type := 0;
38
                            variable next_arrival_time : time;
39
                            variable number_of_tokens_generated : natural := 0;
40
                            variable inter_arrival_time : natural;  -- in time_unit
41
                            variable sum_of_inter_arrival_times : real := 0.0;  -- in time_unit
42
                            variable sum_of_squares_of_inter_arrival_times : real := 0.0;  --in time_unit**2
43

    
44
                            variable random_info : random_info_record;
45
                            variable random_number : real;
46

    
47
                            use std.textio.all;
48
                            file info_file : text;
49
                            variable L : line;
50

    
51
                            use math.math_real.sqrt;
52

    
53
                            procedure write_summary is
54
                              variable measured_mean_inter_arrival_time : real
55
                                := sum_of_inter_arrival_times / real(number_of_tokens_generated);
56
                              variable measured_std_dev_of_inter_arrival_times : real
57
                                := sqrt ( ( sum_of_squares_of_inter_arrival_times
58
                                            - sum_of_inter_arrival_times**2 / real(number_of_tokens_generated) )
59
                                          / real( number_of_tokens_generated - 1 ) );
60
                            begin
61
                              write(L, string'("Summary information for source "));
62
                              write(L, name);
63
                              write(L, string'(" up to time "));
64
                              write(L, now, unit => time_unit);
65
                              writeline(info_file, L);
66
                              write(L, string'("  Inter arrival distribution: "));
67
                              write(L, distribution_type'image(distribution));
68
                              write(L, string'(" with mean inter arrival time of "));
69
                              write(L, mean_inter_arrival_time, unit => time_unit);
70
                              writeline(info_file, L);
71
                              write(L, string'("  Number of tokens generated = "));
72
                              write(L, natural(next_token_id));
73
                              writeline(info_file, L);
74
                              write(L, string'("  Mean inter arrival time = "));
75
                              write(L, measured_mean_inter_arrival_time * time_unit, unit => time_unit);
76
                              writeline(info_file, L);
77
                              write(L, string'("  Standard deviation of inter arrival times = "));
78
                              write(L, measured_std_dev_of_inter_arrival_times * time_unit, unit => time_unit);
79
                              writeline(info_file, L);
80
                              writeline(info_file, L);
81
                            end procedure write_summary;
82

    
83
                            procedure write_trace is
84
                            begin
85
                              write(L, string'("Source "));
86
                              write(L, name);
87
                              write(L, string'(": at "));
88
                              write(L, now, unit => time_unit);
89
                              write(L, string'(" generated token "));
90
                              write(L, natural(next_token_id));
91
                              writeline(info_file, L);
92
                            end procedure write_trace;
93

    
94
  begin
95
    if name'length > name_max_length then
96
      source_name := name(1 to name_max_length);
97
      source_name_length := name_max_length;
98
    else
99
      source_name(1 to name'length) := name;
100
      source_name_length := name'length;
101
    end if;
102
    file_open(info_file, info_file_name, write_mode);
103

    
104
    case distribution is
105
      when fixed =>
106
        init_fixed(random_info, real(mean_inter_arrival_time / time_unit));
107
      when uniform =>
108
        init_uniform( random_info,
109
                      lower_bound => 0.0,
110
                      upper_bound => 2.0 * real(mean_inter_arrival_time / time_unit),
111
                      seed => seed );
112
      when exponential =>
113
        init_exponential( random_info,
114
                          mean => real(mean_inter_arrival_time / time_unit),
115
                          seed => seed );
116
    end case;
117

    
118
    loop
119
      generate_random(random_info, random_number);
120
      inter_arrival_time :=  natural(random_number);
121
      next_arrival_time := inter_arrival_time * time_unit + now;
122
      loop
123
        wait on info_detail'transaction for next_arrival_time - now;
124
        if info_detail'active and info_detail = summary then
125
          write_summary;
126
        end if;
127
        exit when next_arrival_time = now;
128
      end loop;
129
      out_arc <= arc_type'( transaction => not out_arc.transaction'driving_value,
130
		            token => token_type'( source_name => source_name,
131
                                                  source_name_length => source_name_length,
132
                                                  id => next_token_id,
133
                                                  creation_time => now ) );
134
      number_of_tokens_generated := number_of_tokens_generated + 1;
135
      sum_of_inter_arrival_times := sum_of_inter_arrival_times
136
                                    + real(inter_arrival_time);
137
      sum_of_squares_of_inter_arrival_times := sum_of_squares_of_inter_arrival_times
138
                                               + real(inter_arrival_time) ** 2;
139

    
140
      if info_detail = trace then
141
        write_trace;
142
      end if;
143
      next_token_id := next_token_id + 1;
144
    end loop;
145
  end process token_generator;
146

    
147
end architecture behavior;
(149-149/171)