Skip to content

Instantly share code, notes, and snippets.

@suarezvictor
Created August 26, 2023 17:50
Show Gist options
  • Save suarezvictor/d51bcc7cf10a3e6064a80b29910de93e to your computer and use it in GitHub Desktop.
Save suarezvictor/d51bcc7cf10a3e6064a80b29910de93e to your computer and use it in GitHub Desktop.
QSPICE C++ test
// Automatically generated C++ file on Sat Aug 26 14:20:23 2023
//
// To build with Digital Mars C++ Compiler:
//
// dmc -mn -WD test0_x1.cpp kernel32.lib
#include <stdio.h>
#include <malloc.h>
#include <stdarg.h>
#include <time.h>
union uData
{
bool b;
char c;
unsigned char uc;
short s;
unsigned short us;
int i;
unsigned int ui;
float f;
double d;
long long int i64;
unsigned long long int ui64;
char *str;
unsigned char *bytes;
};
int __stdcall DllMain(void *module, unsigned int reason, void *reserved) { return 1; }
void display(const char *fmt, ...)
{ // for diagnostic print statements
//msleep(30);
//fflush(stdout);
va_list args = { 0 };
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
fflush(stdout);
//msleep(30);
}
// #undef pin names lest they collide with names in any header file(s) you might include.
#undef in
#undef out
//default simulation: 5ms, sine voltage over 1Kohm
extern "C" __declspec(dllexport) void test0_x1(void **opaque, double t, union uData *data)
{
float in = data[0].f; // input
float &out = data[1].f; // output
out = in*in;
static FILE *f = fopen(__FILE__ ".log", "wb"); //write log file on same folder than the schematics and dll
static double t0 = 0;
float dt = t - t0; //4.88 us for the 1 KHz (2.5us for 10Khz, about .2-.7 us for 100KHz)
t0 = t;
static int i;
if(++i == 100)
{
i = 0;
fprintf(f, "t: %g, dt = %g, in %g, out %g\n", t, dt, in, out);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment