CAMLprim value kern_gettimeofday(value v_unit) { struct timeval atv; microtime(&atv); return caml_copy_double(fixpt_add(fixpt_from_int(atv.tv_sec), fixpt_div(fixpt_from_int(atv.tv_usec), 10000000 * fixpt_one))); }
static void contrtemp_run(fixpt_t r) { fixpt_t dt, y, y_current; uint8_t emergency_flags; if (!contrtemp.enabled) return; if (contrtemp.emergency) return; /* Get delta-t that elapsed since last run, in seconds */ dt = fixpt_div(int_to_fixpt(timer_ms_since(&contrtemp.dt_timer)), int_to_fixpt(1000)); timer_set_now(&contrtemp.dt_timer); /* Run the PID controller */ y = pid_run(&contrtemp.pid, dt, r); debug_report_fixpt(DEBUG_PFX1("ty1"), &contrtemp.old_temp_control1, y); /* Map the requested temperature to a heater current. */ y_current = temp_to_amps(y); emergency_flags = contrcurr_get_emerg(); if (r > float_to_fixpt(CONTRTEMP_POSLIM)) { /* The measured temperature is higher than the maximum. * We need to avoid damage. * Disable current by requesting an emergency in * the current controller. */ emergency_flags |= CONTRCURR_EMERG_HIGH_TEMP; y_current = float_to_fixpt(CONTRCURR_NEGLIM); } else { emergency_flags &= (uint8_t)~CONTRCURR_EMERG_HIGH_TEMP; } contrcurr_set_emerg(emergency_flags); debug_report_fixpt(DEBUG_PFX1("ty2"), &contrtemp.old_temp_control2, y_current); /* Set the current controller setpoint to the requested current. */ contrcurr_set_setpoint(y_current); }