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 6

Go to most recent revision | 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
-- Revision 1.1.1.1  2003/01/14 21:48:10  rpaley_yid
52
-- initial checkin 
53 2 rpaley_yid
--
54 6 mgeng
-- Revision 1.1  2003/01/14 17:47:32  Default
55
-- Initial revision
56
--
57
-- Revision 1.1  2002/12/24 18:03:50  Default
58
-- Initial revision
59
--
60 2 rpaley_yid
LIBRARY IEEE;
61
LIBRARY WORK;
62
USE IEEE.STD_LOGIC_1164.ALL;
63
USE WORK.single_port_pkg.all;
64
 
65
PACKAGE linked_list_mem_pkg IS
66 6 mgeng
  -- pointer to one data word in the memory
67
  -- The reason for using a pointer here is that it seems to be the only way to keep the model
68
  -- independent of the data width
69
  TYPE data_ptr IS ACCESS BIT_VECTOR;
70 2 rpaley_yid
  -- data memory array type definition
71 6 mgeng
  TYPE mem_array_typ IS ARRAY (0 TO PAGEDEPTH-1) OF data_ptr;
72 2 rpaley_yid
  -- Define memory page linked list cell. This cell contains,
73
  -- the mem_array, starting page address, valid data array, and 
74
  -- the pointer to the next element in the linked list.
75
  TYPE mem_page_typ;
76
  -- pointer to next item in the linked list.
77 6 mgeng
  TYPE mem_page_ptr IS ACCESS mem_page_typ;
78 2 rpaley_yid
  TYPE mem_page_typ IS RECORD
79 6 mgeng
    mem_array    : mem_array_typ; -- data memory
80 2 rpaley_yid
    page_address : addr_typ;
81 6 mgeng
    next_cell    : mem_page_ptr;
82 2 rpaley_yid
  END RECORD mem_page_typ;
83
  PROCEDURE rw_mem (
84 6 mgeng
    VARIABLE data       : INOUT STD_LOGIC_VECTOR;
85
    VARIABLE addr       : IN    addr_typ;
86
    VARIABLE next_cell  : INOUT mem_page_ptr;
87
    CONSTANT write_flag : IN    BOOLEAN);
88 2 rpaley_yid
  PROCEDURE deallocate_mem (
89 6 mgeng
    VARIABLE next_cell : INOUT mem_page_ptr);
90 2 rpaley_yid
 
91
END PACKAGE linked_list_mem_pkg;
92
 
93
PACKAGE BODY LINKED_LIST_MEM_PKG IS
94
  -- --------------------------------------------------
95
  -- The purpose of this procedure is to write a memory location from 
96
  -- the linked list, if the particular page does not exist, create it.
97
  -- --------------------------------------------------  
98
  PROCEDURE rw_mem (
99 6 mgeng
    VARIABLE data       : INOUT STD_LOGIC_VECTOR;
100
    VARIABLE addr       : IN    addr_typ;
101
    VARIABLE next_cell  : INOUT mem_page_ptr;
102
    CONSTANT write_flag : IN    BOOLEAN) IS
103
    VARIABLE current_cell_v : mem_page_ptr; -- current page pointer
104
    VARIABLE page_address_v : addr_typ;     -- calculated page address
105
    VARIABLE index_v        : INTEGER;      -- address within the memory page
106
    VARIABLE mem_array_v    : mem_array_typ;
107 2 rpaley_yid
  BEGIN
108
    -- Copy the top of the linked list pointer to a working pointer
109
    current_cell_v := next_cell;
110
    -- Calculate the index within the page from the given address
111
    index_v := addr MOD PAGEDEPTH;
112
    -- Calculate the page address from the given address
113
    page_address_v := addr - index_v;
114
    -- Search through the memory to determine if the calculated
115
    -- memory page exists. Stop searching when reach the end of
116
    -- the linked list.
117 6 mgeng
    WHILE ( current_cell_v /= NULL AND
118
            current_cell_v.page_address /= page_address_v) LOOP
119 2 rpaley_yid
      current_cell_v := current_cell_v.next_cell;
120
    END LOOP;
121
 
122
    IF write_flag THEN
123
      IF ( current_cell_v /= NULL AND -- Check if address exists in memory.
124 6 mgeng
           current_cell_v.page_address = page_address_v ) THEN
125 2 rpaley_yid
        -- Found the memory page the particular address belongs to
126 6 mgeng
        IF ( current_cell_v.mem_array(index_v) /= NULL ) THEN
127
          current_cell_v.mem_array(index_v).ALL := TO_BITVECTOR(data);
128
        ELSE
129
          current_cell_v.mem_array(index_v) := NEW BIT_VECTOR'(TO_BITVECTOR(data));
130
        END IF;
131 2 rpaley_yid
      ELSE
132
        -- The memory page the address belongs to was not allocated in memory.
133
        -- Allocate page here and assign data.
134 6 mgeng
        mem_array_v(index_v) := NEW BIT_VECTOR'(TO_BITVECTOR(data));
135
        next_cell := NEW mem_page_typ'( mem_array => mem_array_v,
136 2 rpaley_yid
                                  page_address => page_address_v,
137 6 mgeng
                                  next_cell => next_cell);
138 2 rpaley_yid
      END IF;
139
    ELSE -- Read memory
140
      IF ( current_cell_v /= NULL AND -- Check if address exists in memory.
141
           current_cell_v.page_address = page_address_v AND
142 6 mgeng
           current_cell_v.mem_array(index_v) /= NULL ) THEN
143 2 rpaley_yid
        -- Found the memory page the particular address belongs to,
144
        -- and the memory location has valid data.
145 6 mgeng
        data := TO_STDLOGICVECTOR(current_cell_v.mem_array(index_v).ALL);
146 2 rpaley_yid
      ELSE
147
        -- Trying to read from unwritten or unallocated 
148
        -- memory location, return 'U';
149 6 mgeng
        data := (data'RANGE => 'U');
150 2 rpaley_yid
      END IF;
151
    END IF;
152
  END PROCEDURE rw_mem;
153
 
154
  PROCEDURE deallocate_mem (
155 6 mgeng
    VARIABLE next_cell : INOUT mem_page_ptr) IS
156 2 rpaley_yid
    VARIABLE delete_cell_v : mem_page_ptr;
157
  BEGIN
158
    -- Deallocate the linked link memory from work station memory.
159
    WHILE next_cell /= NULL LOOP -- while not reached the end of the LL
160
      delete_cell_v := next_cell; -- Copy pointer to record for deleting
161 6 mgeng
      FOR i IN 0 TO PAGEDEPTH-1 LOOP
162
        IF delete_cell_v.mem_array(i) /= NULL THEN
163
          deallocate(delete_cell_v.mem_array(i));
164
        END IF;
165
      END LOOP;
166 2 rpaley_yid
      next_cell := next_cell.next_cell; -- set pointer to next cell in LL
167
      deallocate(delete_cell_v); -- Deallocate current cell from memory.
168
    END LOOP;
169
  END PROCEDURE deallocate_mem;
170
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.