ngspice/src/spicelib/parser/inp2m.c

252 lines
8.7 KiB
C
Raw Normal View History

2000-04-27 22:03:57 +02:00
/**********
Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1988 Thomas L. Quarles
Modified: 2001 Paolo Nenzi (Cider Integration)
2000-04-27 22:03:57 +02:00
**********/
#include "ngspice/ngspice.h"
2000-04-27 22:03:57 +02:00
#include <stdio.h>
#include "ngspice/ifsim.h"
#include "ngspice/inpdefs.h"
#include "ngspice/inpmacs.h"
#include "ngspice/fteext.h"
#include "inpxx.h"
2000-04-27 22:03:57 +02:00
2017-01-09 19:05:34 +01:00
static int
model_numnodes(int type)
{
if (type == INPtypelook("B4SOI") || /* 7 ; B4SOInames */
type == INPtypelook("B3SOIPD") || /* 7 ; B3SOIPDnames */
type == INPtypelook("B3SOIFD") || /* 7 ; B3SOIFDnames */
type == INPtypelook("B3SOIDD")) /* 7 ; B3SOIDDnames */
{
return 7;
}
if (type == INPtypelook("HiSIMHV1") || /* 6 ; HSMHVnames */
type == INPtypelook("HiSIMHV2") || /* 6 ; HSMHV2names */
type == INPtypelook("SOI3")) /* 6 ; SOI3names */
{
return 6;
}
return 4;
}
static bool
valid_numnodes(int numnodes, INPmodel *thismodel, card *current)
{
bool valid;
switch (numnodes) {
case 7:
valid =
thismodel->INPmodType == INPtypelook("B4SOI") ||
thismodel->INPmodType == INPtypelook("B3SOIPD") ||
thismodel->INPmodType == INPtypelook("B3SOIFD") ||
thismodel->INPmodType == INPtypelook("B3SOIDD");
if (!valid)
LITERR ("only level 55-58: B3SOI(PD|FD|DD) and B4SOI can have 7 nodes");
return valid;
case 6:
valid =
thismodel->INPmodType == INPtypelook("B4SOI") ||
thismodel->INPmodType == INPtypelook("B3SOIPD") ||
thismodel->INPmodType == INPtypelook("B3SOIFD") ||
thismodel->INPmodType == INPtypelook("B3SOIDD") ||
thismodel->INPmodType == INPtypelook("HiSIMHV1") ||
thismodel->INPmodType == INPtypelook("HiSIMHV2") ||
thismodel->INPmodType == INPtypelook("SOI3");
if (!valid)
LITERR ("only level 55-58,61,62: B3SOI(PD|FD|DD), B4SOI, STAG (SOI3) and HiSIMHV can have 6 nodes");
return valid;
case 5:
valid =
thismodel->INPmodType == INPtypelook("B4SOI") ||
thismodel->INPmodType == INPtypelook("B3SOIPD") ||
thismodel->INPmodType == INPtypelook("B3SOIFD") ||
thismodel->INPmodType == INPtypelook("B3SOIDD") ||
thismodel->INPmodType == INPtypelook("HiSIMHV1") ||
thismodel->INPmodType == INPtypelook("HiSIMHV2") ||
thismodel->INPmodType == INPtypelook("SOI3");
if (!valid)
LITERR ("only level 55-58,61,62: B3SOI(PD|FD|DD), B4SOI, STAG (SOI3) and HiSIMHV can have 5 nodes");
return valid;
default:
return TRUE;
}
}
void
2017-01-09 19:05:34 +01:00
INP2M(CKTcircuit *ckt, INPtables *tab, card *current)
2000-04-27 22:03:57 +02:00
{
2013-09-29 22:09:42 +02:00
/* Mname <node> <node> <node> <node> <model> [L=<val>]
* [W=<val>] [AD=<val>] [AS=<val>] [PD=<val>]
* [PS=<val>] [NRD=<val>] [NRS=<val>] [OFF]
* [IC=<val>,<val>,<val>]
*/
2000-04-27 22:03:57 +02:00
2013-09-29 22:09:42 +02:00
int type; /* the type the model says it is */
char *line; /* the part of the current line left to parse */
char *name; /* the resistor's name */
char *nname[8];
2013-09-29 22:09:42 +02:00
char *save; /* saj - used to save the posn of the start of
2017-01-09 19:05:34 +01:00
the parameters if the model is a mosfet*/
CKTnode *node[7];
2013-09-29 22:09:42 +02:00
int error; /* error code temporary */
2017-03-07 21:36:34 +01:00
int numnodes; /* flag indicating 4 or 5 (or 6 or 7) nodes */
2013-09-29 22:09:42 +02:00
GENinstance *fast; /* pointer to the actual instance */
int waslead; /* flag to indicate that funny unlabeled number was found */
double leadval; /* actual value of unlabeled number */
char *model; /* the name of the model */
INPmodel *thismodel; /* pointer to model description for user's model */
GENmodel *mdfast; /* pointer to the actual model */
IFuid uid; /* uid for default model */
2017-01-09 19:05:34 +01:00
char *err_msg;
int i;
2000-04-27 22:03:57 +02:00
#ifdef TRACE
2017-01-09 19:05:34 +01:00
printf("INP2M: Parsing '%s'\n", current->line);
#endif
2017-03-07 21:36:34 +01:00
numnodes = 4; /* initially specify a 4 terminal device */
2013-09-29 22:09:42 +02:00
line = current->line;
2017-01-09 19:05:34 +01:00
INPgetTok(&line, &name, 1);
INPinsert(&name, tab);
INPgetNetTok(&line, &nname[0], 1);
INPtermInsert(ckt, &nname[0], tab, &node[0]);
INPgetNetTok(&line, &nname[1], 1);
INPtermInsert(ckt, &nname[1], tab, &node[1]);
INPgetNetTok(&line, &nname[2], 1);
INPtermInsert(ckt, &nname[2], tab, &node[2]);
INPgetNetTok(&line, &nname[3], 1);
INPtermInsert(ckt, &nname[3], tab, &node[3]);
node[4] = NULL;
node[5] = NULL;
node[6] = NULL;
2017-03-07 21:36:34 +01:00
for (numnodes = 4; numnodes < 8; numnodes++) {
2017-01-09 19:05:34 +01:00
2017-03-07 21:36:34 +01:00
INPgetNetTok(&line, &nname[numnodes], 1);
2017-01-09 19:05:34 +01:00
2017-03-07 21:36:34 +01:00
if (numnodes == 4)
save = line; /* saj - save the posn for later if
the default mosfet model is used */
2017-03-07 21:36:34 +01:00
err_msg = INPgetMod(ckt, nname[numnodes], &thismodel, tab);
2013-09-08 14:02:21 +02:00
tfree(err_msg);
2017-01-09 19:05:34 +01:00
/* check if using model binning -- pass in line since need 'l' and 'w' */
2017-03-07 21:36:34 +01:00
if (!thismodel && numnodes < 5)
INPgetModBin(ckt, nname[numnodes], &thismodel, tab, line);
if (thismodel)
break;
}
/* nothing found, reset and process as if it were a 4 node device */
2017-03-07 21:36:34 +01:00
if (numnodes >= 8) {
numnodes = 4;
line = save;
}
2017-03-07 21:36:34 +01:00
if (!valid_numnodes(numnodes, thismodel, current))
return;
2017-03-07 21:36:34 +01:00
for (i = 4; i < numnodes; i++)
INPtermInsert(ckt, &nname[i], tab, &node[i]);
2017-03-07 21:36:34 +01:00
model = nname[numnodes];
2017-01-09 19:05:34 +01:00
INPinsert(&model, tab);
#ifdef TRACE
2013-09-29 22:09:42 +02:00
printf("INP2M: Looking up model\n");
#endif
2017-01-09 19:05:34 +01:00
err_msg = INPgetMod(ckt, model, &thismodel, tab);
2017-01-09 19:06:48 +01:00
if (!thismodel) {
2017-01-09 19:05:34 +01:00
INPgetModBin(ckt, model, &thismodel, tab, save);
2017-01-08 20:13:59 +01:00
if (!thismodel) {
2013-09-29 22:16:23 +02:00
current->error = err_msg;
2017-01-08 20:13:59 +01:00
err_msg = NULL;
}
2013-09-29 22:09:42 +02:00
}
2017-01-08 20:13:59 +01:00
tfree(err_msg);
2017-01-09 19:06:48 +01:00
if (thismodel) {
2017-01-09 19:05:34 +01:00
if (thismodel->INPmodType != INPtypelook("Mos1") &&
thismodel->INPmodType != INPtypelook("Mos2") &&
thismodel->INPmodType != INPtypelook("Mos3") &&
thismodel->INPmodType != INPtypelook("Mos5") &&
thismodel->INPmodType != INPtypelook("Mos6") &&
thismodel->INPmodType != INPtypelook("Mos8") &&
thismodel->INPmodType != INPtypelook("Mos9") &&
thismodel->INPmodType != INPtypelook("BSIM1") &&
thismodel->INPmodType != INPtypelook("BSIM2") &&
thismodel->INPmodType != INPtypelook("BSIM3") &&
thismodel->INPmodType != INPtypelook("BSIM3v32") &&
thismodel->INPmodType != INPtypelook("B4SOI") &&
thismodel->INPmodType != INPtypelook("B3SOIPD") &&
thismodel->INPmodType != INPtypelook("B3SOIFD") &&
thismodel->INPmodType != INPtypelook("B3SOIDD") &&
thismodel->INPmodType != INPtypelook("BSIM4") &&
thismodel->INPmodType != INPtypelook("BSIM4v5") &&
thismodel->INPmodType != INPtypelook("BSIM4v6") &&
thismodel->INPmodType != INPtypelook("BSIM4v7") &&
thismodel->INPmodType != INPtypelook("BSIM3v0") &&
thismodel->INPmodType != INPtypelook("BSIM3v1") &&
thismodel->INPmodType != INPtypelook("SOI3") &&
#ifdef CIDER
2017-01-09 19:05:34 +01:00
thismodel->INPmodType != INPtypelook("NUMOS") &&
#endif
2006-02-18 10:15:17 +01:00
#ifdef ADMS
2017-01-09 19:05:34 +01:00
thismodel->INPmodType != INPtypelook("ekv") &&
thismodel->INPmodType != INPtypelook("psp102") &&
2013-09-29 22:09:42 +02:00
#endif
2017-01-09 19:05:34 +01:00
thismodel->INPmodType != INPtypelook("HiSIM2") &&
thismodel->INPmodType != INPtypelook("HiSIMHV1") &&
thismodel->INPmodType != INPtypelook("HiSIMHV2"))
2017-01-09 19:07:33 +01:00
{
2013-09-29 22:09:42 +02:00
LITERR ("incorrect model type");
return;
}
type = thismodel->INPmodType;
2017-01-09 19:07:33 +01:00
mdfast = thismodel->INPmodfast;
2013-09-29 22:09:42 +02:00
} else {
2017-01-09 19:05:34 +01:00
type = INPtypelook("Mos1");
2013-09-29 22:09:42 +02:00
if (type < 0) {
LITERR ("Device type MOS1 not supported by this binary\n");
return;
}
if (!tab->defMmod) {
/* create default M model */
2017-01-09 19:05:34 +01:00
IFnewUid(ckt, &uid, NULL, "M", UID_MODEL, NULL);
2013-09-29 22:09:42 +02:00
IFC (newModel, (ckt, type, &(tab->defMmod), uid));
}
mdfast = tab->defMmod;
2000-04-27 22:03:57 +02:00
}
2017-01-09 19:05:34 +01:00
2013-09-29 22:09:42 +02:00
IFC (newInstance, (ckt, mdfast, &fast, name));
2017-01-09 19:05:34 +01:00
2013-09-29 22:09:42 +02:00
/* use type - not thismodel->INPmodType as it might not exist! */
int model_numnodes_ = model_numnodes(type);
2017-03-07 20:56:19 +01:00
for (i = 0; i < model_numnodes_; i++)
if (i < numnodes)
IFC (bindNode, (ckt, fast, i + 1, node[i]));
else
fast->GENnode[i] = -1;
2013-09-29 22:09:42 +02:00
PARSECALL ((&line, ckt, type, fast, &leadval, &waslead, tab));
2017-01-09 19:07:33 +01:00
if (waslead)
2013-09-29 22:09:42 +02:00
LITERR (" error: no unlabeled parameter permitted on mosfet\n");
2000-04-27 22:03:57 +02:00
}