Moved C++ comments from source files to headers (#1111)

Also sorted functions in C++ sources to match order in related headers.
This commit is contained in:
Tyler Veness
2018-05-31 20:47:15 -07:00
committed by Peter Johnson
parent d9971a705a
commit 8c680a26f8
234 changed files with 9936 additions and 9309 deletions

View File

@@ -198,10 +198,6 @@ static double unpackAxis(int16_t raw) {
extern "C" {
/**
* Set the accelerometer to active or standby mode. It must be in standby
* mode to change any configuration.
*/
void HAL_SetAccelerometerActive(HAL_Bool active) {
initializeAccelerometer();
@@ -210,10 +206,6 @@ void HAL_SetAccelerometerActive(HAL_Bool active) {
writeRegister(kReg_CtrlReg1, ctrlReg1 | (active ? 1 : 0));
}
/**
* 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 HAL_SetAccelerometerRange(HAL_AccelerometerRange range) {
initializeAccelerometer();
@@ -224,11 +216,6 @@ void HAL_SetAccelerometerRange(HAL_AccelerometerRange range) {
writeRegister(kReg_XYZDataCfg, xyzDataCfg | range);
}
/**
* Get the x-axis acceleration
*
* This is a floating point value in units of 1 g-force
*/
double HAL_GetAccelerometerX(void) {
initializeAccelerometer();
@@ -237,11 +224,6 @@ double HAL_GetAccelerometerX(void) {
return unpackAxis(raw);
}
/**
* Get the y-axis acceleration
*
* This is a floating point value in units of 1 g-force
*/
double HAL_GetAccelerometerY(void) {
initializeAccelerometer();
@@ -250,11 +232,6 @@ double HAL_GetAccelerometerY(void) {
return unpackAxis(raw);
}
/**
* Get the z-axis acceleration
*
* This is a floating point value in units of 1 g-force
*/
double HAL_GetAccelerometerZ(void) {
initializeAccelerometer();

View File

@@ -20,12 +20,6 @@ void InitializeAnalogAccumulator() {}
extern "C" {
/**
* Is the channel attached to an accumulator.
*
* @param analogPortHandle Handle to the analog port.
* @return The analog channel is attached to an accumulator.
*/
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
@@ -39,11 +33,6 @@ HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle,
return false;
}
/**
* Initialize the accumulator.
*
* @param analogPortHandle Handle to the analog port.
*/
void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
if (!HAL_IsAccumulatorChannel(analogPortHandle, status)) {
@@ -54,11 +43,6 @@ void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle,
HAL_ResetAccumulator(analogPortHandle, status);
}
/**
* Resets the accumulator to the initial value.
*
* @param analogPortHandle Handle to the analog port.
*/
void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
@@ -73,21 +57,6 @@ void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
port->accumulator->strobeReset(status);
}
/**
* Set the center value of the accumulator.
*
* The center value is subtracted from each A/D value before it is added to the
* accumulator. This is used for the center value of devices like gyros and
* accelerometers to make integration work and to take the device offset into
* account when integrating.
*
* This center value is based on the output of the oversampled and averaged
* source from channel 1. Because of this, any non-zero oversample bits will
* affect the size of the value for this field.
*
* @param analogPortHandle Handle to the analog port.
* @param center The center value of the accumulator.
*/
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
int32_t center, int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
@@ -102,12 +71,6 @@ void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
port->accumulator->writeCenter(center, status);
}
/**
* Set the accumulator's deadband.
*
* @param analogPortHandle Handle to the analog port.
* @param deadband The deadband of the accumulator.
*/
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
int32_t deadband, int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
@@ -122,15 +85,6 @@ void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
port->accumulator->writeDeadband(deadband, status);
}
/**
* Read the accumulated value.
*
* Read the value that has been accumulating on channel 1.
* The accumulator is attached after the oversample and average engine.
*
* @param analogPortHandle Handle to the analog port.
* @return The 64-bit value accumulated since the last Reset().
*/
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
@@ -146,15 +100,6 @@ int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
return value;
}
/**
* Read the number of accumulated values.
*
* Read the count of the accumulated values since the accumulator was last
* Reset().
*
* @param analogPortHandle Handle to the analog port.
* @return The number of times samples from the channel were accumulated.
*/
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
@@ -169,16 +114,6 @@ int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
return port->accumulator->readOutput_Count(status);
}
/**
* Read the accumulated value and the number of accumulated values atomically.
*
* This function reads the value and count from the FPGA atomically.
* This can be used for averaging.
*
* @param analogPortHandle Handle to the analog port.
* @param value Pointer to the 64-bit accumulated output.
* @param count Pointer to the number of accumulation cycles.
*/
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle,
int64_t* value, int64_t* count, int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);

View File

@@ -27,11 +27,6 @@ using namespace hal;
extern "C" {
/**
* Initialize the analog input port using the given port object.
*
* @param portHandle Handle to the port to initialize.
*/
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle,
int32_t* status) {
hal::init::CheckInit();
@@ -70,41 +65,17 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle,
return handle;
}
/**
* @param analogPortHandle Handle to the analog port.
*/
void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle) {
// no status, so no need to check for a proper free.
analogInputHandles->Free(analogPortHandle);
}
/**
* Check that the analog module number is valid.
*
* @param module The analog module number.
* @return Analog module is valid and present
*/
HAL_Bool HAL_CheckAnalogModule(int32_t module) { return module == 1; }
/**
* Check that the analog output channel number is value.
* Verify that the analog channel number is one of the legal channel numbers.
* Channel numbers are 0-based.
*
* @param channel The analog output channel number.
* @return Analog channel is valid
*/
HAL_Bool HAL_CheckAnalogInputChannel(int32_t channel) {
return channel < kNumAnalogInputs && channel >= 0;
}
/**
* Set the sample rate.
*
* This is a global setting for the Athena and effects all channels.
*
* @param samplesPerSecond The number of samples per channel per second.
*/
void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status) {
// TODO: This will change when variable size scan lists are implemented.
// TODO: Need double comparison with epsilon.
@@ -114,14 +85,6 @@ void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status) {
setAnalogSampleRate(samplesPerSecond, status);
}
/**
* Get the current sample rate.
*
* This assumes one entry in the scan list.
* This is a global setting for the Athena and effects all channels.
*
* @return Sample rate.
*/
double HAL_GetAnalogSampleRate(int32_t* status) {
initializeAnalog(status);
if (*status != 0) return 0;
@@ -131,16 +94,6 @@ double HAL_GetAnalogSampleRate(int32_t* status) {
return static_cast<double>(kTimebase) / static_cast<double>(ticksPerSample);
}
/**
* Set the number of averaging bits.
*
* This sets the number of averaging bits. The actual number of averaged samples
* is 2**bits. Use averaging to improve the stability of your measurement at the
* expense of sampling rate. The averaging is done automatically in the FPGA.
*
* @param analogPortHandle Handle to the analog port to configure.
* @param bits Number of bits to average.
*/
void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
int32_t bits, int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
@@ -152,15 +105,6 @@ void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
status);
}
/**
* Get the number of averaging bits.
*
* This gets the number of averaging bits from the FPGA. The actual number of
* averaged samples is 2**bits. The averaging is done automatically in the FPGA.
*
* @param analogPortHandle Handle to the analog port to use.
* @return Bits to average.
*/
int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
@@ -172,17 +116,6 @@ int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
return result;
}
/**
* Set the number of oversample bits.
*
* This sets the number of oversample bits. The actual number of oversampled
* values is 2**bits. Use oversampling to improve the resolution of your
* measurements at the expense of sampling rate. The oversampling is done
* automatically in the FPGA.
*
* @param analogPortHandle Handle to the analog port to use.
* @param bits Number of bits to oversample.
*/
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
int32_t bits, int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
@@ -194,16 +127,6 @@ void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
static_cast<uint8_t>(bits), status);
}
/**
* Get the number of oversample bits.
*
* This gets the number of oversample bits from the FPGA. The actual number of
* oversampled values is 2**bits. The oversampling is done automatically in the
* FPGA.
*
* @param analogPortHandle Handle to the analog port to use.
* @return Bits to oversample.
*/
int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
@@ -215,16 +138,6 @@ int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
return result;
}
/**
* Get a sample straight from the channel on this module.
*
* The sample is a 12-bit value representing the 0V to 5V range of the A/D
* converter in the module. The units are in A/D converter codes. Use
* GetVoltage() to get the analog value in calibrated units.
*
* @param analogPortHandle Handle to the analog port to use.
* @return A sample straight from the channel on this module.
*/
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
@@ -243,20 +156,6 @@ int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
return static_cast<int16_t>(analogInputSystem->readOutput(status));
}
/**
* Get a sample from the output of the oversample and average engine for the
* channel.
*
* The sample is 12-bit + the value configured in SetOversampleBits().
* The value configured in SetAverageBits() will cause this value to be averaged
* 2**bits number of samples. This is not a sliding window. The sample will not
* change until 2**(OversamplBits + AverageBits) samples have been acquired from
* the module on this channel. Use GetAverageVoltage() to get the analog value
* in calibrated units.
*
* @param analogPortHandle Handle to the analog port to use.
* @return A sample from the oversample and average engine for the channel.
*/
int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
@@ -274,62 +173,6 @@ int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle,
return static_cast<int32_t>(analogInputSystem->readOutput(status));
}
/**
* Get a scaled sample straight from the channel on this module.
*
* The value is scaled to units of Volts using the calibrated scaling data from
* GetLSBWeight() and GetOffset().
*
* @param analogPortHandle Handle to the analog port to use.
* @return A scaled sample straight from the channel on this module.
*/
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
int32_t value = HAL_GetAnalogValue(analogPortHandle, status);
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status);
int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status);
double voltage = LSBWeight * 1.0e-9 * value - offset * 1.0e-9;
return voltage;
}
/**
* Get a scaled sample from the output of the oversample and average engine for
* the channel.
*
* The value is scaled to units of Volts using the calibrated scaling data from
* GetLSBWeight() and GetOffset(). Using oversampling will cause this value to
* be higher resolution, but it will update more slowly. Using averaging will
* cause this value to be more stable, but it will update more slowly.
*
* @param analogPortHandle Handle to the analog port to use.
* @return A scaled sample from the output of the oversample and average engine
* for the channel.
*/
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
int32_t value = HAL_GetAnalogAverageValue(analogPortHandle, status);
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status);
int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status);
int32_t oversampleBits =
HAL_GetAnalogOversampleBits(analogPortHandle, status);
double voltage =
LSBWeight * 1.0e-9 * value / static_cast<double>(1 << oversampleBits) -
offset * 1.0e-9;
return voltage;
}
/**
* Convert a voltage to a raw value for a specified channel.
*
* This process depends on the calibration of each channel, so the channel must
* be specified.
*
* @todo This assumes raw values. Oversampling not supported as is.
*
* @param analogPortHandle Handle to the analog port to use.
* @param voltage The voltage to convert.
* @return The raw value for the channel.
*/
int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle,
double voltage, int32_t* status) {
if (voltage > 5.0) {
@@ -347,16 +190,28 @@ int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle,
return value;
}
/**
* Get the factory scaling least significant bit weight constant.
* The least significant bit weight constant for the channel that was calibrated
* in manufacturing and stored in an eeprom in the module.
*
* Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
*
* @param analogPortHandle Handle to the analog port to use.
* @return Least significant bit weight.
*/
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
int32_t value = HAL_GetAnalogValue(analogPortHandle, status);
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status);
int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status);
double voltage = LSBWeight * 1.0e-9 * value - offset * 1.0e-9;
return voltage;
}
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
int32_t value = HAL_GetAnalogAverageValue(analogPortHandle, status);
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status);
int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status);
int32_t oversampleBits =
HAL_GetAnalogOversampleBits(analogPortHandle, status);
double voltage =
LSBWeight * 1.0e-9 * value / static_cast<double>(1 << oversampleBits) -
offset * 1.0e-9;
return voltage;
}
int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
@@ -369,16 +224,6 @@ int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle,
return lsbWeight;
}
/**
* Get the factory scaling offset constant.
* The offset constant for the channel that was calibrated in manufacturing and
* stored in an eeprom in the module.
*
* Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
*
* @param analogPortHandle Handle to the analog port to use.
* @return Offset constant.
*/
int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);

View File

@@ -41,9 +41,6 @@ void InitializeAnalogInternal() {
}
} // namespace init
/**
* Initialize the analog System.
*/
void initializeAnalog(int32_t* status) {
hal::init::CheckInit();
if (analogSystemInitialized) return;
@@ -56,41 +53,22 @@ void initializeAnalog(int32_t* status) {
analogSystemInitialized = true;
}
/**
* Return the number of channels on the module in use.
*
* @return Active channels.
*/
int32_t getAnalogNumActiveChannels(int32_t* status) {
int32_t scanSize = analogInputSystem->readConfig_ScanSize(status);
if (scanSize == 0) return 8;
return scanSize;
}
/**
* Get the number of active channels.
*
* This is an internal function to allow the atomic update of both the
* number of active channels and the sample rate.
*
* When the number of channels changes, use the new value. Otherwise,
* return the curent value.
*
* @return Value to write to the active channels field.
*/
void setAnalogNumChannelsToActivate(int32_t channels) {
analogNumChannelsToActivate = channels;
}
int32_t getAnalogNumChannelsToActivate(int32_t* status) {
if (analogNumChannelsToActivate == 0)
return getAnalogNumActiveChannels(status);
return analogNumChannelsToActivate;
}
/**
* Set the sample rate.
*
* This is a global setting for the Athena and effects all channels.
*
* @param samplesPerSecond The number of samples per channel per second.
*/
void setAnalogSampleRate(double samplesPerSecond, int32_t* status) {
// TODO: This will change when variable size scan lists are implemented.
// TODO: Need double comparison with epsilon.
@@ -119,17 +97,4 @@ void setAnalogSampleRate(double samplesPerSecond, int32_t* status) {
setAnalogNumChannelsToActivate(0);
}
/**
* Set the number of active channels.
*
* Store the number of active channels to set. Don't actually commit to
* hardware
* until SetSampleRate().
*
* @param channels Number of active channels.
*/
void setAnalogNumChannelsToActivate(int32_t channels) {
analogNumChannelsToActivate = channels;
}
} // namespace hal

View File

@@ -40,10 +40,49 @@ extern IndexedHandleResource<HAL_AnalogInputHandle, hal::AnalogPort,
kNumAnalogInputs, HAL_HandleEnum::AnalogInput>*
analogInputHandles;
int32_t getAnalogNumActiveChannels(int32_t* status);
int32_t getAnalogNumChannelsToActivate(int32_t* status);
void setAnalogNumChannelsToActivate(int32_t channels);
void setAnalogSampleRate(double samplesPerSecond, int32_t* status);
/**
* Initialize the analog System.
*/
void initializeAnalog(int32_t* status);
/**
* Return the number of channels on the module in use.
*
* @return Active channels.
*/
int32_t getAnalogNumActiveChannels(int32_t* status);
/**
* Set the number of active channels.
*
* Store the number of active channels to set. Don't actually commit to
* hardware
* until SetSampleRate().
*
* @param channels Number of active channels.
*/
void setAnalogNumChannelsToActivate(int32_t channels);
/**
* Get the number of active channels.
*
* This is an internal function to allow the atomic update of both the
* number of active channels and the sample rate.
*
* When the number of channels changes, use the new value. Otherwise,
* return the curent value.
*
* @return Value to write to the active channels field.
*/
int32_t getAnalogNumChannelsToActivate(int32_t* status);
/**
* Set the sample rate.
*
* This is a global setting for the Athena and effects all channels.
*
* @param samplesPerSecond The number of samples per channel per second.
*/
void setAnalogSampleRate(double samplesPerSecond, int32_t* status);
} // namespace hal

View File

@@ -41,9 +41,6 @@ void InitializeAnalogOutput() {
extern "C" {
/**
* Initialize the analog output port using the given port object.
*/
HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle,
int32_t* status) {
hal::init::CheckInit();
@@ -78,17 +75,6 @@ void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analogOutputHandle) {
analogOutputHandles->Free(analogOutputHandle);
}
/**
* Check that the analog output channel number is value.
* Verify that the analog channel number is one of the legal channel numbers.
* Channel numbers are 0-based.
*
* @return Analog channel is valid
*/
HAL_Bool HAL_CheckAnalogOutputChannel(int32_t channel) {
return channel < kNumAnalogOutputs && channel >= 0;
}
void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
double voltage, int32_t* status) {
auto port = analogOutputHandles->Get(analogOutputHandle);
@@ -120,4 +106,8 @@ double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
return rawValue * 5.0 / 0x1000;
}
HAL_Bool HAL_CheckAnalogOutputChannel(int32_t channel) {
return channel < kNumAnalogOutputs && channel >= 0;
}
} // extern "C"

View File

@@ -94,10 +94,6 @@ void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle,
trigger->trigger->writeUpperLimit(upper, status);
}
/**
* Set the upper and lower limits of the analog trigger.
* The limits are given as floating point voltage values.
*/
void HAL_SetAnalogTriggerLimitsVoltage(
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
int32_t* status) {
@@ -118,11 +114,6 @@ void HAL_SetAnalogTriggerLimitsVoltage(
HAL_GetAnalogVoltsToValue(trigger->analogHandle, upper, status), status);
}
/**
* Configure the analog trigger to use the averaged vs. raw values.
* If the value is true, then the averaged value is selected for the analog
* trigger, otherwise the immediate value is used.
*/
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_Bool useAveragedValue, int32_t* status) {
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
@@ -138,12 +129,6 @@ void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
trigger->trigger->writeSourceSelect_Averaged(useAveragedValue, status);
}
/**
* Configure the analog trigger to use a filtered value.
* The analog trigger will operate with a 3 point average rejection filter. This
* is designed to help with 360 degree pot applications for the period where the
* pot crosses through zero.
*/
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_Bool useFilteredValue, int32_t* status) {
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
@@ -159,11 +144,6 @@ void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle,
trigger->trigger->writeSourceSelect_Filter(useFilteredValue, status);
}
/**
* Return the InWindow output of the analog trigger.
* True if the analog input is between the upper and lower limits.
* @return The InWindow output of the analog trigger.
*/
HAL_Bool HAL_GetAnalogTriggerInWindow(
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) {
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
@@ -174,13 +154,6 @@ HAL_Bool HAL_GetAnalogTriggerInWindow(
return trigger->trigger->readOutput_InHysteresis(trigger->index, status) != 0;
}
/**
* Return the TriggerState output of the analog trigger.
* True if above upper limit.
* False if below lower limit.
* If in Hysteresis, maintain previous state.
* @return The TriggerState output of the analog trigger.
*/
HAL_Bool HAL_GetAnalogTriggerTriggerState(
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) {
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
@@ -191,10 +164,6 @@ HAL_Bool HAL_GetAnalogTriggerTriggerState(
return trigger->trigger->readOutput_OverLimit(trigger->index, status) != 0;
}
/**
* Get the state of the analog trigger output.
* @return The state of the analog trigger output.
*/
HAL_Bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_AnalogTriggerType type,
int32_t* status) {

View File

@@ -77,10 +77,6 @@ void HAL_SetCounterAverageSize(HAL_CounterHandle counterHandle, int32_t size,
counter->counter->writeTimerConfig_AverageSize(size, status);
}
/**
* Set the source object that causes the counter to count up.
* Set the up counting DigitalSource.
*/
void HAL_SetCounterUpSource(HAL_CounterHandle counterHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
@@ -115,10 +111,6 @@ void HAL_SetCounterUpSource(HAL_CounterHandle counterHandle,
counter->counter->strobeReset(status);
}
/**
* Set the edge sensitivity on an up counting source.
* Set the up source to either detect rising edges or falling edges.
*/
void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counterHandle,
HAL_Bool risingEdge, HAL_Bool fallingEdge,
int32_t* status) {
@@ -131,9 +123,6 @@ void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counterHandle,
counter->counter->writeConfig_UpFallingEdge(fallingEdge, status);
}
/**
* Disable the up counting source to the counter.
*/
void HAL_ClearCounterUpSource(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
@@ -148,10 +137,6 @@ void HAL_ClearCounterUpSource(HAL_CounterHandle counterHandle,
counter->counter->writeConfig_UpSource_AnalogTrigger(false, status);
}
/**
* Set the source object that causes the counter to count down.
* Set the down counting DigitalSource.
*/
void HAL_SetCounterDownSource(HAL_CounterHandle counterHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
@@ -189,10 +174,6 @@ void HAL_SetCounterDownSource(HAL_CounterHandle counterHandle,
counter->counter->strobeReset(status);
}
/**
* Set the edge sensitivity on a down counting source.
* Set the down source to either detect rising edges or falling edges.
*/
void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counterHandle,
HAL_Bool risingEdge, HAL_Bool fallingEdge,
int32_t* status) {
@@ -205,9 +186,6 @@ void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counterHandle,
counter->counter->writeConfig_DownFallingEdge(fallingEdge, status);
}
/**
* Disable the down counting source to the counter.
*/
void HAL_ClearCounterDownSource(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
@@ -222,10 +200,6 @@ void HAL_ClearCounterDownSource(HAL_CounterHandle counterHandle,
counter->counter->writeConfig_DownSource_AnalogTrigger(false, status);
}
/**
* Set standard up / down counting mode on this counter.
* Up and down counts are sourced independently from two inputs.
*/
void HAL_SetCounterUpDownMode(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
@@ -236,11 +210,6 @@ void HAL_SetCounterUpDownMode(HAL_CounterHandle counterHandle,
counter->counter->writeConfig_Mode(HAL_Counter_kTwoPulse, status);
}
/**
* Set external direction mode on this counter.
* Counts are sourced on the Up counter input.
* The Down counter input represents the direction to count.
*/
void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
@@ -251,10 +220,6 @@ void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counterHandle,
counter->counter->writeConfig_Mode(HAL_Counter_kExternalDirection, status);
}
/**
* Set Semi-period mode on this counter.
* Counts up on both rising and falling edges.
*/
void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counterHandle,
HAL_Bool highSemiPeriod, int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
@@ -267,13 +232,6 @@ void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counterHandle,
HAL_SetCounterUpdateWhenEmpty(counterHandle, false, status);
}
/**
* Configure the counter to count in up or down based on the length of the input
* pulse.
* This mode is most useful for direction sensitive gear tooth sensors.
* @param threshold The pulse length beyond which the counter counts the
* opposite direction. Units are seconds.
*/
void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counterHandle,
double threshold, int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
@@ -288,13 +246,6 @@ void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counterHandle,
status);
}
/**
* Get the Samples to Average which specifies the number of samples of the timer
* to
* average when calculating the period. Perform averaging to account for
* mechanical imperfections or as oversampling to increase resolution.
* @return SamplesToAverage The number of samples being averaged (from 1 to 127)
*/
int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
@@ -305,12 +256,6 @@ int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
return counter->counter->readTimerConfig_AverageSize(status);
}
/**
* Set the Samples to Average which specifies the number of samples of the timer
* to average when calculating the period. Perform averaging to account for
* mechanical imperfections or as oversampling to increase resolution.
* @param samplesToAverage The number of samples to average from 1 to 127.
*/
void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
int32_t samplesToAverage, int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
@@ -324,11 +269,6 @@ void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
counter->counter->writeTimerConfig_AverageSize(samplesToAverage, status);
}
/**
* Reset the Counter to zero.
* Set the counter value to zero. This doesn't effect the running state of the
* counter, just sets the current value to zero.
*/
void HAL_ResetCounter(HAL_CounterHandle counterHandle, int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
if (counter == nullptr) {
@@ -338,11 +278,6 @@ void HAL_ResetCounter(HAL_CounterHandle counterHandle, int32_t* status) {
counter->counter->strobeReset(status);
}
/**
* Read the current counter value.
* 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 HAL_GetCounter(HAL_CounterHandle counterHandle, int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
if (counter == nullptr) {
@@ -353,12 +288,6 @@ int32_t HAL_GetCounter(HAL_CounterHandle counterHandle, int32_t* status) {
return value;
}
/*
* Get the Period of the most recent count.
* Returns the time interval of the most recent count. This can be used for
* velocity calculations to determine shaft speed.
* @returns The period of the last two pulses in units of seconds.
*/
double HAL_GetCounterPeriod(HAL_CounterHandle counterHandle, int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
if (counter == nullptr) {
@@ -381,14 +310,6 @@ double HAL_GetCounterPeriod(HAL_CounterHandle counterHandle, int32_t* status) {
2.5e-8); // result * timebase (currently 25ns)
}
/**
* Set the maximum period where the device is still considered "moving".
* Sets the maximum period where the device is considered moving. This value is
* used to determine the "stopped" state of the counter using the GetStopped
* method.
* @param maxPeriod The maximum period where the counted device is considered
* moving in seconds.
*/
void HAL_SetCounterMaxPeriod(HAL_CounterHandle counterHandle, double maxPeriod,
int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
@@ -400,19 +321,6 @@ void HAL_SetCounterMaxPeriod(HAL_CounterHandle counterHandle, double maxPeriod,
static_cast<uint32_t>(maxPeriod * 4.0e8), status);
}
/**
* Select whether you want to continue updating the event timer output when
* there are no samples captured. The output of the event timer has a buffer of
* periods that are averaged and posted to a register on the FPGA. When the
* timer detects that the event source has stopped (based on the MaxPeriod) the
* buffer of samples to be averaged is emptied. If you enable the update when
* empty, you will be notified of the stopped source and the event time will
* report 0 samples. If you disable update when empty, the most recent average
* will remain on the output until a new sample is acquired. You will never see
* 0 samples output (except when there have been no events since an FPGA reset)
* 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 HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counterHandle,
HAL_Bool enabled, int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
@@ -423,14 +331,6 @@ void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counterHandle,
counter->counter->writeTimerConfig_UpdateWhenEmpty(enabled, status);
}
/**
* Determine if the clock is stopped.
* Determine if the clocked input is stopped based on the MaxPeriod value set
* using the SetMaxPeriod method. If the clock exceeds the MaxPeriod, then the
* device (and counter) are assumed to be stopped and it returns true.
* @return Returns true if the most recent counter period exceeds the MaxPeriod
* value set by SetMaxPeriod.
*/
HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
@@ -441,10 +341,6 @@ HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counterHandle,
return counter->counter->readTimerOutput_Stalled(status);
}
/**
* The last direction the counter value changed.
* @return The last direction the counter value changed.
*/
HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles->Get(counterHandle);
@@ -456,12 +352,6 @@ HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counterHandle,
return value;
}
/**
* Set the Counter to return reversed sensing on the direction.
* This allows counters to change the direction they are counting in the case of
* 1X and 2X quadrature encoding only. Any other counter mode isn't supported.
* @param reverseDirection true if the value counted should be negated.
*/
void HAL_SetCounterReverseDirection(HAL_CounterHandle counterHandle,
HAL_Bool reverseDirection,
int32_t* status) {

View File

@@ -42,9 +42,6 @@ void InitializeDIO() {
extern "C" {
/**
* Create a new instance of a digital port.
*/
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
HAL_Bool input, int32_t* status) {
hal::init::CheckInit();
@@ -163,12 +160,6 @@ void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
}
}
/**
* Allocate a DO PWM Generator.
* Allocate PWM generators so that they are not accidentally reused.
*
* @return PWM Generator handle
*/
HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
auto handle = digitalPWMHandles->Allocate();
if (handle == HAL_kInvalidHandle) {
@@ -186,24 +177,10 @@ HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
return handle;
}
/**
* Free the resource associated with a DO PWM generator.
*
* @param pwmGenerator The pwmGen to free that was allocated with
* allocateDigitalPWM()
*/
void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status) {
digitalPWMHandles->Free(pwmGenerator);
}
/**
* Change the frequency of the DO PWM generator.
*
* The valid range is from 0.6 Hz to 19 kHz. The frequency resolution is
* logarithmic.
*
* @param rate The frequency to output all digital output PWM signals.
*/
void HAL_SetDigitalPWMRate(double rate, int32_t* status) {
// Currently rounding in the log rate domain... heavy weight toward picking a
// higher freq.
@@ -215,12 +192,6 @@ void HAL_SetDigitalPWMRate(double rate, int32_t* status) {
digitalSystem->writePWMPeriodPower(pwmPeriodPower, status);
}
/**
* Configure the duty-cycle of the PWM generator
*
* @param pwmGenerator The generator index reserved by allocateDigitalPWM()
* @param dutyCycle The percent duty cycle to output [0..1].
*/
void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
double dutyCycle, int32_t* status) {
auto port = digitalPWMHandles->Get(pwmGenerator);
@@ -250,12 +221,6 @@ void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
}
}
/**
* Configure which DO channel the PWM signal is output on
*
* @param pwmGenerator The generator index reserved by allocateDigitalPWM()
* @param channel The Digital Output channel to output on
*/
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
int32_t channel, int32_t* status) {
auto port = digitalPWMHandles->Get(pwmGenerator);
@@ -275,14 +240,6 @@ void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
digitalSystem->writePWMOutputSelect(id, channel, status);
}
/**
* Write a digital I/O bit to the FPGA.
* Set a single value on a digital I/O channel.
*
* @param channel The Digital I/O channel
* @param value The state to set the digital channel (if it is configured as an
* output)
*/
void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
@@ -324,12 +281,6 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
}
}
/**
* Set direction of a DIO channel.
*
* @param channel The Digital I/O channel
* @param input true to set input, false for output
*/
void HAL_SetDIODirection(HAL_DigitalHandle dioPortHandle, HAL_Bool input,
int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
@@ -368,13 +319,6 @@ void HAL_SetDIODirection(HAL_DigitalHandle dioPortHandle, HAL_Bool input,
}
}
/**
* Read a digital I/O bit from the FPGA.
* Get a single value from a digital I/O channel.
*
* @param channel The digital I/O channel
* @return The state of the specified channel
*/
HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
@@ -396,13 +340,6 @@ HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status) {
}
}
/**
* Read the direction of a the Digital I/O lines
* A 1 bit means output and a 0 bit means input.
*
* @param channel The digital I/O channel
* @return The direction of the specified channel
*/
HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
@@ -427,14 +364,6 @@ HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status) {
}
}
/**
* Generate a single pulse.
* Write a pulse to the specified digital output channel. There can only be a
* single pulse going at any time.
*
* @param channel The Digital Output channel that the pulse should be output on
* @param pulseLength The active length of the pulse (in seconds)
*/
void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
@@ -459,11 +388,6 @@ void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
digitalSystem->writePulse(pulse, status);
}
/**
* Check a DIO line to see if it is currently generating a pulse.
*
* @return A pulse is in progress
*/
HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
@@ -481,11 +405,6 @@ HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status) {
}
}
/**
* Check if any DIO line is currently generating a pulse.
*
* @return A pulse on some line is in progress
*/
HAL_Bool HAL_IsAnyPulsing(int32_t* status) {
initializeDigital(status);
if (*status != 0) return false;
@@ -494,14 +413,6 @@ HAL_Bool HAL_IsAnyPulsing(int32_t* status) {
pulseRegister.SPIPort != 0;
}
/**
* Write the filter index from the FPGA.
* Set the filter index used to filter out short pulses.
*
* @param dioPortHandle Handle to the digital I/O channel
* @param filterIndex The filter index. Must be in the range 0 - 3, where 0
* means "none" and 1 - 3 means filter # filterIndex - 1.
*/
void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
@@ -523,14 +434,6 @@ void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
}
}
/**
* Read the filter index from the FPGA.
* Get the filter index used to filter out short pulses.
*
* @param dioPortHandle Handle to the digital I/O channel
* @return filterIndex The filter index. Must be in the range 0 - 3,
* where 0 means "none" and 1 - 3 means filter # filterIndex - 1.
*/
int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
@@ -551,17 +454,6 @@ int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
}
}
/**
* Set the filter period for the specified filter index.
*
* Set the filter period in FPGA cycles. Even though there are 2 different
* filter index domains (MXP vs HDR), ignore that distinction for now since it
* compilicates the interface. That can be changed later.
*
* @param filterIndex The filter index, 0 - 2.
* @param value The number of cycles that the signal must not transition to be
* counted as a transition.
*/
void HAL_SetFilterPeriod(int32_t filterIndex, int64_t value, int32_t* status) {
initializeDigital(status);
if (*status != 0) return;
@@ -572,18 +464,6 @@ void HAL_SetFilterPeriod(int32_t filterIndex, int64_t value, int32_t* status) {
}
}
/**
* Get the filter period for the specified filter index.
*
* Get the filter period in FPGA cycles. Even though there are 2 different
* filter index domains (MXP vs HDR), ignore that distinction for now since it
* compilicates the interface. Set status to NiFpga_Status_SoftwareFault if the
* filter values miss-match.
*
* @param filterIndex The filter index, 0 - 2.
* @param value The number of cycles that the signal must not transition to be
* counted as a transition.
*/
int64_t HAL_GetFilterPeriod(int32_t filterIndex, int32_t* status) {
initializeDigital(status);
if (*status != 0) return 0;

View File

@@ -67,9 +67,6 @@ int32_t ComputeDigitalMask(HAL_DigitalHandle handle, int32_t* status) {
}
} // namespace detail
/**
* Initialize the digital system.
*/
void initializeDigital(int32_t* status) {
hal::init::CheckInit();
static std::atomic_bool initialized{false};
@@ -135,32 +132,6 @@ void initializeDigital(int32_t* status) {
initialized = true;
}
/**
* Map SPI channel numbers from their physical number (27 to 31) to their
* position in the bit field.
*/
int32_t remapSPIChannel(int32_t channel) { return channel - 26; }
/**
* Map DIO channel numbers from their physical number (10 to 26) to their
* position in the bit field.
*/
int32_t remapMXPChannel(int32_t channel) { return channel - 10; }
int32_t remapMXPPWMChannel(int32_t channel) {
if (channel < 14) {
return channel - 10; // first block of 4 pwms (MXP 0-3)
} else {
return channel - 6; // block of PWMs after SPI
}
}
/**
* remap the digital source channel and set the module.
* If it's an analog trigger, determine the module from the high order routing
* channel else do normal digital input remapping based on channel number
* (MXP)
*/
bool remapDigitalSource(HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
uint8_t& channel, uint8_t& module,
@@ -192,6 +163,18 @@ bool remapDigitalSource(HAL_Handle digitalSourceHandle,
}
}
int32_t remapMXPChannel(int32_t channel) { return channel - 10; }
int32_t remapMXPPWMChannel(int32_t channel) {
if (channel < 14) {
return channel - 10; // first block of 4 pwms (MXP 0-3)
} else {
return channel - 6; // block of PWMs after SPI
}
}
int32_t remapSPIChannel(int32_t channel) { return channel - 26; }
} // namespace hal
// Unused function here to test template compile.

View File

@@ -81,12 +81,33 @@ extern DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
extern wpi::mutex digitalDIOMutex;
/**
* Initialize the digital system.
*/
void initializeDigital(int32_t* status);
/**
* remap the digital source channel and set the module.
* If it's an analog trigger, determine the module from the high order routing
* channel else do normal digital input remapping based on channel number
* (MXP)
*/
bool remapDigitalSource(HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
uint8_t& channel, uint8_t& module, bool& analogTrigger);
int32_t remapSPIChannel(int32_t channel);
int32_t remapMXPPWMChannel(int32_t channel);
/**
* Map DIO channel numbers from their physical number (10 to 26) to their
* position in the bit field.
*/
int32_t remapMXPChannel(int32_t channel);
int32_t remapMXPPWMChannel(int32_t channel);
/**
* Map SPI channel numbers from their physical number (27 to 31) to their
* position in the bit field.
*/
int32_t remapSPIChannel(int32_t channel);
} // namespace hal

View File

@@ -102,10 +102,6 @@ void HAL_FreeFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
fpgaEncoderHandles->Free(fpgaEncoderHandle);
}
/**
* Reset the Encoder distance to zero.
* Resets the current count to zero on the encoder.
*/
void HAL_ResetFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status) {
auto encoder = fpgaEncoderHandles->Get(fpgaEncoderHandle);
@@ -116,12 +112,6 @@ void HAL_ResetFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
encoder->encoder->strobeReset(status);
}
/**
* Gets the fpga value from the encoder.
* The fpga value is the actual count unscaled by the 1x, 2x, or 4x scale
* factor.
* @return Current fpga count from the encoder
*/
int32_t HAL_GetFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status) {
auto encoder = fpgaEncoderHandles->Get(fpgaEncoderHandle);
@@ -132,16 +122,6 @@ int32_t HAL_GetFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
return encoder->encoder->readOutput_Value(status);
}
/**
* Returns the period of the most recent pulse.
* Returns the period of the most recent Encoder pulse in seconds.
* This method compenstates for the decoding type.
*
* @deprecated Use GetRate() in favor of this method. This returns unscaled
* periods and GetRate() scales using value from SetDistancePerPulse().
*
* @return Period in seconds of the most recent pulse.
*/
double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status) {
auto encoder = fpgaEncoderHandles->Get(fpgaEncoderHandle);
@@ -165,20 +145,6 @@ double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
return measuredPeriod / DECODING_SCALING_FACTOR;
}
/**
* Sets the maximum period for stopped detection.
* Sets the value that represents the maximum period of the Encoder before it
* will assume that the attached device is stopped. This timeout allows users
* to determine if the wheels or other shaft has stopped rotating.
* This method compensates for the decoding type.
*
* @deprecated Use SetMinRate() in favor of this method. This takes unscaled
* periods and SetMinRate() scales using value from SetDistancePerPulse().
*
* @param maxPeriod The maximum time between rising and falling edges before the
* FPGA will
* report the device stopped. This is expressed in seconds.
*/
void HAL_SetFPGAEncoderMaxPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
double maxPeriod, int32_t* status) {
auto encoder = fpgaEncoderHandles->Get(fpgaEncoderHandle);
@@ -191,13 +157,6 @@ void HAL_SetFPGAEncoderMaxPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
status);
}
/**
* Determine if the encoder is stopped.
* Using the MaxPeriod value, a boolean is returned that is true if the encoder
* is considered stopped and false if it is still moving. A stopped encoder is
* one where the most recent pulse width exceeds the MaxPeriod.
* @return True if the encoder is considered stopped.
*/
HAL_Bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status) {
auto encoder = fpgaEncoderHandles->Get(fpgaEncoderHandle);
@@ -208,10 +167,6 @@ HAL_Bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpgaEncoderHandle,
return encoder->encoder->readTimerOutput_Stalled(status) != 0;
}
/**
* The last direction the encoder value changed.
* @return The last direction the encoder value changed.
*/
HAL_Bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status) {
auto encoder = fpgaEncoderHandles->Get(fpgaEncoderHandle);
@@ -222,12 +177,6 @@ HAL_Bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpgaEncoderHandle,
return encoder->encoder->readOutput_Direction(status);
}
/**
* Set the direction sensing for this encoder.
* This sets the direction sensing on the encoder so that it could count in the
* correct software direction regardless of the mounting.
* @param reverseDirection true if the encoder direction should be reversed
*/
void HAL_SetFPGAEncoderReverseDirection(HAL_FPGAEncoderHandle fpgaEncoderHandle,
HAL_Bool reverseDirection,
int32_t* status) {
@@ -239,12 +188,6 @@ void HAL_SetFPGAEncoderReverseDirection(HAL_FPGAEncoderHandle fpgaEncoderHandle,
encoder->encoder->writeConfig_Reverse(reverseDirection, status);
}
/**
* Set the Samples to Average which specifies the number of samples of the timer
* to average when calculating the period. Perform averaging to account for
* mechanical imperfections or as oversampling to increase resolution.
* @param samplesToAverage The number of samples to average from 1 to 127.
*/
void HAL_SetFPGAEncoderSamplesToAverage(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t samplesToAverage,
int32_t* status) {
@@ -259,12 +202,6 @@ void HAL_SetFPGAEncoderSamplesToAverage(HAL_FPGAEncoderHandle fpgaEncoderHandle,
encoder->encoder->writeTimerConfig_AverageSize(samplesToAverage, status);
}
/**
* Get the Samples to Average which specifies the number of samples of the timer
* to average when calculating the period. Perform averaging to account for
* mechanical imperfections or as oversampling to increase resolution.
* @return SamplesToAverage The number of samples being averaged (from 1 to 127)
*/
int32_t HAL_GetFPGAEncoderSamplesToAverage(
HAL_FPGAEncoderHandle fpgaEncoderHandle, int32_t* status) {
auto encoder = fpgaEncoderHandles->Get(fpgaEncoderHandle);
@@ -275,10 +212,6 @@ int32_t HAL_GetFPGAEncoderSamplesToAverage(
return encoder->encoder->readTimerConfig_AverageSize(status);
}
/**
* Set an index source for an encoder, which is an input that resets the
* encoder's count.
*/
void HAL_SetFPGAEncoderIndexSource(HAL_FPGAEncoderHandle fpgaEncoderHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,

View File

@@ -20,26 +20,103 @@ HAL_FPGAEncoderHandle HAL_InitializeFPGAEncoder(
HAL_Bool reverseDirection, int32_t* index, int32_t* status);
void HAL_FreeFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status);
/**
* Reset the Encoder distance to zero.
* Resets the current count to zero on the encoder.
*/
void HAL_ResetFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status);
/**
* Gets the fpga value from the encoder.
* The fpga value is the actual count unscaled by the 1x, 2x, or 4x scale
* factor.
* @return Current fpga count from the encoder
*/
int32_t HAL_GetFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status); // Raw value
/**
* Returns the period of the most recent pulse.
* Returns the period of the most recent Encoder pulse in seconds.
* This method compenstates for the decoding type.
*
* @deprecated Use GetRate() in favor of this method. This returns unscaled
* periods and GetRate() scales using value from SetDistancePerPulse().
*
* @return Period in seconds of the most recent pulse.
*/
double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status);
/**
* Sets the maximum period for stopped detection.
* Sets the value that represents the maximum period of the Encoder before it
* will assume that the attached device is stopped. This timeout allows users
* to determine if the wheels or other shaft has stopped rotating.
* This method compensates for the decoding type.
*
* @deprecated Use SetMinRate() in favor of this method. This takes unscaled
* periods and SetMinRate() scales using value from SetDistancePerPulse().
*
* @param maxPeriod The maximum time between rising and falling edges before the
* FPGA will
* report the device stopped. This is expressed in seconds.
*/
void HAL_SetFPGAEncoderMaxPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
double maxPeriod, int32_t* status);
/**
* Determine if the encoder is stopped.
* Using the MaxPeriod value, a boolean is returned that is true if the encoder
* is considered stopped and false if it is still moving. A stopped encoder is
* one where the most recent pulse width exceeds the MaxPeriod.
* @return True if the encoder is considered stopped.
*/
HAL_Bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status);
/**
* The last direction the encoder value changed.
* @return The last direction the encoder value changed.
*/
HAL_Bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status);
/**
* Set the direction sensing for this encoder.
* This sets the direction sensing on the encoder so that it could count in the
* correct software direction regardless of the mounting.
* @param reverseDirection true if the encoder direction should be reversed
*/
void HAL_SetFPGAEncoderReverseDirection(HAL_FPGAEncoderHandle fpgaEncoderHandle,
HAL_Bool reverseDirection,
int32_t* status);
/**
* Set the Samples to Average which specifies the number of samples of the timer
* to average when calculating the period. Perform averaging to account for
* mechanical imperfections or as oversampling to increase resolution.
* @param samplesToAverage The number of samples to average from 1 to 127.
*/
void HAL_SetFPGAEncoderSamplesToAverage(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t samplesToAverage,
int32_t* status);
/**
* Get the Samples to Average which specifies the number of samples of the timer
* to average when calculating the period. Perform averaging to account for
* mechanical imperfections or as oversampling to increase resolution.
* @return SamplesToAverage The number of samples being averaged (from 1 to 127)
*/
int32_t HAL_GetFPGAEncoderSamplesToAverage(
HAL_FPGAEncoderHandle fpgaEncoderHandle, int32_t* status);
/**
* Set an index source for an encoder, which is an input that resets the
* encoder's count.
*/
void HAL_SetFPGAEncoderIndexSource(HAL_FPGAEncoderHandle fpgaEncoderHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,

View File

@@ -146,17 +146,7 @@ int32_t HAL_GetJoystickButtons(int32_t joystickNum,
return FRC_NetworkCommunication_getJoystickButtons(
joystickNum, &buttons->buttons, &buttons->count);
}
/**
* Retrieve the Joystick Descriptor for particular slot
* @param desc [out] descriptor (data transfer object) to fill in. desc is
* filled in regardless of success. In other words, if descriptor is not
* available, desc is filled in with default values matching the init-values in
* Java and C++ Driverstation for when caller requests a too-large joystick
* index.
*
* @return error code reported from Network Comm back-end. Zero is good,
* nonzero is bad.
*/
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
HAL_JoystickDescriptor* desc) {
desc->isXbox = 0;
@@ -333,16 +323,8 @@ bool HAL_IsNewControlData(void) {
return true;
}
/**
* Waits for the newest DS packet to arrive. Note that this is a blocking call.
*/
void HAL_WaitForDSData(void) { HAL_WaitForDSDataTimeout(0); }
/**
* Waits for the newest DS packet to arrive. If timeout is <= 0, this will wait
* forever. Otherwise, it will wait until either a new packet, or the timeout
* time has passed. Returns true on new data, false on timeout.
*/
HAL_Bool HAL_WaitForDSDataTimeout(double timeout) {
auto timeoutTime =
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
@@ -375,11 +357,6 @@ static void newDataOccur(uint32_t refNum) {
newDSDataAvailableCond->notify_all();
}
/*
* Call this to initialize the driver station communication. This will properly
* handle multiple calls. However note that this CANNOT be called from a library
* that interfaces with LabVIEW.
*/
void HAL_InitializeDriverStation(void) {
hal::init::CheckInit();
static std::atomic_bool initialized{false};
@@ -399,10 +376,6 @@ void HAL_InitializeDriverStation(void) {
initialized = true;
}
/*
* Releases the DS Mutex to allow proper shutdown of any threads that are
* waiting on it.
*/
void HAL_ReleaseDSMutex(void) { newDataOccur(refNumber); }
} // extern "C"

View File

@@ -84,9 +84,6 @@ HAL_PortHandle HAL_GetPort(int32_t channel) {
return createPortHandle(channel, 1);
}
/**
* @deprecated Uses module numbers
*/
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel) {
// Dont allow a number that wouldn't fit in a uint8_t
if (channel < 0 || channel >= 255) return HAL_kInvalidHandle;
@@ -215,16 +212,8 @@ const char* HAL_GetErrorMessage(int32_t code) {
}
}
/**
* Returns the runtime type of this HAL
*/
HAL_RuntimeType HAL_GetRuntimeType(void) { return HAL_Athena; }
/**
* Return the FPGA Version number.
* For now, expect this to be competition year.
* @return FPGA Version number.
*/
int32_t HAL_GetFPGAVersion(int32_t* status) {
if (!global) {
*status = NiFpga_Status_ResourceNotInitialized;
@@ -233,14 +222,6 @@ int32_t HAL_GetFPGAVersion(int32_t* status) {
return global->readVersion(status);
}
/**
* Return the FPGA Revision number.
* The format of the revision is 3 numbers.
* The 12 most significant bits are the Major Revision.
* the next 8 bits are the Minor Revision.
* The 12 least significant bits are the Build Number.
* @return FPGA Revision number.
*/
int64_t HAL_GetFPGARevision(int32_t* status) {
if (!global) {
*status = NiFpga_Status_ResourceNotInitialized;
@@ -249,12 +230,6 @@ int64_t HAL_GetFPGARevision(int32_t* status) {
return global->readRevision(status);
}
/**
* Read the microsecond-resolution timer on the FPGA.
*
* @return The current time in microseconds according to the FPGA (since FPGA
* reset).
*/
uint64_t HAL_GetFPGATime(int32_t* status) {
if (!global) {
*status = NiFpga_Status_ResourceNotInitialized;
@@ -273,10 +248,6 @@ uint64_t HAL_GetFPGATime(int32_t* status) {
return (upper2 << 32) + lower;
}
/**
* Get the state of the "USER" button on the roboRIO
* @return true if the button is currently pressed down
*/
HAL_Bool HAL_GetFPGAButton(int32_t* status) {
if (!global) {
*status = NiFpga_Status_ResourceNotInitialized;
@@ -360,9 +331,6 @@ static bool killExistingProgram(int timeout, int mode) {
return true;
}
/**
* Call this to start up HAL. This is required for robot programs.
*/
HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
static std::atomic_bool initialized{false};
static wpi::mutex initializeMutex;

View File

@@ -41,11 +41,6 @@ void InitializeI2C() {}
extern "C" {
/*
* Initialize the I2C port. Opens the port if necessary and saves the handle.
* If opening the MXP port, also sets up the channel functions appropriately
* @param port The port to open, 0 for the on-board, 1 for the MXP.
*/
void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
hal::init::CheckInit();
initializeDigital(status);
@@ -90,18 +85,6 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
}
}
/**
* Generic transaction.
*
* This is a lower-level interface to the I2C hardware giving you more control
* over each transaction.
*
* @param dataToSend Buffer of data to send as part of the transaction.
* @param sendSize Number of bytes to send as part of the transaction.
* @param dataReceived Buffer to read data into.
* @param receiveSize Number of bytes to read from the device.
* @return >= 0 on success or -1 on transfer abort.
*/
int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
const uint8_t* dataToSend, int32_t sendSize,
uint8_t* dataReceived, int32_t receiveSize) {
@@ -133,17 +116,6 @@ int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
}
}
/**
* Execute a write transaction with the device.
*
* Write a single byte to a register on a device and wait until the
* transaction is complete.
*
* @param registerAddress The address of the register on the device to be
* written.
* @param data The byte to write to the register on the device.
* @return >= 0 on success or -1 on transfer abort.
*/
int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress,
const uint8_t* dataToSend, int32_t sendSize) {
if (port > 1) {
@@ -170,19 +142,6 @@ int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress,
}
}
/**
* Execute a read transaction with the device.
*
* Read bytes from a device.
* Most I2C devices will auto-increment the register pointer internally allowing
* you to read consecutive registers on a device in a single transaction.
*
* @param registerAddress The register to read first in the transaction.
* @param count The number of bytes to read in the transaction.
* @param buffer A pointer to the array of bytes to store the data read from the
* device.
* @return >= 0 on success or -1 on transfer abort.
*/
int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer,
int32_t count) {
if (port > 1) {

View File

@@ -123,13 +123,6 @@ void* HAL_CleanInterrupts(HAL_InterruptHandle interruptHandle,
return param;
}
/**
* In synchronous mode, wait for the defined interrupt to occur.
* @param timeout Timeout in seconds
* @param ignorePrevious If true, ignore interrupts that happened before
* waitForInterrupt was called.
* @return The mask of interrupts that fired.
*/
int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interruptHandle,
double timeout, HAL_Bool ignorePrevious,
int32_t* status) {
@@ -152,12 +145,6 @@ int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interruptHandle,
return result;
}
/**
* Enable interrupts to occur on this input.
* Interrupts are disabled when the RequestInterrupt call is made. This gives
* time to do the setup of the other options before starting to field
* interrupts.
*/
void HAL_EnableInterrupts(HAL_InterruptHandle interruptHandle,
int32_t* status) {
auto anInterrupt = interruptHandles->Get(interruptHandle);
@@ -168,9 +155,6 @@ void HAL_EnableInterrupts(HAL_InterruptHandle interruptHandle,
anInterrupt->manager->enable(status);
}
/**
* Disable Interrupts without without deallocating structures.
*/
void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
int32_t* status) {
auto anInterrupt = interruptHandles->Get(interruptHandle);
@@ -181,11 +165,6 @@ void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
anInterrupt->manager->disable(status);
}
/**
* Return the timestamp for the rising interrupt that occurred most recently.
* This is in the same time domain as GetClock().
* @return Timestamp in seconds since boot.
*/
double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle,
int32_t* status) {
auto anInterrupt = interruptHandles->Get(interruptHandle);
@@ -197,11 +176,6 @@ double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle,
return timestamp * 1e-6;
}
/**
* Return the timestamp for the falling interrupt that occurred most recently.
* This is in the same time domain as GetClock().
* @return Timestamp in seconds since boot.
*/
double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle,
int32_t* status) {
auto anInterrupt = interruptHandles->Get(interruptHandle);

View File

@@ -235,14 +235,6 @@ HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
return port->eliminateDeadband;
}
/**
* Set a PWM channel to the desired value. The values range from 0 to 255 and
* the period is controlled
* by the PWM Period and MinHigh registers.
*
* @param channel The PWM channel to set.
* @param value The PWM value to set.
*/
void HAL_SetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t value,
int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
@@ -258,15 +250,6 @@ void HAL_SetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t value,
}
}
/**
* Set a PWM channel to the desired scaled value. The values range from -1 to 1
* and
* the period is controlled
* by the PWM Period and MinHigh registers.
*
* @param channel The PWM channel to set.
* @param value The scaled PWM value to set.
*/
void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
@@ -313,15 +296,6 @@ void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
HAL_SetPWMRaw(pwmPortHandle, rawValue, status);
}
/**
* Set a PWM channel to the desired position value. The values range from 0 to 1
* and
* the period is controlled
* by the PWM Period and MinHigh registers.
*
* @param channel The PWM channel to set.
* @param value The scaled PWM value to set.
*/
void HAL_SetPWMPosition(HAL_DigitalHandle pwmPortHandle, double pos,
int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
@@ -359,12 +333,6 @@ void HAL_SetPWMDisabled(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
HAL_SetPWMRaw(pwmPortHandle, kPwmDisabled, status);
}
/**
* Get a value from a PWM channel. The values range from 0 to 255.
*
* @param channel The PWM channel to read from.
* @return The raw PWM value.
*/
int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
@@ -379,12 +347,6 @@ int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
}
}
/**
* Get a scaled value from a PWM channel. The values range from -1 to 1.
*
* @param channel The PWM channel to read from.
* @return The scaled PWM value.
*/
double HAL_GetPWMSpeed(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
@@ -417,12 +379,6 @@ double HAL_GetPWMSpeed(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
}
}
/**
* Get a position value from a PWM channel. The values range from 0 to 1.
*
* @param channel The PWM channel to read from.
* @return The scaled PWM value.
*/
double HAL_GetPWMPosition(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
@@ -459,12 +415,6 @@ void HAL_LatchPWMZero(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
pwmSystem->writeZeroLatch(port->channel, false, status);
}
/**
* Set how how often the PWM signal is squelched, thus scaling the period.
*
* @param channel The PWM channel to configure.
* @param squelchMask The 2-bit mask of outputs to squelch.
*/
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwmPortHandle, int32_t squelchMask,
int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
@@ -481,22 +431,12 @@ void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwmPortHandle, int32_t squelchMask,
}
}
/**
* Get the loop timing of the PWM system
*
* @return The loop time
*/
int32_t HAL_GetPWMLoopTiming(int32_t* status) {
initializeDigital(status);
if (*status != 0) return 0;
return pwmSystem->readLoopTiming(status);
}
/**
* Get the pwm starting cycle time
*
* @return The pwm cycle start time.
*/
uint64_t HAL_GetPWMCycleStartTime(int32_t* status) {
initializeDigital(status);
if (*status != 0) return 0;

View File

@@ -35,115 +35,73 @@ void InitializePower() {}
extern "C" {
/**
* Get the roboRIO input voltage
*/
double HAL_GetVinVoltage(int32_t* status) {
initializePower(status);
return power->readVinVoltage(status) / 4.096 * 0.025733 - 0.029;
}
/**
* Get the roboRIO input current
*/
double HAL_GetVinCurrent(int32_t* status) {
initializePower(status);
return power->readVinCurrent(status) / 4.096 * 0.017042 - 0.071;
}
/**
* Get the 6V rail voltage
*/
double HAL_GetUserVoltage6V(int32_t* status) {
initializePower(status);
return power->readUserVoltage6V(status) / 4.096 * 0.007019 - 0.014;
}
/**
* Get the 6V rail current
*/
double HAL_GetUserCurrent6V(int32_t* status) {
initializePower(status);
return power->readUserCurrent6V(status) / 4.096 * 0.005566 - 0.009;
}
/**
* Get the active state of the 6V rail
*/
HAL_Bool HAL_GetUserActive6V(int32_t* status) {
initializePower(status);
return power->readStatus_User6V(status) == 4;
}
/**
* Get the fault count for the 6V rail
*/
int32_t HAL_GetUserCurrentFaults6V(int32_t* status) {
initializePower(status);
return static_cast<int32_t>(
power->readFaultCounts_OverCurrentFaultCount6V(status));
}
/**
* Get the 5V rail voltage
*/
double HAL_GetUserVoltage5V(int32_t* status) {
initializePower(status);
return power->readUserVoltage5V(status) / 4.096 * 0.005962 - 0.013;
}
/**
* Get the 5V rail current
*/
double HAL_GetUserCurrent5V(int32_t* status) {
initializePower(status);
return power->readUserCurrent5V(status) / 4.096 * 0.001996 - 0.002;
}
/**
* Get the active state of the 5V rail
*/
HAL_Bool HAL_GetUserActive5V(int32_t* status) {
initializePower(status);
return power->readStatus_User5V(status) == 4;
}
/**
* Get the fault count for the 5V rail
*/
int32_t HAL_GetUserCurrentFaults5V(int32_t* status) {
initializePower(status);
return static_cast<int32_t>(
power->readFaultCounts_OverCurrentFaultCount5V(status));
}
/**
* Get the 3.3V rail voltage
*/
double HAL_GetUserVoltage3V3(int32_t* status) {
initializePower(status);
return power->readUserVoltage3V3(status) / 4.096 * 0.004902 - 0.01;
}
/**
* Get the 3.3V rail current
*/
double HAL_GetUserCurrent3V3(int32_t* status) {
initializePower(status);
return power->readUserCurrent3V3(status) / 4.096 * 0.002486 - 0.003;
}
/**
* Get the active state of the 3.3V rail
*/
HAL_Bool HAL_GetUserActive3V3(int32_t* status) {
initializePower(status);
return power->readStatus_User3V3(status) == 4;
}
/**
* Get the fault count for the 3.3V rail
*/
int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) {
initializePower(status);
return static_cast<int32_t>(

View File

@@ -93,10 +93,6 @@ HAL_Bool HAL_CheckRelayChannel(int32_t channel) {
return channel < kNumRelayHeaders && channel >= 0;
}
/**
* Set the state of a relay.
* Set the state of a relay output.
*/
void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
int32_t* status) {
auto port = relayHandles->Get(relayPortHandle);
@@ -127,9 +123,6 @@ void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
}
}
/**
* Get the current state of the relay channel
*/
HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status) {
auto port = relayHandles->Get(relayPortHandle);
if (port == nullptr) {

View File

@@ -100,11 +100,6 @@ static void CommonSPIPortFree(void) {
}
}
/*
* Initialize the spi port. Opens the port if necessary and saves the handle.
* If opening the MXP port, also sets up the channel functions appropriately
* @param port The number of the port to use. 0-3 for Onboard CS0-CS3, 4 for MXP
*/
void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
hal::init::CheckInit();
if (port < 0 || port >= kSpiMaxHandles) {
@@ -244,18 +239,6 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
}
}
/**
* Generic transaction.
*
* This is a lower-level interface to the spi hardware giving you more control
* over each transaction.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
* @param dataToSend Buffer of data to send as part of the transaction.
* @param dataReceived Buffer to read data into.
* @param size Number of bytes to transfer. [0..7]
* @return Number of bytes transferred, -1 for error
*/
int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t* dataToSend,
uint8_t* dataReceived, int32_t size) {
if (port < 0 || port >= kSpiMaxHandles) {
@@ -274,16 +257,6 @@ int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t* dataToSend,
return ioctl(HAL_GetSPIHandle(port), SPI_IOC_MESSAGE(1), &xfer);
}
/**
* Execute a write transaction with the device.
*
* Write to a device and wait until the transaction is complete.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
* @param datToSend The data to write to the register on the device.
* @param sendSize The number of bytes to be written
* @return The number of bytes written. -1 for an error
*/
int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t sendSize) {
if (port < 0 || port >= kSpiMaxHandles) {
@@ -301,19 +274,6 @@ int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t* dataToSend,
return ioctl(HAL_GetSPIHandle(port), SPI_IOC_MESSAGE(1), &xfer);
}
/**
* Execute a read from the device.
*
* This method does not write any data out to the device
* Most spi devices will require a register address to be written before
* they begin returning data
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
* @param buffer A pointer to the array of bytes to store the data read from the
* device.
* @param count The number of bytes to read in the transaction. [1..7]
* @return Number of bytes read. -1 for error.
*/
int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count) {
if (port < 0 || port >= kSpiMaxHandles) {
return -1;
@@ -330,11 +290,6 @@ int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count) {
return ioctl(HAL_GetSPIHandle(port), SPI_IOC_MESSAGE(1), &xfer);
}
/**
* Close the SPI port
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
*/
void HAL_CloseSPI(HAL_SPIPort port) {
if (port < 0 || port >= kSpiMaxHandles) {
return;
@@ -375,12 +330,6 @@ void HAL_CloseSPI(HAL_SPIPort port) {
}
}
/**
* Set the clock speed for the SPI bus.
*
* @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 HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed) {
if (port < 0 || port >= kSpiMaxHandles) {
return;
@@ -390,16 +339,6 @@ void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed) {
ioctl(HAL_GetSPIHandle(port), SPI_IOC_WR_MAX_SPEED_HZ, &speed);
}
/**
* Set the SPI options
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
* @param msbFirst True to write the MSB first, False for LSB first
* @param sampleOnTrailing True to sample on the trailing edge, False to sample
* on the leading edge
* @param clkIdleHigh True to set the clock to active low, False to set the
* clock active high
*/
void HAL_SetSPIOpts(HAL_SPIPort port, HAL_Bool msbFirst,
HAL_Bool sampleOnTrailing, HAL_Bool clkIdleHigh) {
if (port < 0 || port >= kSpiMaxHandles) {
@@ -415,11 +354,6 @@ void HAL_SetSPIOpts(HAL_SPIPort port, HAL_Bool msbFirst,
ioctl(HAL_GetSPIHandle(port), SPI_IOC_WR_MODE, &mode);
}
/**
* Set the CS Active high for a SPI port
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
*/
void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status) {
if (port < 0 || port >= kSpiMaxHandles) {
*status = PARAMETER_OUT_OF_RANGE;
@@ -435,11 +369,6 @@ void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status) {
}
}
/**
* Set the CS Active low for a SPI port
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
*/
void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t* status) {
if (port < 0 || port >= kSpiMaxHandles) {
*status = PARAMETER_OUT_OF_RANGE;
@@ -455,12 +384,6 @@ void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t* status) {
}
}
/**
* Get the stored handle for a SPI port
*
* @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 HAL_GetSPIHandle(HAL_SPIPort port) {
if (port < 0 || port >= kSpiMaxHandles) {
return 0;
@@ -483,13 +406,6 @@ int32_t HAL_GetSPIHandle(HAL_SPIPort port) {
}
}
/**
* Set the stored handle for a SPI port
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for
* MXP.
* @param handle The value of the handle for the port.
*/
void HAL_SetSPIHandle(HAL_SPIPort port, int32_t handle) {
if (port < 0 || port >= kSpiMaxHandles) {
return;

View File

@@ -20,14 +20,6 @@ void InitializeThreads() {}
extern "C" {
/**
* Get the thread priority for the specified thread.
*
* @param handle Native handle pointer to the thread to get the priority for
* @param isRealTime Set to true if thread is realtime, otherwise false
* @param status Error status variable. 0 on success
* @return The current thread priority. Scaled 1-99, with 1 being highest.
*/
int32_t HAL_GetThreadPriority(NativeThreadHandle handle, HAL_Bool* isRealTime,
int32_t* status) {
sched_param sch;
@@ -49,31 +41,11 @@ int32_t HAL_GetThreadPriority(NativeThreadHandle handle, HAL_Bool* isRealTime,
}
}
/**
* Get the thread priority for the current thread.
*
* @param handle Native handle pointer to the thread to get the priority for
* @param isRealTime Set to true if thread is realtime, otherwise false
* @param status Error status variable. 0 on success
* @return The current thread priority. Scaled 1-99, with 1 being highest.
*/
int32_t HAL_GetCurrentThreadPriority(HAL_Bool* isRealTime, int32_t* status) {
auto thread = pthread_self();
return HAL_GetThreadPriority(&thread, isRealTime, status);
}
/**
* Sets the thread priority for the specified thread
*
* @param thread Reference to the thread to set the priority of
* @param realTime Set to true to set a realtime priority, false for standard
* priority
* @param priority Priority to set the thread to. Scaled 1-99, with 1 being
* highest
* @param status Error status variable. 0 on success
*
* @return The success state of setting the priority
*/
HAL_Bool HAL_SetThreadPriority(NativeThreadHandle handle, HAL_Bool realTime,
int32_t priority, int32_t* status) {
if (handle == nullptr) {
@@ -109,18 +81,6 @@ HAL_Bool HAL_SetThreadPriority(NativeThreadHandle handle, HAL_Bool realTime,
}
}
/**
* Sets the thread priority for the current thread
*
* @param thread Reference to the thread to set the priority of
* @param realTime Set to true to set a realtime priority, false for standard
* priority
* @param priority Priority to set the thread to. Scaled 1-99, with 1 being
* highest
* @param status Error status variable. 0 on success
*
* @return The success state of setting the priority
*/
HAL_Bool HAL_SetCurrentThreadPriority(HAL_Bool realTime, int32_t priority,
int32_t* status) {
auto thread = pthread_self();

View File

@@ -18,10 +18,37 @@ enum HAL_AccelerometerRange : int32_t {
#ifdef __cplusplus
extern "C" {
#endif
/**
* Set the accelerometer to active or standby mode. It must be in standby
* mode to change any configuration.
*/
void HAL_SetAccelerometerActive(HAL_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 HAL_SetAccelerometerRange(HAL_AccelerometerRange range);
/**
* Get the x-axis acceleration
*
* This is a floating point value in units of 1 g-force
*/
double HAL_GetAccelerometerX(void);
/**
* Get the y-axis acceleration
*
* This is a floating point value in units of 1 g-force
*/
double HAL_GetAccelerometerY(void);
/**
* Get the z-axis acceleration
*
* This is a floating point value in units of 1 g-force
*/
double HAL_GetAccelerometerZ(void);
#ifdef __cplusplus
} // extern "C"

View File

@@ -15,20 +15,92 @@
extern "C" {
#endif
/**
* Is the channel attached to an accumulator.
*
* @param analogPortHandle Handle to the analog port.
* @return The analog channel is attached to an accumulator.
*/
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
/**
* Initialize the accumulator.
*
* @param analogPortHandle Handle to the analog port.
*/
void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
/**
* Resets the accumulator to the initial value.
*
* @param analogPortHandle Handle to the analog port.
*/
void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
/**
* Set the center value of the accumulator.
*
* The center value is subtracted from each A/D value before it is added to the
* accumulator. This is used for the center value of devices like gyros and
* accelerometers to make integration work and to take the device offset into
* account when integrating.
*
* This center value is based on the output of the oversampled and averaged
* source from channel 1. Because of this, any non-zero oversample bits will
* affect the size of the value for this field.
*
* @param analogPortHandle Handle to the analog port.
* @param center The center value of the accumulator.
*/
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
int32_t center, int32_t* status);
/**
* Set the accumulator's deadband.
*
* @param analogPortHandle Handle to the analog port.
* @param deadband The deadband of the accumulator.
*/
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
int32_t deadband, int32_t* status);
/**
* Read the accumulated value.
*
* Read the value that has been accumulating on channel 1.
* The accumulator is attached after the oversample and average engine.
*
* @param analogPortHandle Handle to the analog port.
* @return The 64-bit value accumulated since the last Reset().
*/
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
/**
* Read the number of accumulated values.
*
* Read the count of the accumulated values since the accumulator was last
* Reset().
*
* @param analogPortHandle Handle to the analog port.
* @return The number of times samples from the channel were accumulated.
*/
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
/**
* Read the accumulated value and the number of accumulated values atomically.
*
* This function reads the value and count from the FPGA atomically.
* This can be used for averaging.
*
* @param analogPortHandle Handle to the analog port.
* @param value Pointer to the 64-bit accumulated output.
* @param count Pointer to the number of accumulation cycles.
*/
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle,
int64_t* value, int64_t* count, int32_t* status);
#ifdef __cplusplus

View File

@@ -15,34 +15,204 @@
extern "C" {
#endif
/**
* Initialize the analog input port using the given port object.
*
* @param portHandle Handle to the port to initialize.
*/
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle,
int32_t* status);
/**
* @param analogPortHandle Handle to the analog port.
*/
void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle);
/**
* Check that the analog module number is valid.
*
* @param module The analog module number.
* @return Analog module is valid and present
*/
HAL_Bool HAL_CheckAnalogModule(int32_t module);
/**
* Check that the analog output channel number is value.
* Verify that the analog channel number is one of the legal channel numbers.
* Channel numbers are 0-based.
*
* @param channel The analog output channel number.
* @return Analog channel is valid
*/
HAL_Bool HAL_CheckAnalogInputChannel(int32_t channel);
/**
* Set the sample rate.
*
* This is a global setting for the Athena and effects all channels.
*
* @param samplesPerSecond The number of samples per channel per second.
*/
void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status);
/**
* Get the current sample rate.
*
* This assumes one entry in the scan list.
* This is a global setting for the Athena and effects all channels.
*
* @return Sample rate.
*/
double HAL_GetAnalogSampleRate(int32_t* status);
/**
* Set the number of averaging bits.
*
* This sets the number of averaging bits. The actual number of averaged samples
* is 2**bits. Use averaging to improve the stability of your measurement at the
* expense of sampling rate. The averaging is done automatically in the FPGA.
*
* @param analogPortHandle Handle to the analog port to configure.
* @param bits Number of bits to average.
*/
void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
int32_t bits, int32_t* status);
/**
* Get the number of averaging bits.
*
* This gets the number of averaging bits from the FPGA. The actual number of
* averaged samples is 2**bits. The averaging is done automatically in the FPGA.
*
* @param analogPortHandle Handle to the analog port to use.
* @return Bits to average.
*/
int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
/**
* Set the number of oversample bits.
*
* This sets the number of oversample bits. The actual number of oversampled
* values is 2**bits. Use oversampling to improve the resolution of your
* measurements at the expense of sampling rate. The oversampling is done
* automatically in the FPGA.
*
* @param analogPortHandle Handle to the analog port to use.
* @param bits Number of bits to oversample.
*/
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
int32_t bits, int32_t* status);
/**
* Get the number of oversample bits.
*
* This gets the number of oversample bits from the FPGA. The actual number of
* oversampled values is 2**bits. The oversampling is done automatically in the
* FPGA.
*
* @param analogPortHandle Handle to the analog port to use.
* @return Bits to oversample.
*/
int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
/**
* Get a sample straight from the channel on this module.
*
* The sample is a 12-bit value representing the 0V to 5V range of the A/D
* converter in the module. The units are in A/D converter codes. Use
* GetVoltage() to get the analog value in calibrated units.
*
* @param analogPortHandle Handle to the analog port to use.
* @return A sample straight from the channel on this module.
*/
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
/**
* Get a sample from the output of the oversample and average engine for the
* channel.
*
* The sample is 12-bit + the value configured in SetOversampleBits().
* The value configured in SetAverageBits() will cause this value to be averaged
* 2**bits number of samples. This is not a sliding window. The sample will not
* change until 2**(OversamplBits + AverageBits) samples have been acquired from
* the module on this channel. Use GetAverageVoltage() to get the analog value
* in calibrated units.
*
* @param analogPortHandle Handle to the analog port to use.
* @return A sample from the oversample and average engine for the channel.
*/
int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
/**
* Convert a voltage to a raw value for a specified channel.
*
* This process depends on the calibration of each channel, so the channel must
* be specified.
*
* @todo This assumes raw values. Oversampling not supported as is.
*
* @param analogPortHandle Handle to the analog port to use.
* @param voltage The voltage to convert.
* @return The raw value for the channel.
*/
int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle,
double voltage, int32_t* status);
/**
* Get a scaled sample straight from the channel on this module.
*
* The value is scaled to units of Volts using the calibrated scaling data from
* GetLSBWeight() and GetOffset().
*
* @param analogPortHandle Handle to the analog port to use.
* @return A scaled sample straight from the channel on this module.
*/
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
/**
* Get a scaled sample from the output of the oversample and average engine for
* the channel.
*
* The value is scaled to units of Volts using the calibrated scaling data from
* GetLSBWeight() and GetOffset(). Using oversampling will cause this value to
* be higher resolution, but it will update more slowly. Using averaging will
* cause this value to be more stable, but it will update more slowly.
*
* @param analogPortHandle Handle to the analog port to use.
* @return A scaled sample from the output of the oversample and average engine
* for the channel.
*/
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
/**
* Get the factory scaling least significant bit weight constant.
* The least significant bit weight constant for the channel that was calibrated
* in manufacturing and stored in an eeprom in the module.
*
* Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
*
* @param analogPortHandle Handle to the analog port to use.
* @return Least significant bit weight.
*/
int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
/**
* Get the factory scaling offset constant.
* The offset constant for the channel that was calibrated in manufacturing and
* stored in an eeprom in the module.
*
* Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
*
* @param analogPortHandle Handle to the analog port to use.
* @return Offset constant.
*/
int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
#ifdef __cplusplus

View File

@@ -15,13 +15,27 @@
extern "C" {
#endif
/**
* Initialize the analog output port using the given port object.
*/
HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle,
int32_t* status);
void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analogOutputHandle);
void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
double voltage, int32_t* status);
double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
int32_t* status);
/**
* Check that the analog output channel number is value.
* Verify that the analog channel number is one of the legal channel numbers.
* Channel numbers are 0-based.
*
* @return Analog channel is valid
*/
HAL_Bool HAL_CheckAnalogOutputChannel(int32_t channel);
#ifdef __cplusplus
} // extern "C"

View File

@@ -28,17 +28,54 @@ void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle,
void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle,
int32_t lower, int32_t upper,
int32_t* status);
/**
* Set the upper and lower limits of the analog trigger.
* The limits are given as floating point voltage values.
*/
void HAL_SetAnalogTriggerLimitsVoltage(
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
int32_t* status);
/**
* Configure the analog trigger to use the averaged vs. raw values.
* If the value is true, then the averaged value is selected for the analog
* trigger, otherwise the immediate value is used.
*/
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_Bool useAveragedValue, int32_t* status);
/**
* Configure the analog trigger to use a filtered value.
* The analog trigger will operate with a 3 point average rejection filter. This
* is designed to help with 360 degree pot applications for the period where the
* pot crosses through zero.
*/
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_Bool useFilteredValue, int32_t* status);
/**
* Return the InWindow output of the analog trigger.
* True if the analog input is between the upper and lower limits.
* @return The InWindow output of the analog trigger.
*/
HAL_Bool HAL_GetAnalogTriggerInWindow(
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status);
/**
* Return the TriggerState output of the analog trigger.
* True if above upper limit.
* False if below lower limit.
* If in Hysteresis, maintain previous state.
* @return The TriggerState output of the analog trigger.
*/
HAL_Bool HAL_GetAnalogTriggerTriggerState(
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status);
/**
* Get the state of the analog trigger output.
* @return The state of the analog trigger output.
*/
HAL_Bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_AnalogTriggerType type,
int32_t* status);

View File

@@ -27,45 +27,174 @@ HAL_CounterHandle HAL_InitializeCounter(HAL_Counter_Mode mode, int32_t* index,
void HAL_FreeCounter(HAL_CounterHandle counterHandle, int32_t* status);
void HAL_SetCounterAverageSize(HAL_CounterHandle counterHandle, int32_t size,
int32_t* status);
/**
* Set the source object that causes the counter to count up.
* Set the up counting DigitalSource.
*/
void HAL_SetCounterUpSource(HAL_CounterHandle counterHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status);
/**
* Set the edge sensitivity on an up counting source.
* Set the up source to either detect rising edges or falling edges.
*/
void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counterHandle,
HAL_Bool risingEdge, HAL_Bool fallingEdge,
int32_t* status);
/**
* Disable the up counting source to the counter.
*/
void HAL_ClearCounterUpSource(HAL_CounterHandle counterHandle, int32_t* status);
/**
* Set the source object that causes the counter to count down.
* Set the down counting DigitalSource.
*/
void HAL_SetCounterDownSource(HAL_CounterHandle counterHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status);
/**
* Set the edge sensitivity on a down counting source.
* Set the down source to either detect rising edges or falling edges.
*/
void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counterHandle,
HAL_Bool risingEdge, HAL_Bool fallingEdge,
int32_t* status);
/**
* Disable the down counting source to the counter.
*/
void HAL_ClearCounterDownSource(HAL_CounterHandle counterHandle,
int32_t* status);
/**
* Set standard up / down counting mode on this counter.
* Up and down counts are sourced independently from two inputs.
*/
void HAL_SetCounterUpDownMode(HAL_CounterHandle counterHandle, int32_t* status);
/**
* Set standard up / down counting mode on this counter.
* Up and down counts are sourced independently from two inputs.
*/
void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counterHandle,
int32_t* status);
/**
* Set Semi-period mode on this counter.
* Counts up on both rising and falling edges.
*/
void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counterHandle,
HAL_Bool highSemiPeriod, int32_t* status);
/**
* Configure the counter to count in up or down based on the length of the input
* pulse.
* This mode is most useful for direction sensitive gear tooth sensors.
* @param threshold The pulse length beyond which the counter counts the
* opposite direction. Units are seconds.
*/
void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counterHandle,
double threshold, int32_t* status);
/**
* Get the Samples to Average which specifies the number of samples of the timer
* to
* average when calculating the period. Perform averaging to account for
* mechanical imperfections or as oversampling to increase resolution.
* @return SamplesToAverage The number of samples being averaged (from 1 to 127)
*/
int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
int32_t* status);
/**
* Set the Samples to Average which specifies the number of samples of the timer
* to average when calculating the period. Perform averaging to account for
* mechanical imperfections or as oversampling to increase resolution.
* @param samplesToAverage The number of samples to average from 1 to 127.
*/
void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
int32_t samplesToAverage, int32_t* status);
/**
* Reset the Counter to zero.
* Set the counter value to zero. This doesn't effect the running state of the
* counter, just sets the current value to zero.
*/
void HAL_ResetCounter(HAL_CounterHandle counterHandle, int32_t* status);
/**
* Read the current counter value.
* 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 HAL_GetCounter(HAL_CounterHandle counterHandle, int32_t* status);
/*
* Get the Period of the most recent count.
* Returns the time interval of the most recent count. This can be used for
* velocity calculations to determine shaft speed.
* @returns The period of the last two pulses in units of seconds.
*/
double HAL_GetCounterPeriod(HAL_CounterHandle counterHandle, int32_t* status);
/**
* Set the maximum period where the device is still considered "moving".
* Sets the maximum period where the device is considered moving. This value is
* used to determine the "stopped" state of the counter using the GetStopped
* method.
* @param maxPeriod The maximum period where the counted device is considered
* moving in seconds.
*/
void HAL_SetCounterMaxPeriod(HAL_CounterHandle counterHandle, double maxPeriod,
int32_t* status);
/**
* Select whether you want to continue updating the event timer output when
* there are no samples captured. The output of the event timer has a buffer of
* periods that are averaged and posted to a register on the FPGA. When the
* timer detects that the event source has stopped (based on the MaxPeriod) the
* buffer of samples to be averaged is emptied. If you enable the update when
* empty, you will be notified of the stopped source and the event time will
* report 0 samples. If you disable update when empty, the most recent average
* will remain on the output until a new sample is acquired. You will never see
* 0 samples output (except when there have been no events since an FPGA reset)
* 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 HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counterHandle,
HAL_Bool enabled, int32_t* status);
/**
* Determine if the clock is stopped.
* Determine if the clocked input is stopped based on the MaxPeriod value set
* using the SetMaxPeriod method. If the clock exceeds the MaxPeriod, then the
* device (and counter) are assumed to be stopped and it returns true.
* @return Returns true if the most recent counter period exceeds the MaxPeriod
* value set by SetMaxPeriod.
*/
HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counterHandle,
int32_t* status);
/**
* The last direction the counter value changed.
* @return The last direction the counter value changed.
*/
HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counterHandle,
int32_t* status);
/**
* Set the Counter to return reversed sensing on the direction.
* This allows counters to change the direction they are counting in the case of
* 1X and 2X quadrature encoding only. Any other counter mode isn't supported.
* @param reverseDirection true if the value counted should be negated.
*/
void HAL_SetCounterReverseDirection(HAL_CounterHandle counterHandle,
HAL_Bool reverseDirection, int32_t* status);
#ifdef __cplusplus

View File

@@ -15,32 +15,169 @@
extern "C" {
#endif
/**
* Create a new instance of a digital port.
*/
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
HAL_Bool input, int32_t* status);
HAL_Bool HAL_CheckDIOChannel(int32_t channel);
void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle);
/**
* Allocate a DO PWM Generator.
* Allocate PWM generators so that they are not accidentally reused.
*
* @return PWM Generator handle
*/
HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status);
/**
* Free the resource associated with a DO PWM generator.
*
* @param pwmGenerator The pwmGen to free that was allocated with
* allocateDigitalPWM()
*/
void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status);
/**
* Change the frequency of the DO PWM generator.
*
* The valid range is from 0.6 Hz to 19 kHz. The frequency resolution is
* logarithmic.
*
* @param rate The frequency to output all digital output PWM signals.
*/
void HAL_SetDigitalPWMRate(double rate, int32_t* status);
/**
* Configure the duty-cycle of the PWM generator
*
* @param pwmGenerator The generator index reserved by allocateDigitalPWM()
* @param dutyCycle The percent duty cycle to output [0..1].
*/
void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
double dutyCycle, int32_t* status);
/**
* Configure which DO channel the PWM signal is output on
*
* @param pwmGenerator The generator index reserved by allocateDigitalPWM()
* @param channel The Digital Output channel to output on
*/
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
int32_t channel, int32_t* status);
/**
* Write a digital I/O bit to the FPGA.
* Set a single value on a digital I/O channel.
*
* @param channel The Digital I/O channel
* @param value The state to set the digital channel (if it is configured as an
* output)
*/
void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
int32_t* status);
/**
* Set direction of a DIO channel.
*
* @param channel The Digital I/O channel
* @param input true to set input, false for output
*/
void HAL_SetDIODirection(HAL_DigitalHandle dioPortHandle, HAL_Bool input,
int32_t* status);
/**
* Read a digital I/O bit from the FPGA.
* Get a single value from a digital I/O channel.
*
* @param channel The digital I/O channel
* @return The state of the specified channel
*/
HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status);
/**
* Read the direction of a the Digital I/O lines
* A 1 bit means output and a 0 bit means input.
*
* @param channel The digital I/O channel
* @return The direction of the specified channel
*/
HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status);
/**
* Generate a single pulse.
* Write a pulse to the specified digital output channel. There can only be a
* single pulse going at any time.
*
* @param channel The Digital Output channel that the pulse should be output on
* @param pulseLength The active length of the pulse (in seconds)
*/
void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
int32_t* status);
/**
* Check a DIO line to see if it is currently generating a pulse.
*
* @return A pulse is in progress
*/
HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status);
/**
* Check if any DIO line is currently generating a pulse.
*
* @return A pulse on some line is in progress
*/
HAL_Bool HAL_IsAnyPulsing(int32_t* status);
/**
* Write the filter index from the FPGA.
* Set the filter index used to filter out short pulses.
*
* @param dioPortHandle Handle to the digital I/O channel
* @param filterIndex The filter index. Must be in the range 0 - 3, where 0
* means "none" and 1 - 3 means filter # filterIndex - 1.
*/
void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
int32_t* status);
/**
* Read the filter index from the FPGA.
* Get the filter index used to filter out short pulses.
*
* @param dioPortHandle Handle to the digital I/O channel
* @return filterIndex The filter index. Must be in the range 0 - 3,
* where 0 means "none" and 1 - 3 means filter # filterIndex - 1.
*/
int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status);
/**
* Set the filter period for the specified filter index.
*
* Set the filter period in FPGA cycles. Even though there are 2 different
* filter index domains (MXP vs HDR), ignore that distinction for now since it
* compilicates the interface. That can be changed later.
*
* @param filterIndex The filter index, 0 - 2.
* @param value The number of cycles that the signal must not transition to be
* counted as a transition.
*/
void HAL_SetFilterPeriod(int32_t filterIndex, int64_t value, int32_t* status);
/**
* Get the filter period for the specified filter index.
*
* Get the filter period in FPGA cycles. Even though there are 2 different
* filter index domains (MXP vs HDR), ignore that distinction for now since it
* compilicates the interface. Set status to NiFpga_Status_SoftwareFault if the
* filter values miss-match.
*
* @param filterIndex The filter index, 0 - 2.
* @param value The number of cycles that the signal must not transition to be
* counted as a transition.
*/
int64_t HAL_GetFilterPeriod(int32_t filterIndex, int32_t* status);
#ifdef __cplusplus
} // extern "C"

View File

@@ -108,8 +108,21 @@ int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes);
int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs);
int32_t HAL_GetJoystickButtons(int32_t joystickNum,
HAL_JoystickButtons* buttons);
/**
* Retrieve the Joystick Descriptor for particular slot
* @param desc [out] descriptor (data transfer object) to fill in. desc is
* filled in regardless of success. In other words, if descriptor is not
* available, desc is filled in with default values matching the init-values in
* Java and C++ Driverstation for when caller requests a too-large joystick
* index.
*
* @return error code reported from Network Comm back-end. Zero is good,
* nonzero is bad.
*/
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
HAL_JoystickDescriptor* desc);
HAL_Bool HAL_GetJoystickIsXbox(int32_t joystickNum);
int32_t HAL_GetJoystickType(int32_t joystickNum);
char* HAL_GetJoystickName(int32_t joystickNum);
@@ -124,10 +137,31 @@ void HAL_FreeMatchInfo(HAL_MatchInfo* info);
#ifndef HAL_USE_LABVIEW
/**
* Releases the DS Mutex to allow proper shutdown of any threads that are
* waiting on it.
*/
void HAL_ReleaseDSMutex(void);
bool HAL_IsNewControlData(void);
/**
* Waits for the newest DS packet to arrive. Note that this is a blocking call.
*/
void HAL_WaitForDSData(void);
/**
* Waits for the newest DS packet to arrive. If timeout is <= 0, this will wait
* forever. Otherwise, it will wait until either a new packet, or the timeout
* time has passed. Returns true on new data, false on timeout.
*/
HAL_Bool HAL_WaitForDSDataTimeout(double timeout);
/**
* Call this to initialize the driver station communication. This will properly
* handle multiple calls. However note that this CANNOT be called from a library
* that interfaces with LabVIEW.
*/
void HAL_InitializeDriverStation(void);
void HAL_ObserveUserProgramStarting(void);

View File

@@ -21,5 +21,10 @@ typedef int halsim_extension_init_func_t(void);
extern "C" {
int HAL_LoadOneExtension(const char* library);
/**
* Load any extra halsim libraries provided in the HALSIM_EXTENSIONS
* environment variable.
*/
int HAL_LoadExtensions(void);
} // extern "C"

View File

@@ -51,10 +51,29 @@ extern "C" {
const char* HAL_GetErrorMessage(int32_t code);
/**
* Return the FPGA Version number.
* For now, expect this to be competition year.
* @return FPGA Version number.
*/
int32_t HAL_GetFPGAVersion(int32_t* status);
/**
* Return the FPGA Revision number.
* The format of the revision is 3 numbers.
* The 12 most significant bits are the Major Revision.
* the next 8 bits are the Minor Revision.
* The 12 least significant bits are the Build Number.
* @return FPGA Revision number.
*/
int64_t HAL_GetFPGARevision(int32_t* status);
HAL_RuntimeType HAL_GetRuntimeType(void);
/**
* Get the state of the "USER" button on the roboRIO
* @return true if the button is currently pressed down
*/
HAL_Bool HAL_GetFPGAButton(int32_t* status);
HAL_Bool HAL_GetSystemActive(int32_t* status);
@@ -65,10 +84,23 @@ void HAL_BaseInitialize(int32_t* status);
#ifndef HAL_USE_LABVIEW
HAL_PortHandle HAL_GetPort(int32_t channel);
/**
* @deprecated Uses module numbers
*/
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel);
/**
* Read the microsecond-resolution timer on the FPGA.
*
* @return The current time in microseconds according to the FPGA (since FPGA
* reset).
*/
uint64_t HAL_GetFPGATime(int32_t* status);
/**
* Call this to start up HAL. This is required for robot programs.
*/
HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode);
// ifdef's definition is to allow for default parameters in C++.

View File

@@ -15,14 +15,59 @@ enum HAL_I2CPort : int32_t { HAL_I2C_kOnboard = 0, HAL_I2C_kMXP };
extern "C" {
#endif
/**
* Initialize the I2C port. Opens the port if necessary and saves the handle.
* If opening the MXP port, also sets up the channel functions appropriately
* @param port The port to open, 0 for the on-board, 1 for the MXP.
*/
void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status);
/**
* Generic transaction.
*
* This is a lower-level interface to the I2C hardware giving you more control
* over each transaction.
*
* @param dataToSend Buffer of data to send as part of the transaction.
* @param sendSize Number of bytes to send as part of the transaction.
* @param dataReceived Buffer to read data into.
* @param receiveSize Number of bytes to read from the device.
* @return >= 0 on success or -1 on transfer abort.
*/
int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
const uint8_t* dataToSend, int32_t sendSize,
uint8_t* dataReceived, int32_t receiveSize);
/**
* Execute a write transaction with the device.
*
* Write a single byte to a register on a device and wait until the
* transaction is complete.
*
* @param registerAddress The address of the register on the device to be
* written.
* @param data The byte to write to the register on the device.
* @return >= 0 on success or -1 on transfer abort.
*/
int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress,
const uint8_t* dataToSend, int32_t sendSize);
/**
* Execute a read transaction with the device.
*
* Read bytes from a device.
* Most I2C devices will auto-increment the register pointer internally allowing
* you to read consecutive registers on a device in a single transaction.
*
* @param registerAddress The register to read first in the transaction.
* @param count The number of bytes to read in the transaction.
* @param buffer A pointer to the array of bytes to store the data read from the
* device.
* @return >= 0 on success or -1 on transfer abort.
*/
int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer,
int32_t count);
void HAL_CloseI2C(HAL_I2CPort port);
#ifdef __cplusplus
} // extern "C"

View File

@@ -22,16 +22,47 @@ typedef void (*HAL_InterruptHandlerFunction)(uint32_t interruptAssertedMask,
HAL_InterruptHandle HAL_InitializeInterrupts(HAL_Bool watcher, int32_t* status);
void* HAL_CleanInterrupts(HAL_InterruptHandle interruptHandle, int32_t* status);
/**
* In synchronous mode, wait for the defined interrupt to occur.
* @param timeout Timeout in seconds
* @param ignorePrevious If true, ignore interrupts that happened before
* waitForInterrupt was called.
* @return The mask of interrupts that fired.
*/
int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interruptHandle,
double timeout, HAL_Bool ignorePrevious,
int32_t* status);
/**
* Enable interrupts to occur on this input.
* Interrupts are disabled when the RequestInterrupt call is made. This gives
* time to do the setup of the other options before starting to field
* interrupts.
*/
void HAL_EnableInterrupts(HAL_InterruptHandle interruptHandle, int32_t* status);
/**
* Disable Interrupts without without deallocating structures.
*/
void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
int32_t* status);
/**
* Return the timestamp for the rising interrupt that occurred most recently.
* This is in the same time domain as GetClock().
* @return Timestamp in seconds since boot.
*/
double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle,
int32_t* status);
/**
* Return the timestamp for the falling interrupt that occurred most recently.
* This is in the same time domain as GetClock().
* @return Timestamp in seconds since boot.
*/
double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle,
int32_t* status);
void HAL_RequestInterrupts(HAL_InterruptHandle interruptHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,

View File

@@ -36,20 +36,91 @@ void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
HAL_Bool eliminateDeadband, int32_t* status);
HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
int32_t* status);
/**
* Set a PWM channel to the desired value. The values range from 0 to 255 and
* the period is controlled
* by the PWM Period and MinHigh registers.
*
* @param channel The PWM channel to set.
* @param value The PWM value to set.
*/
void HAL_SetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t value,
int32_t* status);
/**
* Set a PWM channel to the desired scaled value. The values range from -1 to 1
* and
* the period is controlled
* by the PWM Period and MinHigh registers.
*
* @param channel The PWM channel to set.
* @param value The scaled PWM value to set.
*/
void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
int32_t* status);
/**
* Set a PWM channel to the desired position value. The values range from 0 to 1
* and
* the period is controlled
* by the PWM Period and MinHigh registers.
*
* @param channel The PWM channel to set.
* @param value The scaled PWM value to set.
*/
void HAL_SetPWMPosition(HAL_DigitalHandle pwmPortHandle, double position,
int32_t* status);
void HAL_SetPWMDisabled(HAL_DigitalHandle pwmPortHandle, int32_t* status);
/**
* Get a value from a PWM channel. The values range from 0 to 255.
*
* @param channel The PWM channel to read from.
* @return The raw PWM value.
*/
int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t* status);
/**
* Get a scaled value from a PWM channel. The values range from -1 to 1.
*
* @param channel The PWM channel to read from.
* @return The scaled PWM value.
*/
double HAL_GetPWMSpeed(HAL_DigitalHandle pwmPortHandle, int32_t* status);
/**
* Get a position value from a PWM channel. The values range from 0 to 1.
*
* @param channel The PWM channel to read from.
* @return The scaled PWM value.
*/
double HAL_GetPWMPosition(HAL_DigitalHandle pwmPortHandle, int32_t* status);
void HAL_LatchPWMZero(HAL_DigitalHandle pwmPortHandle, int32_t* status);
/**
* Set how how often the PWM signal is squelched, thus scaling the period.
*
* @param channel The PWM channel to configure.
* @param squelchMask The 2-bit mask of outputs to squelch.
*/
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwmPortHandle, int32_t squelchMask,
int32_t* status);
/**
* Get the loop timing of the PWM system
*
* @return The loop time
*/
int32_t HAL_GetPWMLoopTiming(int32_t* status);
/**
* Get the pwm starting cycle time
*
* @return The pwm cycle start time.
*/
uint64_t HAL_GetPWMCycleStartTime(int32_t* status);
#ifdef __cplusplus
} // extern "C"

View File

@@ -15,19 +15,74 @@
extern "C" {
#endif
/**
* Get the roboRIO input voltage
*/
double HAL_GetVinVoltage(int32_t* status);
/**
* Get the roboRIO input current
*/
double HAL_GetVinCurrent(int32_t* status);
/**
* Get the 6V rail voltage
*/
double HAL_GetUserVoltage6V(int32_t* status);
/**
* Get the 6V rail current
*/
double HAL_GetUserCurrent6V(int32_t* status);
/**
* Get the active state of the 6V rail
*/
HAL_Bool HAL_GetUserActive6V(int32_t* status);
/**
* Get the fault count for the 6V rail
*/
int32_t HAL_GetUserCurrentFaults6V(int32_t* status);
/**
* Get the 5V rail voltage
*/
double HAL_GetUserVoltage5V(int32_t* status);
/**
* Get the 5V rail current
*/
double HAL_GetUserCurrent5V(int32_t* status);
/**
* Get the active state of the 5V rail
*/
HAL_Bool HAL_GetUserActive5V(int32_t* status);
/**
* Get the fault count for the 5V rail
*/
int32_t HAL_GetUserCurrentFaults5V(int32_t* status);
/**
* Get the 3.3V rail voltage
*/
double HAL_GetUserVoltage3V3(int32_t* status);
/**
* Get the 3.3V rail current
*/
double HAL_GetUserCurrent3V3(int32_t* status);
/**
* Get the active state of the 3.3V rail
*/
HAL_Bool HAL_GetUserActive3V3(int32_t* status);
/**
* Get the fault count for the 3.3V rail
*/
int32_t HAL_GetUserCurrentFaults3V3(int32_t* status);
#ifdef __cplusplus
} // extern "C"

View File

@@ -21,8 +21,16 @@ void HAL_FreeRelayPort(HAL_RelayHandle relayPortHandle);
HAL_Bool HAL_CheckRelayChannel(int32_t channel);
/**
* Set the state of a relay.
* Set the state of a relay output.
*/
void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
int32_t* status);
/**
* Get the current state of the relay channel
*/
HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status);
#ifdef __cplusplus
} // extern "C"

View File

@@ -24,36 +24,138 @@ enum HAL_SPIPort : int32_t {
extern "C" {
#endif
/**
* Initialize the spi port. Opens the port if necessary and saves the handle.
* If opening the MXP port, also sets up the channel functions appropriately
* @param port The number of the port to use. 0-3 for Onboard CS0-CS3, 4 for MXP
*/
void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status);
/**
* Generic transaction.
*
* This is a lower-level interface to the spi hardware giving you more control
* over each transaction.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
* @param dataToSend Buffer of data to send as part of the transaction.
* @param dataReceived Buffer to read data into.
* @param size Number of bytes to transfer. [0..7]
* @return Number of bytes transferred, -1 for error
*/
int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t* dataToSend,
uint8_t* dataReceived, int32_t size);
/**
* Execute a write transaction with the device.
*
* Write to a device and wait until the transaction is complete.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
* @param datToSend The data to write to the register on the device.
* @param sendSize The number of bytes to be written
* @return The number of bytes written. -1 for an error
*/
int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t sendSize);
/**
* Execute a read from the device.
*
* This method does not write any data out to the device
* Most spi devices will require a register address to be written before
* they begin returning data
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
* @param buffer A pointer to the array of bytes to store the data read from the
* device.
* @param count The number of bytes to read in the transaction. [1..7]
* @return Number of bytes read. -1 for error.
*/
int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count);
/**
* Close the SPI port
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
*/
void HAL_CloseSPI(HAL_SPIPort port);
/**
* Set the clock speed for the SPI bus.
*
* @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 HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed);
/**
* Set the SPI options
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
* @param msbFirst True to write the MSB first, False for LSB first
* @param sampleOnTrailing True to sample on the trailing edge, False to sample
* on the leading edge
* @param clkIdleHigh True to set the clock to active low, False to set the
* clock active high
*/
void HAL_SetSPIOpts(HAL_SPIPort port, HAL_Bool msbFirst,
HAL_Bool sampleOnTrailing, HAL_Bool clkIdleHigh);
/**
* Set the CS Active high for a SPI port
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
*/
void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status);
/**
* Set the CS Active low for a SPI port
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
*/
void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t* status);
/**
* Get the stored handle for a SPI port
*
* @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 HAL_GetSPIHandle(HAL_SPIPort port);
/**
* Set the stored handle for a SPI port
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for
* MXP.
* @param handle The value of the handle for the port.
*/
void HAL_SetSPIHandle(HAL_SPIPort port, int32_t handle);
void HAL_InitSPIAuto(HAL_SPIPort port, int32_t bufferSize, int32_t* status);
void HAL_FreeSPIAuto(HAL_SPIPort port, int32_t* status);
void HAL_StartSPIAutoRate(HAL_SPIPort port, double period, int32_t* status);
void HAL_StartSPIAutoTrigger(HAL_SPIPort port, HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
HAL_Bool triggerRising, HAL_Bool triggerFalling,
int32_t* status);
void HAL_StopSPIAuto(HAL_SPIPort port, int32_t* status);
void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t dataSize, int32_t zeroSize,
int32_t* status);
void HAL_ForceSPIAutoRead(HAL_SPIPort port, int32_t* status);
int32_t HAL_ReadSPIAutoReceivedData(HAL_SPIPort port, uint8_t* buffer,
int32_t numToRead, double timeout,
int32_t* status);
int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status);
#ifdef __cplusplus

View File

@@ -18,11 +18,54 @@
#include "HAL/Types.h"
extern "C" {
/**
* Get the thread priority for the specified thread.
*
* @param handle Native handle pointer to the thread to get the priority for
* @param isRealTime Set to true if thread is realtime, otherwise false
* @param status Error status variable. 0 on success
* @return The current thread priority. Scaled 1-99, with 1 being highest.
*/
int32_t HAL_GetThreadPriority(NativeThreadHandle handle, HAL_Bool* isRealTime,
int32_t* status);
/**
* Get the thread priority for the current thread.
*
* @param handle Native handle pointer to the thread to get the priority for
* @param isRealTime Set to true if thread is realtime, otherwise false
* @param status Error status variable. 0 on success
* @return The current thread priority. Scaled 1-99, with 1 being highest.
*/
int32_t HAL_GetCurrentThreadPriority(HAL_Bool* isRealTime, int32_t* status);
/**
* Sets the thread priority for the specified thread
*
* @param thread Reference to the thread to set the priority of
* @param realTime Set to true to set a realtime priority, false for standard
* priority
* @param priority Priority to set the thread to. Scaled 1-99, with 1 being
* highest
* @param status Error status variable. 0 on success
*
* @return The success state of setting the priority
*/
HAL_Bool HAL_SetThreadPriority(NativeThreadHandle handle, HAL_Bool realTime,
int32_t priority, int32_t* status);
/**
* Sets the thread priority for the current thread
*
* @param thread Reference to the thread to set the priority of
* @param realTime Set to true to set a realtime priority, false for standard
* priority
* @param priority Priority to set the thread to. Scaled 1-99, with 1 being
* highest
* @param status Error status variable. 0 on success
*
* @return The success state of setting the priority
*/
HAL_Bool HAL_SetCurrentThreadPriority(HAL_Bool realTime, int32_t priority,
int32_t* status);
} // extern "C"

View File

@@ -37,9 +37,6 @@ void InitializeDIO() {
extern "C" {
/**
* Create a new instance of a digital port.
*/
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
HAL_Bool input, int32_t* status) {
hal::init::CheckInit();
@@ -84,12 +81,6 @@ void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
SimDIOData[port->channel].SetInitialized(true);
}
/**
* Allocate a DO PWM Generator.
* Allocate PWM generators so that they are not accidentally reused.
*
* @return PWM Generator handle
*/
HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
auto handle = digitalPWMHandles->Allocate();
if (handle == HAL_kInvalidHandle) {
@@ -109,12 +100,6 @@ HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
return handle;
}
/**
* Free the resource associated with a DO PWM generator.
*
* @param pwmGenerator The pwmGen to free that was allocated with
* allocateDigitalPWM()
*/
void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status) {
auto port = digitalPWMHandles->Get(pwmGenerator);
digitalPWMHandles->Free(pwmGenerator);
@@ -123,14 +108,6 @@ void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status) {
SimDigitalPWMData[id].SetInitialized(false);
}
/**
* Change the frequency of the DO PWM generator.
*
* The valid range is from 0.6 Hz to 19 kHz. The frequency resolution is
* logarithmic.
*
* @param rate The frequency to output all digital output PWM signals.
*/
void HAL_SetDigitalPWMRate(double rate, int32_t* status) {
// Currently rounding in the log rate domain... heavy weight toward picking a
// higher freq.
@@ -143,12 +120,6 @@ void HAL_SetDigitalPWMRate(double rate, int32_t* status) {
// digitalSystem->writePWMPeriodPower(pwmPeriodPower, status);
}
/**
* Configure the duty-cycle of the PWM generator
*
* @param pwmGenerator The generator index reserved by allocateDigitalPWM()
* @param dutyCycle The percent duty cycle to output [0..1].
*/
void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
double dutyCycle, int32_t* status) {
auto port = digitalPWMHandles->Get(pwmGenerator);
@@ -162,12 +133,6 @@ void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
SimDigitalPWMData[id].SetDutyCycle(dutyCycle);
}
/**
* Configure which DO channel the PWM signal is output on
*
* @param pwmGenerator The generator index reserved by allocateDigitalPWM()
* @param channel The Digital Output channel to output on
*/
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
int32_t channel, int32_t* status) {
auto port = digitalPWMHandles->Get(pwmGenerator);
@@ -179,14 +144,6 @@ void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
SimDigitalPWMData[id].SetPin(channel);
}
/**
* Write a digital I/O bit to the FPGA.
* Set a single value on a digital I/O channel.
*
* @param channel The Digital I/O channel
* @param value The state to set the digital channel (if it is configured as an
* output)
*/
void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
@@ -200,12 +157,6 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
SimDIOData[port->channel].SetValue(value);
}
/**
* Set direction of a DIO channel.
*
* @param channel The Digital I/O channel
* @param input true to set input, false for output
*/
void HAL_SetDIODirection(HAL_DigitalHandle dioPortHandle, HAL_Bool input,
int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
@@ -217,13 +168,6 @@ void HAL_SetDIODirection(HAL_DigitalHandle dioPortHandle, HAL_Bool input,
SimDIOData[port->channel].SetIsInput(input);
}
/**
* Read a digital I/O bit from the FPGA.
* Get a single value from a digital I/O channel.
*
* @param channel The digital I/O channel
* @return The state of the specified channel
*/
HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
@@ -236,13 +180,6 @@ HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status) {
return value;
}
/**
* Read the direction of a the Digital I/O lines
* A 1 bit means output and a 0 bit means input.
*
* @param channel The digital I/O channel
* @return The direction of the specified channel
*/
HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
@@ -255,14 +192,6 @@ HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status) {
return value;
}
/**
* Generate a single pulse.
* Write a pulse to the specified digital output channel. There can only be a
* single pulse going at any time.
*
* @param channel The Digital Output channel that the pulse should be output on
* @param pulseLength The active length of the pulse (in seconds)
*/
void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
@@ -273,11 +202,6 @@ void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
// TODO (Thad) Add this
}
/**
* Check a DIO line to see if it is currently generating a pulse.
*
* @return A pulse is in progress
*/
HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
@@ -288,23 +212,10 @@ HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status) {
// TODO (Thad) Add this
}
/**
* Check if any DIO line is currently generating a pulse.
*
* @return A pulse on some line is in progress
*/
HAL_Bool HAL_IsAnyPulsing(int32_t* status) {
return false; // TODO(Thad) Figure this out
}
/**
* Write the filter index from the FPGA.
* Set the filter index used to filter out short pulses.
*
* @param dioPortHandle Handle to the digital I/O channel
* @param filterIndex The filter index. Must be in the range 0 - 3, where 0
* means "none" and 1 - 3 means filter # filterIndex - 1.
*/
void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
@@ -316,14 +227,6 @@ void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
// TODO(Thad) Figure this out
}
/**
* Read the filter index from the FPGA.
* Get the filter index used to filter out short pulses.
*
* @param dioPortHandle Handle to the digital I/O channel
* @return filterIndex The filter index. Must be in the range 0 - 3,
* where 0 means "none" and 1 - 3 means filter # filterIndex - 1.
*/
int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
@@ -334,33 +237,10 @@ int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
// TODO(Thad) Figure this out
}
/**
* Set the filter period for the specified filter index.
*
* Set the filter period in FPGA cycles. Even though there are 2 different
* filter index domains (MXP vs HDR), ignore that distinction for now since it
* compilicates the interface. That can be changed later.
*
* @param filterIndex The filter index, 0 - 2.
* @param value The number of cycles that the signal must not transition to be
* counted as a transition.
*/
void HAL_SetFilterPeriod(int32_t filterIndex, int64_t value, int32_t* status) {
// TODO(Thad) figure this out
}
/**
* Get the filter period for the specified filter index.
*
* Get the filter period in FPGA cycles. Even though there are 2 different
* filter index domains (MXP vs HDR), ignore that distinction for now since it
* compilicates the interface. Set status to NiFpga_Status_SoftwareFault if the
* filter values miss-match.
*
* @param filterIndex The filter index, 0 - 2.
* @param value The number of cycles that the signal must not transition to be
* counted as a transition.
*/
int64_t HAL_GetFilterPeriod(int32_t filterIndex, int32_t* status) {
return 0; // TODO(Thad) figure this out
}

View File

@@ -28,26 +28,6 @@ void InitializeDigitalInternal() {
}
} // namespace init
/**
* Map DIO channel numbers from their physical number (10 to 26) to their
* position in the bit field.
*/
int32_t remapMXPChannel(int32_t channel) { return channel - 10; }
int32_t remapMXPPWMChannel(int32_t channel) {
if (channel < 14) {
return channel - 10; // first block of 4 pwms (MXP 0-3)
} else {
return channel - 6; // block of PWMs after SPI
}
}
/**
* remap the digital source channel and set the module.
* If it's an analog trigger, determine the module from the high order routing
* channel else do normal digital input remapping based on channel number
* (MXP)
*/
bool remapDigitalSource(HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
uint8_t& channel, uint8_t& module,
@@ -75,6 +55,16 @@ bool remapDigitalSource(HAL_Handle digitalSourceHandle,
}
}
int32_t remapMXPChannel(int32_t channel) { return channel - 10; }
int32_t remapMXPPWMChannel(int32_t channel) {
if (channel < 14) {
return channel - 10; // first block of 4 pwms (MXP 0-3)
} else {
return channel - 6; // block of PWMs after SPI
}
}
int32_t GetDigitalInputChannel(HAL_DigitalHandle handle, int32_t* status) {
auto digital = digitalChannelHandles->Get(handle, HAL_HandleEnum::DIO);
if (digital == nullptr) {

View File

@@ -70,11 +70,24 @@ extern DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
kNumDigitalChannels + kNumPWMHeaders>*
digitalChannelHandles;
/**
* Remap the digital source channel and set the module.
*
* If it's an analog trigger, determine the module from the high order routing
* channel else do normal digital input remapping based on channel number
* (MXP).
*/
bool remapDigitalSource(HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
uint8_t& channel, uint8_t& module, bool& analogTrigger);
int32_t remapMXPPWMChannel(int32_t channel);
/**
* Map DIO channel numbers from their physical number (10 to 26) to their
* position in the bit field.
*/
int32_t remapMXPChannel(int32_t channel);
int32_t remapMXPPWMChannel(int32_t channel);
int32_t GetDigitalInputChannel(HAL_DigitalHandle handle, int32_t* status);
} // namespace hal

View File

@@ -124,17 +124,7 @@ int32_t HAL_GetJoystickButtons(int32_t joystickNum,
SimDriverStationData->GetJoystickButtons(joystickNum, buttons);
return 0;
}
/**
* Retrieve the Joystick Descriptor for particular slot
* @param desc [out] descriptor (data transfer object) to fill in. desc is
* filled in regardless of success. In other words, if descriptor is not
* available, desc is filled in with default values matching the init-values in
* Java and C++ Driverstation for when caller requests a too-large joystick
* index.
*
* @return error code reported from Network Comm back-end. Zero is good,
* nonzero is bad.
*/
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
HAL_JoystickDescriptor* desc) {
SimDriverStationData->GetJoystickDescriptor(joystickNum, desc);
@@ -241,16 +231,8 @@ bool HAL_IsNewControlData(void) {
return true;
}
/**
* Waits for the newest DS packet to arrive. Note that this is a blocking call.
*/
void HAL_WaitForDSData(void) { HAL_WaitForDSDataTimeout(0); }
/**
* Waits for the newest DS packet to arrive. If timeout is <= 0, this will wait
* forever. Otherwise, it will wait until either a new packet, or the timeout
* time has passed. Returns true on new data, false on timeout.
*/
HAL_Bool HAL_WaitForDSDataTimeout(double timeout) {
auto timeoutTime =
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
@@ -284,11 +266,6 @@ static int32_t newDataOccur(uint32_t refNum) {
return 0;
}
/*
* Call this to initialize the driver station communication. This will properly
* handle multiple calls. However note that this CANNOT be called from a library
* that interfaces with LabVIEW.
*/
void HAL_InitializeDriverStation(void) {
hal::init::CheckInit();
static std::atomic_bool initialized{false};
@@ -305,10 +282,6 @@ void HAL_InitializeDriverStation(void) {
initialized = true;
}
/*
* Releases the DS Mutex to allow proper shutdown of any threads that are
* waiting on it.
*/
void HAL_ReleaseDSMutex(void) { newDataOccur(refNumber); }
} // extern "C"

View File

@@ -67,10 +67,6 @@ int HAL_LoadOneExtension(const char* library) {
return rc;
}
/**
* Load any extra halsim libraries provided in the HALSIM_EXTENSIONS
* environment variable.
*/
int HAL_LoadExtensions(void) {
int rc = 1;
wpi::SmallVector<wpi::StringRef, 2> libraries;

View File

@@ -83,9 +83,6 @@ HAL_PortHandle HAL_GetPort(int32_t channel) {
return createPortHandle(channel, 1);
}
/**
* @deprecated Uses module numbers
*/
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel) {
// Dont allow a number that wouldn't fit in a uint8_t
if (channel < 0 || channel >= 255) return HAL_kInvalidHandle;
@@ -204,44 +201,18 @@ const char* HAL_GetErrorMessage(int32_t code) {
}
}
/**
* Returns the runtime type of this HAL
*/
HAL_RuntimeType HAL_GetRuntimeType(void) { return HAL_Mock; }
/**
* Return the FPGA Version number.
* For now, expect this to be competition year.
* @return FPGA Version number.
*/
int32_t HAL_GetFPGAVersion(int32_t* status) {
return 2018; // Automatically script this at some point
}
/**
* Return the FPGA Revision number.
* The format of the revision is 3 numbers.
* The 12 most significant bits are the Major Revision.
* the next 8 bits are the Minor Revision.
* The 12 least significant bits are the Build Number.
* @return FPGA Revision number.
*/
int64_t HAL_GetFPGARevision(int32_t* status) {
return 0; // TODO: Find a better number to return;
}
/**
* Read the microsecond-resolution timer on the FPGA.
*
* @return The current time in microseconds according to the FPGA (since FPGA
* reset).
*/
uint64_t HAL_GetFPGATime(int32_t* status) { return hal::GetFPGATime(); }
/**
* Get the state of the "USER" button on the roboRIO
* @return true if the button is currently pressed down
*/
HAL_Bool HAL_GetFPGAButton(int32_t* status) {
return SimRoboRioData[0].GetFPGAButton();
}

View File

@@ -166,14 +166,6 @@ HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
return port->eliminateDeadband;
}
/**
* Set a PWM channel to the desired value. The values range from 0 to 255 and
* the period is controlled
* by the PWM Period and MinHigh registers.
*
* @param channel The PWM channel to set.
* @param value The PWM value to set.
*/
void HAL_SetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t value,
int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
@@ -185,15 +177,6 @@ void HAL_SetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t value,
SimPWMData[port->channel].SetRawValue(value);
}
/**
* Set a PWM channel to the desired scaled value. The values range from -1 to 1
* and
* the period is controlled
* by the PWM Period and MinHigh registers.
*
* @param channel The PWM channel to set.
* @param value The scaled PWM value to set.
*/
void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
@@ -215,15 +198,6 @@ void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
SimPWMData[port->channel].SetSpeed(speed);
}
/**
* Set a PWM channel to the desired position value. The values range from 0 to 1
* and
* the period is controlled
* by the PWM Period and MinHigh registers.
*
* @param channel The PWM channel to set.
* @param value The scaled PWM value to set.
*/
void HAL_SetPWMPosition(HAL_DigitalHandle pwmPortHandle, double pos,
int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
@@ -256,12 +230,6 @@ void HAL_SetPWMDisabled(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
SimPWMData[port->channel].SetSpeed(0);
}
/**
* Get a value from a PWM channel. The values range from 0 to 255.
*
* @param channel The PWM channel to read from.
* @return The raw PWM value.
*/
int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
@@ -272,12 +240,6 @@ int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
return SimPWMData[port->channel].GetRawValue();
}
/**
* Get a scaled value from a PWM channel. The values range from -1 to 1.
*
* @param channel The PWM channel to read from.
* @return The scaled PWM value.
*/
double HAL_GetPWMSpeed(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
@@ -295,12 +257,6 @@ double HAL_GetPWMSpeed(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
return speed;
}
/**
* Get a position value from a PWM channel. The values range from 0 to 1.
*
* @param channel The PWM channel to read from.
* @return The scaled PWM value.
*/
double HAL_GetPWMPosition(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
@@ -329,12 +285,6 @@ void HAL_LatchPWMZero(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
SimPWMData[port->channel].SetZeroLatch(false);
}
/**
* Set how how often the PWM signal is squelched, thus scaling the period.
*
* @param channel The PWM channel to configure.
* @param squelchMask The 2-bit mask of outputs to squelch.
*/
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwmPortHandle, int32_t squelchMask,
int32_t* status) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
@@ -346,17 +296,7 @@ void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwmPortHandle, int32_t squelchMask,
SimPWMData[port->channel].SetPeriodScale(squelchMask);
}
/**
* Get the loop timing of the PWM system
*
* @return The loop time
*/
int32_t HAL_GetPWMLoopTiming(int32_t* status) { return kExpectedLoopTiming; }
/**
* Get the pwm starting cycle time
*
* @return The pwm cycle start time.
*/
uint64_t HAL_GetPWMCycleStartTime(int32_t* status) { return 0; }
} // extern "C"