mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Moves Interrupts over to Handles instead of pointers (#99)
This commit is contained in:
committed by
Peter Johnson
parent
74fc10999b
commit
046e043c4e
@@ -11,9 +11,6 @@
|
||||
#include "Utility.h"
|
||||
#include "WPIErrors.h"
|
||||
|
||||
std::unique_ptr<Resource> InterruptableSensorBase::m_interrupts =
|
||||
std::make_unique<Resource>(interrupt_kNumSystems);
|
||||
|
||||
InterruptableSensorBase::InterruptableSensorBase() {}
|
||||
|
||||
/**
|
||||
@@ -27,15 +24,10 @@ InterruptableSensorBase::InterruptableSensorBase() {}
|
||||
void InterruptableSensorBase::RequestInterrupts(
|
||||
InterruptHandlerFunction handler, void* param) {
|
||||
if (StatusIsFatal()) return;
|
||||
uint32_t index = m_interrupts->Allocate("Async Interrupt");
|
||||
if (index == std::numeric_limits<uint32_t>::max()) {
|
||||
CloneError(*m_interrupts);
|
||||
return;
|
||||
}
|
||||
m_interruptIndex = index;
|
||||
|
||||
// Creates a manager too
|
||||
wpi_assert(m_interrupt == HAL_INVALID_HANDLE);
|
||||
AllocateInterrupts(false);
|
||||
if (StatusIsFatal()) return; // if allocate failed, out of interrupts
|
||||
|
||||
int32_t status = 0;
|
||||
requestInterrupts(m_interrupt, GetModuleForRouting(), GetChannelForRouting(),
|
||||
@@ -54,14 +46,10 @@ void InterruptableSensorBase::RequestInterrupts(
|
||||
*/
|
||||
void InterruptableSensorBase::RequestInterrupts() {
|
||||
if (StatusIsFatal()) return;
|
||||
uint32_t index = m_interrupts->Allocate("Sync Interrupt");
|
||||
if (index == std::numeric_limits<uint32_t>::max()) {
|
||||
CloneError(*m_interrupts);
|
||||
return;
|
||||
}
|
||||
m_interruptIndex = index;
|
||||
|
||||
wpi_assert(m_interrupt == HAL_INVALID_HANDLE);
|
||||
AllocateInterrupts(true);
|
||||
if (StatusIsFatal()) return; // if allocate failed, out of interrupts
|
||||
|
||||
int32_t status = 0;
|
||||
requestInterrupts(m_interrupt, GetModuleForRouting(), GetChannelForRouting(),
|
||||
@@ -71,10 +59,10 @@ void InterruptableSensorBase::RequestInterrupts() {
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::AllocateInterrupts(bool watcher) {
|
||||
wpi_assert(m_interrupt == nullptr);
|
||||
wpi_assert(m_interrupt == HAL_INVALID_HANDLE);
|
||||
// Expects the calling leaf class to allocate an interrupt index.
|
||||
int32_t status = 0;
|
||||
m_interrupt = initializeInterrupts(m_interruptIndex, watcher, &status);
|
||||
m_interrupt = initializeInterrupts(watcher, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
@@ -85,12 +73,11 @@ void InterruptableSensorBase::AllocateInterrupts(bool watcher) {
|
||||
*/
|
||||
void InterruptableSensorBase::CancelInterrupts() {
|
||||
if (StatusIsFatal()) return;
|
||||
wpi_assert(m_interrupt != nullptr);
|
||||
wpi_assert(m_interrupt != HAL_INVALID_HANDLE);
|
||||
int32_t status = 0;
|
||||
cleanInterrupts(m_interrupt, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
m_interrupt = nullptr;
|
||||
m_interrupts->Free(m_interruptIndex);
|
||||
// ignore status, as an invalid handle just needs to be ignored.
|
||||
m_interrupt = HAL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +95,7 @@ void InterruptableSensorBase::CancelInterrupts() {
|
||||
InterruptableSensorBase::WaitResult InterruptableSensorBase::WaitForInterrupt(
|
||||
float timeout, bool ignorePrevious) {
|
||||
if (StatusIsFatal()) return InterruptableSensorBase::kTimeout;
|
||||
wpi_assert(m_interrupt != nullptr);
|
||||
wpi_assert(m_interrupt != HAL_INVALID_HANDLE);
|
||||
int32_t status = 0;
|
||||
uint32_t result;
|
||||
|
||||
@@ -127,7 +114,7 @@ InterruptableSensorBase::WaitResult InterruptableSensorBase::WaitForInterrupt(
|
||||
*/
|
||||
void InterruptableSensorBase::EnableInterrupts() {
|
||||
if (StatusIsFatal()) return;
|
||||
wpi_assert(m_interrupt != nullptr);
|
||||
wpi_assert(m_interrupt != HAL_INVALID_HANDLE);
|
||||
int32_t status = 0;
|
||||
enableInterrupts(m_interrupt, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
@@ -138,7 +125,7 @@ void InterruptableSensorBase::EnableInterrupts() {
|
||||
*/
|
||||
void InterruptableSensorBase::DisableInterrupts() {
|
||||
if (StatusIsFatal()) return;
|
||||
wpi_assert(m_interrupt != nullptr);
|
||||
wpi_assert(m_interrupt != HAL_INVALID_HANDLE);
|
||||
int32_t status = 0;
|
||||
disableInterrupts(m_interrupt, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
@@ -155,7 +142,7 @@ void InterruptableSensorBase::DisableInterrupts() {
|
||||
*/
|
||||
double InterruptableSensorBase::ReadRisingTimestamp() {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
wpi_assert(m_interrupt != nullptr);
|
||||
wpi_assert(m_interrupt != HAL_INVALID_HANDLE);
|
||||
int32_t status = 0;
|
||||
double timestamp = readRisingTimestamp(m_interrupt, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
@@ -173,7 +160,7 @@ double InterruptableSensorBase::ReadRisingTimestamp() {
|
||||
*/
|
||||
double InterruptableSensorBase::ReadFallingTimestamp() {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
wpi_assert(m_interrupt != nullptr);
|
||||
wpi_assert(m_interrupt != HAL_INVALID_HANDLE);
|
||||
int32_t status = 0;
|
||||
double timestamp = readFallingTimestamp(m_interrupt, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
@@ -189,13 +176,13 @@ double InterruptableSensorBase::ReadFallingTimestamp() {
|
||||
void InterruptableSensorBase::SetUpSourceEdge(bool risingEdge,
|
||||
bool fallingEdge) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (m_interrupt == nullptr) {
|
||||
if (m_interrupt == HAL_INVALID_HANDLE) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
NullParameter,
|
||||
"You must call RequestInterrupts before SetUpSourceEdge");
|
||||
return;
|
||||
}
|
||||
if (m_interrupt != nullptr) {
|
||||
if (m_interrupt != HAL_INVALID_HANDLE) {
|
||||
int32_t status = 0;
|
||||
setInterruptUpSourceEdge(m_interrupt, risingEdge, fallingEdge, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
Reference in New Issue
Block a user