Skip to content
Snippets Groups Projects
Commit be51b40d authored by Federico's avatar Federico
Browse files

Fixed race condition in TimerAdapter::IRQhandler()

parent bedddbe0
Branches
No related tags found
2 merge requests!40Update to Miosix 2.7,!17Draft: Improved miosix build system and fixed cmake scripts
...@@ -209,7 +209,7 @@ public: ...@@ -209,7 +209,7 @@ public:
// interrupts can be disabeld, equals to one hardware timer period minus // interrupts can be disabeld, equals to one hardware timer period minus
// the time between the two timer reads in this algorithm. // the time between the two timer reads in this algorithm.
unsigned int counter=D::IRQgetTimerCounter(); unsigned int counter=D::IRQgetTimerCounter();
if((D::IRQgetOverflowFlag()) && D::IRQgetTimerCounter()>=counter) if(D::IRQgetOverflowFlag() && D::IRQgetTimerCounter()>=counter)
return (upperTimeTick | static_cast<long long>(counter)) + upperIncr; return (upperTimeTick | static_cast<long long>(counter)) + upperIncr;
return upperTimeTick | static_cast<long long>(counter); return upperTimeTick | static_cast<long long>(counter);
} }
...@@ -293,14 +293,13 @@ public: ...@@ -293,14 +293,13 @@ public:
if(D::IRQgetMatchFlag() || lateIrq) if(D::IRQgetMatchFlag() || lateIrq)
{ {
D::IRQclearMatchFlag(); D::IRQclearMatchFlag();
if(upperTimeTick == upperIrqTick || lateIrq) long long tick=IRQgetTimeTick();
if(tick >= IRQgetIrqTick() || lateIrq)
{ {
lateIrq=false; lateIrq=false;
IRQtimerInterrupt(IRQgetTimeNs()); IRQtimerInterrupt(tc.tick2ns(tick));
} }
} }
//Rollover
if(D::IRQgetOverflowFlag()) if(D::IRQgetOverflowFlag())
{ {
D::IRQclearOverflowFlag(); D::IRQclearOverflowFlag();
...@@ -329,11 +328,18 @@ public: ...@@ -329,11 +328,18 @@ public:
* \code * \code
* namespace miosix { * namespace miosix {
* class MyHwTimer : public TimerAdapter<MyHwTimer, insert timer bits here> * class MyHwTimer : public TimerAdapter<MyHwTimer, insert timer bits here>
* {
* [...] * [...]
* };
* *
* static MyHwTimer timer; * static MyHwTimer timer;
* DEFAULT_OS_TIMER_INTERFACE_IMPLMENTATION(timer); * DEFAULT_OS_TIMER_INTERFACE_IMPLMENTATION(timer);
* } * }
*
* void timerInterruptRoutine()
* {
* timer.IRQhandler();
* }
* \endcode * \endcode
*/ */
#define DEFAULT_OS_TIMER_INTERFACE_IMPLMENTATION(timer) \ #define DEFAULT_OS_TIMER_INTERFACE_IMPLMENTATION(timer) \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment