Browse Source

Update for the caller to invoke shared ngspice

path to shared ngspice also via command line parameter
add some alter statement after bg_halt
some smaller fixes to outputs, messages upon exit etc.
pre-master-46
Holger Vogt 5 years ago
parent
commit
d9a140c213
  1. 2
      visualc/ng_shared_xspice_v/examples/adder_mos.cir
  2. 40
      visualc/ng_shared_xspice_v/src/main_xspice.c

2
visualc/ng_shared_xspice_v/examples/adder_mos.cir

@ -55,7 +55,7 @@ X1 1 2 3 4 5 6 7 8 9 10 11 12 0 13 99 FOURBIT
.option noinit acct
.TRAN 500p 6400NS
* save inputs
.save V(1) V(2) V(3) V(4) V(5) V(6) V(7) V(8)
* .save V(1) V(2) V(3) V(4) V(5) V(6) V(7) V(8)
* use BSIM3 model with default parameters
.model n1 nmos level=49 version=3.3.0

40
visualc/ng_shared_xspice_v/src/main_xspice.c

@ -111,12 +111,12 @@ void * ngdllhandle = NULL;
pthread_t mainthread;
#endif // _MSC_VER
int main()
int main(int argc, char* argv[])
{
char *errmsg = NULL, *loadstring, *curplot, *vecname;
char *errmsg = NULL, *loadstring = NULL, *curplot, *vecname;
int *ret, i;
char **vecarray;
printf("\n");
printf("****************************\n");
printf("** ngspice shared start **\n");
printf("****************************\n");
@ -124,7 +124,17 @@ int main()
#ifndef _MSC_VER
mainthread = pthread_self();
#endif // _MSC_VER
printf("ng_shared_test_v.exe found in %s\n", argv[0]);
printf("Load ngspice.dll\n");
/* path to shared ngspice via command line */
if (argc > 1) {
loadstring = argv[1];
ngdllhandle = dlopen(loadstring, RTLD_NOW);
}
/* try some standard paths */
if (!ngdllhandle) {
#ifdef __CYGWIN__
loadstring = "/cygdrive/c/cygwin/usr/local/bin/cygngspice-0.dll";
#elif _MSC_VER
@ -135,6 +145,7 @@ int main()
loadstring = "libngspice.so";
#endif
ngdllhandle = dlopen(loadstring, RTLD_NOW);
}
errmsg = dlerror();
if (errmsg)
printf("%s\n", errmsg);
@ -142,7 +153,11 @@ int main()
printf("ngspice.dll loaded\n");
else {
printf("ngspice.dll not loaded !\n");
// exit(1);
/* Delay closing the Windows console */
#if defined(__MINGW32__) || defined(_MSC_VER)
Sleep(3000);
#endif
exit(1);
}
ngSpice_Init_handle = dlsym(ngdllhandle, "ngSpice_Init");
@ -222,7 +237,7 @@ int main()
dlclose(ngdllhandle);
printf("ngspice.dll unloaded\n\n");
ngdllhandle = NULL;
return 0;
return 1;
}
/* simulate for 500 milli seconds or until simulation has finished */
@ -403,6 +418,8 @@ test2:
usleep(1000000);
#endif
}
ret = ((int * (*)(char*)) ngSpice_Command_handle)("alter VCC = 5");
ret = ((int * (*)(char*)) ngSpice_Command_handle)("bg_resume");
/* wait for 1s while simulation continues */
@ -526,6 +543,11 @@ ng_exit(int exitstatus, bool immediate, bool quitexit, int ident, void* userdata
will_unload = true;
}
/* Delay closing the Windows console */
#if defined(__MINGW32__) || defined(_MSC_VER)
Sleep(3000);
#endif
return exitstatus;
}
@ -537,11 +559,11 @@ ng_data(pvecvaluesall vdata, int numvecs, int ident, void* userdata)
double tscale;
static double olddat = 0.0;
static int i, j;
char *vecname = "V(6)";
char *vecname = "V(12)";
if (firsttime) {
for (i = 0; i < numvecs; i++) {
/* We have a look at vector V(6) from adder_mos.cir.
/* We have a look at vector V(12) from adder_mos.cir.
Get the index i */
if (cieq(vdata->vecsa[i]->name, vecname))
break;
@ -558,8 +580,8 @@ ng_data(pvecvaluesall vdata, int numvecs, int ident, void* userdata)
}
if ((testnumber == 2) && (i < numvecs)){
v2dat = vdata->vecsa[i]->creal;
/* print output value only if it has changed */
if (olddat != v2dat) {
/* print output value only if it has changed by more than 10 mV */
if ((olddat + 0.01 < v2dat) || (olddat - 0.01 > v2dat)) {
tscale = vdata->vecsa[j]->creal;
printf("real value of vector %s is %e at %e\n", vdata->vecsa[i]->name, v2dat, tscale);
}

Loading…
Cancel
Save