Fixed interrupt freeing in C++

When interrupts are cancelled on any interruptable class, the resource is now
freed.  Previously, the resource was only freed if the object is destructed
before CancelInterrupts() is called, so it was impossible to create and
destruct more than 8 interrupts.

The interrupts resource object is now in InterruptableSensorBase instead of
SensorBase.

A synchronous interrupt integration test was added.

Change-Id: I0806176340cecd4c1480dd8f043474cc05919f24
This commit is contained in:
Thomas Clark
2014-08-06 09:46:50 -04:00
parent a09f75934a
commit 2356008d8c
5 changed files with 34 additions and 6 deletions

View File

@@ -11,6 +11,9 @@
static const double kDelayTime = 0.1;
static const double kSynchronousInterruptTime = 2.0;
static const double kSynchronousInterruptTimeTolerance = 0.01;
/**
* A fixture with a digital input and a digital output physically wired
* together.
@@ -79,7 +82,7 @@ static void InterruptHandler(uint32_t interruptAssertedMask, void *param) {
*(int *)param = 12345;
}
TEST_F(DIOLoopTest, AsynchronusInterruptWorks) {
TEST_F(DIOLoopTest, AsynchronousInterruptWorks) {
int param = 0;
// Given an interrupt handler that sets an int to 12345
@@ -95,3 +98,26 @@ TEST_F(DIOLoopTest, AsynchronusInterruptWorks) {
Wait(kDelayTime);
EXPECT_EQ(12345, param) << "The interrupt did not run.";
}
static void *InterruptTriggerer(void *data) {
DigitalOutput *output = static_cast<DigitalOutput *>(data);
output->Set(false);
Wait(kSynchronousInterruptTime);
output->Set(true);
return NULL;
}
TEST_F(DIOLoopTest, SynchronousInterruptWorks) {
// Given a synchronous interrupt
m_input->RequestInterrupts();
// If we have another thread trigger the interrupt in a few seconds
pthread_t interruptTriggererLoop;
pthread_create(&interruptTriggererLoop, NULL, InterruptTriggerer, m_output);
// Then this thread should pause and resume after that number of seconds
Timer timer;
timer.Start();
m_input->WaitForInterrupt(kSynchronousInterruptTime + 1.0);
EXPECT_NEAR(kSynchronousInterruptTime, timer.Get(), kSynchronousInterruptTimeTolerance);
}