mirror of
https://github.com/LuckfoxTECH/luckfox-pico.git
synced 2026-01-19 09:52:31 +01:00
project:build.sh: Added fastboot support; custom modifications to U-Boot and kernel implemented using patches.
project:cfg:BoardConfig_IPC: Added fastboot BoardConfig file and firmware post-scripts, distinguishing between the BoardConfigs for Luckfox Pico Pro and Luckfox Pico Max. project:app: Added fastboot_client and rk_smart_door for quick boot applications; updated rkipc app to adapt to the latest media library. media:samples: Added more usage examples. media:rockit: Fixed bugs; removed support for retrieving data frames from VPSS. media:isp: Updated rkaiq library and related tools to support connection to RKISP_Tuner. sysdrv:Makefile: Added support for compiling drv_ko on Luckfox Pico Ultra W using Ubuntu; added support for custom root filesystem. sysdrv:tools:board: Updated Buildroot optional mirror sources, updated some software versions, and stored device tree files and configuration files that undergo multiple modifications for U-Boot and kernel separately. sysdrv:source:mcu: Used RISC-V MCU SDK with RT-Thread system, mainly for initializing camera AE during quick boot. sysdrv:source:uboot: Added support for fastboot; added high baud rate DDR bin for serial firmware upgrades. sysdrv:source:kernel: Upgraded to version 5.10.160; increased NPU frequency for RV1106G3; added support for fastboot. Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
This commit is contained in:
78
sysdrv/source/mcu/rt-thread/third_party/netutils/ntp/README.md
vendored
Normal file
78
sysdrv/source/mcu/rt-thread/third_party/netutils/ntp/README.md
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
# NTP:网络时间协议
|
||||
|
||||
## 1、介绍
|
||||
|
||||
[NTP](https://baike.baidu.com/item/NTP) 是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机时间的协议。
|
||||
|
||||
在 RT-Thread 上实现了 NTP 客户端,连接上网络后,可以获取当前 UTC 时间,并更新至 RTC 中。
|
||||
|
||||
## 2、使用
|
||||
|
||||
首先打开 meunconfig ,配置并开启 netutils 软件包。在配置选项中,默认提供了 3 个 NTP 服务器,保证了 NTP 功能的可靠性。
|
||||
|
||||
### 2.1 获取 UTC 时间
|
||||
|
||||
[UTC 时间](https://baike.baidu.com/item/%E5%8D%8F%E8%B0%83%E4%B8%96%E7%95%8C%E6%97%B6/787659?fromtitle=UTC&fromid=5899996) 又称世界统一时间、世界标准时间、国际协调时间。北京时间为 UTC+8 时间,比 UTC 时间多 8 小时,或者理解为早 8 小时。
|
||||
|
||||
API: `time_t ntp_get_time(void)`
|
||||
|
||||
|参数 |描述|
|
||||
|:----- |:----|
|
||||
|return |`>0`: 当前 UTC 时间,`=0`:获取时间失败|
|
||||
|
||||
|
||||
示例代码:
|
||||
|
||||
```C
|
||||
#include <ntp.h>
|
||||
|
||||
void main(void)
|
||||
{
|
||||
time_t cur_time;
|
||||
|
||||
cur_time = ntp_get_time();
|
||||
|
||||
if (cur_time)
|
||||
{
|
||||
rt_kprintf("NTP Server Time: %s", ctime((const time_t*) &cur_time));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2.2 获取本地时间
|
||||
|
||||
本地时间比 UTC 时间多了时区的概念,例如:北京时间为东八区,比 UTC 时间多 8 个小时。
|
||||
|
||||
在 `menuconfig` 中可以设置当前时区,默认为 `8`
|
||||
|
||||
API: `time_t ntp_get_local_time(void)`
|
||||
|
||||
|参数 |描述|
|
||||
|:----- |:----|
|
||||
|return |`>0`: 当前本地时间,`=0`:获取时间失败|
|
||||
|
||||
该 API 使用方法与 `ntp_get_time()` 类似
|
||||
|
||||
### 2.3 同步本地时间至 RTC
|
||||
|
||||
如果开启 RTC 设备,还可以使用下面的命令及 API 同步 NTP 的本地时间至 RTC 设备。
|
||||
|
||||
Finsh/MSH 命令效果如下:
|
||||
|
||||
```
|
||||
msh />ntp_sync
|
||||
Get local time from NTP server: Sat Feb 10 15:22:33 2018
|
||||
The system time is updated. Timezone is 8.
|
||||
msh />
|
||||
```
|
||||
|
||||
API: `time_t ntp_sync_to_rtc(void)`
|
||||
|
||||
|参数 |描述|
|
||||
|:----- |:----|
|
||||
|return |`>0`: 当前本地时间,`=0`:同步时间失败|
|
||||
|
||||
## 3、注意事项
|
||||
|
||||
- 1、NTP API 方法执行时会占用较多的线程堆栈,使用时保证堆栈空间充足(≥1.5K);
|
||||
- 2、NTP API 方法 **不支持可重入** ,并发使用时,请注意加锁。
|
||||
10
sysdrv/source/mcu/rt-thread/third_party/netutils/ntp/SConscript
vendored
Normal file
10
sysdrv/source/mcu/rt-thread/third_party/netutils/ntp/SConscript
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('NetUtils', src, depend = ['RT_NETUTILS_NTP'], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
417
sysdrv/source/mcu/rt-thread/third_party/netutils/ntp/ntp.c
vendored
Normal file
417
sysdrv/source/mcu/rt-thread/third_party/netutils/ntp/ntp.c
vendored
Normal file
@@ -0,0 +1,417 @@
|
||||
/*
|
||||
*
|
||||
* (C) 2014 David Lettier.
|
||||
* (C) 2018 Armink (armink.ztl@gmail.com)
|
||||
*
|
||||
* http://www.lettier.com/
|
||||
*
|
||||
* NTP client.
|
||||
*
|
||||
* Compiled with gcc version 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC).
|
||||
*
|
||||
* Tested on Linux 3.8.11-200.fc18.x86_64 #1 SMP Wed May 1 19:44:27 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux.
|
||||
* Tested on RT-Thread 3.0.0+
|
||||
*
|
||||
* To compile: $ gcc main.c -o ntpClient.out
|
||||
*
|
||||
* Usage: $ ./ntpClient.out
|
||||
*
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#if defined(RT_USING_SAL) && defined(RT_USING_NETDEV)
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#elif defined(RT_USING_LWIP)
|
||||
#include <lwip/inet.h>
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip/netdb.h>
|
||||
extern struct hostent *gethostbyname(const char *name);
|
||||
extern int recvfrom(int s, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
|
||||
extern int sendto(int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen);
|
||||
extern int socket(int domain, int type, int protocol);
|
||||
extern int closesocket(int s);
|
||||
#endif /* RT_USING_SAL */
|
||||
|
||||
#if defined(RT_USING_NETDEV)
|
||||
#include <netdev.h>
|
||||
#elif defined(RT_USING_LWIP)
|
||||
#include <lwip/netif.h>
|
||||
#endif /* RT_USING_NETDEV */
|
||||
|
||||
#define DBG_SECTION_NAME "ntp"
|
||||
#define DBG_LEVEL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
#ifdef NETUTILS_NTP_TIMEZONE
|
||||
#define NTP_TIMEZONE NETUTILS_NTP_TIMEZONE
|
||||
#endif
|
||||
|
||||
#ifdef NETUTILS_NTP_HOSTNAME
|
||||
#define NTP_HOSTNAME1 NETUTILS_NTP_HOSTNAME
|
||||
#else
|
||||
#define NTP_HOSTNAME1 NULL
|
||||
#endif
|
||||
|
||||
#ifdef NETUTILS_NTP_HOSTNAME2
|
||||
#define NTP_HOSTNAME2 NETUTILS_NTP_HOSTNAME2
|
||||
#else
|
||||
#define NTP_HOSTNAME2 NULL
|
||||
#endif
|
||||
|
||||
#ifdef NETUTILS_NTP_HOSTNAME3
|
||||
#define NTP_HOSTNAME3 NETUTILS_NTP_HOSTNAME3
|
||||
#else
|
||||
#define NTP_HOSTNAME3 NULL
|
||||
#endif
|
||||
|
||||
#define NTP_TIMESTAMP_DELTA 2208988800ull
|
||||
|
||||
#ifndef NTP_TIMEZONE
|
||||
#define NTP_TIMEZONE 8
|
||||
#endif
|
||||
|
||||
#define LI(packet) (uint8_t) ((packet.li_vn_mode & 0xC0) >> 6) // (li & 11 000 000) >> 6
|
||||
#define VN(packet) (uint8_t) ((packet.li_vn_mode & 0x38) >> 3) // (vn & 00 111 000) >> 3
|
||||
#define MODE(packet) (uint8_t) ((packet.li_vn_mode & 0x07) >> 0) // (mode & 00 000 111) >> 0
|
||||
|
||||
// Structure that defines the 48 byte NTP packet protocol.
|
||||
typedef struct {
|
||||
|
||||
uint8_t li_vn_mode; // Eight bits. li, vn, and mode.
|
||||
// li. Two bits. Leap indicator.
|
||||
// vn. Three bits. Version number of the protocol.
|
||||
// mode. Three bits. Client will pick mode 3 for client.
|
||||
|
||||
uint8_t stratum; // Eight bits. Stratum level of the local clock.
|
||||
uint8_t poll; // Eight bits. Maximum interval between successive messages.
|
||||
uint8_t precision; // Eight bits. Precision of the local clock.
|
||||
|
||||
uint32_t rootDelay; // 32 bits. Total round trip delay time.
|
||||
uint32_t rootDispersion; // 32 bits. Max error aloud from primary clock source.
|
||||
uint32_t refId; // 32 bits. Reference clock identifier.
|
||||
|
||||
uint32_t refTm_s; // 32 bits. Reference time-stamp seconds.
|
||||
uint32_t refTm_f; // 32 bits. Reference time-stamp fraction of a second.
|
||||
|
||||
uint32_t origTm_s; // 32 bits. Originate time-stamp seconds.
|
||||
uint32_t origTm_f; // 32 bits. Originate time-stamp fraction of a second.
|
||||
|
||||
uint32_t rxTm_s; // 32 bits. Received time-stamp seconds.
|
||||
uint32_t rxTm_f; // 32 bits. Received time-stamp fraction of a second.
|
||||
|
||||
uint32_t txTm_s; // 32 bits and the most important field the client cares about. Transmit time-stamp seconds.
|
||||
uint32_t txTm_f; // 32 bits. Transmit time-stamp fraction of a second.
|
||||
|
||||
} ntp_packet; // Total: 384 bits or 48 bytes.
|
||||
|
||||
static ntp_packet packet = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
static int sendto_ntp_server(int sockfd, const char *host_name, struct sockaddr_in *serv_addr)
|
||||
{
|
||||
struct hostent *server;
|
||||
socklen_t addr_len = sizeof(struct sockaddr_in);
|
||||
/* NTP UDP port number. */
|
||||
int portno = 123;
|
||||
|
||||
server = gethostbyname(host_name);
|
||||
if (server == NULL)
|
||||
{
|
||||
LOG_D("No such host(%s)", host_name);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Zero out the server address structure. */
|
||||
memset((char *)serv_addr, 0, addr_len);
|
||||
|
||||
serv_addr->sin_family = AF_INET;
|
||||
|
||||
/* Convert the port number integer to network big-endian style and save it to the server address structure. */
|
||||
serv_addr->sin_port = htons(portno);
|
||||
|
||||
/* Copy the server's IP address to the server address structure. */
|
||||
memcpy(&serv_addr->sin_addr.s_addr, (char *) server->h_addr, server->h_length);
|
||||
|
||||
return sendto(sockfd, (char *) &packet, sizeof(ntp_packet), 0, (const struct sockaddr *)serv_addr, addr_len);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the UTC time from NTP server
|
||||
*
|
||||
* @param host_name NTP server host name, NULL: will using default host name
|
||||
*
|
||||
* @note this function is not reentrant
|
||||
*
|
||||
* @return >0: success, current UTC time
|
||||
* =0: get failed
|
||||
*/
|
||||
time_t ntp_get_time(const char *host_name)
|
||||
{
|
||||
/* the delay(ms) between two receive */
|
||||
#define RECV_TIME_DELAY_MS 10
|
||||
/* NTP receive timeout(S) */
|
||||
#define NTP_GET_TIMEOUT 5
|
||||
/* number of NTP servers */
|
||||
#define NTP_SERVER_NUM 3
|
||||
|
||||
int sockfd, n, i = 0, server_num = 0;
|
||||
struct sockaddr_in serv_addr[NTP_SERVER_NUM];
|
||||
rt_tick_t start = 0;
|
||||
time_t new_time = 0;
|
||||
socklen_t addr_len = sizeof(struct sockaddr_in);
|
||||
const char *const host_name_buf[NTP_SERVER_NUM] = {NTP_HOSTNAME1, NTP_HOSTNAME2, NTP_HOSTNAME3};
|
||||
|
||||
/* Create and zero out the packet. All 48 bytes worth. */
|
||||
memset(&packet, 0, sizeof(ntp_packet));
|
||||
|
||||
/* Set the first byte's bits to 00,011,011 for li = 0, vn = 3, and mode = 3. The rest will be left set to zero.
|
||||
Represents 27 in base 10 or 00011011 in base 2. */
|
||||
*((char *) &packet + 0) = 0x1b;
|
||||
|
||||
#if defined(RT_USING_NETDEV) || defined(RT_USING_LWIP)
|
||||
{
|
||||
#define NTP_INTERNET 0x02
|
||||
#define NTP_INTERNET_BUFF_LEN 18
|
||||
#define NTP_INTERNET_MONTH_LEN 4
|
||||
#define NTP_INTERNET_DATE_LEN 16
|
||||
#ifndef SW_VER_NUM
|
||||
#define SW_VER_NUM 0x00000000
|
||||
#endif
|
||||
|
||||
const char month[][NTP_INTERNET_MONTH_LEN] =
|
||||
{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
|
||||
char date[NTP_INTERNET_DATE_LEN] = {0};
|
||||
uint8_t send_data[NTP_INTERNET_BUFF_LEN] = {0};
|
||||
uint8_t index, moth_num = 0;
|
||||
uint16_t check = 0;
|
||||
|
||||
/* get build moth value*/
|
||||
rt_snprintf(date, NTP_INTERNET_DATE_LEN, "%s", __DATE__);
|
||||
|
||||
for (index = 0; index < sizeof(month) / NTP_INTERNET_MONTH_LEN; index++)
|
||||
{
|
||||
if (rt_memcmp(date, month[index], NTP_INTERNET_MONTH_LEN - 1) == 0)
|
||||
{
|
||||
moth_num = index + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
send_data[0] = NTP_INTERNET;
|
||||
|
||||
/* get hardware address */
|
||||
{
|
||||
#if defined(RT_USING_LWIP) && !defined(RT_USING_NETDEV)
|
||||
#define netdev netif
|
||||
#define netdev_default netif_default
|
||||
#endif
|
||||
extern struct netdev *netdev_default;
|
||||
struct netdev *dev = netdev_default;
|
||||
|
||||
for (index = 0; index < dev->hwaddr_len; index++)
|
||||
{
|
||||
send_data[index + 1] = dev->hwaddr[index] + moth_num;
|
||||
}
|
||||
}
|
||||
|
||||
send_data[9] = RT_VERSION;
|
||||
send_data[10] = RT_SUBVERSION;
|
||||
send_data[11] = RT_REVISION;
|
||||
send_data[12] = (uint8_t)(SW_VER_NUM >> 24);
|
||||
send_data[13] = (uint8_t)(SW_VER_NUM >> 16);
|
||||
send_data[14] = (uint8_t)(SW_VER_NUM >> 8);
|
||||
send_data[15] = (uint8_t)(SW_VER_NUM & 0xFF);
|
||||
|
||||
/* get the check value */
|
||||
for (index = 0; index < NTP_INTERNET_BUFF_LEN - sizeof(check); index++)
|
||||
{
|
||||
check += (uint8_t)send_data[index];
|
||||
}
|
||||
send_data[NTP_INTERNET_BUFF_LEN - 2] = check >> 8;
|
||||
send_data[NTP_INTERNET_BUFF_LEN - 1] = check & 0xFF;
|
||||
|
||||
rt_memcpy(((char *)&packet + 4), send_data, NTP_INTERNET_BUFF_LEN);
|
||||
}
|
||||
#endif /* RT_USING_NETDEV || RT_USING_LWIP */
|
||||
|
||||
|
||||
/* Create a UDP socket. */
|
||||
sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (sockfd < 0)
|
||||
{
|
||||
LOG_E("Create socket failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (host_name)
|
||||
{
|
||||
/* access the incoming host_name server */
|
||||
if (sendto_ntp_server(sockfd, host_name, serv_addr) >= 0)
|
||||
{
|
||||
server_num = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* use the static default NTP server */
|
||||
for (i = 0; i < NTP_SERVER_NUM; i++)
|
||||
{
|
||||
if (host_name_buf[i] == NULL || strlen(host_name_buf[i]) == 0)
|
||||
continue;
|
||||
|
||||
if (sendto_ntp_server(sockfd, host_name_buf[i], &serv_addr[server_num]) >= 0)
|
||||
{
|
||||
server_num ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (server_num <= 0)
|
||||
{
|
||||
closesocket(sockfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
start = rt_tick_get();
|
||||
while (rt_tick_get() <= start + NTP_GET_TIMEOUT * RT_TICK_PER_SECOND)
|
||||
{
|
||||
for (i = 0; i < server_num; i++)
|
||||
{
|
||||
/* non-blocking receive the packet back from the server. If n == -1, it failed. */
|
||||
n = recvfrom(sockfd, (char *) &packet, sizeof(ntp_packet), MSG_DONTWAIT, (struct sockaddr *)&serv_addr[i], &addr_len);
|
||||
if (n <= 0)
|
||||
{
|
||||
LOG_D("Reading from server %s error (%d).", inet_ntoa(serv_addr[i].sin_addr.s_addr), n);
|
||||
}
|
||||
else if (n > 0)
|
||||
{
|
||||
goto __exit;
|
||||
}
|
||||
}
|
||||
|
||||
rt_thread_mdelay(RECV_TIME_DELAY_MS);
|
||||
}
|
||||
|
||||
__exit:
|
||||
|
||||
if (rt_tick_get() <= start + NTP_GET_TIMEOUT * RT_TICK_PER_SECOND)
|
||||
{
|
||||
/* These two fields contain the time-stamp seconds as the packet left the NTP server.
|
||||
The number of seconds correspond to the seconds passed since 1900.
|
||||
ntohl() converts the bit/byte order from the network's to host's "endianness". */
|
||||
packet.txTm_s = ntohl(packet.txTm_s); // Time-stamp seconds.
|
||||
packet.txTm_f = ntohl(packet.txTm_f); // Time-stamp fraction of a second.
|
||||
|
||||
/* Extract the 32 bits that represent the time-stamp seconds (since NTP epoch) from when the packet left the server.
|
||||
Subtract 70 years worth of seconds from the seconds since 1900.
|
||||
This leaves the seconds since the UNIX epoch of 1970.
|
||||
(1900)------------------(1970)**************************************(Time Packet Left the Server) */
|
||||
new_time = (time_t)(packet.txTm_s - NTP_TIMESTAMP_DELTA);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("Receive the socket from server timeout (%dS).", NTP_GET_TIMEOUT);
|
||||
}
|
||||
|
||||
closesocket(sockfd);
|
||||
|
||||
return new_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the local time from NTP server
|
||||
*
|
||||
* @param host_name NTP server host name, NULL: will using default host name
|
||||
*
|
||||
* @return >0: success, current local time, offset timezone by NTP_TIMEZONE
|
||||
* =0: get failed
|
||||
*/
|
||||
time_t ntp_get_local_time(const char *host_name)
|
||||
{
|
||||
time_t cur_time = ntp_get_time(host_name);
|
||||
|
||||
if (cur_time)
|
||||
{
|
||||
/* add the timezone offset for set_time/set_date */
|
||||
cur_time += NTP_TIMEZONE * 3600;
|
||||
}
|
||||
|
||||
return cur_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync current local time to RTC by NTP
|
||||
*
|
||||
* @param host_name NTP server host name, NULL: will using default host name
|
||||
*
|
||||
* @return >0: success, current local time, offset timezone by NTP_TIMEZONE
|
||||
* =0: sync failed
|
||||
*/
|
||||
time_t ntp_sync_to_rtc(const char *host_name)
|
||||
{
|
||||
#ifdef RT_USING_RTC
|
||||
struct tm *cur_tm;
|
||||
#endif
|
||||
|
||||
time_t cur_time = ntp_get_local_time(host_name);
|
||||
|
||||
if (cur_time)
|
||||
{
|
||||
|
||||
#ifdef RT_USING_RTC
|
||||
cur_tm = localtime(&cur_time);
|
||||
set_time(cur_tm->tm_hour, cur_tm->tm_min, cur_tm->tm_sec);
|
||||
|
||||
cur_tm = localtime(&cur_time);
|
||||
set_date(cur_tm->tm_year + 1900, cur_tm->tm_mon + 1, cur_tm->tm_mday);
|
||||
#endif /* RT_USING_RTC */
|
||||
|
||||
}
|
||||
|
||||
return cur_time;
|
||||
}
|
||||
|
||||
static void ntp_sync(const char *host_name)
|
||||
{
|
||||
time_t cur_time = ntp_sync_to_rtc(host_name);
|
||||
|
||||
if (cur_time)
|
||||
{
|
||||
rt_kprintf("Get local time from NTP server: %s", ctime((const time_t *) &cur_time));
|
||||
|
||||
#ifdef RT_USING_RTC
|
||||
rt_kprintf("The system time is updated. Timezone is %d.\n", NTP_TIMEZONE);
|
||||
#else
|
||||
rt_kprintf("The system time update failed. Please enable RT_USING_RTC.\n");
|
||||
#endif /* RT_USING_RTC */
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_ntp_sync(int argc, char **argv)
|
||||
{
|
||||
char *host_name = NULL;
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
host_name = argv[1];
|
||||
}
|
||||
|
||||
ntp_sync(host_name);
|
||||
}
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
#include <finsh.h>
|
||||
FINSH_FUNCTION_EXPORT(ntp_sync, Update time by NTP(Network Time Protocol): ntp_sync(host_name));
|
||||
MSH_CMD_EXPORT_ALIAS(cmd_ntp_sync, ntp_sync, Update time by NTP(Network Time Protocol): ntp_sync [host_name]);
|
||||
#endif /* RT_USING_FINSH */
|
||||
61
sysdrv/source/mcu/rt-thread/third_party/netutils/ntp/ntp.h
vendored
Normal file
61
sysdrv/source/mcu/rt-thread/third_party/netutils/ntp/ntp.h
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* File : ntp.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-02-10 armink the first version
|
||||
*/
|
||||
#ifndef _NTP_H_
|
||||
#define _NTP_H_
|
||||
|
||||
#include <time.h>
|
||||
|
||||
/**
|
||||
* Get the UTC time from NTP server
|
||||
*
|
||||
* @param host_name NTP server host name, NULL: will using default host name
|
||||
*
|
||||
* @note this function is not reentrant
|
||||
*
|
||||
* @return >0: success, current UTC time
|
||||
* =0: get failed
|
||||
*/
|
||||
time_t ntp_get_time(const char *host_name);
|
||||
|
||||
/**
|
||||
* Get the local time from NTP server
|
||||
*
|
||||
* @param host_name NTP server host name, NULL: will using default host name
|
||||
*
|
||||
* @return >0: success, current local time, offset timezone by NTP_TIMEZONE
|
||||
* =0: get failed
|
||||
*/
|
||||
time_t ntp_get_local_time(const char *host_name);
|
||||
|
||||
/**
|
||||
* Sync current local time to RTC by NTP
|
||||
*
|
||||
* @param host_name NTP server host name, NULL: will using default host name
|
||||
*
|
||||
* @return >0: success, current local time, offset timezone by NTP_TIMEZONE
|
||||
* =0: sync failed
|
||||
*/
|
||||
time_t ntp_sync_to_rtc(const char *host_name);
|
||||
|
||||
#endif /* _NTP_H_ */
|
||||
Reference in New Issue
Block a user