2016-03-09 16:18:51 +00:00
|
|
|
/************************************************************************//**
|
|
|
|
* RTC time keeping and synchronization using SNTP for esp-open-rtos.
|
|
|
|
* Uses SNTP lwIP contribution.
|
|
|
|
*
|
|
|
|
* 2016, Jesus Alonso (doragasu)
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _SNTP_H_
|
|
|
|
#define _SNTP_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2016-03-13 17:29:30 +00:00
|
|
|
#include <sys/time.h>
|
2016-03-09 16:18:51 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
2016-03-13 17:29:30 +00:00
|
|
|
/*
|
|
|
|
* Function used by lwIP sntp module to update the date/time,
|
|
|
|
* with microseconds resolution.
|
|
|
|
*/
|
2016-03-09 16:18:51 +00:00
|
|
|
#define SNTP_SET_SYSTEM_TIME_US(sec, us) sntp_update_rtc(sec, us)
|
|
|
|
|
2016-03-13 17:29:30 +00:00
|
|
|
/*
|
|
|
|
* For the lwIP implementation of SNTP to allow using names for NTP servers.
|
|
|
|
*/
|
2016-03-09 16:18:51 +00:00
|
|
|
#define SNTP_SERVER_DNS 1
|
|
|
|
|
2016-03-13 17:29:30 +00:00
|
|
|
/*
|
|
|
|
* Number of supported NTP servers
|
|
|
|
*/
|
2016-03-09 16:18:51 +00:00
|
|
|
#define SNTP_NUM_SERVERS_SUPPORTED 4
|
|
|
|
|
2016-03-13 17:29:30 +00:00
|
|
|
/*
|
|
|
|
* Initialize the module, and start requesting SNTP updates. This function
|
|
|
|
* must be called only once.
|
|
|
|
* WARNING: tz->tz_dsttime doesn't have the same meaning as the standard
|
|
|
|
* implementation. If it is set to 1, a dst hour will be applied. If set
|
|
|
|
* to zero, time will not be modified.
|
|
|
|
*/
|
|
|
|
void sntp_initialize(const struct timezone *tz);
|
2016-03-09 16:18:51 +00:00
|
|
|
|
2016-03-13 17:29:30 +00:00
|
|
|
/*
|
|
|
|
* Sets time zone. Allowed values are in the range [-11, 13].
|
|
|
|
* NOTE: Settings do not take effect until SNTP time is updated. It is
|
|
|
|
* recommended to set these parameters only during initialization.
|
|
|
|
* WARNING: tz->tz_dsttime doesn't have the same meaning as the standard
|
|
|
|
* implementation. If it is set to 1, a dst hour will be applied. If set
|
|
|
|
* to zero, time will not be modified.
|
|
|
|
*/
|
|
|
|
void sntp_set_timezone(const struct timezone *tz);
|
2016-03-09 16:18:51 +00:00
|
|
|
|
2016-03-13 17:29:30 +00:00
|
|
|
/*
|
|
|
|
* Set SNTP servers. Up to SNTP_NUM_SERVERS_SUPPORTED can be set.
|
|
|
|
* Returns 0 if OK, less than 0 if error.
|
|
|
|
* NOTE: This function must NOT be called before sntp_initialize().
|
|
|
|
*/
|
2019-04-06 00:30:53 +00:00
|
|
|
int sntp_set_servers(const char *server_url[], int num_servers);
|
2016-03-09 16:18:51 +00:00
|
|
|
|
2016-03-13 17:29:30 +00:00
|
|
|
/*
|
|
|
|
* Sets the update delay in ms. If requested value is less than 15s,
|
|
|
|
* a 15s update interval will be set.
|
|
|
|
*/
|
2016-03-09 16:18:51 +00:00
|
|
|
void sntp_set_update_delay(uint32_t ms);
|
|
|
|
|
2016-03-13 17:29:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Update RTC timer. This function is called by the SNTP module each time
|
|
|
|
* an SNTP update is received.
|
|
|
|
*/
|
|
|
|
void sntp_update_rtc(time_t t, uint32_t us);
|
|
|
|
|
2016-03-09 16:18:51 +00:00
|
|
|
#endif /* _SNTP_H_ */
|
|
|
|
|