README.rst
1.. zephyr:code-sample:: gptp
2 :name: gPTP
3 :relevant-api: gptp ptp_time
4
5 Enable gPTP support and monitor functionality using net-shell.
6
7Overview
8********
9
10The gPTP sample application for Zephyr will enable gPTP support, registers
11gPTP phase discontinuity callback, enable traffic class support (TX multi
12queues) and setup VLANs (if enabled). The net-shell is also enabled so that
13user can monitor gPTP functionality.
14
15The source code for this sample application can be found at:
16:zephyr_file:`samples/net/gptp`.
17
18Requirements
19************
20
21For generic host connectivity, that can be used for debugging purposes, see
22:ref:`networking_with_native_sim` for details.
23
24Building and Running
25********************
26
27A good way to run this sample is to run this gPTP application inside
28native_sim board as described in :ref:`networking_with_native_sim` or with
29embedded device like NXP FRDM-K64F, Nucleo-H743-ZI, Nucleo-H745ZI-Q,
30Nucleo-F767ZI or Atmel SAM-E70 Xplained. Note that gPTP is only supported for
31boards that have an Ethernet port and which has support for collecting
32timestamps for sent and received Ethernet frames.
33
34Follow these steps to build the gPTP sample application:
35
36.. zephyr-app-commands::
37 :zephyr-app: samples/net/gptp
38 :board: <board to use>
39 :goals: build
40 :compact:
41
42The net-shell command "**net gptp**" will print out general gPTP information.
43For port 1, the command "**net gptp 1**" will print detailed information about
44port 1 statistics etc. Note that executing the shell command could affect
45the timing of the sent or received gPTP packets and the grandmaster might
46mark the device as non AS capable and disable it.
47
48Setting up Linux Host
49=====================
50
51If you need VLAN support in your network, then the
52:zephyr_file:`samples/net/vlan/vlan-setup-linux.sh` provides a script that can be
53executed on the Linux host. It creates two VLANs on the Linux host and creates
54routes to Zephyr. If you are using native_sim board, then
55the ``net-setup.sh`` will create VLAN setup automatically with this command:
56
57.. code-block:: console
58
59 ./net-setup.sh -c zeth-vlan.conf
60
61The OpenAVNU repository at https://github.com/AVnu contains gPTP
62daemon that can be run in Linux host and which can act as a grandmaster for
63the IEEE 801.1AS network. Note that OpenAVNU will not work with
64native_sim board as that board only supports software timestamping and
65OpenAVNU only supports hardware timestamping. See instructions at the end
66of this chapter how to run linuxptp daemon with native_sim board.
67
68Get OpenAvnu/gPTP project sources
69
70.. code-block:: console
71
72 git clone git@github.com:AVnu/gptp.git
73
74After downloading the source code, compile it like this in Linux:
75
76.. code-block:: console
77
78 mkdir build
79 cd build
80 cmake ..
81 make
82 cp ../gptp_cfg.ini .
83
84Edit the :file:`gptp_cfg.ini` file and set the neighborPropDelayThresh to 10000
85as the default value 800 is too low if you run the gPTP in FRDM-K64F.
86
87Then execute the daemon with correct network interface and the configuration
88file.
89
90.. code-block:: console
91
92 sudo ./gptp enp0s25 -F gptp_cfg.ini
93
94Note that here the example network interface **enp0s25** is the name of the
95network interface that is connected to your Zephyr device.
96
97If everything is configured correctly, you should see following kind of
98messages from gptp:
99
100.. code-block:: console
101
102 INFO : GPTP [13:01:14:837] gPTP starting
103 INFO : GPTP [13:01:14:838] priority1 = 248
104 INFO : GPTP [13:01:14:838] announceReceiptTimeout: 3
105 INFO : GPTP [13:01:14:838] syncReceiptTimeout: 3
106 INFO : GPTP [13:01:14:838] LINKSPEED_100MB - PHY delay
107 TX: 1044 | RX: 2133
108 INFO : GPTP [13:01:14:838] LINKSPEED_1G - PHY delay
109 TX: 184 | RX: 382
110 INFO : GPTP [13:01:14:838] neighborPropDelayThresh: 10000
111 INFO : GPTP [13:01:14:838] syncReceiptThreshold: 8
112 ERROR : GPTP [13:01:14:838] Using clock device: /dev/ptp0
113 STATUS : GPTP [13:01:14:838] Starting PDelay
114 STATUS : GPTP [13:01:14:838] Link Speed: 1000000 kb/sec
115 STATUS : GPTP [13:01:14:871] AsCapable: Enabled
116 STATUS : GPTP [13:01:16:497] New Grandmaster "3C:97:0E:FF:FE:23:F2:32" (previous "00:00:00:00:00:00:00:00")
117 STATUS : GPTP [13:01:16:497] Switching to Master
118
119If Zephyr syncs properly with gptp daemon, then this is printed:
120
121.. code-block:: console
122
123 STATUS : GPTP [13:01:25:965] AsCapable: Enabled
124
125By default gPTP in Zephyr will not print any gPTP debug messages to console.
126One can enable debug prints by setting
127:kconfig:option:`CONFIG_NET_GPTP_LOG_LEVEL_DBG` in the config file.
128
129For native_sim board, use ``linuxptp`` project as that supports
130software timestamping.
131
132Get linuxptp project sources
133
134.. code-block:: console
135
136 git clone git://git.code.sf.net/p/linuxptp/code
137
138Compile the ``ptp4l`` daemon and start it like this:
139
140.. code-block:: console
141
142 sudo ./ptp4l -2 -f gPTP-zephyr.cfg -i zeth -m -q -l 6 -S
143
144Use the ``default.cfg`` as a base, copy it to ``gPTP-zephyr.cfg``, and modify
145it according to your needs.
146
147
148Multiport Setup
149===============
150
151If you set :kconfig:option:`CONFIG_NET_GPTP_NUM_PORTS` larger than 1, then gPTP sample
152will create multiple TSN ports. This configuration is currently only supported
153in native_sim board.
154
155You need to enable the ports in the net-tools. If the number of ports is set
156to 2, then give following commands to create the network interfaces in host
157side:
158
159.. code-block:: console
160
161 sudo ./net-setup.sh -c zeth0-gptp.conf -i zeth0 start
162 sudo ./net-setup.sh -c zeth1-gptp.conf -i zeth1 start
163
164After that you can start ptp4l daemon for both interfaces. Please use two
165terminals when starting ptp4l daemon. Note that you must use ptp4l as OpenAVNU
166does not work with software clock available in native_sim.
167
168.. code-block:: console
169
170 cd <ptp4l directory>
171 sudo ./ptp4l -2 -f gPTP-zephyr.cfg -m -q -l 6 -S -i zeth0
172 sudo ./ptp4l -2 -f gPTP-zephyr.cfg -m -q -l 6 -S -i zeth1
173
174Compile Zephyr application.
175
176.. zephyr-app-commands::
177 :zephyr-app: samples/net/gptp
178 :board: native_sim
179 :goals: build
180 :compact:
181
182When the Zephyr image is build, you can start it like this:
183
184.. code-block:: console
185
186 build/zephyr/zephyr.exe -attach_uart
187