[hal] Fix HAL_GetRuntimeType being slow on the roboRIO (#5130)

HAL_GetRuntimeType used to be a free call before the roboRIO2 was added. However, nLoadOut::getTargetClass() is not a free call, and it may hit the IPC layer. Cache this value so it is not called every time.
This commit is contained in:
Thad House
2023-02-23 00:59:59 -08:00
committed by GitHub
parent 9efed9a533
commit bb7053d9ee

View File

@@ -253,12 +253,10 @@ const char* HAL_GetErrorMessage(int32_t code) {
}
}
static HAL_RuntimeType runtimeType = HAL_Runtime_RoboRIO;
HAL_RuntimeType HAL_GetRuntimeType(void) {
nLoadOut::tTargetClass targetClass = nLoadOut::getTargetClass();
if (targetClass == nLoadOut::kTargetClass_RoboRIO2) {
return HAL_Runtime_RoboRIO2;
}
return HAL_Runtime_RoboRIO;
return runtimeType;
}
int32_t HAL_GetFPGAVersion(int32_t* status) {
@@ -523,6 +521,13 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
return false;
}
nLoadOut::tTargetClass targetClass = nLoadOut::getTargetClass();
if (targetClass == nLoadOut::kTargetClass_RoboRIO2) {
runtimeType = HAL_Runtime_RoboRIO2;
} else {
runtimeType = HAL_Runtime_RoboRIO;
}
InterruptManager::Initialize(global->getSystemInterface());
hal::InitializeDriverStation();