aboutsummaryrefslogtreecommitdiff
path: root/j1demo/firmware/ntp.fs
diff options
context:
space:
mode:
authorDimitri Sokolyuk <ds@doozer.de>2017-05-23 17:06:09 +0200
committerDimitri Sokolyuk <ds@doozer.de>2017-05-23 17:06:09 +0200
commit6f86ce7057dd7cd1b491e8f09501258822d2ea74 (patch)
treeb3bfa11f0f72d0e1ca7c84d948af20b7494dd26b /j1demo/firmware/ntp.fs
Import j1demo
Diffstat (limited to 'j1demo/firmware/ntp.fs')
-rw-r--r--j1demo/firmware/ntp.fs36
1 files changed, 36 insertions, 0 deletions
diff --git a/j1demo/firmware/ntp.fs b/j1demo/firmware/ntp.fs
new file mode 100644
index 0000000..881296a
--- /dev/null
+++ b/j1demo/firmware/ntp.fs
@@ -0,0 +1,36 @@
+( NTP JCB 09:54 11/17/10)
+
+: ntp-server
+ \ h# 02830a00.
+ \ ip# 91.189.94.4 \ time.ubuntu
+ ip# 17.151.16.20 \ time.apple.com
+;
+
+: ntp-request
+ d# 123 d# 9999
+ ntp-server
+ net-my-ip
+ 2over arp-lookup
+ ( dst-port src-port dst-ip src-ip *ethaddr )
+ udp-header
+ h# 2304 mac-pkt-, h# 04ec mac-pkt-,
+ d# 6 mac-pkt-,0
+
+ d# 4 mac-pkt-,0 \ originate
+ d# 4 mac-pkt-,0 \ reference
+ d# 4 mac-pkt-,0 \ receive
+ \ d# 4 mac-pkt-,0 \ transmit
+ time@ mac-pkt-d, d# 2 mac-pkt-,0
+ udp-wrapup mac-send
+;
+
+: ntp-handler
+ IP_PROTO_UDP ip-isproto
+ ETH.IP.UDP.SOURCEPORT packet@ d# 123 = and
+ ETH.IP.UDP.DESTPORT packet@ d# 9999 = and
+ if
+ ETH.IP.UDP.NTP.TRANSMIT packetd@ setdate
+ time@ ETH.IP.UDP.NTP.ORIGINATE packetd@ d- setdelay
+ then
+;
+