diff --git a/src/include/ngspice/mifcmdat.h b/src/include/ngspice/mifcmdat.h index 00504f5a2..7afa54c0f 100644 --- a/src/include/ngspice/mifcmdat.h +++ b/src/include/ngspice/mifcmdat.h @@ -406,6 +406,12 @@ struct Mif_Private { Mif_Inst_Var_Data_t **inst_var; /* Information about each inst variable */ Mif_Callback_t *callback; /* Callback function */ + // Rude hack here! + + CKTcircuit *ckt; + struct SPICEdev **sdevs; + struct IFdevice **ifdevs; + unsigned int devices; /* Size of device table in *ckt. */ }; diff --git a/src/xspice/evt/evtload.c b/src/xspice/evt/evtload.c index 35ee44716..293ebc75f 100644 --- a/src/xspice/evt/evtload.c +++ b/src/xspice/evt/evtload.c @@ -344,7 +344,7 @@ static void EVTcreate_state( state_data = ckt->evt->data.state; /* Exit immediately if no states on this instance */ - if(state_data->desc[inst_index] == NULL) + if (!state_data || state_data->desc[inst_index] == NULL) return; /* Get size of state block to be allocated */ diff --git a/src/xspice/icm/xtradev/modpath.lst b/src/xspice/icm/xtradev/modpath.lst index ec7a2f87f..231b14913 100644 --- a/src/xspice/icm/xtradev/modpath.lst +++ b/src/xspice/icm/xtradev/modpath.lst @@ -10,3 +10,4 @@ zener memristor sidiode pswitch +spider diff --git a/src/xspice/icm/xtradev/spider/cfunc.mod b/src/xspice/icm/xtradev/spider/cfunc.mod new file mode 100644 index 000000000..4f6535f02 --- /dev/null +++ b/src/xspice/icm/xtradev/spider/cfunc.mod @@ -0,0 +1,89 @@ +#include + +#include "ngspice/ifsim.h" +#include "ngspice/devdefs.h" +#include "ngspice/gendefs.h" + +/* Modified copy from spiceif.c. FIX ME! */ + +static IFparm *parmlookup(IFdevice *dev, char *param) +{ + IFparm *p; + int i; + + if (dev->numInstanceParms) { + for (i = 0; i < *(dev->numInstanceParms); i++) { + p = dev->instanceParms + i; + if ((p->dataType & IF_SET) && !strcmp(p->keyword, param)) { + while ((p->dataType & IF_REDUNDANT) && i > 0) + i--; + if ((p->dataType & IF_VARTYPES) != IF_REAL) + return NULL; + return p; + } + } + } + + if (dev->numModelParms) { + for (i = 0; i < *(dev->numModelParms); i++) { + p = dev->modelParms + i; + if ((p->dataType & IF_SET) && !strcmp(p->keyword, param)) { + while ((p->dataType & IF_REDUNDANT) && i > 0) + i--; + if ((p->dataType & IF_VARTYPES) != IF_REAL) + return NULL; + return p; + } + } + } + return NULL; +} + +void ucm_spider(ARGS) +{ + CKTcircuit *ckt; + SPICEdev *sdev; + IFdevice *ifdev; + GENmodel *mod; + GENinstance *dev; + IFparm *p; + char *what; + IFvalue nval; + double v; + int i; + + if (INIT) { +// cm_irreversible(1); + return; + } + ckt = mif_private->ckt; + what = PARAM(parameter); + nval.rValue = INPUT(value); + + if (!strcmp(what, "temp")) { + /* Set the overall circuit temperature. */ + + ckt->CKTtemp = nval.rValue; + } + + for (i = 0; i < mif_private->devices; ++i) { + ifdev = mif_private->ifdevs[i]; + p = parmlookup(ifdev, what); // Cache me! + if (!p) + continue; + sdev = mif_private->sdevs[i]; + for (mod = ckt->CKThead[i]; mod; mod = mod->GENnextModel) { + for (dev = mod->GENinstances; dev; dev = dev->GENnextInstance) { + /* Try setting the named parameter on this device. + * Modelled on cktparam.c. + */ + + sdev->DEVparam(p->id, &nval, dev, NULL); + } + } + } +} + + + + diff --git a/src/xspice/icm/xtradev/spider/ifspec.ifs b/src/xspice/icm/xtradev/spider/ifspec.ifs new file mode 100644 index 000000000..e95565dcd --- /dev/null +++ b/src/xspice/icm/xtradev/spider/ifspec.ifs @@ -0,0 +1,30 @@ +/* Hack XSPICE device allow altering arbirary parameter during simulation. */ + +NAME_TABLE: + +Spice_Model_Name: spider +C_Function_Name: ucm_spider +Description: "Parameter tweaker" + +PORT_TABLE: + +Port_Name: value +Description: "input" +Direction: in +Default_Type: v +Allowed_Types: [v, vd, i, id] +Vector: no +Vector_Bounds: - +Null_Allowed: no + + +PARAMETER_TABLE: + +Parameter_Name: parameter +Description: "Name of parameter to be varied" +Data_Type: string +Default_Value: - +Limits: - +Vector: no +Vector_Bounds: - +Null_Allowed: no diff --git a/src/xspice/mif/mifload.c b/src/xspice/mif/mifload.c index cc6c7c016..2caeecb7d 100644 --- a/src/xspice/mif/mifload.c +++ b/src/xspice/mif/mifload.c @@ -50,6 +50,7 @@ NON-STANDARD FEATURES #include "ngspice/cktdefs.h" #include "ngspice/devdefs.h" #include "ngspice/sperror.h" +#include "ngspice/fteext.h" #include "ngspice/evt.h" @@ -173,6 +174,11 @@ MIFload( /* Setup the circuit data in the structure to be passed to the code models */ /* *********************************************************************** */ + cm_data.ckt = ckt; + cm_data.sdevs = DEVices; + cm_data.ifdevs = ft_sim->devices; + cm_data.devices = ft_sim->numDevices; + /* anal_init is set if this is the first iteration at any step in */ /* an analysis */ if(!(ckt->CKTmode & MODEINITFLOAT))