mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[wpiutil] timestamp: Call FPGA functions directly (#5235)
This works around an exit race with wpi::Now() on Rio; it was overridden to call HAL_GetFPGATime(), which calls chipobject, but on exit, because there was not a library dependency, the chipobject could be destroyed prior to wpiutil/wpinet being shut down.
This commit is contained in:
@@ -516,8 +516,9 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
||||
setNewDataSem(nullptr);
|
||||
});
|
||||
|
||||
nFPGA::nRoboRIO_FPGANamespace::g_currentTargetClass =
|
||||
nLoadOut::getTargetClass();
|
||||
// Setup WPI_Now to use FPGA timestamp
|
||||
// this also sets nFPGA::nRoboRIO_FPGANamespace::g_currentTargetClass
|
||||
wpi::impl::SetupNowRio();
|
||||
|
||||
int32_t status = 0;
|
||||
global.reset(tGlobal::create(&status));
|
||||
@@ -543,21 +544,6 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set WPI_Now to use FPGA timestamp
|
||||
wpi::SetNowImpl([]() -> uint64_t {
|
||||
int32_t status = 0;
|
||||
uint64_t rv = HAL_GetFPGATime(&status);
|
||||
if (status != 0) {
|
||||
fmt::print(stderr,
|
||||
"Call to HAL_GetFPGATime failed in wpi::Now() with status {}. "
|
||||
"Initialization might have failed. Time will not be correct\n",
|
||||
status);
|
||||
std::fflush(stderr);
|
||||
return 0u;
|
||||
}
|
||||
return rv;
|
||||
});
|
||||
|
||||
hal::WaitForInitialPacket();
|
||||
|
||||
initialized = true;
|
||||
|
||||
Reference in New Issue
Block a user