Skip to content

Commit 7bc2fae

Browse files
committed
esp_wifi: Add esp_wifi_get_tsf_time() API to get the tsf time of
specified interface. Closes espressif/esp-idf#5533
1 parent f29370b commit 7bc2fae

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

components/esp_wifi/esp32/esp_adapter.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ static void IRAM_ATTR wifi_int_restore_wrapper(void *wifi_int_mux, uint32_t tmp)
211211
}
212212
}
213213

214+
static bool IRAM_ATTR is_from_isr_wrapper(void)
215+
{
216+
return xPortInIsrContext();
217+
}
218+
214219
static void IRAM_ATTR task_yield_from_isr_wrapper(void)
215220
{
216221
portYIELD_FROM_ISR();
@@ -636,6 +641,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
636641
._coex_condition_set = coex_condition_set_wrapper,
637642
._coex_wifi_request = coex_wifi_request_wrapper,
638643
._coex_wifi_release = coex_wifi_release_wrapper,
644+
._is_from_isr = is_from_isr_wrapper,
639645
._magic = ESP_WIFI_OS_ADAPTER_MAGIC,
640646
};
641647

components/esp_wifi/esp32s2/esp_adapter.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ static void IRAM_ATTR wifi_int_restore_wrapper(void *wifi_int_mux, uint32_t tmp)
201201
}
202202
}
203203

204+
static bool IRAM_ATTR is_from_isr_wrapper(void)
205+
{
206+
return xPortInIsrContext();
207+
}
208+
204209
static void IRAM_ATTR task_yield_from_isr_wrapper(void)
205210
{
206211
portYIELD_FROM_ISR();
@@ -635,6 +640,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
635640
._coex_condition_set = coex_condition_set_wrapper,
636641
._coex_wifi_request = coex_wifi_request_wrapper,
637642
._coex_wifi_release = coex_wifi_release_wrapper,
643+
._is_from_isr = is_from_isr_wrapper,
638644
._magic = ESP_WIFI_OS_ADAPTER_MAGIC,
639645
};
640646

components/esp_wifi/include/esp_private/wifi_os_adapter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
extern "C" {
2222
#endif
2323

24-
#define ESP_WIFI_OS_ADAPTER_VERSION 0x00000006
24+
#define ESP_WIFI_OS_ADAPTER_VERSION 0x00000007
2525
#define ESP_WIFI_OS_ADAPTER_MAGIC 0xDEADBEAF
2626

2727
#define OSI_FUNCS_TIME_BLOCKING 0xffffffff
@@ -133,6 +133,7 @@ typedef struct {
133133
void (* _coex_condition_set)(uint32_t type, bool dissatisfy);
134134
int32_t (* _coex_wifi_request)(uint32_t event, uint32_t latency, uint32_t duration);
135135
int32_t (* _coex_wifi_release)(uint32_t event);
136+
bool (* _is_from_isr)(void);
136137
int32_t _magic;
137138
} wifi_osi_funcs_t;
138139

components/esp_wifi/include/esp_wifi.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,19 @@ esp_err_t esp_wifi_set_ant(const wifi_ant_config_t *config);
10931093
*/
10941094
esp_err_t esp_wifi_get_ant(wifi_ant_config_t *config);
10951095

1096+
/**
1097+
* @brief Get the TSF time
1098+
* In Station mode or SoftAP+Station mode if station is not connected or station doesn't receive at least
1099+
* one beacon after connected, will return 0
1100+
*
1101+
* @attention Enabling power save may cause the return value inaccurate, except WiFi modem sleep
1102+
*
1103+
* @param interface The interface whose tsf_time is to be retrieved.
1104+
*
1105+
* @return 0 or the TSF time
1106+
*/
1107+
int64_t esp_wifi_get_tsf_time(wifi_interface_t interface);
1108+
10961109
#ifdef __cplusplus
10971110
}
10981111
#endif

0 commit comments

Comments
 (0)