About the timestamp accuracy in wifi packet acceptance

salieri
Posts: 5
Joined: Thu Aug 24, 2023 8:43 am

About the timestamp accuracy in wifi packet acceptance

Postby salieri » 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?

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

Re: About the timestamp accuracy in wifi packet acceptance

Postby ESP_Sprite » Sun Aug 27, 2023 9:47 am

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.

salieri
Posts: 5
Joined: Thu Aug 24, 2023 8:43 am

Re: About the timestamp accuracy in wifi packet acceptance

Postby salieri » Sun Aug 27, 2023 11:04 am

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?

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: About the timestamp accuracy in wifi packet acceptance

Postby MicroController » Mon Aug 28, 2023 12:25 am

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.

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

Re: About the timestamp accuracy in wifi packet acceptance

Postby ESP_Sprite » Mon Aug 28, 2023 12:40 am

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)

salieri
Posts: 5
Joined: Thu Aug 24, 2023 8:43 am

Re: About the timestamp accuracy in wifi packet acceptance

Postby salieri » Mon Aug 28, 2023 5:45 am

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?
Attachments
1.png
Excerpts from the paper
1.png (450.82 KiB) Viewed 1059 times

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

Re: About the timestamp accuracy in wifi packet acceptance

Postby ESP_Sprite » Mon Aug 28, 2023 6:41 am

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.

Who is online

Users browsing this forum: Bing [Bot] and 128 guests