Long critical sections causing missed interrupts
Posted: Thu May 16, 2024 10:01 pm
I finally figured out I was missing interrupts at times and traced it to a critical section in i2s_tdm_set_clock(). That function enters a critical section and calls i2s_hal_set_tx_clock() which calls i2s_hal_calc_mclk_precise_division() which takes 1.6ms! This is on an ESP32S3 running at 240mhz. The time is spent in the calculation in hal_utils_calc_clk_div_frac_accurate. That calculation does not need to be in a critical section and clearly it should not be. Can't have critical sections taking milliseconds. My worry is that there are others, because I have seen missed interrupts being caused in other critical sections, just haven't trapped them in the debugger.
Anyone else seeing this? If not, beware because it could bite you if you have a moderately high frequency interrupt. Espressif, please time your critical sections and make sure only necessary code is in there. Is there any particular reason that this calculation could be taking longer on my system than it should be?
Anyone else seeing this? If not, beware because it could bite you if you have a moderately high frequency interrupt. Espressif, please time your critical sections and make sure only necessary code is in there. Is there any particular reason that this calculation could be taking longer on my system than it should be?