diff --git a/ntcoreffi/src/main/native/symbols.txt b/ntcoreffi/src/main/native/symbols.txt index 1bfc067351..e2f1766534 100644 --- a/ntcoreffi/src/main/native/symbols.txt +++ b/ntcoreffi/src/main/native/symbols.txt @@ -244,6 +244,7 @@ WPI_DestroySemaphore WPI_DestroySignalObject WPI_GetSystemTime WPI_Impl_SetupNowRio +WPI_Impl_ShutdownNowRio WPI_Now WPI_NowDefault WPI_ReleaseSemaphore diff --git a/wpiutil/src/main/native/cpp/timestamp.cpp b/wpiutil/src/main/native/cpp/timestamp.cpp index d2de941507..f5f82bec66 100644 --- a/wpiutil/src/main/native/cpp/timestamp.cpp +++ b/wpiutil/src/main/native/cpp/timestamp.cpp @@ -92,6 +92,18 @@ struct HMBHolder { cfg.Enables_Timestamp = 1; hmb->writeConfig(cfg, &status); } + void Reset() { + if (hmb) { + std::unique_ptr oldHmb; + oldHmb.swap(hmb); + closeHmb(oldHmb->getSystemInterface()->getHandle(), hmbName); + closeHmb = nullptr; + hmbBuffer = nullptr; + oldHmb.reset(); + dlclose(niFpga); + niFpga = nullptr; + } + } std::unique_ptr hmb; void* niFpga = nullptr; NiFpga_CloseHmbFunc closeHmb = nullptr; @@ -182,6 +194,12 @@ void wpi::impl::SetupNowRio() { #endif } +void wpi::impl::ShutdownNowRio() { +#ifdef __FRC_ROBORIO__ + hmb.Reset(); +#endif +} + void wpi::SetNowImpl(uint64_t (*func)(void)) { now_impl = func ? func : NowDefault; } @@ -230,6 +248,10 @@ void WPI_Impl_SetupNowRio(void) { return wpi::impl::SetupNowRio(); } +void WPI_Impl_ShutdownNowRio(void) { + return wpi::impl::ShutdownNowRio(); +} + uint64_t WPI_NowDefault(void) { return wpi::NowDefault(); } diff --git a/wpiutil/src/main/native/include/wpi/timestamp.h b/wpiutil/src/main/native/include/wpi/timestamp.h index 3444781e94..c232481eb7 100644 --- a/wpiutil/src/main/native/include/wpi/timestamp.h +++ b/wpiutil/src/main/native/include/wpi/timestamp.h @@ -18,6 +18,12 @@ extern "C" { */ void WPI_Impl_SetupNowRio(void); +/** + * De-initialize the on-Rio Now() implementation. No effect on non-Rio + * platforms. + */ +void WPI_Impl_ShutdownNowRio(void); + /** * The default implementation used for Now(). * In general this is the time returned by the operating system. @@ -62,6 +68,12 @@ namespace impl { * thus should generally not be called by user code. */ void SetupNowRio(); + +/** + * De-initialize the on-Rio Now() implementation. No effect on non-Rio + * platforms. + */ +void ShutdownNowRio(); } // namespace impl /**