Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error out of hal initialize if SetupRioNow fails #6374

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions hal/src/main/native/athena/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ static bool killExistingProgram(int timeout, int mode) {
return true;
}

static void SetupNowRio(void) {
static bool SetupNowRio(void) {
nFPGA::nRoboRIO_FPGANamespace::g_currentTargetClass =
nLoadOut::getTargetClass();

Expand All @@ -534,23 +534,23 @@ static void SetupNowRio(void) {
status = dladdr(reinterpret_cast<void*>(tHMB::create), &info);
if (status == 0) {
fmt::print(stderr, "Failed to call dladdr on chipobject {}\n", dlerror());
return;
return false;
}

void* chipObjectLibrary = dlopen(info.dli_fname, RTLD_LAZY);
if (chipObjectLibrary == nullptr) {
fmt::print(stderr, "Failed to call dlopen on chipobject {}\n", dlerror());
return;
return false;
}

std::unique_ptr<tHMB> hmb;
hmb.reset(tHMB::create(&status));
if (hmb == nullptr) {
fmt::print(stderr, "Failed to open HMB on chipobject {}\n", status);
dlclose(chipObjectLibrary);
return;
return false;
}
wpi::impl::SetupNowRio(chipObjectLibrary, std::move(hmb));
return wpi::impl::SetupNowRio(chipObjectLibrary, std::move(hmb));
}

HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
Expand Down Expand Up @@ -593,7 +593,9 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
setNewDataSem(nullptr);
});

SetupNowRio();
if (!SetupNowRio()) {
return false;
}

int32_t status = 0;

Expand Down
16 changes: 10 additions & 6 deletions wpiutil/src/main/native/cpp/timestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ struct HMBLowLevel {
dlcloseWrapper};
};
struct HMBHolder {
void Configure(void* col, std::unique_ptr<fpga::tHMB> hmbObject) {
bool Configure(void* col, std::unique_ptr<fpga::tHMB> hmbObject) {
hmb = std::move(hmbObject);
chipObjectLibrary.reset(col);
if (!lowLevel.Configure(hmb->getSystemInterface()->getHandle())) {
hmb = nullptr;
chipObjectLibrary = nullptr;
return false;
}
return true;
}
void Reset() {
lowLevel.Reset();
Expand Down Expand Up @@ -236,20 +238,22 @@ void wpi::impl::SetupNowDefaultOnRio() {

#ifdef __FRC_ROBORIO__
template <>
void wpi::impl::SetupNowRio(void* chipObjectLibrary,
bool wpi::impl::SetupNowRio(void* chipObjectLibrary,
std::unique_ptr<fpga::tHMB> hmbObject) {
if (!hmbInitialized.test()) {
hmb.Configure(chipObjectLibrary, std::move(hmbObject));
return hmb.Configure(chipObjectLibrary, std::move(hmbObject));
}
return true;
}
#endif

void wpi::impl::SetupNowRio(uint32_t session) {
bool wpi::impl::SetupNowRio(uint32_t session) {
#ifdef __FRC_ROBORIO__
if (!hmbInitialized.test()) {
hmb.lowLevel.Configure(session);
return hmb.lowLevel.Configure(session);
}
#endif
return true;
}

void wpi::impl::ShutdownNowRio() {
Expand Down Expand Up @@ -311,7 +315,7 @@ void WPI_Impl_SetupNowUseDefaultOnRio(void) {
}

void WPI_Impl_SetupNowRioWithSession(uint32_t session) {
return wpi::impl::SetupNowRio(session);
wpi::impl::SetupNowRio(session);
}

void WPI_Impl_ShutdownNowRio(void) {
Expand Down
8 changes: 5 additions & 3 deletions wpiutil/src/main/native/include/wpi/timestamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,20 @@ void SetupNowDefaultOnRio();
*/
#ifdef __FRC_ROBORIO__
template <typename T>
void SetupNowRio(void* chipObjectLibrary, std::unique_ptr<T> hmbObject);
bool SetupNowRio(void* chipObjectLibrary, std::unique_ptr<T> hmbObject);
#else
template <typename T>
inline void SetupNowRio(void*, std::unique_ptr<T>) {}
inline bool SetupNowRio(void*, std::unique_ptr<T>) {
return true;
}
#endif

/**
* Initialize the on-Rio Now() implementation to use the FPGA timestamp.
* No effect on non-Rio platforms. This take an FPGA session that has
* already been initialized, and is used from LabVIEW.
*/
void SetupNowRio(uint32_t session);
bool SetupNowRio(uint32_t session);

/**
* De-initialize the on-Rio Now() implementation. No effect on non-Rio
Expand Down
Loading