Skip to content

Commit 1f2b65b

Browse files
committed
disable PWM ownership within ISR()
takeOwnership / releaseOwnership must be called in thread-context
1 parent c3f8e34 commit 1f2b65b

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

cores/nRF5/HardwarePWM.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -287,18 +287,10 @@ bool HardwarePWM::takeOwnership(uintptr_t token)
287287
if ( this->usedChannelCount() != 0 ) return false;
288288
if ( this->enabled() ) return false;
289289

290-
if ( isInISR() )
291-
{
292-
UBaseType_t intr_status = taskENTER_CRITICAL_FROM_ISR();
293-
_owner_token = token;
294-
taskEXIT_CRITICAL_FROM_ISR(intr_status);
295-
}
296-
else
297-
{
298-
taskENTER_CRITICAL();
299-
_owner_token = token;
300-
taskEXIT_CRITICAL();
301-
}
290+
// This function must not be called within ISR
291+
taskENTER_CRITICAL();
292+
_owner_token = token;
293+
taskEXIT_CRITICAL();
302294

303295
return true;
304296
}
@@ -326,18 +318,10 @@ bool HardwarePWM::releaseOwnership(uintptr_t token)
326318
return false; // if it's enabled, do not allow ownership to be released, even with no pins in use
327319
}
328320

329-
if ( isInISR() )
330-
{
331-
UBaseType_t intr_status = taskENTER_CRITICAL_FROM_ISR();
332-
_owner_token = 0;
333-
taskEXIT_CRITICAL_FROM_ISR(intr_status);
334-
}
335-
else
336-
{
337-
taskENTER_CRITICAL();
338-
_owner_token = 0;
339-
taskEXIT_CRITICAL();
340-
}
321+
// This function must not be called within ISR
322+
taskENTER_CRITICAL();
323+
_owner_token = 0;
324+
taskEXIT_CRITICAL();
341325

342326
return true;
343327
}

0 commit comments

Comments
 (0)