Utilities for use by the PTP implementation. More...
Utilities for use by the PTP implementation.
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 .
[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().
ptp_integer8 ptp_clockIdentityCompare | ( | ptp_clockIdentity | A, |
ptp_clockIdentity | B | ||
) |
Clock identity compare.
Compares two given clock identities.
[in] | A | First clock identity. |
[in] | B | Second clock identity. |
Definition at line 201 of file ptp_util.c.
Referenced by ptp_bmc(), ptp_dataSetComparisonDE(), ptp_dataSetComparisonEE(), ptp_rcvmessage(), and ptp_storeForeignMaster().
void ptp_copyOctets | ( | ptp_uinteger8 | len, |
ptp_octet * | source, | ||
ptp_octet * | dest | ||
) |
Copy octets.
This function copy octets from a buffer to another.
[in] | len | Length of the data to copy. |
[in] | source | Buffer to read the value from. |
[out] | dest | Buffer to write to. |
Definition at line 1177 of file ptp_util.c.
Referenced by ptp_portsSetListening(), and ptp_rcvOctets().
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.
[out] | DBetter | indicates if self clock is better. |
[in] | D | Self clock |
[in] | E | Announce message |
[in] | portNumber | Port number of the announce message |
Definition at line 677 of file ptp_util.c.
References ptp_clockIdentityCompare(), and PTP_ZEROSEQ64.
Referenced by ptp_bmc().
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.
[out] | iBetter | Better announce message |
[out] | byTopology | indicates if result is only by topology |
[in] | E1 | first announce message |
[in] | E2 | second announce message |
[in] | i1 | Return value if E1 is better |
[in] | i2 | Return value if E2 is better |
Definition at line 501 of file ptp_util.c.
References ptp_clockIdentityCompare(), and PTP_ZEROSEQ64.
Referenced by ptp_bmc().
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().
ptp_clockIdentity* ptp_getClockIdentity | ( | ) |
Get clock identity.
This function returns a pointer to the Clock Identity value. It can be modified for specific applications.
Definition at line 85 of file ptp_util.c.
References nwk_getPIeeeAddress().
Referenced by ptp_initEnd().
void ptp_getCurrentTime | ( | PTP_TimeStamp * | dest | ) |
Get cuttent time.
This function get the current time of the device.
[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().
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().
ptp_integer64 ptp_rcvInt64 | ( | ptp_octet * | pBuf | ) |
Receive 64 bits integer.
This function reads a 64-bit value from a buffer.
[in] | pBuf | Buffer to read the value from. |
Definition at line 1138 of file ptp_util.c.
Referenced by ptp_MsgPdelayReqRcv(), and ptp_MsgPdelayRespRcv().
void ptp_rcvOctets | ( | ptp_uinteger8 | len, |
ptp_octet * | pBuf, | ||
ptp_octet * | dest | ||
) |
Receive octets.
This function reads octets from a buffer.
[in] | len | Length of the data to read. |
[in] | pBuf | Buffer to read the value from. |
[out] | dest | Pointer to the destination value. |
Definition at line 1162 of file ptp_util.c.
References ptp_copyOctets().
Referenced by ptp_MsgPdelayReqRcv(), and ptp_storeForeignMaster().
ptp_uinteger16 ptp_rcvUInt16 | ( | ptp_octet * | pBuf | ) |
Receive unsigned 16 bits integer.
This function reads a 16-bit value from a buffer.
[in] | pBuf | Buffer to read the value from. |
Definition at line 1043 of file ptp_util.c.
Referenced by ptp_MsgPdelayReqRcv(), ptp_MsgPdelayRespRcv(), ptp_rcvmessage(), and ptp_storeForeignMaster().
ptp_uinteger32 ptp_rcvUInt32 | ( | ptp_octet * | pBuf | ) |
Receive unsigned 32 bits integer.
This function reads a 32-bit value from a buffer.
[in] | pBuf | Buffer to read the value from. |
Definition at line 1059 of file ptp_util.c.
Referenced by ptp_MsgPdelayReqRcv(), and ptp_MsgPdelayRespRcv().
ptp_uinteger48 ptp_rcvUInt48 | ( | ptp_octet * | pBuf | ) |
Receive unsigned 48 bits integer.
This function reads a 48-bit value from a buffer.
[in] | pBuf | Buffer to read the value from. |
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.
[in] | pBuf | Buffer to read the value from. |
[out] | p | Pointer to the destination value. |
Definition at line 1098 of file ptp_util.c.
Referenced by ptp_MsgPdelayReqRcv(), and ptp_MsgPdelayRespRcv().
ptp_uinteger64 ptp_rcvUInt64 | ( | ptp_octet * | pBuf | ) |
Receive unsigned 64 bits integer.
This function reads a 64-bit value from a buffer.
[in] | pBuf | Buffer to read the value from. |
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.
[in] | pBuf | Buffer to read the value from. |
Definition at line 1030 of file ptp_util.c.
Referenced by ptp_storeForeignMaster().
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.
[in] | len | Amount of data, in bytes to write to the network buffer. |
[in] | pBuf | Pointer to source data buffer to copy to the network buffer. |
Definition at line 906 of file ptp_util.c.
References nwk_snd().
Referenced by ptp_MsgAnnounceSnd(), ptp_MsgHeaderSnd(), ptp_MsgPdelayReqSnd(), and ptp_MsgPdelayRespSnd().
ptp_uinteger8 ptp_sndInt64 | ( | ptp_integer64 * | p | ) |
Send 64 bits integer.
This function write a 64-bit value to the network buffer.
[in] | p | Pointer to the value to write. |
Definition at line 1017 of file ptp_util.c.
References nwk_sndInt64().
Referenced by ptp_MsgHeaderSnd().
ptp_uinteger8 ptp_sndUInt16 | ( | ptp_uinteger16 | v | ) |
Send unsigned 16 bits integer.
This function write a 16-bit value to the network buffer.
[in] | v | Value to write. |
Definition at line 944 of file ptp_util.c.
References nwk_sndUInt16().
Referenced by ptp_MsgAnnounceSnd(), ptp_MsgHeaderSnd(), and ptp_MsgPdelayRespSnd().
ptp_uinteger8 ptp_sndUInt32 | ( | ptp_uinteger32 * | p | ) |
Send unsigned 32 bits integer.
This function write a 32-bit value to the network buffer.
[in] | p | Pointer to the value to write. |
Definition at line 958 of file ptp_util.c.
References nwk_sndUInt32().
Referenced by ptp_MsgAnnounceSnd(), ptp_MsgPdelayReqSnd(), and ptp_MsgPdelayRespSnd().
ptp_uinteger8 ptp_sndUInt48 | ( | ptp_uinteger48 * | p | ) |
Send unsigned 48 bits integer.
This function write a 48-bit value to the network buffer.
[in] | p | Pointer to the value to write. |
Definition at line 972 of file ptp_util.c.
References nwk_sndUInt48().
ptp_uinteger8 ptp_sndUInt48sc | ( | PTP_SecondsCount * | p | ) |
Send a seconds count value.
This function write a seconds count value to the network buffer.
[in] | p | Pointer to the value to write. |
Definition at line 986 of file ptp_util.c.
References nwk_sndUInt16(), and nwk_sndUInt32().
Referenced by ptp_MsgAnnounceSnd(), ptp_MsgPdelayReqSnd(), and ptp_MsgPdelayRespSnd().
ptp_uinteger8 ptp_sndUInt64 | ( | ptp_uinteger64 * | p | ) |
Send unsigned 64 bits integer.
This function write a 64-bit value to the network buffer.
[in] | p | Pointer to the value to write. |
Definition at line 1003 of file ptp_util.c.
References nwk_sndUInt64().
ptp_uinteger8 ptp_sndUInt8 | ( | ptp_uinteger8 | v | ) |
Send unsigned 8 bits integer.
This function write a 8-bit value to the network buffer.
[in] | v | Value to write. |
Definition at line 930 of file ptp_util.c.
References nwk_sndUInt8().
Referenced by ptp_MsgAnnounceSnd(), and ptp_MsgHeaderSnd().
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.
[in] | destination | Destination of the frame. |
[in] | len | Lenght of the data. |
Definition at line 889 of file ptp_util.c.
References NWK_CMDIDPTP, and nwk_startFrame().
Referenced by ptp_MsgAnnounceSnd(), ptp_MsgPdelayReqSnd(), and ptp_MsgPdelayRespSnd().
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().
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.
[in] | pBuf | Pointer to the contents of the announce message. |
[in] | portNumber | Port 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().
ptp_integer64 ptp_timeDiff | ( | PTP_TimeStamp * | t1, |
PTP_TimeStamp * | t2 | ||
) |
Time difference.
Calculates the difference between two given times.
[in] | t1 | Pointer to the supposedly initial time. |
[in] | t2 | Pointer to the supposedly final time. |
Definition at line 187 of file ptp_util.c.
References clock_timeDiff().
Referenced by ptp_MsgPdelayRespRcv(), and ptp_MsgPdelayRespSnd().