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

Subversion Repositories System09

[/] [System09/] [trunk/] [rtl/] [System09_Digilent_Atlys/] [common.vhd] - Blame information for rev 169

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

Line No. Rev Author Line
1 141 davidgb
--------------------------------------------------------------------
2
-- Company       : XESS Corp.
3
-- Engineer      : Dave Vanden Bout
4
-- Creation Date : 05/17/2005
5
-- Copyright     : 2005, XESS Corp
6
-- Tool Versions : WebPACK 6.3.03i
7
--
8
-- Description:
9
--    Miscellaneous VHDL constants and functions
10
--
11
-- Revision:
12
--    1.0.0
13
--
14
-- Additional Comments:
15
--    1.1.0:
16
--        Added int_select() and real_select functions.
17
--    1.0.0:
18
--        Initial release.
19
--
20
-- License:
21
--    This code can be freely distributed and modified as long as
22
--    this header is not removed.
23
--------------------------------------------------------------------
24
 
25
 
26
 
27
library IEEE;
28
use IEEE.std_logic_1164.all;
29
use IEEE.numeric_std.all;
30
 
31
package common is
32
 
33
  constant YES                :    std_logic := '1';
34
  constant NO                 :    std_logic := '0';
35
  constant HI                 :    std_logic := '1';
36
  constant LO                 :    std_logic := '0';
37
  constant ONE                :    std_logic := '1';
38
  constant ZERO               :    std_logic := '0';
39
  -- convert a Boolean to a std_logic
40
  function boolean2stdlogic(b : in boolean) return std_logic;
41
  -- find the base-2 logarithm of a number
42
  function log2(v             : in natural) return natural;
43
  -- select one of two integers based on a Boolean
44
  function int_select(s       : in boolean; a : in integer; b : in integer) return integer;
45
  -- select one of two reals based on a Boolean
46
  function real_select(s      : in boolean; a : in real; b : in real) return real;
47
 
48
end package common;
49
 
50
 
51
 
52
library IEEE;
53
use IEEE.std_logic_1164.all;
54
use IEEE.numeric_std.all;
55
 
56
 
57
package body common is
58
 
59
  -- convert a Boolean to a std_logic
60
  function boolean2stdlogic(b : in boolean) return std_logic is
61
    variable s                :    std_logic;
62
  begin
63
    if b then
64
      s := '1';
65
    else
66
      s := '0';
67
    end if;
68
    return s;
69
  end function boolean2stdlogic;
70
 
71
  -- find the base 2 logarithm of a number
72
  function log2(v : in natural) return natural is
73
    variable n    :    natural;
74
    variable logn :    natural;
75
  begin
76
    n      := 1;
77
    for i in 0 to 128 loop
78
      logn := i;
79
      exit when (n >= v);
80
      n    := n * 2;
81
    end loop;
82
    return logn;
83
  end function log2;
84
 
85
  -- select one of two integers based on a Boolean
86
  function int_select(s : in boolean; a : in integer; b : in integer) return integer is
87
  begin
88
    if s then
89
      return a;
90
    else
91
      return b;
92
    end if;
93
    return a;
94
  end function int_select;
95
 
96
  -- select one of two reals based on a Boolean
97
  function real_select(s : in boolean; a : in real; b : in real) return real is
98
  begin
99
    if s then
100
      return a;
101
    else
102
      return b;
103
    end if;
104
    return a;
105
  end function real_select;
106
 
107
end package body common;

powered by: WebSVN 2.1.0

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