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 690ee254744aa29d96cc17a59b9a60a5f6ba78ae..83a6dd7a3c667da80785f3eb9425e259b31bb309 100644 --- a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/cstimer.cpp +++ b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/cstimer.cpp @@ -19,7 +19,7 @@ namespace miosix { } long long ContextSwitchTimer::getNextInterrupt() const{ - return tc->tick2ns(pImpl->b.IRQgetSetTimeCCV1()); + return tc->tick2ns(pImpl->b.IRQgetSetTimeCS()); } long long ContextSwitchTimer::getCurrentTime() const{ 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 b4efddb19940590e63464983c46b6e38ae154e25..83cfefbcd1951952fb5ee81af029b906bbfc8b84 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 @@ -14,7 +14,7 @@ using namespace miosix; -Thread* GPIOtimer::tWaitingGPIO=nullptr; +Thread* GPIOtimer::tWaiting=nullptr; long long GPIOtimer::getValue() const{ return b.getCurrentTick(); @@ -42,7 +42,7 @@ bool GPIOtimer::getMode(){ //NOTE: Think about how to set the right ms32chkp related to the captured timestamp long long GPIOtimer::getExtEventTimestamp() const{ - return b.IRQgetSetTimeCCV2(); + return b.IRQgetSetTimeGPIO(); } bool GPIOtimer::absoluteWaitTimeoutOrEvent(long long tick){ @@ -60,15 +60,15 @@ bool GPIOtimer::absoluteWaitTimeoutOrEvent(long long tick){ b.enableCC2InterruptTim1(true); do { - tWaitingGPIO=Thread::IRQgetCurrentThread(); + tWaiting=Thread::IRQgetCurrentThread(); Thread::IRQwait(); { FastInterruptEnableLock eLock(dLock); Thread::yield(); } - } while(tWaitingGPIO && tick>b.getCurrentTick()); + } while(tWaiting && tick>b.getCurrentTick()); - if(tWaitingGPIO==nullptr){ + if(tWaiting==nullptr){ return false; }else{ return true; @@ -118,13 +118,13 @@ bool GPIOtimer::absoluteSyncWaitTrigger(long long tick){ } expansion::gpio1::low(); do { - tWaitingGPIO=Thread::IRQgetCurrentThread(); + tWaiting=Thread::IRQgetCurrentThread(); Thread::IRQwait(); { FastInterruptEnableLock eLock(dLock); Thread::yield(); } - } while(tWaitingGPIO && tick>b.getCurrentTick()); + } while(tWaiting && tick>b.getCurrentTick()); } return false; } @@ -141,7 +141,6 @@ long long GPIOtimer::ns2tick(long long ns){ return tc.ns2tick(ns); } -long long GPIOtimer::aux1=0; GPIOtimer::~GPIOtimer() {} GPIOtimer& GPIOtimer::instance(){ diff --git a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/gpio_timer.h b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/gpio_timer.h index 105c44ec5b1181df184de7f6e3338647a6286609..92b8fdae23c0366f21cca6efb1dd8d4469ad4bb4 100644 --- a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/gpio_timer.h +++ b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/gpio_timer.h @@ -22,8 +22,7 @@ namespace miosix { class GPIOtimer : public HardwareTimer{ public: - static Thread *tWaitingGPIO; - static long long aux1; + static Thread *tWaiting; long long getValue() const; 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 d7356a4f3254b82e8920c08cda99d1cacb606bbd..426554bf29e792f7ff132970d0b0110912bd6472 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 @@ -74,11 +74,11 @@ inline void interruptGPIOTimerRoutine(){ } } //Reactivating the thread that is waiting for the event. - if(GPIOtimer::tWaitingGPIO){ - GPIOtimer::tWaitingGPIO->IRQwakeup(); - if(GPIOtimer::tWaitingGPIO->IRQgetPriority()>Thread::IRQgetCurrentThread()->IRQgetPriority()) + if(GPIOtimer::tWaiting){ + GPIOtimer::tWaiting->IRQwakeup(); + if(GPIOtimer::tWaiting->IRQgetPriority()>Thread::IRQgetCurrentThread()->IRQgetPriority()) Scheduler::IRQfindNextThread(); - GPIOtimer::tWaitingGPIO=nullptr; + GPIOtimer::tWaiting=nullptr; } } @@ -240,13 +240,13 @@ void __attribute__((used)) cstirqhnd1(){ } } -long long HighResolutionTimerBase::IRQgetSetTimeCCV0() const{ - return ms32chkp[0] | TIMER3->CC[0].CCV<<16 | TIMER1->CC[0].CCV; +long long HighResolutionTimerBase::IRQgetSetTimeTransceiver() const{ + return ms32chkp[0] | TIMER3->CC[0].CCV<<16 | TIMER2->CC[0].CCV; } -long long HighResolutionTimerBase::IRQgetSetTimeCCV1() const{ +long long HighResolutionTimerBase::IRQgetSetTimeCS() const{ return ms32chkp[1] | TIMER3->CC[1].CCV<<16 | TIMER1->CC[1].CCV; } -long long HighResolutionTimerBase::IRQgetSetTimeCCV2() const{ +long long HighResolutionTimerBase::IRQgetSetTimeGPIO() const{ return ms32chkp[2] | TIMER3->CC[2].CCV<<16 | TIMER1->CC[2].CCV; } @@ -422,6 +422,13 @@ void HighResolutionTimerBase::cleanBufferGPIO(){ falseRead(&TIMER1->CC[2].CCV); } +void HighResolutionTimerBase::cleanBufferTrasceiver(){ + falseRead(&TIMER3->CC[0].CCV); + falseRead(&TIMER2->CC[0].CCV); + falseRead(&TIMER3->CC[0].CCV); + falseRead(&TIMER2->CC[0].CCV); +} + void HighResolutionTimerBase::setModeTransceiverTimer(){ //For input capture feature: //Connect TIMER2->CC0 to pin PA8 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 f63e54b877394c26b2b36a1cc82f492f4ddc304f..925daecf7397468c15ef1153e19c9120b01682cd 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 @@ -51,14 +51,16 @@ public: * \return the time when the next interrupt will be fired. * That is, the last value passed to setNextInterrupt(). */ - long long IRQgetSetTimeCCV0() const; - long long IRQgetSetTimeCCV1() const; - long long IRQgetSetTimeCCV2() const; + long long IRQgetSetTimeTransceiver() const; + long long IRQgetSetTimeCS() const; + long long IRQgetSetTimeGPIO() const; /* - * Clean buffer in TIMER used by GPIOTimer + * Clean buffer in TIMER used by GPIOTimer, necessary when input capture mode is enabled */ void cleanBufferGPIO(); + void cleanBufferTrasceiver(); + /** * Could be call both when the interrupts are enabled/disabled! * TODO: investigate if it's possible to remove the possibility to call @@ -78,6 +80,14 @@ public: void enableCC2InterruptTim1(bool enable); void enableCC0InterruptTim2(bool enable); void enableCC1InterruptTim2(bool enable); + + /** + * Function to prepare the timers to works in a given mode. For Transceiver, + * it use 2 different low channel, so we can set both of them at the + * beginning of our code. + * @param input true to set the input/capture mode, false to set the output + * mode + */ void setModeGPIOTimer(bool input); void setModeTransceiverTimer(); diff --git a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/transceiver_timer.cpp b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/transceiver_timer.cpp index 4cb85a0bf89a3d5455ba09bcf00499f74103eeed..a8c8ef9806608cc5f831d060c664d6e86be1056e 100644 --- a/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/transceiver_timer.cpp +++ b/miosix/arch/cortexM3_efm32gg/efm32gg332f1024_wandstem/interfaces-impl/transceiver_timer.cpp @@ -54,7 +54,7 @@ bool TransceiverTimer::absoluteWaitTimeoutOrEvent(long long tick){ if(tick<b.getCurrentTick()){ return true; } - + b.cleanBufferTrasceiver(); b.enableCC0Interrupt(false); b.enableCC0InterruptTim2(true); do { @@ -91,7 +91,7 @@ unsigned int TransceiverTimer::getTickFrequency() const{ long long TransceiverTimer::getExtEventTimestamp() const{ - return b.IRQgetSetTimeCCV0(); + return b.IRQgetSetTimeTransceiver(); } TransceiverTimer::TransceiverTimer():b(HighResolutionTimerBase::instance()),tc(b.getTimerFrequency()) {