From 39f6bbbe07c3c375341ac8064691376d42995e5a Mon Sep 17 00:00:00 2001
From: Fabiano Riccardi <fabiuz4@hotmail.it>
Date: Mon, 24 Oct 2016 16:00:22 +0200
Subject: [PATCH] Refactor of cstimer.h, renamed all the files that use its
 functions

Signed-off-by: Fabiano Riccardi <fabiuz4@hotmail.it>
---
 .../interfaces-impl/cstimer.cpp                  |  8 ++++----
 .../interfaces-impl/gpio_timer.cpp               | 16 ++++++++--------
 .../high_resolution_timer_base.cpp               |  8 ++++----
 .../interfaces-impl/high_resolution_timer_base.h |  6 +++---
 .../interfaces-impl/radio_timer.cpp              | 10 +++++-----
 .../common/interfaces-impl/cstimer.cpp           |  4 ++--
 .../common/interfaces-impl/cstimer.cpp           |  4 ++--
 miosix/interfaces/cstimer.h                      |  6 +++---
 miosix/kernel/kernel.cpp                         |  4 ++--
 .../scheduler/control/control_scheduler.cpp      |  4 ++--
 .../scheduler/priority/priority_scheduler.cpp    |  2 +-
 11 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/cstimer.cpp b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/cstimer.cpp
index f42630e9..e4fbff90 100644
--- a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/cstimer.cpp
+++ b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/cstimer.cpp
@@ -22,12 +22,12 @@ namespace miosix {
          return tc->tick2ns(pImpl->b.IRQgetSetTimeCCV1());
     }
     
-    long long ContextSwitchTimer::getCurrentTick() const{
-        return tc->tick2ns(pImpl->b.getCurrentTick());
+    long long ContextSwitchTimer::getCurrentTime() const{
+        return tc->tick2ns(pImpl->b.getCurrentTime());
     }
     
-    long long ContextSwitchTimer::IRQgetCurrentTick() const{
-        return tc->tick2ns(pImpl->b.IRQgetCurrentTick());
+    long long ContextSwitchTimer::IRQgetCurrentTime() const{
+        return tc->tick2ns(pImpl->b.IRQgetCurrentTime());
     }
     
     ContextSwitchTimer::~ContextSwitchTimer(){}
diff --git a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/gpio_timer.cpp b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/gpio_timer.cpp
index dba5b416..35f28731 100644
--- a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/gpio_timer.cpp
+++ b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/gpio_timer.cpp
@@ -17,7 +17,7 @@ using namespace miosix;
 Thread* GPIOtimer::tWaitingGPIO=nullptr;
 
 long long GPIOtimer::getValue() const{
-    return b.getCurrentTick();
+    return b.getCurrentTime();
 }
 
 unsigned int GPIOtimer::getTickFrequency() const{
@@ -29,7 +29,7 @@ void GPIOtimer::wait(long long tick){
 }
 
 bool GPIOtimer::absoluteWait(long long tick){
-    if(b.getCurrentTick()>=tick){
+    if(b.getCurrentTime()>=tick){
 	return true;
     }
     Thread::nanoSleepUntil(tc.tick2ns(tick));
@@ -47,7 +47,7 @@ long long GPIOtimer::getExtEventTimestamp() const{
 
 bool GPIOtimer::absoluteWaitTimeoutOrEvent(long long tick){
     FastInterruptDisableLock dLock;
-    if(tick<b.getCurrentTick()){
+    if(tick<b.getCurrentTime()){
 	return true;
     }
     if(!isInput){
@@ -65,7 +65,7 @@ bool GPIOtimer::absoluteWaitTimeoutOrEvent(long long tick){
             FastInterruptEnableLock eLock(dLock);
 	    Thread::yield();
         }
-    } while(tWaitingGPIO && tick>b.getCurrentTick());
+    } while(tWaitingGPIO && tick>b.getCurrentTime());
     
     if(tWaitingGPIO==nullptr){
 	return false;
@@ -75,7 +75,7 @@ bool GPIOtimer::absoluteWaitTimeoutOrEvent(long long tick){
 }
 
 bool GPIOtimer::waitTimeoutOrEvent(long long tick){
-    return absoluteWaitTimeoutOrEvent(b.getCurrentTick()+tick);
+    return absoluteWaitTimeoutOrEvent(b.getCurrentTime()+tick);
 }
 
 /*
@@ -95,7 +95,7 @@ bool GPIOtimer::absoluteWaitTrigger(long long tick){
 }
 
 bool GPIOtimer::waitTrigger(long long tick){
-    return absoluteWaitTrigger(b.getCurrentTick()+tick);
+    return absoluteWaitTrigger(b.getCurrentTime()+tick);
 }
 
 /*
@@ -121,13 +121,13 @@ bool GPIOtimer::absoluteSyncWaitTrigger(long long tick){
 		FastInterruptEnableLock eLock(dLock);
 		Thread::yield();
 	    }
-	} while(tWaitingGPIO && tick>b.getCurrentTick());
+	} while(tWaitingGPIO && tick>b.getCurrentTime());
     }
     return false;
 }
 
 bool GPIOtimer::syncWaitTrigger(long long tick){
-    return absoluteSyncWaitTrigger(b.getCurrentTick()+tick); 
+    return absoluteSyncWaitTrigger(b.getCurrentTime()+tick); 
 }
 
 long long GPIOtimer::tick2ns(long long tick){
diff --git a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/high_resolution_timer_base.cpp b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/high_resolution_timer_base.cpp
index b40c6b8c..1aaf6bb9 100644
--- a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/high_resolution_timer_base.cpp
+++ b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/high_resolution_timer_base.cpp
@@ -198,7 +198,7 @@ void __attribute__((used)) cstirqhnd1(){
 	    
 	    //get nextInterrupt
 	    long long t=ms32chkp[2]|TIMER1->CC[2].CCV;
-	    long long diff=t-b.IRQgetCurrentTick();
+	    long long diff=t-b.IRQgetCurrentTime();
 	    if(diff<=0xFFFF){
 		TIMER1->CC[2].CTRL = (TIMER1->CC[2].CTRL & ~_TIMER_CC_CTRL_CMOA_MASK) | TIMER_CC_CTRL_CMOA_SET;
 		faseGPIO=1;
@@ -220,7 +220,7 @@ long long HighResolutionTimerBase::IRQgetSetTimeCCV2() const{
     return ms32chkp[2] | TIMER3->CC[2].CCV<<16 | TIMER1->CC[2].CCV;
 }
 
-long long HighResolutionTimerBase::IRQgetCurrentTick(){
+long long HighResolutionTimerBase::IRQgetCurrentTime(){
     return IRQgetTick();
 }
 
@@ -258,13 +258,13 @@ void HighResolutionTimerBase::setCCInterrupt0Tim2(bool enable){
         TIMER2->IEN&=~TIMER_IEN_CC0;
 }
 
-long long HighResolutionTimerBase::getCurrentTick(){
+long long HighResolutionTimerBase::getCurrentTime(){
     bool interrupts=areInterruptsEnabled();
     //TODO: optimization opportunity, if we can guarantee that no call to this
     //function occurs before kernel is started, then we can use
     //fastInterruptDisable())
     if(interrupts) disableInterrupts();
-    long long result=IRQgetCurrentTick();
+    long long result=IRQgetCurrentTime();
     if(interrupts) enableInterrupts();
     return result;
 
diff --git a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/high_resolution_timer_base.h b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/high_resolution_timer_base.h
index 38453c7a..09b5616a 100644
--- a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/high_resolution_timer_base.h
+++ b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/high_resolution_timer_base.h
@@ -57,10 +57,10 @@ public:
     /**
      * Could be call both when the interrupts are enabled/disabled!
      * TODO: investigate if it's possible to remove the possibility to call
-     * this with IRQ disabled and use IRQgetCurrentTick() instead
+     * this with IRQ disabled and use IRQgetCurrentTime() instead
      * \return the current tick count of the timer
      */
-    long long getCurrentTick();
+    long long getCurrentTime();
     
     void setCCInterrupt0(bool enable);
     void setCCInterrupt1(bool enable);
@@ -73,7 +73,7 @@ public:
      * \return the current tick count of the timer.
      * Can only be called with interrupts disabled or within an IRQ
      */
-    long long IRQgetCurrentTick();
+    long long IRQgetCurrentTime();
     
     virtual ~HighResolutionTimerBase();
     
diff --git a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/radio_timer.cpp b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/radio_timer.cpp
index ed7245f0..b81d97da 100644
--- a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/radio_timer.cpp
+++ b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/radio_timer.cpp
@@ -18,7 +18,7 @@ using namespace miosix;
 Thread* RadioTimer::tWaiting=nullptr;
 
 long long RadioTimer::getValue() const{
-     return b.getCurrentTick();
+     return b.getCurrentTime();
  }  
             
 void RadioTimer::wait(long long tick){
@@ -26,7 +26,7 @@ void RadioTimer::wait(long long tick){
 }
 
 bool RadioTimer::absoluteWait(long long tick){
-    if(b.getCurrentTick()>=tick){
+    if(b.getCurrentTime()>=tick){
 	return true;
     }
     Thread::nanoSleepUntil(tc.tick2ns(tick));
@@ -46,13 +46,13 @@ bool RadioTimer::absoluteWaitTrigger(long long tick){
 	    FastInterruptEnableLock eLock(dLock);
 	    Thread::yield();
 	}
-    } while(tWaiting && tick>b.getCurrentTick());
+    } while(tWaiting && tick>b.getCurrentTime());
     return false;
 }
 
 bool RadioTimer::absoluteWaitTimeoutOrEvent(long long tick){
     FastInterruptDisableLock dLock;
-    if(tick<b.getCurrentTick()){
+    if(tick<b.getCurrentTime()){
 	return true;
     }
     
@@ -66,7 +66,7 @@ bool RadioTimer::absoluteWaitTimeoutOrEvent(long long tick){
             FastInterruptEnableLock eLock(dLock);
 	    Thread::yield();
         }
-    } while(tWaiting && tick>b.getCurrentTick());
+    } while(tWaiting && tick>b.getCurrentTime());
     
     if(tWaiting==nullptr){
 	return false;
diff --git a/miosix/arch/cortexM3_stm32/common/interfaces-impl/cstimer.cpp b/miosix/arch/cortexM3_stm32/common/interfaces-impl/cstimer.cpp
index 4b78f8d4..dee20df4 100644
--- a/miosix/arch/cortexM3_stm32/common/interfaces-impl/cstimer.cpp
+++ b/miosix/arch/cortexM3_stm32/common/interfaces-impl/cstimer.cpp
@@ -110,7 +110,7 @@ long long ContextSwitchTimer::getNextInterrupt() const
     return tc->tick2ns(nextInterrupt());
 }
 
-long long ContextSwitchTimer::getCurrentTick() const
+long long ContextSwitchTimer::getCurrentTime() const
 {
     bool interrupts=areInterruptsEnabled();
     //TODO: optimization opportunity, if we can guarantee that no call to this
@@ -122,7 +122,7 @@ long long ContextSwitchTimer::getCurrentTick() const
     return result;
 }
 
-long long ContextSwitchTimer::IRQgetCurrentTick() const
+long long ContextSwitchTimer::IRQgetCurrentTime() const
 {
     return tc->tick2ns(IRQgetTick());
 }
diff --git a/miosix/arch/cortexM4_stm32f4/common/interfaces-impl/cstimer.cpp b/miosix/arch/cortexM4_stm32f4/common/interfaces-impl/cstimer.cpp
index f3c678fb..de59750b 100644
--- a/miosix/arch/cortexM4_stm32f4/common/interfaces-impl/cstimer.cpp
+++ b/miosix/arch/cortexM4_stm32f4/common/interfaces-impl/cstimer.cpp
@@ -110,7 +110,7 @@ long long ContextSwitchTimer::getNextInterrupt() const
     return tc->tick2ns(nextInterrupt());
 }
 
-long long ContextSwitchTimer::getCurrentTick() const
+long long ContextSwitchTimer::getCurrentTime() const
 {
     bool interrupts=areInterruptsEnabled();
     //TODO: optimization opportunity, if we can guarantee that no call to this
@@ -122,7 +122,7 @@ long long ContextSwitchTimer::getCurrentTick() const
     return result;
 }
 
-long long ContextSwitchTimer::IRQgetCurrentTick() const
+long long ContextSwitchTimer::IRQgetCurrentTime() const
 {
     return tc->tick2ns(IRQgetTick());
 }
diff --git a/miosix/interfaces/cstimer.h b/miosix/interfaces/cstimer.h
index 958816b8..c67e7b8d 100644
--- a/miosix/interfaces/cstimer.h
+++ b/miosix/interfaces/cstimer.h
@@ -38,16 +38,16 @@ public:
     /**
      * Could be call both when the interrupts are enabled/disabled!
      * TODO: investigate if it's possible to remove the possibility to call
-     * this with IRQ disabled and use IRQgetCurrentTick() instead
+     * this with IRQ disabled and use IRQgetCurrentTime() instead
      * \return the current tick count of the timer (in terms of nanoseconds)
      */
-    long long getCurrentTick() const;
+    long long getCurrentTime() const;
     
     /**
      * \return the current tick count of the timer (in terms of nanoseconds)
      * Can only be called with interrupts disabled or within an IRQ
      */
-    long long IRQgetCurrentTick() const;
+    long long IRQgetCurrentTime() const;
     
     /**
      * \return the timer frequency in Hz
diff --git a/miosix/kernel/kernel.cpp b/miosix/kernel/kernel.cpp
index e93630ad..f6372247 100755
--- a/miosix/kernel/kernel.cpp
+++ b/miosix/kernel/kernel.cpp
@@ -249,7 +249,7 @@ bool isKernelRunning()
 
 long long getTime()
 {
-    return ContextSwitchTimer::instance().getCurrentTick();
+    return ContextSwitchTimer::instance().getCurrentTime();
 }
 
 /**
@@ -373,7 +373,7 @@ void Thread::nanoSleep(long long ns)
 {
     if(ns==0) return; //TODO: should be (ns &lt; resolution + epsilon)
     //TODO: Mutual Exclusion issue
-    nanoSleepUntil(ContextSwitchTimer::instance().getCurrentTick() + ns);
+    nanoSleepUntil(ContextSwitchTimer::instance().getCurrentTime() + ns);
 }
 
 void Thread::nanoSleepUntil(long long absoluteTime)
diff --git a/miosix/kernel/scheduler/control/control_scheduler.cpp b/miosix/kernel/scheduler/control/control_scheduler.cpp
index 05eb8268..3c78b955 100644
--- a/miosix/kernel/scheduler/control/control_scheduler.cpp
+++ b/miosix/kernel/scheduler/control/control_scheduler.cpp
@@ -207,7 +207,7 @@ static inline void IRQsetNextPreemption(long long burst){
         firstWakeupInList = numeric_limits<long long>::max();
     else
         firstWakeupInList = sleepingList->front()->wakeup_time;
-    burstStart = timer.IRQgetCurrentTick();
+    burstStart = timer.IRQgetCurrentTime();
     nextPreemption = burstStart + burst;
     if (firstWakeupInList < nextPreemption)
         timer.IRQsetNextInterrupt(firstWakeupInList);
@@ -229,7 +229,7 @@ unsigned int ControlScheduler::IRQfindNextThread()
         //Not preempting from the idle thread, store actual burst time of
         //the preempted thread
         //int Tp=miosix_private::AuxiliaryTimer::IRQgetValue(); //CurTime - LastTime = real burst
-        int Tp = static_cast<int>(timer.IRQgetCurrentTick() - burstStart);
+        int Tp = static_cast<int>(timer.IRQgetCurrentTime() - burstStart);
         cur->schedData.Tp=Tp;
         Tr+=Tp;
     }
diff --git a/miosix/kernel/scheduler/priority/priority_scheduler.cpp b/miosix/kernel/scheduler/priority/priority_scheduler.cpp
index a07e837c..f98dc625 100644
--- a/miosix/kernel/scheduler/priority/priority_scheduler.cpp
+++ b/miosix/kernel/scheduler/priority/priority_scheduler.cpp
@@ -209,7 +209,7 @@ static void setNextPreemption(bool curIsIdleThread){
     if (curIsIdleThread){
         timer.IRQsetNextInterrupt(firstWakeupInList);
     }else{
-        long long nextPeriodicPreemption = timer.IRQgetCurrentTick() + preemptionPeriodNs;   
+        long long nextPeriodicPreemption = timer.IRQgetCurrentTime() + preemptionPeriodNs;   
         if (firstWakeupInList < nextPeriodicPreemption )
             timer.IRQsetNextInterrupt(firstWakeupInList);
         else
-- 
GitLab