2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-11-14 22:52:34 -08:00
|
|
|
|
|
|
|
|
#include "frc/DMA.h"
|
|
|
|
|
|
|
|
|
|
#include <hal/DMA.h>
|
|
|
|
|
#include <hal/HALBase.h>
|
|
|
|
|
|
2021-04-18 20:35:29 -07:00
|
|
|
#include "frc/AnalogInput.h"
|
|
|
|
|
#include "frc/Counter.h"
|
|
|
|
|
#include "frc/DigitalSource.h"
|
|
|
|
|
#include "frc/DutyCycle.h"
|
|
|
|
|
#include "frc/Encoder.h"
|
|
|
|
|
#include "frc/Errors.h"
|
|
|
|
|
|
2019-11-14 22:52:34 -08:00
|
|
|
using namespace frc;
|
|
|
|
|
|
|
|
|
|
DMA::DMA() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
dmaHandle = HAL_InitializeDMA(&status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "InitializeDMA");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
DMA::~DMA() {
|
|
|
|
|
HAL_FreeDMA(dmaHandle);
|
|
|
|
|
}
|
2019-11-14 22:52:34 -08:00
|
|
|
|
|
|
|
|
void DMA::SetPause(bool pause) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_SetDMAPause(dmaHandle, pause, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "SetPause");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::SetRate(int cycles) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_SetDMARate(dmaHandle, cycles, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "SetRate");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::AddEncoder(const Encoder* encoder) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_AddDMAEncoder(dmaHandle, encoder->m_encoder, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "AddEncoder");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::AddEncoderPeriod(const Encoder* encoder) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_AddDMAEncoderPeriod(dmaHandle, encoder->m_encoder, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "AddEncoderPeriod");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::AddCounter(const Counter* counter) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_AddDMACounter(dmaHandle, counter->m_counter, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "AddCounter");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::AddCounterPeriod(const Counter* counter) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_AddDMACounterPeriod(dmaHandle, counter->m_counter, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "AddCounterPeriod");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::AddDigitalSource(const DigitalSource* digitalSource) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_AddDMADigitalSource(dmaHandle, digitalSource->GetPortHandleForRouting(),
|
|
|
|
|
&status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "AddDigitalSource");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::AddDutyCycle(const DutyCycle* dutyCycle) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_AddDMADutyCycle(dmaHandle, dutyCycle->m_handle, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "AddDutyCycle");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::AddAnalogInput(const AnalogInput* analogInput) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_AddDMAAnalogInput(dmaHandle, analogInput->m_port, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "AddAnalogInput");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::AddAveragedAnalogInput(const AnalogInput* analogInput) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_AddDMAAveragedAnalogInput(dmaHandle, analogInput->m_port, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "AddAveragedAnalogInput");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::AddAnalogAccumulator(const AnalogInput* analogInput) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_AddDMAAnalogAccumulator(dmaHandle, analogInput->m_port, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "AddAnalogAccumulator");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::SetExternalTrigger(DigitalSource* source, bool rising, bool falling) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_SetDMAExternalTrigger(dmaHandle, source->GetPortHandleForRouting(),
|
|
|
|
|
static_cast<HAL_AnalogTriggerType>(
|
|
|
|
|
source->GetAnalogTriggerTypeForRouting()),
|
|
|
|
|
rising, falling, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "SetExternalTrigger");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::StartDMA(int queueDepth) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_StartDMA(dmaHandle, queueDepth, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "StartDMA");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::StopDMA() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_StopDMA(dmaHandle, &status);
|
2021-05-23 19:33:33 -07:00
|
|
|
FRC_CheckErrorStatus(status, "{}", "StopDMA");
|
2019-11-14 22:52:34 -08:00
|
|
|
}
|