diff --git a/examples/degradation/Inverter_degmon_new_2.cir b/examples/degradation/Inverter_degmon_new_2.cir index 51870e30e..e85d0f162 100644 --- a/examples/degradation/Inverter_degmon_new_2.cir +++ b/examples/degradation/Inverter_degmon_new_2.cir @@ -32,11 +32,12 @@ pre_osdi ../lib/ngspice/psp103_nqs.osdi pre_osdi ../lib/ngspice/psp103.osdi run rusage +plot xnot1.mon1 xnot2.mon1 xnot3.mon1 +plot in out+2 degsim run *set nolegend set xbrushwidth=3 -plot xnot1.mon1 xnot2.mon1 xnot3.mon1 plot in out+2 .endc diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 79a5cc016..9fbb28a7f 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -65,7 +65,7 @@ extern void com_optran(wordlist * wl); extern void tprint(struct card *deck); static bool wantdegsim = FALSE; -extern int preparedegsim(struct card* deck); +extern int prepare_degsim(struct card* deck); //void inp_source_recent(void); //void inp_mc_free(void); @@ -1098,7 +1098,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) extra degradation elements. */ if (wantdegsim && newcompat.de) { wantdegsim = FALSE; - preparedegsim(deck); + prepare_degsim(deck); } /* Parsing the circuit 5. diff --git a/src/frontend/inpdeg.c b/src/frontend/inpdeg.c index 605f29d0c..0b0453961 100644 --- a/src/frontend/inpdeg.c +++ b/src/frontend/inpdeg.c @@ -15,7 +15,7 @@ License: Modified BSD #include "inpcom.h" -int preparedegsim(struct card* deck); +int prepare_degsim(struct card* deck); /* maximum number of model parameters */ #define DEGPARAMAX 64 @@ -302,7 +302,53 @@ int remsqrbra(struct card* deck) { /* Remove the degradation monitors. Add current measurement, delta_vg and current source. Use the data retrieved from degdatahash */ -int preparedegsim(struct card* deck) { +int prepare_degsim(struct card* deck) { + struct card* prevcard = deck, *ldeck; + + if (!deck) + return 1; + + /* skip the title line */ + for (ldeck = deck->nextcard; ldeck; ldeck = ldeck->nextcard) { + char* line = ldeck->line; + + if (*line == '*') { + continue; + } + + /* remove the remnants of the first run */ + if (ciprefix(".model", line) && search_plain_identifier(line, "degmon")) { + double *result; + char* insttoken; + struct card* nextdeck = ldeck->nextcard; + char* prevline = prevcard->line; + if (nextdeck) { + char* nextline = nextdeck->line; + if (*nextline == 'a' && strstr(nextline, "degmon")) { + *nextline = '*'; + } + } + /* get the device instance line */ + insttoken = gettok_instance(&prevline); + result = (double*)nghash_find(degdatahash, insttoken); + if (result) { + fprintf(stdout, "Instance %s, Result: %e, %e, %e\n", insttoken, result[0], result[1], result[2]); + } + else + fprintf(stdout, "Instance %s not found in hash table\n", insttoken); + + tfree(insttoken); + + *line = '*'; + } + prevcard = ldeck; + } fprintf(stdout, "Note: degradation simulation prepared.\n"); return 0; } + +/* clear memory */ +int clear_degsim (void){ + /* delete the hashtables */ + return 0; +} diff --git a/src/xspice/icm/xtradev/degmonitor/cfunc.mod b/src/xspice/icm/xtradev/degmonitor/cfunc.mod index dc0dbd11c..18a0a66c0 100644 --- a/src/xspice/icm/xtradev/degmonitor/cfunc.mod +++ b/src/xspice/icm/xtradev/degmonitor/cfunc.mod @@ -92,7 +92,7 @@ typedef struct { double L2[3]; /* degradation model parameter */ double n[3]; /* degradation model parameter */ double c[3]; /* degradation model parameter */ - double result[3]; /* degradation simulation result */ + double *result; /* degradation simulation result */ char *parentname; /* name of parent device for degmon */ } degLocal_Data_t; @@ -110,7 +110,8 @@ cm_degmon_callback(ARGS, Mif_Callback_Reason_t reason) if (loc == (degLocal_Data_t *) NULL) { break; } - + /* loc->result) should not be freed here, as is used in the second run. + Free it via the hash table.*/ free(loc); STATIC_VAR(locdata) = NULL; @@ -343,6 +344,9 @@ void cm_degmon(ARGS) /* structure holding parms, cm_cexit(1); } + double *result = (double*)malloc(3 * sizeof(double)); + loc->result = result; + /* use agemods as input to set the agemodel model parameters, e.g. loc->A[3] */ err = getdata(agemods, loc, devmod); @@ -466,6 +470,8 @@ void cm_degmon(ARGS) /* structure holding parms, /* save the degradation data for this instance */ if (T(0) > 0.99999 * tsim) { nghash_insert(glohash, loc->parentname, loc->result); + cm_message_printf("instance %s, data: %e %e %e\n", loc->parentname, loc->result[0], + loc->result[1], loc->result[2]); } } }