// Automatically generated C++ file on Sat Dec 21 21:11:43 2024 // // To build with Digital Mars C++ Compiler: // // dmc -mn -WD set_frequency_limitation.cpp kernel32.lib 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; } // #undef pin names lest they collide with names in any header file(s) you might include. #undef set1 #undef set2 extern "C" __declspec(dllexport) void set_frequency_limitation(void **opaque, double t, union uData *data) { bool set1 = data[0].b; // input bool &set2 = data[1].b; // output // Static variables to track previous states static bool prev_set1 = false; // Previous value of set1 static double last_rising_edge_time = 0.0; // Time when set2 was set high static bool set2_high = false; // Flag to check if set2 has been set high const double THRESHOLD_TIME = 30e-9; // 30ns in seconds // Detect rising edge of set1 (when set1 transitions from low to high) if (set1 && !prev_set1) { // Rising edge detected, set set2 high set2 = true; set2_high = true; last_rising_edge_time = t; // Record the time when set2 was set high } // If set2 was set high and 30ns have passed, check set1 state if (set2_high && (t - last_rising_edge_time) >= THRESHOLD_TIME) { if (!set1) { // If set1 is low after 30ns, set set2 low set2 = false; } set2_high = false; // Reset flag } // Update previous set1 state prev_set1 = set1; }