diff --git a/simulator/data_recorder.c b/simulator/data_recorder.c index 0daeafd..41475f8 100644 --- a/simulator/data_recorder.c +++ b/simulator/data_recorder.c @@ -18,7 +18,7 @@ static int32_t values[MAX_PINS]; ///< Pin and value states static int pin_count; ///< Number of pins we emit static void emit_log_data(void); -static void recorder_close(int code, void*x ) { +static void recorder_close(void) { if (!file) return; // force last line to emit emit_log_data(); @@ -42,7 +42,7 @@ void recorder_init(const char* filename) { fprintf(file, "#\n"); fflush(file); - on_exit(recorder_close, NULL); + atexit((void*)recorder_close); } void add_trace_var(const char* name, int pin) { diff --git a/simulator/timer_ext.c b/simulator/timer_ext.c index 25858b3..f7f05e1 100644 --- a/simulator/timer_ext.c +++ b/simulator/timer_ext.c @@ -5,7 +5,13 @@ #include "dda_queue.h" #include "timer.h" #include "simulator.h" -#include +#ifdef __MACH__ + #include + #define CLOCK_REALTIME 0 + #define CLOCK_MONOTONIC 0 +#else + #include +#endif #include // printf #include // usleep @@ -28,6 +34,21 @@ static volatile uint8_t timer_reason; // Who scheduled this timer static uint64_t ticks; static uint32_t warpTarget; +#ifdef __MACH__ +int clock_gettime(int clk_id, struct timespec *t) { + mach_timebase_info_data_t timebase; + mach_timebase_info(&timebase); + uint64_t time; + + time = mach_absolute_time(); + double nseconds = ((double)time * (double)timebase.numer)/((double)timebase.denom); + double seconds = ((double)time * (double)timebase.numer)/((double)timebase.denom * 1e9); + t->tv_sec = seconds; + t->tv_nsec = nseconds; + return 0; +} +#endif + static uint64_t now_ns(void) { struct timespec tv;