Project

General

Profile

Download (6.51 KB) Statistics
| Branch: | Tag: | Revision:
1
---------------------------------------------------------------------------------------------------
2
-- Filename    : mt_toolbox.vhd
3
-- Project     : maintech IP-Core toolbox
4
-- Purpose     : maintech toolbox package
5
--
6
-- Description : declaration of common types, functions and attributes
7
--               used throughout the toolbox
8
---------------------------------------------------------------------------------------------------
9

    
10
-----------------------------------------------------------------------------------
11
-- Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany --
12
-- written by Matthias Kleffel                                                   --
13
--                                                                               --
14
-- This program is free software; you can redistribute it and/or modify          --
15
-- it under the terms of the GNU General Public License as published by          --
16
-- the Free Software Foundation as version 3 of the License, or                  --
17
--                                                                               --
18
-- This program is distributed in the hope that it will be useful,               --
19
-- but WITHOUT ANY WARRANTY; without even the implied warranty of                --
20
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  --
21
-- GNU General Public License V3 for more details.                               --
22
--                                                                               --
23
-- You should have received a copy of the GNU General Public License             --
24
-- along with this program. If not, see <http://www.gnu.org/licenses/>.          --
25
-----------------------------------------------------------------------------------
26
library ieee;
27
	use ieee.std_logic_1164.all;
28
	use ieee.numeric_std.all;
29
	
30
package mt_toolbox is
31
	
32
	--
33
	-- basic types
34
	--
35
	subtype slv8_t  is std_logic_vector(7 downto 0);
36
	subtype slv16_t is std_logic_vector(15 downto 0);
37
	subtype slv32_t is std_logic_vector(31 downto 0);
38
	subtype byte_t  is unsigned(7 downto 0);
39
	subtype word_t  is unsigned(15 downto 0);
40
	subtype dword_t is unsigned(31 downto 0);
41
	type slv8_array_t  is array (natural range<>) of slv8_t;
42
	type slv16_array_t is array (natural range<>) of slv16_t;
43
	type slv32_array_t is array (natural range<>) of slv32_t;
44
	type byte_array_t  is array (natural range<>) of byte_t;
45
	type word_array_t  is array (natural range<>) of word_t;
46
	type dword_array_t is array (natural range<>) of dword_t;
47

    
48
	--
49
	-- simple helper functions
50
	--
51
	function log2(x: natural) return positive;
52
	
53
	--
54
	-- type conversion helper
55
	--
56
	function to_slv8(x: std_logic) return std_logic_vector;
57
	function to_slv8(x: std_logic_vector) return std_logic_vector;
58
	function to_slv8(x: unsigned) return std_logic_vector;
59
	function to_slv8(x: signed) return std_logic_vector;
60
	function to_slv8(x: natural) return std_logic_vector;
61
	function to_slv16(x: std_logic) return std_logic_vector;
62
	function to_slv16(x: std_logic_vector) return std_logic_vector;
63
	function to_slv16(x: unsigned) return std_logic_vector;
64
	function to_slv16(x: signed) return std_logic_vector;
65
	function to_slv16(x: natural) return std_logic_vector;
66
	function to_slv32(x: std_logic) return std_logic_vector;
67
	function to_slv32(x: std_logic_vector) return std_logic_vector;
68
	function to_slv32(x: unsigned) return std_logic_vector;
69
	function to_slv32(x: signed) return std_logic_vector;
70
	function to_slv32(x: natural) return std_logic_vector;
71
	
72
	--
73
	-- common attributes
74
	--
75
	attribute syn_keep      : boolean;
76
	attribute syn_ramstyle  : string;
77
	attribute syn_romstyle  : string;
78
	attribute shreg_extract : string;
79
	
80
end mt_toolbox;
81

    
82
package body mt_toolbox is
83
	
84
	--
85
	-- simple helper functions
86
	--
87

    
88
	-- calculate ceiling base 2 logarithm (returns always >=1)
89
	function log2(x: natural) return positive is
90
		variable x_tmp: natural;
91
		variable y: positive;
92
	begin
93
		x_tmp := x-1;
94
		y := 1;
95
		while x_tmp > 1 loop
96
			y := y+1;
97
			x_tmp := x_tmp/2;
98
		end loop;
99
		return y;
100
	end;
101

    
102
	-- to_slv8 (pack basic types into "std_logic_vector(7 downto 0)")
103
	function to_slv8(x: std_logic) return std_logic_vector is
104
		variable res : std_logic_vector(7 downto 0);
105
	begin
106
		res := (0=>x,others=>'0');
107
		return res;
108
	end to_slv8;
109
	function to_slv8(x: std_logic_vector) return std_logic_vector is
110
		variable res : std_logic_vector(7 downto 0);
111
	begin
112
		res := (others=>'0');
113
		res(x'length-1 downto 0) := x;
114
		return res;
115
	end to_slv8;
116
	function to_slv8(x: unsigned) return std_logic_vector is
117
	begin
118
		return to_slv8(std_logic_vector(x));
119
	end to_slv8;
120
	function to_slv8(x: signed) return std_logic_vector is
121
	begin
122
		return to_slv8(std_logic_vector(x));
123
	end to_slv8;
124
	function to_slv8(x: natural) return std_logic_vector is
125
	begin
126
		return to_slv8(to_unsigned(x,8));
127
	end to_slv8;
128
	
129
	-- to_slv16 (pack basic types into "std_logic_vector(15 downto 0)")
130
	function to_slv16(x: std_logic) return std_logic_vector is
131
		variable res : std_logic_vector(15 downto 0);
132
	begin
133
		res := (0=>x,others=>'0');
134
		return res;
135
	end to_slv16;
136
	function to_slv16(x: std_logic_vector) return std_logic_vector is
137
		variable res : std_logic_vector(15 downto 0);
138
	begin
139
		res := (others=>'0');
140
		res(x'length-1 downto 0) := x;
141
		return res;
142
	end to_slv16;
143
	function to_slv16(x: unsigned) return std_logic_vector is
144
	begin
145
		return to_slv16(std_logic_vector(x));
146
	end to_slv16;
147
	function to_slv16(x: signed) return std_logic_vector is
148
	begin
149
		return to_slv16(std_logic_vector(x));
150
	end to_slv16;
151
	function to_slv16(x: natural) return std_logic_vector is
152
	begin
153
		return to_slv16(to_unsigned(x,16));
154
	end to_slv16;
155
	
156
	-- to_slv32 (pack basic types into "std_logic_vector(31 downto 0)")
157
	function to_slv32(x: std_logic) return std_logic_vector is
158
		variable res : std_logic_vector(31 downto 0);
159
	begin
160
		res := (0=>x,others=>'0');
161
		return res;
162
	end to_slv32;
163
	function to_slv32(x: std_logic_vector) return std_logic_vector is
164
		variable res : std_logic_vector(31 downto 0);
165
	begin
166
		res := (others=>'0');
167
		res(x'length-1 downto 0) := x;
168
		return res;
169
	end to_slv32;
170
	function to_slv32(x: unsigned) return std_logic_vector is
171
	begin
172
		return to_slv32(std_logic_vector(x));
173
	end to_slv32;
174
	function to_slv32(x: signed) return std_logic_vector is
175
	begin
176
		return to_slv32(std_logic_vector(x));
177
	end to_slv32;
178
	function to_slv32(x: natural) return std_logic_vector is
179
	begin
180
		return to_slv32(to_unsigned(x,32));
181
	end to_slv32;
182
end mt_toolbox;
183

    
(3-3/3)
Add picture from clipboard (Maximum size: 48.8 MB)