void huanyang_rtc_callback() {
- if (ha.last && HUANYANG_TIMEOUT < rtc_get_time() - ha.last) {
+ if (ha.last && rtc_expired(ha.last + HUANYANG_TIMEOUT)) {
if (ha.retry < HUANYANG_RETRIES) _retry_command();
else {
if (ha.debug) printf_P(PSTR("huanyang: timedout\n"));
for (int motor = 0; motor < MOTORS; motor++)
// Deenergize motor if disabled, in error or after timeout when not holding
if (motors[motor].power_mode == MOTOR_DISABLED || motor_error(motor) ||
- motors[motor].timeout < rtc_get_time())
+ rtc_expired(motors[motor].timeout))
_deenergize(motor);
return STAT_OK;
const float time = MIN_SEGMENT_TIME; // In minutes
const float maxDeltaV = JOG_ACCELERATION * time;
- if (cal.wait <= rtc_get_time())
+ if (rtc_expired(cal.wait))
switch (cal.state) {
case CAL_START: {
cal.axis = motor_get_axis(cal.motor);
uint32_t rtc_get_time() {return ticks;}
+
+
+bool rtc_expired(uint32_t t) {
+ return 0 <= (int32_t)(ticks - t);
+}
#include <stdint.h>
+#include <stdbool.h>
#define RTC_MILLISECONDS 10 // interrupt on every 10 RTC ticks (~10 ms)
void rtc_init(); // initialize and start general timer
uint32_t rtc_get_time();
+int32_t rtc_diff(uint32_t t);
+bool rtc_expired(uint32_t t);