Skip to content

Commit a71fa82

Browse files
committed
esp_netif/lwip: Fix core-locking config
* Fix thread safety issues in non-core locking * Add option to verify thread safety issues in lwip (core-lock assertion) * Make esp_sntp.h thread safe API * Fix sntp examples * Fix openthread libs Closes #9908 Closes #10502 Closes #10466
1 parent 9e24739 commit a71fa82

File tree

43 files changed

+1189
-309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1189
-309
lines changed

components/esp_netif/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ endif()
88

99
set(srcs_lwip
1010
"lwip/esp_netif_lwip.c"
11+
"lwip/esp_netif_sntp.c"
1112
"lwip/esp_netif_lwip_defaults.c"
1213
"lwip/netif/wlanif.c"
1314
"lwip/netif/ethernetif.c"
@@ -55,3 +56,4 @@ endif()
5556

5657

5758
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
59+
target_compile_definitions(${COMPONENT_LIB} PRIVATE ESP_NETIF_COMPONENT_BUILD)

components/esp_netif/include/esp_netif.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,34 @@ esp_err_t esp_netif_bridge_fdb_add(esp_netif_t *esp_netif_br, uint8_t *addr, uin
306306
esp_err_t esp_netif_bridge_fdb_remove(esp_netif_t *esp_netif_br, uint8_t *addr);
307307
#endif // CONFIG_ESP_NETIF_BRIDGE_EN
308308

309+
/**
310+
* @brief Cause the TCP/IP stack to join a IPv6 multicast group
311+
*
312+
* @param[in] esp_netif Handle to esp-netif instance
313+
* @param[in] addr The multicast group to join
314+
*
315+
* @return
316+
* - ESP_OK
317+
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
318+
* - ESP_ERR_ESP_NETIF_MLD6_FAILED
319+
* - ESP_ERR_NO_MEM
320+
*/
321+
esp_err_t esp_netif_join_ip6_multicast_group(esp_netif_t *esp_netif, const esp_ip6_addr_t *addr);
322+
323+
/**
324+
* @brief Cause the TCP/IP stack to leave a IPv6 multicast group
325+
*
326+
* @param[in] esp_netif Handle to esp-netif instance
327+
* @param[in] addr The multicast group to leave
328+
*
329+
* @return
330+
* - ESP_OK
331+
* - ESP_ERR_ESP_NETIF_INVALID_PARAMS
332+
* - ESP_ERR_ESP_NETIF_MLD6_FAILED
333+
* - ESP_ERR_NO_MEM
334+
*/
335+
esp_err_t esp_netif_leave_ip6_multicast_group(esp_netif_t *esp_netif, const esp_ip6_addr_t *addr);
336+
309337
/**
310338
* @}
311339
*/
@@ -940,6 +968,27 @@ void esp_netif_netstack_buf_ref(void *netstack_buf);
940968
*/
941969
void esp_netif_netstack_buf_free(void *netstack_buf);
942970

971+
/**
972+
* @}
973+
*/
974+
975+
/** @addtogroup ESP_NETIF_TCPIP_EXEC
976+
* @{
977+
*/
978+
979+
/**
980+
* @brief TCPIP thread safe callback used with esp_netif_tcpip_exec()
981+
*/
982+
typedef esp_err_t (*esp_netif_callback_fn)(void *ctx);
983+
984+
/**
985+
* @brief Utility to execute the supplied callback in TCP/IP context
986+
* @param fn Pointer to the callback
987+
* @param ctx Parameter to the callback
988+
* @return The error code (esp_err_t) returned by the callback
989+
*/
990+
esp_err_t esp_netif_tcpip_exec(esp_netif_callback_fn fn, void *ctx);
991+
943992
/**
944993
* @}
945994
*/
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdbool.h>
10+
#include <stdint.h>
11+
#include "freertos/FreeRTOS.h"
12+
#include "esp_err.h"
13+
#include "esp_netif_types.h"
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
19+
/**
20+
* @defgroup ESP_NETIF_SNTP_API ESP-NETIF SNTP API
21+
* @brief SNTP API for underlying TCP/IP stack
22+
*
23+
*/
24+
25+
/** @addtogroup ESP_NETIF_SNTP_API
26+
* @{
27+
*/
28+
29+
30+
/**
31+
* @brief Time sync notification function
32+
*/
33+
typedef void (*esp_sntp_time_cb_t)(struct timeval *tv);
34+
35+
/**
36+
* @brief Utility macro for providing multiple servers in parentheses
37+
*/
38+
#define ESP_SNTP_SERVER_LIST(...) { __VA_ARGS__ }
39+
40+
/**
41+
* @brief Default configuration to init SNTP with multiple servers
42+
* @param servers_in_list Number of servers in the list
43+
* @param list_of_servers List of servers (use ESP_SNTP_SERVER_LIST(...))
44+
*
45+
*/
46+
#define ESP_NETIF_SNTP_DEFAULT_CONFIG_MULTIPLE(servers_in_list, list_of_servers) { \
47+
.smooth_sync = false, \
48+
.server_from_dhcp = false, \
49+
.wait_for_sync = true, \
50+
.start = true, \
51+
.sync_cb = NULL, \
52+
.renew_servers_after_new_IP = false, \
53+
.ip_event_to_renew = 0, \
54+
.index_of_first_server = 0, \
55+
.num_of_servers = (servers_in_list), \
56+
.servers = list_of_servers, \
57+
}
58+
59+
/**
60+
* @brief Default configuration with a single server
61+
*/
62+
#define ESP_NETIF_SNTP_DEFAULT_CONFIG(server) \
63+
ESP_NETIF_SNTP_DEFAULT_CONFIG_MULTIPLE(1, {server})
64+
65+
/**
66+
* @brief SNTP configuration struct
67+
*/
68+
typedef struct esp_sntp_config {
69+
bool smooth_sync; ///< set to true if smooth sync required
70+
bool server_from_dhcp; ///< set to true to request NTP server config from DHCP
71+
bool wait_for_sync; ///< if true, we create a semaphore to signal time sync event
72+
bool start; ///< set to true to automatically start the SNTP service
73+
esp_sntp_time_cb_t sync_cb; ///< optionally sets callback function on time sync event
74+
bool renew_servers_after_new_IP; ///< this is used to refresh server list if NTP provided by DHCP (which cleans other pre-configured servers)
75+
ip_event_t ip_event_to_renew; ///< set the IP event id on which we refresh server list (if renew_servers_after_new_IP=true)
76+
size_t index_of_first_server; ///< refresh server list after this server (if renew_servers_after_new_IP=true)
77+
size_t num_of_servers; ///< number of preconfigured NTP servers
78+
const char* servers[CONFIG_LWIP_SNTP_MAX_SERVERS]; ///< list of servers
79+
} esp_sntp_config_t;
80+
81+
/**
82+
* @brief Initialize SNTP with supplied config struct
83+
* @param config Config struct
84+
* @return ESP_OK on success
85+
*/
86+
esp_err_t esp_netif_sntp_init(const esp_sntp_config_t * config);
87+
88+
/**
89+
* @brief Start SNTP service
90+
* if it wasn't started during init (config.start = false)
91+
* or restart it if already started
92+
* @return ESP_OK on success
93+
*/
94+
esp_err_t esp_netif_sntp_start(void);
95+
96+
/**
97+
* @brief Deinitialize esp_netif SNTP module
98+
*/
99+
void esp_netif_sntp_deinit(void);
100+
101+
/**
102+
* @brief Wait for time sync event
103+
* @param tout Specified timeout in RTOS ticks
104+
* @return ESP_TIMEOUT if sync event didn't came withing the timeout
105+
* ESP_ERR_NOT_FINISHED if the sync event came, but we're in smooth update mode and still in progress (SNTP_SYNC_STATUS_IN_PROGRESS)
106+
* ESP_OK if time sync'ed
107+
*/
108+
esp_err_t esp_netif_sntp_sync_wait(TickType_t tout);
109+
110+
/**
111+
* @}
112+
*/
113+
114+
#ifdef __cplusplus
115+
}
116+
#endif

0 commit comments

Comments
 (0)