1 |
2 |
rpaley_yid |
-- $Author: rpaley_yid $
|
2 |
|
|
-- $Date: 2003-01-14 21:48:10 $
|
3 |
|
|
-- $Header: /home/marcus/revision_ctrl_test/oc_cvs/cvs/single_port/VHDL/linked_list_mem_pkg.vhd,v 1.1.1.1 2003-01-14 21:48:10 rpaley_yid Exp $
|
4 |
|
|
-- $Locker
|
5 |
|
|
-- $Revision: 1.1.1.1 $
|
6 |
|
|
-- $State: Exp $
|
7 |
|
|
|
8 |
|
|
-- --------------------------------------------------------------------------
|
9 |
|
|
--
|
10 |
|
|
-- Purpose: This package implements functions to allocate, write, read, and
|
11 |
|
|
-- deallocate a linked list based memory.
|
12 |
|
|
--
|
13 |
|
|
--
|
14 |
|
|
-- References:
|
15 |
|
|
-- 1. The Designer's Guide to VHDL by Peter Ashenden
|
16 |
|
|
-- ISBN: 1-55860-270-4 (pbk.)
|
17 |
|
|
-- 2. Writing Testbenches - Functional Verification of HDL models by
|
18 |
|
|
-- Janick Bergeron | ISBN: 0-7923-7766-4
|
19 |
|
|
--
|
20 |
|
|
-- Notes:
|
21 |
|
|
--
|
22 |
|
|
-- --------------------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
LIBRARY IEEE;
|
25 |
|
|
LIBRARY WORK;
|
26 |
|
|
USE IEEE.STD_LOGIC_1164.ALL;
|
27 |
|
|
USE WORK.single_port_pkg.all;
|
28 |
|
|
|
29 |
|
|
PACKAGE linked_list_mem_pkg IS
|
30 |
|
|
-- data memory array type definition
|
31 |
|
|
TYPE mem_array_typ IS ARRAY (0 TO PAGEDEPTH-1) OF data_typ;
|
32 |
|
|
-- Define memory page linked list cell. This cell contains,
|
33 |
|
|
-- the mem_array, starting page address, valid data array, and
|
34 |
|
|
-- the pointer to the next element in the linked list.
|
35 |
|
|
TYPE mem_page_typ;
|
36 |
|
|
-- pointer to next item in the linked list.
|
37 |
|
|
TYPE mem_page_ptr IS ACCESS mem_page_typ;
|
38 |
|
|
TYPE mem_page_typ IS RECORD
|
39 |
|
|
mem_array : mem_array_typ; -- data memory
|
40 |
|
|
-- This array is a flag which indicates if the corresponding
|
41 |
|
|
-- address location inside mem_array contains valid data.
|
42 |
|
|
data_valid_array : BIT_VECTOR( 0 TO PAGEDEPTH-1);
|
43 |
|
|
page_address : addr_typ;
|
44 |
|
|
next_cell : mem_page_ptr;
|
45 |
|
|
END RECORD mem_page_typ;
|
46 |
|
|
PROCEDURE rw_mem (
|
47 |
|
|
VARIABLE data : INOUT data_inter_typ;
|
48 |
|
|
VARIABLE addr : addr_typ;
|
49 |
|
|
VARIABLE write_flag : BOOLEAN;
|
50 |
|
|
VARIABLE next_cell : INOUT mem_page_ptr
|
51 |
|
|
);
|
52 |
|
|
PROCEDURE deallocate_mem (
|
53 |
|
|
VARIABLE next_cell : INOUT mem_page_ptr
|
54 |
|
|
);
|
55 |
|
|
|
56 |
|
|
END PACKAGE linked_list_mem_pkg;
|
57 |
|
|
|
58 |
|
|
PACKAGE BODY LINKED_LIST_MEM_PKG IS
|
59 |
|
|
-- --------------------------------------------------
|
60 |
|
|
-- The purpose of this procedure is to write a memory location from
|
61 |
|
|
-- the linked list, if the particular page does not exist, create it.
|
62 |
|
|
-- --------------------------------------------------
|
63 |
|
|
PROCEDURE rw_mem (
|
64 |
|
|
VARIABLE data : INOUT data_inter_typ;
|
65 |
|
|
VARIABLE addr : addr_typ;
|
66 |
|
|
VARIABLE write_flag : BOOLEAN;
|
67 |
|
|
VARIABLE next_cell : INOUT mem_page_ptr
|
68 |
|
|
) IS
|
69 |
|
|
VARIABLE current_cell_v : mem_page_ptr; -- current page pointer
|
70 |
|
|
VARIABLE page_address_v : addr_typ; -- calculated page address
|
71 |
|
|
VARIABLE index_v : INTEGER; -- address within the memory page
|
72 |
|
|
VARIABLE mem_array_v : mem_array_typ;
|
73 |
|
|
VARIABLE data_valid_array_v : BIT_VECTOR(0 TO PAGEDEPTH-1);
|
74 |
|
|
BEGIN
|
75 |
|
|
-- Copy the top of the linked list pointer to a working pointer
|
76 |
|
|
current_cell_v := next_cell;
|
77 |
|
|
-- Calculate the index within the page from the given address
|
78 |
|
|
index_v := addr MOD PAGEDEPTH;
|
79 |
|
|
-- Calculate the page address from the given address
|
80 |
|
|
page_address_v := addr - index_v;
|
81 |
|
|
-- Search through the memory to determine if the calculated
|
82 |
|
|
-- memory page exists. Stop searching when reach the end of
|
83 |
|
|
-- the linked list.
|
84 |
|
|
WHILE ( current_cell_v /= NULL
|
85 |
|
|
AND current_cell_v.page_address /= page_address_v) LOOP
|
86 |
|
|
current_cell_v := current_cell_v.next_cell;
|
87 |
|
|
END LOOP;
|
88 |
|
|
|
89 |
|
|
IF write_flag THEN
|
90 |
|
|
IF ( current_cell_v /= NULL AND -- Check if address exists in memory.
|
91 |
|
|
current_cell_v.page_address = page_address_v
|
92 |
|
|
) THEN
|
93 |
|
|
-- Found the memory page the particular address belongs to
|
94 |
|
|
current_cell_v.mem_array(index_v) := TO_BITVECTOR(data);
|
95 |
|
|
-- set memory location valid flag
|
96 |
|
|
current_cell_v.data_valid_array(index_v) := '1';
|
97 |
|
|
ELSE
|
98 |
|
|
-- The memory page the address belongs to was not allocated in memory.
|
99 |
|
|
-- Allocate page here and assign data.
|
100 |
|
|
mem_array_v(index_v) := TO_BITVECTOR(data);
|
101 |
|
|
data_valid_array_v(index_v) := '1';
|
102 |
|
|
next_cell := NEW mem_page_typ'( mem_array => mem_array_v,
|
103 |
|
|
data_valid_array => data_valid_array_v,
|
104 |
|
|
page_address => page_address_v,
|
105 |
|
|
next_cell => next_cell
|
106 |
|
|
);
|
107 |
|
|
END IF;
|
108 |
|
|
ELSE -- Read memory
|
109 |
|
|
IF ( current_cell_v /= NULL AND -- Check if address exists in memory.
|
110 |
|
|
current_cell_v.page_address = page_address_v AND
|
111 |
|
|
current_cell_v.data_valid_array(index_v) = '1'
|
112 |
|
|
) THEN
|
113 |
|
|
-- Found the memory page the particular address belongs to,
|
114 |
|
|
-- and the memory location has valid data.
|
115 |
|
|
data := TO_STDLOGICVECTOR(current_cell_v.mem_array(index_v));
|
116 |
|
|
ELSE
|
117 |
|
|
-- Trying to read from unwritten or unallocated
|
118 |
|
|
-- memory location, return 'U';
|
119 |
|
|
data := (OTHERS => 'U');
|
120 |
|
|
END IF;
|
121 |
|
|
END IF;
|
122 |
|
|
END PROCEDURE rw_mem;
|
123 |
|
|
|
124 |
|
|
PROCEDURE deallocate_mem (
|
125 |
|
|
VARIABLE next_cell : INOUT mem_page_ptr
|
126 |
|
|
) IS
|
127 |
|
|
VARIABLE delete_cell_v : mem_page_ptr;
|
128 |
|
|
BEGIN
|
129 |
|
|
-- Deallocate the linked link memory from work station memory.
|
130 |
|
|
WHILE next_cell /= NULL LOOP -- while not reached the end of the LL
|
131 |
|
|
delete_cell_v := next_cell; -- Copy pointer to record for deleting
|
132 |
|
|
next_cell := next_cell.next_cell; -- set pointer to next cell in LL
|
133 |
|
|
deallocate(delete_cell_v); -- Deallocate current cell from memory.
|
134 |
|
|
END LOOP;
|
135 |
|
|
END PROCEDURE deallocate_mem;
|
136 |
|
|
END PACKAGE BODY LINKED_LIST_MEM_PKG;
|
137 |
|
|
|
138 |
|
|
-- $Log: not supported by cvs2svn $
|
139 |
|
|
-- Revision 1.1 2003/01/14 17:47:32 Default
|
140 |
|
|
-- Initial revision
|
141 |
|
|
--
|
142 |
|
|
-- Revision 1.1 2002/12/24 18:03:50 Default
|
143 |
|
|
-- Initial revision
|
144 |
|
|
--
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|