static IRAM void mgos_mg_poll_cb(void *arg) { mgos_ints_disable(); s_mg_polls_in_flight--; mgos_ints_enable(); int timeout_ms = 0; if (mongoose_poll(0) == 0) { /* Nothing is happening now, see when next timer is due. */ double min_timer = mg_mgr_min_timer(mgos_get_mgr()); if (min_timer > 0) { /* Note: timeout_ms can get negative if a timer is past due. That's ok. */ timeout_ms = (int) ((min_timer - mg_time()) * 1000.0); if (timeout_ms < 0) { timeout_ms = 0; /* Now */ } else if (timeout_ms > MGOS_MONGOOSE_MAX_POLL_SLEEP_MS) { timeout_ms = MGOS_MONGOOSE_MAX_POLL_SLEEP_MS; } } else { timeout_ms = MGOS_MONGOOSE_MAX_POLL_SLEEP_MS; } } else { /* Things are happening, we need another poll ASAP. */ } if (timeout_ms == 0) { mongoose_schedule_poll(false /* from_isr */); } else { os_timer_disarm(&s_mg_poll_tmr); /* We set repeat = true in case things get stuck for any reason. */ os_timer_arm(&s_mg_poll_tmr, timeout_ms, 1 /* repeat */); } (void) arg; }
void mongoose_schedule_poll(bool from_isr) { (void) from_isr; mg_broadcast(mgos_get_mgr(), dummy_handler, NULL, 0); }