aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/gna/issue2156/timing_pkg.vhdl
blob: ab00651e5ee4745868f51762fddd1954103d7acb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package timing_pkg is

  type frequency is range 0.0 to real'high;

  function to_string(
    freq : frequency;
    unit : string := "";
    fmt  : string := "%.6f")
    return string;

end package;

package body timing_pkg is

  function to_string(
    freq : frequency;
    unit : string := "";
    fmt  : string := "%.6f")
    return string
  is
  begin
    if unit = "" then
      if freq < 1.0e3 then
        return to_string(real(freq), fmt) & " Hz";
      elsif 1.0e3 <= freq and freq < 1.0e6 then
        return to_string(real(freq) * 1.0e-3, fmt) & " kHz";
      elsif 1.0e6 <= freq and freq < 1.0e9 then
        return to_string(real(freq) * 1.0e-6, fmt) & " MHz";
      else
        return to_string(real(freq) * 1.0e-9, fmt) & " GHz";
      end if;
    elsif unit = "Hz" then
      return to_string(real(freq), fmt) & " Hz";
    elsif unit = "kHz" then
      return to_string(real(freq) * 1.0e-3, fmt) & " kHz";
    elsif unit = "MHz" then
      return to_string(real(freq) * 1.0e-6, fmt) & " MHz";
    elsif unit = "GHz" then
      return to_string(real(freq) * 1.0e-9, fmt) & " GHz";
    else
      report "invalid frequency unit (Hz, kHz, MHz, GHz)"
      severity failure;
    end if;
  end function;

end package body;