⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spiceif.c

📁 支持数字元件仿真的SPICE插件
💻 C
📖 第 1 页 / 共 2 页
字号:
    struct variable *nv;    int i = 0;#ifndef LINT    switch (opt->dataType & IF_VARTYPES) {#else    switch (i) {#endif        case IF_INTEGER:            vv->va_type = VT_NUM;            vv->va_num = pv->iValue;            break;        case IF_REAL:        case IF_COMPLEX:            vv->va_type = VT_REAL;            vv->va_real = pv->rValue;            break;        case IF_STRING:            vv->va_type = VT_STRING;            vv->va_string = pv->sValue;            break;        case IF_FLAG:            vv->va_type = VT_BOOL;            vv->va_bool = pv->iValue ? true : false;            break;        case IF_REALVEC:            vv->va_type = VT_LIST;            for (i = 0; i < pv->v.numValue; i++) {                nv = alloc(variable);                nv->va_next = vv->va_vlist;                vv->va_vlist = nv;                nv->va_type = VT_REAL;                nv->va_real = pv->v.vec.rVec[i];            }            break;        default:            fprintf(cp_err,              "parmtovar: Internal Error: bad PARM type %d.\n",                    opt->dataType);            return (NULL);    }    /* It's not clear whether we want the keyword or the desc here... */    vv->va_name = copy(opt->description);    return (vv);}/* Extract the IFparm structure from the device. If isdev is true, then get * the DEVmodQuest, otherwise get the DEVquest. */static IFparm *parmlookup(dev, inptr, param)    IFdevice *dev;    GENinstance **inptr;    char *param;{    int i;    /* fprintf(cp_err, "Called: parmlookup(%x, %c, %s)\n",             dev, isdev, param); */    /* First try the device questions... */    if (inptr) {        for (i = 0; i < dev->numInstanceParms; i++) {            if ((dev->instanceParms[i].dataType & IF_ASK) &&                    eq(dev->instanceParms[i].keyword, param))                return (&dev->instanceParms[i]);        }    }    /* Zero the device pointer so that CKTmodAsk will get called...     * This is ugly...     */    *inptr = NULL;    for (i = 0; i < dev->numModelParms; i++)        if ( (dev->instanceParms[i].dataType & IF_ASK) &&                eq(dev->modelParms[i].keyword, param))            return (&dev->modelParms[i]);    return (NULL);}/* Perform the CKTask call. We have both 'fast' and 'modfast', so the other * parameters aren't necessary. *//* ARGSUSED */static IFvalue *doask(ckt, typecode, dev, mod, opt, ind)    char *ckt;    GENinstance *dev;    GENmodel *mod;    IFparm *opt;    int ind;{    static IFvalue pv;    int err;    pv.iValue = ind;    /* Sometimes this will be junk and ignored... */    /* fprintf(cp_err, "Calling doask(%d, %x, %x, %x)\n",             typecode, dev, mod, opt); */    if (dev)        err = (*(ft_sim->askInstanceQuest))((GENERIC *)ckt, (GENERIC *)dev,                 opt->id, &pv, (IFvalue *)NULL);    else        err = (*(ft_sim->askModelQuest))((GENERIC*)ckt, (GENERIC*) mod,                 opt->id, &pv, (IFvalue *)NULL);    if (err != OK) {        ft_sperror(err, "if_getparam");        return (NULL);    }    return (&pv);}/* Get pointers to a device, its model, and its type number given the name. If * there is no such device, try to find a model with that name. */static intfinddev(ck, name, devptr, modptr)    char *ck;    char *name;    GENERIC **devptr;    GENERIC **modptr;{    int err;    int type = -1;    err = (*(ft_sim->findInstance))((GENERIC *)ck,&type,devptr,name,NULL,NULL);    if(err == OK) return(type);    type = -1;    *devptr = (GENERIC *)NULL;    err = (*(ft_sim->findModel))((GENERIC *)ck,&type,modptr,name);    if(err == OK) return(type);    *modptr = (GENERIC *)NULL;    return(-1);}/* Extract the node and device names from the line and add them to the command * completion structure.  This is probably not a good thing to do if it * takes too much time. */ /* BLOW THIS AWAY */voidif_setndnames(line)    char *line;{    char *t;    int i;/* gtri - add - wbk - 10/23/90 - add new local variables */    char *next_t;/* gtri - end - wbk - 10/23/90 *//* gtri - add - wbk - 10/23/90 - handle new A devices here without *//* calling inp_numnodes()                                          */    if((*line == 'a') || (*line == 'A')) {        /* skip the instance name */        MIFgettok(&line);        /* process up to last token */        next_t = MIFgettok(&line);        while(1) {            /* rotate the tokens and get the next one */            t = next_t;            next_t = MIFgettok(&line);            /* if next one is null, current one is model name, */            /* so exit                                         */            if(next_t == NULL)                break;            /* otherwise, check to see if it is a node name */            switch(*t) {            case '{':            case '}':            case '~':                break;            case '%':                /* skip over the next token which is the port type */                next_t = MIFgettok(&line);                break;            default:                /* it's a node name, so add it to the list */                cp_addkword(CT_DEVNAMES, t);                break;            } /*switch */        } /* while */        return;    } /* if *//* gtri - end - wbk - 10/23/90 */    while (isspace(*line))        line++;    if (!*line || (*line == '*') || (*line == '.'))        return;    t = gettok(&line);    if (!(i = inp_numnodes(*t)))        return;    if ((*t == 'q') || (*t == 'Q'))        i = 3;        cp_addkword(CT_DEVNAMES, t);    while (i-- > 0) {        t = gettok(&line);        if (t)            cp_addkword(CT_NODENAMES, t);    }    return;}/* get an analysis parameter by name instead of id */int if_analQbyName(ckt,which,anal,name,parm)    GENERIC *ckt;    int which;    GENERIC *anal;    char *name;    IFvalue *parm;{    int i;    for(i=0;i<ft_sim->analyses[which]->numParms;i++) {        if(strcmp(ft_sim->analyses[which]->analysisParms[i].keyword,name)==0) {            return( (*(ft_sim->askAnalysisQuest))(ckt,anal,                    ft_sim->analyses[which]->analysisParms[i].id,parm,                    (IFvalue *)NULL) );        }    }    return(E_BADPARM);}/* Get the parameters tstart, tstop, and tstep from the CKT struct. *//* BLOW THIS AWAY TOO */boolif_tranparams(ci, start, stop, step)    struct circ *ci;    double *start, *stop, *step;{    IFvalue tmp;    int err;    int which = -1;    int i;    GENERIC *anal;    IFuid tranUid;    if(!ci->ci_curTask) return(false);    for(i=0;i<ft_sim->numAnalyses;i++) {        if(strcmp(ft_sim->analyses[i]->name,"TRAN")==0){            which = i;            break;        }    }    if(which == -1) return(false);    err = IFnewUid(ci->ci_ckt,&tranUid,(IFuid)NULL,"transient",UID_ANALYSIS,            (GENERIC**)NULL);    if(err != OK) return(false);    err =(*(ft_sim->findAnalysis))(ci->ci_ckt,&which, &anal,tranUid,            ci->ci_curTask,(IFuid *)NULL);    if(err != OK) return(false);    err = if_analQbyName(ci->ci_ckt,which,anal,"tstart",&tmp);    if(err != OK) return(false);    *start = tmp.rValue;    err = if_analQbyName(ci->ci_ckt,which,anal,"tstop",&tmp);    if(err != OK) return(false);    *stop = tmp.rValue;    err = if_analQbyName(ci->ci_ckt,which,anal,"tstep",&tmp);    if(err != OK) return(false);    *step = tmp.rValue;    return (true);}/* Get the statistic called 'name'.  If this is NULL get all statistics * available. */struct variable *if_getstat(ckt, name)    char *ckt;    char *name;{    int i;    struct variable *v, *vars;    IFvalue parm;    int which = -1;    for(i=0;i<ft_sim->numAnalyses;i++) {        if(strcmp(ft_sim->analyses[i]->name,"options")==0) {            which = i;            break;        }    }    if(which==-1) {        fprintf(cp_err,"Warning:  statistics unsupported\n");        return(NULL);    }    if (name) {        for (i = 0; i < ft_sim->analyses[which]->numParms; i++)            if (eq(ft_sim->analyses[which]->analysisParms[i].keyword, name))                break;        if (i == ft_sim->analyses[which]->numParms)            return (NULL);        if ((*(ft_sim->askAnalysisQuest))(ckt, ft_curckt->ci_curTask,                ft_sim->analyses[which]->analysisParms[i].id, &parm,                 (IFvalue *)NULL) == -1) {            fprintf(cp_err,                 "if_getstat: Internal Error: can't get %s\n",                name);            return (NULL);        }        return (parmtovar(&parm, &(ft_sim->analyses[which]->analysisParms[i])));    } else {        for (i = 0, vars = v = NULL; i<ft_sim->analyses[which]->numParms; i++) {            if(!(ft_sim->analyses[which]->analysisParms[i].dataType&IF_ASK)) {                continue;            }            if ((*(ft_sim->askAnalysisQuest))(ckt, ft_curckt->ci_curTask,                     ft_sim->analyses[which]->analysisParms[i].id,                     &parm, (IFvalue *)NULL) == -1) {                fprintf(cp_err,                 "if_getstat: Internal Error: can't get %s\n",                    name);                return (NULL);            }            if (v) {                v->va_next = parmtovar(&parm,                         &(ft_sim->analyses[which]->analysisParms[i]));                v = v->va_next;            } else {                vars = v = parmtovar(&parm,                         &(ft_sim->analyses[which]->analysisParms[i]));             }        }        return (vars);    }}int SIMinit(frontEnd,simulator)    IFfrontEnd *frontEnd;    IFsimulator **simulator;{    return(SPIinit(frontEnd,simulator));}/* gtri - add - 12/6/90 - wbk - Fake linker into including all obj *//* modules needed for prelink *//* * Copyright (c) 1987 Thomas L. Quarles */#include "CKTdefs.h"#include "DEVdefs.h"#include "JOBdefs.h"#include "SPerror.h"#include "OPTdefs.h"extern SPICEdev ASRCinfo;extern SPICEdev VSRCinfo;extern SPICEdev ISRCinfo;extern SPICEdev URCinfo;extern SPICEdev VCVSinfo;extern SPICEdev CCVSinfo;extern SPICEdev VCCSinfo;extern SPICEdev CCCSinfo;extern SPICEdev RESinfo;extern SPICEdev TRAinfo;extern SPICEdev CAPinfo;extern SPICEdev INDinfo;extern SPICEdev MUTinfo;extern SPICEdev MOS1info;extern SPICEdev MOS2info;extern SPICEdev MOS3info;extern SPICEdev DIOinfo;extern SPICEdev BJTinfo;extern SPICEdev JFETinfo;extern SPICEdev BSIMinfo;extern SPICEdev CSWinfo;extern SPICEdev SWinfo;extern SPICEdev MESinfo;extern SPICEdev icm_poly_info;extern SPICEanalysis ACinfo;extern SPICEanalysis OPTinfo;extern SPICEanalysis DCTinfo;extern SPICEanalysis DCOinfo;extern SPICEanalysis TRANinfo;extern SPICEanalysis PZinfo;extern SPICEanalysis SENinfo;extern SPICEanalysis TFinfo;static char * specSigList[] = {    "time"};static IFparm nodeParms[] = {    IP( "nodeset",PARM_NS ,IF_REAL,"suggested initial voltage"),    IP( "ic",PARM_IC ,IF_REAL,"initial voltage"),    IP( "type",PARM_NODETYPE ,IF_INTEGER,"output type of equation")};SPICEanalysis *dummy_analInfo[] = {    &OPTinfo,    &ACinfo,    &DCTinfo,    &DCOinfo,    &TRANinfo,    &PZinfo,    &SENinfo,    &TFinfo,};SPICEdev *dummy_DEVices[] = {        &ASRCinfo,        &VSRCinfo,        &ISRCinfo,        &URCinfo,        &VCVSinfo,        &CCVSinfo,        &VCCSinfo,        &CCCSinfo,        &RESinfo,        &TRAinfo,        &CAPinfo,        &INDinfo,        &MUTinfo,        &MOS1info,        &MOS2info,        &MOS3info,        &DIOinfo,        &BJTinfo,        &JFETinfo,        &BSIMinfo,        &CSWinfo,        &MESinfo,        &SWinfo,        &icm_poly_info,};IFsimulator dummy_SIMinfo = {/* gtri - begin - change name of program to XSPICE */    "XSPICE",       /* my name */    "XSPICE circuit level simulation program",  /* more about me */    "1.0",         /* my version *//* gtri - end - change name of program to XSPICE */    CKTinit,        /* newCircuit function */    CKTdestroy,     /* deleteCircuit function */    CKTnewNode,     /* newNode function */    CKTground,      /* groundNode function */    CKTbindNode,    /* bindNode function */    CKTfndNode,     /* findNode function */    CKTinst2Node,   /* instToNode function */    CKTsetNodPm,    /* setNodeParm function */    CKTaskNodQst,   /* askNodeQuest function */    CKTdltNod,      /* deleteNode function */    CKTcrtElt,      /* newInstance function */    CKTparam,       /* setInstanceParm function */    CKTask,         /* askInstanceQuest function */    CKTfndDev,      /* findInstance funciton */    CKTdltInst,     /* deleteInstance function */    CKTmodCrt,      /* newModel function */    CKTmodParam,    /* setModelParm function */    CKTmodAsk,      /* askModelQuest function */    CKTfndMod,      /* findModel function */    CKTdltMod,      /* deleteModel function */    CKTnewTask,     /* newTask function */    CKTnewAnal,     /* newAnalysis function */    CKTsetAnalPm,   /* setAnalysisParm function */    CKTaskAnalQ,    /* askAnalysisQeust function */    CKTfndAnal,     /* findAnalysis function */    CKTfndTask,     /* findTask function */    CKTdelTask,     /* deleteTask function */    CKTdoJob,       /* doAnalyses function */    sizeof(dummy_DEVices)/sizeof(SPICEdev *),    (IFdevice**) dummy_DEVices,    sizeof(dummy_analInfo)/sizeof(SPICEanalysis *),    (IFanalysis **) dummy_analInfo,    sizeof(nodeParms)/sizeof(IFparm),    nodeParms,    sizeof(specSigList)/sizeof(char *),    specSigList,};/* gtri - end - 12/6/90 - wbk *//* gtri - evt - wbk - 5/20/91 - Add stuff for user-defined nodes *//* Define dummy struct to force inclusion of idn_digital_info for prelink */extern Evt_Udn_Info_t idn_digital_info;Evt_Udn_Info_t  *dummy_evt_udn_info[] = {    &idn_digital_info,};/* gtri - end - wbk - 5/20/91 - Add stuff for user-defined nodes */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -