11#include " Scheduler.h"
22#include " Process.h"
33
4+ Process *Scheduler::_active = NULL ;
5+ jmp_buf Scheduler::_env = {};
6+
7+ ISR (TIMER0_COMPA_vect)
8+ {
9+ if (Scheduler::getActive ()) { // routine is running
10+ uint32_t timeout = Scheduler::getActive ()->getTimeout ();
11+ if (timeout && Scheduler::getCurrTS () - Scheduler::getActive ()->getActualRunTS () >= timeout)
12+ longjmp (Scheduler::_env, LONGJMP_ISR_CODE);
13+ }
14+ }
15+
416
517Scheduler::Scheduler ()
618: _pLevels{}
@@ -21,7 +33,7 @@ uint32_t Scheduler::getCurrTS()
2133 return TIMESTAMP ();
2234}
2335
24- Process *Scheduler::getCurrProcess ()
36+ Process *Scheduler::getActive ()
2537{
2638 return _active;
2739}
@@ -134,15 +146,22 @@ int Scheduler::run()
134146
135147#ifdef _PROCESS_EXCEPTION_HANDLING
136148 int ret = setjmp (_env);
149+
150+ #ifdef _PROCESS_TIMEOUT_INTERRUPTS
151+ ENABLE_SCHEDULER_ISR ();
152+ #endif
137153 if (!ret) {
138154 _active->service ();
139155 } else {
140- eDispatcher (ret);
156+ jmpHandler (ret);
141157 }
142158#else
143159 _active->service ();
144160#endif
145161
162+ #ifdef _PROCESS_TIMEOUT_INTERRUPTS
163+ DISABLE_SCHEDULER_ISR ();
164+ #endif
146165
147166#ifdef _PROCESS_STATISTICS
148167 uint32_t runTime = getCurrTS () - start;
@@ -383,12 +402,15 @@ void Scheduler::handleHistOverFlow(uint8_t div)
383402 }
384403
385404
386- bool Scheduler::eDispatcher (int e)
405+ bool Scheduler::jmpHandler (int e)
387406 {
388407 if (e != 0 && _active)
389408 {
390- if (!_active->handleException (e))
409+ if (e == LONGJMP_ISR_CODE)
410+ _active->handleWarning (WARNING_PROC_TIMED_OUT);
411+ else if (!_active->handleException (e))
391412 handleException (*_active, e);
413+
392414 return true ;
393415 }
394416 return false ;
0 commit comments