diff --git a/hal/include/HAL/HAL.h b/hal/include/HAL/HAL.h index ca54b03216..e8a26d71da 100644 --- a/hal/include/HAL/HAL.h +++ b/hal/include/HAL/HAL.h @@ -26,6 +26,7 @@ #include "Notifier.h" #include "PDP.h" #include "PWM.h" +#include "Ports.h" #include "Power.h" #include "Relay.h" #include "SPI.h" @@ -103,9 +104,6 @@ struct HALJoystickDescriptor { }; extern "C" { -extern const uint32_t dio_kNumSystems; -extern const uint32_t solenoid_kNumDO7_0Elements; -extern const uint32_t interrupt_kNumSystems; extern const uint32_t kSystemClockTicksPerMicrosecond; HalPortHandle getPort(uint8_t pin); diff --git a/hal/include/HAL/Ports.h b/hal/include/HAL/Ports.h new file mode 100644 index 0000000000..2966f6098c --- /dev/null +++ b/hal/include/HAL/Ports.h @@ -0,0 +1,31 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include + +extern "C" { +int32_t HAL_getNumAccumulators(void); +int32_t HAL_getNumAnalogTriggers(void); +int32_t HAL_getNumAnalogInputs(void); +int32_t HAL_getNumAnalogOutputs(void); +int32_t HAL_getNumCounters(void); +int32_t HAL_getNumDigitalHeaders(void); +int32_t HAL_getNumPWMHeaders(void); +int32_t HAL_getNumDigitalPins(void); +int32_t HAL_getNumPWMPins(void); +int32_t HAL_getNumDigitalPWMOutputs(void); +int32_t HAL_getNumEncoders(void); +int32_t HAL_getNumInterrupts(void); +int32_t HAL_getNumRelayPins(void); +int32_t HAL_getNumRelayHeaders(void); +int32_t HAL_getNumPCMModules(void); +int32_t HAL_getNumSolenoidPins(void); +int32_t HAL_getNumPDPModules(void); +int32_t HAL_getNumCanTalons(void); +} diff --git a/hal/lib/athena/AnalogAccumulator.cpp b/hal/lib/athena/AnalogAccumulator.cpp index 1c6ec231bc..80d65a287f 100644 --- a/hal/lib/athena/AnalogAccumulator.cpp +++ b/hal/lib/athena/AnalogAccumulator.cpp @@ -25,7 +25,7 @@ bool isAccumulatorChannel(HalAnalogInputHandle analog_port_handle, *status = PARAMETER_OUT_OF_RANGE; return false; } - for (uint32_t i = 0; i < kAccumulatorNumChannels; i++) { + for (uint32_t i = 0; i < kNumAccumulators; i++) { if (port->pin == kAccumulatorChannels[i]) return true; } return false; diff --git a/hal/lib/athena/AnalogInput.cpp b/hal/lib/athena/AnalogInput.cpp index 77caf9c593..5266d00387 100644 --- a/hal/lib/athena/AnalogInput.cpp +++ b/hal/lib/athena/AnalogInput.cpp @@ -14,6 +14,7 @@ #include "HAL/AnalogAccumulator.h" #include "HAL/HAL.h" #include "HAL/cpp/priority_mutex.h" +#include "PortsInternal.h" #include "handles/HandlesInternal.h" using namespace hal; @@ -83,7 +84,7 @@ bool checkAnalogModule(uint8_t module) { return module == 1; } * @return Analog channel is valid */ bool checkAnalogInputChannel(uint32_t pin) { - if (pin < kAnalogInputPins) return true; + if (pin < kNumAnalogInputs) return true; return false; } diff --git a/hal/lib/athena/AnalogInternal.cpp b/hal/lib/athena/AnalogInternal.cpp index 853f3a0523..3e45a683c3 100644 --- a/hal/lib/athena/AnalogInternal.cpp +++ b/hal/lib/athena/AnalogInternal.cpp @@ -10,13 +10,14 @@ #include "ChipObject.h" #include "HAL/AnalogInput.h" #include "HAL/cpp/priority_mutex.h" +#include "PortsInternal.h" namespace hal { priority_recursive_mutex analogRegisterWindowMutex; tAI* analogInputSystem = nullptr; tAO* analogOutputSystem = nullptr; -IndexedHandleResource analogInputHandles; @@ -32,7 +33,7 @@ void initializeAnalog(int32_t* status) { if (analogSystemInitialized) return; analogInputSystem = tAI::create(status); analogOutputSystem = tAO::create(status); - setAnalogNumChannelsToActivate(kAnalogInputPins); + setAnalogNumChannelsToActivate(kNumAnalogInputs); setAnalogSampleRate(kDefaultSampleRate, status); analogSystemInitialized = true; } diff --git a/hal/lib/athena/AnalogInternal.h b/hal/lib/athena/AnalogInternal.h index 8248bba573..fd1b8cd3d8 100644 --- a/hal/lib/athena/AnalogInternal.h +++ b/hal/lib/athena/AnalogInternal.h @@ -10,7 +10,9 @@ #include #include "ChipObject.h" +#include "HAL/Ports.h" #include "HAL/cpp/priority_mutex.h" +#include "PortsInternal.h" #include "handles/IndexedHandleResource.h" namespace hal { @@ -18,9 +20,6 @@ constexpr long kTimebase = 40000000; ///< 40 MHz clock constexpr long kDefaultOversampleBits = 0; constexpr long kDefaultAverageBits = 7; constexpr float kDefaultSampleRate = 50000.0; -constexpr uint32_t kAnalogInputPins = 8; -constexpr uint32_t kAnalogOutputPins = 2; -constexpr uint32_t kAccumulatorNumChannels = 2; static const uint32_t kAccumulatorChannels[] = {0, 1}; extern tAI* analogInputSystem; @@ -33,7 +32,7 @@ struct AnalogPort { }; extern IndexedHandleResource + kNumAnalogInputs, HalHandleEnum::AnalogInput> analogInputHandles; uint32_t getAnalogNumActiveChannels(int32_t* status); diff --git a/hal/lib/athena/AnalogOutput.cpp b/hal/lib/athena/AnalogOutput.cpp index 034accbaac..b814642618 100644 --- a/hal/lib/athena/AnalogOutput.cpp +++ b/hal/lib/athena/AnalogOutput.cpp @@ -9,6 +9,7 @@ #include "AnalogInternal.h" #include "HAL/Errors.h" +#include "PortsInternal.h" #include "handles/HandlesInternal.h" #include "handles/IndexedHandleResource.h" @@ -21,7 +22,7 @@ struct AnalogOutput { } static IndexedHandleResource + kNumAnalogOutputs, HalHandleEnum::AnalogOutput> analogOutputHandles; extern "C" { @@ -69,7 +70,7 @@ void freeAnalogOutputPort(HalAnalogOutputHandle analog_output_handle) { * @return Analog channel is valid */ bool checkAnalogOutputChannel(uint32_t pin) { - if (pin < kAnalogOutputPins) return true; + if (pin < kNumAnalogOutputs) return true; return false; } diff --git a/hal/lib/athena/AnalogTrigger.cpp b/hal/lib/athena/AnalogTrigger.cpp index 823115298c..3eb85fd360 100644 --- a/hal/lib/athena/AnalogTrigger.cpp +++ b/hal/lib/athena/AnalogTrigger.cpp @@ -11,6 +11,7 @@ #include "HAL/AnalogInput.h" #include "HAL/Errors.h" #include "HAL/cpp/Resource.h" +#include "PortsInternal.h" #include "handles/HandlesInternal.h" #include "handles/LimitedHandleResource.h" @@ -25,8 +26,7 @@ struct AnalogTrigger { } static LimitedHandleResource + kNumAnalogTriggers, HalHandleEnum::AnalogTrigger> analogTriggerHandles; extern "C" { diff --git a/hal/lib/athena/Compressor.cpp b/hal/lib/athena/Compressor.cpp index 8e386bf9d3..c484003208 100644 --- a/hal/lib/athena/Compressor.cpp +++ b/hal/lib/athena/Compressor.cpp @@ -9,6 +9,7 @@ #include "HAL/Errors.h" #include "PCMInternal.h" +#include "PortsInternal.h" #include "ctre/PCM.h" #include "handles/HandlesInternal.h" @@ -31,9 +32,7 @@ HalCompressorHandle initializeCompressor(uint8_t module, int32_t* status) { return (HalCompressorHandle)createHandle(module, HalHandleEnum::Compressor); } -bool checkCompressorModule(uint8_t module) { - return module < NUM_MODULE_NUMBERS; -} +bool checkCompressorModule(uint8_t module) { return module < kNumPCMModules; } bool getCompressor(HalCompressorHandle compressor_handle, int32_t* status) { int16_t index = diff --git a/hal/lib/athena/Counter.cpp b/hal/lib/athena/Counter.cpp index 72dba524ba..266df4a9aa 100644 --- a/hal/lib/athena/Counter.cpp +++ b/hal/lib/athena/Counter.cpp @@ -9,11 +9,9 @@ #include "DigitalInternal.h" #include "HAL/HAL.h" +#include "PortsInternal.h" #include "handles/LimitedHandleResource.h" -static_assert(sizeof(uint32_t) <= sizeof(void*), - "This file shoves uint32_ts into pointers."); - using namespace hal; namespace { @@ -23,7 +21,7 @@ struct Counter { }; } -static LimitedHandleResource counterHandles; diff --git a/hal/lib/athena/DIO.cpp b/hal/lib/athena/DIO.cpp index 2d748d5fe8..20dddb2900 100644 --- a/hal/lib/athena/DIO.cpp +++ b/hal/lib/athena/DIO.cpp @@ -10,21 +10,17 @@ #include #include "DigitalInternal.h" +#include "PortsInternal.h" #include "handles/HandlesInternal.h" #include "handles/LimitedHandleResource.h" -static_assert(sizeof(uint32_t) <= sizeof(void*), - "This file shoves uint32_ts into pointers."); - using namespace hal; // Create a mutex to protect changes to the digital output values static priority_recursive_mutex digitalDIOMutex; static LimitedHandleResource + kNumDigitalPWMOutputs, HalHandleEnum::DigitalPWM> digitalPWMHandles; extern "C" { @@ -61,7 +57,7 @@ HalDigitalHandle initializeDIOPort(HalPortHandle port_handle, uint8_t input, tDIO::tOutputEnable outputEnable = digitalSystem->readOutputEnable(status); - if (port->pin < kNumHeaders) { + if (port->pin < kNumDigitalHeaders) { uint32_t bitToSet = 1 << port->pin; if (input) { outputEnable.Headers = @@ -196,7 +192,7 @@ void setDigitalPWMOutputChannel(HalDigitalPWMHandle pwmGenerator, uint32_t pin, return; } uint32_t id = *port; - if (pin >= kNumHeaders) { // if it is on the MXP + if (pin >= kNumDigitalHeaders) { // if it is on the MXP pin += kMXPDigitalPWMOffset; // then to write as a digital PWM pin requires // an offset to write on the correct pin } @@ -224,7 +220,7 @@ void setDIO(HalDigitalHandle dio_port_handle, short value, int32_t* status) { std::lock_guard sync(digitalDIOMutex); tDIO::tDO currentDIO = digitalSystem->readDO(status); - if (port->pin < kNumHeaders) { + if (port->pin < kNumDigitalHeaders) { if (value == 0) { currentDIO.Headers = currentDIO.Headers & ~(1 << port->pin); } else if (value == 1) { @@ -266,7 +262,7 @@ bool getDIO(HalDigitalHandle dio_port_handle, int32_t* status) { // if it == 0, then return false // else return true - if (port->pin < kNumHeaders) { + if (port->pin < kNumDigitalHeaders) { return ((currentDIO.Headers >> port->pin) & 1) != 0; } else { // Disable special functions @@ -300,7 +296,7 @@ bool getDIODirection(HalDigitalHandle dio_port_handle, int32_t* status) { // if it == 0, then return false // else return true - if (port->pin < kNumHeaders) { + if (port->pin < kNumDigitalHeaders) { return ((currentOutputEnable.Headers >> port->pin) & 1) != 0; } else { return ((currentOutputEnable.MXP >> remapMXPChannel(port->pin)) & 1) != 0; @@ -324,7 +320,7 @@ void pulse(HalDigitalHandle dio_port_handle, double pulseLength, } tDIO::tPulse pulse; - if (port->pin < kNumHeaders) { + if (port->pin < kNumDigitalHeaders) { pulse.Headers = 1 << port->pin; } else { pulse.MXP = 1 << remapMXPChannel(port->pin); @@ -349,7 +345,7 @@ bool isPulsing(HalDigitalHandle dio_port_handle, int32_t* status) { } tDIO::tPulse pulseRegister = digitalSystem->readPulse(status); - if (port->pin < kNumHeaders) { + if (port->pin < kNumDigitalHeaders) { return (pulseRegister.Headers & (1 << port->pin)) != 0; } else { return (pulseRegister.MXP & (1 << remapMXPChannel(port->pin))) != 0; @@ -383,7 +379,7 @@ void setFilterSelect(HalDigitalHandle dio_port_handle, int filter_index, } std::lock_guard sync(digitalDIOMutex); - if (port->pin < kNumHeaders) { + if (port->pin < kNumDigitalHeaders) { digitalSystem->writeFilterSelectHdr(port->pin, filter_index, status); } else { digitalSystem->writeFilterSelectMXP(remapMXPChannel(port->pin), @@ -407,7 +403,7 @@ int getFilterSelect(HalDigitalHandle dio_port_handle, int32_t* status) { } std::lock_guard sync(digitalDIOMutex); - if (port->pin < kNumHeaders) { + if (port->pin < kNumDigitalHeaders) { return digitalSystem->readFilterSelectHdr(port->pin, status); } else { return digitalSystem->readFilterSelectMXP(remapMXPChannel(port->pin), diff --git a/hal/lib/athena/DigitalInternal.cpp b/hal/lib/athena/DigitalInternal.cpp index fd300510f7..b9880a3665 100644 --- a/hal/lib/athena/DigitalInternal.cpp +++ b/hal/lib/athena/DigitalInternal.cpp @@ -13,11 +13,10 @@ #include "ChipObject.h" #include "FRC_NetworkCommunication/LoadOut.h" #include "HAL/HAL.h" -#include "HAL/cpp/Resource.h" +#include "HAL/Ports.h" #include "HAL/cpp/priority_mutex.h" +#include "PortsInternal.h" -static_assert(sizeof(uint32_t) <= sizeof(void*), - "This file shoves uint32_ts into pointers."); namespace hal { // Create a mutex to protect changes to the DO PWM config priority_recursive_mutex digitalPwmMutex; @@ -28,7 +27,8 @@ tPWM* pwmSystem = nullptr; bool digitalSystemsInitialized = false; -DigitalHandleResource +DigitalHandleResource digitalPinHandles; /** @@ -67,7 +67,7 @@ void initializeDigital(int32_t* status) { (kDefaultPwmCenter - kDefaultPwmStepsDown * loopTime) / loopTime + .5); pwmSystem->writeConfig_MinHigh(minHigh, status); // Ensure that PWM output values are set to OFF - for (uint32_t pwm_index = 0; pwm_index < kPwmPins; pwm_index++) { + for (uint32_t pwm_index = 0; pwm_index < kNumPWMPins; pwm_index++) { // Copy of SetPWM if (pwm_index < tPWM::kNumHdrRegisters) { pwmSystem->writeHdr(pwm_index, kPwmDisabled, status); @@ -112,7 +112,7 @@ extern "C++" void remapDigitalSource(bool analogTrigger, uint32_t& pin, if (analogTrigger) { module = pin >> 4; } else { - if (pin >= kNumHeaders) { + if (pin >= kNumDigitalHeaders) { pin = remapMXPChannel(pin); module = 1; } else { diff --git a/hal/lib/athena/DigitalInternal.h b/hal/lib/athena/DigitalInternal.h index b480302d7f..856792b808 100644 --- a/hal/lib/athena/DigitalInternal.h +++ b/hal/lib/athena/DigitalInternal.h @@ -11,14 +11,12 @@ #include "ChipObject.h" #include "HAL/Handles.h" -#include "HAL/cpp/Resource.h" +#include "HAL/Ports.h" +#include "PortsInternal.h" #include "handles/DigitalHandleResource.h" #include "handles/HandlesInternal.h" namespace hal { -constexpr uint32_t kNumHeaders = 10; // Number of non-MXP pins -constexpr uint32_t kDigitalPins = 26; -constexpr uint32_t kPwmPins = 20; constexpr uint32_t kMXPDigitalPWMOffset = 6; // MXP pins when used as digital // output pwm are offset by 6 from // actual value @@ -67,7 +65,7 @@ struct DigitalPort { }; extern DigitalHandleResource + kNumDigitalPins + kNumPWMHeaders> digitalPinHandles; void initializeDigital(int32_t* status); diff --git a/hal/lib/athena/Encoder.cpp b/hal/lib/athena/Encoder.cpp index 885a48153b..85d48ba7a1 100644 --- a/hal/lib/athena/Encoder.cpp +++ b/hal/lib/athena/Encoder.cpp @@ -8,6 +8,7 @@ #include "HAL/Encoder.h" #include "DigitalInternal.h" +#include "HAL/cpp/Resource.h" static_assert(sizeof(uint32_t) <= sizeof(void*), "This file shoves uint32_ts into pointers."); diff --git a/hal/lib/athena/HALAthena.cpp b/hal/lib/athena/HALAthena.cpp index 94265cce0a..afa2d20844 100644 --- a/hal/lib/athena/HALAthena.cpp +++ b/hal/lib/athena/HALAthena.cpp @@ -27,9 +27,6 @@ #include "handles/HandlesInternal.h" #include "visa/visa.h" -const uint32_t solenoid_kNumDO7_0Elements = 8; -const uint32_t dio_kNumSystems = tDIO::kNumSystems; -const uint32_t interrupt_kNumSystems = tInterrupt::kNumSystems; const uint32_t kSystemClockTicksPerMicrosecond = 40; static tGlobal* global = nullptr; @@ -376,7 +373,4 @@ void RTSetCleanupProc() {} void EDVR_CreateReference() {} void Occur() {} -void imaqGetErrorText() {} -void imaqGetLastError() {} - } // extern "C" diff --git a/hal/lib/athena/I2C.cpp b/hal/lib/athena/I2C.cpp index b351be57e9..8a182ce31f 100644 --- a/hal/lib/athena/I2C.cpp +++ b/hal/lib/athena/I2C.cpp @@ -12,9 +12,6 @@ #include "HAL/HAL.h" #include "i2clib/i2c-lib.h" -static_assert(sizeof(uint32_t) <= sizeof(void*), - "This file shoves uint32_ts into pointers."); - using namespace hal; static priority_recursive_mutex digitalI2COnBoardMutex; diff --git a/hal/lib/athena/Interrupts.cpp b/hal/lib/athena/Interrupts.cpp index afd1aeafd1..3dc1782365 100644 --- a/hal/lib/athena/Interrupts.cpp +++ b/hal/lib/athena/Interrupts.cpp @@ -13,6 +13,7 @@ #include "DigitalInternal.h" #include "HAL/Errors.h" +#include "PortsInternal.h" #include "handles/LimitedHandleResource.h" using namespace hal; @@ -25,8 +26,8 @@ struct Interrupt // FIXME: why is this internal? }; } -static LimitedHandleResource +static LimitedHandleResource interruptHandles; extern "C" { diff --git a/hal/lib/athena/PCMInternal.cpp b/hal/lib/athena/PCMInternal.cpp index 3101cc0a20..1ee9392c89 100644 --- a/hal/lib/athena/PCMInternal.cpp +++ b/hal/lib/athena/PCMInternal.cpp @@ -7,8 +7,10 @@ #include "PCMInternal.h" +#include "PortsInternal.h" + namespace hal { -PCM* PCM_modules[NUM_MODULE_NUMBERS] = {nullptr}; +PCM* PCM_modules[kNumPCMModules] = {nullptr}; void initializePCM(int module) { if (!PCM_modules[module]) { diff --git a/hal/lib/athena/PCMInternal.h b/hal/lib/athena/PCMInternal.h index 5acac0bbe1..6154edc62a 100644 --- a/hal/lib/athena/PCMInternal.h +++ b/hal/lib/athena/PCMInternal.h @@ -9,13 +9,12 @@ #include +#include "HAL/Ports.h" +#include "PortsInternal.h" #include "ctre/PCM.h" namespace hal { -constexpr int NUM_MODULE_NUMBERS = 63; -constexpr int NUM_SOLENOID_PINS = 8; - -extern PCM* PCM_modules[NUM_MODULE_NUMBERS]; +extern PCM* PCM_modules[kNumPCMModules]; void initializePCM(int module); } diff --git a/hal/lib/athena/PDP.cpp b/hal/lib/athena/PDP.cpp index 4989840d31..37b8c36b91 100644 --- a/hal/lib/athena/PDP.cpp +++ b/hal/lib/athena/PDP.cpp @@ -7,11 +7,13 @@ #include "HAL/PDP.h" +#include "HAL/Ports.h" +#include "PortsInternal.h" #include "ctre/PDP.h" -static const int NUM_MODULE_NUMBERS = 63; +using namespace hal; -static PDP* pdp[NUM_MODULE_NUMBERS] = {nullptr}; +static PDP* pdp[kNumPDPModules] = {nullptr}; extern "C" { diff --git a/hal/lib/athena/PWM.cpp b/hal/lib/athena/PWM.cpp index f17d1d9cf0..ae43e2f961 100644 --- a/hal/lib/athena/PWM.cpp +++ b/hal/lib/athena/PWM.cpp @@ -8,11 +8,9 @@ #include "HAL/PWM.h" #include "DigitalInternal.h" +#include "PortsInternal.h" #include "handles/HandlesInternal.h" -static_assert(sizeof(uint32_t) <= sizeof(void*), - "This file shoves uint32_ts into pointers."); - using namespace hal; extern "C" { @@ -30,8 +28,8 @@ HalDigitalHandle initializePWMPort(HalPortHandle port_handle, int32_t* status) { uint8_t origPin = static_cast(pin); - if (origPin < kNumHeaders) { - pin += kDigitalPins; // remap Headers to end of allocations + if (origPin < kNumPWMHeaders) { + pin += kNumDigitalPins; // remap Headers to end of allocations } else { pin = remapMXPPWMChannel(pin) + 10; // remap MXP to proper channel } @@ -74,7 +72,7 @@ void freePWMPort(HalDigitalHandle pwm_port_handle, int32_t* status) { digitalPinHandles.Free(pwm_port_handle, HalHandleEnum::PWM); } -bool checkPWMChannel(uint8_t pin) { return pin < kPwmPins; } +bool checkPWMChannel(uint8_t pin) { return pin < kNumPWMPins; } /** * Set a PWM channel to the desired value. The values range from 0 to 255 and diff --git a/hal/lib/athena/Ports.cpp b/hal/lib/athena/Ports.cpp new file mode 100644 index 0000000000..0b1dc4fe30 --- /dev/null +++ b/hal/lib/athena/Ports.cpp @@ -0,0 +1,33 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "HAL/Ports.h" + +#include "PortsInternal.h" + +using namespace hal; + +extern "C" { +int32_t HAL_getNumAccumulators(void) { return kNumAccumulators; } +int32_t HAL_getNumAnalogTriggers(void) { return kNumAnalogTriggers; } +int32_t HAL_getNumAnalogInputs(void) { return kNumAnalogInputs; } +int32_t HAL_getNumAnalogOutputs(void) { return kNumAnalogOutputs; } +int32_t HAL_getNumCounters(void) { return kNumCounters; } +int32_t HAL_getNumDigitalHeaders(void) { return kNumDigitalHeaders; } +int32_t HAL_getNumPWMHeaders(void) { return kNumPWMHeaders; } +int32_t HAL_getNumDigitalPins(void) { return kNumDigitalPins; } +int32_t HAL_getNumPWMPins(void) { return kNumPWMPins; } +int32_t HAL_getNumDigitalPWMOutputs(void) { return kNumDigitalPWMOutputs; } +int32_t HAL_getNumEncoders(void) { return kNumEncoders; } +int32_t HAL_getNumInterrupts(void) { return kNumInterrupts; } +int32_t HAL_getNumRelayPins(void) { return kNumRelayPins; } +int32_t HAL_getNumRelayHeaders(void) { return kNumRelayHeaders; } +int32_t HAL_getNumPCMModules(void) { return kNumPCMModules; } +int32_t HAL_getNumSolenoidPins(void) { return kNumSolenoidPins; } +int32_t HAL_getNumPDPModules(void) { return kNumPDPModules; } +int32_t HAL_getNumCanTalons(void) { return kNumCanTalons; } +} diff --git a/hal/lib/athena/PortsInternal.h b/hal/lib/athena/PortsInternal.h new file mode 100644 index 0000000000..35143306e0 --- /dev/null +++ b/hal/lib/athena/PortsInternal.h @@ -0,0 +1,34 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include + +#include "ChipObject.h" + +namespace hal { +constexpr int32_t kNumAccumulators = tAccumulator::kNumSystems; +constexpr int32_t kNumAnalogTriggers = tAnalogTrigger::kNumSystems; +constexpr int32_t kNumAnalogInputs = 8; +constexpr int32_t kNumAnalogOutputs = tAO::kNumMXPRegisters; +constexpr int32_t kNumCounters = tCounter::kNumSystems; +constexpr int32_t kNumDigitalHeaders = 10; +constexpr int32_t kNumPWMHeaders = tPWM::kNumHdrRegisters; +constexpr int32_t kNumDigitalPins = 26; +constexpr int32_t kNumPWMPins = tPWM::kNumMXPRegisters + kNumPWMHeaders; +constexpr int32_t kNumDigitalPWMOutputs = + tDIO::kNumPWMDutyCycleAElements + tDIO::kNumPWMDutyCycleBElements; +constexpr int32_t kNumEncoders = tEncoder::kNumSystems; +constexpr int32_t kNumInterrupts = tInterrupt::kNumSystems; +constexpr int32_t kNumRelayPins = 8; +constexpr int32_t kNumRelayHeaders = kNumRelayPins / 2; +constexpr int32_t kNumPCMModules = 63; +constexpr int32_t kNumSolenoidPins = 8; +constexpr int32_t kNumPDPModules = 63; +constexpr int32_t kNumCanTalons = 63; +} diff --git a/hal/lib/athena/Relay.cpp b/hal/lib/athena/Relay.cpp index 804f6ecd58..5cad4278f9 100644 --- a/hal/lib/athena/Relay.cpp +++ b/hal/lib/athena/Relay.cpp @@ -8,6 +8,7 @@ #include "HAL/Relay.h" #include "DigitalInternal.h" +#include "PortsInternal.h" #include "handles/IndexedHandleResource.h" using namespace hal; @@ -19,10 +20,7 @@ struct Relay { }; } -constexpr uint32_t kRelayPins = 8; -constexpr uint32_t kRelayHeaders = kRelayPins / 2; // Number of FPGA ID's - -static IndexedHandleResource relayHandles; @@ -42,7 +40,7 @@ HalRelayHandle initializeRelayPort(HalPortHandle port_handle, uint8_t fwd, return HAL_INVALID_HANDLE; } - if (!fwd) pin += kRelayHeaders; // add 4 to reverse pins + if (!fwd) pin += kNumRelayHeaders; // add 4 to reverse pins auto handle = relayHandles.Allocate(pin, status); @@ -56,8 +54,8 @@ HalRelayHandle initializeRelayPort(HalPortHandle port_handle, uint8_t fwd, } if (!fwd) { - pin -= kRelayHeaders; // subtract number of headers to put pin in range. - port->fwd = false; // set to reverse + pin -= kNumRelayHeaders; // subtract number of headers to put pin in range. + port->fwd = false; // set to reverse } else { port->fwd = true; // set to forward } @@ -72,9 +70,10 @@ void freeRelayPort(HalRelayHandle relay_port_handle) { } bool checkRelayChannel(uint8_t pin) { - return pin < kRelayHeaders; // roboRIO only has 4 headers, and the FPGA has - // seperate functions for forward and reverse, - // instead of seperate pin IDs + // roboRIO only has 4 headers, and the FPGA has + // seperate functions for forward and reverse, + // instead of seperate pin IDs + return pin < kNumRelayHeaders; } /** diff --git a/hal/lib/athena/Solenoid.cpp b/hal/lib/athena/Solenoid.cpp index aadb325b99..b2b534c0ef 100644 --- a/hal/lib/athena/Solenoid.cpp +++ b/hal/lib/athena/Solenoid.cpp @@ -10,7 +10,9 @@ #include "ChipObject.h" #include "FRC_NetworkCommunication/LoadOut.h" #include "HAL/Errors.h" +#include "HAL/Ports.h" #include "PCMInternal.h" +#include "PortsInternal.h" #include "ctre/PCM.h" #include "handles/HandlesInternal.h" #include "handles/IndexedHandleResource.h" @@ -25,7 +27,7 @@ struct Solenoid { using namespace hal; static IndexedHandleResource solenoidHandles; @@ -40,7 +42,7 @@ HalSolenoidHandle initializeSolenoidPort(HalPortHandle port_handle, return HAL_INVALID_HANDLE; } - if (module >= NUM_MODULE_NUMBERS || pin >= NUM_SOLENOID_PINS) { + if (module >= kNumPCMModules || pin >= kNumSolenoidPins) { *status = PARAMETER_OUT_OF_RANGE; return HAL_INVALID_HANDLE; } @@ -48,7 +50,7 @@ HalSolenoidHandle initializeSolenoidPort(HalPortHandle port_handle, initializePCM(module); auto handle = - solenoidHandles.Allocate(module * NUM_SOLENOID_PINS + pin, status); + solenoidHandles.Allocate(module * kNumSolenoidPins + pin, status); if (handle == HAL_INVALID_HANDLE) { // out of resources *status = NO_AVAILABLE_RESOURCES; return HAL_INVALID_HANDLE; @@ -68,7 +70,7 @@ void freeSolenoidPort(HalSolenoidHandle solenoid_port_handle) { solenoidHandles.Free(solenoid_port_handle); } -bool checkSolenoidModule(uint8_t module) { return module < NUM_MODULE_NUMBERS; } +bool checkSolenoidModule(uint8_t module) { return module < kNumPCMModules; } bool getSolenoid(HalSolenoidHandle solenoid_port_handle, int32_t* status) { auto port = solenoidHandles.Get(solenoid_port_handle); @@ -84,7 +86,7 @@ bool getSolenoid(HalSolenoidHandle solenoid_port_handle, int32_t* status) { } uint8_t getAllSolenoids(uint8_t module, int32_t* status) { - if (module >= NUM_MODULE_NUMBERS) { + if (module >= kNumPCMModules) { *status = PARAMETER_OUT_OF_RANGE; return 0; } @@ -107,7 +109,7 @@ void setSolenoid(HalSolenoidHandle solenoid_port_handle, bool value, } int getPCMSolenoidBlackList(uint8_t module, int32_t* status) { - if (module >= NUM_MODULE_NUMBERS) { + if (module >= kNumPCMModules) { *status = PARAMETER_OUT_OF_RANGE; return 0; } @@ -118,7 +120,7 @@ int getPCMSolenoidBlackList(uint8_t module, int32_t* status) { return value; } bool getPCMSolenoidVoltageStickyFault(uint8_t module, int32_t* status) { - if (module >= NUM_MODULE_NUMBERS) { + if (module >= kNumPCMModules) { *status = PARAMETER_OUT_OF_RANGE; return false; } @@ -129,7 +131,7 @@ bool getPCMSolenoidVoltageStickyFault(uint8_t module, int32_t* status) { return value; } bool getPCMSolenoidVoltageFault(uint8_t module, int32_t* status) { - if (module >= NUM_MODULE_NUMBERS) { + if (module >= kNumPCMModules) { *status = PARAMETER_OUT_OF_RANGE; return false; } @@ -140,7 +142,7 @@ bool getPCMSolenoidVoltageFault(uint8_t module, int32_t* status) { return value; } void clearAllPCMStickyFaults_sol(uint8_t module, int32_t* status) { - if (module >= NUM_MODULE_NUMBERS) { + if (module >= kNumPCMModules) { *status = PARAMETER_OUT_OF_RANGE; return; }