mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'feature/sntp_api_sync_interval' into 'master'
sntp: Add API to set update interval Closes IDFGH-2298 See merge request espressif/esp-idf!6956
This commit is contained in:
commit
9d196ce51f
@ -18,12 +18,14 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "sntp.h"
|
#include "sntp.h"
|
||||||
|
#include "lwip/apps/sntp.h"
|
||||||
|
|
||||||
static const char *TAG = "sntp";
|
static const char *TAG = "sntp";
|
||||||
|
|
||||||
static volatile sntp_sync_mode_t sntp_sync_mode = SNTP_SYNC_MODE_IMMED;
|
static volatile sntp_sync_mode_t sntp_sync_mode = SNTP_SYNC_MODE_IMMED;
|
||||||
static volatile sntp_sync_status_t sntp_sync_status = SNTP_SYNC_STATUS_RESET;
|
static volatile sntp_sync_status_t sntp_sync_status = SNTP_SYNC_STATUS_RESET;
|
||||||
static sntp_sync_time_cb_t time_sync_notification_cb = NULL;
|
static sntp_sync_time_cb_t time_sync_notification_cb = NULL;
|
||||||
|
static uint32_t s_sync_interval = CONFIG_LWIP_SNTP_UPDATE_DELAY;
|
||||||
|
|
||||||
inline void sntp_set_sync_status(sntp_sync_status_t sync_status)
|
inline void sntp_set_sync_status(sntp_sync_status_t sync_status)
|
||||||
{
|
{
|
||||||
@ -91,3 +93,27 @@ sntp_sync_status_t sntp_get_sync_status(void)
|
|||||||
}
|
}
|
||||||
return ret_sync_status;
|
return ret_sync_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sntp_set_sync_interval(uint32_t interval_ms)
|
||||||
|
{
|
||||||
|
if (interval_ms < 15000) {
|
||||||
|
// SNTPv4 RFC 4330 enforces a minimum update time of 15 seconds
|
||||||
|
interval_ms = 15000;
|
||||||
|
}
|
||||||
|
s_sync_interval = interval_ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t sntp_get_sync_interval(void)
|
||||||
|
{
|
||||||
|
return s_sync_interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sntp_restart(void)
|
||||||
|
{
|
||||||
|
if (sntp_enabled()) {
|
||||||
|
sntp_stop();
|
||||||
|
sntp_init();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -120,6 +120,33 @@ void sntp_set_sync_status(sntp_sync_status_t sync_status);
|
|||||||
*/
|
*/
|
||||||
void sntp_set_time_sync_notification_cb(sntp_sync_time_cb_t callback);
|
void sntp_set_time_sync_notification_cb(sntp_sync_time_cb_t callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the sync interval of SNTP operation
|
||||||
|
*
|
||||||
|
* Note: SNTPv4 RFC 4330 enforces a minimum sync interval of 15 seconds.
|
||||||
|
* This sync interval will be used in the next attempt update time throught SNTP.
|
||||||
|
* To apply the new sync interval call the sntp_restart() function,
|
||||||
|
* otherwise, it will be applied after the last interval expired.
|
||||||
|
*
|
||||||
|
* @param interval_ms The sync interval in ms. It cannot be lower than 15 seconds, otherwise 15 seconds will be set.
|
||||||
|
*/
|
||||||
|
void sntp_set_sync_interval(uint32_t interval_ms);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the sync interval of SNTP operation
|
||||||
|
*
|
||||||
|
* @return the sync interval
|
||||||
|
*/
|
||||||
|
uint32_t sntp_get_sync_interval(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Restart SNTP
|
||||||
|
*
|
||||||
|
* @return True - Restart
|
||||||
|
* False - SNTP was not initialized yet
|
||||||
|
*/
|
||||||
|
bool sntp_restart(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -844,7 +844,10 @@
|
|||||||
*/
|
*/
|
||||||
#define SNTP_SERVER_DNS 1
|
#define SNTP_SERVER_DNS 1
|
||||||
|
|
||||||
#define SNTP_UPDATE_DELAY CONFIG_LWIP_SNTP_UPDATE_DELAY
|
// It disables a check of SNTP_UPDATE_DELAY it is done in sntp_set_sync_interval
|
||||||
|
#define SNTP_SUPPRESS_DELAY_CHECK
|
||||||
|
|
||||||
|
#define SNTP_UPDATE_DELAY (sntp_get_sync_interval())
|
||||||
|
|
||||||
#define SNTP_SET_SYSTEM_TIME_US(sec, us) \
|
#define SNTP_SET_SYSTEM_TIME_US(sec, us) \
|
||||||
do { \
|
do { \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user