From 1f2b65bd4569ab771d840b893cc1dfc884d958db Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 25 Aug 2020 18:00:54 +0700 Subject: [PATCH] disable PWM ownership within ISR() takeOwnership / releaseOwnership must be called in thread-context --- cores/nRF5/HardwarePWM.cpp | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/cores/nRF5/HardwarePWM.cpp b/cores/nRF5/HardwarePWM.cpp index 55c229ca..adcfcaf3 100644 --- a/cores/nRF5/HardwarePWM.cpp +++ b/cores/nRF5/HardwarePWM.cpp @@ -287,18 +287,10 @@ bool HardwarePWM::takeOwnership(uintptr_t token) if ( this->usedChannelCount() != 0 ) return false; if ( this->enabled() ) return false; - if ( isInISR() ) - { - UBaseType_t intr_status = taskENTER_CRITICAL_FROM_ISR(); - _owner_token = token; - taskEXIT_CRITICAL_FROM_ISR(intr_status); - } - else - { - taskENTER_CRITICAL(); - _owner_token = token; - taskEXIT_CRITICAL(); - } + // This function must not be called within ISR + taskENTER_CRITICAL(); + _owner_token = token; + taskEXIT_CRITICAL(); return true; } @@ -326,18 +318,10 @@ bool HardwarePWM::releaseOwnership(uintptr_t token) return false; // if it's enabled, do not allow ownership to be released, even with no pins in use } - if ( isInISR() ) - { - UBaseType_t intr_status = taskENTER_CRITICAL_FROM_ISR(); - _owner_token = 0; - taskEXIT_CRITICAL_FROM_ISR(intr_status); - } - else - { - taskENTER_CRITICAL(); - _owner_token = 0; - taskEXIT_CRITICAL(); - } + // This function must not be called within ISR + taskENTER_CRITICAL(); + _owner_token = 0; + taskEXIT_CRITICAL(); return true; }