1 /*$Id: d_logic.h,v 1.4 2009-12-13 17:55:01 felix Exp $ -*- C++ -*-
3 * Copyright (C) 2001 Albert Davis
4 * Author: Albert Davis <aldavis@gnu.org>
6 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3, 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., 51 Franklin Street, Fifth Floor, Boston, MA
22 *------------------------------------------------------------------
23 * data structures and defaults for logic model.
25 //testing=script,sparse 2006.07.17
31 /*--------------------------------------------------------------------------*/
32 enum {PORTS_PER_GATE
= 10};
33 /*--------------------------------------------------------------------------*/
34 class DEV_LOGIC
: public ELEMENT
{
36 enum {OUTNODE
=0,GND_NODE
=1,PWR_NODE
=2,ENABLE
=3,BEGIN_IN
=4}; //node labels
38 uint_t _lastchangenode
;
40 std::string _failuremode
;
44 node_t nodes
[PORTS_PER_GATE
]; /* PORTS_PER_GATE <= PORTSPERSUBCKT */
47 explicit DEV_LOGIC(const DEV_LOGIC
& p
);
48 ~DEV_LOGIC() {--_count
;}
49 private: // override virtuals
50 char id_letter()const {return 'U';}
51 std::string
value_name()const {return "#";}
52 bool print_type_in_spice()const {return true;}
53 std::string
dev_type()const {assert(has_common());
54 return (common()->modelname() + " " + common()->name()).c_str();}
55 uint_t
tail_size()const {return 2;}
56 uint_t
max_nodes()const {return PORTS_PER_GATE
;}
57 uint_t
min_nodes()const {return BEGIN_IN
+1;}
58 uint_t
matrix_nodes()const {return 2;}
59 uint_t
net_nodes()const {return _net_nodes
;}
60 CARD
* clone()const {return new DEV_LOGIC(*this);}
61 void precalc_first() {ELEMENT::precalc_first(); if (subckt()) {subckt()->precalc_first();}}
63 void precalc_last() {ELEMENT::precalc_last(); if (subckt()) {subckt()->precalc_last();}}
66 void tr_iwant_matrix();
72 bool tr_needs_eval()const;
76 TIME_PAIR
tr_review();
79 hp_float_t
tr_involts()const {unreachable(); return 0;}
80 //double tr_input()const //ELEMENT
81 hp_float_t
tr_involts_limited()const {unreachable(); return 0;}
82 //double tr_input_limited()const //ELEMENT
83 //double tr_amps()const //ELEMENT
84 double tr_probe_num(const std::string
&)const;
86 void ac_iwant_matrix();
88 void do_ac() {untested(); assert(subckt()); subckt()->do_ac();}
89 void ac_load() {untested(); assert(subckt()); subckt()->ac_load();}
90 COMPLEX
ac_involts()const {unreachable(); return 0.;}
91 COMPLEX
ac_amps()const {unreachable(); return 0.;}
92 XPROBE
ac_probe_ext(const std::string
&)const;
95 std::string
port_name(uint_t
)const {untested();
100 static int count() {return _count
;}
102 bool tr_eval_digital();
103 bool want_analog()const;
104 bool want_digital()const;
109 /*--------------------------------------------------------------------------*/
110 class MODEL_LOGIC
: public MODEL_CARD
{
112 explicit MODEL_LOGIC(const MODEL_LOGIC
& p
);
114 explicit MODEL_LOGIC(const COMPONENT
*);
115 ~MODEL_LOGIC() {--_count
;}
116 protected: // override virtuals
117 std::string
dev_type()const {return "logic";}
118 CARD
* clone()const {return new MODEL_LOGIC(*this);}
119 void precalc_first();
120 void set_param_by_index(int, std::string
&, int);
121 bool param_is_printable(int)const;
122 std::string
param_name(int)const;
123 std::string
param_name(int,int)const;
124 std::string
param_value(int)const;
125 int param_count()const {return (13 + MODEL_CARD::param_count());}
127 static int count() {return _count
;}
129 /* ----- digital mode ----- */
130 PARAMETER
<double> delay
; /* propagation delay */
131 /* -- conversion parameters both ways -- */
132 PARAMETER
<double> vmax
; /* nominal volts for logic 1 */
133 PARAMETER
<double> vmin
; /* nominal volts for logic 0 */
134 PARAMETER
<double> unknown
; /* nominal volts for unknown (bogus) */
135 /* ---- D to A conversion ---- */
136 PARAMETER
<double> rise
; /* rise time (time in slope) */
137 PARAMETER
<double> fall
; /* fall time (time in slope) */
138 PARAMETER
<double> rs
; /* series resistance -- strong */
139 PARAMETER
<double> rw
; /* series resistance -- weak */
140 /* ---- A to D conversion ---- */
141 PARAMETER
<double> th1
; /* threshold for 1 as fraction of range */
142 PARAMETER
<double> th0
; /* threshold for 0 as fraction of range */
143 /* ---- quality judgement parameters ---- */
144 PARAMETER
<double> mr
; /* margin rise - how much worse rise can be */
145 PARAMETER
<double> mf
; /* margin fall - how much worse fall can be */
146 PARAMETER
<double> over
; /* overshoot limit - as fraction of range */
147 public: // calculated parameters
148 double range
; /* vmax - vmin */
149 double margin
; // safety margin for analog transitions. under construction.
150 intptr_t logic_hash()const {return _hash
;}
156 /*--------------------------------------------------------------------------*/
157 class INTERFACE COMMON_LOGIC
: public COMMON_COMPONENT
{
159 explicit COMMON_LOGIC(int c
=0)
160 :COMMON_COMPONENT(c
), incount(0) {++_count
;}
161 explicit COMMON_LOGIC(const COMMON_LOGIC
& p
)
162 :COMMON_COMPONENT(p
), incount(p
.incount
) {++_count
;}
164 ~COMMON_LOGIC() { --_count
; }
165 bool operator==(const COMMON_COMPONENT
&)const;
166 static int count() {return _count
;}
167 virtual LOGICVAL
logic_eval(const node_t
*)const = 0;
173 /*--------------------------------------------------------------------------*/
174 class LOGIC_AND
: public COMMON_LOGIC
{
176 explicit LOGIC_AND(const LOGIC_AND
& p
) :COMMON_LOGIC(p
){++_count
;}
177 COMMON_COMPONENT
* clone()const {return new LOGIC_AND(*this);}
179 explicit LOGIC_AND(int c
=0) :COMMON_LOGIC(c
) {}
180 LOGICVAL
logic_eval(const node_t
* n
)const {
181 LOGICVAL
out(n
[0]->lv());
182 for (int ii
=1; ii
<incount
; ++ii
) {untested();
187 virtual std::string
name()const {return "and";}
189 /*--------------------------------------------------------------------------*/
190 class LOGIC_NAND
: public COMMON_LOGIC
{
192 explicit LOGIC_NAND(const LOGIC_NAND
&p
):COMMON_LOGIC(p
){++_count
;}
193 COMMON_COMPONENT
* clone()const {return new LOGIC_NAND(*this);}
195 explicit LOGIC_NAND(int c
=0) :COMMON_LOGIC(c
) {}
196 LOGICVAL
logic_eval(const node_t
* n
)const {itested();
197 LOGICVAL
out(n
[0]->lv());
198 for (int ii
=1; ii
<incount
; ++ii
) {itested();
203 virtual std::string
name()const {itested();return "nand";}
205 /*--------------------------------------------------------------------------*/
206 class LOGIC_OR
: public COMMON_LOGIC
{
208 explicit LOGIC_OR(const LOGIC_OR
& p
) :COMMON_LOGIC(p
){itested();++_count
;}
209 COMMON_COMPONENT
* clone()const {itested(); return new LOGIC_OR(*this);}
211 explicit LOGIC_OR(int c
=0) :COMMON_LOGIC(c
) {itested();}
212 LOGICVAL
logic_eval(const node_t
* n
)const {itested();
213 LOGICVAL
out(n
[0]->lv());
214 for (int ii
=1; ii
<incount
; ++ii
) {itested();
219 virtual std::string
name()const {itested();return "or";}
221 /*--------------------------------------------------------------------------*/
222 class LOGIC_NOR
: public COMMON_LOGIC
{
224 explicit LOGIC_NOR(const LOGIC_NOR
& p
) :COMMON_LOGIC(p
) {++_count
;}
225 COMMON_COMPONENT
* clone()const {return new LOGIC_NOR(*this);}
227 explicit LOGIC_NOR(int c
=0) :COMMON_LOGIC(c
) {}
228 LOGICVAL
logic_eval(const node_t
* n
)const {
229 LOGICVAL
out(n
[0]->lv());
230 for (int ii
=1; ii
<incount
; ++ii
) {
235 virtual std::string
name()const {return "nor";}
237 /*--------------------------------------------------------------------------*/
238 class LOGIC_XOR
: public COMMON_LOGIC
{
240 explicit LOGIC_XOR(const LOGIC_XOR
& p
) :COMMON_LOGIC(p
){untested();++_count
;}
241 COMMON_COMPONENT
* clone()const {untested(); return new LOGIC_XOR(*this);}
243 explicit LOGIC_XOR(int c
=0) :COMMON_LOGIC(c
) {untested();}
244 LOGICVAL
logic_eval(const node_t
* n
)const {untested();
245 LOGICVAL
out(n
[0]->lv());
246 for (int ii
=1; ii
<incount
; ++ii
) {untested();
251 virtual std::string
name()const {itested();return "xor";}
253 /*--------------------------------------------------------------------------*/
254 class LOGIC_XNOR
: public COMMON_LOGIC
{
256 explicit LOGIC_XNOR(const LOGIC_XNOR
&p
):COMMON_LOGIC(p
){untested();++_count
;}
257 COMMON_COMPONENT
* clone()const {untested(); return new LOGIC_XNOR(*this);}
259 explicit LOGIC_XNOR(int c
=0) :COMMON_LOGIC(c
) {untested();}
260 LOGICVAL
logic_eval(const node_t
* n
)const {untested();
261 LOGICVAL
out(n
[0]->lv());
262 for (int ii
=1; ii
<incount
; ++ii
) {untested();
267 virtual std::string
name()const {itested();return "xnor";}
269 /*--------------------------------------------------------------------------*/
270 class LOGIC_INV
: public COMMON_LOGIC
{
272 explicit LOGIC_INV(const LOGIC_INV
& p
) :COMMON_LOGIC(p
){++_count
;}
273 COMMON_COMPONENT
* clone()const {return new LOGIC_INV(*this);}
275 explicit LOGIC_INV(int c
=0) :COMMON_LOGIC(c
) {}
276 LOGICVAL
logic_eval(const node_t
* n
)const {
279 virtual std::string
name()const {return "inv";}
281 /*--------------------------------------------------------------------------*/
282 class LOGIC_NONE
: public COMMON_LOGIC
{
284 explicit LOGIC_NONE(const LOGIC_NONE
&p
):COMMON_LOGIC(p
){itested();++_count
;}
285 COMMON_COMPONENT
* clone()const {itested(); return new LOGIC_NONE(*this);}
287 explicit LOGIC_NONE(int c
=0) :COMMON_LOGIC(c
) {}
288 LOGICVAL
logic_eval(const node_t
*)const {untested();
291 virtual std::string
name()const {untested();return "error";}
293 /*--------------------------------------------------------------------------*/
294 //extern LOGIC_NONE Default_LOGIC;
295 /*--------------------------------------------------------------------------*/
297 // vim:ts=8:sw=2:noet: