static void synctimer_test(void) { size_t i; LIST_INIT(&synctimer_list); for (i = 0; i < countof(synctimer_timers); ++i) { Timer *timer = &synctimer_timers[i]; timer_setDelay(timer, ms_to_ticks(test_delays[i])); timer_setSoftint(timer, synctimer_test_hook, (iptr_t)timer); synctimer_add(timer, &synctimer_list); } int secs = 0; mtime_t start_time = ticks_to_ms(timer_clock()); mtime_t now; while (secs <= 10) { now = ticks_to_ms(timer_clock()); synctimer_poll(&synctimer_list); if (now - start_time >= 1000) { ++secs; start_time += 1000; kprintf("seconds = %d, ticks=%lu\n", secs, (unsigned long)now); } wdt_reset(); } for (i = 0; i < countof(synctimer_timers); ++i) { synctimer_abort(&synctimer_timers[i]); } }
void controlLoop(void) { static uint8_t i = 0; uint8_t ch; // The currently selected channel // Keep quite the dog at each iteration WATCHDOG_RESET(); // Set device status led if (CalibrationDone()) LED_ON(); else LED_SWITCH(); // Schedule timer activities (SMS and Console checking) synctimer_poll(&timers_lst); // Checking for pending signals to serve checkSignals(); // Select Channel to sample and get P measure ch = sampleChannel(); if (ch==MAX_CHANNELS) { // No channels enabled... avoid calibration/monitoring if (chCalib) { DB(LOG_INFO("Idle (%s, Fault: 0x%04X, Cal: 0x%04X) %c\r", controlMonitoringEnabled() ? "Mon" : "Dis", chSpoiled, chCalib, progress[i++%4])); } else { DB(LOG_INFO("Idle (%s, Fault: 0x%04X) %c\r", controlMonitoringEnabled() ? "Mon" : "Dis", chSpoiled, progress[i++%4])); } DELAY(500); return; } if (needCalibration(ch)) { calibrate(ch); // Check if all channels has been calibrated // So that we can notify calibration completion (just one time) if (!CalibrationDone()) return; // Notify calibration completion LOG_INFO("\n\nCALIBRATION COMPLETED\r\n\n"); LED_ON(); notifyCalibrationCompleted(); return; } // Monitor the current channel if (controlMonitoringEnabled()) monitor(ch); }