fix possible race condition
This commit is contained in:
1 parent
0205da555a
commit
6f2adf4f62
2 files changed
+21
-7
No files matched your search
@@ -289,10 +289,13 @@ bool HardwarePWM::takeOwnership(uintptr_t token)
|
||||
|
||||
// This function must not be called within ISR
|
||||
taskENTER_CRITICAL();
|
||||
_owner_token = token;
|
||||
if ( this->_owner_token == 0 )
|
||||
{
|
||||
_owner_token = token;
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
return true;
|
||||
return _owner_token == token;
|
||||
}
|
||||
|
||||
// returns true ONLY when (1) no PWM channel has a pin attached, and (2) the owner token matches
|
||||
@@ -320,8 +323,11 @@ bool HardwarePWM::releaseOwnership(uintptr_t token)
|
||||
|
||||
// This function must not be called within ISR
|
||||
taskENTER_CRITICAL();
|
||||
_owner_token = 0;
|
||||
if ( this->_owner_token == token )
|
||||
{
|
||||
_owner_token = 0;
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
return true;
|
||||
return _owner_token == 0;
|
||||
}
|
||||
@@ -48,11 +48,19 @@ uint8_t Servo::attach(int pin, int min, int max)
|
||||
}
|
||||
bool succeeded = false;
|
||||
|
||||
if (min < MIN_PULSE_WIDTH) min = MIN_PULSE_WIDTH;
|
||||
if (max > MAX_PULSE_WIDTH) max = MAX_PULSE_WIDTH;
|
||||
if (min < MIN_PULSE_WIDTH)
|
||||
{
|
||||
min = MIN_PULSE_WIDTH;
|
||||
}
|
||||
|
||||
if (max > MAX_PULSE_WIDTH)
|
||||
{
|
||||
max = MAX_PULSE_WIDTH;
|
||||
}
|
||||
|
||||
//fix min if conversion to pulse cycle value is too low
|
||||
if ( (min/DUTY_CYCLE_RESOLUTION) * DUTY_CYCLE_RESOLUTION < min) {
|
||||
if ( (min / DUTY_CYCLE_RESOLUTION) * DUTY_CYCLE_RESOLUTION < min )
|
||||
{
|
||||
min += DUTY_CYCLE_RESOLUTION;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user