Implementation
|
We
can classify the functions of this module in 3 main areas:
- implementation of the behaviour of the PTP slave node;
- management of cyclic and acyclic traffic;
- timestamping operation and adjustment of the system clock.
Moreover, this module implements the servo clock algorithm, which can be modify, rewritten and so on, as explain in the following.
PTP protocol management
This module implements the basic functions of a slave node, as
specified by the PTP protocol. We briefly remember that the
functions of a PTP slave node are:
- to send at uniformly distributed time interval DELAY-REQUEST messages to the
master node;
- to manage the information contain in the SYNC and DELAY-RESPONSE messages that the slave node receives from the
master node;
- to synchronize the slave system clock to the master clock.
Generation of DELAY-REQUEST messages
In order to implement the transmission of the DELAY-REQUEST messages, a timer shall be used. This timer is implemented by a self-message.
- When the node receives a self-message (from the
handleMessage function), the handleSelfMessage
function is invoked.
- The handleSelfMessage function makes a call to the
clock module in order to get a
timestamp value, which will be associated to the transmission of
a DELAY-REQUEST message.
- The clock module return a message containing the required timestamp value.
- The timestamp returned from the clock is saved in the variable ts_s_dreq.
- A DELAY-REQUEST packet is actually generated and sent to the master node.
- Then the timer is restarted by scheduling a new self-message.
Management of master messages
A node module can receive from the master
node both SYNC messages and DELAY-RESPONSE messages.
When a message is received from the master, the
handleMasterMessage function is called. This function
controls the kind of message received from the master.
If a DELAY-RESPONSE message is received:
- the value contained in the data field of this message is saved
in the variable ts_m_dreq
- the handleDelayResponse function is called.
- In the handleDelayResponse function the delay from slave to master, dsm, and the one-way delay, dprop, are estimated.
- At this point, a possible post-processing of these measures can be done.
If a SYNC message is received:
- the value stored in the data field is saved in the variable ts_m_sync.
- A message is sent to the clock module in order to
obtain the timestamp associated to the arrive of the SYNC message.
- The clock module return a message containing the required timestamp value.
- The timestamp returned from the clock is saved in the variable ts_s_sync.
- Finally the handleSync function is called.
- In the handleSync function the delay from master to slave, dms, and the offset between master and slave, offset, are estimated.
- Then a servo_clock function is invoked. This function, that
must be rewritten by the user in order to implement a specific algorithm,
is responsible for the synchronisation mechanism between master and slave.
Cyclic and acyclic traffic management
The generation of cyclic or acyclic data from the slave node is
managed by the manager module. This
last one sends to a slave a message, called event message,
specifying destination and byte length of the
packets and how many packets the slave node must send.
When an event message is received by the slave node, the
handleEventMessage function is called.
Clock messages
These messages and the related operation of the node module when
a message of this kind is received, are described both in the
previous paragraph "PTP protocol management" and in the
clock module section.
|