]> git.sur5r.net Git - freertos/blob - FreeRTOS-Labs/Demo/Common/Demo_IP_Protocols/include/NTPClient.h
Add the Labs projects provided in the V10.2.1_191129 zip file.
[freertos] / FreeRTOS-Labs / Demo / Common / Demo_IP_Protocols / include / NTPClient.h
1 //\r
2 //      ntpClient.h\r
3 //\r
4 \r
5 #ifndef __NTPCLIENT_H__\r
6 \r
7 #define __NTPCLIENT_H__\r
8 \r
9 #define NTP_PORT        123\r
10 \r
11 typedef uint32_t quint32;\r
12 typedef int32_t qint32;\r
13 typedef uint8_t quint8;\r
14 typedef int8_t qint8;\r
15 \r
16 typedef union _SNtpFlags  SNtpFlags;\r
17 \r
18 /**\r
19  * 64-bit NTP timestamp.\r
20  */\r
21 struct __attribute__ ((__packed__)) _SNtpTimestamp {\r
22   /** Number of seconds passed since Jan 1 1900, in big-endian format. */\r
23   quint32 seconds;\r
24 \r
25   /** Fractional time part, in <tt>1/0xFFFFFFFF</tt>s of a second. */\r
26   quint32 fraction;\r
27 };\r
28 \r
29 typedef struct _SNtpTimestamp SNtpTimestamp;\r
30 /**\r
31  * Mandatory part of an NTP packet\r
32  */\r
33 struct SNtpPacket {\r
34   /** Flags. */\r
35   unsigned char flags;  // value 0xDB : mode 3 (client), version 3, leap indicator unknown 3\r
36 \r
37   /** Stratum of the clock. */\r
38   quint8 stratum;  // value 0 : unspecified\r
39 \r
40   /** Maximum interval between successive messages, in log2 seconds. Note that the value is signed. */\r
41   qint8 poll;  // 10 means 1 << 10 = 1024 seconds\r
42 \r
43   /** Precision of the clock, in log2 seconds. Note that the value is signed. */\r
44   qint8 precision; // 0xFA = 250 = 0.015625 seconds\r
45 \r
46   /** Round trip time to the primary reference source, in NTP short format. */\r
47   qint32 rootDelay; // 0x5D2E = 23854 or (23854/65535)= 0.3640 sec\r
48 \r
49   /** Nominal error relative to the primary reference source. */\r
50   qint32 rootDispersion; // 0x0008 CAC8 = 8.7912  seconds\r
51 \r
52   /** Reference identifier (either a 4 character string or an IP address). */\r
53   qint8 referenceID[4]; // or just 0000\r
54 \r
55   /** The time at which the clock was last set or corrected. */\r
56   SNtpTimestamp referenceTimestamp; // Current time\r
57 \r
58   /** The time at which the request departed the client for the server. */\r
59   SNtpTimestamp originateTimestamp; // Keep 0\r
60 \r
61   /** The time at which the request arrived at the server. */\r
62   SNtpTimestamp receiveTimestamp; // Keep 0\r
63 \r
64   /** The time at which the reply departed the server for client. */\r
65   SNtpTimestamp transmitTimestamp;\r
66 };\r
67 \r
68 /* Add this number to get secs since 1-1-1900 */\r
69 #define TIME1970 2208988800UL\r
70 \r
71 #endif // __NTPCLIENT_H__\r