diff --git a/hal/include/HAL/HAL.h b/hal/include/HAL/HAL.h index fd09567e21..1885c5c10f 100644 --- a/hal/include/HAL/HAL.h +++ b/hal/include/HAL/HAL.h @@ -150,12 +150,3 @@ void HAL_NetworkCommunicationObserveUserProgramTest(); uint32_t HAL_Report(uint8_t resource, uint8_t instanceNumber, uint8_t context = 0, const char* feature = nullptr); } - -// TODO: HACKS for now... -extern "C" { - -void NumericArrayResize(); -void RTSetCleanupProc(); -void EDVR_CreateReference(); -void Occur(); -} diff --git a/hal/include/HAL/cpp/Resource.h b/hal/include/HAL/cpp/Resource.h deleted file mode 100644 index 1a585948f5..0000000000 --- a/hal/include/HAL/cpp/Resource.h +++ /dev/null @@ -1,48 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-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 - -#include "../Errors.h" -#include "HAL/cpp/priority_mutex.h" - -// TODO: Replace this with something appropriate to avoid conflicts with -// wpilibC++ Resource class (which performs an essentially identical function). -namespace hal { - -/** - * The Resource class is a convenient way to track allocated resources. - * It tracks them as indicies in the range [0 .. elements - 1]. - * E.g. the library uses this to track hardware channel allocation. - * - * The Resource class does not allocate the hardware channels or other - * resources; it just tracks which indices were marked in use by - * Allocate and not yet freed by Free. - */ -class Resource { - public: - Resource(const Resource&) = delete; - Resource& operator=(const Resource&) = delete; - explicit Resource(uint32_t size); - virtual ~Resource() = default; - static void CreateResourceObject(Resource** r, uint32_t elements); - uint32_t Allocate(const char* resourceDesc); - uint32_t Allocate(uint32_t index, const char* resourceDesc); - void Free(uint32_t index); - - private: - std::vector m_isAllocated; - priority_recursive_mutex m_allocateLock; - - static priority_recursive_mutex m_createLock; -}; - -} // namespace hal diff --git a/hal/lib/athena/AnalogInput.cpp b/hal/lib/athena/AnalogInput.cpp index cd73c38bd1..ff96e2895d 100644 --- a/hal/lib/athena/AnalogInput.cpp +++ b/hal/lib/athena/AnalogInput.cpp @@ -236,23 +236,15 @@ int16_t HAL_GetAnalogValue(HAL_AnalogInputHandle analog_port_handle, *status = HAL_HANDLE_ERROR; return 0; } - int16_t value; - if (!HAL_CheckAnalogInputChannel(port->pin)) { - return 0; - } tAI::tReadSelect readSelect; readSelect.Channel = port->pin; readSelect.Averaged = false; - { - std::lock_guard sync(analogRegisterWindowMutex); - analogInputSystem->writeReadSelect(readSelect, status); - analogInputSystem->strobeLatchOutput(status); - value = (int16_t)analogInputSystem->readOutput(status); - } - - return value; + std::lock_guard sync(analogRegisterWindowMutex); + analogInputSystem->writeReadSelect(readSelect, status); + analogInputSystem->strobeLatchOutput(status); + return static_cast(analogInputSystem->readOutput(status)); } /** @@ -276,23 +268,14 @@ int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analog_port_handle, *status = HAL_HANDLE_ERROR; return 0; } - int32_t value; - if (!HAL_CheckAnalogInputChannel(port->pin)) { - return 0; - } - tAI::tReadSelect readSelect; readSelect.Channel = port->pin; readSelect.Averaged = true; - { - std::lock_guard sync(analogRegisterWindowMutex); - analogInputSystem->writeReadSelect(readSelect, status); - analogInputSystem->strobeLatchOutput(status); - value = (int32_t)analogInputSystem->readOutput(status); - } - - return value; + std::lock_guard sync(analogRegisterWindowMutex); + analogInputSystem->writeReadSelect(readSelect, status); + analogInputSystem->strobeLatchOutput(status); + return static_cast(analogInputSystem->readOutput(status)); } /** diff --git a/hal/lib/athena/DigitalInternal.cpp b/hal/lib/athena/DigitalInternal.cpp index 9e2cb78335..4f2b7bbf24 100644 --- a/hal/lib/athena/DigitalInternal.cpp +++ b/hal/lib/athena/DigitalInternal.cpp @@ -109,10 +109,9 @@ uint32_t remapMXPPWMChannel(uint32_t pin) { * If it's an analog trigger, determine the module from the high order routing * channel else do normal digital input remapping based on pin number (MXP) */ -extern "C++" bool remapDigitalSource(HAL_Handle digitalSourceHandle, - HAL_AnalogTriggerType analogTriggerType, - uint32_t& pin, uint8_t& module, - bool& analogTrigger) { +bool remapDigitalSource(HAL_Handle digitalSourceHandle, + HAL_AnalogTriggerType analogTriggerType, uint32_t& pin, + uint8_t& module, bool& analogTrigger) { if (isHandleType(digitalSourceHandle, HAL_HandleEnum::AnalogTrigger)) { // If handle passed, index is not negative uint32_t index = getHandleIndex(digitalSourceHandle); diff --git a/hal/lib/athena/HALAthena.cpp b/hal/lib/athena/HALAthena.cpp index 3225a145df..1732a64fd0 100644 --- a/hal/lib/athena/HALAthena.cpp +++ b/hal/lib/athena/HALAthena.cpp @@ -374,6 +374,7 @@ uint32_t HAL_Report(uint8_t resource, uint8_t instanceNumber, uint8_t context, } // TODO: HACKS +// No need for header definitions, as we should not run from user code. void NumericArrayResize() {} void RTSetCleanupProc() {} void EDVR_CreateReference() {} diff --git a/hal/lib/athena/cpp/Resource.cpp b/hal/lib/athena/cpp/Resource.cpp deleted file mode 100644 index 052b506fc7..0000000000 --- a/hal/lib/athena/cpp/Resource.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-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/cpp/Resource.h" - -#include - -#include "HAL/Errors.h" -#include "HAL/cpp/priority_mutex.h" - -namespace hal { - -priority_recursive_mutex Resource::m_createLock; - -/** - * Allocate storage for a new instance of Resource. - * Allocate a bool array of values that will get initialized to indicate that no - * resources have been allocated yet. The indicies of the resources are [0 .. - * elements - 1]. - */ -Resource::Resource(uint32_t elements) { - std::lock_guard sync(m_createLock); - m_isAllocated = std::vector(elements, false); -} - -/** - * Factory method to create a Resource allocation-tracker *if* needed. - * - * @param r -- address of the caller's Resource pointer. If *r == nullptr, this - * will construct a Resource and make *r point to it. If *r != nullptr, i.e. - * the caller already has a Resource instance, this won't do anything. - * @param elements -- the number of elements for this Resource allocator to - * track, that is, it will allocate resource numbers in the range - * [0 .. elements - 1]. - */ -/*static*/ void Resource::CreateResourceObject(Resource** r, - uint32_t elements) { - std::lock_guard sync(m_createLock); - if (*r == nullptr) { - *r = new Resource(elements); - } -} - -/** - * Allocate a resource. - * When a resource is requested, mark it allocated. In this case, a free - * resource value - * within the range is located and returned after it is marked allocated. - */ -uint32_t Resource::Allocate(const char* resourceDesc) { - std::lock_guard sync(m_allocateLock); - for (uint32_t i = 0; i < m_isAllocated.size(); i++) { - if (!m_isAllocated[i]) { - m_isAllocated[i] = true; - return i; - } - } - // TODO: wpi_setWPIErrorWithContext(NoAvailableResources, resourceDesc); - return ~0ul; -} - -/** - * Allocate a specific resource value. - * The user requests a specific resource value, i.e. channel number and it is - * verified unallocated, then returned. - */ -uint32_t Resource::Allocate(uint32_t index, const char* resourceDesc) { - std::lock_guard sync(m_allocateLock); - if (index >= m_isAllocated.size()) { - // TODO: wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc); - return ~0ul; - } - if (m_isAllocated[index]) { - // TODO: wpi_setWPIErrorWithContext(ResourceAlreadyAllocated, resourceDesc); - return ~0ul; - } - m_isAllocated[index] = true; - return index; -} - -/** - * Free an allocated resource. - * After a resource is no longer needed, for example a destructor is called for - * a channel assignment class, Free will release the resource value so it can - * be reused somewhere else in the program. - */ -void Resource::Free(uint32_t index) { - std::lock_guard sync(m_allocateLock); - if (index == ~0ul) return; - if (index >= m_isAllocated.size()) { - // TODO: wpi_setWPIError(NotAllocated); - return; - } - if (!m_isAllocated[index]) { - // TODO: wpi_setWPIError(NotAllocated); - return; - } - m_isAllocated[index] = false; -} - -} // namespace hal diff --git a/wpilibj/src/athena/cpp/lib/CompressorJNI.cpp b/wpilibj/src/athena/cpp/lib/CompressorJNI.cpp index 9c18f85cc6..6e27bf3816 100644 --- a/wpilibj/src/athena/cpp/lib/CompressorJNI.cpp +++ b/wpilibj/src/athena/cpp/lib/CompressorJNI.cpp @@ -23,8 +23,7 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_initializeCompressor( int32_t status = 0; auto handle = HAL_InitializeCompressor(module, &status); if (status == PARAMETER_OUT_OF_RANGE) { - //TODO: Move 63 to a constant (Thad will do) - ThrowBoundaryException(env, module, 0, 63); + ThrowBoundaryException(env, module, 0, HAL_GetNumPCMModules()); } return (jint)handle;