[hal, wpilib] Remove interrupt (#7724)

This commit is contained in:
Thad House
2025-01-23 21:45:18 -08:00
committed by GitHub
parent e2b6beb28a
commit 5898cdd5c3
18 changed files with 0 additions and 1970 deletions

View File

@@ -1,180 +0,0 @@
// 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.
#pragma once
#include <frc/SynchronousInterrupt.h>
#include <atomic>
#include <functional>
#include <memory>
#include <thread>
#include <utility>
#include <units/time.h>
namespace frc {
/**
* Class for handling asynchronous interrupts using a callback thread.
*
* <p> By default, interrupts will occur on rising edge. Callbacks are disabled
* by default, and Enable() must be called before they will occur.
*
* <p> Both rising and falling edges can be indicated in one callback if both a
* rising and falling edge occurred since the previous callback.
*
* <p>Synchronous (blocking) interrupts are handled by the SynchronousInterrupt
* class.
*/
class AsynchronousInterrupt {
public:
/**
* Construct an Asynchronous Interrupt from a Digital Source.
*
* <p> At construction, the interrupt will trigger on the rising edge.
*
* <p> The first bool in the callback indicates the rising edge triggered the
* interrupt, the second bool is falling edge.
*
* @param source the DigitalSource the interrupts are triggered from
* @param callback the callback function to call when the interrupt is
* triggered
*/
AsynchronousInterrupt(DigitalSource& source,
std::function<void(bool, bool)> callback);
/**
* Construct an Asynchronous Interrupt from a Digital Source.
*
* <p> At construction, the interrupt will trigger on the rising edge.
*
* <p> The first bool in the callback indicates the rising edge triggered the
* interrupt, the second bool is falling edge.
*
* @param source the DigitalSource the interrupts are triggered from
* @param callback the callback function to call when the interrupt is
* triggered
*/
AsynchronousInterrupt(DigitalSource* source,
std::function<void(bool, bool)> callback);
/**
* Construct an Asynchronous Interrupt from a Digital Source.
*
* <p> At construction, the interrupt will trigger on the rising edge.
*
* <p> The first bool in the callback indicates the rising edge triggered the
* interrupt, the second bool is falling edge.
*
* @param source the DigitalSource the interrupts are triggered from
* @param callback the callback function to call when the interrupt is
* triggered
*/
AsynchronousInterrupt(std::shared_ptr<DigitalSource> source,
std::function<void(bool, bool)> callback);
/**
* Construct an Asynchronous Interrupt from a Digital Source.
*
* <p> At construction, the interrupt will trigger on the rising edge.
*
* @param source the DigitalSource the interrupts are triggered from
* @param f the callback function to call when the interrupt is triggered
* @param arg the first argument, interrupt was triggered on rising edge
* @param args the remaining arguments, interrupt was triggered on falling
* edge
*/
template <typename Callable, typename Arg, typename... Args>
AsynchronousInterrupt(DigitalSource& source, Callable&& f, Arg&& arg,
Args&&... args)
: AsynchronousInterrupt(
source, std::bind(std::forward<Callable>(f), std::forward<Arg>(arg),
std::forward<Args>(args)...)) {}
/**
* Construct an Asynchronous Interrupt from a Digital Source.
*
* <p> At construction, the interrupt will trigger on the rising edge.
*
* @param source the DigitalSource the interrupts are triggered from
* @param f the callback function to call when the interrupt is triggered
* @param arg the first argument, interrupt was triggered on rising edge
* @param args the remaining arguments, interrupt was triggered on falling
* edge
*/
template <typename Callable, typename Arg, typename... Args>
AsynchronousInterrupt(DigitalSource* source, Callable&& f, Arg&& arg,
Args&&... args)
: AsynchronousInterrupt(
source, std::bind(std::forward<Callable>(f), std::forward<Arg>(arg),
std::forward<Args>(args)...)) {}
/**
* Construct an Asynchronous Interrupt from a Digital Source.
*
* <p> At construction, the interrupt will trigger on the rising edge.
*
* @param source the DigitalSource the interrupts are triggered from
* @param f the callback function to call when the interrupt is triggered
* @param arg the first argument, interrupt was triggered on rising edge
* @param args the remaining arguments, interrupt was triggered on falling
* edge
*/
template <typename Callable, typename Arg, typename... Args>
AsynchronousInterrupt(std::shared_ptr<DigitalSource> source, Callable&& f,
Arg&& arg, Args&&... args)
: AsynchronousInterrupt(
source, std::bind(std::forward<Callable>(f), std::forward<Arg>(arg),
std::forward<Args>(args)...)) {}
~AsynchronousInterrupt();
/**
* Enables interrupt callbacks. Before this, callbacks will not occur. Does
* nothing if already enabled.
*/
void Enable();
/**
* Disables interrupt callbacks. Does nothing if already disabled.
*/
void Disable();
/**
* Set which edges to trigger the interrupt on.
*
* @param risingEdge %Trigger on rising edge
* @param fallingEdge %Trigger on falling edge
*/
void SetInterruptEdges(bool risingEdge, bool fallingEdge);
/**
* Get the timestamp of the last rising edge.
*
* <p>This function does not require the interrupt to be enabled to work.
*
* <p>This only works if rising edge was configured using SetInterruptEdges.
* @return the timestamp in seconds relative to GetFPGATime
*/
units::second_t GetRisingTimestamp();
/**
* Get the timestamp of the last falling edge.
*
* <p>This function does not require the interrupt to be enabled to work.
*
* <p>This only works if falling edge was configured using SetInterruptEdges.
* @return the timestamp in seconds relative to GetFPGATime
*/
units::second_t GetFallingTimestamp();
private:
void ThreadMain();
std::atomic_bool m_keepRunning{false};
std::thread m_thread;
SynchronousInterrupt m_interrupt;
std::function<void(bool, bool)> m_callback;
};
} // namespace frc

View File

@@ -1,112 +0,0 @@
// 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.
#pragma once
#include <memory>
#include <hal/Interrupts.h>
#include <hal/Types.h>
#include <units/time.h>
namespace frc {
class DigitalSource;
/**
* Class for handling synchronous (blocking) interrupts.
*
* <p> By default, interrupts will occur on rising edge.
*
* <p> Asynchronous interrupts are handled by the AsynchronousInterrupt class.
*/
class SynchronousInterrupt {
public:
/**
* Event trigger combinations for a synchronous interrupt.
*/
enum WaitResult {
/// Timeout event.
kTimeout = 0x0,
/// Rising edge event.
kRisingEdge = 0x1,
/// Falling edge event.
kFallingEdge = 0x100,
/// Both rising and falling edge events.
kBoth = 0x101,
};
/**
* Construct a Synchronous Interrupt from a Digital Source.
*
* @param source the DigitalSource the interrupts are triggered from
*/
explicit SynchronousInterrupt(DigitalSource& source);
/**
* Construct a Synchronous Interrupt from a Digital Source.
*
* @param source the DigitalSource the interrupts are triggered from
*/
explicit SynchronousInterrupt(DigitalSource* source);
/**
* Construct a Synchronous Interrupt from a Digital Source.
*
* @param source the DigitalSource the interrupts are triggered from
*/
explicit SynchronousInterrupt(std::shared_ptr<DigitalSource> source);
SynchronousInterrupt(SynchronousInterrupt&&) = default;
SynchronousInterrupt& operator=(SynchronousInterrupt&&) = default;
/**
* Wait for an interrupt to occur.
*
* <p> Both rising and falling edge can be returned if both a rising and
* falling happened between calls, and ignorePrevious is false.
*
* @param timeout The timeout to wait for. 0s or less will return immediately.
* @param ignorePrevious True to ignore any previous interrupts, false to
* return interrupt value if an interrupt has occurred since last call.
* @return The edge(s) that were triggered, or timeout.
*/
WaitResult WaitForInterrupt(units::second_t timeout,
bool ignorePrevious = true);
/**
* Set which edges cause an interrupt to occur.
*
* @param risingEdge true to trigger on rising edge, false otherwise.
* @param fallingEdge true to trigger on falling edge, false otherwise
*/
void SetInterruptEdges(bool risingEdge, bool fallingEdge);
/**
* Get the timestamp (relative to FPGA Time) of the last rising edge.
*
* @return the timestamp in seconds relative to getFPGATime
*/
units::second_t GetRisingTimestamp();
/**
* Get the timestamp of the last falling edge.
*
* <p>This function does not require the interrupt to be enabled to work.
*
* <p>This only works if falling edge was configured using setInterruptEdges.
* @return the timestamp in seconds relative to getFPGATime
*/
units::second_t GetFallingTimestamp();
/**
* Wake up an existing wait call. Can be called from any thread.
*/
void WakeupWaitingInterrupt();
private:
void InitSynchronousInterrupt();
std::shared_ptr<DigitalSource> m_source;
hal::Handle<HAL_InterruptHandle, HAL_CleanInterrupts> m_handle;
};
} // namespace frc