Add DMA support to HAL and WPILibC (#2080)

This commit is contained in:
Thad House
2019-11-14 22:52:34 -08:00
committed by Peter Johnson
parent 8280b7e3af
commit 82b2170feb
22 changed files with 1672 additions and 2 deletions

View File

@@ -201,6 +201,14 @@ double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
return voltage;
}
double HAL_GetAnalogValueToVolts(HAL_AnalogInputHandle analogPortHandle,
int32_t rawValue, int32_t* status) {
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status);
int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status);
double voltage = LSBWeight * 1.0e-9 * rawValue - offset * 1.0e-9;
return voltage;
}
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
int32_t value = HAL_GetAnalogAverageValue(analogPortHandle, status);

File diff suppressed because it is too large Load Diff

View File

@@ -238,6 +238,19 @@ void InitializeEncoder() {
} // namespace init
} // namespace hal
namespace hal {
bool GetEncoderBaseHandle(HAL_EncoderHandle handle,
HAL_FPGAEncoderHandle* fpgaHandle,
HAL_CounterHandle* counterHandle) {
auto encoder = encoderHandles->Get(handle);
if (!handle) return false;
*fpgaHandle = encoder->m_encoder;
*counterHandle = encoder->m_counter;
return true;
}
} // namespace hal
extern "C" {
HAL_EncoderHandle HAL_InitializeEncoder(
HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -13,8 +13,16 @@
namespace hal {
bool GetEncoderBaseHandle(HAL_EncoderHandle handle,
HAL_FPGAEncoderHandle* fpgaEncoderHandle,
HAL_CounterHandle* counterHandle);
class Encoder {
public:
friend bool GetEncoderBaseHandle(HAL_EncoderHandle handle,
HAL_FPGAEncoderHandle* fpgaEncoderHandle,
HAL_CounterHandle* counterHandle);
Encoder(HAL_Handle digitalSourceHandleA,
HAL_AnalogTriggerType analogTriggerTypeA,
HAL_Handle digitalSourceHandleB,

View File

@@ -56,6 +56,7 @@ void InitializeHAL() {
InitializeCounter();
InitializeDigitalInternal();
InitializeDIO();
InitializeDMA();
InitializeDutyCycle();
InitializeEncoder();
InitializeFPGAEncoder();
@@ -256,6 +257,28 @@ uint64_t HAL_GetFPGATime(int32_t* status) {
return (upper2 << 32) + lower;
}
uint64_t HAL_ExpandFPGATime(uint32_t unexpanded_lower, int32_t* status) {
// Capture the current FPGA time. This will give us the upper half of the
// clock.
uint64_t fpga_time = HAL_GetFPGATime(status);
if (*status != 0) return 0;
// Now, we need to detect the case where the lower bits rolled over after we
// sampled. In that case, the upper bits will be 1 bigger than they should
// be.
// Break it into lower and upper portions.
uint32_t lower = fpga_time & 0xffffffffull;
uint64_t upper = (fpga_time >> 32) & 0xffffffff;
// The time was sampled *before* the current time, so roll it back.
if (lower < unexpanded_lower) {
--upper;
}
return (upper << 32) + static_cast<uint64_t>(unexpanded_lower);
}
HAL_Bool HAL_GetFPGAButton(int32_t* status) {
if (!global) {
*status = NiFpga_Status_ResourceNotInitialized;

View File

@@ -32,6 +32,7 @@ extern void InitializeConstants();
extern void InitializeCounter();
extern void InitializeDigitalInternal();
extern void InitializeDIO();
extern void InitializeDMA();
extern void InitializeDutyCycle();
extern void InitializeEncoder();
extern void InitializeFPGAEncoder();