pt1588-SH7216 1
IEEE1588v2 Implementation for Renesas SH7216 Demo

C:/Users/mzimmer/IEEE1588/pt1588/branches/pt1588-SH7216/pt1588/ptp-protocol.h File Reference

Main operation of IEEE 1588 Precision Time Protocol (PTP). More...

#include <stdio.h>
#include <stdarg.h>
#include "ptp-constants.h"
#include "platform/ptp-config.h"
#include "platform/ptp-platform-data-types.h"
#include "ptp-data-types.h"
#include "platform/ptp-msg.h"
#include "platform/ptp-clock.h"

Go to the source code of this file.

Functions

void PTPActor (const Event *eventIn)
 The PTPActor() function is responsible for implementing the IEEE 1588 PTP.
void PTPInitialize ()
 Initialize the data sets in the PTPState ptp as specified in 8.2.
void computeMeanPathDelay ()
 Compute CurrentDS.meanPathDelay.
void computeOffsetFromMaster ()
 Compute CurrentDS.offsetFromMaster.
void adjustClock ()
 Adjust slave clock frequency to synchronize to master clock.
void generateAnnounceReceiptTimeout ()
 Create an event to fire PTPActor() at a time 'announce interval' in the future.
void generateQualificationTimeout (UInteger8 N)
 Create an event to fire PTPActor() at a time 'N * announce interval' in the future.
void eventMsgIn (const Event *eventIn)
 Handle an incoming PTP message.
void eventPowerup ()
 Handle an EVENT_POWERUP event (9.2.5, 9.2.6.2).
void eventInitialize ()
 Handle an EVENT_INITIALIZE event (9.2.5, 9.2.6.3).
void eventDesignatedEnabled ()
 Handle an EVENT_DESIGNATED_ENABLED event (9.2.5, 9.2.6.4).
void eventDesignatedDisabled ()
 Handle an EVENT_DESIGNATED_DISABLED event (9.2.5, 9.2.6.5).
void eventFaultCleared ()
 Handle an EVENT_FAULT_CLEARED event (9.2.5, 9.2.6.6).
void eventFaultDetected ()
 Handle an EVENT_FAULT_DETECTED event (9.2.5, 9.2.6.7).
void eventStateDecisionEvent ()
 Handle an EVENT_STATE_DECISION_EVENT event (9.2.5, 9.2.6.8).
void eventQualificationTimeoutExpires ()
 Handle an EVENT_QUALIFICATION_TIMEOUT_EXPIRES event (9.2.5, 9.2.6.10).
void eventAnnounceReceiptTimeoutExpires (const Event *eventIn)
 Handle an EVENT_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES event (9.2.5, 9.2.6.11).
void eventSynchronizationFault ()
 Handle an EVENT_SYNCHRONIZATION_FAULT event (9.2.5, 9.2.6.12).
void eventMasterClockSelected ()
 Handle an EVENT_MASTER_CLOCK_SELECTED event (9.2.5, 9.2.6.13).
void eventPeriodicAnnounce ()
 Handle an EVENT_PERIODIC_ANNOUNCE event.
void eventPeriodicSync ()
 Handle an EVENT_PERIODIC_SYNC event.
void eventDelayReq ()
 Handle an EVENT_DELAY_REQ event.
void eventFollowUp ()
 Handle an EVENT_FOLLOW_UP event.
void stateInitializing ()
 Perform actions required when entering the INITIALIZING state.
void stateFaulty ()
 Perform actions required when entering the FAULTY state.
void stateDisabled ()
 Perform actions required when entering the DISABLED state.
void stateListening ()
 Perform actions required when entering the LISTENING state.
void statePreMaster ()
 Perform actions required when entering the PRE_MASTER state.
void stateMaster ()
 Perform actions required when entering the MASTER state.
void statePassive ()
 Perform actions required when entering the PASSIVE state.
void stateUncalibrated ()
 Perform actions required when entering the UNCALIBRATED state.
void stateSlave ()
 Perform actions required when entering the SLAVE state.
void announceMsgIn (UInteger8 *msg)
 React to a received Announce message (9.5.3).
void syncMsgIn (UInteger8 *msg)
 React to a received Sync message (9.5.4).
void followUpMsgIn (UInteger8 *msg)
 React to a received Follow_Up message (9.5.5).
void delayReqMsgIn (UInteger8 *msg)
 React to a received Delay_Req message (9.5.6).
void delayRespMsgIn (UInteger8 *msg)
 React to a received Delay_Resp message (9.5.7).
void managementMsgIn (UInteger8 *msg)
 React to a recieved Management message (15).
void toDataSetFromMsg (ClockDataSet *ds, AnnounceMsg *msg)
 Convert message information to common data structure for comparison (9.3.4).
void toDataSetFromLocal (ClockDataSet *ds)
 Convert local clock information to common data structure for comparison (9.3.4).
UInteger8 compareDataSet (const ClockDataSet *a, const ClockDataSet *b)
 Compare two data sets to find which is "better".
void updateDataSet (UInteger8 code, const AnnounceMsg *msg)
 Update the data sets according to state decision code (9.3.5).
Boolean comparePortIdentity (const PortIdentity *a, const PortIdentity *b)
 Check if two ports are equal.
Boolean isQualified (const ForeignMasterDS *d)
 Check qualification of Announce message (9.3.2.5).
void fixTimestamps (const TimeInterval *timeInterval)
 Fix timestamps when clock is stepped.
void printStatus ()
 Print status to LCD screen.

Detailed Description

Main operation of IEEE 1588 Precision Time Protocol (PTP).

Author:
Michael Zimmer (mzimmer@eecs.berkeley.edu)
Version:
Id:
ptp-protocol.h 51 2011-04-12 01:19:19Z mzimmer

Definition in file ptp-protocol.h.


Function Documentation

void adjustClock ( )

Adjust slave clock frequency to synchronize to master clock.

Adjust slave clock frequency to synchronize to master clock.

If the offset from master is outside the cutoff, the clock is stepped since it would take too long to syncrhonize with frequency adjustment. If it is within the cutoff, a rateAdjFreq is calcuated to attempt to make the frequency of the slave clock equal to that of the master. Even if the frequencies are equal, an offset may still exist (even though it wouldn't change if the frequencies are equal). To account for this, a temporary rateAdjOffset is also calculated to attempt to reduce the offset by the next time adjustClock() is called. There is a PI controller for adjusting rateAdjFreq and a PI controller for adjusting rateAdjOffset. This code can be modified to change the servo algorithm.

Definition at line 268 of file ptp-protocol.c.

void announceMsgIn ( UInteger8 msg)

React to a received Announce message (9.5.3).

Parameters:
[in]msgThe Announce message.

Definition at line 1016 of file ptp-protocol.c.

UInteger8 compareDataSet ( const ClockDataSet a,
const ClockDataSet b 
)

Compare two data sets to find which is "better".

Parameters:
[in]aA ClockDataSet.
[in]bA ClockDataSet.
Returns:
The enumeration for which data set is better.

Definition at line 1351 of file ptp-protocol.c.

Boolean comparePortIdentity ( const PortIdentity a,
const PortIdentity b 
)

Check if two ports are equal.

Parameters:
[in]aa A PortIdentity.
[in]bb A PortIdentity.
Returns:
TRUE or FALSE depending on if PortIdentity equal or not.

Definition at line 1505 of file ptp-protocol.c.

void computeMeanPathDelay ( )

Compute CurrentDS.meanPathDelay.

Called when a Sync message (or Follow_Up message in 2 step mode) is received.

Compute CurrentDS.meanPathDelay.

Since clock adjustment is performed after a Sync message and clock adjustment affects the mean path delay calculation (by affecting the timestamps of messages), take those changes into account. This code can be modified to add filtering to deal with the variability of mean path delay.

Definition at line 203 of file ptp-protocol.c.

void computeOffsetFromMaster ( )

Compute CurrentDS.offsetFromMaster.

Called when a Delay_Resp message is received.

Definition at line 233 of file ptp-protocol.c.

void delayReqMsgIn ( UInteger8 msg)

React to a received Delay_Req message (9.5.6).

Parameters:
[in]msgThe Delay_Req message.

Definition at line 1227 of file ptp-protocol.c.

void delayRespMsgIn ( UInteger8 msg)

React to a received Delay_Resp message (9.5.7).

Parameters:
[in]msgThe Delay_Resp message.

Definition at line 1255 of file ptp-protocol.c.

void eventAnnounceReceiptTimeoutExpires ( const Event eventIn)

Handle an EVENT_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES event (9.2.5, 9.2.6.11).

The EVENT_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES timout event is used to change the clock state to MASTER if the device hasn't received any Announce messages from other clocks for a set duration of time.

Parameters:
[in]eventInThe input event.

Definition at line 745 of file ptp-protocol.c.

void eventDelayReq ( )

Handle an EVENT_DELAY_REQ event.

Called when a Delay_Req message is received.

Definition at line 887 of file ptp-protocol.c.

void eventDesignatedDisabled ( )

Handle an EVENT_DESIGNATED_DISABLED event (9.2.5, 9.2.6.5).

Called when a DISABLE_PORT Management message is received.

Definition at line 484 of file ptp-protocol.c.

void eventDesignatedEnabled ( )

Handle an EVENT_DESIGNATED_ENABLED event (9.2.5, 9.2.6.4).

Called when an ENABLE_PORT Management message is received.

Definition at line 474 of file ptp-protocol.c.

void eventFaultCleared ( )

Handle an EVENT_FAULT_CLEARED event (9.2.5, 9.2.6.6).

Called when fault and/or fualt conditions are cleared.

Definition at line 502 of file ptp-protocol.c.

void eventFaultDetected ( )

Handle an EVENT_FAULT_DETECTED event (9.2.5, 9.2.6.7).

Called when a fault is detected.

Definition at line 513 of file ptp-protocol.c.

void eventFollowUp ( )

Handle an EVENT_FOLLOW_UP event.

Called when a Follow_Up message needs to be sent (in two step mode).

Definition at line 895 of file ptp-protocol.c.

void eventInitialize ( )

Handle an EVENT_INITIALIZE event (9.2.5, 9.2.6.3).

Called when an INITIALIZE Management message is received.

Definition at line 465 of file ptp-protocol.c.

void eventMasterClockSelected ( )

Handle an EVENT_MASTER_CLOCK_SELECTED event (9.2.5, 9.2.6.13).

Called when UNCALIBRATED state has successfully finished.

Definition at line 800 of file ptp-protocol.c.

void eventMsgIn ( const Event eventIn)

Handle an incoming PTP message.

Parameters:
[in]eventInThe incoming event with a pointer to the message.

Definition at line 426 of file ptp-protocol.c.

void eventPeriodicAnnounce ( )

Handle an EVENT_PERIODIC_ANNOUNCE event.

Called periodically with period of 'announce interval'.

Handle an EVENT_PERIODIC_ANNOUNCE event.

If master, will also send announce message.

Definition at line 815 of file ptp-protocol.c.

void eventPeriodicSync ( )

Handle an EVENT_PERIODIC_SYNC event.

Called periodically when clock is MASTER with period of 'sync interval'.

Handle an EVENT_PERIODIC_SYNC event.

If master, also send a sync message (and follow_up in 2 step mode).

Definition at line 843 of file ptp-protocol.c.

void eventPowerup ( )

Handle an EVENT_POWERUP event (9.2.5, 9.2.6.2).

Called when a device is powered on or reset.

Definition at line 456 of file ptp-protocol.c.

void eventQualificationTimeoutExpires ( )

Handle an EVENT_QUALIFICATION_TIMEOUT_EXPIRES event (9.2.5, 9.2.6.10).

The EVENT_QUALIFICATION_TIMEOUT_EXPIRES timeout event keeps the protocol in the PRE_MASTER state for a set duration of time.

Definition at line 730 of file ptp-protocol.c.

void eventStateDecisionEvent ( )

Handle an EVENT_STATE_DECISION_EVENT event (9.2.5, 9.2.6.8).

Called at least once per 'announce interval' to trigger the BMC algorithm (9.3).

Handle an EVENT_STATE_DECISION_EVENT event (9.2.5, 9.2.6.8).

Depending on the result of the BMC algorithm, perform state transition as specified in 9.2.5.

Definition at line 534 of file ptp-protocol.c.

void eventSynchronizationFault ( )

Handle an EVENT_SYNCHRONIZATION_FAULT event (9.2.5, 9.2.6.12).

Called when events in the UNCALIBRATED state should be repeated.

Definition at line 787 of file ptp-protocol.c.

void fixTimestamps ( const TimeInterval timeInterval)

Fix timestamps when clock is stepped.

Definition at line 1550 of file ptp-protocol.c.

void followUpMsgIn ( UInteger8 msg)

React to a received Follow_Up message (9.5.5).

Parameters:
[in]msgThe Follow_Up message.

Definition at line 1180 of file ptp-protocol.c.

void generateAnnounceReceiptTimeout ( )

Create an event to fire PTPActor() at a time 'announce interval' in the future.

To cancel this event, 'ptp.announceReceiptTimeoutExpiresID' must be incremented.

Create an event to fire PTPActor() at a time 'announce interval' in the future.

Call addFutureEvent() with this event to have this event fire PTPActor() when current time reaches that of the timestamp.

Definition at line 373 of file ptp-protocol.c.

void generateQualificationTimeout ( UInteger8  N)

Create an event to fire PTPActor() at a time 'N * announce interval' in the future.

Create an event to fire PTPActor() at a time 'N * announce interval' in the future.

Call addFutureEvent() with this event to have this event fire PTPActor() when current time reaches that of the timestamp.

Definition at line 407 of file ptp-protocol.c.

Boolean isQualified ( const ForeignMasterDS d)

Check qualification of Announce message (9.3.2.5).

Parameters:
dA ForeignMasterDS.
Returns:
TRUE or FALSE if the Announce message in d is qualified.

Definition at line 1516 of file ptp-protocol.c.

void managementMsgIn ( UInteger8 msg)

React to a recieved Management message (15).

Parameters:
[in]msgThe Management message.

Definition at line 1299 of file ptp-protocol.c.

void printStatus ( )

Print status to LCD screen.

Definition at line 1570 of file ptp-protocol.c.

void PTPActor ( const Event eventIn)

The PTPActor() function is responsible for implementing the IEEE 1588 PTP.

Correct operation of the protocol is dependent on the PTPActor() being provided with input events when required. Possible input events:

  • Event provided by powerup of the device: eventType = EVENT_POWERUP
  • Event provided by the network protocol stack when a new PTP general or event message is received: eventType = EVENT_MSG_IN eventDataPointer = <pointer to message>
  • Event provided by PTPActor for future firing of itself: eventType = EVENT_QUALIFICATION_TIMEOUT_EXPIRES | EVENT_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES | EVENT_PERIODIC_ANNOUNCE | EVENT_PERIODIC_SYNC | EVENT_DELAY_REQ | EVENT_FOLLOW_UP eventTimestamp = <time for event to fire PTPActor>
    Parameters:
    [in]eventInThe input event.

Definition at line 40 of file ptp-protocol.c.

void PTPInitialize ( )

Initialize the data sets in the PTPState ptp as specified in 8.2.

Definition at line 104 of file ptp-protocol.c.

void stateDisabled ( )

Perform actions required when entering the DISABLED state.

Definition at line 936 of file ptp-protocol.c.

void stateFaulty ( )

Perform actions required when entering the FAULTY state.

Definition at line 926 of file ptp-protocol.c.

void stateInitializing ( )

Perform actions required when entering the INITIALIZING state.

Definition at line 908 of file ptp-protocol.c.

void stateListening ( )

Perform actions required when entering the LISTENING state.

Definition at line 946 of file ptp-protocol.c.

void stateMaster ( )

Perform actions required when entering the MASTER state.

Definition at line 971 of file ptp-protocol.c.

void statePassive ( )

Perform actions required when entering the PASSIVE state.

Definition at line 984 of file ptp-protocol.c.

void statePreMaster ( )

Perform actions required when entering the PRE_MASTER state.

Definition at line 956 of file ptp-protocol.c.

void stateSlave ( )

Perform actions required when entering the SLAVE state.

Definition at line 1006 of file ptp-protocol.c.

void stateUncalibrated ( )

Perform actions required when entering the UNCALIBRATED state.

Definition at line 994 of file ptp-protocol.c.

void syncMsgIn ( UInteger8 msg)

React to a received Sync message (9.5.4).

Parameters:
[in]msgThe Sync message.

Definition at line 1112 of file ptp-protocol.c.

void toDataSetFromLocal ( ClockDataSet ds)

Convert local clock information to common data structure for comparison (9.3.4).

Parameters:
[in,out]dsThe ClockDataSet used in comparison.

Definition at line 1331 of file ptp-protocol.c.

void toDataSetFromMsg ( ClockDataSet ds,
AnnounceMsg msg 
)

Convert message information to common data structure for comparison (9.3.4).

Parameters:
[in,out]dsThe ClockDataSet used in comparison.
[in]msgThe Announce message where the clock information is located.

Definition at line 1312 of file ptp-protocol.c.

void updateDataSet ( UInteger8  code,
const AnnounceMsg msg 
)

Update the data sets according to state decision code (9.3.5).

Parameters:
[in]codeThe state decision.
[in]msgThe Announce message containing clock information used to update the ptp data sets.

Definition at line 1426 of file ptp-protocol.c.

 All Data Structures Files Functions Variables Typedefs Enumerator Defines