-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimfifo_pkg.vhd
73 lines (62 loc) · 1.87 KB
/
simfifo_pkg.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* VHDL 2008 */
library ieee;
context ieee.ieee_std_context;
package simfifo_pkg is
generic (DATA_WIDTH: positive);
subtype data_t is std_logic_vector(DATA_WIDTH-1 downto 0);
subtype level_t is natural;
type simfifo is protected
procedure push(constant data: in data_t);
impure function pop return data_t;
impure function get_level return level_t;
end protected;
end package;
package body simfifo_pkg is
type simfifo is protected body
type item_t;
type ptr is access item_t;
type item_t is record
data: data_t;
next_item: ptr;
end record;
variable root: ptr;
variable depth: natural;
procedure push(
constant data: in data_t
) is
variable new_item: ptr := new item_t;
variable node: ptr;
begin
new_item.data := data;
new_item.next_item := null;
if (null = root) then
root := new_item;
depth := 1;
else
node := root;
while (null /= node.next_item) loop
node := node.next_item;
end loop;
depth := depth + 1;
node.next_item := new_item;
end if;
end procedure;
impure function pop return data_t is
variable node: ptr := root;
variable data: data_t;
begin
if (null /= root) then
data := root.data;
node := root;
root := root.next_item;
deallocate(node);
depth := depth - 1;
end if;
return data;
end function;
impure function get_level return level_t
is begin
return depth;
end function;
end protected body;
end package body;