2 * Copyright (c) 1999-2000 Picture Elements, Inc.
3 * Stephen Williams (steve@picturel.com)
5 * This source code is free software; you can redistribute it
6 * and/or modify it in source code form under the terms of the GNU
7 * General Public License as published by the Free Software
8 * Foundation; either version 2 of the License, or (at your option)
9 * any later version. In order to redistribute the software in
10 * binary form, you will need a Picture Elements Binary Software
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
22 * You should also have received a copy of the Picture Elements
23 * Binary Software License offer along with the source. This offer
24 * allows you to obtain the right to redistribute the software in
25 * binary (compiled) form. If you have not received it, contact
26 * Picture Elements, Inc., 777 Panoramic Way, Berkeley, CA 94704.
29 #ident "$Id: vpi_memory.c,v 1.4 2007/02/26 19:49:51 steve Exp $"
32 # include "vpi_priv.h"
36 static int memory_get(int code
, vpiHandle ref
)
38 struct __vpiMemory
*rfp
= (struct __vpiMemory
*)ref
;
40 assert(ref
->vpi_type
->type_code
==vpiMemory
);
51 static const char* memory_get_str(int code
, vpiHandle ref
)
53 struct __vpiMemory
*rfp
= (struct __vpiMemory
*)ref
;
54 assert(ref
->vpi_type
->type_code
==vpiMemory
);
59 return (char*)rfp
->name
;
65 static vpiHandle
memory_iterate(int code
, vpiHandle ref
)
68 struct __vpiMemory
*rfp
= (struct __vpiMemory
*)ref
;
69 assert(ref
->vpi_type
->type_code
==vpiMemory
);
74 rfp
->args
= calloc(rfp
->size
, sizeof(vpiHandle
));
75 for (idx
= 0 ; idx
< rfp
->size
; idx
+= 1)
76 rfp
->args
[idx
] = &rfp
->words
[idx
].base
;
78 return vpip_make_iterator(rfp
->size
, rfp
->args
);
85 static vpiHandle
memory_index(vpiHandle ref
, int index
)
87 struct __vpiMemory
*rfp
= (struct __vpiMemory
*)ref
;
88 assert(ref
->vpi_type
->type_code
==vpiMemory
);
92 rfp
->args
= calloc(rfp
->size
, sizeof(vpiHandle
));
93 for (idx
= 0 ; idx
< rfp
->size
; idx
+= 1)
94 rfp
->args
[idx
] = &rfp
->words
[idx
].base
;
97 if (index
> rfp
->size
) return 0;
98 if (index
< 0) return 0;
99 return &(rfp
->words
[index
].base
);
102 static int memory_word_get(int code
, vpiHandle ref
)
104 struct __vpiMemoryWord
*rfp
= (struct __vpiMemoryWord
*)ref
;
105 assert(ref
->vpi_type
->type_code
==vpiMemoryWord
);
109 return rfp
->mem
->width
;
116 static vpiHandle
memory_word_put(vpiHandle ref
, p_vpi_value val
,
117 p_vpi_time tim
, int flags
)
121 struct __vpiMemoryWord
*rfp
= (struct __vpiMemoryWord
*)ref
;
122 assert(ref
->vpi_type
->type_code
==vpiMemoryWord
);
124 base
= rfp
->mem
->bits
+ rfp
->index
*rfp
->mem
->width
;
126 assert(val
->format
== vpiVectorVal
);
127 for (idx
= 0 ; idx
< rfp
->mem
->width
; idx
+= 1) {
128 p_vpi_vecval cur
= val
->value
.vector
+ (idx
/32);
129 int aval
= cur
->aval
>> (idx
%32);
130 int bval
= cur
->bval
>> (idx
%32);
148 static void memory_word_get_value(vpiHandle ref
, s_vpi_value
*vp
)
150 struct __vpiMemoryWord
*rfp
= (struct __vpiMemoryWord
*)ref
;
151 assert(ref
->vpi_type
->type_code
==vpiMemoryWord
);
153 vpip_bits_get_value(rfp
->mem
->bits
+rfp
->index
*rfp
->mem
->width
,
154 rfp
->mem
->width
, vp
, 0);
157 static const struct __vpirt vpip_memory_rt
= {
168 static const struct __vpirt vpip_memory_word_rt
= {
172 memory_word_get_value
,
179 vpiHandle
vpip_make_memory(struct __vpiMemory
*ref
, const char*name
,
180 unsigned wid
, unsigned siz
)
184 ref
->base
.vpi_type
= &vpip_memory_rt
;
186 ref
->bits
= calloc(wid
*siz
, sizeof(vpip_bit_t
));
187 for (idx
= 0 ; idx
< wid
*siz
; idx
+= 1)
188 ref
->bits
[idx
] = StX
;
189 ref
->words
= calloc(siz
, sizeof(struct __vpiMemoryWord
));
194 for (idx
= 0 ; idx
< siz
; idx
+= 1) {
195 ref
->words
[idx
].base
.vpi_type
= &vpip_memory_word_rt
;
196 ref
->words
[idx
].mem
= ref
;
197 ref
->words
[idx
].index
= idx
;
203 * $Log: vpi_memory.c,v $
204 * Revision 1.4 2007/02/26 19:49:51 steve
205 * Spelling fixes (larry doolittle)
207 * Revision 1.3 2002/08/12 01:35:05 steve
208 * conditional ident string using autoconfig.
210 * Revision 1.2 2001/10/26 02:29:10 steve
211 * const/non-const warnings. (Stephan Boettcher)
213 * Revision 1.1 2001/03/14 19:27:44 steve
214 * Rearrange VPI support libraries.
216 * Revision 1.9 2001/01/06 22:22:17 steve
217 * Support signed decimal display of variables.
219 * Revision 1.8 2000/06/28 18:38:00 steve
220 * Initialize memories as they are create.
222 * Revision 1.7 2000/03/22 04:26:41 steve
223 * Replace the vpip_bit_t with a typedef and
224 * define values for all the different bit
225 * values, including strengths.
227 * Revision 1.6 2000/02/29 01:41:32 steve
228 * Fix warning and typo.
230 * Revision 1.5 2000/02/23 02:56:56 steve
231 * Macintosh compilers do not support ident.
233 * Revision 1.4 2000/02/13 19:18:28 steve
234 * Accept memory words as parameter to $display.
236 * Revision 1.3 1999/12/15 04:15:17 steve
237 * Implement vpi_put_value for memory words.
239 * Revision 1.2 1999/12/15 04:01:14 steve
240 * Add the VPI implementation of $readmemh.
242 * Revision 1.1 1999/11/10 02:52:24 steve
243 * Create the vpiMemory handle type.