Arduino: separated interrupt callbacks

Java: fixed TC
This commit is contained in:
Ziver Koc 2016-05-26 16:35:22 +02:00
parent 17e50573d6
commit 15555ea7eb
5 changed files with 34 additions and 30 deletions

View file

@ -61,7 +61,7 @@ void setup()
#endif
DEBUG("Setup INTERRUPT");
Interrupt::setCallback(timerInterruptFunc);
Interrupt::setWatchDogCallback(timerInterruptFunc);
Interrupt::setupWatchDogInterrupt(TIMER_MILLISECOND); // one minute scheduled interrupt

View file

@ -6,25 +6,15 @@
#include "HalInterfaces.h"
void emptyFunc(){}
InterruptFunction Interrupt::callback = emptyFunc;
bool Interrupt::wakeUpNow = false;
InterruptFunction Interrupt::pinCallback = emptyFunc;
InterruptFunction Interrupt::wdtCallback = emptyFunc;
void __interruptHandler__() // the interrupt is handled here after wakeup
void Interrupt::handlePinInterrupt() // the interrupt is handled here after wakeup
{
// execute code here after wake-up before returning to the loop() function
// timers and code using timers (serial.print and more...) will not work here.
noInterrupts(); // disable all interrupts
(Interrupt::getCallback()) ();
interrupts(); // enable all interrupts
Interrupt::wakeUp();
}
void Interrupt::wakeUp()
{
wakeUpNow = true;
(*Interrupt::pinCallback) ();
//Interrupt::wakeUp();
}
void Interrupt::sleep()
@ -81,7 +71,7 @@ void Interrupt::setupPinInterrupt(int pin)
*
* In all but the IDLE sleep modes only LOW can be used.
*/
attachInterrupt((pin == PIND2 ? 0 : 1), __interruptHandler__, LOW);
attachInterrupt((pin == PIND2 ? 0 : 1), Interrupt::handlePinInterrupt, LOW);
//detachInterrupt(0); // disables interrupt 0 on pin 2 so the
// wakeUpNow code will not be executed
@ -93,9 +83,9 @@ void Interrupt::setupPinInterrupt(int pin)
// Watchdog timer
unsigned int wdtTime;
long wdtTimeLeft;
void __setWatchDogInterrupt();
ISR(WDT_vect)
void Interrupt::handleWatchDogInterrupt()
{
//DEBUG("WDT Interrupt");
wdt_disable();
@ -103,19 +93,24 @@ ISR(WDT_vect)
{
DEBUG("WDT interrupt");
Interrupt::wakeUp();
__interruptHandler__();
(*Interrupt::wdtCallback) ();
wdtTimeLeft = wdtTime;
}
__setWatchDogInterrupt();
setupWatchDogInterrupt();
}
ISR(WDT_vect)
{
Interrupt::handleWatchDogInterrupt();
}
void Interrupt::setupWatchDogInterrupt(unsigned int milliseconds)
{
wdtTimeLeft = wdtTime = milliseconds;
__setWatchDogInterrupt();
setupWatchDogInterrupt();
}
void __setWatchDogInterrupt()
void Interrupt::setupWatchDogInterrupt()
{
noInterrupts();
@ -194,7 +189,7 @@ void __setWatchDogInterrupt()
ISR(Timer1_COMPA_vect) // timer compare interrupt service routine
{
//DEBUG("Timer1e Interrupt");
__interruptHandler__();
__pinInterruptHandler__();
}
*/
/*

View file

@ -7,22 +7,31 @@ typedef void (*InterruptFunction) ();
class Interrupt
{
public:
static void wakeUp();
static void wakeUp() { wakeUpNow = true; };
static void sleep();
static void setupPinInterrupt(int pin);
static void setupWatchDogInterrupt(unsigned int milliseconds);
//static void setupTimerInterrupt(unsigned int milliseconds);
static void setCallback(InterruptFunction callback){ Interrupt::callback = callback;}
static InterruptFunction getCallback(){ return Interrupt::callback;}
static void setPinCallback(InterruptFunction callback){ Interrupt::pinCallback = callback;}
static void setWatchDogCallback(InterruptFunction callback){ Interrupt::wdtCallback = callback;}
/* Should not be called externally, used as triggering functions */
static void handlePinInterrupt();
static void handleWatchDogInterrupt();
private:
static InterruptFunction callback;
static bool wakeUpNow;
static InterruptFunction pinCallback;
static InterruptFunction wdtCallback;
static void setupWatchDogInterrupt();
// Disable constructors and copy operators
Interrupt() {};
Interrupt(Interrupt const&);
void operator=(Interrupt const&);
};

View file

@ -9,7 +9,7 @@ void SensorPhotocell::interruptHandler()
void SensorPhotocell::setup()
{
Interrupt::setCallback(SensorPhotocell::interruptHandler);
Interrupt::setPinCallback(SensorPhotocell::interruptHandler);
Interrupt::setupPinInterrupt(PC2); //PC3
}