WPILibC++ 2024.3.2
SynchronousInterrupt.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <memory>
8
9#include <hal/Types.h>
10#include <units/time.h>
11
12namespace frc {
13class DigitalSource;
14
15/**
16 * Class for handling synchronous (blocking) interrupts.
17 *
18 * <p> By default, interrupts will occur on rising edge.
19 *
20 * <p> Asynchronous interrupts are handled by the AsynchronousInterrupt class.
21 */
23 public:
24 /**
25 * Event trigger combinations for a synchronous interrupt.
26 */
28 /// Timeout event.
29 kTimeout = 0x0,
30 /// Rising edge event.
32 /// Falling edge event.
33 kFallingEdge = 0x100,
34 /// Both rising and falling edge events.
35 kBoth = 0x101,
36 };
37
38 /**
39 * Construct a Synchronous Interrupt from a Digital Source.
40 *
41 * @param source the DigitalSource the interrupts are triggered from
42 */
44
45 /**
46 * Construct a Synchronous Interrupt from a Digital Source.
47 *
48 * @param source the DigitalSource the interrupts are triggered from
49 */
51
52 /**
53 * Construct a Synchronous Interrupt from a Digital Source.
54 *
55 * @param source the DigitalSource the interrupts are triggered from
56 */
57 explicit SynchronousInterrupt(std::shared_ptr<DigitalSource> source);
58
60
63
64 /**
65 * Wait for an interrupt to occur.
66 *
67 * <p> Both rising and falling edge can be returned if both a rising and
68 * falling happened between calls, and ignorePrevious is false.
69 *
70 * @param timeout The timeout to wait for. 0s or less will return immediately.
71 * @param ignorePrevious True to ignore any previous interrupts, false to
72 * return interrupt value if an interrupt has occurred since last call.
73 * @return The edge(s) that were triggered, or timeout.
74 */
75 WaitResult WaitForInterrupt(units::second_t timeout,
76 bool ignorePrevious = true);
77
78 /**
79 * Set which edges cause an interrupt to occur.
80 *
81 * @param risingEdge true to trigger on rising edge, false otherwise.
82 * @param fallingEdge true to trigger on falling edge, false otherwise
83 */
84 void SetInterruptEdges(bool risingEdge, bool fallingEdge);
85
86 /**
87 * Get the timestamp (relative to FPGA Time) of the last rising edge.
88 *
89 * @return the timestamp in seconds relative to getFPGATime
90 */
91 units::second_t GetRisingTimestamp();
92
93 /**
94 * Get the timestamp of the last falling edge.
95 *
96 * <p>This function does not require the interrupt to be enabled to work.
97 *
98 * <p>This only works if falling edge was configured using setInterruptEdges.
99 * @return the timestamp in seconds relative to getFPGATime
100 */
101 units::second_t GetFallingTimestamp();
102
103 /**
104 * Wake up an existing wait call. Can be called from any thread.
105 */
107
108 private:
109 void InitSynchronousInterrupt();
110 std::shared_ptr<DigitalSource> m_source;
112};
113} // namespace frc
and restrictions which apply to each piece of software is included later in this file and or inside of the individual applicable source files The disclaimer of warranty in the WPILib license above applies to all code in and nothing in any of the other licenses gives permission to use the names of FIRST nor the names of the WPILib contributors to endorse or promote products derived from this software The following pieces of software have additional or alternate and or Google Inc All rights reserved Redistribution and use in source and binary with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer *Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution *Neither the name of Google Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation source
Definition: ThirdPartyNotices.txt:111
DigitalSource Interface.
Definition: DigitalSource.h:22
Class for handling synchronous (blocking) interrupts.
Definition: SynchronousInterrupt.h:22
WaitResult
Event trigger combinations for a synchronous interrupt.
Definition: SynchronousInterrupt.h:27
@ kTimeout
Timeout event.
Definition: SynchronousInterrupt.h:29
@ kFallingEdge
Falling edge event.
Definition: SynchronousInterrupt.h:33
@ kBoth
Both rising and falling edge events.
Definition: SynchronousInterrupt.h:35
@ kRisingEdge
Rising edge event.
Definition: SynchronousInterrupt.h:31
SynchronousInterrupt(SynchronousInterrupt &&)=default
void SetInterruptEdges(bool risingEdge, bool fallingEdge)
Set which edges cause an interrupt to occur.
units::second_t GetRisingTimestamp()
Get the timestamp (relative to FPGA Time) of the last rising edge.
WaitResult WaitForInterrupt(units::second_t timeout, bool ignorePrevious=true)
Wait for an interrupt to occur.
SynchronousInterrupt & operator=(SynchronousInterrupt &&)=default
SynchronousInterrupt(DigitalSource *source)
Construct a Synchronous Interrupt from a Digital Source.
SynchronousInterrupt(DigitalSource &source)
Construct a Synchronous Interrupt from a Digital Source.
units::second_t GetFallingTimestamp()
Get the timestamp of the last falling edge.
SynchronousInterrupt(std::shared_ptr< DigitalSource > source)
Construct a Synchronous Interrupt from a Digital Source.
void WakeupWaitingInterrupt()
Wake up an existing wait call.
Definition: AprilTagPoseEstimator.h:15