Created
December 20, 2012 15:16
-
-
Save cjmeyer/4345864 to your computer and use it in GitHub Desktop.
VHDL: Behavioral dynamically expanding queue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type axi_data is record | |
val : std_logic; | |
end record; | |
type axi_data_array is array (natural range <>) of axi_data; | |
type axi_data_store is access axi_data_array; | |
type axi_data_q is record | |
data : axi_data_store; | |
count : natural; | |
head : natural; | |
tail : natural; | |
end record; | |
type axi_data_q_ptr is access axi_data_q; | |
procedure queue_push (variable q : inout axi_data_q_ptr; variable d : in axi_data) is | |
variable new_d : axi_data_store; | |
begin | |
if q.count = q.data'length then | |
new_d := new axi_data_array(0 to (q.data'length * 2)-1); | |
if q.head = 0 then | |
new_d(0 to q.data'length-1) := q.data.all; | |
else | |
new_d(0 to q.data'length-1) := | |
q.data(q.head to q.data'length-1) & q.data(0 to q.tail-1); | |
end if; | |
deallocate(q.data); | |
q.data := new_d; | |
q.head := 0; | |
q.tail := q.count; | |
end if; | |
q.data(q.tail) := d; | |
q.tail := (q.tail + 1) mod q.data'length; | |
q.count := q.count + 1; | |
end procedure; | |
procedure queue_pop(variable q : inout axi_data_q_ptr; variable d : out axi_data) is | |
begin | |
if q.count /= 0 then | |
d := q.data(q.head); | |
q.count := q.count - 1; | |
q.head := (q.head + 1) mod q.data'length; | |
else | |
d := (others => 'X'); | |
log("attempted to pop data from empty AXI data queue", error); | |
end if; | |
end procedure; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment