@@ -172,32 +172,13 @@ inline static int _bits_used(unsigned long long x) {
172
172
*/
173
173
void tone (uint8_t pin, unsigned int frequency, unsigned long duration)
174
174
{
175
- // Used only to protect calls against simultaneous multiple calls to tone().
176
- // Using a function-local static to avoid accidental reference from ISR or elsewhere,
177
- // and to simplify ensuring the semaphore gets initialized.
178
- static StaticSemaphore_t _tone_semaphore_allocation;
179
- static auto init_semaphore = [] () { // < use a lambda to both initialize AND give the mutex
180
- SemaphoreHandle_t handle = xSemaphoreCreateMutexStatic (&_tone_semaphore_allocation);
181
- auto mustSucceed = xSemaphoreGive (handle);
182
- (void )mustSucceed;
183
- NRFX_ASSERT (mustSucceed == pdTRUE);
184
- return handle;
185
- };
186
- static SemaphoreHandle_t _tone_semaphore = init_semaphore ();
187
-
188
175
// limit frequency to reasonable audible range
189
176
if ((frequency < 20 ) | (frequency > 25000 )) {
190
177
LOG_LV1 (" TON" , " frequency outside range [20..25000] -- ignoring" );
191
178
return ;
192
179
}
193
-
194
- if (xSemaphoreTake (_tone_semaphore, portMAX_DELAY) != pdTRUE) {
195
- LOG_LV1 (" TON" , " error acquiring semaphore (should never occur?)" );
196
- return ;
197
- }
198
180
uint64_t pulse_count = _calculate_pulse_count (frequency, duration);
199
181
uint16_t time_period = _calculate_time_period (frequency);
200
-
201
182
if (!_pwm_config.ensurePwmPeripheralOwnership ()) {
202
183
LOG_LV1 (" TON" , " Unable to acquire PWM peripheral" );
203
184
} else if (!_pwm_config.stopPlayback ()) {
@@ -211,7 +192,6 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
211
192
} else {
212
193
// LOG_LV2("TON", "Started playback of tone at frequency %d duration %ld", frequency, duration);
213
194
}
214
- xSemaphoreGive (_tone_semaphore);
215
195
return ;
216
196
}
217
197
void noTone (uint8_t pin)
0 commit comments