OpenCores
URL https://opencores.org/ocsvn/single_port/single_port/trunk

Subversion Repositories single_port

[/] [single_port/] [trunk/] [VHDL/] [linked_list_mem_pkg.vhd] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 mgeng
----------------------------------------------------------------------
2
----                                                              ----
3
---- Single port asynchronous RAM simulation model                ----
4
----                                                              ----
5
---- This file is part of the single_port project                 ----
6
----                                                              ----
7
---- Description                                                  ----
8
---- This package implements functions to allocate, write, read   ----
9
---- and deallocate a linked list based memory.                   ----
10
----                                                              ----
11
---- Authors:                                                     ----
12
---- - Robert Paley, rpaley_yid@yahoo.com                         ----
13
---- - Michael Geng, vhdl@MichaelGeng.de                          ----
14
----                                                              ----
15
---- References:                                                  ----
16
----   1. The Designer's Guide to VHDL by Peter Ashenden          ----
17
----      ISBN: 1-55860-270-4 (pbk.)                              ----
18
----   2. Writing Testbenches - Functional Verification of HDL    ----
19
----      models by Janick Bergeron | ISBN: 0-7923-7766-4         ----
20
----                                                              ----
21
----------------------------------------------------------------------
22
----                                                              ----
23
---- Copyright (C) 2005 Authors and OPENCORES.ORG                 ----
24
----                                                              ----
25
---- This source file may be used and distributed without         ----
26
---- restriction provided that this copyright statement is not    ----
27
---- removed from the file and that any derivative work contains  ----
28
---- the original copyright notice and the associated disclaimer. ----
29
----                                                              ----
30
---- This source file is free software; you can redistribute it   ----
31
---- and/or modify it under the terms of the GNU Lesser General   ----
32
---- Public License as published by the Free Software Foundation; ----
33
---- either version 2.1 of the License, or (at your option) any   ----
34
---- later version.                                               ----
35
----                                                              ----
36
---- This source is distributed in the hope that it will be       ----
37
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ----
38
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ----
39
---- PURPOSE. See the GNU Lesser General Public License for more  ----
40
---- details.                                                     ----
41
----                                                              ----
42
---- You should have received a copy of the GNU Lesser General    ----
43
---- Public License along with this source; if not, download it   ----
44
---- from http://www.opencores.org/lgpl.shtml                     ----
45
----                                                              ----
46
----------------------------------------------------------------------
47 2 rpaley_yid
--
48 6 mgeng
-- CVS Revision History
49 2 rpaley_yid
--
50 6 mgeng
-- $Log: not supported by cvs2svn $
51 8 mgeng
-- Revision 1.2  2005/10/12 19:39:27  mgeng
52
-- Buses unconstrained, LGPL header added
53
--
54 6 mgeng
-- Revision 1.1.1.1  2003/01/14 21:48:10  rpaley_yid
55
-- initial checkin 
56 2 rpaley_yid
--
57 6 mgeng
-- Revision 1.1  2003/01/14 17:47:32  Default
58
-- Initial revision
59
--
60
-- Revision 1.1  2002/12/24 18:03:50  Default
61
-- Initial revision
62
--
63 2 rpaley_yid
LIBRARY IEEE;
64
LIBRARY WORK;
65
USE IEEE.STD_LOGIC_1164.ALL;
66
USE WORK.single_port_pkg.all;
67
 
68
PACKAGE linked_list_mem_pkg IS
69 8 mgeng
  CONSTANT PAGEDEPTH : INTEGER := 256; -- memory page depth
70 6 mgeng
  -- pointer to one data word in the memory
71
  -- The reason for using a pointer here is that it seems to be the only way to keep the model
72
  -- independent of the data width
73
  TYPE data_ptr IS ACCESS BIT_VECTOR;
74 2 rpaley_yid
  -- data memory array type definition
75 6 mgeng
  TYPE mem_array_typ IS ARRAY (0 TO PAGEDEPTH-1) OF data_ptr;
76 8 mgeng
  -- Define memory page linked list cell. This cell contains
77
  -- the mem_array, starting page address, valid data array and 
78 2 rpaley_yid
  -- the pointer to the next element in the linked list.
79
  TYPE mem_page_typ;
80
  -- pointer to next item in the linked list.
81 6 mgeng
  TYPE mem_page_ptr IS ACCESS mem_page_typ;
82 2 rpaley_yid
  TYPE mem_page_typ IS RECORD
83 6 mgeng
    mem_array    : mem_array_typ; -- data memory
84 2 rpaley_yid
    page_address : addr_typ;
85 6 mgeng
    next_cell    : mem_page_ptr;
86 2 rpaley_yid
  END RECORD mem_page_typ;
87
  PROCEDURE rw_mem (
88 6 mgeng
    VARIABLE data       : INOUT STD_LOGIC_VECTOR;
89
    VARIABLE addr       : IN    addr_typ;
90
    VARIABLE next_cell  : INOUT mem_page_ptr;
91
    CONSTANT write_flag : IN    BOOLEAN);
92 2 rpaley_yid
  PROCEDURE deallocate_mem (
93 6 mgeng
    VARIABLE next_cell : INOUT mem_page_ptr);
94 2 rpaley_yid
 
95
END PACKAGE linked_list_mem_pkg;
96
 
97 8 mgeng
PACKAGE BODY linked_list_mem_pkg IS
98 2 rpaley_yid
  -- --------------------------------------------------
99
  -- The purpose of this procedure is to write a memory location from 
100
  -- the linked list, if the particular page does not exist, create it.
101
  -- --------------------------------------------------  
102
  PROCEDURE rw_mem (
103 6 mgeng
    VARIABLE data       : INOUT STD_LOGIC_VECTOR;
104
    VARIABLE addr       : IN    addr_typ;
105
    VARIABLE next_cell  : INOUT mem_page_ptr;
106
    CONSTANT write_flag : IN    BOOLEAN) IS
107
    VARIABLE current_cell_v : mem_page_ptr; -- current page pointer
108
    VARIABLE page_address_v : addr_typ;     -- calculated page address
109
    VARIABLE index_v        : INTEGER;      -- address within the memory page
110
    VARIABLE mem_array_v    : mem_array_typ;
111 2 rpaley_yid
  BEGIN
112
    -- Copy the top of the linked list pointer to a working pointer
113
    current_cell_v := next_cell;
114
    -- Calculate the index within the page from the given address
115
    index_v := addr MOD PAGEDEPTH;
116
    -- Calculate the page address from the given address
117
    page_address_v := addr - index_v;
118
    -- Search through the memory to determine if the calculated
119
    -- memory page exists. Stop searching when reach the end of
120
    -- the linked list.
121 6 mgeng
    WHILE ( current_cell_v /= NULL AND
122
            current_cell_v.page_address /= page_address_v) LOOP
123 2 rpaley_yid
      current_cell_v := current_cell_v.next_cell;
124
    END LOOP;
125
 
126
    IF write_flag THEN
127
      IF ( current_cell_v /= NULL AND -- Check if address exists in memory.
128 6 mgeng
           current_cell_v.page_address = page_address_v ) THEN
129 2 rpaley_yid
        -- Found the memory page the particular address belongs to
130 6 mgeng
        IF ( current_cell_v.mem_array(index_v) /= NULL ) THEN
131
          current_cell_v.mem_array(index_v).ALL := TO_BITVECTOR(data);
132
        ELSE
133
          current_cell_v.mem_array(index_v) := NEW BIT_VECTOR'(TO_BITVECTOR(data));
134
        END IF;
135 2 rpaley_yid
      ELSE
136
        -- The memory page the address belongs to was not allocated in memory.
137
        -- Allocate page here and assign data.
138 6 mgeng
        mem_array_v(index_v) := NEW BIT_VECTOR'(TO_BITVECTOR(data));
139
        next_cell := NEW mem_page_typ'( mem_array => mem_array_v,
140 2 rpaley_yid
                                  page_address => page_address_v,
141 6 mgeng
                                  next_cell => next_cell);
142 2 rpaley_yid
      END IF;
143
    ELSE -- Read memory
144
      IF ( current_cell_v /= NULL AND -- Check if address exists in memory.
145
           current_cell_v.page_address = page_address_v AND
146 6 mgeng
           current_cell_v.mem_array(index_v) /= NULL ) THEN
147 2 rpaley_yid
        -- Found the memory page the particular address belongs to,
148
        -- and the memory location has valid data.
149 6 mgeng
        data := TO_STDLOGICVECTOR(current_cell_v.mem_array(index_v).ALL);
150 2 rpaley_yid
      ELSE
151
        -- Trying to read from unwritten or unallocated 
152
        -- memory location, return 'U';
153 6 mgeng
        data := (data'RANGE => 'U');
154 2 rpaley_yid
      END IF;
155
    END IF;
156
  END PROCEDURE rw_mem;
157
 
158
  PROCEDURE deallocate_mem (
159 6 mgeng
    VARIABLE next_cell : INOUT mem_page_ptr) IS
160 2 rpaley_yid
    VARIABLE delete_cell_v : mem_page_ptr;
161
  BEGIN
162
    -- Deallocate the linked link memory from work station memory.
163
    WHILE next_cell /= NULL LOOP -- while not reached the end of the LL
164
      delete_cell_v := next_cell; -- Copy pointer to record for deleting
165 6 mgeng
      FOR i IN 0 TO PAGEDEPTH-1 LOOP
166
        IF delete_cell_v.mem_array(i) /= NULL THEN
167
          deallocate(delete_cell_v.mem_array(i));
168
        END IF;
169
      END LOOP;
170 2 rpaley_yid
      next_cell := next_cell.next_cell; -- set pointer to next cell in LL
171
      deallocate(delete_cell_v); -- Deallocate current cell from memory.
172
    END LOOP;
173
  END PROCEDURE deallocate_mem;
174 8 mgeng
END PACKAGE BODY linked_list_mem_pkg;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.