Prepends all HAL functions with HAL_ (#146)

This commit is contained in:
Thad House
2016-07-09 00:24:26 -07:00
committed by Peter Johnson
parent 5ad28d58ec
commit b637b9ee4c
162 changed files with 2855 additions and 2747 deletions

View File

@@ -7,16 +7,16 @@
#pragma once
enum AccelerometerRange {
kRange_2G = 0,
kRange_4G = 1,
kRange_8G = 2,
enum HAL_AccelerometerRange {
HAL_AccelerometerRange_k2G = 0,
HAL_AccelerometerRange_k4G = 1,
HAL_AccelerometerRange_k8G = 2,
};
extern "C" {
void setAccelerometerActive(bool);
void setAccelerometerRange(AccelerometerRange);
double getAccelerometerX();
double getAccelerometerY();
double getAccelerometerZ();
void HAL_SetAccelerometerActive(bool);
void HAL_SetAccelerometerRange(HAL_AccelerometerRange);
double HAL_GetAccelerometerX();
double HAL_GetAccelerometerY();
double HAL_GetAccelerometerZ();
}

View File

@@ -12,18 +12,20 @@
#include "Handles.h"
extern "C" {
bool isAccumulatorChannel(HalAnalogInputHandle analog_port_handle,
bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analog_port_handle,
int32_t* status);
void HAL_InitAccumulator(HAL_AnalogInputHandle analog_port_handle,
int32_t* status);
void HAL_ResetAccumulator(HAL_AnalogInputHandle analog_port_handle,
int32_t* status);
void initAccumulator(HalAnalogInputHandle analog_port_handle, int32_t* status);
void resetAccumulator(HalAnalogInputHandle analog_port_handle, int32_t* status);
void setAccumulatorCenter(HalAnalogInputHandle analog_port_handle,
int32_t center, int32_t* status);
void setAccumulatorDeadband(HalAnalogInputHandle analog_port_handle,
int32_t deadband, int32_t* status);
int64_t getAccumulatorValue(HalAnalogInputHandle analog_port_handle,
int32_t* status);
uint32_t getAccumulatorCount(HalAnalogInputHandle analog_port_handle,
int32_t* status);
void getAccumulatorOutput(HalAnalogInputHandle analog_port_handle,
int64_t* value, uint32_t* count, int32_t* status);
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analog_port_handle,
int32_t center, int32_t* status);
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analog_port_handle,
int32_t deadband, int32_t* status);
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analog_port_handle,
int32_t* status);
uint32_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analog_port_handle,
int32_t* status);
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analog_port_handle,
int64_t* value, uint32_t* count, int32_t* status);
}

View File

@@ -12,21 +12,22 @@
#include "HAL/Handles.h"
extern "C" {
HalGyroHandle initializeAnalogGyro(HalAnalogInputHandle handle,
int32_t* status);
void setupAnalogGyro(HalGyroHandle handle, int32_t* status);
void freeAnalogGyro(HalGyroHandle handle);
void setAnalogGyroParameters(HalGyroHandle handle,
float voltsPerDegreePerSecond, float offset,
uint32_t center, int32_t* status);
void setAnalogGyroVoltsPerDegreePerSecond(HalGyroHandle handle,
float voltsPerDegreePerSecond,
int32_t* status);
void resetAnalogGyro(HalGyroHandle handle, int32_t* status);
void calibrateAnalogGyro(HalGyroHandle handle, int32_t* status);
void setAnalogGyroDeadband(HalGyroHandle handle, float volts, int32_t* status);
float getAnalogGyroAngle(HalGyroHandle handle, int32_t* status);
double getAnalogGyroRate(HalGyroHandle handle, int32_t* status);
float getAnalogGyroOffset(HalGyroHandle handle, int32_t* status);
uint32_t getAnalogGyroCenter(HalGyroHandle handle, int32_t* status);
HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle handle,
int32_t* status);
void HAL_SetupAnalogGyro(HAL_GyroHandle handle, int32_t* status);
void HAL_FreeAnalogGyro(HAL_GyroHandle handle);
void HAL_SetAnalogGyroParameters(HAL_GyroHandle handle,
float voltsPerDegreePerSecond, float offset,
uint32_t center, int32_t* status);
void HAL_SetAnalogGyroVoltsPerDegreePerSecond(HAL_GyroHandle handle,
float voltsPerDegreePerSecond,
int32_t* status);
void HAL_ResetAnalogGyro(HAL_GyroHandle handle, int32_t* status);
void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status);
void HAL_SetAnalogGyroDeadband(HAL_GyroHandle handle, float volts,
int32_t* status);
float HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status);
double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status);
float HAL_GetAnalogGyroOffset(HAL_GyroHandle handle, int32_t* status);
uint32_t HAL_GetAnalogGyroCenter(HAL_GyroHandle handle, int32_t* status);
}

View File

@@ -13,34 +13,34 @@
extern "C" {
// Analog input functions
HalAnalogInputHandle initializeAnalogInputPort(HalPortHandle port_handle,
int32_t* status);
void freeAnalogInputPort(HalAnalogInputHandle analog_port_handle);
bool checkAnalogModule(uint8_t module);
bool checkAnalogInputChannel(uint32_t pin);
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle port_handle,
int32_t* status);
void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analog_port_handle);
bool HAL_CheckAnalogModule(uint8_t module);
bool HAL_CheckAnalogInputChannel(uint32_t pin);
void setAnalogSampleRate(double samplesPerSecond, int32_t* status);
float getAnalogSampleRate(int32_t* status);
void setAnalogAverageBits(HalAnalogInputHandle analog_port_handle,
uint32_t bits, int32_t* status);
uint32_t getAnalogAverageBits(HalAnalogInputHandle analog_port_handle,
int32_t* status);
void setAnalogOversampleBits(HalAnalogInputHandle analog_port_handle,
uint32_t bits, int32_t* status);
uint32_t getAnalogOversampleBits(HalAnalogInputHandle analog_port_handle,
int32_t* status);
int16_t getAnalogValue(HalAnalogInputHandle analog_port_handle,
int32_t* status);
int32_t getAnalogAverageValue(HalAnalogInputHandle analog_port_handle,
int32_t* status);
int32_t getAnalogVoltsToValue(HalAnalogInputHandle analog_port_handle,
double voltage, int32_t* status);
float getAnalogVoltage(HalAnalogInputHandle analog_port_handle,
int32_t* status);
float getAnalogAverageVoltage(HalAnalogInputHandle analog_port_handle,
int32_t* status);
uint32_t getAnalogLSBWeight(HalAnalogInputHandle analog_port_handle,
void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status);
float HAL_GetAnalogSampleRate(int32_t* status);
void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
uint32_t bits, int32_t* status);
uint32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
int32_t* status);
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
uint32_t bits, int32_t* status);
uint32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
int32_t* status);
int16_t HAL_GetAnalogValue(HAL_AnalogInputHandle analog_port_handle,
int32_t* status);
int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analog_port_handle,
int32_t* status);
int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analog_port_handle,
double voltage, int32_t* status);
float HAL_GetAnalogVoltage(HAL_AnalogInputHandle analog_port_handle,
int32_t* status);
float HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analog_port_handle,
int32_t* status);
uint32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analog_port_handle,
int32_t* status);
int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analog_port_handle,
int32_t* status);
int32_t getAnalogOffset(HalAnalogInputHandle analog_port_handle,
int32_t* status);
}

View File

@@ -12,12 +12,12 @@
#include "Handles.h"
extern "C" {
HalAnalogOutputHandle initializeAnalogOutputPort(HalPortHandle port_handle,
int32_t* status);
void freeAnalogOutputPort(HalAnalogOutputHandle analog_output_handle);
void setAnalogOutput(HalAnalogOutputHandle analog_output_handle, double voltage,
int32_t* status);
double getAnalogOutput(HalAnalogOutputHandle analog_output_handle,
int32_t* status);
bool checkAnalogOutputChannel(uint32_t pin);
HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(
HAL_PortHandle port_handle, int32_t* status);
void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analog_output_handle);
void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analog_output_handle,
double voltage, int32_t* status);
double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analog_output_handle,
int32_t* status);
bool HAL_CheckAnalogOutputChannel(uint32_t pin);
}

View File

@@ -11,31 +11,32 @@
#include "Handles.h"
enum AnalogTriggerType {
kInWindow = 0,
kState = 1,
kRisingPulse = 2,
kFallingPulse = 3
enum HAL_AnalogTriggerType {
HAL_Trigger_kInWindow = 0,
HAL_Trigger_kState = 1,
HAL_Trigger_kRisingPulse = 2,
HAL_Trigger_kFallingPulse = 3
};
extern "C" {
HalAnalogTriggerHandle initializeAnalogTrigger(HalAnalogInputHandle port_handle,
uint32_t* index,
int32_t* status);
void cleanAnalogTrigger(HalAnalogTriggerHandle analog_trigger_handle,
int32_t* status);
void setAnalogTriggerLimitsRaw(HalAnalogTriggerHandle analog_trigger_handle,
int32_t lower, int32_t upper, int32_t* status);
void setAnalogTriggerLimitsVoltage(HalAnalogTriggerHandle analog_trigger_handle,
double lower, double upper, int32_t* status);
void setAnalogTriggerAveraged(HalAnalogTriggerHandle analog_trigger_handle,
bool useAveragedValue, int32_t* status);
void setAnalogTriggerFiltered(HalAnalogTriggerHandle analog_trigger_handle,
bool useFilteredValue, int32_t* status);
bool getAnalogTriggerInWindow(HalAnalogTriggerHandle analog_trigger_handle,
int32_t* status);
bool getAnalogTriggerTriggerState(HalAnalogTriggerHandle analog_trigger_handle,
HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
HAL_AnalogInputHandle port_handle, uint32_t* index, int32_t* status);
void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analog_trigger_handle,
int32_t* status);
void HAL_SetAnalogTriggerLimitsRaw(
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t lower, int32_t upper,
int32_t* status);
void HAL_SetAnalogTriggerLimitsVoltage(
HAL_AnalogTriggerHandle analog_trigger_handle, double lower, double upper,
int32_t* status);
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analog_trigger_handle,
bool useAveragedValue, int32_t* status);
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analog_trigger_handle,
bool useFilteredValue, int32_t* status);
bool HAL_GetAnalogTriggerInWindow(HAL_AnalogTriggerHandle analog_trigger_handle,
int32_t* status);
bool getAnalogTriggerOutput(HalAnalogTriggerHandle analog_trigger_handle,
AnalogTriggerType type, int32_t* status);
bool HAL_GetAnalogTriggerTriggerState(
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t* status);
bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analog_trigger_handle,
HAL_AnalogTriggerType type, int32_t* status);
}

View File

@@ -12,32 +12,33 @@
#include "HAL/Handles.h"
extern "C" {
HalCompressorHandle initializeCompressor(uint8_t module, int32_t* status);
bool checkCompressorModule(uint8_t module);
HAL_CompressorHandle HAL_InitializeCompressor(uint8_t module, int32_t* status);
bool HAL_CheckCompressorModule(uint8_t module);
bool getCompressor(HalCompressorHandle compressor_handle, int32_t* status);
bool HAL_GetCompressor(HAL_CompressorHandle compressor_handle, int32_t* status);
void setClosedLoopControl(HalCompressorHandle compressor_handle, bool value,
int32_t* status);
bool getClosedLoopControl(HalCompressorHandle compressor_handle,
int32_t* status);
void HAL_SetClosedLoopControl(HAL_CompressorHandle compressor_handle,
bool value, int32_t* status);
bool HAL_GetClosedLoopControl(HAL_CompressorHandle compressor_handle,
int32_t* status);
bool getPressureSwitch(HalCompressorHandle compressor_handle, int32_t* status);
float getCompressorCurrent(HalCompressorHandle compressor_handle,
bool HAL_GetPressureSwitch(HAL_CompressorHandle compressor_handle,
int32_t* status);
bool getCompressorCurrentTooHighFault(HalCompressorHandle compressor_handle,
int32_t* status);
bool getCompressorCurrentTooHighStickyFault(
HalCompressorHandle compressor_handle, int32_t* status);
bool getCompressorShortedStickyFault(HalCompressorHandle compressor_handle,
int32_t* status);
bool getCompressorShortedFault(HalCompressorHandle compressor_handle,
float HAL_GetCompressorCurrent(HAL_CompressorHandle compressor_handle,
int32_t* status);
bool getCompressorNotConnectedStickyFault(HalCompressorHandle compressor_handle,
int32_t* status);
bool getCompressorNotConnectedFault(HalCompressorHandle compressor_handle,
int32_t* status);
void clearAllPCMStickyFaults(HalCompressorHandle compressor_handle,
int32_t* status);
bool HAL_GetCompressorCurrentTooHighFault(
HAL_CompressorHandle compressor_handle, int32_t* status);
bool HAL_GetCompressorCurrentTooHighStickyFault(
HAL_CompressorHandle compressor_handle, int32_t* status);
bool HAL_GetCompressorShortedStickyFault(HAL_CompressorHandle compressor_handle,
int32_t* status);
bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressor_handle,
int32_t* status);
bool HAL_GetCompressorNotConnectedStickyFault(
HAL_CompressorHandle compressor_handle, int32_t* status);
bool HAL_GetCompressorNotConnectedFault(HAL_CompressorHandle compressor_handle,
int32_t* status);
void HAL_ClearAllPCMStickyFaults(HAL_CompressorHandle compressor_handle,
int32_t* status);
}

View File

@@ -10,5 +10,5 @@
#include <stdint.h>
extern "C" {
int32_t HAL_getSystemClockTicksPerMicrosecond(void);
int32_t HAL_GetSystemClockTicksPerMicrosecond(void);
}

View File

@@ -12,50 +12,58 @@
#include "HAL/AnalogTrigger.h"
#include "HAL/Handles.h"
enum Mode {
kTwoPulse = 0,
kSemiperiod = 1,
kPulseLength = 2,
kExternalDirection = 3
enum HAL_Counter_Mode {
HAL_Counter_kTwoPulse = 0,
HAL_Counter_kSemiperiod = 1,
HAL_Counter_kPulseLength = 2,
HAL_Counter_kExternalDirection = 3
};
extern "C" {
HalCounterHandle initializeCounter(Mode mode, int32_t* index, int32_t* status);
void freeCounter(HalCounterHandle counter_handle, int32_t* status);
void setCounterAverageSize(HalCounterHandle counter_handle, int32_t size,
int32_t* status);
void setCounterUpSource(HalCounterHandle counter_handle,
HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType, int32_t* status);
void setCounterUpSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
bool fallingEdge, int32_t* status);
void clearCounterUpSource(HalCounterHandle counter_handle, int32_t* status);
void setCounterDownSource(HalCounterHandle counter_handle,
HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType, int32_t* status);
void setCounterDownSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
bool fallingEdge, int32_t* status);
void clearCounterDownSource(HalCounterHandle counter_handle, int32_t* status);
void setCounterUpDownMode(HalCounterHandle counter_handle, int32_t* status);
void setCounterExternalDirectionMode(HalCounterHandle counter_handle,
int32_t* status);
void setCounterSemiPeriodMode(HalCounterHandle counter_handle,
bool highSemiPeriod, int32_t* status);
void setCounterPulseLengthMode(HalCounterHandle counter_handle,
double threshold, int32_t* status);
int32_t getCounterSamplesToAverage(HalCounterHandle counter_handle,
int32_t* status);
void setCounterSamplesToAverage(HalCounterHandle counter_handle,
int samplesToAverage, int32_t* status);
void resetCounter(HalCounterHandle counter_handle, int32_t* status);
int32_t getCounter(HalCounterHandle counter_handle, int32_t* status);
double getCounterPeriod(HalCounterHandle counter_handle, int32_t* status);
void setCounterMaxPeriod(HalCounterHandle counter_handle, double maxPeriod,
int32_t* status);
void setCounterUpdateWhenEmpty(HalCounterHandle counter_handle, bool enabled,
HAL_CounterHandle HAL_InitializeCounter(HAL_Counter_Mode mode, int32_t* index,
int32_t* status);
void HAL_FreeCounter(HAL_CounterHandle counter_handle, int32_t* status);
void HAL_SetCounterAverageSize(HAL_CounterHandle counter_handle, int32_t size,
int32_t* status);
bool getCounterStopped(HalCounterHandle counter_handle, int32_t* status);
bool getCounterDirection(HalCounterHandle counter_handle, int32_t* status);
void setCounterReverseDirection(HalCounterHandle counter_handle,
bool reverseDirection, int32_t* status);
void HAL_SetCounterUpSource(HAL_CounterHandle counter_handle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status);
void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counter_handle,
bool risingEdge, bool fallingEdge,
int32_t* status);
void HAL_ClearCounterUpSource(HAL_CounterHandle counter_handle,
int32_t* status);
void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status);
void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counter_handle,
bool risingEdge, bool fallingEdge,
int32_t* status);
void HAL_ClearCounterDownSource(HAL_CounterHandle counter_handle,
int32_t* status);
void HAL_SetCounterUpDownMode(HAL_CounterHandle counter_handle,
int32_t* status);
void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counter_handle,
int32_t* status);
void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counter_handle,
bool highSemiPeriod, int32_t* status);
void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counter_handle,
double threshold, int32_t* status);
int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
int32_t* status);
void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
int samplesToAverage, int32_t* status);
void HAL_ResetCounter(HAL_CounterHandle counter_handle, int32_t* status);
int32_t HAL_GetCounter(HAL_CounterHandle counter_handle, int32_t* status);
double HAL_GetCounterPeriod(HAL_CounterHandle counter_handle, int32_t* status);
void HAL_SetCounterMaxPeriod(HAL_CounterHandle counter_handle, double maxPeriod,
int32_t* status);
void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counter_handle,
bool enabled, int32_t* status);
bool HAL_GetCounterStopped(HAL_CounterHandle counter_handle, int32_t* status);
bool HAL_GetCounterDirection(HAL_CounterHandle counter_handle, int32_t* status);
void HAL_SetCounterReverseDirection(HAL_CounterHandle counter_handle,
bool reverseDirection, int32_t* status);
}

View File

@@ -12,30 +12,31 @@
#include "Handles.h"
extern "C" {
HalDigitalHandle initializeDIOPort(HalPortHandle port_handle, uint8_t input,
int32_t* status);
void freeDIOPort(HalDigitalHandle dio_port_handle);
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle port_handle,
uint8_t input, int32_t* status);
void HAL_FreeDIOPort(HAL_DigitalHandle dio_port_handle);
HalDigitalPWMHandle allocateDigitalPWM(int32_t* status);
void freeDigitalPWM(HalDigitalPWMHandle pwmGenerator, int32_t* status);
void setDigitalPWMRate(double rate, int32_t* status);
void setDigitalPWMDutyCycle(HalDigitalPWMHandle pwmGenerator, double dutyCycle,
int32_t* status);
void setDigitalPWMOutputChannel(HalDigitalPWMHandle pwmGenerator, uint32_t pin,
int32_t* status);
HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status);
void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status);
void HAL_SetDigitalPWMRate(double rate, int32_t* status);
void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
double dutyCycle, int32_t* status);
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
uint32_t pin, int32_t* status);
void setDIO(HalDigitalHandle dio_port_handle, short value, int32_t* status);
bool getDIO(HalDigitalHandle dio_port_handle, int32_t* status);
bool getDIODirection(HalDigitalHandle dio_port_handle, int32_t* status);
void pulse(HalDigitalHandle dio_port_handle, double pulseLength,
int32_t* status);
bool isPulsing(HalDigitalHandle dio_port_handle, int32_t* status);
bool isAnyPulsing(int32_t* status);
void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, short value,
int32_t* status);
bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status);
bool HAL_GetDIODirection(HAL_DigitalHandle dio_port_handle, int32_t* status);
void HAL_Pulse(HAL_DigitalHandle dio_port_handle, double pulseLength,
int32_t* status);
bool HAL_IsPulsing(HAL_DigitalHandle dio_port_handle, int32_t* status);
bool HAL_IsAnyPulsing(int32_t* status);
void setFilterSelect(HalDigitalHandle dio_port_handle, int filter_index,
int32_t* status);
int getFilterSelect(HalDigitalHandle dio_port_handle, int32_t* status);
void HAL_SetFilterSelect(HAL_DigitalHandle dio_port_handle, int filter_index,
int32_t* status);
int HAL_GetFilterSelect(HAL_DigitalHandle dio_port_handle, int32_t* status);
void setFilterPeriod(int filter_index, uint32_t value, int32_t* status);
uint32_t getFilterPeriod(int filter_index, int32_t* status);
void HAL_SetFilterPeriod(int filter_index, uint32_t value, int32_t* status);
uint32_t HAL_GetFilterPeriod(int filter_index, int32_t* status);
}

View File

@@ -13,55 +13,64 @@
#include "HAL/Handles.h"
extern "C" {
enum EncoderIndexingType {
enum HAL_EncoderIndexingType {
HAL_kResetWhileHigh,
HAL_kResetWhileLow,
HAL_kResetOnFallingEdge,
HAL_kResetOnRisingEdge
};
enum EncoderEncodingType { HAL_Encoder_k1X, HAL_Encoder_k2X, HAL_Encoder_k4X };
enum HAL_EncoderEncodingType {
HAL_Encoder_k1X,
HAL_Encoder_k2X,
HAL_Encoder_k4X
};
HalEncoderHandle initializeEncoder(
HalHandle digitalSourceHandleA, AnalogTriggerType analogTriggerTypeA,
HalHandle digitalSourceHandleB, AnalogTriggerType analogTriggerTypeB,
bool reverseDirection, EncoderEncodingType encodingType, int32_t* status);
void freeEncoder(HalEncoderHandle encoder_handle, int32_t* status);
int32_t getEncoder(HalEncoderHandle encoder_handle, int32_t* status);
int32_t getEncoderRaw(HalEncoderHandle encoder_handle, int32_t* status);
int32_t getEncoderEncodingScale(HalEncoderHandle encoder_handle,
HAL_EncoderHandle HAL_InitializeEncoder(
HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
bool reverseDirection, HAL_EncoderEncodingType encodingType,
int32_t* status);
void HAL_FreeEncoder(HAL_EncoderHandle encoder_handle, int32_t* status);
int32_t HAL_GetEncoder(HAL_EncoderHandle encoder_handle, int32_t* status);
int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoder_handle, int32_t* status);
int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoder_handle,
int32_t* status);
void HAL_ResetEncoder(HAL_EncoderHandle encoder_handle, int32_t* status);
int32_t HAL_GetEncoderPeriod(HAL_EncoderHandle encoder_handle, int32_t* status);
void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoder_handle, double maxPeriod,
int32_t* status);
uint8_t HAL_GetEncoderStopped(HAL_EncoderHandle encoder_handle,
int32_t* status);
uint8_t HAL_GetEncoderDirection(HAL_EncoderHandle encoder_handle,
int32_t* status);
void resetEncoder(HalEncoderHandle encoder_handle, int32_t* status);
int32_t getEncoderPeriod(HalEncoderHandle encoder_handle, int32_t* status);
void setEncoderMaxPeriod(HalEncoderHandle encoder_handle, double maxPeriod,
int32_t* status);
uint8_t getEncoderStopped(HalEncoderHandle encoder_handle, int32_t* status);
uint8_t getEncoderDirection(HalEncoderHandle encoder_handle, int32_t* status);
double getEncoderDistance(HalEncoderHandle encoder_handle, int32_t* status);
double getEncoderRate(HalEncoderHandle encoder_handle, int32_t* status);
void setEncoderMinRate(HalEncoderHandle encoder_handle, double minRate,
int32_t* status);
void setEncoderDistancePerPulse(HalEncoderHandle encoder_handle,
double distancePerPulse, int32_t* status);
void setEncoderReverseDirection(HalEncoderHandle encoder_handle,
uint8_t reverseDirection, int32_t* status);
void setEncoderSamplesToAverage(HalEncoderHandle encoder_handle,
int32_t samplesToAverage, int32_t* status);
int32_t getEncoderSamplesToAverage(HalEncoderHandle encoder_handle,
int32_t* status);
double HAL_GetEncoderDistance(HAL_EncoderHandle encoder_handle,
int32_t* status);
double HAL_GetEncoderRate(HAL_EncoderHandle encoder_handle, int32_t* status);
void HAL_SetEncoderMinRate(HAL_EncoderHandle encoder_handle, double minRate,
int32_t* status);
void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoder_handle,
double distancePerPulse, int32_t* status);
void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoder_handle,
uint8_t reverseDirection, int32_t* status);
void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoder_handle,
int32_t samplesToAverage, int32_t* status);
int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoder_handle,
int32_t* status);
void setEncoderIndexSource(HalEncoderHandle encoder_handle,
HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType,
EncoderIndexingType type, int32_t* status);
void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoder_handle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
HAL_EncoderIndexingType type, int32_t* status);
int32_t getEncoderFPGAIndex(HalEncoderHandle encoder_handle, int32_t* status);
int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoder_handle,
int32_t* status);
double getEncoderDecodingScaleFactor(HalEncoderHandle encoder_handle,
int32_t* status);
double HAL_GetEncoderDecodingScaleFactor(HAL_EncoderHandle encoder_handle,
int32_t* status);
double getEncoderDistancePerPulse(HalEncoderHandle encoder_handle,
int32_t* status);
double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoder_handle,
int32_t* status);
EncoderEncodingType getEncoderEncodingType(HalEncoderHandle encoder_handle,
int32_t* status);
HAL_EncoderEncodingType HAL_GetEncoderEncodingType(
HAL_EncoderHandle encoder_handle, int32_t* status);
}

View File

@@ -53,7 +53,7 @@ namespace HALUsageReporting = nUsageReporting;
#define HALFRC_NetworkCommunication_DynamicType_Kinect_Joystick 24
#define HALFRC_NetworkCommunication_DynamicType_Kinect_Custom 25
struct HALControlWord {
struct HAL_ControlWord {
uint32_t enabled : 1;
uint32_t autonomous : 1;
uint32_t test : 1;
@@ -63,91 +63,92 @@ struct HALControlWord {
uint32_t control_reserved : 26;
};
enum HALAllianceStationID {
kHALAllianceStationID_red1,
kHALAllianceStationID_red2,
kHALAllianceStationID_red3,
kHALAllianceStationID_blue1,
kHALAllianceStationID_blue2,
kHALAllianceStationID_blue3,
enum HAL_AllianceStationID {
HAL_AllianceStationID_kRed1,
HAL_AllianceStationID_kRed2,
HAL_AllianceStationID_kRed3,
HAL_AllianceStationID_kBlue1,
HAL_AllianceStationID_kBlue2,
HAL_AllianceStationID_kBlue3,
};
/* The maximum number of axes that will be stored in a single HALJoystickAxes
* struct. This is used for allocating buffers, not bounds checking, since
* there are usually less axes in practice.
*/
static const size_t kMaxJoystickAxes = 12;
static const size_t kMaxJoystickPOVs = 12;
static constexpr size_t HAL_kMaxJoystickAxes = 12;
static constexpr size_t HAL_kMaxJoystickPOVs = 12;
struct HALJoystickAxes {
struct HAL_JoystickAxes {
uint16_t count;
float axes[kMaxJoystickAxes];
float axes[HAL_kMaxJoystickAxes];
};
struct HALJoystickPOVs {
struct HAL_JoystickPOVs {
uint16_t count;
int16_t povs[kMaxJoystickPOVs];
int16_t povs[HAL_kMaxJoystickPOVs];
};
struct HALJoystickButtons {
struct HAL_JoystickButtons {
uint32_t buttons;
uint8_t count;
};
struct HALJoystickDescriptor {
struct HAL_JoystickDescriptor {
uint8_t isXbox;
uint8_t type;
char name[256];
uint8_t axisCount;
uint8_t axisTypes[kMaxJoystickAxes];
uint8_t axisTypes[HAL_kMaxJoystickAxes];
uint8_t buttonCount;
uint8_t povCount;
};
extern "C" {
HalPortHandle getPort(uint8_t pin);
HalPortHandle getPortWithModule(uint8_t module, uint8_t pin);
const char* getHALErrorMessage(int32_t code);
HAL_PortHandle HAL_GetPort(uint8_t pin);
HAL_PortHandle HAL_GetPortWithModule(uint8_t module, uint8_t pin);
const char* HAL_GetErrorMessage(int32_t code);
uint16_t getFPGAVersion(int32_t* status);
uint32_t getFPGARevision(int32_t* status);
uint64_t getFPGATime(int32_t* status);
uint16_t HAL_GetFPGAVersion(int32_t* status);
uint32_t HAL_GetFPGARevision(int32_t* status);
uint64_t HAL_GetFPGATime(int32_t* status);
bool getFPGAButton(int32_t* status);
bool HAL_GetFPGAButton(int32_t* status);
int HALSetErrorData(const char* errors, int errorsLength, int wait_ms);
int HALSendError(int isError, int32_t errorCode, int isLVCode,
const char* details, const char* location,
const char* callStack, int printMsg);
int HAL_SetErrorData(const char* errors, int errorsLength, int wait_ms);
int HAL_SendError(int isError, int32_t errorCode, int isLVCode,
const char* details, const char* location,
const char* callStack, int printMsg);
int HALGetControlWord(HALControlWord* data);
int HALGetAllianceStation(enum HALAllianceStationID* allianceStation);
int HALGetJoystickAxes(uint8_t joystickNum, HALJoystickAxes* axes);
int HALGetJoystickPOVs(uint8_t joystickNum, HALJoystickPOVs* povs);
int HALGetJoystickButtons(uint8_t joystickNum, HALJoystickButtons* buttons);
int HALGetJoystickDescriptor(uint8_t joystickNum, HALJoystickDescriptor* desc);
int HALGetJoystickIsXbox(uint8_t joystickNum);
int HALGetJoystickType(uint8_t joystickNum);
char* HALGetJoystickName(uint8_t joystickNum);
int HALGetJoystickAxisType(uint8_t joystickNum, uint8_t axis);
int HALSetJoystickOutputs(uint8_t joystickNum, uint32_t outputs,
uint16_t leftRumble, uint16_t rightRumble);
int HALGetMatchTime(float* matchTime);
int HAL_GetControlWord(HAL_ControlWord* data);
int HAL_GetAllianceStation(enum HAL_AllianceStationID* allianceStation);
int HAL_GetJoystickAxes(uint8_t joystickNum, HAL_JoystickAxes* axes);
int HAL_GetJoystickPOVs(uint8_t joystickNum, HAL_JoystickPOVs* povs);
int HAL_GetJoystickButtons(uint8_t joystickNum, HAL_JoystickButtons* buttons);
int HAL_GetJoystickDescriptor(uint8_t joystickNum,
HAL_JoystickDescriptor* desc);
int HAL_GetJoystickIsXbox(uint8_t joystickNum);
int HAL_GetJoystickType(uint8_t joystickNum);
char* HAL_GetJoystickName(uint8_t joystickNum);
int HAL_GetJoystickAxisType(uint8_t joystickNum, uint8_t axis);
int HAL_SetJoystickOutputs(uint8_t joystickNum, uint32_t outputs,
uint16_t leftRumble, uint16_t rightRumble);
int HAL_GetMatchTime(float* matchTime);
void HALSetNewDataSem(MULTIWAIT_ID sem);
void HAL_SetNewDataSem(MULTIWAIT_ID sem);
bool HALGetSystemActive(int32_t* status);
bool HALGetBrownedOut(int32_t* status);
bool HAL_GetSystemActive(int32_t* status);
bool HAL_GetBrownedOut(int32_t* status);
int HALInitialize(int mode = 0);
void HALNetworkCommunicationObserveUserProgramStarting();
void HALNetworkCommunicationObserveUserProgramDisabled();
void HALNetworkCommunicationObserveUserProgramAutonomous();
void HALNetworkCommunicationObserveUserProgramTeleop();
void HALNetworkCommunicationObserveUserProgramTest();
int HAL_Initialize(int mode = 0);
void HAL_NetworkCommunicationObserveUserProgramStarting();
void HAL_NetworkCommunicationObserveUserProgramDisabled();
void HAL_NetworkCommunicationObserveUserProgramAutonomous();
void HAL_NetworkCommunicationObserveUserProgramTeleop();
void HAL_NetworkCommunicationObserveUserProgramTest();
uint32_t HALReport(uint8_t resource, uint8_t instanceNumber,
uint8_t context = 0, const char* feature = nullptr);
uint32_t HAL_Report(uint8_t resource, uint8_t instanceNumber,
uint8_t context = 0, const char* feature = nullptr);
}
// TODO: HACKS for now...

View File

@@ -9,36 +9,36 @@
#include <stdint.h>
#define HAL_INVALID_HANDLE 0
#define HAL_kInvalidHandle 0
typedef int32_t HalHandle;
typedef int32_t HAL_Handle;
typedef HalHandle HalPortHandle;
typedef HAL_Handle HAL_PortHandle;
typedef HalHandle HalInterruptHandle;
typedef HAL_Handle HAL_InterruptHandle;
typedef HalHandle HalNotifierHandle;
typedef HAL_Handle HAL_NotifierHandle;
typedef HalHandle HalAnalogOutputHandle;
typedef HAL_Handle HAL_AnalogOutputHandle;
typedef HalHandle HalAnalogInputHandle;
typedef HAL_Handle HAL_AnalogInputHandle;
typedef HalHandle HalAnalogTriggerHandle;
typedef HAL_Handle HAL_AnalogTriggerHandle;
typedef HalHandle HalRelayHandle;
typedef HAL_Handle HAL_RelayHandle;
typedef HalHandle HalDigitalHandle;
typedef HAL_Handle HAL_DigitalHandle;
typedef HalHandle HalDigitalPWMHandle;
typedef HAL_Handle HAL_DigitalPWMHandle;
typedef HalHandle HalCounterHandle;
typedef HAL_Handle HAL_CounterHandle;
typedef HalHandle HalCompressorHandle;
typedef HAL_Handle HAL_CompressorHandle;
typedef HalHandle HalSolenoidHandle;
typedef HAL_Handle HAL_SolenoidHandle;
typedef HalHandle HalFPGAEncoderHandle;
typedef HAL_Handle HAL_FPGAEncoderHandle;
typedef HalHandle HalEncoderHandle;
typedef HAL_Handle HAL_EncoderHandle;
typedef HalHandle HalGyroHandle;
typedef HAL_Handle HAL_GyroHandle;

View File

@@ -10,13 +10,13 @@
#include <stdint.h>
extern "C" {
void i2CInitialize(uint8_t port, int32_t* status);
int32_t i2CTransaction(uint8_t port, uint8_t deviceAddress, uint8_t* dataToSend,
uint8_t sendSize, uint8_t* dataReceived,
uint8_t receiveSize);
int32_t i2CWrite(uint8_t port, uint8_t deviceAddress, uint8_t* dataToSend,
uint8_t sendSize);
int32_t i2CRead(uint8_t port, uint8_t deviceAddress, uint8_t* buffer,
uint8_t count);
void i2CClose(uint8_t port);
void HAL_I2CInitialize(uint8_t port, int32_t* status);
int32_t HAL_I2CTransaction(uint8_t port, uint8_t deviceAddress,
uint8_t* dataToSend, uint8_t sendSize,
uint8_t* dataReceived, uint8_t receiveSize);
int32_t HAL_I2CWrite(uint8_t port, uint8_t deviceAddress, uint8_t* dataToSend,
uint8_t sendSize);
int32_t HAL_I2CRead(uint8_t port, uint8_t deviceAddress, uint8_t* buffer,
uint8_t count);
void HAL_I2CClose(uint8_t port);
}

View File

@@ -16,24 +16,28 @@ extern "C" {
typedef void (*InterruptHandlerFunction)(uint32_t interruptAssertedMask,
void* param);
HalInterruptHandle initializeInterrupts(bool watcher, int32_t* status);
void cleanInterrupts(HalInterruptHandle interrupt_handle, int32_t* status);
HAL_InterruptHandle HAL_InitializeInterrupts(bool watcher, int32_t* status);
void HAL_CleanInterrupts(HAL_InterruptHandle interrupt_handle, int32_t* status);
uint32_t waitForInterrupt(HalInterruptHandle interrupt_handle, double timeout,
bool ignorePrevious, int32_t* status);
void enableInterrupts(HalInterruptHandle interrupt_handle, int32_t* status);
void disableInterrupts(HalInterruptHandle interrupt_handle, int32_t* status);
double readRisingTimestamp(HalInterruptHandle interrupt_handle,
int32_t* status);
double readFallingTimestamp(HalInterruptHandle interrupt_handle,
int32_t* status);
void requestInterrupts(HalInterruptHandle interrupt_handle,
HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType, int32_t* status);
void attachInterruptHandler(HalInterruptHandle interrupt_handle,
InterruptHandlerFunction handler, void* param,
int32_t* status);
void setInterruptUpSourceEdge(HalInterruptHandle interrupt_handle,
bool risingEdge, bool fallingEdge,
uint32_t HAL_WaitForInterrupt(HAL_InterruptHandle interrupt_handle,
double timeout, bool ignorePrevious,
int32_t* status);
void HAL_EnableInterrupts(HAL_InterruptHandle interrupt_handle,
int32_t* status);
void HAL_DisableInterrupts(HAL_InterruptHandle interrupt_handle,
int32_t* status);
double HAL_ReadRisingTimestamp(HAL_InterruptHandle interrupt_handle,
int32_t* status);
double HAL_ReadFallingTimestamp(HAL_InterruptHandle interrupt_handle,
int32_t* status);
void HAL_RequestInterrupts(HAL_InterruptHandle interrupt_handle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status);
void HAL_AttachInterruptHandler(HAL_InterruptHandle interrupt_handle,
InterruptHandlerFunction handler, void* param,
int32_t* status);
void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interrupt_handle,
bool risingEdge, bool fallingEdge,
int32_t* status);
}

View File

@@ -12,11 +12,11 @@
#include "Handles.h"
extern "C" {
HalNotifierHandle initializeNotifier(void (*process)(uint64_t, void*),
void* param, int32_t* status);
void cleanNotifier(HalNotifierHandle notifier_handle, int32_t* status);
void* getNotifierParam(HalNotifierHandle notifier_handle, int32_t* status);
void updateNotifierAlarm(HalNotifierHandle notifier_handle,
uint64_t triggerTime, int32_t* status);
void stopNotifierAlarm(HalNotifierHandle notifier_handle, int32_t* status);
HAL_NotifierHandle HAL_InitializeNotifier(void (*process)(uint64_t, void*),
void* param, int32_t* status);
void HAL_CleanNotifier(HAL_NotifierHandle notifier_handle, int32_t* status);
void* HAL_GetNotifierParam(HAL_NotifierHandle notifier_handle, int32_t* status);
void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifier_handle,
uint64_t triggerTime, int32_t* status);
void HAL_StopNotifierAlarm(HAL_NotifierHandle notifier_handle, int32_t* status);
}

View File

@@ -10,13 +10,14 @@
#include <stdint.h>
extern "C" {
void initializePDP(uint8_t module);
double getPDPTemperature(uint8_t module, int32_t* status);
double getPDPVoltage(uint8_t module, int32_t* status);
double getPDPChannelCurrent(uint8_t module, uint8_t channel, int32_t* status);
double getPDPTotalCurrent(uint8_t module, int32_t* status);
double getPDPTotalPower(uint8_t module, int32_t* status);
double getPDPTotalEnergy(uint8_t module, int32_t* status);
void resetPDPTotalEnergy(uint8_t module, int32_t* status);
void clearPDPStickyFaults(uint8_t module, int32_t* status);
void HAL_InitializePDP(uint8_t module);
double HAL_GetPDPTemperature(uint8_t module, int32_t* status);
double HAL_GetPDPVoltage(uint8_t module, int32_t* status);
double HAL_GetPDPChannelCurrent(uint8_t module, uint8_t channel,
int32_t* status);
double HAL_GetPDPTotalCurrent(uint8_t module, int32_t* status);
double HAL_GetPDPTotalPower(uint8_t module, int32_t* status);
double HAL_GetPDPTotalEnergy(uint8_t module, int32_t* status);
void HAL_ResetPDPTotalEnergy(uint8_t module, int32_t* status);
void HAL_ClearPDPStickyFaults(uint8_t module, int32_t* status);
}

View File

@@ -12,36 +12,39 @@
#include "HAL/Handles.h"
extern "C" {
HalDigitalHandle initializePWMPort(HalPortHandle port_handle, int32_t* status);
void freePWMPort(HalDigitalHandle pwm_port_handle, int32_t* status);
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle port_handle,
int32_t* status);
void HAL_FreePWMPort(HAL_DigitalHandle pwm_port_handle, int32_t* status);
bool checkPWMChannel(uint8_t pin);
bool HAL_CheckPWMChannel(uint8_t pin);
void setPWMConfig(HalDigitalHandle pwm_port_handle, double maxPwm,
double deadbandMaxPwm, double centerPwm,
double deadbandMinPwm, double minPwm, int32_t* status);
void setPWMConfigRaw(HalDigitalHandle pwm_port_handle, int32_t maxPwm,
int32_t deadbandMaxPwm, int32_t centerPwm,
int32_t deadbandMinPwm, int32_t minPwm, int32_t* status);
void getPWMConfigRaw(HalDigitalHandle pwm_port_handle, int32_t* maxPwm,
int32_t* deadbandMaxPwm, int32_t* centerPwm,
int32_t* deadbandMinPwm, int32_t* minPwm, int32_t* status);
void setPWMEliminateDeadband(HalDigitalHandle pwm_port_handle,
uint8_t eliminateDeadband, int32_t* status);
uint8_t getPWMEliminateDeadband(HalDigitalHandle pwm_port_handle,
int32_t* status);
void setPWMRaw(HalDigitalHandle pwm_port_handle, uint16_t value,
int32_t* status);
void setPWMSpeed(HalDigitalHandle pwm_port_handle, float speed,
int32_t* status);
void setPWMPosition(HalDigitalHandle pwm_port_handle, float position,
int32_t* status);
void setPWMDisabled(HalDigitalHandle pwm_port_handle, int32_t* status);
uint16_t getPWMRaw(HalDigitalHandle pwm_port_handle, int32_t* status);
float getPWMSpeed(HalDigitalHandle pwm_port_handle, int32_t* status);
float getPWMPosition(HalDigitalHandle pwm_port_handle, int32_t* status);
void latchPWMZero(HalDigitalHandle pwm_port_handle, int32_t* status);
void setPWMPeriodScale(HalDigitalHandle pwm_port_handle, uint32_t squelchMask,
int32_t* status);
uint16_t getLoopTiming(int32_t* status);
void HAL_SetPWMConfig(HAL_DigitalHandle pwm_port_handle, double maxPwm,
double deadbandMaxPwm, double centerPwm,
double deadbandMinPwm, double minPwm, int32_t* status);
void HAL_SetPWMConfigRaw(HAL_DigitalHandle pwm_port_handle, int32_t maxPwm,
int32_t deadbandMaxPwm, int32_t centerPwm,
int32_t deadbandMinPwm, int32_t minPwm,
int32_t* status);
void HAL_GetPWMConfigRaw(HAL_DigitalHandle pwm_port_handle, int32_t* maxPwm,
int32_t* deadbandMaxPwm, int32_t* centerPwm,
int32_t* deadbandMinPwm, int32_t* minPwm,
int32_t* status);
void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
uint8_t eliminateDeadband, int32_t* status);
uint8_t HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
int32_t* status);
void HAL_SetPWMRaw(HAL_DigitalHandle pwm_port_handle, uint16_t value,
int32_t* status);
void HAL_SetPWMSpeed(HAL_DigitalHandle pwm_port_handle, float speed,
int32_t* status);
void HAL_SetPWMPosition(HAL_DigitalHandle pwm_port_handle, float position,
int32_t* status);
void HAL_SetPWMDisabled(HAL_DigitalHandle pwm_port_handle, int32_t* status);
uint16_t HAL_GetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t* status);
float HAL_GetPWMSpeed(HAL_DigitalHandle pwm_port_handle, int32_t* status);
float HAL_GetPWMPosition(HAL_DigitalHandle pwm_port_handle, int32_t* status);
void HAL_LatchPWMZero(HAL_DigitalHandle pwm_port_handle, int32_t* status);
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwm_port_handle,
uint32_t squelchMask, int32_t* status);
uint16_t HAL_GetLoopTiming(int32_t* status);
}

View File

@@ -10,23 +10,23 @@
#include <stdint.h>
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_getNumPDPChannels(void);
int32_t HAL_getNumCanTalons(void);
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_GetNumPDPChannels(void);
int32_t HAL_GetNumCanTalons(void);
}

View File

@@ -10,18 +10,18 @@
#include <stdint.h>
extern "C" {
float getVinVoltage(int32_t* status);
float getVinCurrent(int32_t* status);
float getUserVoltage6V(int32_t* status);
float getUserCurrent6V(int32_t* status);
bool getUserActive6V(int32_t* status);
int getUserCurrentFaults6V(int32_t* status);
float getUserVoltage5V(int32_t* status);
float getUserCurrent5V(int32_t* status);
bool getUserActive5V(int32_t* status);
int getUserCurrentFaults5V(int32_t* status);
float getUserVoltage3V3(int32_t* status);
float getUserCurrent3V3(int32_t* status);
bool getUserActive3V3(int32_t* status);
int getUserCurrentFaults3V3(int32_t* status);
float HAL_GetVinVoltage(int32_t* status);
float HAL_GetVinCurrent(int32_t* status);
float HAL_GetUserVoltage6V(int32_t* status);
float HAL_GetUserCurrent6V(int32_t* status);
bool HAL_GetUserActive6V(int32_t* status);
int HAL_GetUserCurrentFaults6V(int32_t* status);
float HAL_GetUserVoltage5V(int32_t* status);
float HAL_GetUserCurrent5V(int32_t* status);
bool HAL_GetUserActive5V(int32_t* status);
int HAL_GetUserCurrentFaults5V(int32_t* status);
float HAL_GetUserVoltage3V3(int32_t* status);
float HAL_GetUserCurrent3V3(int32_t* status);
bool HAL_GetUserActive3V3(int32_t* status);
int HAL_GetUserCurrentFaults3V3(int32_t* status);
}

View File

@@ -12,12 +12,12 @@
#include "Handles.h"
extern "C" {
HalRelayHandle initializeRelayPort(HalPortHandle port_handle, uint8_t fwd,
int32_t* status);
void freeRelayPort(HalRelayHandle relay_port_handle);
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle port_handle, uint8_t fwd,
int32_t* status);
void HAL_FreeRelayPort(HAL_RelayHandle relay_port_handle);
bool checkRelayChannel(uint8_t pin);
bool HAL_CheckRelayChannel(uint8_t pin);
void setRelay(HalRelayHandle relay_port_handle, bool on, int32_t* status);
bool getRelay(HalRelayHandle relay_port_handle, int32_t* status);
void HAL_SetRelay(HAL_RelayHandle relay_port_handle, bool on, int32_t* status);
bool HAL_GetRelay(HAL_RelayHandle relay_port_handle, int32_t* status);
}

View File

@@ -14,33 +14,34 @@
priority_recursive_mutex& spiGetSemaphore(uint8_t port);
extern "C" {
void spiInitialize(uint8_t port, int32_t* status);
int32_t spiTransaction(uint8_t port, uint8_t* dataToSend, uint8_t* dataReceived,
uint8_t size);
int32_t spiWrite(uint8_t port, uint8_t* dataToSend, uint8_t sendSize);
int32_t spiRead(uint8_t port, uint8_t* buffer, uint8_t count);
void spiClose(uint8_t port);
void spiSetSpeed(uint8_t port, uint32_t speed);
void spiSetOpts(uint8_t port, int msb_first, int sample_on_trailing,
int clk_idle_high);
void spiSetChipSelectActiveHigh(uint8_t port, int32_t* status);
void spiSetChipSelectActiveLow(uint8_t port, int32_t* status);
int32_t spiGetHandle(uint8_t port);
void spiSetHandle(uint8_t port, int32_t handle);
void HAL_SpiInitialize(uint8_t port, int32_t* status);
int32_t HAL_SpiTransaction(uint8_t port, uint8_t* dataToSend,
uint8_t* dataReceived, uint8_t size);
int32_t HAL_SpiWrite(uint8_t port, uint8_t* dataToSend, uint8_t sendSize);
int32_t HAL_SpiRead(uint8_t port, uint8_t* buffer, uint8_t count);
void HAL_SpiClose(uint8_t port);
void HAL_SpiSetSpeed(uint8_t port, uint32_t speed);
void HAL_SpiSetOpts(uint8_t port, int msb_first, int sample_on_trailing,
int clk_idle_high);
void HAL_SpiSetChipSelectActiveHigh(uint8_t port, int32_t* status);
void HAL_SpiSetChipSelectActiveLow(uint8_t port, int32_t* status);
int32_t HAL_SpiGetHandle(uint8_t port);
void HAL_SpiSetHandle(uint8_t port, int32_t handle);
void spiInitAccumulator(uint8_t port, uint32_t period, uint32_t cmd,
uint8_t xfer_size, uint32_t valid_mask,
uint32_t valid_value, uint8_t data_shift,
uint8_t data_size, bool is_signed, bool big_endian,
int32_t* status);
void spiFreeAccumulator(uint8_t port, int32_t* status);
void spiResetAccumulator(uint8_t port, int32_t* status);
void spiSetAccumulatorCenter(uint8_t port, int32_t center, int32_t* status);
void spiSetAccumulatorDeadband(uint8_t port, int32_t deadband, int32_t* status);
int32_t spiGetAccumulatorLastValue(uint8_t port, int32_t* status);
int64_t spiGetAccumulatorValue(uint8_t port, int32_t* status);
uint32_t spiGetAccumulatorCount(uint8_t port, int32_t* status);
double spiGetAccumulatorAverage(uint8_t port, int32_t* status);
void spiGetAccumulatorOutput(uint8_t port, int64_t* value, uint32_t* count,
int32_t* status);
void HAL_SpiInitAccumulator(uint8_t port, uint32_t period, uint32_t cmd,
uint8_t xfer_size, uint32_t valid_mask,
uint32_t valid_value, uint8_t data_shift,
uint8_t data_size, bool is_signed, bool big_endian,
int32_t* status);
void HAL_SpiFreeAccumulator(uint8_t port, int32_t* status);
void HAL_SpiResetAccumulator(uint8_t port, int32_t* status);
void HAL_SpiSetAccumulatorCenter(uint8_t port, int32_t center, int32_t* status);
void HAL_SpiSetAccumulatorDeadband(uint8_t port, int32_t deadband,
int32_t* status);
int32_t HAL_SpiGetAccumulatorLastValue(uint8_t port, int32_t* status);
int64_t HAL_SpiGetAccumulatorValue(uint8_t port, int32_t* status);
uint32_t HAL_SpiGetAccumulatorCount(uint8_t port, int32_t* status);
double HAL_SpiGetAccumulatorAverage(uint8_t port, int32_t* status);
void HAL_SpiGetAccumulatorOutput(uint8_t port, int64_t* value, uint32_t* count,
int32_t* status);
}

View File

@@ -15,14 +15,14 @@ typedef priority_condition_variable* MULTIWAIT_ID;
typedef priority_condition_variable::native_handle_type NATIVE_MULTIWAIT_ID;
extern "C" {
MUTEX_ID initializeMutexNormal();
void deleteMutex(MUTEX_ID sem);
void takeMutex(MUTEX_ID sem);
bool tryTakeMutex(MUTEX_ID sem);
void giveMutex(MUTEX_ID sem);
MUTEX_ID HAL_InitializeMutexNormal();
void HAL_DeleteMutex(MUTEX_ID sem);
void HAL_TakeMutex(MUTEX_ID sem);
bool HAL_TryTakeMutex(MUTEX_ID sem);
void HAL_GiveMutex(MUTEX_ID sem);
MULTIWAIT_ID initializeMultiWait();
void deleteMultiWait(MULTIWAIT_ID sem);
void takeMultiWait(MULTIWAIT_ID sem, MUTEX_ID m);
void giveMultiWait(MULTIWAIT_ID sem);
MULTIWAIT_ID HAL_InitializeMultiWait();
void HAL_DeleteMultiWait(MULTIWAIT_ID sem);
void HAL_TakeMultiWait(MULTIWAIT_ID sem, MUTEX_ID m);
void HAL_GiveMultiWait(MULTIWAIT_ID sem);
}

View File

@@ -10,23 +10,25 @@
#include <stdint.h>
extern "C" {
void serialInitializePort(uint8_t port, int32_t* status);
void serialSetBaudRate(uint8_t port, uint32_t baud, int32_t* status);
void serialSetDataBits(uint8_t port, uint8_t bits, int32_t* status);
void serialSetParity(uint8_t port, uint8_t parity, int32_t* status);
void serialSetStopBits(uint8_t port, uint8_t stopBits, int32_t* status);
void serialSetWriteMode(uint8_t port, uint8_t mode, int32_t* status);
void serialSetFlowControl(uint8_t port, uint8_t flow, int32_t* status);
void serialSetTimeout(uint8_t port, float timeout, int32_t* status);
void serialEnableTermination(uint8_t port, char terminator, int32_t* status);
void serialDisableTermination(uint8_t port, int32_t* status);
void serialSetReadBufferSize(uint8_t port, uint32_t size, int32_t* status);
void serialSetWriteBufferSize(uint8_t port, uint32_t size, int32_t* status);
int32_t serialGetBytesReceived(uint8_t port, int32_t* status);
uint32_t serialRead(uint8_t port, char* buffer, int32_t count, int32_t* status);
uint32_t serialWrite(uint8_t port, const char* buffer, int32_t count,
int32_t* status);
void serialFlush(uint8_t port, int32_t* status);
void serialClear(uint8_t port, int32_t* status);
void serialClose(uint8_t port, int32_t* status);
void HAL_SerialInitializePort(uint8_t port, int32_t* status);
void HAL_SerialSetBaudRate(uint8_t port, uint32_t baud, int32_t* status);
void HAL_SerialSetDataBits(uint8_t port, uint8_t bits, int32_t* status);
void HAL_SerialSetParity(uint8_t port, uint8_t parity, int32_t* status);
void HAL_SerialSetStopBits(uint8_t port, uint8_t stopBits, int32_t* status);
void HAL_SerialSetWriteMode(uint8_t port, uint8_t mode, int32_t* status);
void HAL_SerialSetFlowControl(uint8_t port, uint8_t flow, int32_t* status);
void HAL_SerialSetTimeout(uint8_t port, float timeout, int32_t* status);
void HAL_SerialEnableTermination(uint8_t port, char terminator,
int32_t* status);
void HAL_SerialDisableTermination(uint8_t port, int32_t* status);
void HAL_SerialSetReadBufferSize(uint8_t port, uint32_t size, int32_t* status);
void HAL_SerialSetWriteBufferSize(uint8_t port, uint32_t size, int32_t* status);
int32_t HAL_SerialGetBytesReceived(uint8_t port, int32_t* status);
uint32_t HAL_SerialRead(uint8_t port, char* buffer, int32_t count,
int32_t* status);
uint32_t HAL_SerialWrite(uint8_t port, const char* buffer, int32_t count,
int32_t* status);
void HAL_SerialFlush(uint8_t port, int32_t* status);
void HAL_SerialClear(uint8_t port, int32_t* status);
void HAL_SerialClose(uint8_t port, int32_t* status);
}

View File

@@ -12,18 +12,18 @@
#include "Handles.h"
extern "C" {
HalSolenoidHandle initializeSolenoidPort(HalPortHandle port_handle,
int32_t* status);
void freeSolenoidPort(HalSolenoidHandle solenoid_port_handle);
bool checkSolenoidModule(uint8_t module);
HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle port_handle,
int32_t* status);
void HAL_FreeSolenoidPort(HAL_SolenoidHandle solenoid_port_handle);
bool HAL_CheckSolenoidModule(uint8_t module);
bool getSolenoid(HalSolenoidHandle solenoid_port_handle, int32_t* status);
uint8_t getAllSolenoids(uint8_t module, int32_t* status);
void setSolenoid(HalSolenoidHandle solenoid_port_handle, bool value,
int32_t* status);
bool HAL_GetSolenoid(HAL_SolenoidHandle solenoid_port_handle, int32_t* status);
uint8_t HAL_GetAllSolenoids(uint8_t module, int32_t* status);
void HAL_SetSolenoid(HAL_SolenoidHandle solenoid_port_handle, bool value,
int32_t* status);
int getPCMSolenoidBlackList(uint8_t module, int32_t* status);
bool getPCMSolenoidVoltageStickyFault(uint8_t module, int32_t* status);
bool getPCMSolenoidVoltageFault(uint8_t module, int32_t* status);
void clearAllPCMStickyFaults_sol(uint8_t module, int32_t* status);
int HAL_GetPCMSolenoidBlackList(uint8_t module, int32_t* status);
bool HAL_GetPCMSolenoidVoltageStickyFault(uint8_t module, int32_t* status);
bool HAL_GetPCMSolenoidVoltageFault(uint8_t module, int32_t* status);
void HAL_ClearAllPCMStickyFaults_sol(uint8_t module, int32_t* status);
}

View File

@@ -28,9 +28,9 @@ extern "C" {
// Note: These constants used to be declared extern and were defined in
// Task.cpp. This caused issues with the JNI bindings for java, and so the
// instantiations were moved here.
const int32_t HAL_taskLib_ILLEGAL_PRIORITY = 22; // 22 is EINVAL
const int32_t HAL_TaskLib_ILLEGAL_PRIORITY = 22; // 22 is EINVAL
STATUS verifyTaskID(TASK task);
STATUS setTaskPriority(TASK task, int priority); // valid priority [1..99]
STATUS getTaskPriority(TASK task, int* priority);
STATUS HAL_VerifyTaskID(TASK task);
STATUS HAL_SetTaskPriority(TASK task, int priority); // valid priority [1..99]
STATUS HAL_GetTaskPriority(TASK task, int* priority);
}

View File

@@ -13,6 +13,7 @@
#include <stdint.h>
#include "ChipObject.h"
#include "HAL/HAL.h"
// The 7-bit I2C address with a 0 "send" bit
static const uint8_t kSendAddress = (0x1c << 1) | 0;
@@ -25,7 +26,7 @@ static const uint8_t kControlStart = 2;
static const uint8_t kControlStop = 4;
static tAccel* accel = 0;
static AccelerometerRange accelerometerRange;
static HAL_AccelerometerRange accelerometerRange;
// Register addresses
enum Register {
@@ -73,8 +74,6 @@ enum Register {
kReg_OffZ = 0x31
};
extern "C" uint32_t getFPGATime(int32_t* status);
static void writeRegister(Register reg, uint8_t data);
static uint8_t readRegister(Register reg);
@@ -110,9 +109,9 @@ static void writeRegister(Register reg, uint8_t data) {
accel->strobeGO(&status);
// Execute and wait until it's done (up to a millisecond)
initialTime = getFPGATime(&status);
initialTime = HAL_GetFPGATime(&status);
while (accel->readSTAT(&status) & 1) {
if (getFPGATime(&status) > initialTime + 1000) break;
if (HAL_GetFPGATime(&status) > initialTime + 1000) break;
}
// Send a stop transmit/receive message with the data
@@ -121,9 +120,9 @@ static void writeRegister(Register reg, uint8_t data) {
accel->strobeGO(&status);
// Execute and wait until it's done (up to a millisecond)
initialTime = getFPGATime(&status);
initialTime = HAL_GetFPGATime(&status);
while (accel->readSTAT(&status) & 1) {
if (getFPGATime(&status) > initialTime + 1000) break;
if (HAL_GetFPGATime(&status) > initialTime + 1000) break;
}
std::fflush(stdout);
@@ -140,9 +139,9 @@ static uint8_t readRegister(Register reg) {
accel->strobeGO(&status);
// Execute and wait until it's done (up to a millisecond)
initialTime = getFPGATime(&status);
initialTime = HAL_GetFPGATime(&status);
while (accel->readSTAT(&status) & 1) {
if (getFPGATime(&status) > initialTime + 1000) break;
if (HAL_GetFPGATime(&status) > initialTime + 1000) break;
}
// Receive a message with the data and stop
@@ -151,9 +150,9 @@ static uint8_t readRegister(Register reg) {
accel->strobeGO(&status);
// Execute and wait until it's done (up to a millisecond)
initialTime = getFPGATime(&status);
initialTime = HAL_GetFPGATime(&status);
while (accel->readSTAT(&status) & 1) {
if (getFPGATime(&status) > initialTime + 1000) break;
if (HAL_GetFPGATime(&status) > initialTime + 1000) break;
}
std::fflush(stdout);
@@ -173,11 +172,11 @@ static double unpackAxis(int16_t raw) {
raw >>= 4;
switch (accelerometerRange) {
case kRange_2G:
case HAL_AccelerometerRange_k2G:
return raw / 1024.0;
case kRange_4G:
case HAL_AccelerometerRange_k4G:
return raw / 512.0;
case kRange_8G:
case HAL_AccelerometerRange_k8G:
return raw / 256.0;
default:
return 0.0;
@@ -190,7 +189,7 @@ extern "C" {
* Set the accelerometer to active or standby mode. It must be in standby
* mode to change any configuration.
*/
void setAccelerometerActive(bool active) {
void HAL_SetAccelerometerActive(bool active) {
initializeAccelerometer();
uint8_t ctrlReg1 = readRegister(kReg_CtrlReg1);
@@ -202,7 +201,7 @@ void setAccelerometerActive(bool active) {
* Set the range of values that can be measured (either 2, 4, or 8 g-forces).
* The accelerometer should be in standby mode when this is called.
*/
void setAccelerometerRange(AccelerometerRange range) {
void HAL_SetAccelerometerRange(HAL_AccelerometerRange range) {
initializeAccelerometer();
accelerometerRange = range;
@@ -217,7 +216,7 @@ void setAccelerometerRange(AccelerometerRange range) {
*
* This is a floating point value in units of 1 g-force
*/
double getAccelerometerX() {
double HAL_GetAccelerometerX() {
initializeAccelerometer();
int raw =
@@ -230,7 +229,7 @@ double getAccelerometerX() {
*
* This is a floating point value in units of 1 g-force
*/
double getAccelerometerY() {
double HAL_GetAccelerometerY() {
initializeAccelerometer();
int raw =
@@ -243,7 +242,7 @@ double getAccelerometerY() {
*
* This is a floating point value in units of 1 g-force
*/
double getAccelerometerZ() {
double HAL_GetAccelerometerZ() {
initializeAccelerometer();
int raw =

View File

@@ -18,8 +18,8 @@ extern "C" {
*
*@return The analog channel is attached to an accumulator.
*/
bool isAccumulatorChannel(HalAnalogInputHandle analog_port_handle,
int32_t* status) {
bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analog_port_handle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -34,16 +34,17 @@ bool isAccumulatorChannel(HalAnalogInputHandle analog_port_handle,
/**
* Initialize the accumulator.
*/
void initAccumulator(HalAnalogInputHandle analog_port_handle, int32_t* status) {
setAccumulatorCenter(analog_port_handle, 0, status);
resetAccumulator(analog_port_handle, status);
void HAL_InitAccumulator(HAL_AnalogInputHandle analog_port_handle,
int32_t* status) {
HAL_SetAccumulatorCenter(analog_port_handle, 0, status);
HAL_ResetAccumulator(analog_port_handle, status);
}
/**
* Resets the accumulator to the initial value.
*/
void resetAccumulator(HalAnalogInputHandle analog_port_handle,
int32_t* status) {
void HAL_ResetAccumulator(HAL_AnalogInputHandle analog_port_handle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -68,8 +69,8 @@ void resetAccumulator(HalAnalogInputHandle analog_port_handle,
* source from channel 1. Because of this, any non-zero oversample bits will
* affect the size of the value for this field.
*/
void setAccumulatorCenter(HalAnalogInputHandle analog_port_handle,
int32_t center, int32_t* status) {
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analog_port_handle,
int32_t center, int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -85,8 +86,8 @@ void setAccumulatorCenter(HalAnalogInputHandle analog_port_handle,
/**
* Set the accumulator's deadband.
*/
void setAccumulatorDeadband(HalAnalogInputHandle analog_port_handle,
int32_t deadband, int32_t* status) {
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analog_port_handle,
int32_t deadband, int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -107,8 +108,8 @@ void setAccumulatorDeadband(HalAnalogInputHandle analog_port_handle,
*
* @return The 64-bit value accumulated since the last Reset().
*/
int64_t getAccumulatorValue(HalAnalogInputHandle analog_port_handle,
int32_t* status) {
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analog_port_handle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -130,8 +131,8 @@ int64_t getAccumulatorValue(HalAnalogInputHandle analog_port_handle,
*
* @return The number of times samples from the channel were accumulated.
*/
uint32_t getAccumulatorCount(HalAnalogInputHandle analog_port_handle,
int32_t* status) {
uint32_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analog_port_handle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -153,8 +154,9 @@ uint32_t getAccumulatorCount(HalAnalogInputHandle analog_port_handle,
* @param value Pointer to the 64-bit accumulated output.
* @param count Pointer to the number of accumulation cycles.
*/
void getAccumulatorOutput(HalAnalogInputHandle analog_port_handle,
int64_t* value, uint32_t* count, int32_t* status) {
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analog_port_handle,
int64_t* value, uint32_t* count,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;

View File

@@ -17,7 +17,7 @@
namespace {
struct AnalogGyro {
HalAnalogInputHandle handle;
HAL_AnalogInputHandle handle;
float voltsPerDegreePerSecond;
float offset;
uint32_t center;
@@ -32,8 +32,8 @@ static constexpr float kDefaultVoltsPerDegreePerSecond = 0.007;
using namespace hal;
static IndexedHandleResource<HalGyroHandle, AnalogGyro, kNumAccumulators,
HalHandleEnum::AnalogGyro>
static IndexedHandleResource<HAL_GyroHandle, AnalogGyro, kNumAccumulators,
HAL_HandleEnum::AnalogGyro>
analogGyroHandles;
static void Wait(double seconds) {
@@ -42,13 +42,13 @@ static void Wait(double seconds) {
}
extern "C" {
HalGyroHandle initializeAnalogGyro(HalAnalogInputHandle analog_handle,
int32_t* status) {
if (!isAccumulatorChannel(analog_handle, status)) {
HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle analog_handle,
int32_t* status) {
if (!HAL_IsAccumulatorChannel(analog_handle, status)) {
if (*status == 0) {
*status = PARAMETER_OUT_OF_RANGE;
}
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
// handle known to be correct, so no need to type check
@@ -57,13 +57,13 @@ HalGyroHandle initializeAnalogGyro(HalAnalogInputHandle analog_handle,
auto handle = analogGyroHandles.Allocate(channel, status);
if (*status != 0)
return HAL_INVALID_HANDLE; // failed to allocate. Pass error back.
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
// Initialize port structure
auto gyro = analogGyroHandles.Get(handle);
if (gyro == nullptr) { // would only error on thread issue
*status = HAL_HANDLE_ERROR;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
gyro->handle = analog_handle;
@@ -74,7 +74,7 @@ HalGyroHandle initializeAnalogGyro(HalAnalogInputHandle analog_handle,
return handle;
}
void setupAnalogGyro(HalGyroHandle handle, int32_t* status) {
void HAL_SetupAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
auto gyro = analogGyroHandles.Get(handle);
if (gyro == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -83,25 +83,27 @@ void setupAnalogGyro(HalGyroHandle handle, int32_t* status) {
gyro->voltsPerDegreePerSecond = kDefaultVoltsPerDegreePerSecond;
setAnalogAverageBits(gyro->handle, kAverageBits, status);
HAL_SetAnalogAverageBits(gyro->handle, kAverageBits, status);
if (*status != 0) return;
setAnalogOversampleBits(gyro->handle, kOversampleBits, status);
HAL_SetAnalogOversampleBits(gyro->handle, kOversampleBits, status);
if (*status != 0) return;
float sampleRate =
kSamplesPerSecond * (1 << (kAverageBits + kOversampleBits));
setAnalogSampleRate(sampleRate, status);
HAL_SetAnalogSampleRate(sampleRate, status);
if (*status != 0) return;
Wait(0.1);
setAnalogGyroDeadband(handle, 0.0f, status);
HAL_SetAnalogGyroDeadband(handle, 0.0f, status);
if (*status != 0) return;
}
void freeAnalogGyro(HalGyroHandle handle) { analogGyroHandles.Free(handle); }
void HAL_FreeAnalogGyro(HAL_GyroHandle handle) {
analogGyroHandles.Free(handle);
}
void setAnalogGyroParameters(HalGyroHandle handle,
float voltsPerDegreePerSecond, float offset,
uint32_t center, int32_t* status) {
void HAL_SetAnalogGyroParameters(HAL_GyroHandle handle,
float voltsPerDegreePerSecond, float offset,
uint32_t center, int32_t* status) {
auto gyro = analogGyroHandles.Get(handle);
if (gyro == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -111,12 +113,12 @@ void setAnalogGyroParameters(HalGyroHandle handle,
gyro->voltsPerDegreePerSecond = voltsPerDegreePerSecond;
gyro->offset = offset;
gyro->center = center;
setAccumulatorCenter(gyro->handle, center, status);
HAL_SetAccumulatorCenter(gyro->handle, center, status);
}
void setAnalogGyroVoltsPerDegreePerSecond(HalGyroHandle handle,
float voltsPerDegreePerSecond,
int32_t* status) {
void HAL_SetAnalogGyroVoltsPerDegreePerSecond(HAL_GyroHandle handle,
float voltsPerDegreePerSecond,
int32_t* status) {
auto gyro = analogGyroHandles.Get(handle);
if (gyro == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -126,59 +128,63 @@ void setAnalogGyroVoltsPerDegreePerSecond(HalGyroHandle handle,
gyro->voltsPerDegreePerSecond = voltsPerDegreePerSecond;
}
void resetAnalogGyro(HalGyroHandle handle, int32_t* status) {
void HAL_ResetAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
auto gyro = analogGyroHandles.Get(handle);
if (gyro == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
resetAccumulator(gyro->handle, status);
HAL_ResetAccumulator(gyro->handle, status);
if (*status != 0) return;
const float sampleTime = 1.0f / getAnalogSampleRate(status);
const float overSamples = 1 << getAnalogOversampleBits(gyro->handle, status);
const float averageSamples = 1 << getAnalogAverageBits(gyro->handle, status);
const float sampleTime = 1.0f / HAL_GetAnalogSampleRate(status);
const float overSamples =
1 << HAL_GetAnalogOversampleBits(gyro->handle, status);
const float averageSamples =
1 << HAL_GetAnalogAverageBits(gyro->handle, status);
if (*status != 0) return;
Wait(sampleTime * overSamples * averageSamples);
}
void calibrateAnalogGyro(HalGyroHandle handle, int32_t* status) {
void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
auto gyro = analogGyroHandles.Get(handle);
if (gyro == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
initAccumulator(gyro->handle, status);
HAL_InitAccumulator(gyro->handle, status);
if (*status != 0) return;
Wait(kCalibrationSampleTime);
int64_t value;
uint32_t count;
getAccumulatorOutput(gyro->handle, &value, &count, status);
HAL_GetAccumulatorOutput(gyro->handle, &value, &count, status);
if (*status != 0) return;
gyro->center = (uint32_t)((float)value / (float)count + .5);
gyro->offset = ((float)value / (float)count) - (float)gyro->center;
setAccumulatorCenter(gyro->handle, gyro->center, status);
HAL_SetAccumulatorCenter(gyro->handle, gyro->center, status);
if (*status != 0) return;
resetAnalogGyro(handle, status);
HAL_ResetAnalogGyro(handle, status);
}
void setAnalogGyroDeadband(HalGyroHandle handle, float volts, int32_t* status) {
void HAL_SetAnalogGyroDeadband(HAL_GyroHandle handle, float volts,
int32_t* status) {
auto gyro = analogGyroHandles.Get(handle);
if (gyro == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
int32_t deadband = volts * 1e9 / getAnalogLSBWeight(gyro->handle, status) *
(1 << getAnalogOversampleBits(gyro->handle, status));
int32_t deadband = volts * 1e9 /
HAL_GetAnalogLSBWeight(gyro->handle, status) *
(1 << HAL_GetAnalogOversampleBits(gyro->handle, status));
if (*status != 0) return;
setAccumulatorDeadband(gyro->handle, deadband, status);
HAL_SetAccumulatorDeadband(gyro->handle, deadband, status);
}
float getAnalogGyroAngle(HalGyroHandle handle, int32_t* status) {
float HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status) {
auto gyro = analogGyroHandles.Get(handle);
if (gyro == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -186,33 +192,33 @@ float getAnalogGyroAngle(HalGyroHandle handle, int32_t* status) {
}
int64_t rawValue = 0;
uint32_t count = 0;
getAccumulatorOutput(gyro->handle, &rawValue, &count, status);
HAL_GetAccumulatorOutput(gyro->handle, &rawValue, &count, status);
int64_t value = rawValue - (int64_t)((float)count * gyro->offset);
double scaledValue =
value * 1e-9 * (double)getAnalogLSBWeight(gyro->handle, status) *
(double)(1 << getAnalogAverageBits(gyro->handle, status)) /
(getAnalogSampleRate(status) * gyro->voltsPerDegreePerSecond);
value * 1e-9 * (double)HAL_GetAnalogLSBWeight(gyro->handle, status) *
(double)(1 << HAL_GetAnalogAverageBits(gyro->handle, status)) /
(HAL_GetAnalogSampleRate(status) * gyro->voltsPerDegreePerSecond);
return (float)scaledValue;
}
double getAnalogGyroRate(HalGyroHandle handle, int32_t* status) {
double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status) {
auto gyro = analogGyroHandles.Get(handle);
if (gyro == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
return (getAnalogAverageValue(gyro->handle, status) -
return (HAL_GetAnalogAverageValue(gyro->handle, status) -
((double)gyro->center + gyro->offset)) *
1e-9 * getAnalogLSBWeight(gyro->handle, status) /
((1 << getAnalogOversampleBits(gyro->handle, status)) *
1e-9 * HAL_GetAnalogLSBWeight(gyro->handle, status) /
((1 << HAL_GetAnalogOversampleBits(gyro->handle, status)) *
gyro->voltsPerDegreePerSecond);
}
float getAnalogGyroOffset(HalGyroHandle handle, int32_t* status) {
float HAL_GetAnalogGyroOffset(HAL_GyroHandle handle, int32_t* status) {
auto gyro = analogGyroHandles.Get(handle);
if (gyro == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -221,7 +227,7 @@ float getAnalogGyroOffset(HalGyroHandle handle, int32_t* status) {
return gyro->offset;
}
uint32_t getAnalogGyroCenter(HalGyroHandle handle, int32_t* status) {
uint32_t HAL_GetAnalogGyroCenter(HAL_GyroHandle handle, int32_t* status) {
auto gyro = analogGyroHandles.Get(handle);
if (gyro == nullptr) {
*status = HAL_HANDLE_ERROR;

View File

@@ -25,43 +25,43 @@ extern "C" {
/**
* Initialize the analog input port using the given port object.
*/
HalAnalogInputHandle initializeAnalogInputPort(HalPortHandle port_handle,
int32_t* status) {
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle port_handle,
int32_t* status) {
initializeAnalog(status);
if (*status != 0) return HAL_INVALID_HANDLE;
if (*status != 0) return HAL_kInvalidHandle;
int16_t pin = getPortHandlePin(port_handle);
if (pin == InvalidHandleIndex) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
HalAnalogInputHandle handle = analogInputHandles.Allocate(pin, status);
HAL_AnalogInputHandle handle = analogInputHandles.Allocate(pin, status);
if (*status != 0)
return HAL_INVALID_HANDLE; // failed to allocate. Pass error back.
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
// Initialize port structure
auto analog_port = analogInputHandles.Get(handle);
if (analog_port == nullptr) { // would only error on thread issue
*status = HAL_HANDLE_ERROR;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
analog_port->pin = static_cast<uint8_t>(pin);
if (isAccumulatorChannel(handle, status)) {
if (HAL_IsAccumulatorChannel(handle, status)) {
analog_port->accumulator = tAccumulator::create(pin, status);
} else
analog_port->accumulator = nullptr;
// Set default configuration
analogInputSystem->writeScanList(pin, pin, status);
setAnalogAverageBits(handle, kDefaultAverageBits, status);
setAnalogOversampleBits(handle, kDefaultOversampleBits, status);
HAL_SetAnalogAverageBits(handle, kDefaultAverageBits, status);
HAL_SetAnalogOversampleBits(handle, kDefaultOversampleBits, status);
return handle;
}
void freeAnalogInputPort(HalAnalogInputHandle analog_port_handle) {
void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analog_port_handle) {
auto port = analogInputHandles.Get(analog_port_handle);
if (!port) return;
// no status, so no need to check for a proper free.
@@ -74,7 +74,7 @@ void freeAnalogInputPort(HalAnalogInputHandle analog_port_handle) {
*
* @return Analog module is valid and present
*/
bool checkAnalogModule(uint8_t module) { return module == 1; }
bool HAL_CheckAnalogModule(uint8_t module) { return module == 1; }
/**
* Check that the analog output channel number is value.
@@ -83,7 +83,7 @@ bool checkAnalogModule(uint8_t module) { return module == 1; }
*
* @return Analog channel is valid
*/
bool checkAnalogInputChannel(uint32_t pin) {
bool HAL_CheckAnalogInputChannel(uint32_t pin) {
if (pin < kNumAnalogInputs) return true;
return false;
}
@@ -95,7 +95,7 @@ bool checkAnalogInputChannel(uint32_t pin) {
*
* @param samplesPerSecond The number of samples per channel per second.
*/
void setAnalogSampleRate(double samplesPerSecond, int32_t* status) {
void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status) {
// TODO: This will change when variable size scan lists are implemented.
// TODO: Need float comparison with epsilon.
// wpi_assert(!sampleRateSet || GetSampleRate() == samplesPerSecond);
@@ -130,7 +130,7 @@ void setAnalogSampleRate(double samplesPerSecond, int32_t* status) {
*
* @return Sample rate.
*/
float getAnalogSampleRate(int32_t* status) {
float HAL_GetAnalogSampleRate(int32_t* status) {
uint32_t ticksPerConversion = analogInputSystem->readLoopTiming(status);
uint32_t ticksPerSample =
ticksPerConversion * getAnalogNumActiveChannels(status);
@@ -147,8 +147,8 @@ float getAnalogSampleRate(int32_t* status) {
* @param analog_port_pointer Pointer to the analog port to configure.
* @param bits Number of bits to average.
*/
void setAnalogAverageBits(HalAnalogInputHandle analog_port_handle,
uint32_t bits, int32_t* status) {
void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
uint32_t bits, int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -166,8 +166,8 @@ void setAnalogAverageBits(HalAnalogInputHandle analog_port_handle,
* @param analog_port_pointer Pointer to the analog port to use.
* @return Bits to average.
*/
uint32_t getAnalogAverageBits(HalAnalogInputHandle analog_port_handle,
int32_t* status) {
uint32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -188,8 +188,8 @@ uint32_t getAnalogAverageBits(HalAnalogInputHandle analog_port_handle,
* @param analog_port_pointer Pointer to the analog port to use.
* @param bits Number of bits to oversample.
*/
void setAnalogOversampleBits(HalAnalogInputHandle analog_port_handle,
uint32_t bits, int32_t* status) {
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
uint32_t bits, int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -208,8 +208,8 @@ void setAnalogOversampleBits(HalAnalogInputHandle analog_port_handle,
* @param analog_port_pointer Pointer to the analog port to use.
* @return Bits to oversample.
*/
uint32_t getAnalogOversampleBits(HalAnalogInputHandle analog_port_handle,
int32_t* status) {
uint32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -229,15 +229,15 @@ uint32_t getAnalogOversampleBits(HalAnalogInputHandle analog_port_handle,
* @param analog_port_pointer Pointer to the analog port to use.
* @return A sample straight from the channel on this module.
*/
int16_t getAnalogValue(HalAnalogInputHandle analog_port_handle,
int32_t* status) {
int16_t HAL_GetAnalogValue(HAL_AnalogInputHandle analog_port_handle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
int16_t value;
if (!checkAnalogInputChannel(port->pin)) {
if (!HAL_CheckAnalogInputChannel(port->pin)) {
return 0;
}
@@ -269,15 +269,15 @@ int16_t getAnalogValue(HalAnalogInputHandle analog_port_handle,
* @param analog_port_pointer Pointer to the analog port to use.
* @return A sample from the oversample and average engine for the channel.
*/
int32_t getAnalogAverageValue(HalAnalogInputHandle analog_port_handle,
int32_t* status) {
int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analog_port_handle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
int32_t value;
if (!checkAnalogInputChannel(port->pin)) {
if (!HAL_CheckAnalogInputChannel(port->pin)) {
return 0;
}
@@ -304,11 +304,11 @@ int32_t getAnalogAverageValue(HalAnalogInputHandle analog_port_handle,
* @param analog_port_pointer Pointer to the analog port to use.
* @return A scaled sample straight from the channel on this module.
*/
float getAnalogVoltage(HalAnalogInputHandle analog_port_handle,
int32_t* status) {
int16_t value = getAnalogValue(analog_port_handle, status);
uint32_t LSBWeight = getAnalogLSBWeight(analog_port_handle, status);
int32_t offset = getAnalogOffset(analog_port_handle, status);
float HAL_GetAnalogVoltage(HAL_AnalogInputHandle analog_port_handle,
int32_t* status) {
int16_t value = HAL_GetAnalogValue(analog_port_handle, status);
uint32_t LSBWeight = HAL_GetAnalogLSBWeight(analog_port_handle, status);
int32_t offset = HAL_GetAnalogOffset(analog_port_handle, status);
float voltage = LSBWeight * 1.0e-9 * value - offset * 1.0e-9;
return voltage;
}
@@ -326,12 +326,13 @@ float getAnalogVoltage(HalAnalogInputHandle analog_port_handle,
* @return A scaled sample from the output of the oversample and average engine
* for the channel.
*/
float getAnalogAverageVoltage(HalAnalogInputHandle analog_port_handle,
int32_t* status) {
int32_t value = getAnalogAverageValue(analog_port_handle, status);
uint32_t LSBWeight = getAnalogLSBWeight(analog_port_handle, status);
int32_t offset = getAnalogOffset(analog_port_handle, status);
uint32_t oversampleBits = getAnalogOversampleBits(analog_port_handle, status);
float HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analog_port_handle,
int32_t* status) {
int32_t value = HAL_GetAnalogAverageValue(analog_port_handle, status);
uint32_t LSBWeight = HAL_GetAnalogLSBWeight(analog_port_handle, status);
int32_t offset = HAL_GetAnalogOffset(analog_port_handle, status);
uint32_t oversampleBits =
HAL_GetAnalogOversampleBits(analog_port_handle, status);
float voltage =
((LSBWeight * 1.0e-9 * value) / (float)(1 << oversampleBits)) -
offset * 1.0e-9;
@@ -350,8 +351,8 @@ float getAnalogAverageVoltage(HalAnalogInputHandle analog_port_handle,
* @param voltage The voltage to convert.
* @return The raw value for the channel.
*/
int32_t getAnalogVoltsToValue(HalAnalogInputHandle analog_port_handle,
double voltage, int32_t* status) {
int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analog_port_handle,
double voltage, int32_t* status) {
if (voltage > 5.0) {
voltage = 5.0;
*status = VOLTAGE_OUT_OF_RANGE;
@@ -360,8 +361,8 @@ int32_t getAnalogVoltsToValue(HalAnalogInputHandle analog_port_handle,
voltage = 0.0;
*status = VOLTAGE_OUT_OF_RANGE;
}
uint32_t LSBWeight = getAnalogLSBWeight(analog_port_handle, status);
int32_t offset = getAnalogOffset(analog_port_handle, status);
uint32_t LSBWeight = HAL_GetAnalogLSBWeight(analog_port_handle, status);
int32_t offset = HAL_GetAnalogOffset(analog_port_handle, status);
int32_t value = (int32_t)((voltage + offset * 1.0e-9) / (LSBWeight * 1.0e-9));
return value;
}
@@ -376,8 +377,8 @@ int32_t getAnalogVoltsToValue(HalAnalogInputHandle analog_port_handle,
* @param analog_port_pointer Pointer to the analog port to use.
* @return Least significant bit weight.
*/
uint32_t getAnalogLSBWeight(HalAnalogInputHandle analog_port_handle,
int32_t* status) {
uint32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analog_port_handle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -398,8 +399,8 @@ uint32_t getAnalogLSBWeight(HalAnalogInputHandle analog_port_handle,
* @param analog_port_pointer Pointer to the analog port to use.
* @return Offset constant.
*/
int32_t getAnalogOffset(HalAnalogInputHandle analog_port_handle,
int32_t* status) {
int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analog_port_handle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;

View File

@@ -17,8 +17,8 @@ priority_recursive_mutex analogRegisterWindowMutex;
tAI* analogInputSystem = nullptr;
tAO* analogOutputSystem = nullptr;
IndexedHandleResource<HalAnalogInputHandle, hal::AnalogPort, kNumAnalogInputs,
HalHandleEnum::AnalogInput>
IndexedHandleResource<HAL_AnalogInputHandle, hal::AnalogPort, kNumAnalogInputs,
HAL_HandleEnum::AnalogInput>
analogInputHandles;
static uint32_t analogNumChannelsToActivate = 0;
@@ -34,7 +34,7 @@ void initializeAnalog(int32_t* status) {
analogInputSystem = tAI::create(status);
analogOutputSystem = tAO::create(status);
setAnalogNumChannelsToActivate(kNumAnalogInputs);
setAnalogSampleRate(kDefaultSampleRate, status);
HAL_SetAnalogSampleRate(kDefaultSampleRate, status);
analogSystemInitialized = true;
}

View File

@@ -31,8 +31,8 @@ struct AnalogPort {
tAccumulator* accumulator;
};
extern IndexedHandleResource<HalAnalogInputHandle, hal::AnalogPort,
kNumAnalogInputs, HalHandleEnum::AnalogInput>
extern IndexedHandleResource<HAL_AnalogInputHandle, hal::AnalogPort,
kNumAnalogInputs, HAL_HandleEnum::AnalogInput>
analogInputHandles;
uint32_t getAnalogNumActiveChannels(int32_t* status);

View File

@@ -21,8 +21,8 @@ struct AnalogOutput {
};
}
static IndexedHandleResource<HalAnalogOutputHandle, AnalogOutput,
kNumAnalogOutputs, HalHandleEnum::AnalogOutput>
static IndexedHandleResource<HAL_AnalogOutputHandle, AnalogOutput,
kNumAnalogOutputs, HAL_HandleEnum::AnalogOutput>
analogOutputHandles;
extern "C" {
@@ -30,34 +30,34 @@ extern "C" {
/**
* Initialize the analog output port using the given port object.
*/
HalAnalogOutputHandle initializeAnalogOutputPort(HalPortHandle port_handle,
int32_t* status) {
HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(
HAL_PortHandle port_handle, int32_t* status) {
initializeAnalog(status);
if (*status != 0) return HAL_INVALID_HANDLE;
if (*status != 0) return HAL_kInvalidHandle;
int16_t pin = getPortHandlePin(port_handle);
if (pin == InvalidHandleIndex) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
HalAnalogOutputHandle handle = analogOutputHandles.Allocate(pin, status);
HAL_AnalogOutputHandle handle = analogOutputHandles.Allocate(pin, status);
if (*status != 0)
return HAL_INVALID_HANDLE; // failed to allocate. Pass error back.
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
auto port = analogOutputHandles.Get(handle);
if (port == nullptr) { // would only error on thread issue
*status = HAL_HANDLE_ERROR;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
port->pin = static_cast<uint8_t>(pin);
return handle;
}
void freeAnalogOutputPort(HalAnalogOutputHandle analog_output_handle) {
void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analog_output_handle) {
// no status, so no need to check for a proper free.
analogOutputHandles.Free(analog_output_handle);
}
@@ -69,13 +69,13 @@ void freeAnalogOutputPort(HalAnalogOutputHandle analog_output_handle) {
*
* @return Analog channel is valid
*/
bool checkAnalogOutputChannel(uint32_t pin) {
bool HAL_CheckAnalogOutputChannel(uint32_t pin) {
if (pin < kNumAnalogOutputs) return true;
return false;
}
void setAnalogOutput(HalAnalogOutputHandle analog_output_handle, double voltage,
int32_t* status) {
void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analog_output_handle,
double voltage, int32_t* status) {
auto port = analogOutputHandles.Get(analog_output_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -92,8 +92,8 @@ void setAnalogOutput(HalAnalogOutputHandle analog_output_handle, double voltage,
analogOutputSystem->writeMXP(port->pin, rawValue, status);
}
double getAnalogOutput(HalAnalogOutputHandle analog_output_handle,
int32_t* status) {
double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analog_output_handle,
int32_t* status) {
auto port = analogOutputHandles.Get(analog_output_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;

View File

@@ -19,28 +19,27 @@ using namespace hal;
namespace {
struct AnalogTrigger {
tAnalogTrigger* trigger;
HalAnalogInputHandle analogHandle;
HAL_AnalogInputHandle analogHandle;
uint32_t index;
};
}
static LimitedHandleResource<HalAnalogTriggerHandle, AnalogTrigger,
kNumAnalogTriggers, HalHandleEnum::AnalogTrigger>
static LimitedHandleResource<HAL_AnalogTriggerHandle, AnalogTrigger,
kNumAnalogTriggers, HAL_HandleEnum::AnalogTrigger>
analogTriggerHandles;
extern "C" {
HalAnalogTriggerHandle initializeAnalogTrigger(HalAnalogInputHandle port_handle,
uint32_t* index,
int32_t* status) {
if (port_handle == HAL_INVALID_HANDLE) {
HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
HAL_AnalogInputHandle port_handle, uint32_t* index, int32_t* status) {
if (port_handle == HAL_kInvalidHandle) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
HalAnalogInputHandle handle = analogTriggerHandles.Allocate();
if (handle == HAL_INVALID_HANDLE) {
HAL_AnalogInputHandle handle = analogTriggerHandles.Allocate();
if (handle == HAL_kInvalidHandle) {
*status = NO_AVAILABLE_RESOURCES;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
auto trigger = analogTriggerHandles.Get(handle);
trigger->analogHandle = port_handle;
@@ -48,7 +47,7 @@ HalAnalogTriggerHandle initializeAnalogTrigger(HalAnalogInputHandle port_handle,
auto analog_port = analogInputHandles.Get(trigger->analogHandle);
if (analog_port == nullptr) { // would only error on thread issue
*status = HAL_HANDLE_ERROR;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
*index = static_cast<uint32_t>(getHandleIndex(handle));
trigger->index = *index;
@@ -59,8 +58,8 @@ HalAnalogTriggerHandle initializeAnalogTrigger(HalAnalogInputHandle port_handle,
return handle;
}
void cleanAnalogTrigger(HalAnalogTriggerHandle analog_trigger_handle,
int32_t* status) {
void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analog_trigger_handle,
int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
if (trigger == nullptr) { // ignore status error
return;
@@ -70,8 +69,9 @@ void cleanAnalogTrigger(HalAnalogTriggerHandle analog_trigger_handle,
delete trigger->trigger;
}
void setAnalogTriggerLimitsRaw(HalAnalogTriggerHandle analog_trigger_handle,
int32_t lower, int32_t upper, int32_t* status) {
void HAL_SetAnalogTriggerLimitsRaw(
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t lower, int32_t upper,
int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -88,9 +88,9 @@ void setAnalogTriggerLimitsRaw(HalAnalogTriggerHandle analog_trigger_handle,
* Set the upper and lower limits of the analog trigger.
* The limits are given as floating point voltage values.
*/
void setAnalogTriggerLimitsVoltage(HalAnalogTriggerHandle analog_trigger_handle,
double lower, double upper,
int32_t* status) {
void HAL_SetAnalogTriggerLimitsVoltage(
HAL_AnalogTriggerHandle analog_trigger_handle, double lower, double upper,
int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -103,9 +103,9 @@ void setAnalogTriggerLimitsVoltage(HalAnalogTriggerHandle analog_trigger_handle,
// TODO: This depends on the averaged setting. Only raw values will work as
// is.
trigger->trigger->writeLowerLimit(
getAnalogVoltsToValue(trigger->analogHandle, lower, status), status);
HAL_GetAnalogVoltsToValue(trigger->analogHandle, lower, status), status);
trigger->trigger->writeUpperLimit(
getAnalogVoltsToValue(trigger->analogHandle, upper, status), status);
HAL_GetAnalogVoltsToValue(trigger->analogHandle, upper, status), status);
}
/**
@@ -113,8 +113,8 @@ void setAnalogTriggerLimitsVoltage(HalAnalogTriggerHandle analog_trigger_handle,
* If the value is true, then the averaged value is selected for the analog
* trigger, otherwise the immediate value is used.
*/
void setAnalogTriggerAveraged(HalAnalogTriggerHandle analog_trigger_handle,
bool useAveragedValue, int32_t* status) {
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analog_trigger_handle,
bool useAveragedValue, int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -134,8 +134,8 @@ void setAnalogTriggerAveraged(HalAnalogTriggerHandle analog_trigger_handle,
* is designed to help with 360 degree pot applications for the period where the
* pot crosses through zero.
*/
void setAnalogTriggerFiltered(HalAnalogTriggerHandle analog_trigger_handle,
bool useFilteredValue, int32_t* status) {
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analog_trigger_handle,
bool useFilteredValue, int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -154,8 +154,8 @@ void setAnalogTriggerFiltered(HalAnalogTriggerHandle analog_trigger_handle,
* True if the analog input is between the upper and lower limits.
* @return The InWindow output of the analog trigger.
*/
bool getAnalogTriggerInWindow(HalAnalogTriggerHandle analog_trigger_handle,
int32_t* status) {
bool HAL_GetAnalogTriggerInWindow(HAL_AnalogTriggerHandle analog_trigger_handle,
int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -171,8 +171,8 @@ bool getAnalogTriggerInWindow(HalAnalogTriggerHandle analog_trigger_handle,
* If in Hysteresis, maintain previous state.
* @return The TriggerState output of the analog trigger.
*/
bool getAnalogTriggerTriggerState(HalAnalogTriggerHandle analog_trigger_handle,
int32_t* status) {
bool HAL_GetAnalogTriggerTriggerState(
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -185,8 +185,8 @@ bool getAnalogTriggerTriggerState(HalAnalogTriggerHandle analog_trigger_handle,
* Get the state of the analog trigger output.
* @return The state of the analog trigger output.
*/
bool getAnalogTriggerOutput(HalAnalogTriggerHandle analog_trigger_handle,
AnalogTriggerType type, int32_t* status) {
bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analog_trigger_handle,
HAL_AnalogTriggerType type, int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -194,15 +194,15 @@ bool getAnalogTriggerOutput(HalAnalogTriggerHandle analog_trigger_handle,
}
bool result = false;
switch (type) {
case kInWindow:
case HAL_Trigger_kInWindow:
result =
trigger->trigger->readOutput_InHysteresis(trigger->index, status);
break; // XXX: Backport
case kState:
case HAL_Trigger_kState:
result = trigger->trigger->readOutput_OverLimit(trigger->index, status);
break; // XXX: Backport
case kRisingPulse:
case kFallingPulse:
case HAL_Trigger_kRisingPulse:
case HAL_Trigger_kFallingPulse:
*status = ANALOG_TRIGGER_PULSE_OUTPUT_ERROR;
return false;
}

View File

@@ -17,11 +17,11 @@ using namespace hal;
extern "C" {
HalCompressorHandle initializeCompressor(uint8_t module, int32_t* status) {
HAL_CompressorHandle HAL_InitializeCompressor(uint8_t module, int32_t* status) {
// fail on invalid index;
if (!checkCompressorModule(module)) {
if (!HAL_CheckCompressorModule(module)) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
initializePCM(module);
@@ -29,14 +29,17 @@ HalCompressorHandle initializeCompressor(uint8_t module, int32_t* status) {
// As compressors can have unlimited objects, just create a
// handle with the module number as the index.
return (HalCompressorHandle)createHandle(module, HalHandleEnum::Compressor);
return (HAL_CompressorHandle)createHandle(module, HAL_HandleEnum::Compressor);
}
bool checkCompressorModule(uint8_t module) { return module < kNumPCMModules; }
bool HAL_CheckCompressorModule(uint8_t module) {
return module < kNumPCMModules;
}
bool getCompressor(HalCompressorHandle compressor_handle, int32_t* status) {
bool HAL_GetCompressor(HAL_CompressorHandle compressor_handle,
int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -49,10 +52,10 @@ bool getCompressor(HalCompressorHandle compressor_handle, int32_t* status) {
return value;
}
void setClosedLoopControl(HalCompressorHandle compressor_handle, bool value,
int32_t* status) {
void HAL_SetClosedLoopControl(HAL_CompressorHandle compressor_handle,
bool value, int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return;
@@ -62,10 +65,10 @@ void setClosedLoopControl(HalCompressorHandle compressor_handle, bool value,
*status = module->SetClosedLoopControl(value);
}
bool getClosedLoopControl(HalCompressorHandle compressor_handle,
int32_t* status) {
bool HAL_GetClosedLoopControl(HAL_CompressorHandle compressor_handle,
int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -78,9 +81,10 @@ bool getClosedLoopControl(HalCompressorHandle compressor_handle,
return value;
}
bool getPressureSwitch(HalCompressorHandle compressor_handle, int32_t* status) {
bool HAL_GetPressureSwitch(HAL_CompressorHandle compressor_handle,
int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -93,10 +97,10 @@ bool getPressureSwitch(HalCompressorHandle compressor_handle, int32_t* status) {
return value;
}
float getCompressorCurrent(HalCompressorHandle compressor_handle,
int32_t* status) {
float HAL_GetCompressorCurrent(HAL_CompressorHandle compressor_handle,
int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -108,10 +112,10 @@ float getCompressorCurrent(HalCompressorHandle compressor_handle,
return value;
}
bool getCompressorCurrentTooHighFault(HalCompressorHandle compressor_handle,
int32_t* status) {
bool HAL_GetCompressorCurrentTooHighFault(
HAL_CompressorHandle compressor_handle, int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -123,10 +127,10 @@ bool getCompressorCurrentTooHighFault(HalCompressorHandle compressor_handle,
return value;
}
bool getCompressorCurrentTooHighStickyFault(
HalCompressorHandle compressor_handle, int32_t* status) {
bool HAL_GetCompressorCurrentTooHighStickyFault(
HAL_CompressorHandle compressor_handle, int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -138,10 +142,10 @@ bool getCompressorCurrentTooHighStickyFault(
return value;
}
bool getCompressorShortedStickyFault(HalCompressorHandle compressor_handle,
int32_t* status) {
bool HAL_GetCompressorShortedStickyFault(HAL_CompressorHandle compressor_handle,
int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -153,10 +157,10 @@ bool getCompressorShortedStickyFault(HalCompressorHandle compressor_handle,
return value;
}
bool getCompressorShortedFault(HalCompressorHandle compressor_handle,
int32_t* status) {
bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressor_handle,
int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -168,10 +172,10 @@ bool getCompressorShortedFault(HalCompressorHandle compressor_handle,
return value;
}
bool getCompressorNotConnectedStickyFault(HalCompressorHandle compressor_handle,
int32_t* status) {
bool HAL_GetCompressorNotConnectedStickyFault(
HAL_CompressorHandle compressor_handle, int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -183,10 +187,10 @@ bool getCompressorNotConnectedStickyFault(HalCompressorHandle compressor_handle,
return value;
}
bool getCompressorNotConnectedFault(HalCompressorHandle compressor_handle,
int32_t* status) {
bool HAL_GetCompressorNotConnectedFault(HAL_CompressorHandle compressor_handle,
int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -198,10 +202,10 @@ bool getCompressorNotConnectedFault(HalCompressorHandle compressor_handle,
return value;
}
void clearAllPCMStickyFaults(HalCompressorHandle compressor_handle,
int32_t* status) {
void HAL_ClearAllPCMStickyFaults(HAL_CompressorHandle compressor_handle,
int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return;

View File

@@ -12,7 +12,7 @@
using namespace hal;
extern "C" {
int32_t HAL_getSystemClockTicksPerMicrosecond(void) {
int32_t HAL_GetSystemClockTicksPerMicrosecond(void) {
return kSystemClockTicksPerMicrosecond;
}
}

View File

@@ -22,21 +22,22 @@ struct Counter {
};
}
static LimitedHandleResource<HalCounterHandle, Counter, kNumCounters,
HalHandleEnum::Counter>
static LimitedHandleResource<HAL_CounterHandle, Counter, kNumCounters,
HAL_HandleEnum::Counter>
counterHandles;
extern "C" {
HalCounterHandle initializeCounter(Mode mode, int32_t* index, int32_t* status) {
HAL_CounterHandle HAL_InitializeCounter(HAL_Counter_Mode mode, int32_t* index,
int32_t* status) {
auto handle = counterHandles.Allocate();
if (handle == HAL_INVALID_HANDLE) { // out of resources
if (handle == HAL_kInvalidHandle) { // out of resources
*status = NO_AVAILABLE_RESOURCES;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
auto counter = counterHandles.Get(handle);
if (counter == nullptr) { // would only occur on thread issues
*status = HAL_HANDLE_ERROR;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
*index = static_cast<uint32_t>(getHandleIndex(handle));
@@ -47,7 +48,7 @@ HalCounterHandle initializeCounter(Mode mode, int32_t* index, int32_t* status) {
return handle;
}
void freeCounter(HalCounterHandle counter_handle, int32_t* status) {
void HAL_FreeCounter(HAL_CounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) { // don't throw status as unneccesary
return;
@@ -56,8 +57,8 @@ void freeCounter(HalCounterHandle counter_handle, int32_t* status) {
counterHandles.Free(counter_handle);
}
void setCounterAverageSize(HalCounterHandle counter_handle, int32_t size,
int32_t* status) {
void HAL_SetCounterAverageSize(HAL_CounterHandle counter_handle, int32_t size,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -70,9 +71,10 @@ void setCounterAverageSize(HalCounterHandle counter_handle, int32_t size,
* Set the source object that causes the counter to count up.
* Set the up counting DigitalSource.
*/
void setCounterUpSource(HalCounterHandle counter_handle,
HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType, int32_t* status) {
void HAL_SetCounterUpSource(HAL_CounterHandle counter_handle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -95,9 +97,10 @@ void setCounterUpSource(HalCounterHandle counter_handle,
counter->counter->writeConfig_UpSource_AnalogTrigger(routingAnalogTrigger,
status);
if (counter->counter->readConfig_Mode(status) == kTwoPulse ||
counter->counter->readConfig_Mode(status) == kExternalDirection) {
setCounterUpSourceEdge(counter_handle, true, false, status);
if (counter->counter->readConfig_Mode(status) == HAL_Counter_kTwoPulse ||
counter->counter->readConfig_Mode(status) ==
HAL_Counter_kExternalDirection) {
HAL_SetCounterUpSourceEdge(counter_handle, true, false, status);
}
counter->counter->strobeReset(status);
}
@@ -106,8 +109,9 @@ void setCounterUpSource(HalCounterHandle counter_handle,
* Set the edge sensitivity on an up counting source.
* Set the up source to either detect rising edges or falling edges.
*/
void setCounterUpSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
bool fallingEdge, int32_t* status) {
void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counter_handle,
bool risingEdge, bool fallingEdge,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -120,7 +124,8 @@ void setCounterUpSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
/**
* Disable the up counting source to the counter.
*/
void clearCounterUpSource(HalCounterHandle counter_handle, int32_t* status) {
void HAL_ClearCounterUpSource(HAL_CounterHandle counter_handle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -137,17 +142,17 @@ void clearCounterUpSource(HalCounterHandle counter_handle, int32_t* status) {
* Set the source object that causes the counter to count down.
* Set the down counting DigitalSource.
*/
void setCounterDownSource(HalCounterHandle counter_handle,
HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType,
int32_t* status) {
void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
unsigned char mode = counter->counter->readConfig_Mode(status);
if (mode != kTwoPulse && mode != kExternalDirection) {
if (mode != HAL_Counter_kTwoPulse && mode != HAL_Counter_kExternalDirection) {
// TODO: wpi_setWPIErrorWithContext(ParameterOutOfRange, "Counter only
// supports DownSource in TwoPulse and ExternalDirection modes.");
*status = PARAMETER_OUT_OF_RANGE;
@@ -170,7 +175,7 @@ void setCounterDownSource(HalCounterHandle counter_handle,
counter->counter->writeConfig_DownSource_AnalogTrigger(routingAnalogTrigger,
status);
setCounterDownSourceEdge(counter_handle, true, false, status);
HAL_SetCounterDownSourceEdge(counter_handle, true, false, status);
counter->counter->strobeReset(status);
}
@@ -178,8 +183,9 @@ void setCounterDownSource(HalCounterHandle counter_handle,
* Set the edge sensitivity on a down counting source.
* Set the down source to either detect rising edges or falling edges.
*/
void setCounterDownSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
bool fallingEdge, int32_t* status) {
void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counter_handle,
bool risingEdge, bool fallingEdge,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -192,7 +198,8 @@ void setCounterDownSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
/**
* Disable the down counting source to the counter.
*/
void clearCounterDownSource(HalCounterHandle counter_handle, int32_t* status) {
void HAL_ClearCounterDownSource(HAL_CounterHandle counter_handle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -209,13 +216,14 @@ void clearCounterDownSource(HalCounterHandle counter_handle, int32_t* status) {
* Set standard up / down counting mode on this counter.
* Up and down counts are sourced independently from two inputs.
*/
void setCounterUpDownMode(HalCounterHandle counter_handle, int32_t* status) {
void HAL_SetCounterUpDownMode(HAL_CounterHandle counter_handle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
counter->counter->writeConfig_Mode(kTwoPulse, status);
counter->counter->writeConfig_Mode(HAL_Counter_kTwoPulse, status);
}
/**
@@ -223,30 +231,30 @@ void setCounterUpDownMode(HalCounterHandle counter_handle, int32_t* status) {
* Counts are sourced on the Up counter input.
* The Down counter input represents the direction to count.
*/
void setCounterExternalDirectionMode(HalCounterHandle counter_handle,
int32_t* status) {
void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counter_handle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
counter->counter->writeConfig_Mode(kExternalDirection, status);
counter->counter->writeConfig_Mode(HAL_Counter_kExternalDirection, status);
}
/**
* Set Semi-period mode on this counter.
* Counts up on both rising and falling edges.
*/
void setCounterSemiPeriodMode(HalCounterHandle counter_handle,
bool highSemiPeriod, int32_t* status) {
void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counter_handle,
bool highSemiPeriod, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
counter->counter->writeConfig_Mode(kSemiperiod, status);
counter->counter->writeConfig_Mode(HAL_Counter_kSemiperiod, status);
counter->counter->writeConfig_UpRisingEdge(highSemiPeriod, status);
setCounterUpdateWhenEmpty(counter_handle, false, status);
HAL_SetCounterUpdateWhenEmpty(counter_handle, false, status);
}
/**
@@ -256,14 +264,14 @@ void setCounterSemiPeriodMode(HalCounterHandle counter_handle,
* @param threshold The pulse length beyond which the counter counts the
* opposite direction. Units are seconds.
*/
void setCounterPulseLengthMode(HalCounterHandle counter_handle,
double threshold, int32_t* status) {
void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counter_handle,
double threshold, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
counter->counter->writeConfig_Mode(kPulseLength, status);
counter->counter->writeConfig_Mode(HAL_Counter_kPulseLength, status);
counter->counter->writeConfig_PulseLengthThreshold(
(uint32_t)(threshold * 1.0e6) * kSystemClockTicksPerMicrosecond, status);
}
@@ -275,8 +283,8 @@ void setCounterPulseLengthMode(HalCounterHandle counter_handle,
* mechanical imperfections or as oversampling to increase resolution.
* @return SamplesToAverage The number of samples being averaged (from 1 to 127)
*/
int32_t getCounterSamplesToAverage(HalCounterHandle counter_handle,
int32_t* status) {
int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -291,8 +299,8 @@ int32_t getCounterSamplesToAverage(HalCounterHandle counter_handle,
* mechanical imperfections or as oversampling to increase resolution.
* @param samplesToAverage The number of samples to average from 1 to 127.
*/
void setCounterSamplesToAverage(HalCounterHandle counter_handle,
int samplesToAverage, int32_t* status) {
void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
int samplesToAverage, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -309,7 +317,7 @@ void setCounterSamplesToAverage(HalCounterHandle counter_handle,
* Set the counter value to zero. This doesn't effect the running state of the
* counter, just sets the current value to zero.
*/
void resetCounter(HalCounterHandle counter_handle, int32_t* status) {
void HAL_ResetCounter(HAL_CounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -323,7 +331,7 @@ void resetCounter(HalCounterHandle counter_handle, int32_t* status) {
* Read the value at this instant. It may still be running, so it reflects the
* current value. Next time it is read, it might have a different value.
*/
int32_t getCounter(HalCounterHandle counter_handle, int32_t* status) {
int32_t HAL_GetCounter(HAL_CounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -339,7 +347,7 @@ int32_t getCounter(HalCounterHandle counter_handle, int32_t* status) {
* velocity calculations to determine shaft speed.
* @returns The period of the last two pulses in units of seconds.
*/
double getCounterPeriod(HalCounterHandle counter_handle, int32_t* status) {
double HAL_GetCounterPeriod(HAL_CounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -367,8 +375,8 @@ double getCounterPeriod(HalCounterHandle counter_handle, int32_t* status) {
* @param maxPeriod The maximum period where the counted device is considered
* moving in seconds.
*/
void setCounterMaxPeriod(HalCounterHandle counter_handle, double maxPeriod,
int32_t* status) {
void HAL_SetCounterMaxPeriod(HAL_CounterHandle counter_handle, double maxPeriod,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -391,8 +399,8 @@ void setCounterMaxPeriod(HalCounterHandle counter_handle, double maxPeriod,
* and you will likely not see the stopped bit become true (since it is updated
* at the end of an average and there are no samples to average).
*/
void setCounterUpdateWhenEmpty(HalCounterHandle counter_handle, bool enabled,
int32_t* status) {
void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counter_handle,
bool enabled, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -409,7 +417,7 @@ void setCounterUpdateWhenEmpty(HalCounterHandle counter_handle, bool enabled,
* @return Returns true if the most recent counter period exceeds the MaxPeriod
* value set by SetMaxPeriod.
*/
bool getCounterStopped(HalCounterHandle counter_handle, int32_t* status) {
bool HAL_GetCounterStopped(HAL_CounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -422,7 +430,8 @@ bool getCounterStopped(HalCounterHandle counter_handle, int32_t* status) {
* The last direction the counter value changed.
* @return The last direction the counter value changed.
*/
bool getCounterDirection(HalCounterHandle counter_handle, int32_t* status) {
bool HAL_GetCounterDirection(HAL_CounterHandle counter_handle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -438,18 +447,19 @@ bool getCounterDirection(HalCounterHandle counter_handle, int32_t* status) {
* 1X and 2X quadrature encoding only. Any other counter mode isn't supported.
* @param reverseDirection true if the value counted should be negated.
*/
void setCounterReverseDirection(HalCounterHandle counter_handle,
bool reverseDirection, int32_t* status) {
void HAL_SetCounterReverseDirection(HAL_CounterHandle counter_handle,
bool reverseDirection, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
if (counter->counter->readConfig_Mode(status) == kExternalDirection) {
if (counter->counter->readConfig_Mode(status) ==
HAL_Counter_kExternalDirection) {
if (reverseDirection)
setCounterDownSourceEdge(counter_handle, true, true, status);
HAL_SetCounterDownSourceEdge(counter_handle, true, true, status);
else
setCounterDownSourceEdge(counter_handle, false, true, status);
HAL_SetCounterDownSourceEdge(counter_handle, false, true, status);
}
}
}

View File

@@ -19,8 +19,8 @@ using namespace hal;
// Create a mutex to protect changes to the digital output values
static priority_recursive_mutex digitalDIOMutex;
static LimitedHandleResource<HalDigitalPWMHandle, uint8_t,
kNumDigitalPWMOutputs, HalHandleEnum::DigitalPWM>
static LimitedHandleResource<HAL_DigitalPWMHandle, uint8_t,
kNumDigitalPWMOutputs, HAL_HandleEnum::DigitalPWM>
digitalPWMHandles;
extern "C" {
@@ -28,27 +28,27 @@ extern "C" {
/**
* Create a new instance of a digital port.
*/
HalDigitalHandle initializeDIOPort(HalPortHandle port_handle, uint8_t input,
int32_t* status) {
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle port_handle,
uint8_t input, int32_t* status) {
initializeDigital(status);
if (*status != 0) return HAL_INVALID_HANDLE;
if (*status != 0) return HAL_kInvalidHandle;
int16_t pin = getPortHandlePin(port_handle);
if (pin == InvalidHandleIndex) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
auto handle = digitalPinHandles.Allocate(pin, HalHandleEnum::DIO, status);
auto handle = digitalPinHandles.Allocate(pin, HAL_HandleEnum::DIO, status);
if (*status != 0)
return HAL_INVALID_HANDLE; // failed to allocate. Pass error back.
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
auto port = digitalPinHandles.Get(handle, HalHandleEnum::DIO);
auto port = digitalPinHandles.Get(handle, HAL_HandleEnum::DIO);
if (port == nullptr) { // would only occur on thread issue.
*status = HAL_HANDLE_ERROR;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
port->pin = static_cast<uint8_t>(pin);
@@ -88,9 +88,9 @@ HalDigitalHandle initializeDIOPort(HalPortHandle port_handle, uint8_t input,
return handle;
}
void freeDIOPort(HalDigitalHandle dio_port_handle) {
void HAL_FreeDIOPort(HAL_DigitalHandle dio_port_handle) {
// no status, so no need to check for a proper free.
digitalPinHandles.Free(dio_port_handle, HalHandleEnum::DIO);
digitalPinHandles.Free(dio_port_handle, HAL_HandleEnum::DIO);
}
/**
@@ -99,17 +99,17 @@ void freeDIOPort(HalDigitalHandle dio_port_handle) {
*
* @return PWM Generator handle
*/
HalDigitalPWMHandle allocateDigitalPWM(int32_t* status) {
HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
auto handle = digitalPWMHandles.Allocate();
if (handle == HAL_INVALID_HANDLE) {
if (handle == HAL_kInvalidHandle) {
*status = NO_AVAILABLE_RESOURCES;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
auto id = digitalPWMHandles.Get(handle);
if (id == nullptr) { // would only occur on thread issue.
*status = HAL_HANDLE_ERROR;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
*id = static_cast<uint8_t>(getHandleIndex(handle));
@@ -122,7 +122,7 @@ HalDigitalPWMHandle allocateDigitalPWM(int32_t* status) {
* @param pwmGenerator The pwmGen to free that was allocated with
* allocateDigitalPWM()
*/
void freeDigitalPWM(HalDigitalPWMHandle pwmGenerator, int32_t* status) {
void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status) {
digitalPWMHandles.Free(pwmGenerator);
}
@@ -134,7 +134,7 @@ void freeDigitalPWM(HalDigitalPWMHandle pwmGenerator, int32_t* status) {
*
* @param rate The frequency to output all digital output PWM signals.
*/
void setDigitalPWMRate(double rate, int32_t* status) {
void HAL_SetDigitalPWMRate(double rate, int32_t* status) {
// Currently rounding in the log rate domain... heavy weight toward picking a
// higher freq.
// TODO: Round in the linear rate domain.
@@ -151,8 +151,8 @@ void setDigitalPWMRate(double rate, int32_t* status) {
* @param pwmGenerator The generator index reserved by allocateDigitalPWM()
* @param dutyCycle The percent duty cycle to output [0..1].
*/
void setDigitalPWMDutyCycle(HalDigitalPWMHandle pwmGenerator, double dutyCycle,
int32_t* status) {
void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
double dutyCycle, int32_t* status) {
auto port = digitalPWMHandles.Get(pwmGenerator);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -184,8 +184,8 @@ void setDigitalPWMDutyCycle(HalDigitalPWMHandle pwmGenerator, double dutyCycle,
* @param pwmGenerator The generator index reserved by allocateDigitalPWM()
* @param channel The Digital Output channel to output on
*/
void setDigitalPWMOutputChannel(HalDigitalPWMHandle pwmGenerator, uint32_t pin,
int32_t* status) {
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
uint32_t pin, int32_t* status) {
auto port = digitalPWMHandles.Get(pwmGenerator);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -207,8 +207,9 @@ void setDigitalPWMOutputChannel(HalDigitalPWMHandle pwmGenerator, uint32_t pin,
* @param value The state to set the digital channel (if it is configured as an
* output)
*/
void setDIO(HalDigitalHandle dio_port_handle, short value, int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, short value,
int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -250,8 +251,8 @@ void setDIO(HalDigitalHandle dio_port_handle, short value, int32_t* status) {
* @param channel The digital I/O channel
* @return The state of the specified channel
*/
bool getDIO(HalDigitalHandle dio_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -283,8 +284,8 @@ bool getDIO(HalDigitalHandle dio_port_handle, int32_t* status) {
* @param channel The digital I/O channel
* @return The direction of the specified channel
*/
bool getDIODirection(HalDigitalHandle dio_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
bool HAL_GetDIODirection(HAL_DigitalHandle dio_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -311,9 +312,9 @@ bool getDIODirection(HalDigitalHandle dio_port_handle, int32_t* status) {
* @param channel The Digital Output channel that the pulse should be output on
* @param pulseLength The active length of the pulse (in seconds)
*/
void pulse(HalDigitalHandle dio_port_handle, double pulseLength,
int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
void HAL_Pulse(HAL_DigitalHandle dio_port_handle, double pulseLength,
int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -337,8 +338,8 @@ void pulse(HalDigitalHandle dio_port_handle, double pulseLength,
*
* @return A pulse is in progress
*/
bool isPulsing(HalDigitalHandle dio_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
bool HAL_IsPulsing(HAL_DigitalHandle dio_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -357,7 +358,7 @@ bool isPulsing(HalDigitalHandle dio_port_handle, int32_t* status) {
*
* @return A pulse on some line is in progress
*/
bool isAnyPulsing(int32_t* status) {
bool HAL_IsAnyPulsing(int32_t* status) {
tDIO::tPulse pulseRegister = digitalSystem->readPulse(status);
return pulseRegister.Headers != 0 && pulseRegister.MXP != 0;
}
@@ -370,9 +371,9 @@ bool isAnyPulsing(int32_t* status) {
* @param filter_index The filter index. Must be in the range 0 - 3,
* where 0 means "none" and 1 - 3 means filter # filter_index - 1.
*/
void setFilterSelect(HalDigitalHandle dio_port_handle, int filter_index,
int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
void HAL_SetFilterSelect(HAL_DigitalHandle dio_port_handle, int filter_index,
int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -395,8 +396,8 @@ void setFilterSelect(HalDigitalHandle dio_port_handle, int filter_index,
* @return filter_index The filter index. Must be in the range 0 - 3,
* where 0 means "none" and 1 - 3 means filter # filter_index - 1.
*/
int getFilterSelect(HalDigitalHandle dio_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
int HAL_GetFilterSelect(HAL_DigitalHandle dio_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -422,7 +423,7 @@ int getFilterSelect(HalDigitalHandle dio_port_handle, int32_t* status) {
* @param value The number of cycles that the signal must not transition to be
* counted as a transition.
*/
void setFilterPeriod(int filter_index, uint32_t value, int32_t* status) {
void HAL_SetFilterPeriod(int filter_index, uint32_t value, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
digitalSystem->writeFilterPeriodHdr(filter_index, value, status);
if (*status == 0) {
@@ -442,7 +443,7 @@ void setFilterPeriod(int filter_index, uint32_t value, int32_t* status) {
* @param value The number of cycles that the signal must not transition to be
* counted as a transition.
*/
uint32_t getFilterPeriod(int filter_index, int32_t* status) {
uint32_t HAL_GetFilterPeriod(int filter_index, int32_t* status) {
uint32_t hdr_period = 0;
uint32_t mxp_period = 0;
{

View File

@@ -29,7 +29,7 @@ tPWM* pwmSystem = nullptr;
bool digitalSystemsInitialized = false;
DigitalHandleResource<HalDigitalHandle, DigitalPort,
DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
kNumDigitalPins + kNumPWMHeaders>
digitalPinHandles;
@@ -109,18 +109,18 @@ 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(HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType,
extern "C++" bool remapDigitalSource(HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
uint32_t& pin, uint8_t& module,
bool& analogTrigger) {
if (isHandleType(digitalSourceHandle, HalHandleEnum::AnalogTrigger)) {
if (isHandleType(digitalSourceHandle, HAL_HandleEnum::AnalogTrigger)) {
// If handle passed, index is not negative
uint32_t index = getHandleIndex(digitalSourceHandle);
pin = (index << 2) + analogTriggerType;
module = pin >> 4;
analogTrigger = true;
return true;
} else if (isHandleType(digitalSourceHandle, HalHandleEnum::DIO)) {
} else if (isHandleType(digitalSourceHandle, HAL_HandleEnum::DIO)) {
uint32_t index = getHandleIndex(digitalSourceHandle);
if (index >= kNumDigitalHeaders) {
pin = remapMXPChannel(index);

View File

@@ -72,13 +72,13 @@ struct DigitalPort {
int32_t minPwm = 0;
};
extern DigitalHandleResource<HalDigitalHandle, DigitalPort,
extern DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
kNumDigitalPins + kNumPWMHeaders>
digitalPinHandles;
void initializeDigital(int32_t* status);
bool remapDigitalSource(HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType, uint32_t& pin,
bool remapDigitalSource(HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType, uint32_t& pin,
uint8_t& module, bool& analogTrigger);
uint32_t remapMXPPWMChannel(uint32_t pin);
uint32_t remapMXPChannel(uint32_t pin);

View File

@@ -17,22 +17,23 @@
using namespace hal;
Encoder::Encoder(HalHandle digitalSourceHandleA,
AnalogTriggerType analogTriggerTypeA,
HalHandle digitalSourceHandleB,
AnalogTriggerType analogTriggerTypeB, bool reverseDirection,
EncoderEncodingType encodingType, int32_t* status) {
Encoder::Encoder(HAL_Handle digitalSourceHandleA,
HAL_AnalogTriggerType analogTriggerTypeA,
HAL_Handle digitalSourceHandleB,
HAL_AnalogTriggerType analogTriggerTypeB,
bool reverseDirection, HAL_EncoderEncodingType encodingType,
int32_t* status) {
m_encodingType = encodingType;
switch (encodingType) {
case HAL_Encoder_k4X: {
m_encodingScale = 4;
m_encoder = initializeFPGAEncoder(
m_encoder = HAL_InitializeFPGAEncoder(
digitalSourceHandleA, analogTriggerTypeA, digitalSourceHandleB,
analogTriggerTypeB, reverseDirection, &m_index, status);
if (*status != 0) {
return;
}
m_counter = HAL_INVALID_HANDLE;
m_counter = HAL_kInvalidHandle;
SetMaxPeriod(.5, status);
break;
}
@@ -51,40 +52,42 @@ Encoder::Encoder(HalHandle digitalSourceHandleA,
}
}
void Encoder::SetupCounter(HalHandle digitalSourceHandleA,
AnalogTriggerType analogTriggerTypeA,
HalHandle digitalSourceHandleB,
AnalogTriggerType analogTriggerTypeB,
void Encoder::SetupCounter(HAL_Handle digitalSourceHandleA,
HAL_AnalogTriggerType analogTriggerTypeA,
HAL_Handle digitalSourceHandleB,
HAL_AnalogTriggerType analogTriggerTypeB,
bool reverseDirection,
EncoderEncodingType encodingType, int32_t* status) {
HAL_EncoderEncodingType encodingType,
int32_t* status) {
m_encodingScale = encodingType == HAL_Encoder_k1X ? 1 : 2;
m_counter = initializeCounter(kExternalDirection, &m_index, status);
m_counter =
HAL_InitializeCounter(HAL_Counter_kExternalDirection, &m_index, status);
if (*status != 0) return;
setCounterMaxPeriod(m_counter, 0.5, status);
HAL_SetCounterMaxPeriod(m_counter, 0.5, status);
if (*status != 0) return;
setCounterUpSource(m_counter, digitalSourceHandleA, analogTriggerTypeA,
status);
HAL_SetCounterUpSource(m_counter, digitalSourceHandleA, analogTriggerTypeA,
status);
if (*status != 0) return;
setCounterDownSource(m_counter, digitalSourceHandleB, analogTriggerTypeB,
status);
HAL_SetCounterDownSource(m_counter, digitalSourceHandleB, analogTriggerTypeB,
status);
if (*status != 0) return;
if (encodingType == HAL_Encoder_k1X) {
setCounterUpSourceEdge(m_counter, true, false, status);
setCounterAverageSize(m_counter, 1, status);
HAL_SetCounterUpSourceEdge(m_counter, true, false, status);
HAL_SetCounterAverageSize(m_counter, 1, status);
} else {
setCounterUpSourceEdge(m_counter, true, true, status);
setCounterAverageSize(m_counter, 2, status);
HAL_SetCounterUpSourceEdge(m_counter, true, true, status);
HAL_SetCounterAverageSize(m_counter, 2, status);
}
setCounterDownSourceEdge(m_counter, reverseDirection, true, status);
HAL_SetCounterDownSourceEdge(m_counter, reverseDirection, true, status);
}
Encoder::~Encoder() {
if (m_counter != HAL_INVALID_HANDLE) {
if (m_counter != HAL_kInvalidHandle) {
int32_t status = 0;
freeCounter(m_counter, &status);
HAL_FreeCounter(m_counter, &status);
} else {
int32_t status = 0;
freeFPGAEncoder(m_encoder, &status);
HAL_FreeFPGAEncoder(m_encoder, &status);
}
}
@@ -95,9 +98,9 @@ int32_t Encoder::Get(int32_t* status) const {
int32_t Encoder::GetRaw(int32_t* status) const {
if (m_counter) {
return getCounter(m_counter, status);
return HAL_GetCounter(m_counter, status);
} else {
return getFPGAEncoder(m_encoder, status);
return HAL_GetFPGAEncoder(m_encoder, status);
}
}
@@ -107,41 +110,41 @@ int32_t Encoder::GetEncodingScale(int32_t* status) const {
void Encoder::Reset(int32_t* status) {
if (m_counter) {
resetCounter(m_counter, status);
HAL_ResetCounter(m_counter, status);
} else {
resetFPGAEncoder(m_encoder, status);
HAL_ResetFPGAEncoder(m_encoder, status);
}
}
double Encoder::GetPeriod(int32_t* status) const {
if (m_counter) {
return getCounterPeriod(m_counter, status) / DecodingScaleFactor();
return HAL_GetCounterPeriod(m_counter, status) / DecodingScaleFactor();
} else {
return getFPGAEncoderPeriod(m_encoder, status);
return HAL_GetFPGAEncoderPeriod(m_encoder, status);
}
}
void Encoder::SetMaxPeriod(double maxPeriod, int32_t* status) {
if (m_counter) {
setCounterMaxPeriod(m_counter, maxPeriod, status);
HAL_SetCounterMaxPeriod(m_counter, maxPeriod, status);
} else {
setFPGAEncoderMaxPeriod(m_encoder, maxPeriod, status);
HAL_SetFPGAEncoderMaxPeriod(m_encoder, maxPeriod, status);
}
}
bool Encoder::GetStopped(int32_t* status) const {
if (m_counter) {
return getCounterStopped(m_counter, status);
return HAL_GetCounterStopped(m_counter, status);
} else {
return getFPGAEncoderStopped(m_encoder, status);
return HAL_GetFPGAEncoderStopped(m_encoder, status);
}
}
bool Encoder::GetDirection(int32_t* status) const {
if (m_counter) {
return getCounterDirection(m_counter, status);
return HAL_GetCounterDirection(m_counter, status);
} else {
return getFPGAEncoderDirection(m_encoder, status);
return HAL_GetFPGAEncoderDirection(m_encoder, status);
}
}
@@ -163,9 +166,9 @@ void Encoder::SetDistancePerPulse(double distancePerPulse, int32_t* status) {
void Encoder::SetReverseDirection(bool reverseDirection, int32_t* status) {
if (m_counter) {
setCounterReverseDirection(m_counter, reverseDirection, status);
HAL_SetCounterReverseDirection(m_counter, reverseDirection, status);
} else {
setFPGAEncoderReverseDirection(m_encoder, reverseDirection, status);
HAL_SetFPGAEncoderReverseDirection(m_encoder, reverseDirection, status);
}
}
@@ -175,23 +178,23 @@ void Encoder::SetSamplesToAverage(int samplesToAverage, int32_t* status) {
return;
}
if (m_counter) {
setCounterSamplesToAverage(m_counter, samplesToAverage, status);
HAL_SetCounterSamplesToAverage(m_counter, samplesToAverage, status);
} else {
setFPGAEncoderSamplesToAverage(m_encoder, samplesToAverage, status);
HAL_SetFPGAEncoderSamplesToAverage(m_encoder, samplesToAverage, status);
}
}
int32_t Encoder::GetSamplesToAverage(int32_t* status) const {
if (m_counter) {
return getCounterSamplesToAverage(m_counter, status);
return HAL_GetCounterSamplesToAverage(m_counter, status);
} else {
return getFPGAEncoderSamplesToAverage(m_encoder, status);
return HAL_GetFPGAEncoderSamplesToAverage(m_encoder, status);
}
}
void Encoder::SetIndexSource(HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType,
EncoderIndexingType type, int32_t* status) {
void Encoder::SetIndexSource(HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
HAL_EncoderIndexingType type, int32_t* status) {
if (m_counter) {
*status = HAL_COUNTER_NOT_SUPPORTED;
return;
@@ -200,8 +203,9 @@ void Encoder::SetIndexSource(HalHandle digitalSourceHandle,
(type == HAL_kResetWhileHigh) || (type == HAL_kResetOnRisingEdge);
bool edgeSensitive =
(type == HAL_kResetOnFallingEdge) || (type == HAL_kResetOnRisingEdge);
setFPGAEncoderIndexSource(m_encoder, digitalSourceHandle, analogTriggerType,
activeHigh, edgeSensitive, status);
HAL_SetFPGAEncoderIndexSource(m_encoder, digitalSourceHandle,
analogTriggerType, activeHigh, edgeSensitive,
status);
}
double Encoder::DecodingScaleFactor() const {
@@ -217,33 +221,34 @@ double Encoder::DecodingScaleFactor() const {
}
}
static LimitedClassedHandleResource<HalEncoderHandle, Encoder,
static LimitedClassedHandleResource<HAL_EncoderHandle, Encoder,
kNumEncoders + kNumCounters,
HalHandleEnum::Encoder>
HAL_HandleEnum::Encoder>
encoderHandles;
extern "C" {
HalEncoderHandle initializeEncoder(
HalHandle digitalSourceHandleA, AnalogTriggerType analogTriggerTypeA,
HalHandle digitalSourceHandleB, AnalogTriggerType analogTriggerTypeB,
bool reverseDirection, EncoderEncodingType encodingType, int32_t* status) {
HAL_EncoderHandle HAL_InitializeEncoder(
HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
bool reverseDirection, HAL_EncoderEncodingType encodingType,
int32_t* status) {
auto encoder = std::make_shared<Encoder>(
digitalSourceHandleA, analogTriggerTypeA, digitalSourceHandleB,
analogTriggerTypeB, reverseDirection, encodingType, status);
if (*status != 0) return HAL_INVALID_HANDLE; // return in creation error
if (*status != 0) return HAL_kInvalidHandle; // return in creation error
auto handle = encoderHandles.Allocate(encoder);
if (handle == HAL_INVALID_HANDLE) {
if (handle == HAL_kInvalidHandle) {
*status = NO_AVAILABLE_RESOURCES;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
return handle;
}
void freeEncoder(HalEncoderHandle encoder_handle, int32_t* status) {
void HAL_FreeEncoder(HAL_EncoderHandle encoder_handle, int32_t* status) {
encoderHandles.Free(encoder_handle);
}
int32_t getEncoder(HalEncoderHandle encoder_handle, int32_t* status) {
int32_t HAL_GetEncoder(HAL_EncoderHandle encoder_handle, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -252,7 +257,7 @@ int32_t getEncoder(HalEncoderHandle encoder_handle, int32_t* status) {
return encoder->Get(status);
}
int32_t getEncoderRaw(HalEncoderHandle encoder_handle, int32_t* status) {
int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoder_handle, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -261,8 +266,8 @@ int32_t getEncoderRaw(HalEncoderHandle encoder_handle, int32_t* status) {
return encoder->GetRaw(status);
}
int32_t getEncoderEncodingScale(HalEncoderHandle encoder_handle,
int32_t* status) {
int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoder_handle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -271,7 +276,7 @@ int32_t getEncoderEncodingScale(HalEncoderHandle encoder_handle,
return encoder->GetEncodingScale(status);
}
void resetEncoder(HalEncoderHandle encoder_handle, int32_t* status) {
void HAL_ResetEncoder(HAL_EncoderHandle encoder_handle, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -280,7 +285,8 @@ void resetEncoder(HalEncoderHandle encoder_handle, int32_t* status) {
encoder->Reset(status);
}
int32_t getEncoderPeriod(HalEncoderHandle encoder_handle, int32_t* status) {
int32_t HAL_GetEncoderPeriod(HAL_EncoderHandle encoder_handle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -289,8 +295,8 @@ int32_t getEncoderPeriod(HalEncoderHandle encoder_handle, int32_t* status) {
return encoder->GetPeriod(status);
}
void setEncoderMaxPeriod(HalEncoderHandle encoder_handle, double maxPeriod,
int32_t* status) {
void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoder_handle, double maxPeriod,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -299,7 +305,8 @@ void setEncoderMaxPeriod(HalEncoderHandle encoder_handle, double maxPeriod,
encoder->SetMaxPeriod(maxPeriod, status);
}
uint8_t getEncoderStopped(HalEncoderHandle encoder_handle, int32_t* status) {
uint8_t HAL_GetEncoderStopped(HAL_EncoderHandle encoder_handle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -308,7 +315,8 @@ uint8_t getEncoderStopped(HalEncoderHandle encoder_handle, int32_t* status) {
return encoder->GetStopped(status);
}
uint8_t getEncoderDirection(HalEncoderHandle encoder_handle, int32_t* status) {
uint8_t HAL_GetEncoderDirection(HAL_EncoderHandle encoder_handle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -317,7 +325,8 @@ uint8_t getEncoderDirection(HalEncoderHandle encoder_handle, int32_t* status) {
return encoder->GetDirection(status);
}
double getEncoderDistance(HalEncoderHandle encoder_handle, int32_t* status) {
double HAL_GetEncoderDistance(HAL_EncoderHandle encoder_handle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -326,7 +335,7 @@ double getEncoderDistance(HalEncoderHandle encoder_handle, int32_t* status) {
return encoder->GetDistance(status);
}
double getEncoderRate(HalEncoderHandle encoder_handle, int32_t* status) {
double HAL_GetEncoderRate(HAL_EncoderHandle encoder_handle, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -335,8 +344,8 @@ double getEncoderRate(HalEncoderHandle encoder_handle, int32_t* status) {
return encoder->GetRate(status);
}
void setEncoderMinRate(HalEncoderHandle encoder_handle, double minRate,
int32_t* status) {
void HAL_SetEncoderMinRate(HAL_EncoderHandle encoder_handle, double minRate,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -345,8 +354,8 @@ void setEncoderMinRate(HalEncoderHandle encoder_handle, double minRate,
encoder->SetMinRate(minRate, status);
}
void setEncoderDistancePerPulse(HalEncoderHandle encoder_handle,
double distancePerPulse, int32_t* status) {
void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoder_handle,
double distancePerPulse, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -355,8 +364,8 @@ void setEncoderDistancePerPulse(HalEncoderHandle encoder_handle,
encoder->SetDistancePerPulse(distancePerPulse, status);
}
void setEncoderReverseDirection(HalEncoderHandle encoder_handle,
uint8_t reverseDirection, int32_t* status) {
void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoder_handle,
uint8_t reverseDirection, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -365,8 +374,8 @@ void setEncoderReverseDirection(HalEncoderHandle encoder_handle,
encoder->SetReverseDirection(reverseDirection, status);
}
void setEncoderSamplesToAverage(HalEncoderHandle encoder_handle,
int32_t samplesToAverage, int32_t* status) {
void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoder_handle,
int32_t samplesToAverage, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -375,8 +384,8 @@ void setEncoderSamplesToAverage(HalEncoderHandle encoder_handle,
encoder->SetSamplesToAverage(samplesToAverage, status);
}
int32_t getEncoderSamplesToAverage(HalEncoderHandle encoder_handle,
int32_t* status) {
int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoder_handle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -385,8 +394,8 @@ int32_t getEncoderSamplesToAverage(HalEncoderHandle encoder_handle,
return encoder->GetSamplesToAverage(status);
}
double getEncoderDecodingScaleFactor(HalEncoderHandle encoder_handle,
int32_t* status) {
double HAL_GetEncoderDecodingScaleFactor(HAL_EncoderHandle encoder_handle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -395,8 +404,8 @@ double getEncoderDecodingScaleFactor(HalEncoderHandle encoder_handle,
return encoder->DecodingScaleFactor();
}
double getEncoderDistancePerPulse(HalEncoderHandle encoder_handle,
int32_t* status) {
double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoder_handle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -405,8 +414,8 @@ double getEncoderDistancePerPulse(HalEncoderHandle encoder_handle,
return encoder->GetDistancePerPulse();
}
EncoderEncodingType getEncoderEncodingType(HalEncoderHandle encoder_handle,
int32_t* status) {
HAL_EncoderEncodingType HAL_GetEncoderEncodingType(
HAL_EncoderHandle encoder_handle, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -415,10 +424,10 @@ EncoderEncodingType getEncoderEncodingType(HalEncoderHandle encoder_handle,
return encoder->GetEncodingType();
}
void setEncoderIndexSource(HalEncoderHandle encoder_handle,
HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType,
EncoderIndexingType type, int32_t* status) {
void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoder_handle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
HAL_EncoderIndexingType type, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -427,7 +436,8 @@ void setEncoderIndexSource(HalEncoderHandle encoder_handle,
encoder->SetIndexSource(digitalSourceHandle, analogTriggerType, type, status);
}
int32_t getEncoderFPGAIndex(HalEncoderHandle encoder_handle, int32_t* status) {
int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoder_handle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;

View File

@@ -14,10 +14,11 @@
namespace hal {
class Encoder {
public:
Encoder(HalHandle digitalSourceHandleA, AnalogTriggerType analogTriggerTypeA,
HalHandle digitalSourceHandleB, AnalogTriggerType analogTriggerTypeB,
bool reverseDirection, EncoderEncodingType encodingType,
int32_t* status);
Encoder(HAL_Handle digitalSourceHandleA,
HAL_AnalogTriggerType analogTriggerTypeA,
HAL_Handle digitalSourceHandleB,
HAL_AnalogTriggerType analogTriggerTypeB, bool reverseDirection,
HAL_EncoderEncodingType encodingType, int32_t* status);
~Encoder();
// CounterBase interface
@@ -38,9 +39,9 @@ class Encoder {
void SetSamplesToAverage(int samplesToAverage, int32_t* status);
int32_t GetSamplesToAverage(int32_t* status) const;
void SetIndexSource(HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType,
EncoderIndexingType type, int32_t* status);
void SetIndexSource(HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
HAL_EncoderIndexingType type, int32_t* status);
int32_t GetFPGAIndex() const { return m_index; }
@@ -50,24 +51,25 @@ class Encoder {
double GetDistancePerPulse() const { return m_distancePerPulse; }
EncoderEncodingType GetEncodingType() const { return m_encodingType; }
HAL_EncoderEncodingType GetEncodingType() const { return m_encodingType; }
private:
void SetupCounter(HalHandle digitalSourceHandleA,
AnalogTriggerType analogTriggerTypeA,
HalHandle digitalSourceHandleB,
AnalogTriggerType analogTriggerTypeB, bool reverseDirection,
EncoderEncodingType encodingType, int32_t* status);
void SetupCounter(HAL_Handle digitalSourceHandleA,
HAL_AnalogTriggerType analogTriggerTypeA,
HAL_Handle digitalSourceHandleB,
HAL_AnalogTriggerType analogTriggerTypeB,
bool reverseDirection, HAL_EncoderEncodingType encodingType,
int32_t* status);
HalFPGAEncoderHandle m_encoder = HAL_INVALID_HANDLE;
HAL_FPGAEncoderHandle m_encoder = HAL_kInvalidHandle;
HalCounterHandle m_counter = HAL_INVALID_HANDLE;
HAL_CounterHandle m_counter = HAL_kInvalidHandle;
int32_t m_index = 0;
double m_distancePerPulse = 1.0;
EncoderEncodingType m_encodingType;
HAL_EncoderEncodingType m_encodingType;
int32_t m_encodingScale;
};

View File

@@ -22,17 +22,15 @@ struct Encoder {
static const double DECODING_SCALING_FACTOR = 0.25;
static LimitedHandleResource<HalFPGAEncoderHandle, Encoder, kNumEncoders,
HalHandleEnum::FPGAEncoder>
static LimitedHandleResource<HAL_FPGAEncoderHandle, Encoder, kNumEncoders,
HAL_HandleEnum::FPGAEncoder>
fpgaEncoderHandles;
extern "C" {
HalFPGAEncoderHandle initializeFPGAEncoder(HalHandle digitalSourceHandleA,
AnalogTriggerType analogTriggerTypeA,
HalHandle digitalSourceHandleB,
AnalogTriggerType analogTriggerTypeB,
bool reverseDirection,
int32_t* index, int32_t* status) {
HAL_FPGAEncoderHandle HAL_InitializeFPGAEncoder(
HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
bool reverseDirection, int32_t* index, int32_t* status) {
bool routingAnalogTriggerA = false;
uint32_t routingPinA = 0;
uint8_t routingModuleA = 0;
@@ -48,19 +46,19 @@ HalFPGAEncoderHandle initializeFPGAEncoder(HalHandle digitalSourceHandleA,
if (!successA || !successB) {
*status = HAL_HANDLE_ERROR;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
auto handle = fpgaEncoderHandles.Allocate();
if (handle == HAL_INVALID_HANDLE) { // out of resources
if (handle == HAL_kInvalidHandle) { // out of resources
*status = NO_AVAILABLE_RESOURCES;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
auto encoder = fpgaEncoderHandles.Get(handle);
if (encoder == nullptr) { // will only error on thread issue
*status = HAL_HANDLE_ERROR;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
encoder->index = static_cast<uint32_t>(getHandleIndex(handle));
@@ -83,8 +81,8 @@ HalFPGAEncoderHandle initializeFPGAEncoder(HalHandle digitalSourceHandleA,
return handle;
}
void freeFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle,
int32_t* status) {
void HAL_FreeFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
fpgaEncoderHandles.Free(fpga_encoder_handle);
if (encoder == nullptr) {
@@ -98,8 +96,8 @@ void freeFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle,
* Reset the Encoder distance to zero.
* Resets the current count to zero on the encoder.
*/
void resetFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle,
int32_t* status) {
void HAL_ResetFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -114,8 +112,8 @@ void resetFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle,
* factor.
* @return Current fpga count from the encoder
*/
int32_t getFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle,
int32_t* status) {
int32_t HAL_GetFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -134,8 +132,8 @@ int32_t getFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle,
*
* @return Period in seconds of the most recent pulse.
*/
double getFPGAEncoderPeriod(HalFPGAEncoderHandle fpga_encoder_handle,
int32_t* status) {
double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -170,8 +168,8 @@ double getFPGAEncoderPeriod(HalFPGAEncoderHandle fpga_encoder_handle,
* FPGA will
* report the device stopped. This is expressed in seconds.
*/
void setFPGAEncoderMaxPeriod(HalFPGAEncoderHandle fpga_encoder_handle,
double maxPeriod, int32_t* status) {
void HAL_SetFPGAEncoderMaxPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
double maxPeriod, int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -188,8 +186,8 @@ void setFPGAEncoderMaxPeriod(HalFPGAEncoderHandle fpga_encoder_handle,
* one where the most recent pulse width exceeds the MaxPeriod.
* @return True if the encoder is considered stopped.
*/
bool getFPGAEncoderStopped(HalFPGAEncoderHandle fpga_encoder_handle,
int32_t* status) {
bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -202,8 +200,8 @@ bool getFPGAEncoderStopped(HalFPGAEncoderHandle fpga_encoder_handle,
* The last direction the encoder value changed.
* @return The last direction the encoder value changed.
*/
bool getFPGAEncoderDirection(HalFPGAEncoderHandle fpga_encoder_handle,
int32_t* status) {
bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -218,8 +216,9 @@ bool getFPGAEncoderDirection(HalFPGAEncoderHandle fpga_encoder_handle,
* correct software direction regardless of the mounting.
* @param reverseDirection true if the encoder direction should be reversed
*/
void setFPGAEncoderReverseDirection(HalFPGAEncoderHandle fpga_encoder_handle,
bool reverseDirection, int32_t* status) {
void HAL_SetFPGAEncoderReverseDirection(
HAL_FPGAEncoderHandle fpga_encoder_handle, bool reverseDirection,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -234,9 +233,9 @@ void setFPGAEncoderReverseDirection(HalFPGAEncoderHandle fpga_encoder_handle,
* mechanical imperfections or as oversampling to increase resolution.
* @param samplesToAverage The number of samples to average from 1 to 127.
*/
void setFPGAEncoderSamplesToAverage(HalFPGAEncoderHandle fpga_encoder_handle,
uint32_t samplesToAverage,
int32_t* status) {
void HAL_SetFPGAEncoderSamplesToAverage(
HAL_FPGAEncoderHandle fpga_encoder_handle, uint32_t samplesToAverage,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -254,8 +253,8 @@ void setFPGAEncoderSamplesToAverage(HalFPGAEncoderHandle fpga_encoder_handle,
* mechanical imperfections or as oversampling to increase resolution.
* @return SamplesToAverage The number of samples being averaged (from 1 to 127)
*/
uint32_t getFPGAEncoderSamplesToAverage(
HalFPGAEncoderHandle fpga_encoder_handle, int32_t* status) {
uint32_t HAL_GetFPGAEncoderSamplesToAverage(
HAL_FPGAEncoderHandle fpga_encoder_handle, int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -268,11 +267,11 @@ uint32_t getFPGAEncoderSamplesToAverage(
* Set an index source for an encoder, which is an input that resets the
* encoder's count.
*/
void setFPGAEncoderIndexSource(HalFPGAEncoderHandle fpga_encoder_handle,
HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType,
bool activeHigh, bool edgeSensitive,
int32_t* status) {
void HAL_SetFPGAEncoderIndexSource(HAL_FPGAEncoderHandle fpga_encoder_handle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
bool activeHigh, bool edgeSensitive,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;

View File

@@ -13,34 +13,35 @@
#include "HAL/Handles.h"
extern "C" {
HalFPGAEncoderHandle initializeFPGAEncoder(HalHandle digitalSourceHandleA,
AnalogTriggerType analogTriggerTypeA,
HalHandle digitalSourceHandleB,
AnalogTriggerType analogTriggerTypeB,
bool reverseDirection,
int32_t* index, int32_t* status);
void freeFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle, int32_t* status);
void resetFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle,
int32_t* status);
int32_t getFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle,
int32_t* status); // Raw value
double getFPGAEncoderPeriod(HalFPGAEncoderHandle fpga_encoder_handle,
int32_t* status);
void setFPGAEncoderMaxPeriod(HalFPGAEncoderHandle fpga_encoder_handle,
double maxPeriod, int32_t* status);
bool getFPGAEncoderStopped(HalFPGAEncoderHandle fpga_encoder_handle,
int32_t* status);
bool getFPGAEncoderDirection(HalFPGAEncoderHandle fpga_encoder_handle,
int32_t* status);
void setFPGAEncoderReverseDirection(HalFPGAEncoderHandle fpga_encoder_handle,
bool reverseDirection, int32_t* status);
void setFPGAEncoderSamplesToAverage(HalFPGAEncoderHandle fpga_encoder_handle,
uint32_t samplesToAverage, int32_t* status);
uint32_t getFPGAEncoderSamplesToAverage(
HalFPGAEncoderHandle fpga_encoder_handle, int32_t* status);
void setFPGAEncoderIndexSource(HalFPGAEncoderHandle fpga_encoder_handle,
HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType,
bool activeHigh, bool edgeSensitive,
HAL_FPGAEncoderHandle HAL_InitializeFPGAEncoder(
HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
bool reverseDirection, int32_t* index, int32_t* status);
void HAL_FreeFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t* status);
void HAL_ResetFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t* status);
int32_t HAL_GetFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t* status); // Raw value
double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t* status);
void HAL_SetFPGAEncoderMaxPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
double maxPeriod, int32_t* status);
bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t* status);
bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t* status);
void HAL_SetFPGAEncoderReverseDirection(
HAL_FPGAEncoderHandle fpga_encoder_handle, bool reverseDirection,
int32_t* status);
void HAL_SetFPGAEncoderSamplesToAverage(
HAL_FPGAEncoderHandle fpga_encoder_handle, uint32_t samplesToAverage,
int32_t* status);
uint32_t HAL_GetFPGAEncoderSamplesToAverage(
HAL_FPGAEncoderHandle fpga_encoder_handle, int32_t* status);
void HAL_SetFPGAEncoderIndexSource(HAL_FPGAEncoderHandle fpga_encoder_handle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
bool activeHigh, bool edgeSensitive,
int32_t* status);
}

View File

@@ -27,8 +27,6 @@
#include "handles/HandlesInternal.h"
#include "visa/visa.h"
const uint32_t kSystemClockTicksPerMicrosecond = 40;
static tGlobal* global = nullptr;
static tSysWatchdog* watchdog = nullptr;
@@ -36,22 +34,22 @@ static priority_mutex timeMutex;
static priority_mutex msgMutex;
static uint32_t timeEpoch = 0;
static uint32_t prevFPGATime = 0;
static HalNotifierHandle rolloverNotifier = 0;
static HAL_NotifierHandle rolloverNotifier = 0;
using namespace hal;
extern "C" {
HalPortHandle getPort(uint8_t pin) { return createPortHandle(pin, 1); }
HAL_PortHandle HAL_GetPort(uint8_t pin) { return createPortHandle(pin, 1); }
/**
* @deprecated Uses module numbers
*/
HalPortHandle getPortWithModule(uint8_t module, uint8_t pin) {
HAL_PortHandle HAL_GetPortWithModule(uint8_t module, uint8_t pin) {
return createPortHandle(pin, module);
}
const char* getHALErrorMessage(int32_t code) {
const char* HAL_GetErrorMessage(int32_t code) {
switch (code) {
case 0:
return "";
@@ -161,7 +159,7 @@ const char* getHALErrorMessage(int32_t code) {
* For now, expect this to be competition year.
* @return FPGA Version number.
*/
uint16_t getFPGAVersion(int32_t* status) {
uint16_t HAL_GetFPGAVersion(int32_t* status) {
if (!global) {
*status = NiFpga_Status_ResourceNotInitialized;
return 0;
@@ -177,7 +175,7 @@ uint16_t getFPGAVersion(int32_t* status) {
* The 12 least significant bits are the Build Number.
* @return FPGA Revision number.
*/
uint32_t getFPGARevision(int32_t* status) {
uint32_t HAL_GetFPGARevision(int32_t* status) {
if (!global) {
*status = NiFpga_Status_ResourceNotInitialized;
return 0;
@@ -191,7 +189,7 @@ uint32_t getFPGARevision(int32_t* status) {
* @return The current time in microseconds according to the FPGA (since FPGA
* reset).
*/
uint64_t getFPGATime(int32_t* status) {
uint64_t HAL_GetFPGATime(int32_t* status) {
if (!global) {
*status = NiFpga_Status_ResourceNotInitialized;
return 0;
@@ -209,7 +207,7 @@ uint64_t getFPGATime(int32_t* status) {
* Get the state of the "USER" button on the roboRIO
* @return true if the button is currently pressed down
*/
bool getFPGAButton(int32_t* status) {
bool HAL_GetFPGAButton(int32_t* status) {
if (!global) {
*status = NiFpga_Status_ResourceNotInitialized;
return false;
@@ -217,13 +215,13 @@ bool getFPGAButton(int32_t* status) {
return global->readUserButton(status);
}
int HALSetErrorData(const char* errors, int errorsLength, int wait_ms) {
int HAL_SetErrorData(const char* errors, int errorsLength, int wait_ms) {
return setErrorData(errors, errorsLength, wait_ms);
}
int HALSendError(int isError, int32_t errorCode, int isLVCode,
const char* details, const char* location,
const char* callStack, int printMsg) {
int HAL_SendError(int isError, int32_t errorCode, int isLVCode,
const char* details, const char* location,
const char* callStack, int printMsg) {
// Avoid flooding console by keeping track of previous 5 error
// messages and only printing again if they're longer than 1 second old.
static constexpr int KEEP_MSGS = 5;
@@ -232,7 +230,7 @@ int HALSendError(int isError, int32_t errorCode, int isLVCode,
static uint64_t prev_msg_time[KEEP_MSGS] = {0, 0, 0};
int32_t status = 0;
uint64_t curTime = getFPGATime(&status);
uint64_t curTime = HAL_GetFPGATime(&status);
int i;
for (i = 0; i < KEEP_MSGS; ++i) {
if (prev_msg[i] == details) break;
@@ -267,7 +265,7 @@ int HALSendError(int isError, int32_t errorCode, int isLVCode,
return retval;
}
bool HALGetSystemActive(int32_t* status) {
bool HAL_GetSystemActive(int32_t* status) {
if (!watchdog) {
*status = NiFpga_Status_ResourceNotInitialized;
return false;
@@ -275,7 +273,7 @@ bool HALGetSystemActive(int32_t* status) {
return watchdog->readStatus_SystemActive(status);
}
bool HALGetBrownedOut(int32_t* status) {
bool HAL_GetBrownedOut(int32_t* status) {
if (!watchdog) {
*status = NiFpga_Status_ResourceNotInitialized;
return false;
@@ -291,13 +289,14 @@ static void HALCleanupAtExit() {
static void timerRollover(uint64_t currentTime, void*) {
// reschedule timer for next rollover
int32_t status = 0;
updateNotifierAlarm(rolloverNotifier, currentTime + 0x80000000ULL, &status);
HAL_UpdateNotifierAlarm(rolloverNotifier, currentTime + 0x80000000ULL,
&status);
}
/**
* Call this to start up HAL. This is required for robot programs.
*/
int HALInitialize(int mode) {
int HAL_Initialize(int mode) {
setlinebuf(stdin);
setlinebuf(stdout);
@@ -315,11 +314,12 @@ int HALInitialize(int mode) {
std::atexit(HALCleanupAtExit);
if (!rolloverNotifier)
rolloverNotifier = initializeNotifier(timerRollover, nullptr, &status);
rolloverNotifier = HAL_InitializeNotifier(timerRollover, nullptr, &status);
if (status == 0) {
uint64_t curTime = getFPGATime(&status);
uint64_t curTime = HAL_GetFPGATime(&status);
if (status == 0)
updateNotifierAlarm(rolloverNotifier, curTime + 0x80000000ULL, &status);
HAL_UpdateNotifierAlarm(rolloverNotifier, curTime + 0x80000000ULL,
&status);
}
// Kill any previous robot programs
@@ -363,8 +363,8 @@ int HALInitialize(int mode) {
return 1;
}
uint32_t HALReport(uint8_t resource, uint8_t instanceNumber, uint8_t context,
const char* feature) {
uint32_t HAL_Report(uint8_t resource, uint8_t instanceNumber, uint8_t context,
const char* feature) {
if (feature == nullptr) {
feature = "";
}

View File

@@ -22,8 +22,8 @@ static uint8_t i2CMXPObjCount = 0;
static uint8_t i2COnBoardHandle = 0;
static uint8_t i2CMXPHandle = 0;
static HalDigitalHandle i2CMXPDigitalHandle1 = HAL_INVALID_HANDLE;
static HalDigitalHandle i2CMXPDigitalHandle2 = HAL_INVALID_HANDLE;
static HAL_DigitalHandle i2CMXPDigitalHandle1 = HAL_kInvalidHandle;
static HAL_DigitalHandle i2CMXPDigitalHandle2 = HAL_kInvalidHandle;
extern "C" {
/*
@@ -31,7 +31,7 @@ extern "C" {
* If opening the MXP port, also sets up the pin functions appropriately
* @param port The port to open, 0 for the on-board, 1 for the MXP.
*/
void i2CInitialize(uint8_t port, int32_t* status) {
void HAL_I2CInitialize(uint8_t port, int32_t* status) {
initializeDigital(status);
if (*status != 0) return;
@@ -51,13 +51,13 @@ void i2CInitialize(uint8_t port, int32_t* status) {
} else if (port == 1) {
i2CMXPObjCount++;
if (i2CMXPHandle > 0) return;
if ((i2CMXPDigitalHandle1 = initializeDIOPort(
getPort(24), false, status)) == HAL_INVALID_HANDLE) {
if ((i2CMXPDigitalHandle1 = HAL_InitializeDIOPort(
HAL_GetPort(24), false, status)) == HAL_kInvalidHandle) {
return;
}
if ((i2CMXPDigitalHandle2 = initializeDIOPort(
getPort(25), false, status)) == HAL_INVALID_HANDLE) {
freeDIOPort(i2CMXPDigitalHandle1); // free the first port allocated
if ((i2CMXPDigitalHandle2 = HAL_InitializeDIOPort(
HAL_GetPort(25), false, status)) == HAL_kInvalidHandle) {
HAL_FreeDIOPort(i2CMXPDigitalHandle1); // free the first port allocated
return;
}
digitalSystem->writeEnableMXPSpecialFunction(
@@ -80,9 +80,9 @@ void i2CInitialize(uint8_t port, int32_t* status) {
* @param receiveSize Number of bytes to read from the device.
* @return The number of bytes read (>= 0) or -1 on transfer abort.
*/
int32_t i2CTransaction(uint8_t port, uint8_t deviceAddress, uint8_t* dataToSend,
uint8_t sendSize, uint8_t* dataReceived,
uint8_t receiveSize) {
int32_t HAL_I2CTransaction(uint8_t port, uint8_t deviceAddress,
uint8_t* dataToSend, uint8_t sendSize,
uint8_t* dataReceived, uint8_t receiveSize) {
if (port > 1) {
// Set port out of range error here
return -1;
@@ -111,8 +111,8 @@ int32_t i2CTransaction(uint8_t port, uint8_t deviceAddress, uint8_t* dataToSend,
* @param data The byte to write to the register on the device.
* @return The number of bytes written (>= 0) or -1 on transfer abort.
*/
int32_t i2CWrite(uint8_t port, uint8_t deviceAddress, uint8_t* dataToSend,
uint8_t sendSize) {
int32_t HAL_I2CWrite(uint8_t port, uint8_t deviceAddress, uint8_t* dataToSend,
uint8_t sendSize) {
if (port > 1) {
// Set port out of range error here
return -1;
@@ -141,8 +141,8 @@ int32_t i2CWrite(uint8_t port, uint8_t deviceAddress, uint8_t* dataToSend,
* device.
* @return The number of bytes read (>= 0) or -1 on transfer abort.
*/
int32_t i2CRead(uint8_t port, uint8_t deviceAddress, uint8_t* buffer,
uint8_t count) {
int32_t HAL_I2CRead(uint8_t port, uint8_t deviceAddress, uint8_t* buffer,
uint8_t count) {
if (port > 1) {
// Set port out of range error here
return -1;
@@ -157,7 +157,7 @@ int32_t i2CRead(uint8_t port, uint8_t deviceAddress, uint8_t* buffer,
}
}
void i2CClose(uint8_t port) {
void HAL_I2CClose(uint8_t port) {
if (port > 1) {
// Set port out of range error here
return;
@@ -173,8 +173,8 @@ void i2CClose(uint8_t port) {
}
if (port == 1) {
freeDIOPort(i2CMXPDigitalHandle1);
freeDIOPort(i2CMXPDigitalHandle2);
HAL_FreeDIOPort(i2CMXPDigitalHandle1);
HAL_FreeDIOPort(i2CMXPDigitalHandle2);
}
return;
}

View File

@@ -27,17 +27,17 @@ struct Interrupt // FIXME: why is this internal?
};
}
static LimitedHandleResource<HalInterruptHandle, Interrupt, kNumInterrupts,
HalHandleEnum::Interrupt>
static LimitedHandleResource<HAL_InterruptHandle, Interrupt, kNumInterrupts,
HAL_HandleEnum::Interrupt>
interruptHandles;
extern "C" {
HalInterruptHandle initializeInterrupts(bool watcher, int32_t* status) {
HalInterruptHandle handle = interruptHandles.Allocate();
if (handle == HAL_INVALID_HANDLE) {
HAL_InterruptHandle HAL_InitializeInterrupts(bool watcher, int32_t* status) {
HAL_InterruptHandle handle = interruptHandles.Allocate();
if (handle == HAL_kInvalidHandle) {
*status = NO_AVAILABLE_RESOURCES;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
auto anInterrupt = interruptHandles.Get(handle);
uint32_t interruptIndex = static_cast<uint32_t>(getHandleIndex(handle));
@@ -49,7 +49,8 @@ HalInterruptHandle initializeInterrupts(bool watcher, int32_t* status) {
return handle;
}
void cleanInterrupts(HalInterruptHandle interrupt_handle, int32_t* status) {
void HAL_CleanInterrupts(HAL_InterruptHandle interrupt_handle,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -67,8 +68,9 @@ void cleanInterrupts(HalInterruptHandle interrupt_handle, int32_t* status) {
* waitForInterrupt was called.
* @return The mask of interrupts that fired.
*/
uint32_t waitForInterrupt(HalInterruptHandle interrupt_handle, double timeout,
bool ignorePrevious, int32_t* status) {
uint32_t HAL_WaitForInterrupt(HAL_InterruptHandle interrupt_handle,
double timeout, bool ignorePrevious,
int32_t* status) {
uint32_t result;
auto anInterrupt = interruptHandles.Get(interrupt_handle);
if (anInterrupt == nullptr) {
@@ -94,7 +96,8 @@ uint32_t waitForInterrupt(HalInterruptHandle interrupt_handle, double timeout,
* time to do the setup of the other options before starting to field
* interrupts.
*/
void enableInterrupts(HalInterruptHandle interrupt_handle, int32_t* status) {
void HAL_EnableInterrupts(HAL_InterruptHandle interrupt_handle,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -106,7 +109,8 @@ void enableInterrupts(HalInterruptHandle interrupt_handle, int32_t* status) {
/**
* Disable Interrupts without without deallocating structures.
*/
void disableInterrupts(HalInterruptHandle interrupt_handle, int32_t* status) {
void HAL_DisableInterrupts(HAL_InterruptHandle interrupt_handle,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -120,8 +124,8 @@ void disableInterrupts(HalInterruptHandle interrupt_handle, int32_t* status) {
* This is in the same time domain as GetClock().
* @return Timestamp in seconds since boot.
*/
double readRisingTimestamp(HalInterruptHandle interrupt_handle,
int32_t* status) {
double HAL_ReadRisingTimestamp(HAL_InterruptHandle interrupt_handle,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -136,8 +140,8 @@ double readRisingTimestamp(HalInterruptHandle interrupt_handle,
* This is in the same time domain as GetClock().
* @return Timestamp in seconds since boot.
*/
double readFallingTimestamp(HalInterruptHandle interrupt_handle,
int32_t* status) {
double HAL_ReadFallingTimestamp(HAL_InterruptHandle interrupt_handle,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -147,9 +151,10 @@ double readFallingTimestamp(HalInterruptHandle interrupt_handle,
return timestamp * 1e-6;
}
void requestInterrupts(HalInterruptHandle interrupt_handle,
HalHandle digitalSourceHandle,
AnalogTriggerType analogTriggerType, int32_t* status) {
void HAL_RequestInterrupts(HAL_InterruptHandle interrupt_handle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -172,9 +177,9 @@ void requestInterrupts(HalInterruptHandle interrupt_handle,
anInterrupt->anInterrupt->writeConfig_Source_Module(routingModule, status);
}
void attachInterruptHandler(HalInterruptHandle interrupt_handle,
InterruptHandlerFunction handler, void* param,
int32_t* status) {
void HAL_AttachInterruptHandler(HAL_InterruptHandle interrupt_handle,
InterruptHandlerFunction handler, void* param,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -183,9 +188,9 @@ void attachInterruptHandler(HalInterruptHandle interrupt_handle,
anInterrupt->manager->registerHandler(handler, param, status);
}
void setInterruptUpSourceEdge(HalInterruptHandle interrupt_handle,
bool risingEdge, bool fallingEdge,
int32_t* status) {
void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interrupt_handle,
bool risingEdge, bool fallingEdge,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;

View File

@@ -41,8 +41,8 @@ static std::atomic_int notifierRefCount{0};
using namespace hal;
static UnlimitedHandleResource<HalNotifierHandle, Notifier,
HalHandleEnum::Notifier>
static UnlimitedHandleResource<HAL_NotifierHandle, Notifier,
HAL_HandleEnum::Notifier>
notifierHandles;
// internal version of updateAlarm used during the alarmCallback when we know
@@ -85,7 +85,7 @@ static void alarmCallback(uint32_t, void*) {
std::shared_ptr<Notifier> notifier = notifiers;
while (notifier) {
if (notifier->triggerTime != UINT64_MAX) {
if (currentTime == 0) currentTime = getFPGATime(&status);
if (currentTime == 0) currentTime = HAL_GetFPGATime(&status);
if (notifier->triggerTime < currentTime) {
notifier->triggerTime = UINT64_MAX;
auto process = notifier->process;
@@ -108,8 +108,8 @@ static void cleanupNotifierAtExit() {
extern "C" {
HalNotifierHandle initializeNotifier(void (*process)(uint64_t, void*),
void* param, int32_t* status) {
HAL_NotifierHandle HAL_InitializeNotifier(void (*process)(uint64_t, void*),
void* param, int32_t* status) {
if (!process) {
*status = NULL_PARAMETER;
return 0;
@@ -139,7 +139,7 @@ HalNotifierHandle initializeNotifier(void (*process)(uint64_t, void*),
return notifierHandles.Allocate(notifier);
}
void cleanNotifier(HalNotifierHandle notifier_handle, int32_t* status) {
void HAL_CleanNotifier(HAL_NotifierHandle notifier_handle, int32_t* status) {
{
std::lock_guard<priority_recursive_mutex> sync(notifierMutex);
auto notifier = notifierHandles.Get(notifier_handle);
@@ -169,14 +169,15 @@ void cleanNotifier(HalNotifierHandle notifier_handle, int32_t* status) {
}
}
void* getNotifierParam(HalNotifierHandle notifier_handle, int32_t* status) {
void* HAL_GetNotifierParam(HAL_NotifierHandle notifier_handle,
int32_t* status) {
auto notifier = notifierHandles.Get(notifier_handle);
if (!notifier) return nullptr;
return notifier->param;
}
void updateNotifierAlarm(HalNotifierHandle notifier_handle,
uint64_t triggerTime, int32_t* status) {
void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifier_handle,
uint64_t triggerTime, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(notifierMutex);
auto notifier = notifierHandles.Get(notifier_handle);
@@ -184,7 +185,8 @@ void updateNotifierAlarm(HalNotifierHandle notifier_handle,
updateNotifierAlarmInternal(notifier, triggerTime, status);
}
void stopNotifierAlarm(HalNotifierHandle notifier_handle, int32_t* status) {
void HAL_StopNotifierAlarm(HAL_NotifierHandle notifier_handle,
int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(notifierMutex);
auto notifier = notifierHandles.Get(notifier_handle);
if (!notifier) return;

View File

@@ -17,13 +17,13 @@ static PDP* pdp[kNumPDPModules] = {nullptr};
extern "C" {
void initializePDP(uint8_t module) {
void HAL_InitializePDP(uint8_t module) {
if (!pdp[module]) {
pdp[module] = new PDP(module);
}
}
double getPDPTemperature(uint8_t module, int32_t* status) {
double HAL_GetPDPTemperature(uint8_t module, int32_t* status) {
double temperature;
*status = pdp[module]->GetTemperature(temperature);
@@ -31,7 +31,7 @@ double getPDPTemperature(uint8_t module, int32_t* status) {
return temperature;
}
double getPDPVoltage(uint8_t module, int32_t* status) {
double HAL_GetPDPVoltage(uint8_t module, int32_t* status) {
double voltage;
*status = pdp[module]->GetVoltage(voltage);
@@ -39,7 +39,8 @@ double getPDPVoltage(uint8_t module, int32_t* status) {
return voltage;
}
double getPDPChannelCurrent(uint8_t module, uint8_t channel, int32_t* status) {
double HAL_GetPDPChannelCurrent(uint8_t module, uint8_t channel,
int32_t* status) {
double current;
*status = pdp[module]->GetChannelCurrent(channel, current);
@@ -47,7 +48,7 @@ double getPDPChannelCurrent(uint8_t module, uint8_t channel, int32_t* status) {
return current;
}
double getPDPTotalCurrent(uint8_t module, int32_t* status) {
double HAL_GetPDPTotalCurrent(uint8_t module, int32_t* status) {
double current;
*status = pdp[module]->GetTotalCurrent(current);
@@ -55,7 +56,7 @@ double getPDPTotalCurrent(uint8_t module, int32_t* status) {
return current;
}
double getPDPTotalPower(uint8_t module, int32_t* status) {
double HAL_GetPDPTotalPower(uint8_t module, int32_t* status) {
double power;
*status = pdp[module]->GetTotalPower(power);
@@ -63,7 +64,7 @@ double getPDPTotalPower(uint8_t module, int32_t* status) {
return power;
}
double getPDPTotalEnergy(uint8_t module, int32_t* status) {
double HAL_GetPDPTotalEnergy(uint8_t module, int32_t* status) {
double energy;
*status = pdp[module]->GetTotalEnergy(energy);
@@ -71,11 +72,11 @@ double getPDPTotalEnergy(uint8_t module, int32_t* status) {
return energy;
}
void resetPDPTotalEnergy(uint8_t module, int32_t* status) {
void HAL_ResetPDPTotalEnergy(uint8_t module, int32_t* status) {
*status = pdp[module]->ResetEnergy();
}
void clearPDPStickyFaults(uint8_t module, int32_t* status) {
void HAL_ClearPDPStickyFaults(uint8_t module, int32_t* status) {
*status = pdp[module]->ClearStickyFaults();
}

View File

@@ -41,15 +41,16 @@ static inline int32_t GetFullRangeScaleFactor(DigitalPort* port) {
extern "C" {
HalDigitalHandle initializePWMPort(HalPortHandle port_handle, int32_t* status) {
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle port_handle,
int32_t* status) {
initializeDigital(status);
if (*status != 0) return HAL_INVALID_HANDLE;
if (*status != 0) return HAL_kInvalidHandle;
int16_t pin = getPortHandlePin(port_handle);
if (pin == InvalidHandleIndex) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
uint8_t origPin = static_cast<uint8_t>(pin);
@@ -60,15 +61,15 @@ HalDigitalHandle initializePWMPort(HalPortHandle port_handle, int32_t* status) {
pin = remapMXPPWMChannel(pin) + 10; // remap MXP to proper channel
}
auto handle = digitalPinHandles.Allocate(pin, HalHandleEnum::PWM, status);
auto handle = digitalPinHandles.Allocate(pin, HAL_HandleEnum::PWM, status);
if (*status != 0)
return HAL_INVALID_HANDLE; // failed to allocate. Pass error back.
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
auto port = digitalPinHandles.Get(handle, HalHandleEnum::PWM);
auto port = digitalPinHandles.Get(handle, HAL_HandleEnum::PWM);
if (port == nullptr) { // would only occur on thread issue.
*status = HAL_HANDLE_ERROR;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
port->pin = origPin;
@@ -80,8 +81,8 @@ HalDigitalHandle initializePWMPort(HalPortHandle port_handle, int32_t* status) {
return handle;
}
void freePWMPort(HalDigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
void HAL_FreePWMPort(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -95,15 +96,15 @@ void freePWMPort(HalDigitalHandle pwm_port_handle, int32_t* status) {
status);
}
digitalPinHandles.Free(pwm_port_handle, HalHandleEnum::PWM);
digitalPinHandles.Free(pwm_port_handle, HAL_HandleEnum::PWM);
}
bool checkPWMChannel(uint8_t pin) { return pin < kNumPWMPins; }
bool HAL_CheckPWMChannel(uint8_t pin) { return pin < kNumPWMPins; }
void setPWMConfig(HalDigitalHandle pwm_port_handle, double max,
double deadbandMax, double center, double deadbandMin,
double min, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
void HAL_SetPWMConfig(HAL_DigitalHandle pwm_port_handle, double max,
double deadbandMax, double center, double deadbandMin,
double min, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -111,7 +112,7 @@ void setPWMConfig(HalDigitalHandle pwm_port_handle, double max,
// calculate the loop time in milliseconds
double loopTime =
getLoopTiming(status) / (kSystemClockTicksPerMicrosecond * 1e3);
HAL_GetLoopTiming(status) / (kSystemClockTicksPerMicrosecond * 1e3);
if (*status != 0) return;
int32_t maxPwm = (int32_t)((max - kDefaultPwmCenter) / loopTime +
@@ -133,10 +134,11 @@ void setPWMConfig(HalDigitalHandle pwm_port_handle, double max,
port->configSet = true;
}
void setPWMConfigRaw(HalDigitalHandle pwm_port_handle, int32_t maxPwm,
int32_t deadbandMaxPwm, int32_t centerPwm,
int32_t deadbandMinPwm, int32_t minPwm, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
void HAL_SetPWMConfigRaw(HAL_DigitalHandle pwm_port_handle, int32_t maxPwm,
int32_t deadbandMaxPwm, int32_t centerPwm,
int32_t deadbandMinPwm, int32_t minPwm,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -149,11 +151,11 @@ void setPWMConfigRaw(HalDigitalHandle pwm_port_handle, int32_t maxPwm,
port->minPwm = minPwm;
}
void getPWMConfigRaw(HalDigitalHandle pwm_port_handle, int32_t* maxPwm,
int32_t* deadbandMaxPwm, int32_t* centerPwm,
int32_t* deadbandMinPwm, int32_t* minPwm,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
void HAL_GetPWMConfigRaw(HAL_DigitalHandle pwm_port_handle, int32_t* maxPwm,
int32_t* deadbandMaxPwm, int32_t* centerPwm,
int32_t* deadbandMinPwm, int32_t* minPwm,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -165,9 +167,9 @@ void getPWMConfigRaw(HalDigitalHandle pwm_port_handle, int32_t* maxPwm,
*minPwm = port->minPwm;
}
void setPWMEliminateDeadband(HalDigitalHandle pwm_port_handle,
uint8_t eliminateDeadband, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
uint8_t eliminateDeadband, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -175,9 +177,9 @@ void setPWMEliminateDeadband(HalDigitalHandle pwm_port_handle,
port->eliminateDeadband = eliminateDeadband;
}
uint8_t getPWMEliminateDeadband(HalDigitalHandle pwm_port_handle,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
uint8_t HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -193,9 +195,9 @@ uint8_t getPWMEliminateDeadband(HalDigitalHandle pwm_port_handle,
* @param channel The PWM channel to set.
* @param value The PWM value to set.
*/
void setPWMRaw(HalDigitalHandle pwm_port_handle, uint16_t value,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
void HAL_SetPWMRaw(HAL_DigitalHandle pwm_port_handle, uint16_t value,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -217,9 +219,9 @@ void setPWMRaw(HalDigitalHandle pwm_port_handle, uint16_t value,
* @param channel The PWM channel to set.
* @param value The scaled PWM value to set.
*/
void setPWMSpeed(HalDigitalHandle pwm_port_handle, float speed,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
void HAL_SetPWMSpeed(HAL_DigitalHandle pwm_port_handle, float speed,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -256,7 +258,7 @@ void setPWMSpeed(HalDigitalHandle pwm_port_handle, float speed,
return;
}
setPWMRaw(pwm_port_handle, rawValue, status);
HAL_SetPWMRaw(pwm_port_handle, rawValue, status);
}
/**
@@ -268,9 +270,9 @@ void setPWMSpeed(HalDigitalHandle pwm_port_handle, float speed,
* @param channel The PWM channel to set.
* @param value The scaled PWM value to set.
*/
void setPWMPosition(HalDigitalHandle pwm_port_handle, float pos,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
void HAL_SetPWMPosition(HAL_DigitalHandle pwm_port_handle, float pos,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -297,11 +299,11 @@ void setPWMPosition(HalDigitalHandle pwm_port_handle, float pos,
return;
}
setPWMRaw(pwm_port_handle, rawValue, status);
HAL_SetPWMRaw(pwm_port_handle, rawValue, status);
}
void setPWMDisabled(HalDigitalHandle pwm_port_handle, int32_t* status) {
setPWMRaw(pwm_port_handle, kPwmDisabled, status);
void HAL_SetPWMDisabled(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
HAL_SetPWMRaw(pwm_port_handle, kPwmDisabled, status);
}
/**
@@ -310,8 +312,8 @@ void setPWMDisabled(HalDigitalHandle pwm_port_handle, int32_t* status) {
* @param channel The PWM channel to read from.
* @return The raw PWM value.
*/
uint16_t getPWMRaw(HalDigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
uint16_t HAL_GetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -330,8 +332,8 @@ uint16_t getPWMRaw(HalDigitalHandle pwm_port_handle, int32_t* status) {
* @param channel The PWM channel to read from.
* @return The scaled PWM value.
*/
float getPWMSpeed(HalDigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
float HAL_GetPWMSpeed(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -341,7 +343,7 @@ float getPWMSpeed(HalDigitalHandle pwm_port_handle, int32_t* status) {
return 0;
}
int32_t value = getPWMRaw(pwm_port_handle, status);
int32_t value = HAL_GetPWMRaw(pwm_port_handle, status);
if (*status != 0) return 0;
DigitalPort* dPort = port.get();
@@ -368,8 +370,8 @@ float getPWMSpeed(HalDigitalHandle pwm_port_handle, int32_t* status) {
* @param channel The PWM channel to read from.
* @return The scaled PWM value.
*/
float getPWMPosition(HalDigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
float HAL_GetPWMPosition(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -379,7 +381,7 @@ float getPWMPosition(HalDigitalHandle pwm_port_handle, int32_t* status) {
return 0;
}
int32_t value = getPWMRaw(pwm_port_handle, status);
int32_t value = HAL_GetPWMRaw(pwm_port_handle, status);
if (*status != 0) return 0;
DigitalPort* dPort = port.get();
@@ -393,8 +395,8 @@ float getPWMPosition(HalDigitalHandle pwm_port_handle, int32_t* status) {
}
}
void latchPWMZero(HalDigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
void HAL_LatchPWMZero(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -410,9 +412,9 @@ void latchPWMZero(HalDigitalHandle pwm_port_handle, int32_t* status) {
* @param channel The PWM channel to configure.
* @param squelchMask The 2-bit mask of outputs to squelch.
*/
void setPWMPeriodScale(HalDigitalHandle pwm_port_handle, uint32_t squelchMask,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwm_port_handle,
uint32_t squelchMask, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -431,7 +433,7 @@ void setPWMPeriodScale(HalDigitalHandle pwm_port_handle, uint32_t squelchMask,
*
* @return The loop time
*/
uint16_t getLoopTiming(int32_t* status) {
uint16_t HAL_GetLoopTiming(int32_t* status) {
return pwmSystem->readLoopTiming(status);
}
}

View File

@@ -12,23 +12,23 @@
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_getNumPDPChannels(void) { return kNumPDPChannels; }
int32_t HAL_getNumCanTalons(void) { return kNumCanTalons; }
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_GetNumPDPChannels(void) { return kNumPDPChannels; }
int32_t HAL_GetNumCanTalons(void) { return kNumCanTalons; }
}

View File

@@ -22,7 +22,7 @@ extern "C" {
/**
* Get the roboRIO input voltage
*/
float getVinVoltage(int32_t* status) {
float HAL_GetVinVoltage(int32_t* status) {
initializePower(status);
return power->readVinVoltage(status) / 4.096f * 0.025733f - 0.029f;
}
@@ -30,7 +30,7 @@ float getVinVoltage(int32_t* status) {
/**
* Get the roboRIO input current
*/
float getVinCurrent(int32_t* status) {
float HAL_GetVinCurrent(int32_t* status) {
initializePower(status);
return power->readVinCurrent(status) / 4.096f * 0.017042 - 0.071f;
}
@@ -38,7 +38,7 @@ float getVinCurrent(int32_t* status) {
/**
* Get the 6V rail voltage
*/
float getUserVoltage6V(int32_t* status) {
float HAL_GetUserVoltage6V(int32_t* status) {
initializePower(status);
return power->readUserVoltage6V(status) / 4.096f * 0.007019f - 0.014f;
}
@@ -46,7 +46,7 @@ float getUserVoltage6V(int32_t* status) {
/**
* Get the 6V rail current
*/
float getUserCurrent6V(int32_t* status) {
float HAL_GetUserCurrent6V(int32_t* status) {
initializePower(status);
return power->readUserCurrent6V(status) / 4.096f * 0.005566f - 0.009f;
}
@@ -54,7 +54,7 @@ float getUserCurrent6V(int32_t* status) {
/**
* Get the active state of the 6V rail
*/
bool getUserActive6V(int32_t* status) {
bool HAL_GetUserActive6V(int32_t* status) {
initializePower(status);
return power->readStatus_User6V(status) == 4;
}
@@ -62,7 +62,7 @@ bool getUserActive6V(int32_t* status) {
/**
* Get the fault count for the 6V rail
*/
int getUserCurrentFaults6V(int32_t* status) {
int HAL_GetUserCurrentFaults6V(int32_t* status) {
initializePower(status);
return (int)power->readFaultCounts_OverCurrentFaultCount6V(status);
}
@@ -70,7 +70,7 @@ int getUserCurrentFaults6V(int32_t* status) {
/**
* Get the 5V rail voltage
*/
float getUserVoltage5V(int32_t* status) {
float HAL_GetUserVoltage5V(int32_t* status) {
initializePower(status);
return power->readUserVoltage5V(status) / 4.096f * 0.005962f - 0.013f;
}
@@ -78,7 +78,7 @@ float getUserVoltage5V(int32_t* status) {
/**
* Get the 5V rail current
*/
float getUserCurrent5V(int32_t* status) {
float HAL_GetUserCurrent5V(int32_t* status) {
initializePower(status);
return power->readUserCurrent5V(status) / 4.096f * 0.001996f - 0.002f;
}
@@ -86,7 +86,7 @@ float getUserCurrent5V(int32_t* status) {
/**
* Get the active state of the 5V rail
*/
bool getUserActive5V(int32_t* status) {
bool HAL_GetUserActive5V(int32_t* status) {
initializePower(status);
return power->readStatus_User5V(status) == 4;
}
@@ -94,12 +94,12 @@ bool getUserActive5V(int32_t* status) {
/**
* Get the fault count for the 5V rail
*/
int getUserCurrentFaults5V(int32_t* status) {
int HAL_GetUserCurrentFaults5V(int32_t* status) {
initializePower(status);
return (int)power->readFaultCounts_OverCurrentFaultCount5V(status);
}
unsigned char getUserStatus5V(int32_t* status) {
unsigned char HAL_GetUserStatus5V(int32_t* status) {
initializePower(status);
return power->readStatus_User5V(status);
}
@@ -107,7 +107,7 @@ unsigned char getUserStatus5V(int32_t* status) {
/**
* Get the 3.3V rail voltage
*/
float getUserVoltage3V3(int32_t* status) {
float HAL_GetUserVoltage3V3(int32_t* status) {
initializePower(status);
return power->readUserVoltage3V3(status) / 4.096f * 0.004902f - 0.01f;
}
@@ -115,7 +115,7 @@ float getUserVoltage3V3(int32_t* status) {
/**
* Get the 3.3V rail current
*/
float getUserCurrent3V3(int32_t* status) {
float HAL_GetUserCurrent3V3(int32_t* status) {
initializePower(status);
return power->readUserCurrent3V3(status) / 4.096f * 0.002486f - 0.003f;
}
@@ -123,7 +123,7 @@ float getUserCurrent3V3(int32_t* status) {
/**
* Get the active state of the 3.3V rail
*/
bool getUserActive3V3(int32_t* status) {
bool HAL_GetUserActive3V3(int32_t* status) {
initializePower(status);
return power->readStatus_User3V3(status) == 4;
}
@@ -131,7 +131,7 @@ bool getUserActive3V3(int32_t* status) {
/**
* Get the fault count for the 3.3V rail
*/
int getUserCurrentFaults3V3(int32_t* status) {
int HAL_GetUserCurrentFaults3V3(int32_t* status) {
initializePower(status);
return (int)power->readFaultCounts_OverCurrentFaultCount3V3(status);
}

View File

@@ -20,24 +20,24 @@ struct Relay {
};
}
static IndexedHandleResource<HalRelayHandle, Relay, kNumRelayPins,
HalHandleEnum::Relay>
static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayPins,
HAL_HandleEnum::Relay>
relayHandles;
// Create a mutex to protect changes to the relay values
static priority_recursive_mutex digitalRelayMutex;
extern "C" {
HalRelayHandle initializeRelayPort(HalPortHandle port_handle, uint8_t fwd,
int32_t* status) {
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle port_handle, uint8_t fwd,
int32_t* status) {
initializeDigital(status);
if (*status != 0) return HAL_INVALID_HANDLE;
if (*status != 0) return HAL_kInvalidHandle;
int16_t pin = getPortHandlePin(port_handle);
if (pin == InvalidHandleIndex) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
if (!fwd) pin += kNumRelayHeaders; // add 4 to reverse pins
@@ -45,12 +45,12 @@ HalRelayHandle initializeRelayPort(HalPortHandle port_handle, uint8_t fwd,
auto handle = relayHandles.Allocate(pin, status);
if (*status != 0)
return HAL_INVALID_HANDLE; // failed to allocate. Pass error back.
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
auto port = relayHandles.Get(handle);
if (port == nullptr) { // would only occur on thread issue.
*status = HAL_HANDLE_ERROR;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
if (!fwd) {
@@ -64,12 +64,12 @@ HalRelayHandle initializeRelayPort(HalPortHandle port_handle, uint8_t fwd,
return handle;
}
void freeRelayPort(HalRelayHandle relay_port_handle) {
void HAL_FreeRelayPort(HAL_RelayHandle relay_port_handle) {
// no status, so no need to check for a proper free.
relayHandles.Free(relay_port_handle);
}
bool checkRelayChannel(uint8_t pin) {
bool HAL_CheckRelayChannel(uint8_t pin) {
// roboRIO only has 4 headers, and the FPGA has
// seperate functions for forward and reverse,
// instead of seperate pin IDs
@@ -80,7 +80,7 @@ bool checkRelayChannel(uint8_t pin) {
* Set the state of a relay.
* Set the state of a relay output.
*/
void setRelay(HalRelayHandle relay_port_handle, bool on, int32_t* status) {
void HAL_SetRelay(HAL_RelayHandle relay_port_handle, bool on, int32_t* status) {
auto port = relayHandles.Get(relay_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -112,7 +112,7 @@ void setRelay(HalRelayHandle relay_port_handle, bool on, int32_t* status) {
/**
* Get the current state of the relay channel
*/
bool getRelay(HalRelayHandle relay_port_handle, int32_t* status) {
bool HAL_GetRelay(HAL_RelayHandle relay_port_handle, int32_t* status) {
auto port = relayHandles.Get(relay_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;

View File

@@ -28,15 +28,15 @@ static priority_recursive_mutex spiOnboardSemaphore;
static priority_recursive_mutex spiMXPSemaphore;
static tSPI* spiSystem;
static HalDigitalHandle spiMXPDigitalHandle1 = HAL_INVALID_HANDLE;
static HalDigitalHandle spiMXPDigitalHandle2 = HAL_INVALID_HANDLE;
static HalDigitalHandle spiMXPDigitalHandle3 = HAL_INVALID_HANDLE;
static HalDigitalHandle spiMXPDigitalHandle4 = HAL_INVALID_HANDLE;
static HAL_DigitalHandle spiMXPDigitalHandle1 = HAL_kInvalidHandle;
static HAL_DigitalHandle spiMXPDigitalHandle2 = HAL_kInvalidHandle;
static HAL_DigitalHandle spiMXPDigitalHandle3 = HAL_kInvalidHandle;
static HAL_DigitalHandle spiMXPDigitalHandle4 = HAL_kInvalidHandle;
extern "C" {
struct SPIAccumulator {
std::atomic<HalNotifierHandle> notifier{0};
std::atomic<HAL_NotifierHandle> notifier{0};
uint64_t triggerTime;
uint32_t period;
@@ -66,54 +66,56 @@ SPIAccumulator* spiAccumulators[5] = {nullptr, nullptr, nullptr, nullptr,
* If opening the MXP port, also sets up the pin functions appropriately
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
*/
void spiInitialize(uint8_t port, int32_t* status) {
void HAL_SpiInitialize(uint8_t port, int32_t* status) {
if (spiSystem == nullptr) spiSystem = tSPI::create(status);
if (spiGetHandle(port) != 0) return;
if (HAL_SpiGetHandle(port) != 0) return;
switch (port) {
case 0:
spiSetHandle(0, spilib_open("/dev/spidev0.0"));
HAL_SpiSetHandle(0, spilib_open("/dev/spidev0.0"));
break;
case 1:
spiSetHandle(1, spilib_open("/dev/spidev0.1"));
HAL_SpiSetHandle(1, spilib_open("/dev/spidev0.1"));
break;
case 2:
spiSetHandle(2, spilib_open("/dev/spidev0.2"));
HAL_SpiSetHandle(2, spilib_open("/dev/spidev0.2"));
break;
case 3:
spiSetHandle(3, spilib_open("/dev/spidev0.3"));
HAL_SpiSetHandle(3, spilib_open("/dev/spidev0.3"));
break;
case 4:
initializeDigital(status);
if (*status != 0) return;
if ((spiMXPDigitalHandle1 = initializeDIOPort(
getPort(14), false, status)) == HAL_INVALID_HANDLE) {
if ((spiMXPDigitalHandle1 = HAL_InitializeDIOPort(
HAL_GetPort(14), false, status)) == HAL_kInvalidHandle) {
printf("Failed to allocate DIO 14\n");
return;
}
if ((spiMXPDigitalHandle2 = initializeDIOPort(
getPort(15), false, status)) == HAL_INVALID_HANDLE) {
if ((spiMXPDigitalHandle2 = HAL_InitializeDIOPort(
HAL_GetPort(15), false, status)) == HAL_kInvalidHandle) {
printf("Failed to allocate DIO 15\n");
freeDIOPort(spiMXPDigitalHandle1); // free the first port allocated
HAL_FreeDIOPort(spiMXPDigitalHandle1); // free the first port allocated
return;
}
if ((spiMXPDigitalHandle3 = initializeDIOPort(
getPort(16), false, status)) == HAL_INVALID_HANDLE) {
if ((spiMXPDigitalHandle3 = HAL_InitializeDIOPort(
HAL_GetPort(16), false, status)) == HAL_kInvalidHandle) {
printf("Failed to allocate DIO 16\n");
freeDIOPort(spiMXPDigitalHandle1); // free the first port allocated
freeDIOPort(spiMXPDigitalHandle2); // free the second port allocated
HAL_FreeDIOPort(spiMXPDigitalHandle1); // free the first port allocated
HAL_FreeDIOPort(
spiMXPDigitalHandle2); // free the second port allocated
return;
}
if ((spiMXPDigitalHandle4 = initializeDIOPort(
getPort(17), false, status)) == HAL_INVALID_HANDLE) {
if ((spiMXPDigitalHandle4 = HAL_InitializeDIOPort(
HAL_GetPort(17), false, status)) == HAL_kInvalidHandle) {
printf("Failed to allocate DIO 17\n");
freeDIOPort(spiMXPDigitalHandle1); // free the first port allocated
freeDIOPort(spiMXPDigitalHandle2); // free the second port allocated
freeDIOPort(spiMXPDigitalHandle3); // free the third port allocated
HAL_FreeDIOPort(spiMXPDigitalHandle1); // free the first port allocated
HAL_FreeDIOPort(
spiMXPDigitalHandle2); // free the second port allocated
HAL_FreeDIOPort(spiMXPDigitalHandle3); // free the third port allocated
return;
}
digitalSystem->writeEnableMXPSpecialFunction(
digitalSystem->readEnableMXPSpecialFunction(status) | 0x00F0, status);
spiSetHandle(4, spilib_open("/dev/spidev1.0"));
HAL_SpiSetHandle(4, spilib_open("/dev/spidev1.0"));
break;
default:
break;
@@ -133,10 +135,10 @@ void spiInitialize(uint8_t port, int32_t* status) {
* @param size Number of bytes to transfer. [0..7]
* @return Number of bytes transferred, -1 for error
*/
int32_t spiTransaction(uint8_t port, uint8_t* dataToSend, uint8_t* dataReceived,
uint8_t size) {
int32_t HAL_SpiTransaction(uint8_t port, uint8_t* dataToSend,
uint8_t* dataReceived, uint8_t size) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
return spilib_writeread(spiGetHandle(port), (const char*)dataToSend,
return spilib_writeread(HAL_SpiGetHandle(port), (const char*)dataToSend,
(char*)dataReceived, (int32_t)size);
}
@@ -150,9 +152,9 @@ int32_t spiTransaction(uint8_t port, uint8_t* dataToSend, uint8_t* dataReceived,
* @param sendSize The number of bytes to be written
* @return The number of bytes written. -1 for an error
*/
int32_t spiWrite(uint8_t port, uint8_t* dataToSend, uint8_t sendSize) {
int32_t HAL_SpiWrite(uint8_t port, uint8_t* dataToSend, uint8_t sendSize) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
return spilib_write(spiGetHandle(port), (const char*)dataToSend,
return spilib_write(HAL_SpiGetHandle(port), (const char*)dataToSend,
(int32_t)sendSize);
}
@@ -169,9 +171,9 @@ int32_t spiWrite(uint8_t port, uint8_t* dataToSend, uint8_t sendSize) {
* @param count The number of bytes to read in the transaction. [1..7]
* @return Number of bytes read. -1 for error.
*/
int32_t spiRead(uint8_t port, uint8_t* buffer, uint8_t count) {
int32_t HAL_SpiRead(uint8_t port, uint8_t* buffer, uint8_t count) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
return spilib_read(spiGetHandle(port), (char*)buffer, (int32_t)count);
return spilib_read(HAL_SpiGetHandle(port), (char*)buffer, (int32_t)count);
}
/**
@@ -179,19 +181,19 @@ int32_t spiRead(uint8_t port, uint8_t* buffer, uint8_t count) {
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
*/
void spiClose(uint8_t port) {
void HAL_SpiClose(uint8_t port) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
if (spiAccumulators[port]) {
int32_t status = 0;
spiFreeAccumulator(port, &status);
HAL_SpiFreeAccumulator(port, &status);
}
spilib_close(spiGetHandle(port));
spiSetHandle(port, 0);
spilib_close(HAL_SpiGetHandle(port));
HAL_SpiSetHandle(port, 0);
if (port == 4) {
freeDIOPort(spiMXPDigitalHandle1);
freeDIOPort(spiMXPDigitalHandle2);
freeDIOPort(spiMXPDigitalHandle3);
freeDIOPort(spiMXPDigitalHandle4);
HAL_FreeDIOPort(spiMXPDigitalHandle1);
HAL_FreeDIOPort(spiMXPDigitalHandle2);
HAL_FreeDIOPort(spiMXPDigitalHandle3);
HAL_FreeDIOPort(spiMXPDigitalHandle4);
}
return;
}
@@ -202,9 +204,9 @@ void spiClose(uint8_t port) {
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
* @param speed The speed in Hz (0-1MHz)
*/
void spiSetSpeed(uint8_t port, uint32_t speed) {
void HAL_SpiSetSpeed(uint8_t port, uint32_t speed) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
spilib_setspeed(spiGetHandle(port), speed);
spilib_setspeed(HAL_SpiGetHandle(port), speed);
}
/**
@@ -217,10 +219,10 @@ void spiSetSpeed(uint8_t port, uint32_t speed) {
* @param clk_idle_high True to set the clock to active low, False to set the
* clock active high
*/
void spiSetOpts(uint8_t port, int msb_first, int sample_on_trailing,
int clk_idle_high) {
void HAL_SpiSetOpts(uint8_t port, int msb_first, int sample_on_trailing,
int clk_idle_high) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
spilib_setopts(spiGetHandle(port), msb_first, sample_on_trailing,
spilib_setopts(HAL_SpiGetHandle(port), msb_first, sample_on_trailing,
clk_idle_high);
}
@@ -229,7 +231,7 @@ void spiSetOpts(uint8_t port, int msb_first, int sample_on_trailing,
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
*/
void spiSetChipSelectActiveHigh(uint8_t port, int32_t* status) {
void HAL_SpiSetChipSelectActiveHigh(uint8_t port, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
if (port < 4) {
spiSystem->writeChipSelectActiveHigh_Hdr(
@@ -244,7 +246,7 @@ void spiSetChipSelectActiveHigh(uint8_t port, int32_t* status) {
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
*/
void spiSetChipSelectActiveLow(uint8_t port, int32_t* status) {
void HAL_SpiSetChipSelectActiveLow(uint8_t port, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
if (port < 4) {
spiSystem->writeChipSelectActiveHigh_Hdr(
@@ -260,7 +262,7 @@ void spiSetChipSelectActiveLow(uint8_t port, int32_t* status) {
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
* @return The stored handle for the SPI port. 0 represents no stored handle.
*/
int32_t spiGetHandle(uint8_t port) {
int32_t HAL_SpiGetHandle(uint8_t port) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
switch (port) {
case 0:
@@ -285,7 +287,7 @@ int32_t spiGetHandle(uint8_t port) {
* MXP.
* @param handle The value of the handle for the port.
*/
void spiSetHandle(uint8_t port, int32_t handle) {
void HAL_SpiSetHandle(uint8_t port, int32_t handle) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
switch (port) {
case 0:
@@ -327,7 +329,7 @@ static void spiAccumulatorProcess(uint64_t currentTime, void* param) {
// perform SPI transaction
uint8_t resp_b[4];
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(accum->port));
spilib_writeread(spiGetHandle(accum->port), (const char*)accum->cmd,
spilib_writeread(HAL_SpiGetHandle(accum->port), (const char*)accum->cmd,
(char*)resp_b, (int32_t)accum->xfer_size);
// convert from bytes
@@ -369,7 +371,7 @@ static void spiAccumulatorProcess(uint64_t currentTime, void* param) {
if (accum->triggerTime < currentTime)
accum->triggerTime = currentTime + accum->period;
int32_t status = 0;
updateNotifierAlarm(accum->notifier, accum->triggerTime, &status);
HAL_UpdateNotifierAlarm(accum->notifier, accum->triggerTime, &status);
}
/**
@@ -388,11 +390,11 @@ static void spiAccumulatorProcess(uint64_t currentTime, void* param) {
* @param is_signed Is data field signed?
* @param big_endian Is device big endian?
*/
void spiInitAccumulator(uint8_t port, uint32_t period, uint32_t cmd,
uint8_t xfer_size, uint32_t valid_mask,
uint32_t valid_value, uint8_t data_shift,
uint8_t data_size, bool is_signed, bool big_endian,
int32_t* status) {
void HAL_SpiInitAccumulator(uint8_t port, uint32_t period, uint32_t cmd,
uint8_t xfer_size, uint32_t valid_mask,
uint32_t valid_value, uint8_t data_shift,
uint8_t data_size, bool is_signed, bool big_endian,
int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
if (port > 4) return;
if (!spiAccumulators[port]) spiAccumulators[port] = new SPIAccumulator();
@@ -421,25 +423,26 @@ void spiInitAccumulator(uint8_t port, uint32_t period, uint32_t cmd,
accum->is_signed = is_signed;
accum->big_endian = big_endian;
if (!accum->notifier) {
accum->notifier = initializeNotifier(spiAccumulatorProcess, accum, status);
accum->triggerTime = getFPGATime(status) + period;
accum->notifier =
HAL_InitializeNotifier(spiAccumulatorProcess, accum, status);
accum->triggerTime = HAL_GetFPGATime(status) + period;
if (*status != 0) return;
updateNotifierAlarm(accum->notifier, accum->triggerTime, status);
HAL_UpdateNotifierAlarm(accum->notifier, accum->triggerTime, status);
}
}
/**
* Frees a SPI accumulator.
*/
void spiFreeAccumulator(uint8_t port, int32_t* status) {
void HAL_SpiFreeAccumulator(uint8_t port, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
SPIAccumulator* accum = spiAccumulators[port];
if (!accum) {
*status = NULL_PARAMETER;
return;
}
HalNotifierHandle handle = accum->notifier.exchange(0);
cleanNotifier(handle, status);
HAL_NotifierHandle handle = accum->notifier.exchange(0);
HAL_CleanNotifier(handle, status);
delete accum;
spiAccumulators[port] = nullptr;
}
@@ -447,7 +450,7 @@ void spiFreeAccumulator(uint8_t port, int32_t* status) {
/**
* Resets the accumulator to zero.
*/
void spiResetAccumulator(uint8_t port, int32_t* status) {
void HAL_SpiResetAccumulator(uint8_t port, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
SPIAccumulator* accum = spiAccumulators[port];
if (!accum) {
@@ -468,7 +471,8 @@ void spiResetAccumulator(uint8_t port, int32_t* status) {
* integration work
* and to take the device offset into account when integrating.
*/
void spiSetAccumulatorCenter(uint8_t port, int32_t center, int32_t* status) {
void HAL_SpiSetAccumulatorCenter(uint8_t port, int32_t center,
int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
SPIAccumulator* accum = spiAccumulators[port];
if (!accum) {
@@ -481,8 +485,8 @@ void spiSetAccumulatorCenter(uint8_t port, int32_t center, int32_t* status) {
/**
* Set the accumulator's deadband.
*/
void spiSetAccumulatorDeadband(uint8_t port, int32_t deadband,
int32_t* status) {
void HAL_SpiSetAccumulatorDeadband(uint8_t port, int32_t deadband,
int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
SPIAccumulator* accum = spiAccumulators[port];
if (!accum) {
@@ -495,7 +499,7 @@ void spiSetAccumulatorDeadband(uint8_t port, int32_t deadband,
/**
* Read the last value read by the accumulator engine.
*/
int32_t spiGetAccumulatorLastValue(uint8_t port, int32_t* status) {
int32_t HAL_SpiGetAccumulatorLastValue(uint8_t port, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
SPIAccumulator* accum = spiAccumulators[port];
if (!accum) {
@@ -510,7 +514,7 @@ int32_t spiGetAccumulatorLastValue(uint8_t port, int32_t* status) {
*
* @return The 64-bit value accumulated since the last Reset().
*/
int64_t spiGetAccumulatorValue(uint8_t port, int32_t* status) {
int64_t HAL_SpiGetAccumulatorValue(uint8_t port, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
SPIAccumulator* accum = spiAccumulators[port];
if (!accum) {
@@ -528,7 +532,7 @@ int64_t spiGetAccumulatorValue(uint8_t port, int32_t* status) {
*
* @return The number of times samples from the channel were accumulated.
*/
uint32_t spiGetAccumulatorCount(uint8_t port, int32_t* status) {
uint32_t HAL_SpiGetAccumulatorCount(uint8_t port, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
SPIAccumulator* accum = spiAccumulators[port];
if (!accum) {
@@ -543,10 +547,10 @@ uint32_t spiGetAccumulatorCount(uint8_t port, int32_t* status) {
*
* @return The accumulated average value (value / count).
*/
double spiGetAccumulatorAverage(uint8_t port, int32_t* status) {
double HAL_SpiGetAccumulatorAverage(uint8_t port, int32_t* status) {
int64_t value;
uint32_t count;
spiGetAccumulatorOutput(port, &value, &count, status);
HAL_SpiGetAccumulatorOutput(port, &value, &count, status);
if (count == 0) return 0.0;
return ((double)value) / count;
}
@@ -560,8 +564,8 @@ double spiGetAccumulatorAverage(uint8_t port, int32_t* status) {
* @param value Pointer to the 64-bit accumulated output.
* @param count Pointer to the number of accumulation cycles.
*/
void spiGetAccumulatorOutput(uint8_t port, int64_t* value, uint32_t* count,
int32_t* status) {
void HAL_SpiGetAccumulatorOutput(uint8_t port, int64_t* value, uint32_t* count,
int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
SPIAccumulator* accum = spiAccumulators[port];
if (!accum) {

View File

@@ -20,36 +20,38 @@ TLogLevel semaphoreLogLevel = logDEBUG;
extern "C" {
MUTEX_ID initializeMutexNormal() { return new priority_mutex; }
MUTEX_ID HAL_InitializeMutexNormal() { return new priority_mutex; }
void deleteMutex(MUTEX_ID sem) { delete sem; }
void HAL_DeleteMutex(MUTEX_ID sem) { delete sem; }
/**
* Lock the mutex, blocking until it's available.
*/
void takeMutex(MUTEX_ID mutex) { mutex->lock(); }
void HAL_TakeMutex(MUTEX_ID mutex) { mutex->lock(); }
/**
* Attempt to lock the mutex.
* @return true if succeeded in locking the mutex, false otherwise.
*/
bool tryTakeMutex(MUTEX_ID mutex) { return mutex->try_lock(); }
bool HAL_TryTakeMutex(MUTEX_ID mutex) { return mutex->try_lock(); }
/**
* Unlock the mutex.
* @return 0 for success, -1 for error. If -1, the error will be in errno.
*/
void giveMutex(MUTEX_ID mutex) { mutex->unlock(); }
void HAL_GiveMutex(MUTEX_ID mutex) { mutex->unlock(); }
MULTIWAIT_ID initializeMultiWait() { return new priority_condition_variable; }
MULTIWAIT_ID HAL_InitializeMultiWait() {
return new priority_condition_variable;
}
void deleteMultiWait(MULTIWAIT_ID cond) { delete cond; }
void HAL_DeleteMultiWait(MULTIWAIT_ID cond) { delete cond; }
void takeMultiWait(MULTIWAIT_ID cond, MUTEX_ID m) {
void HAL_TakeMultiWait(MULTIWAIT_ID cond, MUTEX_ID m) {
std::unique_lock<priority_mutex> lock(*m);
cond->wait(lock);
}
void giveMultiWait(MULTIWAIT_ID cond) { cond->notify_all(); }
void HAL_GiveMultiWait(MULTIWAIT_ID cond) { cond->notify_all(); }
} // extern "C"

View File

@@ -14,7 +14,7 @@ static uint32_t m_portHandle[2];
extern "C" {
void serialInitializePort(uint8_t port, int32_t* status) {
void HAL_SerialInitializePort(uint8_t port, int32_t* status) {
char const* portName;
if (m_resourceManagerHandle == 0)
@@ -32,44 +32,45 @@ void serialInitializePort(uint8_t port, int32_t* status) {
if (*status > 0) *status = 0;
}
void serialSetBaudRate(uint8_t port, uint32_t baud, int32_t* status) {
void HAL_SerialSetBaudRate(uint8_t port, uint32_t baud, int32_t* status) {
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_BAUD, baud);
if (*status > 0) *status = 0;
}
void serialSetDataBits(uint8_t port, uint8_t bits, int32_t* status) {
void HAL_SerialSetDataBits(uint8_t port, uint8_t bits, int32_t* status) {
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_DATA_BITS, bits);
if (*status > 0) *status = 0;
}
void serialSetParity(uint8_t port, uint8_t parity, int32_t* status) {
void HAL_SerialSetParity(uint8_t port, uint8_t parity, int32_t* status) {
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_PARITY, parity);
if (*status > 0) *status = 0;
}
void serialSetStopBits(uint8_t port, uint8_t stopBits, int32_t* status) {
void HAL_SerialSetStopBits(uint8_t port, uint8_t stopBits, int32_t* status) {
*status =
viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_STOP_BITS, stopBits);
if (*status > 0) *status = 0;
}
void serialSetWriteMode(uint8_t port, uint8_t mode, int32_t* status) {
void HAL_SerialSetWriteMode(uint8_t port, uint8_t mode, int32_t* status) {
*status = viSetAttribute(m_portHandle[port], VI_ATTR_WR_BUF_OPER_MODE, mode);
if (*status > 0) *status = 0;
}
void serialSetFlowControl(uint8_t port, uint8_t flow, int32_t* status) {
void HAL_SerialSetFlowControl(uint8_t port, uint8_t flow, int32_t* status) {
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_FLOW_CNTRL, flow);
if (*status > 0) *status = 0;
}
void serialSetTimeout(uint8_t port, float timeout, int32_t* status) {
void HAL_SerialSetTimeout(uint8_t port, float timeout, int32_t* status) {
*status = viSetAttribute(m_portHandle[port], VI_ATTR_TMO_VALUE,
(uint32_t)(timeout * 1e3));
if (*status > 0) *status = 0;
}
void serialEnableTermination(uint8_t port, char terminator, int32_t* status) {
void HAL_SerialEnableTermination(uint8_t port, char terminator,
int32_t* status) {
viSetAttribute(m_portHandle[port], VI_ATTR_TERMCHAR_EN, VI_TRUE);
viSetAttribute(m_portHandle[port], VI_ATTR_TERMCHAR, terminator);
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_END_IN,
@@ -77,24 +78,25 @@ void serialEnableTermination(uint8_t port, char terminator, int32_t* status) {
if (*status > 0) *status = 0;
}
void serialDisableTermination(uint8_t port, int32_t* status) {
void HAL_SerialDisableTermination(uint8_t port, int32_t* status) {
viSetAttribute(m_portHandle[port], VI_ATTR_TERMCHAR_EN, VI_FALSE);
*status =
viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_END_IN, VI_ASRL_END_NONE);
if (*status > 0) *status = 0;
}
void serialSetReadBufferSize(uint8_t port, uint32_t size, int32_t* status) {
void HAL_SerialSetReadBufferSize(uint8_t port, uint32_t size, int32_t* status) {
*status = viSetBuf(m_portHandle[port], VI_READ_BUF, size);
if (*status > 0) *status = 0;
}
void serialSetWriteBufferSize(uint8_t port, uint32_t size, int32_t* status) {
void HAL_SerialSetWriteBufferSize(uint8_t port, uint32_t size,
int32_t* status) {
*status = viSetBuf(m_portHandle[port], VI_WRITE_BUF, size);
if (*status > 0) *status = 0;
}
int32_t serialGetBytesReceived(uint8_t port, int32_t* status) {
int32_t HAL_SerialGetBytesReceived(uint8_t port, int32_t* status) {
int32_t bytes = 0;
*status = viGetAttribute(m_portHandle[port], VI_ATTR_ASRL_AVAIL_NUM, &bytes);
@@ -102,8 +104,8 @@ int32_t serialGetBytesReceived(uint8_t port, int32_t* status) {
return bytes;
}
uint32_t serialRead(uint8_t port, char* buffer, int32_t count,
int32_t* status) {
uint32_t HAL_SerialRead(uint8_t port, char* buffer, int32_t count,
int32_t* status) {
uint32_t retCount = 0;
*status =
@@ -112,15 +114,15 @@ uint32_t serialRead(uint8_t port, char* buffer, int32_t count,
if (*status == VI_ERROR_IO || *status == VI_ERROR_ASRL_OVERRUN ||
*status == VI_ERROR_ASRL_FRAMING || *status == VI_ERROR_ASRL_PARITY) {
int32_t localStatus = 0;
serialClear(port, &localStatus);
HAL_SerialClear(port, &localStatus);
}
if (*status == VI_ERROR_TMO || *status > 0) *status = 0;
return retCount;
}
uint32_t serialWrite(uint8_t port, const char* buffer, int32_t count,
int32_t* status) {
uint32_t HAL_SerialWrite(uint8_t port, const char* buffer, int32_t count,
int32_t* status) {
uint32_t retCount = 0;
*status =
@@ -130,17 +132,17 @@ uint32_t serialWrite(uint8_t port, const char* buffer, int32_t count,
return retCount;
}
void serialFlush(uint8_t port, int32_t* status) {
void HAL_SerialFlush(uint8_t port, int32_t* status) {
*status = viFlush(m_portHandle[port], VI_WRITE_BUF);
if (*status > 0) *status = 0;
}
void serialClear(uint8_t port, int32_t* status) {
void HAL_SerialClear(uint8_t port, int32_t* status) {
*status = viClear(m_portHandle[port]);
if (*status > 0) *status = 0;
}
void serialClose(uint8_t port, int32_t* status) {
void HAL_SerialClose(uint8_t port, int32_t* status) {
*status = viClose(m_portHandle[port]);
if (*status > 0) *status = 0;
}

View File

@@ -26,39 +26,39 @@ struct Solenoid {
using namespace hal;
static IndexedHandleResource<HalSolenoidHandle, Solenoid,
static IndexedHandleResource<HAL_SolenoidHandle, Solenoid,
kNumPCMModules * kNumSolenoidPins,
HalHandleEnum::Solenoid>
HAL_HandleEnum::Solenoid>
solenoidHandles;
extern "C" {
HalSolenoidHandle initializeSolenoidPort(HalPortHandle port_handle,
int32_t* status) {
HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle port_handle,
int32_t* status) {
int16_t pin = getPortHandlePin(port_handle);
int16_t module = getPortHandleModule(port_handle);
if (pin == InvalidHandleIndex) {
*status = PARAMETER_OUT_OF_RANGE; // Change to Handle Error
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
if (module >= kNumPCMModules || pin >= kNumSolenoidPins) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
initializePCM(module);
auto handle =
solenoidHandles.Allocate(module * kNumSolenoidPins + pin, status);
if (handle == HAL_INVALID_HANDLE) { // out of resources
if (handle == HAL_kInvalidHandle) { // out of resources
*status = NO_AVAILABLE_RESOURCES;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
auto solenoid_port = solenoidHandles.Get(handle);
if (solenoid_port == nullptr) { // would only occur on thread issues
*status = HAL_HANDLE_ERROR;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
solenoid_port->module = static_cast<uint8_t>(module);
solenoid_port->pin = static_cast<uint8_t>(pin);
@@ -66,13 +66,13 @@ HalSolenoidHandle initializeSolenoidPort(HalPortHandle port_handle,
return handle;
}
void freeSolenoidPort(HalSolenoidHandle solenoid_port_handle) {
void HAL_FreeSolenoidPort(HAL_SolenoidHandle solenoid_port_handle) {
solenoidHandles.Free(solenoid_port_handle);
}
bool checkSolenoidModule(uint8_t module) { return module < kNumPCMModules; }
bool HAL_CheckSolenoidModule(uint8_t module) { return module < kNumPCMModules; }
bool getSolenoid(HalSolenoidHandle solenoid_port_handle, int32_t* status) {
bool HAL_GetSolenoid(HAL_SolenoidHandle solenoid_port_handle, int32_t* status) {
auto port = solenoidHandles.Get(solenoid_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -85,7 +85,7 @@ bool getSolenoid(HalSolenoidHandle solenoid_port_handle, int32_t* status) {
return value;
}
uint8_t getAllSolenoids(uint8_t module, int32_t* status) {
uint8_t HAL_GetAllSolenoids(uint8_t module, int32_t* status) {
if (module >= kNumPCMModules) {
*status = PARAMETER_OUT_OF_RANGE;
return 0;
@@ -97,8 +97,8 @@ uint8_t getAllSolenoids(uint8_t module, int32_t* status) {
return value;
}
void setSolenoid(HalSolenoidHandle solenoid_port_handle, bool value,
int32_t* status) {
void HAL_SetSolenoid(HAL_SolenoidHandle solenoid_port_handle, bool value,
int32_t* status) {
auto port = solenoidHandles.Get(solenoid_port_handle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
@@ -108,7 +108,7 @@ void setSolenoid(HalSolenoidHandle solenoid_port_handle, bool value,
*status = PCM_modules[port->module]->SetSolenoid(port->pin, value);
}
int getPCMSolenoidBlackList(uint8_t module, int32_t* status) {
int HAL_GetPCMSolenoidBlackList(uint8_t module, int32_t* status) {
if (module >= kNumPCMModules) {
*status = PARAMETER_OUT_OF_RANGE;
return 0;
@@ -119,7 +119,7 @@ int getPCMSolenoidBlackList(uint8_t module, int32_t* status) {
return value;
}
bool getPCMSolenoidVoltageStickyFault(uint8_t module, int32_t* status) {
bool HAL_GetPCMSolenoidVoltageStickyFault(uint8_t module, int32_t* status) {
if (module >= kNumPCMModules) {
*status = PARAMETER_OUT_OF_RANGE;
return false;
@@ -130,7 +130,7 @@ bool getPCMSolenoidVoltageStickyFault(uint8_t module, int32_t* status) {
return value;
}
bool getPCMSolenoidVoltageFault(uint8_t module, int32_t* status) {
bool HAL_GetPCMSolenoidVoltageFault(uint8_t module, int32_t* status) {
if (module >= kNumPCMModules) {
*status = PARAMETER_OUT_OF_RANGE;
return false;
@@ -141,7 +141,7 @@ bool getPCMSolenoidVoltageFault(uint8_t module, int32_t* status) {
return value;
}
void clearAllPCMStickyFaults_sol(uint8_t module, int32_t* status) {
void HAL_ClearAllPCMStickyFaults_sol(uint8_t module, int32_t* status) {
if (module >= kNumPCMModules) {
*status = PARAMETER_OUT_OF_RANGE;
return;

View File

@@ -18,7 +18,7 @@
extern "C" {
STATUS verifyTaskID(TASK task) {
STATUS HAL_VerifyTaskID(TASK task) {
if (task != nullptr && pthread_kill(*task, 0) == 0) {
return OK;
} else {
@@ -26,11 +26,11 @@ STATUS verifyTaskID(TASK task) {
}
}
STATUS setTaskPriority(TASK task, int priority) {
STATUS HAL_SetTaskPriority(TASK task, int priority) {
int policy = 0;
struct sched_param param;
if (verifyTaskID(task) == OK &&
if (HAL_VerifyTaskID(task) == OK &&
pthread_getschedparam(*task, &policy, &param) == 0) {
param.sched_priority = priority;
if (pthread_setschedparam(*task, SCHED_FIFO, &param) == 0) {
@@ -43,11 +43,11 @@ STATUS setTaskPriority(TASK task, int priority) {
}
}
STATUS getTaskPriority(TASK task, int* priority) {
STATUS HAL_GetTaskPriority(TASK task, int* priority) {
int policy = 0;
struct sched_param param;
if (verifyTaskID(task) == OK &&
if (HAL_VerifyTaskID(task) == OK &&
pthread_getschedparam(*task, &policy, &param) == 0) {
*priority = param.sched_priority;
return OK;

View File

@@ -26,7 +26,7 @@ namespace hal {
* Because they are allocated by index, each individual index holds its own
* mutex, which reduces contention heavily.]
*
* @tparam THandle The Handle Type (Must be typedefed from HalHandle)
* @tparam THandle The Handle Type (Must be typedefed from HAL_Handle)
* @tparam TStruct The struct type held by this resource
* @tparam size The number of resources allowed to be allocated
*
@@ -40,9 +40,9 @@ class DigitalHandleResource {
DigitalHandleResource operator=(const DigitalHandleResource&) = delete;
DigitalHandleResource();
~DigitalHandleResource();
THandle Allocate(int16_t index, HalHandleEnum enumValue, int32_t* status);
std::shared_ptr<TStruct> Get(THandle handle, HalHandleEnum enumValue);
void Free(THandle handle, HalHandleEnum enumValue);
THandle Allocate(int16_t index, HAL_HandleEnum enumValue, int32_t* status);
std::shared_ptr<TStruct> Get(THandle handle, HAL_HandleEnum enumValue);
void Free(THandle handle, HAL_HandleEnum enumValue);
private:
// Dynamic array to shrink HAL file size.
@@ -64,17 +64,17 @@ DigitalHandleResource<THandle, TStruct, size>::~DigitalHandleResource() {
template <typename THandle, typename TStruct, int16_t size>
THandle DigitalHandleResource<THandle, TStruct, size>::Allocate(
int16_t index, HalHandleEnum enumValue, int32_t* status) {
int16_t index, HAL_HandleEnum enumValue, int32_t* status) {
// don't aquire the lock if we can fail early.
if (index < 0 || index >= size) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
m_structures[index] = std::make_shared<TStruct>();
return (THandle)hal::createHandle(index, enumValue);
@@ -82,7 +82,7 @@ THandle DigitalHandleResource<THandle, TStruct, size>::Allocate(
template <typename THandle, typename TStruct, int16_t size>
std::shared_ptr<TStruct> DigitalHandleResource<THandle, TStruct, size>::Get(
THandle handle, HalHandleEnum enumValue) {
THandle handle, HAL_HandleEnum enumValue) {
// get handle index, and fail early if index out of range or wrong handle
int16_t index = getHandleTypedIndex(handle, enumValue);
if (index < 0 || index >= size) {
@@ -96,7 +96,7 @@ std::shared_ptr<TStruct> DigitalHandleResource<THandle, TStruct, size>::Get(
template <typename THandle, typename TStruct, int16_t size>
void DigitalHandleResource<THandle, TStruct, size>::Free(
THandle handle, HalHandleEnum enumValue) {
THandle handle, HAL_HandleEnum enumValue) {
// get handle index, and fail early if index out of range or wrong handle
int16_t index = getHandleTypedIndex(handle, enumValue);
if (index < 0 || index >= size) return;

View File

@@ -11,9 +11,9 @@
#include "UnlimitedHandleResource.h"
namespace hal {
HalPortHandle createPortHandle(uint8_t pin, uint8_t module) {
HAL_PortHandle createPortHandle(uint8_t pin, uint8_t module) {
// set last 8 bits, then shift to first 8 bits
HalPortHandle handle = static_cast<HalPortHandle>(HalHandleEnum::Port);
HAL_PortHandle handle = static_cast<HAL_PortHandle>(HAL_HandleEnum::Port);
handle = handle << 24;
// shift module and add to 3rd set of 8 bits
int32_t temp = module;
@@ -24,12 +24,12 @@ HalPortHandle createPortHandle(uint8_t pin, uint8_t module) {
return handle;
}
HalHandle createHandle(int16_t index, HalHandleEnum handleType) {
if (index < 0) return HAL_INVALID_HANDLE;
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType) {
if (index < 0) return HAL_kInvalidHandle;
uint8_t hType = static_cast<uint8_t>(handleType);
if (hType == 0 || hType > 127) return HAL_INVALID_HANDLE;
if (hType == 0 || hType > 127) return HAL_kInvalidHandle;
// set last 8 bits, then shift to first 8 bits
HalHandle handle = hType;
HAL_Handle handle = hType;
handle = handle << 24;
// add index to set last 16 bits
handle += index;

View File

@@ -25,7 +25,7 @@ namespace hal {
constexpr int16_t InvalidHandleIndex = -1;
enum class HalHandleEnum {
enum class HAL_HandleEnum {
Undefined = 0,
DIO = 1,
Port = 2,
@@ -45,19 +45,19 @@ enum class HalHandleEnum {
AnalogGyro = 16
};
static inline int16_t getHandleIndex(HalHandle handle) {
static inline int16_t getHandleIndex(HAL_Handle handle) {
// mask and return last 16 bits
return (int16_t)(handle & 0xffff);
}
static inline HalHandleEnum getHandleType(HalHandle handle) {
static inline HAL_HandleEnum getHandleType(HAL_Handle handle) {
// mask first 8 bits and cast to enum
return (HalHandleEnum)((handle >> 24) & 0xff);
return (HAL_HandleEnum)((handle >> 24) & 0xff);
}
static inline bool isHandleType(HalHandle handle, HalHandleEnum handleType) {
static inline bool isHandleType(HAL_Handle handle, HAL_HandleEnum handleType) {
return handleType == getHandleType(handle);
}
static inline int16_t getHandleTypedIndex(HalHandle handle,
HalHandleEnum enumType) {
static inline int16_t getHandleTypedIndex(HAL_Handle handle,
HAL_HandleEnum enumType) {
if (!isHandleType(handle, enumType)) return InvalidHandleIndex;
return getHandleIndex(handle);
}
@@ -72,18 +72,18 @@ static inline int16_t getHandleTypedIndex(HalHandle handle,
*/
// using a 16 bit value so we can store 0-255 and still report error
static inline int16_t getPortHandlePin(HalPortHandle handle) {
if (!isHandleType(handle, HalHandleEnum::Port)) return InvalidHandleIndex;
static inline int16_t getPortHandlePin(HAL_PortHandle handle) {
if (!isHandleType(handle, HAL_HandleEnum::Port)) return InvalidHandleIndex;
return (uint8_t)(handle & 0xff);
}
// using a 16 bit value so we can store 0-255 and still report error
static inline int16_t getPortHandleModule(HalPortHandle handle) {
if (!isHandleType(handle, HalHandleEnum::Port)) return InvalidHandleIndex;
static inline int16_t getPortHandleModule(HAL_PortHandle handle) {
if (!isHandleType(handle, HAL_HandleEnum::Port)) return InvalidHandleIndex;
return (uint8_t)((handle >> 8) & 0xff);
}
HalPortHandle createPortHandle(uint8_t pin, uint8_t module);
HAL_PortHandle createPortHandle(uint8_t pin, uint8_t module);
HalHandle createHandle(int16_t index, HalHandleEnum handleType);
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType);
}

View File

@@ -25,14 +25,14 @@ namespace hal {
* Because they are allocated by index, each individual index holds its own
* mutex, which reduces contention heavily.]
*
* @tparam THandle The Handle Type (Must be typedefed from HalHandle)
* @tparam THandle The Handle Type (Must be typedefed from HAL_Handle)
* @tparam TStruct The struct type held by this resource
* @tparam size The number of resources allowed to be allocated
* @tparam enumValue The type value stored in the handle
*
*/
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
class IndexedHandleResource {
friend class IndexedHandleResourceTest;
@@ -52,7 +52,7 @@ class IndexedHandleResource {
};
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
IndexedHandleResource<THandle, TStruct, size,
enumValue>::IndexedHandleResource() {
m_structures = new std::shared_ptr<TStruct>[size];
@@ -60,7 +60,7 @@ IndexedHandleResource<THandle, TStruct, size,
}
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
IndexedHandleResource<THandle, TStruct, size,
enumValue>::~IndexedHandleResource() {
delete[] m_structures;
@@ -68,26 +68,26 @@ IndexedHandleResource<THandle, TStruct, size,
}
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
THandle IndexedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
int16_t index, int32_t* status) {
// don't aquire the lock if we can fail early.
if (index < 0 || index >= size) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
m_structures[index] = std::make_shared<TStruct>();
return (THandle)hal::createHandle(index, enumValue);
}
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
std::shared_ptr<TStruct>
IndexedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
// get handle index, and fail early if index out of range or wrong handle
@@ -102,7 +102,7 @@ IndexedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
}
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
void IndexedHandleResource<THandle, TStruct, size, enumValue>::Free(
THandle handle) {
// get handle index, and fail early if index out of range or wrong handle

View File

@@ -23,14 +23,14 @@ namespace hal {
* version
* allows a limited number of handles that are allocated sequentially.
*
* @tparam THandle The Handle Type (Must be typedefed from HalHandle)
* @tparam THandle The Handle Type (Must be typedefed from HAL_Handle)
* @tparam TStruct The struct type held by this resource
* @tparam size The number of resources allowed to be allocated
* @tparam enumValue The type value stored in the handle
*
*/
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
class LimitedClassedHandleResource {
friend class LimitedClassedHandleResourceTest;
@@ -52,7 +52,7 @@ class LimitedClassedHandleResource {
};
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
LimitedClassedHandleResource<THandle, TStruct, size,
enumValue>::LimitedClassedHandleResource() {
m_structures = new std::shared_ptr<TStruct>[size];
@@ -60,7 +60,7 @@ LimitedClassedHandleResource<THandle, TStruct, size,
}
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
LimitedClassedHandleResource<THandle, TStruct, size,
enumValue>::~LimitedClassedHandleResource() {
delete[] m_structures;
@@ -68,7 +68,7 @@ LimitedClassedHandleResource<THandle, TStruct, size,
}
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
THandle
LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
std::shared_ptr<TStruct> toSet) {
@@ -84,11 +84,11 @@ LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
return (THandle)createHandle(i, enumValue);
}
}
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
std::shared_ptr<TStruct> LimitedClassedHandleResource<
THandle, TStruct, size, enumValue>::Get(THandle handle) {
// get handle index, and fail early if index out of range or wrong handle
@@ -103,7 +103,7 @@ std::shared_ptr<TStruct> LimitedClassedHandleResource<
}
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
void LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Free(
THandle handle) {
// get handle index, and fail early if index out of range or wrong handle

View File

@@ -22,14 +22,14 @@ namespace hal {
* The LimitedHandleResource class is a way to track handles. This version
* allows a limited number of handles that are allocated sequentially.
*
* @tparam THandle The Handle Type (Must be typedefed from HalHandle)
* @tparam THandle The Handle Type (Must be typedefed from HAL_Handle)
* @tparam TStruct The struct type held by this resource
* @tparam size The number of resources allowed to be allocated
* @tparam enumValue The type value stored in the handle
*
*/
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
class LimitedHandleResource {
friend class LimitedHandleResourceTest;
@@ -50,7 +50,7 @@ class LimitedHandleResource {
};
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
LimitedHandleResource<THandle, TStruct, size,
enumValue>::LimitedHandleResource() {
m_structures = new std::shared_ptr<TStruct>[size];
@@ -58,7 +58,7 @@ LimitedHandleResource<THandle, TStruct, size,
}
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
LimitedHandleResource<THandle, TStruct, size,
enumValue>::~LimitedHandleResource() {
delete[] m_structures;
@@ -66,7 +66,7 @@ LimitedHandleResource<THandle, TStruct, size,
}
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
THandle LimitedHandleResource<THandle, TStruct, size, enumValue>::Allocate() {
// globally lock to loop through indices
std::lock_guard<priority_mutex> sync(m_allocateMutex);
@@ -80,11 +80,11 @@ THandle LimitedHandleResource<THandle, TStruct, size, enumValue>::Allocate() {
return (THandle)createHandle(i, enumValue);
}
}
return HAL_INVALID_HANDLE;
return HAL_kInvalidHandle;
}
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
std::shared_ptr<TStruct>
LimitedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
// get handle index, and fail early if index out of range or wrong handle
@@ -99,7 +99,7 @@ LimitedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
}
template <typename THandle, typename TStruct, int16_t size,
HalHandleEnum enumValue>
HAL_HandleEnum enumValue>
void LimitedHandleResource<THandle, TStruct, size, enumValue>::Free(
THandle handle) {
// get handle index, and fail early if index out of range or wrong handle

View File

@@ -27,12 +27,12 @@ namespace hal {
* the future.
* Because we have to loop through the allocator, we must use a global mutex.
* @tparam THandle The Handle Type (Must be typedefed from HalHandle)
* @tparam THandle The Handle Type (Must be typedefed from HAL_Handle)
* @tparam TStruct The struct type held by this resource
* @tparam enumValue The type value stored in the handle
*
*/
template <typename THandle, typename TStruct, HalHandleEnum enumValue>
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
class UnlimitedHandleResource {
friend class UnlimitedHandleResourceTest;
@@ -49,7 +49,7 @@ class UnlimitedHandleResource {
priority_mutex m_handleMutex;
};
template <typename THandle, typename TStruct, HalHandleEnum enumValue>
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
THandle UnlimitedHandleResource<THandle, TStruct, enumValue>::Allocate(
std::shared_ptr<TStruct> structure) {
std::lock_guard<priority_mutex> sync(m_handleMutex);
@@ -60,13 +60,13 @@ THandle UnlimitedHandleResource<THandle, TStruct, enumValue>::Allocate(
return (THandle)createHandle(i, enumValue);
}
}
if (i >= INT16_MAX) return HAL_INVALID_HANDLE;
if (i >= INT16_MAX) return HAL_kInvalidHandle;
m_structures.push_back(structure);
return (THandle)createHandle(static_cast<int16_t>(i), enumValue);
}
template <typename THandle, typename TStruct, HalHandleEnum enumValue>
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
std::shared_ptr<TStruct>
UnlimitedHandleResource<THandle, TStruct, enumValue>::Get(THandle handle) {
int16_t index = getHandleTypedIndex(handle, enumValue);
@@ -76,7 +76,7 @@ UnlimitedHandleResource<THandle, TStruct, enumValue>::Get(THandle handle) {
return m_structures[index];
}
template <typename THandle, typename TStruct, HalHandleEnum enumValue>
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
void UnlimitedHandleResource<THandle, TStruct, enumValue>::Free(
THandle handle) {
int16_t index = getHandleTypedIndex(handle, enumValue);

View File

@@ -11,29 +11,31 @@
#include "FRC_NetworkCommunication/FRCComm.h"
struct HALJoystickAxesInt {
struct HAL_JoystickAxesInt {
uint16_t count;
int16_t axes[kMaxJoystickAxes];
int16_t axes[HAL_kMaxJoystickAxes];
};
extern "C" {
int HALGetControlWord(HALControlWord* data) {
int HAL_GetControlWord(HAL_ControlWord* data) {
return FRC_NetworkCommunication_getControlWord((ControlWord_t*)data);
}
void HALSetNewDataSem(MULTIWAIT_ID sem) { setNewDataSem(sem->native_handle()); }
void HAL_SetNewDataSem(MULTIWAIT_ID sem) {
setNewDataSem(sem->native_handle());
}
int HALGetAllianceStation(enum HALAllianceStationID* allianceStation) {
int HAL_GetAllianceStation(enum HAL_AllianceStationID* allianceStation) {
return FRC_NetworkCommunication_getAllianceStation(
(AllianceStationID_t*)allianceStation);
}
int HALGetJoystickAxes(uint8_t joystickNum, HALJoystickAxes* axes) {
HALJoystickAxesInt axesInt;
int HAL_GetJoystickAxes(uint8_t joystickNum, HAL_JoystickAxes* axes) {
HAL_JoystickAxesInt axesInt;
int retVal = FRC_NetworkCommunication_getJoystickAxes(
joystickNum, (JoystickAxes_t*)&axesInt, kMaxJoystickAxes);
joystickNum, (JoystickAxes_t*)&axesInt, HAL_kMaxJoystickAxes);
// copy int values to float values
axes->count = axesInt.count;
@@ -51,12 +53,12 @@ int HALGetJoystickAxes(uint8_t joystickNum, HALJoystickAxes* axes) {
return retVal;
}
int HALGetJoystickPOVs(uint8_t joystickNum, HALJoystickPOVs* povs) {
int HAL_GetJoystickPOVs(uint8_t joystickNum, HAL_JoystickPOVs* povs) {
return FRC_NetworkCommunication_getJoystickPOVs(
joystickNum, (JoystickPOV_t*)povs, kMaxJoystickPOVs);
joystickNum, (JoystickPOV_t*)povs, HAL_kMaxJoystickPOVs);
}
int HALGetJoystickButtons(uint8_t joystickNum, HALJoystickButtons* buttons) {
int HAL_GetJoystickButtons(uint8_t joystickNum, HAL_JoystickButtons* buttons) {
return FRC_NetworkCommunication_getJoystickButtons(
joystickNum, &buttons->buttons, &buttons->count);
}
@@ -71,12 +73,13 @@ int HALGetJoystickButtons(uint8_t joystickNum, HALJoystickButtons* buttons) {
* @return error code reported from Network Comm back-end. Zero is good,
* nonzero is bad.
*/
int HALGetJoystickDescriptor(uint8_t joystickNum, HALJoystickDescriptor* desc) {
int HAL_GetJoystickDescriptor(uint8_t joystickNum,
HAL_JoystickDescriptor* desc) {
desc->isXbox = 0;
desc->type = -1;
desc->name[0] = '\0';
desc->axisCount =
kMaxJoystickAxes; /* set to the desc->axisTypes's capacity */
HAL_kMaxJoystickAxes; /* set to the desc->axisTypes's capacity */
desc->buttonCount = 0;
desc->povCount = 0;
int retval = FRC_NetworkCommunication_getJoystickDesc(
@@ -92,27 +95,27 @@ int HALGetJoystickDescriptor(uint8_t joystickNum, HALJoystickDescriptor* desc) {
return retval;
}
int HALGetJoystickIsXbox(uint8_t joystickNum) {
HALJoystickDescriptor joystickDesc;
if (HALGetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
int HAL_GetJoystickIsXbox(uint8_t joystickNum) {
HAL_JoystickDescriptor joystickDesc;
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
return 0;
} else {
return joystickDesc.isXbox;
}
}
int HALGetJoystickType(uint8_t joystickNum) {
HALJoystickDescriptor joystickDesc;
if (HALGetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
int HAL_GetJoystickType(uint8_t joystickNum) {
HAL_JoystickDescriptor joystickDesc;
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
return -1;
} else {
return joystickDesc.type;
}
}
char* HALGetJoystickName(uint8_t joystickNum) {
HALJoystickDescriptor joystickDesc;
if (HALGetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
char* HAL_GetJoystickName(uint8_t joystickNum) {
HAL_JoystickDescriptor joystickDesc;
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
char* name = (char*)std::malloc(1);
name[0] = '\0';
return name;
@@ -124,42 +127,42 @@ char* HALGetJoystickName(uint8_t joystickNum) {
}
}
int HALGetJoystickAxisType(uint8_t joystickNum, uint8_t axis) {
HALJoystickDescriptor joystickDesc;
if (HALGetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
int HAL_GetJoystickAxisType(uint8_t joystickNum, uint8_t axis) {
HAL_JoystickDescriptor joystickDesc;
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
return -1;
} else {
return joystickDesc.axisTypes[axis];
}
}
int HALSetJoystickOutputs(uint8_t joystickNum, uint32_t outputs,
uint16_t leftRumble, uint16_t rightRumble) {
int HAL_SetJoystickOutputs(uint8_t joystickNum, uint32_t outputs,
uint16_t leftRumble, uint16_t rightRumble) {
return FRC_NetworkCommunication_setJoystickOutputs(joystickNum, outputs,
leftRumble, rightRumble);
}
int HALGetMatchTime(float* matchTime) {
int HAL_GetMatchTime(float* matchTime) {
return FRC_NetworkCommunication_getMatchTime(matchTime);
}
void HALNetworkCommunicationObserveUserProgramStarting(void) {
void HAL_NetworkCommunicationObserveUserProgramStarting(void) {
FRC_NetworkCommunication_observeUserProgramStarting();
}
void HALNetworkCommunicationObserveUserProgramDisabled(void) {
void HAL_NetworkCommunicationObserveUserProgramDisabled(void) {
FRC_NetworkCommunication_observeUserProgramDisabled();
}
void HALNetworkCommunicationObserveUserProgramAutonomous(void) {
void HAL_NetworkCommunicationObserveUserProgramAutonomous(void) {
FRC_NetworkCommunication_observeUserProgramAutonomous();
}
void HALNetworkCommunicationObserveUserProgramTeleop(void) {
void HAL_NetworkCommunicationObserveUserProgramTeleop(void) {
FRC_NetworkCommunication_observeUserProgramTeleop();
}
void HALNetworkCommunicationObserveUserProgramTest(void) {
void HAL_NetworkCommunicationObserveUserProgramTest(void) {
FRC_NetworkCommunication_observeUserProgramTest();
}

View File

@@ -56,5 +56,5 @@ class AnalogGyro : public GyroBase {
std::shared_ptr<AnalogInput> m_analog;
private:
HalGyroHandle m_gyroHandle = HAL_INVALID_HANDLE;
HAL_GyroHandle m_gyroHandle = HAL_kInvalidHandle;
};

View File

@@ -81,7 +81,7 @@ class AnalogInput : public SensorBase,
private:
uint32_t m_channel;
// TODO: Adjust HAL to avoid use of raw pointers.
HalAnalogInputHandle m_port;
HAL_AnalogInputHandle m_port;
int64_t m_accumulatorOffset;
std::shared_ptr<ITable> m_table;

View File

@@ -35,7 +35,7 @@ class AnalogOutput : public SensorBase, public LiveWindowSendable {
protected:
uint32_t m_channel;
HalAnalogOutputHandle m_port;
HAL_AnalogOutputHandle m_port;
std::shared_ptr<ITable> m_table;
};

View File

@@ -33,7 +33,7 @@ class AnalogTrigger : public SensorBase {
private:
uint8_t m_index;
HalAnalogTriggerHandle m_trigger;
HAL_AnalogTriggerHandle m_trigger;
AnalogInput* m_analogInput = nullptr;
bool m_ownsAnalog = false;
};

View File

@@ -49,7 +49,7 @@ class AnalogTriggerOutput : public DigitalSource {
bool Get() const;
// DigitalSource interface
virtual HalHandle GetPortHandleForRouting() const override;
virtual HAL_Handle GetPortHandleForRouting() const override;
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const override;
virtual bool IsAnalogTrigger() const override;
virtual uint32_t GetChannel() const override;

View File

@@ -0,0 +1,15 @@
/*----------------------------------------------------------------------------*/
/* 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
enum class AnalogTriggerType {
kInWindow = 0,
kState = 1,
kRisingPulse = 2,
kFallingPulse = 3
};

View File

@@ -54,7 +54,7 @@ class Compressor : public SensorBase,
std::shared_ptr<nt::Value> value, bool isNew) override;
protected:
HalCompressorHandle m_compressorHandle;
HAL_CompressorHandle m_compressorHandle;
private:
void SetCompressor(bool on);

View File

@@ -31,6 +31,12 @@ class Counter : public SensorBase,
public CounterBase,
public LiveWindowSendable {
public:
enum Mode {
kTwoPulse = 0,
kSemiperiod = 1,
kPulseLength = 2,
kExternalDirection = 3
};
explicit Counter(Mode mode = kTwoPulse);
explicit Counter(int32_t channel);
explicit Counter(DigitalSource* source);
@@ -98,7 +104,7 @@ class Counter : public SensorBase,
// Makes the counter count down.
std::shared_ptr<DigitalSource> m_downSource;
// The FPGA counter object
HalCounterHandle m_counter = HAL_INVALID_HANDLE;
HAL_CounterHandle m_counter = HAL_kInvalidHandle;
private:
int32_t m_index = 0; ///< The index of this counter.

View File

@@ -32,7 +32,7 @@ class DigitalInput : public DigitalSource, public LiveWindowSendable {
uint32_t GetChannel() const override;
// Digital Source Interface
virtual HalHandle GetPortHandleForRouting() const override;
virtual HAL_Handle GetPortHandleForRouting() const override;
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const override;
virtual bool IsAnalogTrigger() const override;
@@ -45,7 +45,7 @@ class DigitalInput : public DigitalSource, public LiveWindowSendable {
private:
uint32_t m_channel;
HalDigitalHandle m_handle;
HAL_DigitalHandle m_handle;
std::shared_ptr<ITable> m_table;
friend class DigitalGlitchFilter;

View File

@@ -36,7 +36,7 @@ class DigitalOutput : public DigitalSource,
void UpdateDutyCycle(float dutyCycle);
// Digital Source Interface
virtual HalHandle GetPortHandleForRouting() const override;
virtual HAL_Handle GetPortHandleForRouting() const override;
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const override;
virtual bool IsAnalogTrigger() const override;
@@ -51,8 +51,8 @@ class DigitalOutput : public DigitalSource,
private:
uint32_t m_channel;
HalDigitalHandle m_handle;
HalDigitalPWMHandle m_pwmGenerator;
HAL_DigitalHandle m_handle;
HAL_DigitalPWMHandle m_pwmGenerator;
std::shared_ptr<ITable> m_table;
};

View File

@@ -23,7 +23,7 @@
class DigitalSource : public InterruptableSensorBase {
public:
virtual ~DigitalSource() = default;
virtual HalHandle GetPortHandleForRouting() const = 0;
virtual HAL_Handle GetPortHandleForRouting() const = 0;
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
virtual bool IsAnalogTrigger() const = 0;
virtual uint32_t GetChannel() const = 0;

View File

@@ -50,8 +50,8 @@ class DoubleSolenoid : public SolenoidBase,
uint32_t m_reverseChannel; ///< The reverse channel on the module to control.
uint8_t m_forwardMask; ///< The mask for the forward channel.
uint8_t m_reverseMask; ///< The mask for the reverse channel.
HalSolenoidHandle m_forwardHandle = HAL_INVALID_HANDLE;
HalSolenoidHandle m_reverseHandle = HAL_INVALID_HANDLE;
HAL_SolenoidHandle m_forwardHandle = HAL_kInvalidHandle;
HAL_SolenoidHandle m_reverseHandle = HAL_kInvalidHandle;
std::shared_ptr<ITable> m_table;
};

View File

@@ -100,16 +100,16 @@ class DriverStation : public SensorBase, public RobotStateInterface {
void ReportJoystickUnpluggedWarning(std::string message);
void Run();
std::unique_ptr<HALJoystickAxes[]> m_joystickAxes;
std::unique_ptr<HALJoystickPOVs[]> m_joystickPOVs;
std::unique_ptr<HALJoystickButtons[]> m_joystickButtons;
std::unique_ptr<HALJoystickDescriptor[]> m_joystickDescriptor;
std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxes;
std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVs;
std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtons;
std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptor;
// Cached Data
std::unique_ptr<HALJoystickAxes[]> m_joystickAxesCache;
std::unique_ptr<HALJoystickPOVs[]> m_joystickPOVsCache;
std::unique_ptr<HALJoystickButtons[]> m_joystickButtonsCache;
std::unique_ptr<HALJoystickDescriptor[]> m_joystickDescriptorCache;
std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxesCache;
std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVsCache;
std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtonsCache;
std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptorCache;
Task m_task;
std::atomic<bool> m_isRunning{false};

View File

@@ -99,7 +99,7 @@ class Encoder : public SensorBase,
std::shared_ptr<DigitalSource> m_aSource; // the A phase of the quad encoder
std::shared_ptr<DigitalSource> m_bSource; // the B phase of the quad encoder
std::unique_ptr<DigitalSource> m_indexSource = nullptr;
HalEncoderHandle m_encoder = HAL_INVALID_HANDLE;
HAL_EncoderHandle m_encoder = HAL_kInvalidHandle;
std::shared_ptr<ITable> m_table;
friend class DigitalGlitchFilter;

View File

@@ -9,7 +9,7 @@
#include <memory>
#include "HAL/AnalogTrigger.h"
#include "AnalogTriggerType.h"
#include "HAL/Interrupts.h"
#include "SensorBase.h"
@@ -24,7 +24,7 @@ class InterruptableSensorBase : public SensorBase {
InterruptableSensorBase();
virtual ~InterruptableSensorBase() = default;
virtual HalHandle GetPortHandleForRouting() const = 0;
virtual HAL_Handle GetPortHandleForRouting() const = 0;
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
virtual void RequestInterrupts(
InterruptHandlerFunction handler,
@@ -45,6 +45,6 @@ class InterruptableSensorBase : public SensorBase {
virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
protected:
HalInterruptHandle m_interrupt = HAL_INVALID_HANDLE;
HAL_InterruptHandle m_interrupt = HAL_kInvalidHandle;
void AllocateInterrupts(bool watcher);
};

View File

@@ -43,7 +43,7 @@ class Notifier : public ErrorBase {
// held while updating process information
priority_mutex m_processMutex;
// HAL handle, atomic for proper destruction
std::atomic<HalNotifierHandle> m_notifier{0};
std::atomic<HAL_NotifierHandle> m_notifier{0};
// address of the handler
TimerEventHandler m_handler;
// the absolute expiration time

View File

@@ -75,5 +75,5 @@ class PWM : public SensorBase,
private:
uint32_t m_channel;
HalDigitalHandle m_handle;
HAL_DigitalHandle m_handle;
};

View File

@@ -67,8 +67,8 @@ class Relay : public MotorSafety,
uint32_t m_channel;
Direction m_direction;
HalRelayHandle m_forwardHandle = HAL_INVALID_HANDLE;
HalRelayHandle m_reverseHandle = HAL_INVALID_HANDLE;
HAL_RelayHandle m_forwardHandle = HAL_kInvalidHandle;
HAL_RelayHandle m_reverseHandle = HAL_kInvalidHandle;
std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
};

View File

@@ -17,12 +17,12 @@ class DriverStation;
#define START_ROBOT_CLASS(_ClassName_) \
int main() { \
if (!HALInitialize()) { \
if (!HAL_Initialize()) { \
std::cerr << "FATAL ERROR: HAL could not be initialized" << std::endl; \
return -1; \
} \
HALReport(HALUsageReporting::kResourceType_Language, \
HALUsageReporting::kLanguage_CPlusPlus); \
HAL_Report(HALUsageReporting::kResourceType_Language, \
HALUsageReporting::kLanguage_CPlusPlus); \
static _ClassName_ robot; \
std::printf("\n********** Robot program starting **********\n"); \
robot.StartCompetition(); \

View File

@@ -41,7 +41,7 @@ class Solenoid : public SolenoidBase,
std::shared_ptr<ITable> GetTable() const;
private:
HalSolenoidHandle m_solenoidHandle = HAL_INVALID_HANDLE;
HAL_SolenoidHandle m_solenoidHandle = HAL_kInvalidHandle;
uint32_t m_channel; ///< The channel on the module to control.
std::shared_ptr<ITable> m_table;
};

View File

@@ -30,8 +30,8 @@ ADXL345_I2C::ADXL345_I2C(I2C::Port port, Range range, int deviceAddress)
// Specify the data format to read
SetRange(range);
HALReport(HALUsageReporting::kResourceType_ADXL345,
HALUsageReporting::kADXL345_I2C, 0);
HAL_Report(HALUsageReporting::kResourceType_ADXL345,
HALUsageReporting::kADXL345_I2C, 0);
LiveWindow::GetInstance()->AddSensor("ADXL345_I2C", port, this);
}

View File

@@ -38,8 +38,8 @@ ADXL345_SPI::ADXL345_SPI(SPI::Port port, ADXL345_SPI::Range range)
SetRange(range);
HALReport(HALUsageReporting::kResourceType_ADXL345,
HALUsageReporting::kADXL345_SPI);
HAL_Report(HALUsageReporting::kResourceType_ADXL345,
HALUsageReporting::kADXL345_SPI);
LiveWindow::GetInstance()->AddSensor("ADXL345_SPI", port, this);
}

View File

@@ -69,7 +69,7 @@ ADXL362::ADXL362(SPI::Port port, Range range) : m_spi(port) {
commands[2] = kPowerCtl_Measure | kPowerCtl_UltraLowNoise;
m_spi.Write(commands, 3);
HALReport(HALUsageReporting::kResourceType_ADXL362, port);
HAL_Report(HALUsageReporting::kResourceType_ADXL362, port);
LiveWindow::GetInstance()->AddSensor("ADXL362", port, this);
}

View File

@@ -75,7 +75,7 @@ ADXRS450_Gyro::ADXRS450_Gyro(SPI::Port port) : m_spi(port) {
Calibrate();
HALReport(HALUsageReporting::kResourceType_ADXRS450, port);
HAL_Report(HALUsageReporting::kResourceType_ADXRS450, port);
LiveWindow::GetInstance()->AddSensor("ADXRS450_Gyro", port, this);
}

View File

@@ -14,8 +14,8 @@
* Common function for initializing the accelerometer.
*/
void AnalogAccelerometer::InitAccelerometer() {
HALReport(HALUsageReporting::kResourceType_Accelerometer,
m_analogInput->GetChannel());
HAL_Report(HALUsageReporting::kResourceType_Accelerometer,
m_analogInput->GetChannel());
LiveWindow::GetInstance()->AddSensor("Accelerometer",
m_analogInput->GetChannel(), this);
}

View File

@@ -80,11 +80,11 @@ AnalogGyro::AnalogGyro(int32_t channel, uint32_t center, float offset) {
m_analog = std::make_shared<AnalogInput>(channel);
InitGyro();
int32_t status = 0;
setAnalogGyroParameters(m_gyroHandle, kDefaultVoltsPerDegreePerSecond, offset,
center, &status);
HAL_SetAnalogGyroParameters(m_gyroHandle, kDefaultVoltsPerDegreePerSecond,
offset, center, &status);
if (status != 0) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
m_gyroHandle = HAL_INVALID_HANDLE;
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
m_gyroHandle = HAL_kInvalidHandle;
return;
}
Reset();
@@ -109,11 +109,11 @@ AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel, uint32_t center,
} else {
InitGyro();
int32_t status = 0;
setAnalogGyroParameters(m_gyroHandle, kDefaultVoltsPerDegreePerSecond,
offset, center, &status);
HAL_SetAnalogGyroParameters(m_gyroHandle, kDefaultVoltsPerDegreePerSecond,
offset, center, &status);
if (status != 0) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
m_gyroHandle = HAL_INVALID_HANDLE;
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
m_gyroHandle = HAL_kInvalidHandle;
return;
}
Reset();
@@ -124,7 +124,7 @@ AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel, uint32_t center,
* AnalogGyro Destructor
*
*/
AnalogGyro::~AnalogGyro() { freeAnalogGyro(m_gyroHandle); }
AnalogGyro::~AnalogGyro() { HAL_FreeAnalogGyro(m_gyroHandle); }
/**
* Reset the gyro.
@@ -136,8 +136,8 @@ AnalogGyro::~AnalogGyro() { freeAnalogGyro(m_gyroHandle); }
void AnalogGyro::Reset() {
if (StatusIsFatal()) return;
int32_t status = 0;
resetAnalogGyro(m_gyroHandle, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_ResetAnalogGyro(m_gyroHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -145,34 +145,34 @@ void AnalogGyro::Reset() {
*/
void AnalogGyro::InitGyro() {
if (StatusIsFatal()) return;
if (m_gyroHandle == HAL_INVALID_HANDLE) {
if (m_gyroHandle == HAL_kInvalidHandle) {
int32_t status = 0;
m_gyroHandle = initializeAnalogGyro(m_analog->m_port, &status);
m_gyroHandle = HAL_InitializeAnalogGyro(m_analog->m_port, &status);
if (status == PARAMETER_OUT_OF_RANGE) {
wpi_setWPIErrorWithContext(ParameterOutOfRange,
" channel (must be accumulator channel)");
m_analog = nullptr;
m_gyroHandle = HAL_INVALID_HANDLE;
m_gyroHandle = HAL_kInvalidHandle;
return;
}
if (status != 0) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
m_analog = nullptr;
m_gyroHandle = HAL_INVALID_HANDLE;
m_gyroHandle = HAL_kInvalidHandle;
return;
}
}
int32_t status = 0;
setupAnalogGyro(m_gyroHandle, &status);
HAL_SetupAnalogGyro(m_gyroHandle, &status);
if (status != 0) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
m_analog = nullptr;
m_gyroHandle = HAL_INVALID_HANDLE;
m_gyroHandle = HAL_kInvalidHandle;
return;
}
HALReport(HALUsageReporting::kResourceType_Gyro, m_analog->GetChannel());
HAL_Report(HALUsageReporting::kResourceType_Gyro, m_analog->GetChannel());
LiveWindow::GetInstance()->AddSensor("AnalogGyro", m_analog->GetChannel(),
this);
}
@@ -180,8 +180,8 @@ void AnalogGyro::InitGyro() {
void AnalogGyro::Calibrate() {
if (StatusIsFatal()) return;
int32_t status = 0;
calibrateAnalogGyro(m_gyroHandle, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_CalibrateAnalogGyro(m_gyroHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -199,8 +199,8 @@ void AnalogGyro::Calibrate() {
float AnalogGyro::GetAngle() const {
if (StatusIsFatal()) return 0.f;
int32_t status = 0;
float value = getAnalogGyroAngle(m_gyroHandle, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
float value = HAL_GetAnalogGyroAngle(m_gyroHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;
}
@@ -214,8 +214,8 @@ float AnalogGyro::GetAngle() const {
double AnalogGyro::GetRate() const {
if (StatusIsFatal()) return 0.0;
int32_t status = 0;
double value = getAnalogGyroRate(m_gyroHandle, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
double value = HAL_GetAnalogGyroRate(m_gyroHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;
}
@@ -228,8 +228,8 @@ double AnalogGyro::GetRate() const {
float AnalogGyro::GetOffset() const {
if (StatusIsFatal()) return 0.0;
int32_t status = 0;
float value = getAnalogGyroOffset(m_gyroHandle, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
float value = HAL_GetAnalogGyroOffset(m_gyroHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;
}
@@ -242,8 +242,8 @@ float AnalogGyro::GetOffset() const {
uint32_t AnalogGyro::GetCenter() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
uint32_t value = getAnalogGyroCenter(m_gyroHandle, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
uint32_t value = HAL_GetAnalogGyroCenter(m_gyroHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;
}
@@ -258,9 +258,9 @@ uint32_t AnalogGyro::GetCenter() const {
*/
void AnalogGyro::SetSensitivity(float voltsPerDegreePerSecond) {
int32_t status = 0;
setAnalogGyroVoltsPerDegreePerSecond(m_gyroHandle, voltsPerDegreePerSecond,
&status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_SetAnalogGyroVoltsPerDegreePerSecond(m_gyroHandle,
voltsPerDegreePerSecond, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -275,6 +275,6 @@ void AnalogGyro::SetSensitivity(float voltsPerDegreePerSecond) {
void AnalogGyro::SetDeadband(float volts) {
if (StatusIsFatal()) return;
int32_t status = 0;
setAnalogGyroDeadband(m_gyroHandle, volts, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_SetAnalogGyroDeadband(m_gyroHandle, volts, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}

View File

@@ -27,33 +27,33 @@ AnalogInput::AnalogInput(uint32_t channel) {
std::stringstream buf;
buf << "Analog Input " << channel;
if (!checkAnalogInputChannel(channel)) {
if (!HAL_CheckAnalogInputChannel(channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
return;
}
m_channel = channel;
HalPortHandle port = getPort(channel);
HAL_PortHandle port = HAL_GetPort(channel);
int32_t status = 0;
m_port = initializeAnalogInputPort(port, &status);
m_port = HAL_InitializeAnalogInputPort(port, &status);
if (status != 0) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
m_channel = std::numeric_limits<uint32_t>::max();
m_port = HAL_INVALID_HANDLE;
m_port = HAL_kInvalidHandle;
return;
}
LiveWindow::GetInstance()->AddSensor("AnalogInput", channel, this);
HALReport(HALUsageReporting::kResourceType_AnalogChannel, channel);
HAL_Report(HALUsageReporting::kResourceType_AnalogChannel, channel);
}
/**
* Channel destructor.
*/
AnalogInput::~AnalogInput() {
freeAnalogInputPort(m_port);
m_port = HAL_INVALID_HANDLE;
HAL_FreeAnalogInputPort(m_port);
m_port = HAL_kInvalidHandle;
}
/**
@@ -68,8 +68,8 @@ AnalogInput::~AnalogInput() {
int16_t AnalogInput::GetValue() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int16_t value = getAnalogValue(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
int16_t value = HAL_GetAnalogValue(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;
}
@@ -90,8 +90,8 @@ int16_t AnalogInput::GetValue() const {
int32_t AnalogInput::GetAverageValue() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int32_t value = getAnalogAverageValue(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
int32_t value = HAL_GetAnalogAverageValue(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;
}
@@ -106,8 +106,8 @@ int32_t AnalogInput::GetAverageValue() const {
float AnalogInput::GetVoltage() const {
if (StatusIsFatal()) return 0.0f;
int32_t status = 0;
float voltage = getAnalogVoltage(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
float voltage = HAL_GetAnalogVoltage(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return voltage;
}
@@ -128,8 +128,8 @@ float AnalogInput::GetVoltage() const {
float AnalogInput::GetAverageVoltage() const {
if (StatusIsFatal()) return 0.0f;
int32_t status = 0;
float voltage = getAnalogAverageVoltage(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
float voltage = HAL_GetAnalogAverageVoltage(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return voltage;
}
@@ -143,8 +143,8 @@ float AnalogInput::GetAverageVoltage() const {
uint32_t AnalogInput::GetLSBWeight() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int32_t lsbWeight = getAnalogLSBWeight(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
int32_t lsbWeight = HAL_GetAnalogLSBWeight(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return lsbWeight;
}
@@ -158,8 +158,8 @@ uint32_t AnalogInput::GetLSBWeight() const {
int32_t AnalogInput::GetOffset() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int32_t offset = getAnalogOffset(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
int32_t offset = HAL_GetAnalogOffset(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return offset;
}
@@ -187,8 +187,8 @@ uint32_t AnalogInput::GetChannel() const {
void AnalogInput::SetAverageBits(uint32_t bits) {
if (StatusIsFatal()) return;
int32_t status = 0;
setAnalogAverageBits(m_port, bits, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_SetAnalogAverageBits(m_port, bits, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -201,8 +201,8 @@ void AnalogInput::SetAverageBits(uint32_t bits) {
*/
uint32_t AnalogInput::GetAverageBits() const {
int32_t status = 0;
int32_t averageBits = getAnalogAverageBits(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
int32_t averageBits = HAL_GetAnalogAverageBits(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return averageBits;
}
@@ -219,8 +219,8 @@ uint32_t AnalogInput::GetAverageBits() const {
void AnalogInput::SetOversampleBits(uint32_t bits) {
if (StatusIsFatal()) return;
int32_t status = 0;
setAnalogOversampleBits(m_port, bits, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_SetAnalogOversampleBits(m_port, bits, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -235,8 +235,8 @@ void AnalogInput::SetOversampleBits(uint32_t bits) {
uint32_t AnalogInput::GetOversampleBits() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int32_t oversampleBits = getAnalogOversampleBits(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
int32_t oversampleBits = HAL_GetAnalogOversampleBits(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return oversampleBits;
}
@@ -248,8 +248,8 @@ uint32_t AnalogInput::GetOversampleBits() const {
bool AnalogInput::IsAccumulatorChannel() const {
if (StatusIsFatal()) return false;
int32_t status = 0;
bool isAccum = isAccumulatorChannel(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
bool isAccum = HAL_IsAccumulatorChannel(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return isAccum;
}
@@ -260,8 +260,8 @@ void AnalogInput::InitAccumulator() {
if (StatusIsFatal()) return;
m_accumulatorOffset = 0;
int32_t status = 0;
initAccumulator(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_InitAccumulator(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -283,8 +283,8 @@ void AnalogInput::SetAccumulatorInitialValue(int64_t initialValue) {
void AnalogInput::ResetAccumulator() {
if (StatusIsFatal()) return;
int32_t status = 0;
resetAccumulator(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_ResetAccumulator(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
if (!StatusIsFatal()) {
// Wait until the next sample, so the next call to GetAccumulator*()
@@ -310,8 +310,8 @@ void AnalogInput::ResetAccumulator() {
void AnalogInput::SetAccumulatorCenter(int32_t center) {
if (StatusIsFatal()) return;
int32_t status = 0;
setAccumulatorCenter(m_port, center, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_SetAccumulatorCenter(m_port, center, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -320,8 +320,8 @@ void AnalogInput::SetAccumulatorCenter(int32_t center) {
void AnalogInput::SetAccumulatorDeadband(int32_t deadband) {
if (StatusIsFatal()) return;
int32_t status = 0;
setAccumulatorDeadband(m_port, deadband, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_SetAccumulatorDeadband(m_port, deadband, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -335,8 +335,8 @@ void AnalogInput::SetAccumulatorDeadband(int32_t deadband) {
int64_t AnalogInput::GetAccumulatorValue() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int64_t value = getAccumulatorValue(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
int64_t value = HAL_GetAccumulatorValue(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value + m_accumulatorOffset;
}
@@ -351,8 +351,8 @@ int64_t AnalogInput::GetAccumulatorValue() const {
uint32_t AnalogInput::GetAccumulatorCount() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
uint32_t count = getAccumulatorCount(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
uint32_t count = HAL_GetAccumulatorCount(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return count;
}
@@ -368,8 +368,8 @@ uint32_t AnalogInput::GetAccumulatorCount() const {
void AnalogInput::GetAccumulatorOutput(int64_t& value, uint32_t& count) const {
if (StatusIsFatal()) return;
int32_t status = 0;
getAccumulatorOutput(m_port, &value, &count, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_GetAccumulatorOutput(m_port, &value, &count, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
value += m_accumulatorOffset;
}
@@ -383,8 +383,8 @@ void AnalogInput::GetAccumulatorOutput(int64_t& value, uint32_t& count) const {
*/
void AnalogInput::SetSampleRate(float samplesPerSecond) {
int32_t status = 0;
setAnalogSampleRate(samplesPerSecond, &status);
wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
HAL_SetAnalogSampleRate(samplesPerSecond, &status);
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -394,8 +394,8 @@ void AnalogInput::SetSampleRate(float samplesPerSecond) {
*/
float AnalogInput::GetSampleRate() {
int32_t status = 0;
float sampleRate = getAnalogSampleRate(&status);
wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
float sampleRate = HAL_GetAnalogSampleRate(&status);
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
return sampleRate;
}

View File

@@ -24,27 +24,27 @@ AnalogOutput::AnalogOutput(uint32_t channel) {
std::stringstream buf;
buf << "analog input " << channel;
if (!checkAnalogOutputChannel(channel)) {
if (!HAL_CheckAnalogOutputChannel(channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
m_channel = std::numeric_limits<uint32_t>::max();
m_port = HAL_INVALID_HANDLE;
m_port = HAL_kInvalidHandle;
return;
}
m_channel = channel;
HalPortHandle port = getPort(m_channel);
HAL_PortHandle port = HAL_GetPort(m_channel);
int32_t status = 0;
m_port = initializeAnalogOutputPort(port, &status);
m_port = HAL_InitializeAnalogOutputPort(port, &status);
if (status != 0) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
m_channel = std::numeric_limits<uint32_t>::max();
m_port = HAL_INVALID_HANDLE;
m_port = HAL_kInvalidHandle;
return;
}
LiveWindow::GetInstance()->AddActuator("AnalogOutput", m_channel, this);
HALReport(HALUsageReporting::kResourceType_AnalogOutput, m_channel);
HAL_Report(HALUsageReporting::kResourceType_AnalogOutput, m_channel);
}
/**
@@ -52,7 +52,7 @@ AnalogOutput::AnalogOutput(uint32_t channel) {
*
* Frees analog output resource.
*/
AnalogOutput::~AnalogOutput() { freeAnalogOutputPort(m_port); }
AnalogOutput::~AnalogOutput() { HAL_FreeAnalogOutputPort(m_port); }
/**
* Set the value of the analog output.
@@ -61,9 +61,9 @@ AnalogOutput::~AnalogOutput() { freeAnalogOutputPort(m_port); }
*/
void AnalogOutput::SetVoltage(float voltage) {
int32_t status = 0;
setAnalogOutput(m_port, voltage, &status);
HAL_SetAnalogOutput(m_port, voltage, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -73,9 +73,9 @@ void AnalogOutput::SetVoltage(float voltage) {
*/
float AnalogOutput::GetVoltage() const {
int32_t status = 0;
float voltage = getAnalogOutput(m_port, &status);
float voltage = HAL_GetAnalogOutput(m_port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return voltage;
}

View File

@@ -36,21 +36,21 @@ AnalogTrigger::AnalogTrigger(AnalogInput* input) {
m_analogInput = input;
int32_t status = 0;
uint32_t index = 0;
m_trigger = initializeAnalogTrigger(input->m_port, &index, &status);
m_trigger = HAL_InitializeAnalogTrigger(input->m_port, &index, &status);
if (status != 0) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
m_index = std::numeric_limits<uint8_t>::max();
m_trigger = HAL_INVALID_HANDLE;
m_trigger = HAL_kInvalidHandle;
return;
}
m_index = index;
HALReport(HALUsageReporting::kResourceType_AnalogTrigger, input->m_channel);
HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, input->m_channel);
}
AnalogTrigger::~AnalogTrigger() {
int32_t status = 0;
cleanAnalogTrigger(m_trigger, &status);
HAL_CleanAnalogTrigger(m_trigger, &status);
if (m_ownsAnalog && m_analogInput != nullptr) {
delete m_analogInput;
@@ -69,8 +69,8 @@ AnalogTrigger::~AnalogTrigger() {
void AnalogTrigger::SetLimitsRaw(int32_t lower, int32_t upper) {
if (StatusIsFatal()) return;
int32_t status = 0;
setAnalogTriggerLimitsRaw(m_trigger, lower, upper, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_SetAnalogTriggerLimitsRaw(m_trigger, lower, upper, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -84,8 +84,8 @@ void AnalogTrigger::SetLimitsRaw(int32_t lower, int32_t upper) {
void AnalogTrigger::SetLimitsVoltage(float lower, float upper) {
if (StatusIsFatal()) return;
int32_t status = 0;
setAnalogTriggerLimitsVoltage(m_trigger, lower, upper, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_SetAnalogTriggerLimitsVoltage(m_trigger, lower, upper, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -100,8 +100,8 @@ void AnalogTrigger::SetLimitsVoltage(float lower, float upper) {
void AnalogTrigger::SetAveraged(bool useAveragedValue) {
if (StatusIsFatal()) return;
int32_t status = 0;
setAnalogTriggerAveraged(m_trigger, useAveragedValue, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_SetAnalogTriggerAveraged(m_trigger, useAveragedValue, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -117,8 +117,8 @@ void AnalogTrigger::SetAveraged(bool useAveragedValue) {
void AnalogTrigger::SetFiltered(bool useFilteredValue) {
if (StatusIsFatal()) return;
int32_t status = 0;
setAnalogTriggerFiltered(m_trigger, useFilteredValue, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
HAL_SetAnalogTriggerFiltered(m_trigger, useFilteredValue, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -143,8 +143,8 @@ uint32_t AnalogTrigger::GetIndex() const {
bool AnalogTrigger::GetInWindow() {
if (StatusIsFatal()) return false;
int32_t status = 0;
bool result = getAnalogTriggerInWindow(m_trigger, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
bool result = HAL_GetAnalogTriggerInWindow(m_trigger, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return result;
}
@@ -161,8 +161,8 @@ bool AnalogTrigger::GetInWindow() {
bool AnalogTrigger::GetTriggerState() {
if (StatusIsFatal()) return false;
int32_t status = 0;
bool result = getAnalogTriggerTriggerState(m_trigger, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
bool result = HAL_GetAnalogTriggerTriggerState(m_trigger, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return result;
}

View File

@@ -24,16 +24,16 @@
AnalogTriggerOutput::AnalogTriggerOutput(const AnalogTrigger& trigger,
AnalogTriggerType outputType)
: m_trigger(trigger), m_outputType(outputType) {
HALReport(HALUsageReporting::kResourceType_AnalogTriggerOutput,
trigger.GetIndex(), outputType);
HAL_Report(HALUsageReporting::kResourceType_AnalogTriggerOutput,
trigger.GetIndex(), (uint8_t)outputType);
}
AnalogTriggerOutput::~AnalogTriggerOutput() {
if (m_interrupt != HAL_INVALID_HANDLE) {
if (m_interrupt != HAL_kInvalidHandle) {
int32_t status = 0;
cleanInterrupts(m_interrupt, &status);
HAL_CleanInterrupts(m_interrupt, &status);
// ignore status, as an invalid handle just needs to be ignored.
m_interrupt = HAL_INVALID_HANDLE;
m_interrupt = HAL_kInvalidHandle;
}
}
@@ -44,16 +44,16 @@ AnalogTriggerOutput::~AnalogTriggerOutput() {
*/
bool AnalogTriggerOutput::Get() const {
int32_t status = 0;
bool result =
getAnalogTriggerOutput(m_trigger.m_trigger, m_outputType, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
bool result = HAL_GetAnalogTriggerOutput(
m_trigger.m_trigger, (HAL_AnalogTriggerType)m_outputType, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return result;
}
/**
* @return The HAL Handle to the specified source.
*/
HalHandle AnalogTriggerOutput::GetPortHandleForRouting() const {
HAL_Handle AnalogTriggerOutput::GetPortHandleForRouting() const {
return m_trigger.m_trigger;
}

View File

@@ -18,8 +18,8 @@
BuiltInAccelerometer::BuiltInAccelerometer(Range range) {
SetRange(range);
HALReport(HALUsageReporting::kResourceType_Accelerometer, 0, 0,
"Built-in accelerometer");
HAL_Report(HALUsageReporting::kResourceType_Accelerometer, 0, 0,
"Built-in accelerometer");
LiveWindow::GetInstance()->AddSensor((std::string) "BuiltInAccel", 0, this);
}
@@ -29,25 +29,25 @@ void BuiltInAccelerometer::SetRange(Range range) {
ParameterOutOfRange, "16G range not supported (use k2G, k4G, or k8G)");
}
setAccelerometerActive(false);
setAccelerometerRange((AccelerometerRange)range);
setAccelerometerActive(true);
HAL_SetAccelerometerActive(false);
HAL_SetAccelerometerRange((HAL_AccelerometerRange)range);
HAL_SetAccelerometerActive(true);
}
/**
* @return The acceleration of the roboRIO along the X axis in g-forces
*/
double BuiltInAccelerometer::GetX() { return getAccelerometerX(); }
double BuiltInAccelerometer::GetX() { return HAL_GetAccelerometerX(); }
/**
* @return The acceleration of the roboRIO along the Y axis in g-forces
*/
double BuiltInAccelerometer::GetY() { return getAccelerometerY(); }
double BuiltInAccelerometer::GetY() { return HAL_GetAccelerometerY(); }
/**
* @return The acceleration of the roboRIO along the Z axis in g-forces
*/
double BuiltInAccelerometer::GetZ() { return getAccelerometerZ(); }
double BuiltInAccelerometer::GetZ() { return HAL_GetAccelerometerZ(); }
std::string BuiltInAccelerometer::GetSmartDashboardType() const {
return "3AxisAccelerometer";

View File

@@ -148,8 +148,8 @@ void CANJaguar::InitCANJaguar() {
default:
break;
}
HALReport(HALUsageReporting::kResourceType_CANJaguar, m_deviceNumber,
m_controlMode);
HAL_Report(HALUsageReporting::kResourceType_CANJaguar, m_deviceNumber,
m_controlMode);
LiveWindow::GetInstance()->AddActuator("CANJaguar", m_deviceNumber, this);
}
@@ -1566,8 +1566,8 @@ void CANJaguar::SetControlMode(ControlMode controlMode) {
m_controlMode = controlMode;
m_controlModeVerified = false;
HALReport(HALUsageReporting::kResourceType_CANJaguar, m_deviceNumber,
m_controlMode);
HAL_Report(HALUsageReporting::kResourceType_CANJaguar, m_deviceNumber,
m_controlMode);
}
/**

View File

@@ -186,13 +186,13 @@ void CANTalon::Set(float value) {
break;
}
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
status = m_impl->SetModeSelect(m_sendMode);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
}
@@ -250,7 +250,7 @@ bool CANTalon::IsEnabled() const { return IsControlEnabled(); }
void CANTalon::SetP(double p) {
CTR_Code status = m_impl->SetPgain(m_profile, p);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -263,7 +263,7 @@ void CANTalon::SetP(double p) {
void CANTalon::SetI(double i) {
CTR_Code status = m_impl->SetIgain(m_profile, i);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -276,7 +276,7 @@ void CANTalon::SetI(double i) {
void CANTalon::SetD(double d) {
CTR_Code status = m_impl->SetDgain(m_profile, d);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -289,7 +289,7 @@ void CANTalon::SetD(double d) {
void CANTalon::SetF(double f) {
CTR_Code status = m_impl->SetFgain(m_profile, f);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -302,7 +302,7 @@ void CANTalon::SetF(double f) {
void CANTalon::SetIzone(unsigned iz) {
CTR_Code status = m_impl->SetIzone(m_profile, iz);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -314,7 +314,7 @@ void CANTalon::SelectProfileSlot(int slotIdx) {
m_profile = (slotIdx == 0) ? 0 : 1; /* only get two slots for now */
CTR_Code status = m_impl->SetProfileSlotSelect(m_profile);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -360,7 +360,7 @@ void CANTalon::SetFeedbackDevice(FeedbackDevice feedbackDevice) {
/* pass feedback to actual CAN frame */
CTR_Code status = m_impl->SetFeedbackDeviceSelect((int)feedbackDevice);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -370,7 +370,7 @@ void CANTalon::SetFeedbackDevice(FeedbackDevice feedbackDevice) {
void CANTalon::SetStatusFrameRateMs(StatusFrameRate stateFrame, int periodMs) {
CTR_Code status = m_impl->SetStatusFrameRate((int)stateFrame, periodMs);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -386,7 +386,7 @@ double CANTalon::GetP() const {
// Update the info in m_impl.
CTR_Code status = m_impl->RequestParam(param);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
// small yield for getting response
std::this_thread::sleep_for(
@@ -394,7 +394,7 @@ double CANTalon::GetP() const {
double p;
status = m_impl->GetPgain(m_profile, p);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return p;
}
@@ -409,7 +409,7 @@ double CANTalon::GetI() const {
// Update the info in m_impl.
CTR_Code status = m_impl->RequestParam(param);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
// small yield for getting response
std::this_thread::sleep_for(
@@ -418,7 +418,7 @@ double CANTalon::GetI() const {
double i;
status = m_impl->GetIgain(m_profile, i);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return i;
}
@@ -433,7 +433,7 @@ double CANTalon::GetD() const {
// Update the info in m_impl.
CTR_Code status = m_impl->RequestParam(param);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
// small yield for getting response
std::this_thread::sleep_for(
@@ -441,7 +441,7 @@ double CANTalon::GetD() const {
double d;
status = m_impl->GetDgain(m_profile, d);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return d;
}
@@ -456,7 +456,7 @@ double CANTalon::GetF() const {
// Update the info in m_impl.
CTR_Code status = m_impl->RequestParam(param);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
// small yield for getting response
@@ -465,7 +465,7 @@ double CANTalon::GetF() const {
double f;
status = m_impl->GetFgain(m_profile, f);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return f;
}
@@ -480,7 +480,7 @@ int CANTalon::GetIzone() const {
// Update the info in m_impl.
CTR_Code status = m_impl->RequestParam(param);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
std::this_thread::sleep_for(
std::chrono::microseconds(kDelayForSolicitedSignalsUs));
@@ -488,7 +488,7 @@ int CANTalon::GetIzone() const {
int iz;
status = m_impl->GetIzone(m_profile, iz);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return iz;
}
@@ -507,7 +507,7 @@ float CANTalon::GetBusVoltage() const {
double voltage;
CTR_Code status = m_impl->GetBatteryV(voltage);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return voltage;
}
@@ -520,7 +520,7 @@ float CANTalon::GetOutputVoltage() const {
CTR_Code status = m_impl->GetAppliedThrottle(throttle11);
float voltage = GetBusVoltage() * (float(throttle11) / 1023.0);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return voltage;
}
@@ -533,7 +533,7 @@ float CANTalon::GetOutputCurrent() const {
CTR_Code status = m_impl->GetCurrent(current);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return current;
@@ -547,7 +547,7 @@ float CANTalon::GetTemperature() const {
CTR_Code status = m_impl->GetTemp(temp);
if (temp != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return temp;
}
@@ -563,7 +563,7 @@ void CANTalon::SetPosition(double pos) {
int32_t nativePos = ScaleRotationsToNativeUnits(m_feedbackDevice, pos);
CTR_Code status = m_impl->SetSensorPosition(nativePos);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -581,7 +581,7 @@ double CANTalon::GetPosition() const {
int32_t position;
CTR_Code status = m_impl->GetSensorPosition(position);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return ScaleNativeUnitsToRotations(m_feedbackDevice, position);
}
@@ -594,7 +594,7 @@ double CANTalon::GetPosition() const {
void CANTalon::SetSensorDirection(bool reverseSensor) {
CTR_Code status = m_impl->SetRevFeedbackSensor(reverseSensor ? 1 : 0);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -612,7 +612,7 @@ void CANTalon::SetSensorDirection(bool reverseSensor) {
void CANTalon::SetClosedLoopOutputDirection(bool reverseOutput) {
CTR_Code status = m_impl->SetRevMotDuringCloseLoopEn(reverseOutput ? 1 : 0);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -626,7 +626,7 @@ int CANTalon::GetClosedLoopError() const {
/* retrieve the closed loop error in native units */
CTR_Code status = m_impl->GetCloseLoopErr(error);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return error;
}
@@ -670,7 +670,7 @@ double CANTalon::GetSpeed() const {
int32_t speed;
CTR_Code status = m_impl->GetSensorVelocity(speed);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return ScaleNativeUnitsToRpm(m_feedbackDevice, speed);
}
@@ -687,7 +687,7 @@ int CANTalon::GetAnalogIn() const {
int position;
CTR_Code status = m_impl->GetAnalogInWithOv(position);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return position;
}
@@ -695,7 +695,7 @@ int CANTalon::GetAnalogIn() const {
void CANTalon::SetAnalogPosition(int newPosition) {
CTR_Code status = m_impl->SetParam(CanTalonSRX::eAinPosition, newPosition);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -717,7 +717,7 @@ int CANTalon::GetAnalogInVel() const {
int vel;
CTR_Code status = m_impl->GetAnalogInVel(vel);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return vel;
}
@@ -732,14 +732,14 @@ int CANTalon::GetEncPosition() const {
int position;
CTR_Code status = m_impl->GetEncPosition(position);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return position;
}
void CANTalon::SetEncPosition(int newPosition) {
CTR_Code status = m_impl->SetParam(CanTalonSRX::eEncPosition, newPosition);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -753,7 +753,7 @@ int CANTalon::GetEncVel() const {
int vel;
CTR_Code status = m_impl->GetEncVel(vel);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return vel;
}
@@ -761,34 +761,34 @@ int CANTalon::GetPulseWidthPosition() const {
int param;
CTR_Code status = m_impl->GetPulseWidthPosition(param);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return param;
}
void CANTalon::SetPulseWidthPosition(int newPosition) {
CTR_Code status = m_impl->SetParam(CanTalonSRX::ePwdPosition, newPosition);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
int CANTalon::GetPulseWidthVelocity() const {
int param;
CTR_Code status = m_impl->GetPulseWidthVelocity(param);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return param;
}
int CANTalon::GetPulseWidthRiseToFallUs() const {
int param;
CTR_Code status = m_impl->GetPulseWidthRiseToFallUs(param);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return param;
}
int CANTalon::GetPulseWidthRiseToRiseUs() const {
int param;
CTR_Code status = m_impl->GetPulseWidthRiseToRiseUs(param);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return param;
}
@@ -840,7 +840,7 @@ int CANTalon::GetPinStateQuadA() const {
int retval;
CTR_Code status = m_impl->GetQuadApin(retval);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return retval;
}
@@ -852,7 +852,7 @@ int CANTalon::GetPinStateQuadB() const {
int retval;
CTR_Code status = m_impl->GetQuadBpin(retval);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return retval;
}
@@ -864,7 +864,7 @@ int CANTalon::GetPinStateQuadIdx() const {
int retval;
CTR_Code status = m_impl->GetQuadIdxpin(retval);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return retval;
}
@@ -878,7 +878,7 @@ int CANTalon::IsFwdLimitSwitchClosed() const {
CTR_Code status = m_impl->GetLimitSwitchClosedFor(
retval); /* rename this func, '1' => open, '0' => closed */
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return retval ? 0 : 1;
}
@@ -892,7 +892,7 @@ int CANTalon::IsRevLimitSwitchClosed() const {
CTR_Code status = m_impl->GetLimitSwitchClosedRev(
retval); /* rename this func, '1' => open, '0' => closed */
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return retval ? 0 : 1;
}
@@ -906,7 +906,7 @@ int CANTalon::GetNumberOfQuadIdxRises() const {
CTR_Code status = m_impl->GetEncIndexRiseEvents(
rises); /* rename this func, '1' => open, '0' => closed */
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return rises;
}
@@ -920,7 +920,7 @@ void CANTalon::SetNumberOfQuadIdxRises(int rises) {
CanTalonSRX::eEncIndexRiseEvents,
rises); /* rename this func, '1' => open, '0' => closed */
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -933,11 +933,11 @@ bool CANTalon::GetForwardLimitOK() const {
CTR_Code status = CTR_OKAY;
status = m_impl->GetFault_ForSoftLim(softLim);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
status = m_impl->GetFault_ForLim(limSwit);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/* If either fault is asserted, signal caller we are disabled (with false?) */
return (softLim | limSwit) ? false : true;
@@ -952,11 +952,11 @@ bool CANTalon::GetReverseLimitOK() const {
CTR_Code status = CTR_OKAY;
status = m_impl->GetFault_RevSoftLim(softLim);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
status = m_impl->GetFault_RevLim(limSwit);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/* If either fault is asserted, signal caller we are disabled (with false?) */
return (softLim | limSwit) ? false : true;
@@ -974,42 +974,42 @@ uint16_t CANTalon::GetFaults() const {
val = 0;
status = m_impl->GetFault_OverTemp(val);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval |= (val) ? CANSpeedController::kTemperatureFault : 0;
/* voltage */
val = 0;
status = m_impl->GetFault_UnderVoltage(val);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval |= (val) ? CANSpeedController::kBusVoltageFault : 0;
/* fwd-limit-switch */
val = 0;
status = m_impl->GetFault_ForLim(val);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval |= (val) ? CANSpeedController::kFwdLimitSwitch : 0;
/* rev-limit-switch */
val = 0;
status = m_impl->GetFault_RevLim(val);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval |= (val) ? CANSpeedController::kRevLimitSwitch : 0;
/* fwd-soft-limit */
val = 0;
status = m_impl->GetFault_ForSoftLim(val);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval |= (val) ? CANSpeedController::kFwdSoftLimit : 0;
/* rev-soft-limit */
val = 0;
status = m_impl->GetFault_RevSoftLim(val);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval |= (val) ? CANSpeedController::kRevSoftLimit : 0;
return retval;
@@ -1024,42 +1024,42 @@ uint16_t CANTalon::GetStickyFaults() const {
val = 0;
status = m_impl->GetStckyFault_OverTemp(val);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval |= (val) ? CANSpeedController::kTemperatureFault : 0;
/* voltage */
val = 0;
status = m_impl->GetStckyFault_UnderVoltage(val);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval |= (val) ? CANSpeedController::kBusVoltageFault : 0;
/* fwd-limit-switch */
val = 0;
status = m_impl->GetStckyFault_ForLim(val);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval |= (val) ? CANSpeedController::kFwdLimitSwitch : 0;
/* rev-limit-switch */
val = 0;
status = m_impl->GetStckyFault_RevLim(val);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval |= (val) ? CANSpeedController::kRevLimitSwitch : 0;
/* fwd-soft-limit */
val = 0;
status = m_impl->GetStckyFault_ForSoftLim(val);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval |= (val) ? CANSpeedController::kFwdSoftLimit : 0;
/* rev-soft-limit */
val = 0;
status = m_impl->GetStckyFault_RevSoftLim(val);
if (status != CTR_OKAY)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval |= (val) ? CANSpeedController::kRevSoftLimit : 0;
return retval;
@@ -1067,7 +1067,7 @@ uint16_t CANTalon::GetStickyFaults() const {
void CANTalon::ClearStickyFaults() {
CTR_Code status = m_impl->ClearStickyFaults();
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
@@ -1088,7 +1088,7 @@ void CANTalon::SetVoltageRampRate(double rampRate) {
double rampRatedThrotPer10ms = (rampRate * 1023.0 / 12.0) / 100;
CTR_Code status = m_impl->SetRampThrottle((int)rampRatedThrotPer10ms);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1098,7 +1098,7 @@ void CANTalon::SetVoltageCompensationRampRate(double rampRate) {
CTR_Code status = CTR_OKAY;
status = m_impl->SetVoltageCompensationRate(rampRate / 1000);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1114,7 +1114,7 @@ void CANTalon::SetCloseLoopRampRate(double rampRate) {
CTR_Code status = m_impl->SetCloseLoopRampRate(
m_profile, rampRate * 1023.0 / 12.0 / 1000.0);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1125,20 +1125,20 @@ uint32_t CANTalon::GetFirmwareVersion() const {
int firmwareVersion;
CTR_Code status = m_impl->RequestParam(CanTalonSRX::eFirmVers);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
std::this_thread::sleep_for(
std::chrono::microseconds(kDelayForSolicitedSignalsUs));
status =
m_impl->GetParamResponseInt32(CanTalonSRX::eFirmVers, firmwareVersion);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/* only sent once on boot */
// CTR_Code status = m_impl->GetFirmVers(firmwareVersion);
// if (status != CTR_OKAY) {
// wpi_setErrorWithContext(status, getHALErrorMessage(status));
// wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
//}
return firmwareVersion;
@@ -1150,7 +1150,7 @@ uint32_t CANTalon::GetFirmwareVersion() const {
int CANTalon::GetIaccum() const {
CTR_Code status = m_impl->RequestParam(CanTalonSRX::ePidIaccum);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
// small yield for getting response
std::this_thread::sleep_for(
@@ -1158,7 +1158,7 @@ int CANTalon::GetIaccum() const {
int iaccum;
status = m_impl->GetParamResponseInt32(CanTalonSRX::ePidIaccum, iaccum);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return iaccum;
}
@@ -1169,7 +1169,7 @@ int CANTalon::GetIaccum() const {
void CANTalon::ClearIaccum() {
CTR_Code status = m_impl->SetParam(CanTalonSRX::ePidIaccum, 0);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1195,7 +1195,7 @@ void CANTalon::ConfigNeutralMode(NeutralMode mode) {
break;
}
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1207,7 +1207,7 @@ int CANTalon::GetBrakeEnableDuringNeutral() const {
int brakeEn = 0;
CTR_Code status = m_impl->GetBrakeIsEnabled(brakeEn);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
return brakeEn;
}
@@ -1299,7 +1299,7 @@ void CANTalon::ConfigLimitSwitchOverrides(bool bForwardLimitSwitchEn,
/* update signal and error check code */
status = m_impl->SetOverrideLimitSwitchEn(fwdRevEnable);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1315,17 +1315,17 @@ void CANTalon::ConfigLimitMode(LimitMode mode) {
* limit switch.*/
status = m_impl->SetForwardSoftEnable(false);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
status = m_impl->SetReverseSoftEnable(false);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/* override enable the limit switches, this circumvents the webdash */
status = m_impl->SetOverrideLimitSwitchEn(
CanTalonSRX::kLimitSwitchOverride_EnableFwd_EnableRev);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
break;
case kLimitMode_SoftPositionLimits: /** Use both switches and soft limits */
@@ -1333,17 +1333,17 @@ void CANTalon::ConfigLimitMode(LimitMode mode) {
* limit switch.*/
status = m_impl->SetForwardSoftEnable(true);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
status = m_impl->SetReverseSoftEnable(true);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/* override enable the limit switches, this circumvents the webdash */
status = m_impl->SetOverrideLimitSwitchEn(
CanTalonSRX::kLimitSwitchOverride_EnableFwd_EnableRev);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
break;
@@ -1353,17 +1353,17 @@ void CANTalon::ConfigLimitMode(LimitMode mode) {
* limit switch.*/
status = m_impl->SetForwardSoftEnable(false);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
status = m_impl->SetReverseSoftEnable(false);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/* override enable the limit switches, this circumvents the webdash */
status = m_impl->SetOverrideLimitSwitchEn(
CanTalonSRX::kLimitSwitchOverride_DisableFwd_DisableRev);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
break;
}
@@ -1378,7 +1378,7 @@ void CANTalon::ConfigForwardLimit(double forwardLimitPosition) {
ScaleRotationsToNativeUnits(m_feedbackDevice, forwardLimitPosition);
status = m_impl->SetForwardSoftLimit(nativeLimitPos);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1393,7 +1393,7 @@ void CANTalon::ConfigForwardSoftLimitEnable(bool bForwardSoftLimitEn) {
CTR_Code status = CTR_OKAY;
status = m_impl->SetForwardSoftEnable(bForwardSoftLimitEn);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1408,7 +1408,7 @@ void CANTalon::ConfigReverseSoftLimitEnable(bool bReverseSoftLimitEn) {
CTR_Code status = CTR_OKAY;
status = m_impl->SetReverseSoftEnable(bReverseSoftLimitEn);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1427,7 +1427,7 @@ void CANTalon::ConfigFwdLimitSwitchNormallyOpen(bool normallyOpen) {
m_impl->SetParam(CanTalonSRX::eOnBoot_LimitSwitch_Forward_NormallyClosed,
normallyOpen ? 0 : 1);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1446,7 +1446,7 @@ void CANTalon::ConfigRevLimitSwitchNormallyOpen(bool normallyOpen) {
m_impl->SetParam(CanTalonSRX::eOnBoot_LimitSwitch_Reverse_NormallyClosed,
normallyOpen ? 0 : 1);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1459,7 +1459,7 @@ void CANTalon::ConfigReverseLimit(double reverseLimitPosition) {
ScaleRotationsToNativeUnits(m_feedbackDevice, reverseLimitPosition);
status = m_impl->SetReverseSoftLimit(nativeLimitPos);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1515,7 +1515,7 @@ void CANTalon::ConfigSetParameter(uint32_t paramEnum, double value) {
/* config peak throttle when in closed-loop mode in the positive direction. */
status = m_impl->SetParam((CanTalonSRX::param_t)paramEnum, value);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1528,7 +1528,7 @@ bool CANTalon::GetParameter(uint32_t paramEnum, double& dvalue) const {
/* send the request frame */
CTR_Code status = m_impl->RequestParam((CanTalonSRX::param_t)paramEnum);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval = false;
}
/* small yield for getting response */
@@ -1537,7 +1537,7 @@ bool CANTalon::GetParameter(uint32_t paramEnum, double& dvalue) const {
/* get the last received update */
status = m_impl->GetParamResponse((CanTalonSRX::param_t)paramEnum, dvalue);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
retval = false;
}
return retval;
@@ -1560,8 +1560,8 @@ void CANTalon::ConfigFaultTime(float faultTime) {
*/
void CANTalon::ApplyControlMode(CANSpeedController::ControlMode mode) {
m_controlMode = mode;
HALReport(HALUsageReporting::kResourceType_CANTalonSRX, m_deviceNumber + 1,
mode);
HAL_Report(HALUsageReporting::kResourceType_CANTalonSRX, m_deviceNumber + 1,
mode);
switch (mode) {
case kPercentVbus:
m_sendMode = kThrottle;
@@ -1588,7 +1588,7 @@ void CANTalon::ApplyControlMode(CANSpeedController::ControlMode mode) {
// Keep the talon disabled until Set() is called.
CTR_Code status = m_impl->SetModeSelect((int)kDisabled);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}
@@ -1723,7 +1723,7 @@ double CANTalon::GetNativeUnitsPerRotationScalar(
}
/* handle any detected errors */
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/* if scaling information is not possible, signal caller
* by returning zero
@@ -1979,7 +1979,7 @@ void CANTalon::GetMotionProfileStatus(
0; /* this signal is only used sending pts to Talon */
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
}

View File

@@ -14,9 +14,9 @@
*/
Compressor::Compressor(uint8_t pcmID) {
int32_t status = 0;
m_compressorHandle = initializeCompressor(pcmID, &status);
m_compressorHandle = HAL_InitializeCompressor(pcmID, &status);
if (status != 0) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return;
}
SetClosedLoopControl(true);
@@ -50,7 +50,7 @@ bool Compressor::Enabled() const {
int32_t status = 0;
bool value;
value = getCompressor(m_compressorHandle, &status);
value = HAL_GetCompressor(m_compressorHandle, &status);
if (status) {
wpi_setWPIError(Timeout);
@@ -69,7 +69,7 @@ bool Compressor::GetPressureSwitchValue() const {
int32_t status = 0;
bool value;
value = getPressureSwitch(m_compressorHandle, &status);
value = HAL_GetPressureSwitch(m_compressorHandle, &status);
if (status) {
wpi_setWPIError(Timeout);
@@ -88,7 +88,7 @@ float Compressor::GetCompressorCurrent() const {
int32_t status = 0;
float value;
value = getCompressorCurrent(m_compressorHandle, &status);
value = HAL_GetCompressorCurrent(m_compressorHandle, &status);
if (status) {
wpi_setWPIError(Timeout);
@@ -108,7 +108,7 @@ void Compressor::SetClosedLoopControl(bool on) {
if (StatusIsFatal()) return;
int32_t status = 0;
setClosedLoopControl(m_compressorHandle, on, &status);
HAL_SetClosedLoopControl(m_compressorHandle, on, &status);
if (status) {
wpi_setWPIError(Timeout);
@@ -127,7 +127,7 @@ bool Compressor::GetClosedLoopControl() const {
int32_t status = 0;
bool value;
value = getClosedLoopControl(m_compressorHandle, &status);
value = HAL_GetClosedLoopControl(m_compressorHandle, &status);
if (status) {
wpi_setWPIError(Timeout);
@@ -147,7 +147,7 @@ bool Compressor::GetCompressorCurrentTooHighFault() const {
int32_t status = 0;
bool value;
value = getCompressorCurrentTooHighFault(m_compressorHandle, &status);
value = HAL_GetCompressorCurrentTooHighFault(m_compressorHandle, &status);
if (status) {
wpi_setWPIError(Timeout);
@@ -171,7 +171,8 @@ bool Compressor::GetCompressorCurrentTooHighStickyFault() const {
int32_t status = 0;
bool value;
value = getCompressorCurrentTooHighStickyFault(m_compressorHandle, &status);
value =
HAL_GetCompressorCurrentTooHighStickyFault(m_compressorHandle, &status);
if (status) {
wpi_setWPIError(Timeout);
@@ -195,7 +196,7 @@ bool Compressor::GetCompressorShortedStickyFault() const {
int32_t status = 0;
bool value;
value = getCompressorShortedStickyFault(m_compressorHandle, &status);
value = HAL_GetCompressorShortedStickyFault(m_compressorHandle, &status);
if (status) {
wpi_setWPIError(Timeout);
@@ -215,7 +216,7 @@ bool Compressor::GetCompressorShortedFault() const {
int32_t status = 0;
bool value;
value = getCompressorShortedFault(m_compressorHandle, &status);
value = HAL_GetCompressorShortedFault(m_compressorHandle, &status);
if (status) {
wpi_setWPIError(Timeout);
@@ -238,7 +239,7 @@ bool Compressor::GetCompressorNotConnectedStickyFault() const {
int32_t status = 0;
bool value;
value = getCompressorNotConnectedStickyFault(m_compressorHandle, &status);
value = HAL_GetCompressorNotConnectedStickyFault(m_compressorHandle, &status);
if (status) {
wpi_setWPIError(Timeout);
@@ -258,7 +259,7 @@ bool Compressor::GetCompressorNotConnectedFault() const {
int32_t status = 0;
bool value;
value = getCompressorNotConnectedFault(m_compressorHandle, &status);
value = HAL_GetCompressorNotConnectedFault(m_compressorHandle, &status);
if (status) {
wpi_setWPIError(Timeout);
@@ -281,7 +282,7 @@ void Compressor::ClearAllPCMStickyFaults() {
if (StatusIsFatal()) return;
int32_t status = 0;
clearAllPCMStickyFaults(m_compressorHandle, &status);
HAL_ClearAllPCMStickyFaults(m_compressorHandle, &status);
if (status) {
wpi_setWPIError(Timeout);

Some files were not shown because too many files have changed in this diff Show More