Page 1 of 1
About the timestamp accuracy in wifi packet acceptance
Posted: Sun Aug 27, 2023 6:32 am
by salieri
I call the function esp_cpu_get_cycle_count() in the wifi sniffer's interrupt function wifi_sniffer_packet_handler() and record the current CPU cycle count. Can I assume that this CPU cycle count corresponds to the local timestamp when a wifi packet arrives at the receiving end, and that the precision of this timestamp is the same as the CPU clock precision?
Re: About the timestamp accuracy in wifi packet acceptance
Posted: Sun Aug 27, 2023 9:47 am
by ESP_Sprite
salieri wrote: ↑Sun Aug 27, 2023 6:32 am
I call the function esp_cpu_get_cycle_count() in the wifi sniffer's interrupt function wifi_sniffer_packet_handler() and record
the current CPU cycle count. Can I assume that
this CPU cycle count corresponds to
the local timestamp when a wifi packet arrives at the receiving end, and that the precision of this timestamp is the same as the CPU clock precision?
No, you cannot assume that as there may be an undeterminable amount of latency between the packet coming in and the handler being triggered.
Re: About the timestamp accuracy in wifi packet acceptance
Posted: Sun Aug 27, 2023 11:04 am
by salieri
But the process of receiving the two wifi packets is the same. I can assume that the cpu count difference between the two wifi packets is correct, right?
Re: About the timestamp accuracy in wifi packet acceptance
Posted: Mon Aug 28, 2023 12:25 am
by MicroController
No. As Sprite said, there are several effects which can cause varying latencies (jitter) between the time a hardware event happens and the time your code gets to handle it, e.g. critical sections (also inside FreeRTOS itself) or higher-priority interrupts.
Re: About the timestamp accuracy in wifi packet acceptance
Posted: Mon Aug 28, 2023 12:40 am
by ESP_Sprite
Aside from software things, you can also have hardware things like cache misses or pipeline stalls because something is talking to a slow peripheral (e.g. slow rtc memory)
Re: About the timestamp accuracy in wifi packet acceptance
Posted: Mon Aug 28, 2023 5:45 am
by salieri
Thanks for the answers, I probably understand what you guys are saying. I learned from a paper that you can use cpu cycle to record wifi packet arrival times as shown in the figure. Is there any way I can record the cpu cycle of wifi packet arrival?
Re: About the timestamp accuracy in wifi packet acceptance
Posted: Mon Aug 28, 2023 6:41 am
by ESP_Sprite
It's not possible to do this on production firmware, in a way that will not have jitter, period. Perhaps the people making the paper were OK with jitter because they had a point to prove ('this is theoretically possible' vs 'this can be implemented in a practical sense'). You can try this if you want, but we as Espressif do not guarantee this will work, or that the timings won't change with a software or hardware change.