forked from salb545/VHDLWhizCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsim_fifo_pck.vhd
More file actions
96 lines (69 loc) · 2.26 KB
/
Copy pathsim_fifo_pck.vhd
File metadata and controls
96 lines (69 loc) · 2.26 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
library ieee;
use ieee.std_logic_1164.all;
library dot_matrix_sim;
---------------- NOTE PROCEDURES AND FUNCTIONS HELP USE VHDL CODE WRITTEN AS "PLAIN SOFTWARE" -----------------
package sim_fifo is
type sim_fifo is protected
-- Add a new element to the list
procedure push(constant data : in integer);
-- Return the oldest element from the list without removing it
impure function peek return integer;
-- Remove and return the oldest element from the list
impure function pop return integer;
-- Return true if there are 0 elements in the list
impure function empty return boolean;
end protected;
end package;
--------------------------------------------------------------------------------------------------------------------
package body sim_fifo is
type sim_fifo is protected body
-- A linked list node
type item;
type ptr is access item;
type item is record
data : integer;
next_item : ptr;
end record;
-- Root of the linked list
variable root : ptr;
----------- PUSH FUNCTION ----------------------------------
procedure push(constant data : in integer) is
variable new_item : ptr;
variable node : ptr;
begin
new_item := new item;
new_item.data := data;
if root = null then
root := new_item;
else
node := root;
while node.next_item /= null loop
node := node.next_item;
end loop;
node.next_item := new_item;
end if;
end procedure;
-------------- PEEK FUNCTION -------------------------------
impure function peek return integer is
begin
return root.data;
end function;
--------------- POP FUNCTION ------------------------------
impure function pop return integer is
variable node : ptr;
variable ret_val : integer;
begin
node := root;
root := root.next_item;
ret_val := node.data;
deallocate(node);
return ret_val;
end function;
---------------- EMPTY FUNCTION ---------------------------
impure function empty return boolean is
begin
return root = null;
end function;
------------------------------------------------------------
end protected body;
end package body;