@@ -172,32 +172,13 @@ inline static int _bits_used(unsigned long long x) {
172172*/
173173void tone (uint8_t pin, unsigned int frequency, unsigned long duration)
174174{
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-
188175 // limit frequency to reasonable audible range
189176 if ((frequency < 20 ) | (frequency > 25000 )) {
190177 LOG_LV1 (" TON" , " frequency outside range [20..25000] -- ignoring" );
191178 return ;
192179 }
193-
194- if (xSemaphoreTake (_tone_semaphore, portMAX_DELAY) != pdTRUE) {
195- LOG_LV1 (" TON" , " error acquiring semaphore (should never occur?)" );
196- return ;
197- }
198180 uint64_t pulse_count = _calculate_pulse_count (frequency, duration);
199181 uint16_t time_period = _calculate_time_period (frequency);
200-
201182 if (!_pwm_config.ensurePwmPeripheralOwnership ()) {
202183 LOG_LV1 (" TON" , " Unable to acquire PWM peripheral" );
203184 } else if (!_pwm_config.stopPlayback ()) {
@@ -211,7 +192,6 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
211192 } else {
212193 // LOG_LV2("TON", "Started playback of tone at frequency %d duration %ld", frequency, duration);
213194 }
214- xSemaphoreGive (_tone_semaphore);
215195 return ;
216196}
217197void noTone (uint8_t pin)
0 commit comments