[hal, wpilib] Remove relay (#7695)

This commit is contained in:
Thad House
2025-01-16 23:20:07 -08:00
committed by GitHub
parent d9f8fded09
commit 5017393b3a
54 changed files with 1 additions and 3115 deletions

View File

@@ -84,7 +84,6 @@ void InitializeHAL() {
InitializeREVPHData();
InitializePowerDistributionData();
InitializePWMData();
InitializeRelayData();
InitializeRoboRioData();
InitializeSimDeviceData();
InitializeSPIAccelerometerData();
@@ -117,7 +116,6 @@ void InitializeHAL() {
InitializeCTREPCM();
InitializeREVPH();
InitializePWM();
InitializeRelay();
InitializeSerialPort();
InitializeSimDevice();
InitializeSPI();

View File

@@ -35,7 +35,6 @@ extern void InitializeCTREPCMData();
extern void InitializeREVPHData();
extern void InitializePowerDistributionData();
extern void InitializePWMData();
extern void InitializeRelayData();
extern void InitializeRoboRioData();
extern void InitializeSimDeviceData();
extern void InitializeSPIAccelerometerData();
@@ -68,7 +67,6 @@ extern void InitializePower();
extern void InitializeCTREPCM();
extern void InitializeREVPH();
extern void InitializePWM();
extern void InitializeRelay();
extern void InitializeSerialPort();
extern void InitializeSimDevice();
extern void InitializeSPI();

View File

@@ -49,12 +49,6 @@ int32_t HAL_GetNumEncoders(void) {
int32_t HAL_GetNumInterrupts(void) {
return kNumInterrupts;
}
int32_t HAL_GetNumRelayChannels(void) {
return kNumRelayChannels;
}
int32_t HAL_GetNumRelayHeaders(void) {
return kNumRelayHeaders;
}
int32_t HAL_GetNumCTREPCMModules(void) {
return kNumCTREPCMModules;
}

View File

@@ -1,136 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "hal/Relay.h"
#include <string>
#include "HALInitializer.h"
#include "HALInternal.h"
#include "PortsInternal.h"
#include "hal/handles/IndexedHandleResource.h"
#include "mockdata/RelayDataInternal.h"
using namespace hal;
namespace {
struct Relay {
uint8_t channel;
bool fwd;
std::string previousAllocation;
};
} // namespace
static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayChannels,
HAL_HandleEnum::Relay>* relayHandles;
namespace hal::init {
void InitializeRelay() {
static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayChannels,
HAL_HandleEnum::Relay>
rH;
relayHandles = &rH;
}
} // namespace hal::init
extern "C" {
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd,
const char* allocationLocation,
int32_t* status) {
hal::init::CheckInit();
if (*status != 0) {
return HAL_kInvalidHandle;
}
int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex || channel >= kNumRelayChannels) {
*status = RESOURCE_OUT_OF_RANGE;
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Relay", 0,
kNumRelayChannels, channel);
return HAL_kInvalidHandle;
}
if (!fwd) {
channel += kNumRelayHeaders; // add 4 to reverse channels
}
HAL_RelayHandle handle;
auto port = relayHandles->Allocate(channel, &handle, status);
if (*status != 0) {
if (port) {
hal::SetLastErrorPreviouslyAllocated(status, "Relay", channel,
port->previousAllocation);
} else {
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Relay", 0,
kNumRelayChannels, channel);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}
if (!fwd) {
// Subtract number of headers to put channel in range
channel -= kNumRelayHeaders;
port->fwd = false; // set to reverse
SimRelayData[channel].initializedReverse = true;
} else {
port->fwd = true; // set to forward
SimRelayData[channel].initializedForward = true;
}
port->channel = static_cast<uint8_t>(channel);
port->previousAllocation = allocationLocation ? allocationLocation : "";
return handle;
}
void HAL_FreeRelayPort(HAL_RelayHandle relayPortHandle) {
auto port = relayHandles->Get(relayPortHandle);
relayHandles->Free(relayPortHandle);
if (port == nullptr) {
return;
}
if (port->fwd) {
SimRelayData[port->channel].initializedForward = false;
} else {
SimRelayData[port->channel].initializedReverse = false;
}
}
HAL_Bool HAL_CheckRelayChannel(int32_t channel) {
// roboRIO only has 4 headers, and the FPGA has
// separate functions for forward and reverse,
// instead of separate channel IDs
return channel < kNumRelayHeaders && channel >= 0;
}
void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
int32_t* status) {
auto port = relayHandles->Get(relayPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
if (port->fwd) {
SimRelayData[port->channel].forward = on;
} else {
SimRelayData[port->channel].reverse = on;
}
}
HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status) {
auto port = relayHandles->Get(relayPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
}
if (port->fwd) {
return SimRelayData[port->channel].forward;
} else {
return SimRelayData[port->channel].reverse;
}
}
} // extern "C"

View File

@@ -1,50 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "../PortsInternal.h"
#include "RelayDataInternal.h"
using namespace hal;
namespace hal::init {
void InitializeRelayData() {
static RelayData srd[kNumRelayHeaders];
::hal::SimRelayData = srd;
}
} // namespace hal::init
RelayData* hal::SimRelayData;
void RelayData::ResetData() {
initializedForward.Reset(false);
initializedReverse.Reset(false);
forward.Reset(false);
reverse.Reset(false);
}
extern "C" {
void HALSIM_ResetRelayData(int32_t index) {
SimRelayData[index].ResetData();
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, Relay##CAPINAME, SimRelayData, \
LOWERNAME)
DEFINE_CAPI(HAL_Bool, InitializedForward, initializedForward)
DEFINE_CAPI(HAL_Bool, InitializedReverse, initializedReverse)
DEFINE_CAPI(HAL_Bool, Forward, forward)
DEFINE_CAPI(HAL_Bool, Reverse, reverse)
#define REGISTER(NAME) \
SimRelayData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterRelayAllCallbacks(int32_t index,
HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
REGISTER(initializedForward);
REGISTER(initializedReverse);
REGISTER(forward);
REGISTER(reverse);
}
} // extern "C"

View File

@@ -1,28 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include "hal/simulation/RelayData.h"
#include "hal/simulation/SimDataValue.h"
namespace hal {
class RelayData {
HAL_SIMDATAVALUE_DEFINE_NAME(InitializedForward)
HAL_SIMDATAVALUE_DEFINE_NAME(InitializedReverse)
HAL_SIMDATAVALUE_DEFINE_NAME(Forward)
HAL_SIMDATAVALUE_DEFINE_NAME(Reverse)
public:
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedForwardName>
initializedForward{false};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedReverseName>
initializedReverse{false};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetForwardName> forward{false};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetReverseName> reverse{false};
virtual void ResetData();
};
extern RelayData* SimRelayData;
} // namespace hal

View File

@@ -19,7 +19,6 @@
#include <hal/simulation/PWMData.h>
#include <hal/simulation/PowerDistributionData.h>
#include <hal/simulation/REVPHData.h>
#include <hal/simulation/RelayData.h>
#include <hal/simulation/RoboRioData.h>
#include <hal/simulation/SPIAccelerometerData.h>
#include <hal/simulation/SPIData.h>
@@ -88,10 +87,6 @@ extern "C" void HALSIM_ResetAllSimData(void) {
HALSIM_ResetPWMData(i);
}
for (int32_t i = 0; i < hal::kNumRelayHeaders; i++) {
HALSIM_ResetRelayData(i);
}
for (int32_t i = 0; i < hal::kNumREVPHModules; i++) {
HALSIM_ResetREVPHData(i);
}