/* * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */#ifndef__ESP_SNTP_H__#define__ESP_SNTP_H__#include"lwip/err.h"#include"lwip/ip.h"#ifdef__cplusplusextern"C"{#endif/* * The time update takes place in the sntp_sync_time() function. * The user has the ability to redefine this function in order * to re-define its functionality. This function has two time update modes, * which can be set via the sntp_set_sync_mode() function. * Two available modes are as follows: * - the first is an immediate update when receiving time from the sntp server, * - the second is a smooth time update (if the time error is no more than 35 minutes, * and an immediate update if the error is more than 35 minutes). * * To receive notification of time synchronization, * you can use the callback function or get the synchronization status * via the sntp_get_sync_status() function. * * To determine the time synchronization time on the device, you can use: * 1) sntp_set_time_sync_notification_cb() function to set the callback function, * which is convenient to use to receive notification of the update time. * 2) sntp_get_sync_status() function for getting time synchronization status. * After the time synchronization is completed, the status will be * SNTP_SYNC_STATUS_COMPLETED, after, it will be reseted to SNTP_SYNC_STATUS_RESET * to wait for the next sync cycle. *//* ... *//// Aliases for esp_sntp prefixed API (inherently thread safe)#defineesp_sntp_sync_timesntp_sync_time#defineesp_sntp_set_sync_modesntp_set_sync_mode#defineesp_sntp_get_sync_modesntp_get_sync_mode#defineesp_sntp_get_sync_statussntp_get_sync_status#defineesp_sntp_set_sync_statussntp_set_sync_status#defineesp_sntp_set_time_sync_notification_cbsntp_set_time_sync_notification_cb#defineesp_sntp_set_sync_intervalsntp_set_sync_interval#defineesp_sntp_get_sync_intervalsntp_get_sync_interval#defineesp_sntp_restartsntp_restart9 defines#ifndefSNTP_OPMODE_POLL#defineSNTP_OPMODE_POLLESP_SNTP_OPMODE_POLL#else#warning"Defined!"#endif/* SNTP_OPMODE_POLL *//// SNTP time update modetypedefenum{SNTP_SYNC_MODE_IMMED,/*!< Update system time immediately when receiving a response from the SNTP server. */SNTP_SYNC_MODE_SMOOTH,/*!< Smooth time updating. Time error is gradually reduced using adjtime function. If the difference between SNTP response time and system time is large (more than 35 minutes) then update immediately. */}{ ... }sntp_sync_mode_t;/// SNTP sync statustypedefenum{SNTP_SYNC_STATUS_RESET,// Reset status.SNTP_SYNC_STATUS_COMPLETED,// Time is synchronized.SNTP_SYNC_STATUS_IN_PROGRESS,// Smooth time sync in progress.}{ ... }sntp_sync_status_t;/// SNTP operating modes per lwip SNTP moduletypedefenum{ESP_SNTP_OPMODE_POLL,ESP_SNTP_OPMODE_LISTENONLY,}{ ... }esp_sntp_operatingmode_t;/** * @brief SNTP callback function for notifying about time sync event * * @param tv Time received from SNTP server. *//* ... */typedefvoid(*sntp_sync_time_cb_t)(structtimeval*tv);/** * @brief This function updates the system time. * * This is a weak-linked function. It is possible to replace all SNTP update functionality * by placing a sntp_sync_time() function in the app firmware source. * If the default implementation is used, calling sntp_set_sync_mode() allows * the time synchronization mode to be changed to instant or smooth. * If a callback function is registered via sntp_set_time_sync_notification_cb(), * it will be called following time synchronization. * * @param tv Time received from SNTP server. *//* ... */voidsntp_sync_time(structtimeval*tv);/** * @brief Set the sync mode * * Modes allowed: SNTP_SYNC_MODE_IMMED and SNTP_SYNC_MODE_SMOOTH. * @param sync_mode Sync mode. *//* ... */voidsntp_set_sync_mode(sntp_sync_mode_tsync_mode);/** * @brief Get set sync mode * * @return SNTP_SYNC_MODE_IMMED: Update time immediately. * SNTP_SYNC_MODE_SMOOTH: Smooth time updating. *//* ... */sntp_sync_mode_tsntp_get_sync_mode(void);/** * @brief Get status of time sync * * After the update is completed, the status will be returned as SNTP_SYNC_STATUS_COMPLETED. * After that, the status will be reset to SNTP_SYNC_STATUS_RESET. * If the update operation is not completed yet, the status will be SNTP_SYNC_STATUS_RESET. * If a smooth mode was chosen and the synchronization is still continuing (adjtime works), then it will be SNTP_SYNC_STATUS_IN_PROGRESS. * * @return SNTP_SYNC_STATUS_RESET: Reset status. * SNTP_SYNC_STATUS_COMPLETED: Time is synchronized. * SNTP_SYNC_STATUS_IN_PROGRESS: Smooth time sync in progress. *//* ... */sntp_sync_status_tsntp_get_sync_status(void);/** * @brief Set status of time sync * * @param sync_status status of time sync (see sntp_sync_status_t) *//* ... */voidsntp_set_sync_status(sntp_sync_status_tsync_status);/** * @brief Set a callback function for time synchronization notification * * @param callback a callback function *//* ... */voidsntp_set_time_sync_notification_cb(sntp_sync_time_cb_tcallback);/** * @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. *//* ... */voidsntp_set_sync_interval(uint32_tinterval_ms);/** * @brief Get the sync interval of SNTP operation * * @return the sync interval *//* ... */uint32_tsntp_get_sync_interval(void);/** * @brief Restart SNTP * * @return True - Restart * False - SNTP was not initialized yet *//* ... */boolsntp_restart(void);/** * @brief Sets SNTP operating mode. The mode has to be set before init. * * @param operating_mode Desired operating mode *//* ... */voidesp_sntp_setoperatingmode(esp_sntp_operatingmode_toperating_mode);/** * @brief Init and start SNTP service *//* ... */voidesp_sntp_init(void);/** * @brief Stops SNTP service *//* ... */voidesp_sntp_stop(void);/** * @brief Sets SNTP server address * * @param idx Index of the server * @param addr IP address of the server *//* ... */voidesp_sntp_setserver(u8_tidx,constip_addr_t*addr);/** * @brief Sets SNTP hostname * @param idx Index of the server * @param server Name of the server *//* ... */voidesp_sntp_setservername(u8_tidx,constchar*server);/** * @brief Gets SNTP server name * @param idx Index of the server * @return Name of the server *//* ... */constchar*esp_sntp_getservername(u8_tidx);/** * @brief Get SNTP server IP * @param idx Index of the server * @return IP address of the server *//* ... */constip_addr_t*esp_sntp_getserver(u8_tidx);/** * @brief Checks if sntp is enabled * @return true if sntp module is enabled *//* ... */boolesp_sntp_enabled(void);/** * @brief Gets the server reachability shift register as described in RFC 5905. * @param idx Index of the SNTP server * @return reachability shift register *//* ... */uint8_tesp_sntp_getreachability(uint8_tidx);/** * @brief Get the configured operating mode * * @return operating mode enum *//* ... */esp_sntp_operatingmode_tesp_sntp_getoperatingmode(void);#ifLWIP_DHCP_GET_NTP_SRV/** * @brief Enable acquiring SNTP server from DHCP * @param enable True for enabling SNTP from DHCP *//* ... */voidesp_sntp_servermode_dhcp(boolenable);/* ... */#endif/* LWIP_DHCP_GET_NTP_SRV */#if!defined(ESP_LWIP_COMPONENT_BUILD)&&!defined(ESP_NETIF_COMPONENT_BUILD)/** * @brief if not build within lwip, provide translating inlines, * that will warn about thread safety *//* ... */staticinline__attribute__((deprecated("use esp_sntp_setoperatingmode() instead")))voidsntp_setoperatingmode(u8_toperating_mode){esp_sntp_setoperatingmode((esp_sntp_operatingmode_t)operating_mode);}{...}staticinline__attribute__((deprecated("use esp_sntp_servermode_dhcp() instead")))voidsntp_servermode_dhcp(intset_servers_from_dhcp){#ifLWIP_DHCP_GET_NTP_SRVesp_sntp_servermode_dhcp(set_servers_from_dhcp);#endif}{...}staticinline__attribute__((deprecated("use esp_sntp_setservername() instead")))voidsntp_setservername(u8_tidx,constchar*server){esp_sntp_setservername(idx,server);}{...}staticinline__attribute__((deprecated("use esp_sntp_init() instead")))voidsntp_init(void){esp_sntp_init();}{...}staticinline__attribute__((deprecated("use esp_sntp_getservername() instead")))constchar*sntp_getservername(u8_tidx){returnesp_sntp_getservername(idx);}{...}staticinline__attribute__((deprecated("use esp_sntp_getserver() instead")))constip_addr_t*sntp_getserver(u8_tidx){returnesp_sntp_getserver(idx);}{...}staticinline__attribute__((deprecated("use esp_sntp_getreachability() instead")))uint8_tsntp_getreachability(uint8_tidx){returnesp_sntp_getreachability(idx);}{...}staticinline__attribute__((deprecated("use esp_sntp_getoperatingmode() instead")))esp_sntp_operatingmode_tsntp_getoperatingmode(void){returnesp_sntp_getoperatingmode();}{...}/* ... */#endif/* ESP_LWIP_COMPONENT_BUILD */#ifdef__cplusplus}{...}#endif/* ... */#endif// __ESP_SNTP_H__
Details
Show: from
Types: Columns:
All items filtered out
All items filtered out
This file uses the notable symbols shown below. Click anywhere in the file to view more details.