-
Notifications
You must be signed in to change notification settings - Fork 6
/
InterruptableSensorBase.cpp
98 lines (88 loc) · 2.92 KB
/
InterruptableSensorBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#include "InterruptableSensorBase.h"
#include "Utility.h"
InterruptableSensorBase::InterruptableSensorBase()
{
m_manager = NULL;
m_interrupt = NULL;
}
InterruptableSensorBase::~InterruptableSensorBase()
{
}
void InterruptableSensorBase::AllocateInterrupts(bool watcher)
{
wpi_assert(m_interrupt == NULL);
wpi_assert(m_manager == NULL);
// Expects the calling leaf class to allocate an interrupt index.
tRioStatusCode localStatus = NiFpga_Status_Success;
m_interrupt = tInterrupt::create(m_interruptIndex, &localStatus);
m_interrupt->writeConfig_WaitForAck(false, &localStatus);
m_manager = new tInterruptManager(1 << m_interruptIndex, watcher, &localStatus);
wpi_setError(localStatus);
}
/**
* Cancel interrupts on this device.
* This deallocates all the chipobject structures and disables any interrupts.
*/
void InterruptableSensorBase::CancelInterrupts()
{
wpi_assert(m_manager != NULL);
wpi_assert(m_interrupt != NULL);
delete m_interrupt;
delete m_manager;
m_interrupt = NULL;
m_manager = NULL;
}
/**
* In synchronous mode, wait for the defined interrupt to occur.
* @param timeout Timeout in seconds
*/
void InterruptableSensorBase::WaitForInterrupt(float timeout)
{
wpi_assert(m_manager != NULL);
wpi_assert(m_interrupt != NULL);
tRioStatusCode localStatus = NiFpga_Status_Success;
m_manager->watch((int32_t)(timeout * 1e3), &localStatus);
wpi_setError(localStatus);
}
/**
* Enable interrupts to occur on this input.
* Interrupts are disabled when the RequestInterrupt call is made. This gives time to do the
* setup of the other options before starting to field interrupts.
*/
void InterruptableSensorBase::EnableInterrupts()
{
wpi_assert(m_manager != NULL);
wpi_assert(m_interrupt != NULL);
tRioStatusCode localStatus = NiFpga_Status_Success;
m_manager->enable(&localStatus);
wpi_setError(localStatus);
}
/**
* Disable Interrupts without without deallocating structures.
*/
void InterruptableSensorBase::DisableInterrupts()
{
wpi_assert(m_manager != NULL);
wpi_assert(m_interrupt != NULL);
tRioStatusCode localStatus = NiFpga_Status_Success;
m_manager->disable(&localStatus);
wpi_setError(localStatus);
}
/**
* Return the timestamp for the interrupt that occurred most recently.
* This is in the same time domain as GetClock().
* @return Timestamp in seconds since boot.
*/
double InterruptableSensorBase::ReadInterruptTimestamp()
{
wpi_assert(m_interrupt != NULL);
tRioStatusCode localStatus = NiFpga_Status_Success;
uint32_t timestamp = m_interrupt->readTimeStamp(&localStatus);
wpi_setError(localStatus);
return timestamp * 1e-6;
}