// Automatically generated C++ file on Thu May 1 00:02:13 2025 // // To build with Digital Mars C++ Compiler: // // dmc -mn -WD modulation.cpp kernel32.lib #include 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 fsw_ref #undef VM #undef delay struct sMODULATION { // declare the structure here float timeprev; float tdiff; }; extern "C" __declspec(dllexport) void modulation(struct sMODULATION **opaque, double t, union uData *data) { float fsw_ref = data[0].f; // input float delay = data[1].f; // input double fresLC = data[2].d; // input parameter float &VM = data[3].f; // output if(!*opaque) { *opaque = (struct sMODULATION *) malloc(sizeof(struct sMODULATION)); bzero(*opaque, sizeof(struct sMODULATION)); } struct sMODULATION *inst = *opaque; // Implement module evaluation code here: static float switching_frequency = 135e3; const float SAFETY_MARGIN = 1.2; //static float timeprev = 0, tdiff; if (t < delay) { inst->timeprev = t; VM = 2.5; return; } inst->tdiff = t - inst->timeprev; VM += inst->tdiff * switching_frequency;; if (VM >= 1.0) { VM -= 1.0; switching_frequency = fsw_ref; } inst->timeprev = t; } extern "C" __declspec(dllexport) void Destroy(struct sMODULATION *inst) { free(inst); }