[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:
Peter Johnson
2023-07-24 23:03:28 -07:00
committed by GitHub
parent 2ba8fbb6f4
commit a95994fff6
11 changed files with 166 additions and 20 deletions

View File

@@ -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;