// Automatically generated C++ file on Tue Oct 1 17:16:09 2024 // // To build with Digital Mars C++ Compiler: // // dmc -mn -WD steste_1.cpp kernel32.lib #include extern "C" __declspec(dllexport) int (*Display)(const char *format, ...) = 0; // works like printf() extern "C" __declspec(dllexport) const double *DegreesC = 0; // pointer to current circuit temperature 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 DllMain() must exist and return 1 for a process to load the .DLL // See https://docs.microsoft.com/en-us/windows/win32/dlls/dllmain for more information. int __stdcall DllMain(void *module, unsigned int reason, void *reserved) { return 1; } void bzero(void *ptr, unsigned int count) { unsigned char *first = (unsigned char *) ptr; unsigned char *last = first + count; while(first < last) *first++ = '\0'; } // #undef pin names lest they collide with names in any header file(s) you might include. #undef in #undef clk #undef ctrl #undef clkn #undef ref struct sSTESTE_1 { // declare the structure here double lastT; unsigned int cnt; bool clk_n1; unsigned long long int cnti; double pwr; double pwr_n1; double iref; // technically, we need initialize only non-zero data members sSTESTE_1() : lastT(0.0), cnt(0), clk_n1(0), cnti(0), pwr(0.0), pwr_n1(0.0), iref(2.5){}; }; extern "C" __declspec(dllexport) void steste_1(struct sSTESTE_1 **opaque, double t, union uData *data) { double in = data[0].d ; // input bool clk = data[1].b ; // input unsigned int clkn = data[2].ui; // input bool &ctrl = data[3].b ; // output double &ref = data[4].d ; // output if(!*opaque) { // *opaque = (struct sSTESTE_1 *) malloc(sizeof(struct sSTESTE_1)); // bzero(*opaque, sizeof(struct sSTESTE_1)); *opaque = new sSTESTE_1(); Display("inst->iref = %f", (*opaque)->iref); } struct sSTESTE_1 *inst = *opaque; // Implement module evaluation code here: if(clk && !(inst->clk_n1) &&((inst->cnti)cnti=inst->cnti+1; ref=(inst->iref); } else if (clk && !(inst->clk_n1) && (inst->cnti)==clkn) // clkn { inst->cnti=0; inst->pwr=in; if (((inst->pwr)-(inst->pwr_n1))>5) { ref=(inst->iref)+0.2; ctrl=1; } else { ref=(inst->iref)-0.2; ctrl=0; } inst->pwr_n1=inst->pwr; inst->iref=ref; } inst->clk_n1=clk; } extern "C" __declspec(dllexport) void Destroy(struct sSTESTE_1 *inst) { // free(inst); delete inst; }