mirror of
https://github.com/espressif/esp-idf.git
synced 2024-09-20 00:36:01 -04:00
lwip: Fix sntp custom options if sntp_get_system_time used
This commit is contained in:
parent
c0032dc9a6
commit
457d837b40
@ -117,3 +117,18 @@ bool sntp_restart(void)
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sntp_set_system_time(uint32_t sec, uint32_t us)
|
||||||
|
{
|
||||||
|
struct timeval tv = { .tv_sec = sec, .tv_usec = us };
|
||||||
|
sntp_sync_time(&tv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sntp_get_system_time(uint32_t *sec, uint32_t *us)
|
||||||
|
{
|
||||||
|
struct timeval tv = { .tv_sec = 0, .tv_usec = 0 };
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
*(sec) = tv.tv_sec;
|
||||||
|
*(us) = tv.tv_usec;
|
||||||
|
sntp_set_sync_status(SNTP_SYNC_STATUS_RESET);
|
||||||
|
}
|
||||||
|
@ -33,9 +33,7 @@
|
|||||||
#define __LWIPOPTS_H__
|
#define __LWIPOPTS_H__
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/fcntl.h>
|
#include <sys/fcntl.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -44,6 +42,7 @@
|
|||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "netif/dhcp_state.h"
|
#include "netif/dhcp_state.h"
|
||||||
|
#include "sntp/sntp_get_set_time.h"
|
||||||
|
|
||||||
/* Enable all Espressif-only options */
|
/* Enable all Espressif-only options */
|
||||||
|
|
||||||
@ -1058,22 +1057,6 @@
|
|||||||
* SNTP update delay - in milliseconds
|
* SNTP update delay - in milliseconds
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* Forward declarations of weak definitions from lwip's sntp.c which could
|
|
||||||
* be redefined by user application. This is needed to provide custom definition
|
|
||||||
* of the below macros in lwip's sntp.c.
|
|
||||||
* Full declaration is provided in IDF's port layer in esp_sntp.h
|
|
||||||
*/
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#define LWIP_FORWARD_DECLARE_C_CXX extern "C"
|
|
||||||
#else
|
|
||||||
#define LWIP_FORWARD_DECLARE_C_CXX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LWIP_FORWARD_DECLARE_C_CXX void sntp_sync_time(struct timeval *tv);
|
|
||||||
|
|
||||||
LWIP_FORWARD_DECLARE_C_CXX uint32_t sntp_get_sync_interval(void);
|
|
||||||
|
|
||||||
/** Set this to 1 to support DNS names (or IP address strings) to set sntp servers
|
/** Set this to 1 to support DNS names (or IP address strings) to set sntp servers
|
||||||
* One server address/name can be defined as default if SNTP_SERVER_DNS == 1:
|
* One server address/name can be defined as default if SNTP_SERVER_DNS == 1:
|
||||||
* \#define SNTP_SERVER_ADDRESS "pool.ntp.org"
|
* \#define SNTP_SERVER_ADDRESS "pool.ntp.org"
|
||||||
@ -1083,22 +1066,9 @@ LWIP_FORWARD_DECLARE_C_CXX uint32_t sntp_get_sync_interval(void);
|
|||||||
// It disables a check of SNTP_UPDATE_DELAY it is done in sntp_set_sync_interval
|
// It disables a check of SNTP_UPDATE_DELAY it is done in sntp_set_sync_interval
|
||||||
#define SNTP_SUPPRESS_DELAY_CHECK
|
#define SNTP_SUPPRESS_DELAY_CHECK
|
||||||
|
|
||||||
#define SNTP_UPDATE_DELAY (sntp_get_sync_interval())
|
#define SNTP_UPDATE_DELAY (sntp_get_sync_interval())
|
||||||
|
#define SNTP_SET_SYSTEM_TIME_US(sec, us) (sntp_set_system_time(sec, us))
|
||||||
#define SNTP_SET_SYSTEM_TIME_US(sec, us) \
|
#define SNTP_GET_SYSTEM_TIME(sec, us) (sntp_get_system_time(&(sec), &(us)))
|
||||||
do { \
|
|
||||||
struct timeval tv = { .tv_sec = sec, .tv_usec = us }; \
|
|
||||||
sntp_sync_time(&tv); \
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
#define SNTP_GET_SYSTEM_TIME(sec, us) \
|
|
||||||
do { \
|
|
||||||
struct timeval tv = { .tv_sec = 0, .tv_usec = 0 }; \
|
|
||||||
gettimeofday(&tv, NULL); \
|
|
||||||
(sec) = tv.tv_sec; \
|
|
||||||
(us) = tv.tv_usec; \
|
|
||||||
sntp_set_sync_status(SNTP_SYNC_STATUS_RESET); \
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
#define SOC_SEND_LOG //printf
|
#define SOC_SEND_LOG //printf
|
||||||
|
|
||||||
|
55
components/lwip/port/esp32/include/sntp/sntp_get_set_time.h
Normal file
55
components/lwip/port/esp32/include/sntp/sntp_get_set_time.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef __SNTP_GET_SET_TIME_H__
|
||||||
|
#define __SNTP_GET_SET_TIME_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Declarations of functions used in lwipopts.h to redefine
|
||||||
|
* default sntp macros, such as:
|
||||||
|
* - SNTP_UPDATE_DELAY()
|
||||||
|
* - SNTP_SET_SYSTEM_TIME_US()
|
||||||
|
* - SNTP_GET_SYSTEM_TIME()
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @brief Get the sync interval of SNTP operation
|
||||||
|
* Full definition is provided in IDF's layer in esp_sntp.c
|
||||||
|
*/
|
||||||
|
uint32_t sntp_get_sync_interval(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief system time setter used in the sntp module
|
||||||
|
* @note The lwip sntp uses u32_t types for sec and us arguments
|
||||||
|
*/
|
||||||
|
void sntp_set_system_time(uint32_t sec, uint32_t us);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief system time getter used in the sntp module
|
||||||
|
* @note The lwip sntp uses u32_t types for sec and us arguments
|
||||||
|
*/
|
||||||
|
void sntp_get_system_time(uint32_t* sec, uint32_t* us);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif //__SNTP_GET_SET_TIME_H__
|
Loading…
Reference in New Issue
Block a user