Page 1 of 2

esp_register_freertos_tick_hook() verus FreeRTOS vApplicationTickHook()

Posted: Tue Jun 19, 2018 6:28 pm
by frankket
Hi all

I need to setup a regular tick feature. The freeRTOS "vanilla" vApplicationTickHook() would work, but I see that the ESP-IDF provides it’s own time hook API (esp_register_freertos_tick_hook), one for each core. This seems like a better choice than the FreeRTOS option, but I can find very the little information on setting up the IDF versions (unless I've missed something in this forum - in which case I apologise for wasting your time) and none of the IDF examples seem to have code with the esp_register_freertos_tick_hook included.

so herewith:

1) I assume that esp_register_freertos_tick_hook() is setup in the configuration options, but which one/s?
2) I am assuming that the CONFIG_FREERTOS_HZ setting is for the freeRTOS "vanilla" vApplicationTickHook() and not the esp_register_freertos_tick_hook()? Or does it do both hooks, depending which one is activate / select?
3) I see that I can actively enable the CONFIG_FREERTOS_LEGACY_TICK_HOOK - does that mean that if this is not activated the ESP-IDF esp_register_freertos_tick_hook() is active?
4) Can I run esp_register_freertos_tick_hook() for each core concurrently?
5) and if yes, can I set a different tick frequency for each core?


many thanks

Frank

Re: esp_register_freertos_tick_hook() verus FreeRTOS vApplicationTickHook()

Posted: Tue Jun 19, 2018 11:38 pm
by ESP_igrr
For the information about FreeRTOS hooks in ESP-IDF, please see https://docs.espressif.com/projects/esp ... html#hooks.

CONFIG_FREERTOS_HZ sets RTOS tick frequency. Same tick frequency is used for both CPUs, although ticks on the two CPUs are not synchronized. Both the traditional FreeRTOS hook and IDF per-CPU hooks are called from tick interrupt, therefore the frequency is CONFIG_FREERTOS_HZ on each core.

Re: esp_register_freertos_tick_hook() verus FreeRTOS vApplicationTickHook()

Posted: Wed Jun 20, 2018 7:35 pm
by frankket
Thank you - that's much clearer. Much appreciated.

Frank

Re: esp_register_freertos_tick_hook() verus FreeRTOS vApplicationTickHook()

Posted: Wed Oct 24, 2018 7:38 pm
by snahmad75
I am using "esp_register_freertos_idle_hook_for_cpu" to register my function to get called every 1ms.

Is this good way.

Thanks,
Naeem

Re: esp_register_freertos_tick_hook() verus FreeRTOS vApplicationTickHook()

Posted: Thu Oct 25, 2018 5:35 am
by ESP_Angus
snahmad75 wrote:I am using "esp_register_freertos_idle_hook_for_cpu" to register my function to get called every 1ms.

Is this good way.
Idle hooks are only a good solution if you have a function you'd like called when the CPU is idle, only.

To get code which is called regularly you can use a FreeRTOS Timer:
https://docs.espressif.com/projects/esp ... Function_t

FreeRTOS timers will run at the RTOS tick rate, maximum.

If you need higher precision timers then you can use the esp_timer APIs:
https://docs.espressif.com/projects/esp ... timer.html

Re: esp_register_freertos_tick_hook() verus FreeRTOS vApplicationTickHook()

Posted: Thu Oct 25, 2018 9:46 am
by snahmad75
I can see esp_register_freertos_tick_hook_for_cpu or esp_register_freertos_tick_hook is not accurate for LED fading and increment or milliseconds count. we need accurate milliseconds counter. Do Esp32 have this already.

For LED on/off or fading every 1ms. This is not good enough.


Should I try use a FreeRTOS Timer then.



I did try higher precision timers then you can use the esp_timer APIs, but problem is esp timer queye gets overflow when I keep my CPU busy with hevy task like scan wifi access points or joining AP.

Re: esp_register_freertos_tick_hook() verus FreeRTOS vApplicationTickHook()

Posted: Thu Oct 25, 2018 1:16 pm
by ESP_Dazz
snahmad75 wrote:For LED on/off or fading every 1ms. This is not good enough.
Why not just use the LED_PWM controller?

Re: esp_register_freertos_tick_hook() verus FreeRTOS vApplicationTickHook()

Posted: Thu Oct 25, 2018 4:32 pm
by snahmad75
ok, will try out and let you know.

Re: esp_register_freertos_tick_hook() verus FreeRTOS vApplicationTickHook()

Posted: Fri Oct 26, 2018 10:39 am
by snahmad75
I am using led_pwm controller.

I do ledc_fade_func_install.

but I need to call below functions every 1ms.
ledc_set_duty();
ledc_update_duty()


In which Task/thread can I do it. I was using esp timer. I avoid using est timer. queue gets overflow when cpu gets busy.

Re: esp_register_freertos_tick_hook() verus FreeRTOS vApplicationTickHook()

Posted: Mon Oct 29, 2018 6:29 am
by ESP_Dazz
snahmad75 wrote:but I need to call below functions every 1ms.
Maybe use the timer peripheral to generate sub millisecond interrupts, then modify ledc pwm in an ISR?