1 #ifndef __memory_H // -*- c++ -*-
4 * Copyright (c) 2001 Stephen Williams (steve@icarus.com)
5 * Copyright (c) 2001 Stephan Boettcher <stephan@nevis.columbia.edu>
7 * This source code is free software; you can redistribute it
8 * and/or modify it in source code form under the terms of the GNU
9 * General Public License as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
23 #ident "$Id: memory.h,v 1.13 2007/03/22 16:08:19 steve Exp $"
30 ** vvp_memory_t is a memory
31 ** vvp_memory_index_t is a memory index range definition
33 typedef struct vvp_memory_s
*vvp_memory_t
;
35 struct memory_address_range
{
41 * Given a memory device, the memory_configure function configures it
42 * by defining the dimensions of the device. It is an error to
43 * redefine the dimensions of a device already configured.
45 * The lsb and msb define the dimensions of a word. They are in
46 * Verilog form. The actual word contents are vvp_vector4_t values.
48 * The idx array is an array of address ranges that describe the
49 * complete multi-dimensional array. In a normal Verilog array, idxs
50 * is 1, and idx is a pointer to a single memory_address_range. The
51 * table does not need to be persistent.
53 extern void memory_configure(vvp_memory_t mem
, int msb
, int lsb
,
55 const struct memory_address_range
*idx
);
56 extern void memory_attach_self(vvp_memory_t mem
, vpiHandle self
);
59 * init_word and set_word functions take the memory to be manipulated
60 * and write a word value at the given word address. The idx is the
61 * canonical (0-based, 1-dimensional) address of the word to be
62 * written. The caller needs to have converted any multi-dimensional
63 * address into a canonical address first.
65 * The difference between init_word and set_word are that the set_word
66 * function causes values to be propagated through structural ports,
67 * but the init_word does not.
69 extern void memory_init_word(vvp_memory_t mem
,
72 extern void memory_set_word(vvp_memory_t mem
,
78 * this doesn't actually write the value to the memory word, but
79 * scedules for the write to happen some time in the future. The delay
80 * is in simulation clock units
82 void schedule_memory(vvp_memory_t mem
, unsigned addr
,
83 vvp_vector4_t val
, unsigned long delay
);
86 * Get the word value at the given index into the memory.
88 extern vvp_vector4_t
memory_get_word(vvp_memory_t mem
, unsigned idx
);
91 /* Number of words in the memory. */
92 unsigned memory_word_count(vvp_memory_t mem
);
94 unsigned memory_word_width(vvp_memory_t mem
);
95 /* Get the user declared geometry of the memory address. This is the
96 msb and lsb values for each pair in the multi-dimensional array. */
97 long memory_left_range(vvp_memory_t mem
, unsigned ix
);
98 long memory_right_range(vvp_memory_t mem
, unsigned ix
);
99 /* Get the user defined geometry for the memory *word*. */
100 long memory_word_left_range(vvp_memory_t mem
);
101 long memory_word_right_range(vvp_memory_t mem
);
105 * The vvp_fum_memport is a structural port into a vvp_memory_t
106 * object. The output is the word that is read from the addressed
107 * memory, and the inputs are the address and optional write controls.
110 * This addresses the word in the memory. The output follows this
111 * address as it changes, and also follows the value of the addressed
120 * NOTE: This functor is unique in that it needs to store the
121 * vvp_net_t pointer associated with it. It needs this because it can
122 * received input from other than its ports. Notably, the memory
123 * itself reports word changes.
125 class vvp_fun_memport
: public vvp_net_fun_t
{
128 explicit vvp_fun_memport(vvp_memory_t mem
, vvp_net_t
*net
);
131 void recv_vec4(vvp_net_ptr_t port
, const vvp_vector4_t
&bit
);
136 friend void memory_set_word(vvp_memory_t
, unsigned,
137 unsigned, vvp_vector4_t
);
138 void check_word_change(unsigned long address
);
139 class vvp_fun_memport
*next_
;
147 ** Access to the memory symbol table.
149 ** The memory_find function locates the memory device by name. If the
150 ** device does not exist, a nil is returned.
152 ** The memory_create functio create a new memory device with the given
153 ** name. It is a fatal error to try to create a device that already exists.
155 vvp_memory_t
memory_find(char *label
);
156 vvp_memory_t
memory_create(char *label
);
160 * Revision 1.13 2007/03/22 16:08:19 steve
161 * Spelling fixes from Larry
163 * Revision 1.12 2006/03/05 05:45:58 steve
164 * Add support for memory value change callbacks.
166 * Revision 1.11 2006/02/02 02:44:00 steve
167 * Allow part selects of memory words in l-values.
169 * Revision 1.10 2005/06/22 00:04:49 steve
170 * Reduce vvp_vector4 copies by using const references.
172 * Revision 1.9 2005/03/09 04:52:40 steve
173 * reimplement memory ports.
175 * Revision 1.8 2005/03/03 04:33:10 steve
176 * Rearrange how memories are supported as vvp_vector4 arrays.