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

Subversion Repositories risc5x

[/] [risc5x/] [trunk/] [pkg_risc5x.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mikej
--
2
-- Risc5x
3
-- www.OpenCores.Org - November 2001
4
--
5
--
6
-- This library is free software; you can distribute it and/or modify it
7
-- under the terms of the GNU Lesser General Public License as published
8
-- by the Free Software Foundation; either version 2.1 of the License, or
9
-- (at your option) any later version.
10
--
11
-- This library is distributed in the hope that it will be useful, but
12
-- WITHOUT ANY WARRANTY; without even the implied warranty of
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
-- See the GNU Lesser General Public License for more details.
15
--
16
-- A RISC CPU core.
17
--
18
-- (c) Mike Johnson 2001. All Rights Reserved.
19
-- mikej@opencores.org for support or any other issues.
20
--
21
-- Revision list
22
--
23
-- version 1.0 initial opencores release
24
--
25
 
26
library ieee;
27
use ieee.std_logic_1164.all;
28
 
29
package pkg_risc5x is
30
  function slv_to_integer(x : std_logic_vector) return integer;
31
  function integer_to_slv(n, bits : integer) return std_logic_vector;
32
 
33
end;
34
 
35
package body pkg_risc5x is
36
 
37
 
38
  function slv_to_integer(x : std_logic_vector) return integer is
39
    variable n : integer := 0;
40
    variable failure : boolean := false;
41
  begin
42
    assert (x'high - x'low + 1) <= 31
43
        report "Range of sulv_to_integer argument exceeds integer range"
44
        severity error;
45
    for i in x'range loop
46
      n := n * 2;
47
      case x(i) is
48
        when '1' | 'H' => n := n + 1;
49
        when '0' | 'L' => null;
50
        when others =>
51
            -- failure := true;
52
            null;
53
      end case;
54
    end loop;
55
 
56
    assert not failure
57
      report "sulv_to_integer cannot convert indefinite std_logic_vector"
58
      severity error;
59
    if failure then
60
      return 0;
61
    else
62
      return n;
63
    end if;
64
  end slv_to_integer;
65
 
66
  function integer_to_slv(n, bits : integer) return std_logic_vector is
67
    variable x : std_logic_vector(bits-1 downto 0) := (others => '0');
68
    variable tempn : integer := n;
69
  begin
70
    for i in x'reverse_range loop
71
      if (tempn mod 2) = 1 then
72
        x(i) := '1';
73
      end if;
74
      tempn := tempn / 2;
75
    end loop;
76
 
77
    return x;
78
  end integer_to_slv;
79
 
80
end;

powered by: WebSVN 2.1.0

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