mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal,wpilib] Rename FPGA clock to monotonic clock (#8672)
- Remove status return from HAL level (clock getting should never fail) - Remove 32-bit timestamp expand function - Make monotonic_clock.hpp (formerly fpga_clock.hpp) header-only and move to root hal include directory
This commit is contained in:
@@ -71,11 +71,11 @@ public final class HALUtil extends JNIWrapper {
|
||||
public static native int getTeamNumber();
|
||||
|
||||
/**
|
||||
* Reads the microsecond-resolution timer on the FPGA.
|
||||
* Reads the microsecond-resolution monotonic timer.
|
||||
*
|
||||
* @return The current time in microseconds according to the FPGA (since FPGA reset).
|
||||
* @return The current monotonic time in microseconds.
|
||||
*/
|
||||
public static native long getFPGATime();
|
||||
public static native long getMonotonicTime();
|
||||
|
||||
/**
|
||||
* Returns the runtime type of the HAL.
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "wpi/hal/cpp/fpga_clock.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
|
||||
#include "wpi/hal/HAL.h"
|
||||
#include "wpi/util/print.hpp"
|
||||
|
||||
namespace wpi::hal {
|
||||
const fpga_clock::time_point fpga_clock::min_time =
|
||||
fpga_clock::time_point(fpga_clock::duration(
|
||||
std::numeric_limits<fpga_clock::duration::rep>::min()));
|
||||
|
||||
fpga_clock::time_point fpga_clock::now() noexcept {
|
||||
int32_t status = 0;
|
||||
uint64_t currentTime = HAL_GetFPGATime(&status);
|
||||
if (status != 0) {
|
||||
wpi::util::print(
|
||||
stderr,
|
||||
"Call to HAL_GetFPGATime failed in fpga_clock::now() with status {}. "
|
||||
"Initialization might have failed. Time will not be correct\n",
|
||||
status);
|
||||
std::fflush(stderr);
|
||||
return epoch();
|
||||
}
|
||||
return time_point(std::chrono::microseconds(currentTime));
|
||||
}
|
||||
} // namespace wpi::hal
|
||||
@@ -473,17 +473,14 @@ Java_org_wpilib_hardware_hal_HALUtil_getTeamNumber
|
||||
|
||||
/*
|
||||
* Class: org_wpilib_hardware_hal_HALUtil
|
||||
* Method: getFPGATime
|
||||
* Method: getMonotonicTime
|
||||
* Signature: ()J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_org_wpilib_hardware_hal_HALUtil_getFPGATime
|
||||
Java_org_wpilib_hardware_hal_HALUtil_getMonotonicTime
|
||||
(JNIEnv* env, jclass)
|
||||
{
|
||||
int32_t status = 0;
|
||||
jlong returnValue = HAL_GetFPGATime(&status);
|
||||
CheckStatus(env, status);
|
||||
return returnValue;
|
||||
return HAL_GetMonotonicTime();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -111,29 +111,11 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status);
|
||||
int32_t HAL_GetCommsDisableCount(int32_t* status);
|
||||
|
||||
/**
|
||||
* Reads the microsecond-resolution timer on the FPGA.
|
||||
* Reads the microsecond-resolution monotonic timer.
|
||||
*
|
||||
* @param[out] status the error code, or 0 for success
|
||||
* @return The current time in microseconds according to the FPGA (since FPGA
|
||||
* reset).
|
||||
* @return The current monotonic time in microseconds.
|
||||
*/
|
||||
uint64_t HAL_GetFPGATime(int32_t* status);
|
||||
|
||||
/**
|
||||
* Given an 32 bit FPGA time, expand it to the nearest likely 64 bit FPGA time.
|
||||
*
|
||||
* Note: This is making the assumption that the timestamp being converted is
|
||||
* always in the past. If you call this with a future timestamp, it probably
|
||||
* will make it in the past. If you wait over 70 minutes between capturing the
|
||||
* bottom 32 bits of the timestamp and expanding it, you will be off by
|
||||
* multiples of 1<<32 microseconds.
|
||||
*
|
||||
* @param[in] unexpandedLower 32 bit FPGA time
|
||||
* @param[out] status the error code, or 0 for success
|
||||
* @return The current time in microseconds according to the FPGA (since FPGA
|
||||
* reset) as a 64 bit number.
|
||||
*/
|
||||
uint64_t HAL_ExpandFPGATime(uint32_t unexpandedLower, int32_t* status);
|
||||
uint64_t HAL_GetMonotonicTime(void);
|
||||
|
||||
/**
|
||||
* Gets the current state of the Robot Signal Light (RSL).
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
/** WPILib Hardware Abstraction Layer (HAL) namespace */
|
||||
namespace wpi::hal {
|
||||
|
||||
/**
|
||||
* A std::chrono compatible wrapper around the FPGA Timer.
|
||||
*/
|
||||
class fpga_clock {
|
||||
public:
|
||||
using rep = std::chrono::microseconds::rep;
|
||||
using period = std::chrono::microseconds::period;
|
||||
using duration = std::chrono::microseconds;
|
||||
using time_point = std::chrono::time_point<fpga_clock>;
|
||||
|
||||
static fpga_clock::time_point now() noexcept;
|
||||
static constexpr bool is_steady = true;
|
||||
|
||||
static fpga_clock::time_point epoch() noexcept { return time_point(zero()); }
|
||||
|
||||
static fpga_clock::duration zero() noexcept { return duration(0); }
|
||||
|
||||
static const time_point min_time;
|
||||
};
|
||||
} // namespace wpi::hal
|
||||
38
hal/src/main/native/include/wpi/hal/monotonic_clock.hpp
Normal file
38
hal/src/main/native/include/wpi/hal/monotonic_clock.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <limits>
|
||||
|
||||
#include "wpi/hal/HAL.h"
|
||||
|
||||
/** WPILib Hardware Abstraction Layer (HAL) namespace */
|
||||
namespace wpi::hal {
|
||||
|
||||
/**
|
||||
* A std::chrono compatible wrapper around the HAL monotonic timer.
|
||||
*/
|
||||
class monotonic_clock {
|
||||
public:
|
||||
using rep = std::chrono::microseconds::rep;
|
||||
using period = std::chrono::microseconds::period;
|
||||
using duration = std::chrono::microseconds;
|
||||
using time_point = std::chrono::time_point<monotonic_clock>;
|
||||
|
||||
static time_point now() noexcept {
|
||||
uint64_t currentTime = HAL_GetMonotonicTime();
|
||||
return time_point(std::chrono::microseconds(currentTime));
|
||||
}
|
||||
static constexpr bool is_steady = true;
|
||||
|
||||
static time_point epoch() noexcept { return time_point(zero()); }
|
||||
|
||||
static duration zero() noexcept { return duration(0); }
|
||||
|
||||
static constexpr time_point min_time =
|
||||
time_point(duration(std::numeric_limits<duration::rep>::min()));
|
||||
};
|
||||
} // namespace wpi::hal
|
||||
@@ -75,7 +75,7 @@ void HAL_SetAlertActive(HAL_AlertHandle alertHandle, HAL_Bool active,
|
||||
// Already active, do nothing (avoids cost of getting time)
|
||||
return;
|
||||
}
|
||||
int64_t now = HAL_GetFPGATime(status);
|
||||
int64_t now = HAL_GetMonotonicTime();
|
||||
int64_t expected = 0;
|
||||
// use compare-exchange to avoid potential race
|
||||
alert->activeStartTime.compare_exchange_strong(expected, now);
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "mockdata/DriverStationDataInternal.hpp"
|
||||
#include "wpi/hal/DriverStationTypes.h"
|
||||
#include "wpi/hal/Errors.h"
|
||||
#include "wpi/hal/cpp/fpga_clock.hpp"
|
||||
#include "wpi/hal/monotonic_clock.hpp"
|
||||
#include "wpi/hal/simulation/MockHooks.h"
|
||||
#include "wpi/util/EventVector.hpp"
|
||||
#include "wpi/util/mutex.hpp"
|
||||
@@ -155,16 +155,16 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
||||
static constexpr int KEEP_MSGS = 5;
|
||||
std::scoped_lock lock(msgMutex);
|
||||
static std::string prevMsg[KEEP_MSGS];
|
||||
static fpga_clock::time_point prevMsgTime[KEEP_MSGS];
|
||||
static monotonic_clock::time_point prevMsgTime[KEEP_MSGS];
|
||||
static bool initialized = false;
|
||||
if (!initialized) {
|
||||
for (int i = 0; i < KEEP_MSGS; i++) {
|
||||
prevMsgTime[i] = fpga_clock::now() - std::chrono::seconds(2);
|
||||
prevMsgTime[i] = monotonic_clock::now() - std::chrono::seconds(2);
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
auto curTime = fpga_clock::now();
|
||||
auto curTime = monotonic_clock::now();
|
||||
int i;
|
||||
for (i = 0; i < KEEP_MSGS; ++i) {
|
||||
if (prevMsg[i] == details) {
|
||||
|
||||
@@ -254,32 +254,8 @@ int32_t HAL_GetTeamNumber(void) {
|
||||
return HALSIM_GetRoboRioTeamNumber();
|
||||
}
|
||||
|
||||
uint64_t HAL_GetFPGATime(int32_t* status) {
|
||||
return wpi::hal::GetFPGATime();
|
||||
}
|
||||
|
||||
uint64_t HAL_ExpandFPGATime(uint32_t unexpandedLower, int32_t* status) {
|
||||
// Capture the current FPGA time. This will give us the upper half of the
|
||||
// clock.
|
||||
uint64_t fpgaTime = HAL_GetFPGATime(status);
|
||||
if (*status != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Now, we need to detect the case where the lower bits rolled over after we
|
||||
// sampled. In that case, the upper bits will be 1 bigger than they should
|
||||
// be.
|
||||
|
||||
// Break it into lower and upper portions.
|
||||
uint32_t lower = fpgaTime & 0xffffffffull;
|
||||
uint64_t upper = (fpgaTime >> 32) & 0xffffffff;
|
||||
|
||||
// The time was sampled *before* the current time, so roll it back.
|
||||
if (lower < unexpandedLower) {
|
||||
--upper;
|
||||
}
|
||||
|
||||
return (upper << 32) + static_cast<uint64_t>(unexpandedLower);
|
||||
uint64_t HAL_GetMonotonicTime(void) {
|
||||
return wpi::hal::GetMonotonicTime();
|
||||
}
|
||||
|
||||
HAL_Bool HAL_GetSystemActive(int32_t* status) {
|
||||
|
||||
@@ -25,7 +25,7 @@ static std::atomic<uint64_t> programStepTime{0};
|
||||
|
||||
namespace wpi::hal::init {
|
||||
void InitializeMockHooks() {
|
||||
wpi::util::SetNowImpl(GetFPGATime);
|
||||
wpi::util::SetNowImpl(GetMonotonicTime);
|
||||
}
|
||||
} // namespace wpi::hal::init
|
||||
|
||||
@@ -59,7 +59,7 @@ void StepTiming(uint64_t delta) {
|
||||
programStepTime += delta;
|
||||
}
|
||||
|
||||
uint64_t GetFPGATime() {
|
||||
uint64_t GetMonotonicTime() {
|
||||
uint64_t curTime = programPauseTime;
|
||||
if (curTime == 0) {
|
||||
curTime = wpi::util::NowDefault();
|
||||
@@ -67,10 +67,6 @@ uint64_t GetFPGATime() {
|
||||
return curTime + programStepTime - programStartTime;
|
||||
}
|
||||
|
||||
double GetFPGATimestamp() {
|
||||
return GetFPGATime() * 1.0e-6;
|
||||
}
|
||||
|
||||
void SetProgramStarted(bool started) {
|
||||
programStarted = started;
|
||||
}
|
||||
@@ -131,8 +127,7 @@ void HALSIM_StepTiming(uint64_t delta) {
|
||||
WaitNotifiers();
|
||||
|
||||
while (delta > 0) {
|
||||
int32_t status = 0;
|
||||
uint64_t curTime = HAL_GetFPGATime(&status);
|
||||
uint64_t curTime = HAL_GetMonotonicTime();
|
||||
uint64_t nextTimeout = HALSIM_GetNextNotifierTimeout();
|
||||
uint64_t step = (std::min)(delta, nextTimeout - curTime);
|
||||
|
||||
|
||||
@@ -17,9 +17,7 @@ bool IsTimingPaused();
|
||||
|
||||
void StepTiming(uint64_t delta);
|
||||
|
||||
uint64_t GetFPGATime();
|
||||
|
||||
double GetFPGATimestamp();
|
||||
uint64_t GetMonotonicTime();
|
||||
|
||||
void SetProgramStarted();
|
||||
} // namespace wpi::hal
|
||||
|
||||
@@ -93,8 +93,7 @@ void NotifierThread::Main() {
|
||||
|
||||
// Wait until next alarm
|
||||
const Alarm& alarm = m_alarmQueue.top();
|
||||
int32_t status = 0;
|
||||
uint64_t curTime = HAL_GetFPGATime(&status);
|
||||
uint64_t curTime = HAL_GetMonotonicTime();
|
||||
if (alarm.notifier->alarmTime > curTime) {
|
||||
m_cond.wait_for(
|
||||
lock, std::chrono::microseconds{alarm.notifier->alarmTime - curTime});
|
||||
@@ -114,8 +113,7 @@ void NotifierThread::Main() {
|
||||
|
||||
void NotifierThread::ProcessAlarms(
|
||||
wpi::util::SmallVectorImpl<HAL_NotifierHandle>* signaled) {
|
||||
int32_t status = 0;
|
||||
uint64_t curTime = HAL_GetFPGATime(&status);
|
||||
uint64_t curTime = HAL_GetMonotonicTime();
|
||||
|
||||
// Process alarms
|
||||
while (!m_alarmQueue.empty() &&
|
||||
@@ -264,7 +262,7 @@ void HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, uint64_t alarmTime,
|
||||
}
|
||||
|
||||
if (!absolute) {
|
||||
alarmTime += HAL_GetFPGATime(status);
|
||||
alarmTime += HAL_GetMonotonicTime();
|
||||
}
|
||||
|
||||
uint64_t prevWakeup = UINT64_MAX;
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#include "SystemServerInternal.hpp"
|
||||
#include "wpi/hal/AddressableLEDTypes.h"
|
||||
#include "wpi/hal/Errors.h"
|
||||
#include "wpi/hal/cpp/fpga_clock.hpp"
|
||||
#include "wpi/hal/handles/HandlesInternal.hpp"
|
||||
#include "wpi/hal/monotonic_clock.hpp"
|
||||
#include "wpi/nt/NetworkTableInstance.hpp"
|
||||
#include "wpi/nt/RawTopic.hpp"
|
||||
|
||||
@@ -133,9 +133,9 @@ void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle) {
|
||||
smartIoHandles->Free(handle, HAL_HandleEnum::AddressableLED);
|
||||
|
||||
// Wait for no other object to hold this handle.
|
||||
auto start = wpi::hal::fpga_clock::now();
|
||||
auto start = wpi::hal::monotonic_clock::now();
|
||||
while (port.use_count() != 1) {
|
||||
auto current = wpi::hal::fpga_clock::now();
|
||||
auto current = wpi::hal::monotonic_clock::now();
|
||||
if (start + std::chrono::seconds(1) < current) {
|
||||
std::puts("AddressableLED handle free timeout");
|
||||
std::fflush(stdout);
|
||||
|
||||
@@ -75,7 +75,7 @@ void HAL_SetAlertActive(HAL_AlertHandle alertHandle, HAL_Bool active,
|
||||
// Already active, do nothing (avoids cost of getting time)
|
||||
return;
|
||||
}
|
||||
int64_t now = HAL_GetFPGATime(status);
|
||||
int64_t now = HAL_GetMonotonicTime();
|
||||
int64_t expected = 0;
|
||||
// use compare-exchange to avoid potential race
|
||||
alert->activeStartTime.compare_exchange_strong(expected, now);
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#include "PortsInternal.hpp"
|
||||
#include "SmartIo.hpp"
|
||||
#include "wpi/hal/Errors.h"
|
||||
#include "wpi/hal/cpp/fpga_clock.hpp"
|
||||
#include "wpi/hal/handles/HandlesInternal.hpp"
|
||||
#include "wpi/hal/monotonic_clock.hpp"
|
||||
|
||||
namespace wpi::hal::init {
|
||||
void InitializeAnalogInput() {}
|
||||
@@ -73,9 +73,9 @@ void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle) {
|
||||
smartIoHandles->Free(analogPortHandle, HAL_HandleEnum::AnalogInput);
|
||||
|
||||
// Wait for no other object to hold this handle.
|
||||
auto start = wpi::hal::fpga_clock::now();
|
||||
auto start = wpi::hal::monotonic_clock::now();
|
||||
while (port.use_count() != 1) {
|
||||
auto current = wpi::hal::fpga_clock::now();
|
||||
auto current = wpi::hal::monotonic_clock::now();
|
||||
if (start + std::chrono::seconds(1) < current) {
|
||||
std::puts("DIO handle free timeout");
|
||||
std::fflush(stdout);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "HALInternal.hpp"
|
||||
#include "PortsInternal.hpp"
|
||||
#include "SmartIo.hpp"
|
||||
#include "wpi/hal/cpp/fpga_clock.hpp"
|
||||
#include "wpi/hal/monotonic_clock.hpp"
|
||||
|
||||
using namespace wpi::hal;
|
||||
|
||||
@@ -74,9 +74,9 @@ void HAL_FreeCounter(HAL_CounterHandle counterHandle) {
|
||||
smartIoHandles->Free(counterHandle, HAL_HandleEnum::Counter);
|
||||
|
||||
// Wait for no other object to hold this handle.
|
||||
auto start = wpi::hal::fpga_clock::now();
|
||||
auto start = wpi::hal::monotonic_clock::now();
|
||||
while (port.use_count() != 1) {
|
||||
auto current = wpi::hal::fpga_clock::now();
|
||||
auto current = wpi::hal::monotonic_clock::now();
|
||||
if (start + std::chrono::seconds(1) < current) {
|
||||
std::puts("DIO handle free timeout");
|
||||
std::fflush(stdout);
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#include "PortsInternal.hpp"
|
||||
#include "SmartIo.hpp"
|
||||
#include "wpi/hal/Errors.h"
|
||||
#include "wpi/hal/cpp/fpga_clock.hpp"
|
||||
#include "wpi/hal/handles/HandlesInternal.hpp"
|
||||
#include "wpi/hal/monotonic_clock.hpp"
|
||||
|
||||
using namespace wpi::hal;
|
||||
|
||||
@@ -79,9 +79,9 @@ void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
|
||||
smartIoHandles->Free(dioPortHandle, HAL_HandleEnum::DIO);
|
||||
|
||||
// Wait for no other object to hold this handle.
|
||||
auto start = wpi::hal::fpga_clock::now();
|
||||
auto start = wpi::hal::monotonic_clock::now();
|
||||
while (port.use_count() != 1) {
|
||||
auto current = wpi::hal::fpga_clock::now();
|
||||
auto current = wpi::hal::monotonic_clock::now();
|
||||
if (start + std::chrono::seconds(1) < current) {
|
||||
std::puts("DIO handle free timeout");
|
||||
std::fflush(stdout);
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#include "PortsInternal.hpp"
|
||||
#include "SmartIo.hpp"
|
||||
#include "wpi/hal/Errors.h"
|
||||
#include "wpi/hal/cpp/fpga_clock.hpp"
|
||||
#include "wpi/hal/handles/HandlesInternal.hpp"
|
||||
#include "wpi/hal/monotonic_clock.hpp"
|
||||
|
||||
using namespace wpi::hal;
|
||||
|
||||
@@ -71,9 +71,9 @@ void HAL_FreeDutyCycle(HAL_DutyCycleHandle dutyCycleHandle) {
|
||||
smartIoHandles->Free(dutyCycleHandle, HAL_HandleEnum::DutyCycle);
|
||||
|
||||
// Wait for no other object to hold this handle.
|
||||
auto start = wpi::hal::fpga_clock::now();
|
||||
auto start = wpi::hal::monotonic_clock::now();
|
||||
while (port.use_count() != 1) {
|
||||
auto current = wpi::hal::fpga_clock::now();
|
||||
auto current = wpi::hal::monotonic_clock::now();
|
||||
if (start + std::chrono::seconds(1) < current) {
|
||||
std::puts("DIO handle free timeout");
|
||||
std::fflush(stdout);
|
||||
|
||||
@@ -205,35 +205,11 @@ int32_t HAL_GetTeamNumber(void) {
|
||||
return teamNumber;
|
||||
}
|
||||
|
||||
uint64_t HAL_GetFPGATime(int32_t* status) {
|
||||
uint64_t HAL_GetMonotonicTime(void) {
|
||||
wpi::hal::init::CheckInit();
|
||||
return wpi::util::NowDefault();
|
||||
}
|
||||
|
||||
uint64_t HAL_ExpandFPGATime(uint32_t unexpandedLower, int32_t* status) {
|
||||
// Capture the current FPGA time. This will give us the upper half of the
|
||||
// clock.
|
||||
uint64_t fpgaTime = HAL_GetFPGATime(status);
|
||||
if (*status != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Now, we need to detect the case where the lower bits rolled over after we
|
||||
// sampled. In that case, the upper bits will be 1 bigger than they should
|
||||
// be.
|
||||
|
||||
// Break it into lower and upper portions.
|
||||
uint32_t lower = fpgaTime & 0xffffffffull;
|
||||
uint64_t upper = (fpgaTime >> 32) & 0xffffffff;
|
||||
|
||||
// The time was sampled *before* the current time, so roll it back.
|
||||
if (lower < unexpandedLower) {
|
||||
--upper;
|
||||
}
|
||||
|
||||
return (upper << 32) + static_cast<uint64_t>(unexpandedLower);
|
||||
}
|
||||
|
||||
HAL_Bool HAL_GetSystemActive(int32_t* status) {
|
||||
wpi::hal::init::CheckInit();
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -296,14 +272,9 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
||||
|
||||
// WPILIB_NetworkCommunication_Reserve(nullptr);
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
wpi::hal::InitializeDriverStation();
|
||||
|
||||
dsStartTime = HAL_GetFPGATime(&status);
|
||||
if (status != 0) {
|
||||
return false;
|
||||
}
|
||||
dsStartTime = HAL_GetMonotonicTime();
|
||||
|
||||
wpi::hal::WaitForInitialPacket();
|
||||
|
||||
|
||||
@@ -84,8 +84,7 @@ void NotifierThread::Main() {
|
||||
|
||||
// Wait until next alarm
|
||||
const Alarm& alarm = m_alarmQueue.top();
|
||||
int32_t status = 0;
|
||||
uint64_t curTime = HAL_GetFPGATime(&status);
|
||||
uint64_t curTime = HAL_GetMonotonicTime();
|
||||
if (alarm.notifier->alarmTime > curTime) {
|
||||
m_cond.wait_for(
|
||||
lock, std::chrono::microseconds{alarm.notifier->alarmTime - curTime});
|
||||
@@ -99,8 +98,7 @@ void NotifierThread::Main() {
|
||||
}
|
||||
|
||||
void NotifierThread::ProcessAlarms() {
|
||||
int32_t status = 0;
|
||||
uint64_t curTime = HAL_GetFPGATime(&status);
|
||||
uint64_t curTime = HAL_GetMonotonicTime();
|
||||
|
||||
while (!m_alarmQueue.empty() &&
|
||||
m_alarmQueue.top().notifier->alarmTime <= curTime) {
|
||||
@@ -190,7 +188,7 @@ void HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, uint64_t alarmTime,
|
||||
}
|
||||
|
||||
if (!absolute) {
|
||||
alarmTime += HAL_GetFPGATime(status);
|
||||
alarmTime += HAL_GetMonotonicTime();
|
||||
}
|
||||
|
||||
uint64_t prevWakeup = UINT64_MAX;
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
#include "PortsInternal.hpp"
|
||||
#include "SmartIo.hpp"
|
||||
#include "wpi/hal/Errors.h"
|
||||
#include "wpi/hal/cpp/fpga_clock.hpp"
|
||||
#include "wpi/hal/handles/HandlesInternal.hpp"
|
||||
#include "wpi/hal/monotonic_clock.hpp"
|
||||
|
||||
using namespace wpi::hal;
|
||||
|
||||
@@ -83,9 +83,9 @@ void HAL_FreePWMPort(HAL_DigitalHandle pwmPortHandle) {
|
||||
smartIoHandles->Free(pwmPortHandle, HAL_HandleEnum::PWM);
|
||||
|
||||
// Wait for no other object to hold this handle.
|
||||
auto start = wpi::hal::fpga_clock::now();
|
||||
auto start = wpi::hal::monotonic_clock::now();
|
||||
while (port.use_count() != 1) {
|
||||
auto current = wpi::hal::fpga_clock::now();
|
||||
auto current = wpi::hal::monotonic_clock::now();
|
||||
if (start + std::chrono::seconds(1) < current) {
|
||||
std::puts("PWM handle free timeout");
|
||||
std::fflush(stdout);
|
||||
|
||||
@@ -34,10 +34,7 @@ HAL_PowerDistributionHandle HAL_InitializePowerDistribution(
|
||||
|
||||
// Ensure we have been alive for long enough to receive a few Power packets.
|
||||
do {
|
||||
uint64_t currentTime = HAL_GetFPGATime(status);
|
||||
if (*status != 0) {
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
uint64_t currentTime = HAL_GetMonotonicTime();
|
||||
if (currentTime >= waitTime) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ functions:
|
||||
HAL_GetRuntimeType:
|
||||
HAL_GetSystemActive:
|
||||
HAL_GetBrownedOut:
|
||||
HAL_GetFPGATime:
|
||||
HAL_ExpandFPGATime:
|
||||
HAL_GetMonotonicTime:
|
||||
HAL_GetRSLState:
|
||||
HAL_GetSystemTimeValid:
|
||||
HAL_Initialize:
|
||||
|
||||
Reference in New Issue
Block a user