SZSPTP ez430-RF2480 1.0

ZigBee Sensor Network with synchronized time and time-stamped measurements.
PTP Utilities

Utilities for use by the PTP implementation. More...

+ Collaboration diagram for PTP Utilities:

Functions

ptp_clockIdentityptp_getClockIdentity ()
 Get clock identity. More...
 
void ptp_getCurrentTime (PTP_TimeStamp *result)
 Get cuttent time. More...
 
void ptp_adjTime (PTP_TimeStamp *t1, PTP_TimeStamp *t2, ptp_uinteger8 portIndex)
 Adjust the clock. More...
 
ptp_integer64 ptp_timeDiff (PTP_TimeStamp *t1, PTP_TimeStamp *t2)
 Time difference. More...
 
ptp_integer8 ptp_clockIdentityCompare (ptp_clockIdentity A, ptp_clockIdentity B)
 Clock identity compare. More...
 
void ptp_portsSetListening ()
 Ports set listening. More...
 
void ptp_state_decision_event ()
 State decision event. More...
 
ptp_integer8 ptp_dataSetComparisonEE (ptp_uinteger8 *iBetter, ptp_boolean *byTopology, PTP_announceDS *E1, PTP_announceDS *E2, ptp_uinteger8 i1, ptp_uinteger8 i2)
 Data set comparison. More...
 
ptp_integer8 ptp_dataSetComparisonDE (ptp_boolean *Dbetter, ptp_clock *D, PTP_announceDS *E, ptp_uinteger8 i)
 Data set comparison self clock/announce message. More...
 
void ptp_storeForeignMaster (ptp_octet *pBuf, ptp_uinteger8 portNumber)
 Store foreign master. More...
 
ptp_uinteger8 ptp_startFrame (ptp_uinteger16 destination, ptp_uinteger8 len)
 Start Frame. More...
 
ptp_uinteger8 ptp_snd (ptp_uinteger8 len, void *pBuf)
 Send data. More...
 
void ptp_endFrame ()
 End frame. More...
 
ptp_uinteger8 ptp_sndUInt8 (ptp_uinteger8 v)
 Send unsigned 8 bits integer. More...
 
ptp_uinteger8 ptp_sndUInt16 (ptp_uinteger16 v)
 Send unsigned 16 bits integer. More...
 
ptp_uinteger8 ptp_sndUInt32 (ptp_uinteger32 *p)
 Send unsigned 32 bits integer. More...
 
ptp_uinteger8 ptp_sndUInt48 (ptp_uinteger48 *p)
 Send unsigned 48 bits integer. More...
 
ptp_uinteger8 ptp_sndUInt48sc (PTP_SecondsCount *p)
 Send a seconds count value. More...
 
ptp_uinteger8 ptp_sndUInt64 (ptp_uinteger64 *p)
 Send unsigned 64 bits integer. More...
 
ptp_uinteger8 ptp_sndInt64 (ptp_integer64 *p)
 Send 64 bits integer. More...
 
ptp_uinteger8 ptp_rcvUInt8 (ptp_octet *pBuf)
 Receive unsigned 8 bits integer. More...
 
ptp_uinteger16 ptp_rcvUInt16 (ptp_octet *pBuf)
 Receive unsigned 16 bits integer. More...
 
ptp_uinteger32 ptp_rcvUInt32 (ptp_octet *pBuf)
 Receive unsigned 32 bits integer. More...
 
ptp_uinteger48 ptp_rcvUInt48 (ptp_octet *pBuf)
 Receive unsigned 48 bits integer. More...
 
void ptp_rcvUInt48sc (ptp_octet *pBuf, PTP_SecondsCount *p)
 Receive seconds count value. More...
 
ptp_uinteger64 ptp_rcvUInt64 (ptp_octet *pBuf)
 Receive unsigned 64 bits integer. More...
 
ptp_integer64 ptp_rcvInt64 (ptp_octet *pBuf)
 Receive 64 bits integer. More...
 
void ptp_rcvOctets (ptp_uinteger8 len, ptp_octet *source, ptp_octet *dest)
 Receive octets. More...
 
void ptp_copyOctets (ptp_uinteger8 len, ptp_octet *source, ptp_octet *dest)
 Copy octets. More...
 

Detailed Description

Utilities for use by the PTP implementation.

Function Documentation

void ptp_adjTime ( PTP_TimeStamp t1,
PTP_TimeStamp t2,
ptp_uinteger8  portIndex 
)

Adjust the clock.

This function adjusts the current time of the device, it adds to thte received offset the .

Parameters
[in]t1- pointer to the time stamp of sender
[in,out]t2- pointer to the time stamp of receiver
[in]portIndex- port Index to read the meanPathDelay

Definition at line 118 of file ptp_util.c.

References clock_adjTime(), clock_adjTimeValues(), clock_setTime(), clock_timeDiff(), and ptp_getCurrentTime().

Referenced by ptp_MsgPdelayReqRcv(), and ptp_MsgPdelayRespRcv().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ptp_integer8 ptp_clockIdentityCompare ( ptp_clockIdentity  A,
ptp_clockIdentity  B 
)

Clock identity compare.

Compares two given clock identities.

Parameters
[in]AFirst clock identity.
[in]BSecond clock identity.
Returns
0 if equals, -1 if A > B and 1 if B > A.

Definition at line 201 of file ptp_util.c.

Referenced by ptp_bmc(), ptp_dataSetComparisonDE(), ptp_dataSetComparisonEE(), ptp_rcvmessage(), and ptp_storeForeignMaster().

+ Here is the caller graph for this function:

void ptp_copyOctets ( ptp_uinteger8  len,
ptp_octet source,
ptp_octet dest 
)

Copy octets.

This function copy octets from a buffer to another.

Parameters
[in]lenLength of the data to copy.
[in]sourceBuffer to read the value from.
[out]destBuffer to write to.
Returns
The value that was read.

Definition at line 1177 of file ptp_util.c.

Referenced by ptp_portsSetListening(), and ptp_rcvOctets().

+ Here is the caller graph for this function:

ptp_integer8 ptp_dataSetComparisonDE ( ptp_boolean Dbetter,
ptp_clock D,
PTP_announceDS E,
ptp_uinteger8  portNumber 
)

Data set comparison self clock/announce message.

This function compares the self clock to an announce message. IEC 61588-2009 / IEEE 1588-2008 9.3.4.

Parameters
[out]DBetterindicates if self clock is better.
[in]DSelf clock
[in]EAnnounce message
[in]portNumberPort number of the announce message

Definition at line 677 of file ptp_util.c.

References ptp_clockIdentityCompare(), and PTP_ZEROSEQ64.

Referenced by ptp_bmc().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ptp_integer8 ptp_dataSetComparisonEE ( ptp_uinteger8 iBetter,
ptp_boolean byTopology,
PTP_announceDS E1,
PTP_announceDS E2,
ptp_uinteger8  i1,
ptp_uinteger8  i2 
)

Data set comparison.

This function compares two announce messages. IEC 61588-2009 / IEEE 1588-2008 9.3.4. Error return (!= 0) avoided by IEC 61588-2009 / IEEE 1588-2008 9.3.2.5.

Parameters
[out]iBetterBetter announce message
[out]byTopologyindicates if result is only by topology
[in]E1first announce message
[in]E2second announce message
[in]i1Return value if E1 is better
[in]i2Return value if E2 is better

Definition at line 501 of file ptp_util.c.

References ptp_clockIdentityCompare(), and PTP_ZEROSEQ64.

Referenced by ptp_bmc().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ptp_endFrame ( )

End frame.

This function sends the written PTP frame to the specified address over the network.

Definition at line 916 of file ptp_util.c.

References nwk_endFrame().

Referenced by ptp_MsgAnnounceSnd(), ptp_MsgPdelayReqSnd(), and ptp_MsgPdelayRespSnd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ptp_clockIdentity* ptp_getClockIdentity ( )

Get clock identity.

This function returns a pointer to the Clock Identity value. It can be modified for specific applications.

Returns
Pointer to the clock identity

Definition at line 85 of file ptp_util.c.

References nwk_getPIeeeAddress().

Referenced by ptp_initEnd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ptp_getCurrentTime ( PTP_TimeStamp dest)

Get cuttent time.

This function get the current time of the device.

Parameters
[out]dest- pointer to the time stamp to set

Definition at line 104 of file ptp_util.c.

References clock_getTime().

Referenced by ptp_adjTime(), ptp_MsgAnnounceSnd(), ptp_MsgPdelayReqSnd(), ptp_MsgPdelayRespSnd(), and ptp_rcvmessage().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ptp_portsSetListening ( )

Ports set listening.

Set the ports state to PTP_PS_LISTENING and their mapped address to 0xFFFF with is invalid, to the network it would be a broadcast address. If device is configured as an end-device, only one port will be enabled, that communicates do the router, and must after be set to PTP_PS_SLAVE.

Definition at line 224 of file ptp_util.c.

References NWK_DEVTYPE_ENDDEVICE, nwk_getDeviceType(), ptp_copyOctets(), and PTP_ZEROSEQ64.

Referenced by ptp_initEnd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ptp_integer64 ptp_rcvInt64 ( ptp_octet pBuf)

Receive 64 bits integer.

This function reads a 64-bit value from a buffer.

Parameters
[in]pBufBuffer to read the value from.
Returns
The value that was read.

Definition at line 1138 of file ptp_util.c.

Referenced by ptp_MsgPdelayReqRcv(), and ptp_MsgPdelayRespRcv().

+ Here is the caller graph for this function:

void ptp_rcvOctets ( ptp_uinteger8  len,
ptp_octet pBuf,
ptp_octet dest 
)

Receive octets.

This function reads octets from a buffer.

Parameters
[in]lenLength of the data to read.
[in]pBufBuffer to read the value from.
[out]destPointer to the destination value.
Returns
The value that was read.

Definition at line 1162 of file ptp_util.c.

References ptp_copyOctets().

Referenced by ptp_MsgPdelayReqRcv(), and ptp_storeForeignMaster().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ptp_uinteger16 ptp_rcvUInt16 ( ptp_octet pBuf)

Receive unsigned 16 bits integer.

This function reads a 16-bit value from a buffer.

Parameters
[in]pBufBuffer to read the value from.
Returns
The value that was read.

Definition at line 1043 of file ptp_util.c.

Referenced by ptp_MsgPdelayReqRcv(), ptp_MsgPdelayRespRcv(), ptp_rcvmessage(), and ptp_storeForeignMaster().

+ Here is the caller graph for this function:

ptp_uinteger32 ptp_rcvUInt32 ( ptp_octet pBuf)

Receive unsigned 32 bits integer.

This function reads a 32-bit value from a buffer.

Parameters
[in]pBufBuffer to read the value from.
Returns
The value that was read.

Definition at line 1059 of file ptp_util.c.

Referenced by ptp_MsgPdelayReqRcv(), and ptp_MsgPdelayRespRcv().

+ Here is the caller graph for this function:

ptp_uinteger48 ptp_rcvUInt48 ( ptp_octet pBuf)

Receive unsigned 48 bits integer.

This function reads a 48-bit value from a buffer.

Parameters
[in]pBufBuffer to read the value from.
Returns
The value that was read.

Definition at line 1077 of file ptp_util.c.

void ptp_rcvUInt48sc ( ptp_octet pBuf,
PTP_SecondsCount p 
)

Receive seconds count value.

This function reads a seconds count value from a buffer.

Parameters
[in]pBufBuffer to read the value from.
[out]pPointer to the destination value.

Definition at line 1098 of file ptp_util.c.

Referenced by ptp_MsgPdelayReqRcv(), and ptp_MsgPdelayRespRcv().

+ Here is the caller graph for this function:

ptp_uinteger64 ptp_rcvUInt64 ( ptp_octet pBuf)

Receive unsigned 64 bits integer.

This function reads a 64-bit value from a buffer.

Parameters
[in]pBufBuffer to read the value from.
Returns
The value that was read.

Definition at line 1116 of file ptp_util.c.

ptp_uinteger8 ptp_rcvUInt8 ( ptp_octet pBuf)

Receive unsigned 8 bits integer.

This function reads a 8-bit value from a buffer.

Parameters
[in]pBufBuffer to read the value from.
Returns
The value that was read.

Definition at line 1030 of file ptp_util.c.

Referenced by ptp_storeForeignMaster().

+ Here is the caller graph for this function:

ptp_uinteger8 ptp_snd ( ptp_uinteger8  len,
void *  pBuf 
)

Send data.

This function write data to the buffer, the ptp_startFrame must be called prior to this function.

Parameters
[in]lenAmount of data, in bytes to write to the network buffer.
[in]pBufPointer to source data buffer to copy to the network buffer.
Returns
1 on success, 0 on fail because size is larger than remaining bytes on buffer accordingly to the requested bytes on the call to ptp_startFrame.

Definition at line 906 of file ptp_util.c.

References nwk_snd().

Referenced by ptp_MsgAnnounceSnd(), ptp_MsgHeaderSnd(), ptp_MsgPdelayReqSnd(), and ptp_MsgPdelayRespSnd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ptp_uinteger8 ptp_sndInt64 ( ptp_integer64 p)

Send 64 bits integer.

This function write a 64-bit value to the network buffer.

Parameters
[in]pPointer to the value to write.
Returns
1 on success, 0 on fail (fail because buffer overflow) buffer accordingly to the requested bytes on the call to ptp_startFrame.

Definition at line 1017 of file ptp_util.c.

References nwk_sndInt64().

Referenced by ptp_MsgHeaderSnd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ptp_uinteger8 ptp_sndUInt16 ( ptp_uinteger16  v)

Send unsigned 16 bits integer.

This function write a 16-bit value to the network buffer.

Parameters
[in]vValue to write.
Returns
1 on success, 0 on fail (fail because buffer overflow) Accordingly to the requested bytes on the call to ptp_startFrame.

Definition at line 944 of file ptp_util.c.

References nwk_sndUInt16().

Referenced by ptp_MsgAnnounceSnd(), ptp_MsgHeaderSnd(), and ptp_MsgPdelayRespSnd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ptp_uinteger8 ptp_sndUInt32 ( ptp_uinteger32 p)

Send unsigned 32 bits integer.

This function write a 32-bit value to the network buffer.

Parameters
[in]pPointer to the value to write.
Returns
1 on success, 0 on fail (fail because buffer overflow) buffer accordingly to the requested bytes on the call to ptp_startFrame.

Definition at line 958 of file ptp_util.c.

References nwk_sndUInt32().

Referenced by ptp_MsgAnnounceSnd(), ptp_MsgPdelayReqSnd(), and ptp_MsgPdelayRespSnd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ptp_uinteger8 ptp_sndUInt48 ( ptp_uinteger48 p)

Send unsigned 48 bits integer.

This function write a 48-bit value to the network buffer.

Parameters
[in]pPointer to the value to write.
Returns
1 on success, 0 on fail (fail because buffer overflow) buffer accordingly to the requested bytes on the call to ptp_startFrame.

Definition at line 972 of file ptp_util.c.

References nwk_sndUInt48().

+ Here is the call graph for this function:

ptp_uinteger8 ptp_sndUInt48sc ( PTP_SecondsCount p)

Send a seconds count value.

This function write a seconds count value to the network buffer.

Parameters
[in]pPointer to the value to write.
Returns
1 on success, 0 on fail (fail because buffer overflow) buffer accordingly to the requested bytes on the call to ptp_startFrame.

Definition at line 986 of file ptp_util.c.

References nwk_sndUInt16(), and nwk_sndUInt32().

Referenced by ptp_MsgAnnounceSnd(), ptp_MsgPdelayReqSnd(), and ptp_MsgPdelayRespSnd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ptp_uinteger8 ptp_sndUInt64 ( ptp_uinteger64 p)

Send unsigned 64 bits integer.

This function write a 64-bit value to the network buffer.

Parameters
[in]pPointer to the value to write.
Returns
1 on success, 0 on fail (fail because buffer overflow) buffer accordingly to the requested bytes on the call to ptp_startFrame.

Definition at line 1003 of file ptp_util.c.

References nwk_sndUInt64().

+ Here is the call graph for this function:

ptp_uinteger8 ptp_sndUInt8 ( ptp_uinteger8  v)

Send unsigned 8 bits integer.

This function write a 8-bit value to the network buffer.

Parameters
[in]vValue to write.
Returns
1 on success, 0 on fail (fail because buffer overflow) Accordingly to the requested bytes on the call to ptp_startFrame.

Definition at line 930 of file ptp_util.c.

References nwk_sndUInt8().

Referenced by ptp_MsgAnnounceSnd(), and ptp_MsgHeaderSnd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ptp_uinteger8 ptp_startFrame ( ptp_uinteger16  destination,
ptp_uinteger8  len 
)

Start Frame.

This function starts to write a PTP frame (packet) to be send over the network.

Parameters
[in]destinationDestination of the frame.
[in]lenLenght of the data.
Returns
1 on success, 0 on fail.

Definition at line 889 of file ptp_util.c.

References NWK_CMDIDPTP, and nwk_startFrame().

Referenced by ptp_MsgAnnounceSnd(), ptp_MsgPdelayReqSnd(), and ptp_MsgPdelayRespSnd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ptp_state_decision_event ( )

State decision event.

This function executes the STATE_DECISION_EVENT. It must be run at least once per announce message transmission interval. IEC 61588-2009 / IEEE 1588-2008 9.2.6.8

Definition at line 248 of file ptp_util.c.

References ptp_bmc(), ptp_portUpdateDS(), and ptp_portUpdateStatus().

Referenced by ptp_process(), and ptp_setNetTime().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ptp_storeForeignMaster ( ptp_octet pBuf,
ptp_uinteger8  portNumber 
)

Store foreign master.

This function stores an announce message received from the network. IEC 61588-2009 / IEEE 1588-2008 9.5.3 b) and 9.3.2.2. Offsets from IEC 61588-2009 / IEEE 1588-2008 13.3.1 and 13.5.1.

Parameters
[in]pBufPointer to the contents of the announce message.
[in]portNumberPort number of the receiver

Definition at line 833 of file ptp_util.c.

References ptp_clockIdentityCompare(), ptp_rcvOctets(), ptp_rcvUInt16(), and ptp_rcvUInt8().

Referenced by ptp_MsgAnnounceRcv().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ptp_integer64 ptp_timeDiff ( PTP_TimeStamp t1,
PTP_TimeStamp t2 
)

Time difference.

Calculates the difference between two given times.

Parameters
[in]t1Pointer to the supposedly initial time.
[in]t2Pointer to the supposedly final time.
Returns
Time difference, in ns, t2 - t1. May be negative.

Definition at line 187 of file ptp_util.c.

References clock_timeDiff().

Referenced by ptp_MsgPdelayRespRcv(), and ptp_MsgPdelayRespSnd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function: