static void alarmCallback(uint32_t, void*) { std::unique_lock<priority_recursive_mutex> sync(notifierMutex); int32_t status = 0; uint64_t currentTime = 0; // the hardware disables itself after each alarm closestTrigger = UINT64_MAX; // process all notifiers Notifier *notifier = notifiers; while (notifier) { if (notifier->triggerTime != UINT64_MAX) { if (currentTime == 0) currentTime = getFPGATime(&status); if (notifier->triggerTime < currentTime) { notifier->triggerTime = UINT64_MAX; auto process = notifier->process; auto param = notifier->param; sync.unlock(); process(currentTime, param); sync.lock(); } else if (notifier->triggerTime < closestTrigger) { updateNotifierAlarm(notifier, notifier->triggerTime, &status); } } notifier = notifier->next; } }
/** * Read the microsecond-resolution timer on the FPGA. * * @return The current time in microseconds according to the FPGA (since FPGA * reset). */ uint64_t GetFPGATime() { int32_t status = 0; uint64_t time = getFPGATime(&status); wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status)); return time; }