annotate packages/net/sntp/current/src/sntp.c @ 925:c6d5daaf0c31

* src/sntp.c: In function sntp_fn() changed 'version' to 'new_srv.version' in the CYG_TRACE1() call.
author jlarmour
date Wed, 09 Apr 2003 20:31:45 +0000
parents 018143c925ee
children 8f7a10771d67
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
748
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
1 //=============================================================================
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
2 //
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
3 // sntp.c
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
4 //
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
5 // Simple Network Time Protocol
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
6 //
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
7 //=============================================================================
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
8 //####ECOSGPLCOPYRIGHTBEGIN####
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
9 // -------------------------------------------
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
11 // Copyright (C) 2003 Andrew Lunn
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
12 //
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
14 // the terms of the GNU General Public License as published by the Free
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later version.
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
16 //
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
20 // for more details.
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
21 //
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
22 // You should have received a copy of the GNU General Public License along
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
25 //
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
26 // As a special exception, if other files instantiate templates or use macros
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
27 // or inline functions from this file, or you compile this file and link it
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
28 // with other works to produce a work based on this file, this file does not
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
29 // by itself cause the resulting work to be covered by the GNU General Public
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
30 // License. However the source code for this file must still be made available
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
31 // in accordance with section (3) of the GNU General Public License.
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
32 //
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
33 // This exception does not invalidate any other reasons why a work based on
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
34 // this file might be covered by the GNU General Public License.
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
35 //
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
37 // at http://sources.redhat.com/ecos/ecos-license/
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
38 // -------------------------------------------
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
39 //####ECOSGPLCOPYRIGHTEND####
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
40 //=============================================================================
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
41 //#####DESCRIPTIONBEGIN####
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
42 //
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
43 // Author(s): andrew.lunn
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
44 // Contributors:
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
45 // Date: 2003-02-12
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
46 // Description: Provides a Simple Network Time Protocol Client
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
47 //####DESCRIPTIONEND####
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
48 //
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
49 //=============================================================================
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
50
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
51 #include <network.h>
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
52 #include <cyg/infra/cyg_type.h>
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
53 #include <cyg/infra/cyg_ass.h>
759
018143c925ee * tests/sntp1.c (net_test): Strip the trailing "\n" making it more
asl
parents: 748
diff changeset
54 #include <cyg/infra/cyg_trac.h>
748
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
55 #include <cyg/sntp/sntp.h>
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
56 #include <time.h>
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
57
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
58 #define VERSION_MASK 0x38000000
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
59 #define VERSION_SHIFT 27
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
60 #define MODE_MASK 0x07000000
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
61 #define MODE_SHIFT 24
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
62 #define STRATUM_MASK 0x00ff0000
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
63 #define STRATUM_SHIFT 16
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
64
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
65 #define MODE_BROADCAST 5
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
66
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
67 struct sntp_srv_s {
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
68 struct sockaddr_in addr;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
69 int stratum;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
70 int version;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
71 cyg_uint32 timestamp;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
72 };
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
73
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
74 #define SECONDSPERMINUTE (cyg_uint32)60
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
75 #define SECONDSPERHOUR (cyg_uint32)(SECONDSPERMINUTE * 60)
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
76 #define SECONDSPERDAY (cyg_uint32)(SECONDSPERHOUR * 24)
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
77 #define SECONDSPERYEAR (cyg_uint32)(SECONDSPERDAY * 365)
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
78
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
79 /* Convert a SNTP timestamp to a time_t. timestamps are seconds from
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
80 1/1/1900. time_t is 1/1/1970. That equates to 70 years, or which
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
81 17 were leap years.*/
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
82 static time_t timestamp2time(cyg_uint32 timestamp) {
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
83
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
84 return timestamp -
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
85 (SECONDSPERYEAR * (cyg_uint32)(70)) -
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
86 (SECONDSPERDAY * (cyg_uint32)(17));
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
87 }
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
88
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
89 /* Is the new server better than the current one? If its the same as
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
90 the current, its always better. If the stratum is lower its better.
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
91 If we have not heard from the old server for more than 10 minutes,
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
92 the new server is better. */
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
93
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
94 static int is_better(struct sntp_srv_s *newer, struct sntp_srv_s *old) {
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
95
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
96 time_t last_time, diff;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
97
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
98 if (newer->addr.sin_addr.s_addr == old->addr.sin_addr.s_addr) return 1;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
99 if (newer->stratum < old->stratum) return 1;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
100
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
101 if (old->timestamp != 0xffffffff) {
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
102 last_time = timestamp2time(old->timestamp);
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
103
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
104 diff = time(NULL) - last_time;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
105 if (diff > 600) return 1;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
106
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
107 return 0;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
108 }
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
109 return 1;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
110 }
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
111
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
112 static void sntp_fn(cyg_addrword_t data) {
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
113 int fd;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
114 int ret;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
115 struct sockaddr_in local;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
116 struct servent *serv;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
117 cyg_uint32 buf[12];
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
118 struct sntp_srv_s new_srv;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
119 struct sntp_srv_s best_srv;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
120 int mode;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
121 int len;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
122 time_t new_time, current_time, diff;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
123
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
124 memset(&best_srv,0xff,sizeof(best_srv));
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
125
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
126 fd = socket(AF_INET,SOCK_DGRAM,0);
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
127 CYG_ASSERT(-1 != fd,"Failed to open socket");
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
128
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
129 serv = getservbyname("ntp","udp");
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
130 CYG_ASSERT(serv,"getservbyname(sntp,udp)");
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
131
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
132 memset(&local,0,sizeof(local));
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
133 local.sin_family = AF_INET;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
134 local.sin_port = serv->s_port;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
135 local.sin_addr.s_addr = INADDR_ANY;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
136
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
137 ret=bind(fd,(struct sockaddr *)&local,sizeof(local));
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
138 CYG_ASSERT(0 == ret, "Bind failed");
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
139
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
140 while (1) {
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
141 len = sizeof(new_srv.addr);
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
142 ret=recvfrom(fd,buf,sizeof(buf),0,(struct sockaddr *)&new_srv.addr,&len);
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
143 CYG_ASSERT(0 < ret,"recvfrom");
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
144
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
145 /* We expect at least enough bytes to fill the buffer. There could
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
146 be more if there is a digest, but we ignore that. */
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
147 if (ret < sizeof(buf))
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
148 continue;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
149
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
150 new_srv.version = (htonl(buf[0]) & VERSION_MASK) >> VERSION_SHIFT;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
151 new_srv.stratum = (htonl(buf[0]) & STRATUM_MASK) >> STRATUM_SHIFT;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
152 new_srv.timestamp = htonl(buf[10]);
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
153 mode = (htonl(buf[0]) & MODE_MASK) >> MODE_SHIFT;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
154
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
155 /* Only support protocol versions 3 or 4 */
759
018143c925ee * tests/sntp1.c (net_test): Strip the trailing "\n" making it more
asl
parents: 748
diff changeset
156 if (new_srv.version < 3 || new_srv.version > 4) {
925
c6d5daaf0c31 * src/sntp.c: In function sntp_fn() changed 'version' to
jlarmour
parents: 759
diff changeset
157 CYG_TRACE1(1, "Unsupported version of NTP. Version %d",new_srv.version);
748
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
158 continue;
759
018143c925ee * tests/sntp1.c (net_test): Strip the trailing "\n" making it more
asl
parents: 748
diff changeset
159 }
748
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
160
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
161 /* Only process broadcast packet */
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
162 if (mode != MODE_BROADCAST)
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
163 continue;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
164
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
165 /* Is the packet from a better server than our current one */
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
166 if (is_better(&new_srv,&best_srv)) {
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
167 best_srv = new_srv;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
168
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
169 /* Work out the difference between server and our time */
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
170 new_time = timestamp2time(best_srv.timestamp);
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
171 current_time = time(NULL);
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
172 diff = current_time - new_time;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
173
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
174 if (diff < 0)
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
175 diff = -diff;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
176
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
177 if (diff > 2)
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
178 cyg_libc_time_settime(new_time);
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
179 }
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
180 }
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
181 }
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
182
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
183 /* Start the SNTP server */
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
184 void cyg_sntp_start(void) {
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
185
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
186 static char sntp_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
187 static cyg_thread sntp_thread_data;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
188 static cyg_handle_t sntp_handle;
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
189
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
190 cyg_thread_create(CYGPKG_NET_THREAD_PRIORITY+1,
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
191 sntp_fn, // entry
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
192 0, // entry parameter
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
193 "sntp", // Name
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
194 &sntp_stack, // stack
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
195 sizeof(sntp_stack), // stack size
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
196 &sntp_handle, // Handle
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
197 &sntp_thread_data); // Thread data structure
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
198
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
199 cyg_thread_resume(sntp_handle);
d21da3c91474 First import of the Simple Network Time Protocol client.
asl
parents:
diff changeset
200 }