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

Subversion Repositories copyblaze

[/] [copyblaze/] [trunk/] [copyblaze/] [rtl/] [vhdl/] [cpu/] [cp_Usefull_Pkg.vhd] - Blame information for rev 59

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

Line No. Rev Author Line
1 2 ameziti
--------------------------------------------------------------------------------
2
-- Company: 
3
--
4
-- File: cp_Usefull_Pkg.vhd
5
--
6
-- Description:
7
--      projet copyBlaze
8
--      Package utilisé pour le projet
9
--
10
-- File history:
11
-- v1.0: 31/08/11: Creation
12
-- v1.1: 20/11/11: Ajout de la fréquence low (10Mhz)
13
-- v1.2: 27/11/11: Ajout des fonctions OR_Func, AND_Func
14
--
15
-- Targeted device: ProAsic A3P250 VQFP100
16
-- Author: AbdAllah Meziti
17
--------------------------------------------------------------------------------
18
 
19
library ieee;
20
use ieee.std_logic_1164.all;
21
use ieee.numeric_std.all;
22
 
23
--------------------------------------------------------------------------------
24
-- Package: Usefull_Pkg
25
--------------------------------------------------------------------------------
26
package Usefull_Pkg is
27
        --- frequence of the fpga core
28
        constant FREQ                           : real          := 40.0e6;
29
        constant FREQ_LOW                       : real          := 10.0e6;
30
 
31
        --- find minimum number of bits required to
32
        --- represent N as an unsigned binary number
33
        function log2_ceil(N: natural) return positive;
34
 
35
        function log2(A: integer) return integer;
36
 
37
        -- OR sur tout les bits d'un vecteur
38
        function OR_Func (x : std_ulogic_vector) return std_ulogic;
39
        -- AND sur tout les bits d'un vecteur
40
        function AND_Func (x : std_ulogic_vector) return std_ulogic;
41
 
42
        function ODD_Func (x : std_ulogic_vector) return std_ulogic;
43
end;
44
 
45
--------------------------------------------------------------------------------
46
-- Body: Usefull_Pkg
47
--------------------------------------------------------------------------------
48
package body Usefull_Pkg is
49
 
50
        --- find minimum number of bits required to
51
        --- represent N as an unsigned binary number
52
        function log2_ceil(N: natural) return positive is
53
        begin
54
                if N < 2 then
55
                        return 1;
56
                else
57
                        return 1 + log2_ceil(N/2);
58
                end if;
59
        end;
60
 
61
--      function log2_ceil(N : integer) return integer is
62
--      begin
63
--              if (N <= 2) then
64
--                      return 1;
65
--              else
66
--                      if (N mod 2 = 0) then
67
--                              return 1 + log2_ceil(N/2);
68
--                      else
69
--                              return 1 + log2_ceil((N+1)/2);
70
--                      end if;
71
--              end if;
72
--      end function log2_ceil;
73
 
74
--      function log2_ceil (constant x : natural) return positive is
75
--      
76
--              variable v_tmp : natural := x;
77
--              variable v_ret : natural := 0;
78
--              variable v_line : integer;
79
--      
80
--      begin -- function log2
81
--      
82
--              while (v_tmp > 0) loop
83
--                      v_tmp := v_tmp / 2;
84
--                      v_ret := v_ret + 1;
85
--              end loop;
86
--
87
--              v_line := v_ret;
88
--              report "value: " & integer'image(v_line);
89
--              return v_ret;
90
--      end function log2_ceil;
91
 
92
        function log2(A: integer) return integer is
93
        begin
94
                for I in 1 to 30 loop  -- Works for up to 32 bit integers
95
                        if(2**I > A) then return(I-1);  end if;
96
                end loop;
97
                return(30);
98
        end;
99
        -- OR sur tout les bits d'un vecteur
100
        function OR_Func (x : std_ulogic_vector) return std_ulogic is
101
                variable tmp : std_ulogic := '0';
102
        begin
103
                for j in x'range loop
104
                        tmp := tmp or x(j);
105
                end loop;
106
        return tmp;
107
        end OR_Func;
108
 
109
        -- AND sur tout les bits d'un vecteur
110
        function AND_Func (x : std_ulogic_vector) return std_ulogic is
111
                variable tmp : std_ulogic := '1';
112
        begin
113
                for j in x'range loop
114
                        tmp := tmp and x(j);
115
                end loop;
116
        return tmp;
117
        end AND_Func;
118
 
119
        function ODD_Func (x : std_ulogic_vector) return std_ulogic is
120
                variable tmp : std_ulogic := '0';
121
        begin
122
                for j in x'range loop
123
                        tmp := tmp xor x(j);
124
                end loop;
125
        return tmp;
126
        end ODD_Func;
127
 
128
end package body;

powered by: WebSVN 2.1.0

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