Skip to content

Commit

Permalink
[wpiutil] timestamp: Add ShutdownNowRio (wpilibsuite#5610)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson authored Sep 7, 2023
1 parent e9f612f commit a6157f1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions ntcoreffi/src/main/native/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ WPI_DestroySemaphore
WPI_DestroySignalObject
WPI_GetSystemTime
WPI_Impl_SetupNowRio
WPI_Impl_ShutdownNowRio
WPI_Now
WPI_NowDefault
WPI_ReleaseSemaphore
Expand Down
22 changes: 22 additions & 0 deletions wpiutil/src/main/native/cpp/timestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ struct HMBHolder {
cfg.Enables_Timestamp = 1;
hmb->writeConfig(cfg, &status);
}
void Reset() {
if (hmb) {
std::unique_ptr<fpga::tHMB> oldHmb;
oldHmb.swap(hmb);
closeHmb(oldHmb->getSystemInterface()->getHandle(), hmbName);
closeHmb = nullptr;
hmbBuffer = nullptr;
oldHmb.reset();
dlclose(niFpga);
niFpga = nullptr;
}
}
std::unique_ptr<fpga::tHMB> hmb;
void* niFpga = nullptr;
NiFpga_CloseHmbFunc closeHmb = nullptr;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand Down
12 changes: 12 additions & 0 deletions wpiutil/src/main/native/include/wpi/timestamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

/**
Expand Down

0 comments on commit a6157f1

Please sign in to comment.