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

Subversion Repositories tcp_ip_core_w_dhcp

[/] [tcp_ip_core_w_dhcp/] [trunk/] [Common.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 craighaywo
----------------------------------------------------------------------------------
2
-- This program is free software; you can redistribute it and/or
3
-- modify it under the terms of the GNU General Public License
4
-- as published by the Free Software Foundation; either version 2
5
-- of the License, or (at your option) any later version.
6
--
7
-- This program is distributed in the hope that it will be useful,
8
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
9
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
-- GNU General Public License for more details.
11
--
12
-- You should have received a copy of the GNU General Public License
13
-- along with this program; if not, write to the Free Software
14
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
15
-- 02111-1307, USA.
16
--
17
-- ©1997-2011 - X Engineering Software Systems Corp. (www.xess.com)
18
----------------------------------------------------------------------------------
19
 
20
----------------------------------------------------------------------------------
21
-- Commonly-used functions and constants.
22
----------------------------------------------------------------------------------
23
 
24
 
25
library IEEE;
26
use IEEE.std_logic_1164.all;
27
use IEEE.numeric_std.all;
28
 
29
package CommonPckg is
30
 
31
  constant YES  : std_logic := '1';
32
  constant NO   : std_logic := '0';
33
  constant HI   : std_logic := '1';
34
  constant LO   : std_logic := '0';
35
  constant ONE  : std_logic := '1';
36
  constant ZERO : std_logic := '0';
37
  constant HIZ  : std_logic := 'Z';
38
 
39
  -- Types of FPGA chips.
40
  constant SPARTAN2_G  : natural := 1;
41
  constant SPARTAN2E_G : natural := 2;
42
  constant SPARTAN3_G  : natural := 3;
43
 
44
  -- Convert a Boolean to a std_logic.
45
  function BooleanToStdLogic(b : in boolean) return std_logic;
46
 
47
  -- Find the base-2 logarithm of a number.
48
  function Log2(v : in natural) return natural;
49
 
50
  -- Select one of two integers based on a Boolean.
51
  function IntSelect(s : in boolean; a : in integer; b : in integer) return integer;
52
 
53
  -- Select one of two reals based on a Boolean.
54
  function RealSelect(s : in boolean; a : in real; b : in real) return real;
55
 
56
  -- Convert a binary number to a graycode number.
57
  function BinaryToGray(b : in std_logic_vector) return std_logic_vector;
58
 
59
  -- Convert a graycode number to a binary number.
60
  function GrayToBinary(g : in std_logic_vector) return std_logic_vector;
61
 
62
  -- Find the maximum of two integers.
63
  function IntMax(a : in integer; b : in integer) return integer;
64
 
65
end package;
66
 
67
 
68
 
69
library IEEE;
70
use IEEE.std_logic_1164.all;
71
use IEEE.numeric_std.all;
72
 
73
 
74
package body CommonPckg is
75
 
76
  -- Convert a Boolean to a std_logic.
77
  function BooleanToStdLogic(b : in boolean) return std_logic is
78
    variable s : std_logic;
79
  begin
80
    if b then
81
      s := '1';
82
    else
83
      s := '0';
84
    end if;
85
    return s;
86
  end function BooleanToStdLogic;
87
 
88
  -- Find the base 2 logarithm of a number.
89
  function Log2(v : in natural) return natural is
90
    variable n    : natural;
91
    variable logn : natural;
92
  begin
93
    n := 1;
94
    for i in 0 to 128 loop
95
      logn := i;
96
      exit when (n >= v);
97
      n    := n * 2;
98
    end loop;
99
    return logn;
100
  end function Log2;
101
 
102
  -- Select one of two integers based on a Boolean.
103
  function IntSelect(s : in boolean; a : in integer; b : in integer) return integer is
104
  begin
105
    if s then
106
      return a;
107
    else
108
      return b;
109
    end if;
110
    return a;
111
  end function IntSelect;
112
 
113
  -- Select one of two reals based on a Boolean.
114
  function RealSelect(s : in boolean; a : in real; b : in real) return real is
115
  begin
116
    if s then
117
      return a;
118
    else
119
      return b;
120
    end if;
121
    return a;
122
  end function RealSelect;
123
 
124
  -- Convert a binary number to a graycode number.
125
  function BinaryToGray(b : in std_logic_vector) return std_logic_vector is
126
    variable g : std_logic_vector(b'range);
127
  begin
128
    for i in b'low to b'high-1 loop
129
      g(i) := b(i) xor b(i+1);
130
    end loop;
131
    g(b'high) := b(b'high);
132
    return g;
133
  end function BinaryToGray;
134
 
135
  -- Convert a graycode number to a binary number.
136
  function GrayToBinary(g : in std_logic_vector) return std_logic_vector is
137
    variable b : std_logic_vector(g'range);
138
  begin
139
    b(b'high) := g(b'high);
140
    for i in g'high-1 downto g'low loop
141
      b(i) := b(i+1) xor g(i);
142
    end loop;
143
    return b;
144
  end function GrayToBinary;
145
 
146
  -- Find the maximum of two integers.
147
  function IntMax(a : in integer; b : in integer) return integer is
148
  begin
149
    if a > b then
150
      return a;
151
    else
152
      return b;
153
    end if;
154
    return a;
155
  end function IntMax;
156
 
157
end package body;

powered by: WebSVN 2.1.0

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