Browse Source

added code to monitor time spent in interrupt handlers

pull/5/head
Youen Toupin 10 years ago
parent
commit
cf3f309ade
  1. 30
      OneWireIO.ino

30
OneWireIO.ino

@ -44,12 +44,22 @@ void owPullLow()
{ {
owPin.outputMode(); owPin.outputMode();
owPin.writeLow(); owPin.writeLow();
owOutTestPin.writeLow(); //owOutTestPin.writeLow();
} }
void owRelease() void owRelease()
{ {
owPin.inputMode(); owPin.inputMode();
//owOutTestPin.writeHigh();
}
void onEnterInterrupt()
{
owOutTestPin.writeLow();
}
void onLeaveInterrupt()
{
owOutTestPin.writeHigh(); owOutTestPin.writeHigh();
} }
@ -166,9 +176,9 @@ void owHandleReset()
void onewireInterrupt() void onewireInterrupt()
{ {
//owOutTestPin.writeLow(); onEnterInterrupt();
onewireInterruptImpl(); onewireInterruptImpl();
//owOutTestPin.writeHigh(); onLeaveInterrupt();
} }
//bool debugState = false; //bool debugState = false;
@ -230,6 +240,8 @@ bool ignoreNextFallingEdge = false;
void owSearchSendBit() void owSearchSendBit()
{ {
onEnterInterrupt();
// wait for a falling edge (active wait is more reliable than interrupts to send the bit fast enough) // wait for a falling edge (active wait is more reliable than interrupts to send the bit fast enough)
while (!owPin.read()); while (!owPin.read());
while (owPin.read()); while (owPin.read());
@ -276,13 +288,18 @@ void owSearchSendBit()
delayMicroseconds(SendBitDuration - (micros() - sendBitStart)); delayMicroseconds(SendBitDuration - (micros() - sendBitStart));
owRelease(); owRelease();
onLeaveInterrupt();
} }
void onewireInterruptSearchROM() void onewireInterruptSearchROM()
{ {
onEnterInterrupt();
if (ignoreNextFallingEdge) if (ignoreNextFallingEdge)
{ {
ignoreNextFallingEdge = false; ignoreNextFallingEdge = false;
onLeaveInterrupt();
return; return;
} }
@ -295,6 +312,7 @@ void onewireInterruptSearchROM()
debug.SC_APPEND_STR("Master didn't send our bit, leaving ROM search"); debug.SC_APPEND_STR("Master didn't send our bit, leaving ROM search");
status = OS_WaitReset; status = OS_WaitReset;
attachInterrupt(InterruptNumber, onewireInterrupt, FALLING); attachInterrupt(InterruptNumber, onewireInterrupt, FALLING);
onLeaveInterrupt();
return; return;
} }
@ -304,7 +322,7 @@ void onewireInterruptSearchROM()
{ {
++searchROMCurrentByte; ++searchROMCurrentByte;
searchROMCurrentBit = 0; searchROMCurrentBit = 0;
debug.SC_APPEND_STR("sent another ROM byte"); //debug.SC_APPEND_STR("sent another ROM byte");
} }
if (searchROMCurrentByte == 8) if (searchROMCurrentByte == 8)
@ -313,6 +331,7 @@ void onewireInterruptSearchROM()
status = OS_WaitReset; status = OS_WaitReset;
debug.SC_APPEND_STR("ROM sent entirely"); debug.SC_APPEND_STR("ROM sent entirely");
attachInterrupt(InterruptNumber, onewireInterrupt, FALLING); attachInterrupt(InterruptNumber, onewireInterrupt, FALLING);
onLeaveInterrupt();
return; return;
} }
@ -322,6 +341,7 @@ void onewireInterruptSearchROM()
setTimerEvent(10, owSearchSendBit); setTimerEvent(10, owSearchSendBit);
detachInterrupt(InterruptNumber); detachInterrupt(InterruptNumber);
onLeaveInterrupt();
return; return;
} }
else else
@ -346,6 +366,8 @@ void onewireInterruptSearchROM()
byte currentByte = owROM[searchROMCurrentByte]; byte currentByte = owROM[searchROMCurrentByte];
searchRomNextBit = bitRead(currentByte, searchROMCurrentBit); searchRomNextBit = bitRead(currentByte, searchROMCurrentBit);
searchRomNextBitToSend = searchROMSendingInverse ? !searchRomNextBit : searchRomNextBit; searchRomNextBitToSend = searchROMSendingInverse ? !searchRomNextBit : searchRomNextBit;
onLeaveInterrupt();
} }
bool readBit() bool readBit()

Loading…
Cancel
Save