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

Subversion Repositories astron_mm

[/] [astron_mm/] [trunk/] [mm_file.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3
-- Copyright (C) 2012
4
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6
--
7
-- This program is free software: you can redistribute it and/or modify
8
-- it under the terms of the GNU General Public License as published by
9
-- the Free Software Foundation, either version 3 of the License, or
10
-- (at your option) any later version.
11
--
12
-- This program is distributed in the hope that it will be useful,
13
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-- GNU General Public License for more details.
16
--
17
-- You should have received a copy of the GNU General Public License
18
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
-------------------------------------------------------------------------------
21
 
22
-- Author:
23
--   D. van der Schuur May 2012  Initial
24
--   E. Kooistra       Jan 2018  Removed unused generics and added remarks.
25
-- Purpose: Provide access to an MM slave via file IO
26
-- Description:
27
--   See mm_file_pkg.
28
--
29
-- * Optional MM file IO throttle via g_mm_timeout, g_mm_pause:
30
--   Default g_mm_timeout=0 ns for full speed MM file IO rate. Optional use
31
--   g_mm_timeout>0 ns to throttle MM file IO rate. The mm_master_out wr and
32
--   rd strobes are monitored. As long as a strobe occurs within
33
--   g_mm_timeout then the MM file IO operates at full speed. When no strobe
34
--   occurs within g_mm_timeout, then a delay of g_mm_pause is inserted
35
--   until the next MM file IO access will be done. This throttling reduces
36
--   the file IO rate when the MM slave is idle and picks up again at full
37
--   speed when MM slave accesses appear again.
38
--
39
--   The g_mm_timeout is in ns, and not defined in number of mm_clk cycles,
40
--   to make it independent of the simulation mm_clk period. This is
41
--   important to be able to handle clock domain crossings between a fast
42
--   simulation mm_clk and a relatively slow internal dp_clk. If the
43
--   g_mm_timeout is too short then it will occur for every MM access that
44
--   needs a MM-DP clock domain crossing. A dp_clk typically runs at
45
--   about 100 or 200 MHz, so period < about 10 ns. A clock domain crossing
46
--   takes about 25 clock cycles in both clock domains (see
47
--   common_reg_cross_domain.vhd). Hence a suitable default value for 
48
--   g_mm_timeout is about 250 ns. With some margin use 1000 ns. 
49
--   The g_mm_pause is defined in ns, but could as well have been defined
50
--   in number mm_clk cycle. Use g_mm_pause default 100 ns to have a factor
51
--   1000 reduction in file IO rate witk c_mmf_mm_clk_period = 100 ps, while
52
--   not introducing too much delay in case a new MM access is pending.
53
--
54
-- Remarks:
55
-- * Positional mapping of generics and port:
56
--   If necessary new generics or ports should be added after the existing
57
--   generics or ports, because then existing mm_file instances that use 
58
--   positional mapping instead of explicit name mapping (with =>) still 
59
--   compile ok.
60
--
61
-- * Default g_mm_rd_latency=2:
62
--   The default g_mm_rd_latency=2 to fit both MM reg (which typically have rd
63
--   latency 1) and MM ram (for which some have rd latency 2). This works
64
--   because the mm_master_out.rd strobes have gaps. The maximum rd strobe 
65
--   rate appears to be 1 strobe in every 4 cycles. By using default 
66
--   g_mm_rd_latency=2 the mm_file instances do not explicitly have to map the
67
--   actual MM slave rd latency, because using 2 fits all. This ensures 
68
--   that all existing mm_file instances that do not map g_mm_rd_latency still
69
--   work and for new mm_file instances it avoids the need to know whether the
70
--   MM slave actually has rd latency 1 or 2.
71
--
72
-- * Default g_file_enable='1':
73
--   Default the mm_file instance will open the files. However if the MM slave
74
--   will not be used in a test, then it can be good to use g_file_enable='0'
75
--   to avoid these files. For multi tb or tb with many mm_file instances this 
76
--   limits the number of file handlers and may help to improve the simulation
77
--   speed (and stability).
78
--
79
LIBRARY IEEE, common_pkg_lib, common_ram_lib;
80
USE IEEE.std_logic_1164.ALL;
81
USE IEEE.numeric_std.ALL;
82
USE common_pkg_lib.common_pkg.ALL;
83
USE common_pkg_lib.tb_common_pkg.ALL;
84
USE common_ram_lib.common_ram_pkg.ALL;
85
USE work.tb_common_mem_pkg.ALL;
86
USE common_pkg_lib.common_str_pkg.ALL;
87
USE work.mm_file_pkg.ALL;
88
USE IEEE.std_logic_textio.ALL;
89
USE std.textio.ALL;
90
 
91
ENTITY mm_file IS
92
  GENERIC (
93
    g_file_prefix       : STRING;            -- e.g. "ppsh" will create i/o files ppsh_stat.txt and ppsh_ctrl.txt
94
    g_file_enable       : STD_LOGIC := '1';  -- default use '1' to enable file IO, use '0' to disable file IO and force mm_master_out to c_mem_mosi_rst
95
    g_mm_rd_latency     : NATURAL := 2;      -- default use 2 to fit 0, 1 or 2, must be >= read latency of the MM slave
96
    g_mm_timeout        : TIME := c_mmf_mm_timeout;  -- use 0 ns for full speed MM, use > 0 ns to define time without MM access after which the MM file IO is paused
97
    g_mm_pause          : TIME := c_mmf_mm_pause     -- defines time for which MM file IO is paused to reduce the file IO rate when the MM slave is idle
98
  );
99
  PORT (
100
    mm_rst        : IN  STD_LOGIC;
101
    mm_clk        : IN  STD_LOGIC;
102
 
103
    mm_master_out : OUT t_mem_mosi := c_mem_mosi_rst;
104
    mm_master_in  : IN  t_mem_miso := c_mem_miso_rst
105
  );
106
END mm_file;
107
 
108
 
109
ARCHITECTURE str OF mm_file IS
110
 
111
  CONSTANT c_rd_file_name : STRING :=  g_file_prefix & ".ctrl";
112
  CONSTANT c_wr_file_name : STRING :=  g_file_prefix & ".stat";
113
 
114
  SIGNAL i_mm_master_out : t_mem_mosi;
115
 
116
  -- Optional file IO throttle control
117
  SIGNAL strobe          : STD_LOGIC;
118
  SIGNAL pause           : STD_LOGIC;
119
  SIGNAL polling         : STD_LOGIC := '0';  -- monitor signal to view in Wave window when mmf_mm_from_file() is busy
120
  SIGNAL timebegin       : TIME := 0 ns;
121
  SIGNAL timeout         : TIME := 0 ns;
122
 
123
BEGIN
124
 
125
  mm_master_out <= i_mm_master_out;
126
 
127
  no_file : IF g_file_enable='0' GENERATE
128
    i_mm_master_out <= c_mem_mosi_rst;
129
  END GENERATE;
130
 
131
  gen_file : IF g_file_enable='1' GENERATE
132
 
133
    p_file_to_mm : PROCESS
134
    BEGIN
135
      i_mm_master_out <= c_mem_mosi_rst;
136
 
137
      -- Create the ctrl file that we're going to read from
138
      print_str("[" & time_to_str(NOW) & "] " & c_rd_file_name & ": Created" );
139
      mmf_file_create(c_rd_file_name);
140
 
141
      WHILE TRUE LOOP
142
        mmf_mm_from_file(mm_clk, mm_rst, i_mm_master_out, mm_master_in, c_rd_file_name, c_wr_file_name, g_mm_rd_latency);
143
 
144
        -- Optional file IO throttle control
145
        IF g_mm_timeout>0 ns AND pause='1' THEN
146
          polling <= '0';
147
          WAIT FOR g_mm_pause;  -- Pause the file IO when MM timeout is enabled and no strobes appeared for g_mm_timeout
148
 
149
          proc_common_wait_some_cycles(mm_clk, 1);  -- Realign to mm_clk, not needed but done to resemble return from mmf_mm_from_file()
150
          polling <= '1';
151
        END IF;
152
      END LOOP;
153
 
154
      WAIT;
155
    END PROCESS;
156
 
157
    -- Optional file IO throttle control
158
    gen_mm_timeout_control : IF g_mm_timeout>0 ns GENERATE
159
      strobe <= i_mm_master_out.wr OR i_mm_master_out.rd;  -- detect MM access
160
 
161
      pause <= NOT strobe WHEN timeout>g_mm_timeout ELSE '0';  -- issue MM file IO pause after strobe timeout
162
 
163
      -- Use mm_clk event to update time based on NOW, without event it does not update
164
      p_mm_now : PROCESS(mm_rst, mm_clk)
165
      BEGIN
166
        IF mm_rst='1' THEN
167
          -- during reset no timeouts
168
          timebegin <= NOW;
169
          timeout <= 0 ns;
170
        ELSE
171
          -- use MM access to restart timeout
172
          IF strobe='1' THEN
173
            timebegin <= NOW;
174
          END IF;
175
          timeout <= NOW - timebegin;
176
        END IF;
177
      END PROCESS;
178
    END GENERATE;
179
 
180
  END GENERATE;
181
 
182
END str;
183
 

powered by: WebSVN 2.1.0

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