Mutexes and esp_timer

vyo2003
Posts: 19
Joined: Fri Dec 22, 2017 8:36 am

Mutexes and esp_timer

Postby vyo2003 » Fri Dec 22, 2017 8:53 am

I want to use `esp_timer` with low delay (150us and below) with mutexes. What is the best way to do it?

My current ideas:
  • Start new task each time and wait for mutex within. What about performance?
  • Start separated task and queue timer notification to it. What about performance, again?
  • Just check and skip tick if mutex is busy. Worst, but OK solution.
I play sound via DAC (yes, I know about I2S), so delay between ticks is very important.
What about already listed ideas, or is thre better one?

P.s.: I have noticed about calling directly from timer's ISR, is it possible?

ESP_Sprite
Posts: 9708
Joined: Thu Nov 26, 2015 4:08 am

Re: Mutexes and esp_timer

Postby ESP_Sprite » Fri Dec 22, 2017 2:16 pm

You need low latency and all you need to do is to push a byte to the DAC, right? In that case, I would just do that in the ISR. Make sure you un-block a semaphore or something if your buffer is mostly empty, so you can have a thread fill it up when needed.

vyo2003
Posts: 19
Joined: Fri Dec 22, 2017 8:36 am

Re: Mutexes and esp_timer

Postby vyo2003 » Fri Dec 22, 2017 2:28 pm

Thank you for this idea, but what do you mean under ISR? https://esp-idf.readthedocs.io/en/lates ... timer.html say that it still isn't implemented.

Also, there is another problem: I should make some calculations (not expensive), so I still need a way to handle thread-unsafe situation.

But idea of refilling task sounds very usable. Thank you for it!

ESP_Sprite
Posts: 9708
Joined: Thu Nov 26, 2015 4:08 am

Re: Mutexes and esp_timer

Postby ESP_Sprite » Sat Dec 23, 2017 5:33 am

You can use one of the hardware timers for this instead of the built-in esp-timer modules. (e.g. https://esp-idf.readthedocs.io/en/lates ... timer.html ). For calculations and other stuff that only use a fixed, low amount of time to complete, you can use portENTER_CRITICAL[_ISR]/portEXIT_CRITICAL[_ISR] to use as a mutex. Just make sure to not call any function which name does not end in _ISR/_FROM_ISR in an interrupt service routine.

vyo2003
Posts: 19
Joined: Fri Dec 22, 2017 8:36 am

Re: Mutexes and esp_timer

Postby vyo2003 » Sat Dec 23, 2017 9:48 am

Thank you very much for this idea, but is there a way to start many timers (I don't want to use one or two of total three aviable timers). Is thre a way to create as many timers as I want, like in esp-timer, but blockable by mutex?

Why do you suggest using ISR instead of task? How soon using call directly from ISR will be aviable in esp-timer?

Who is online

Users browsing this forum: ESP_Roland and 41 guests