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

Subversion Repositories sincos

[/] [sincos/] [trunk/] [vhdl/] [tb/] [file_log/] [file_log.vhd] - Blame information for rev 38

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 dk4xp
-- logging of signal values into a text file
2
-- (c) 2011... Gerhard Hoffmann, Ulm, Germany   opencores@hoffmann-hochfrequenz.de
3
--
4
-- V1.0 2011-feb-24 published under BSD license
5
--
6
-- This entity logs signals to a file. There are several flavours for use with several types.
7
-- Logging happens on the rising edge of the clock signal with CE active.
8
-- The filename is given by a string. The signal log_on, when true, opens the
9
-- file for writing; setting it to false closes the file.
10
-- Toggling log_on several times without changing the filename will overwrite
11
-- the file.
12
--
13
-- TODO: integer version
14
 
15
library ieee;
16
use     ieee.std_logic_1164.all;
17
use     ieee.numeric_std.all;
18
use     std.textio.all;
19
 
20
 
21
entity real_file_log is
22
   Port (
23
      clk:      in  std_logic;
24
      ce:       in  std_logic := '1';
25
      filename: in  string    := "log.txt";
26
      log_on:   in  std_logic := '1';
27
      d:        in  real
28
   );
29
end real_file_log;
30
 
31
 
32
----------------------------------------------------------------------------------------------------
33
 
34
 
35
architecture tb of real_file_log is
36
begin
37
 
38
log_p: process is
39
 
40
   file     phyle:      text;
41
   variable l:          line;
42
   variable filestatus: file_open_status;
43
 
44
begin
45
 
46
   wait until rising_edge(log_on);
47
   file_close(phyle);  -- in case the file was open already
48
   file_open(filestatus, phyle, filename, write_mode);
49
   assert filestatus = open_ok
50
           report "real_file_log: cannot open destination file <" & filename & ">"
51
           severity failure;
52
 
53
log_loop:
54
   loop
55
      wait until rising_edge(clk) or log_on'event;
56
 
57
      if ( log_on /= '1' )
58
      then
59
         file_close(phyle);
60
         exit;
61
      else
62
         -- must have been a rising clock edge
63
         if ce = '1'
64
         then
65
           write (l, d, right, 20);  -- right justified, 20 digits wide 
66
         end if;  -- ce='1' 
67
      end if;     -- not activate   
68
      writeline(phyle, l);
69
   end loop log_loop;
70
end process log_p;
71
 
72
end architecture tb;
73
 

powered by: WebSVN 2.1.0

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