Commit 62acc0ad authored by Adam Wujek's avatar Adam Wujek Committed by Tristan Gingold

proto-ext-whiterabbit/wr-msg: use ntoh* and hton* instead of get_be* and put_be*

Saves some code.
Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent 5818ead1
...@@ -10,47 +10,6 @@ ...@@ -10,47 +10,6 @@
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
#include "../proto-standard/common-fun.h" #include "../proto-standard/common-fun.h"
/*
* WR way to handle little/big endianness
* FIXME: check whether htons would be ok
*/
/* put 16 bit word in big endianess (from little endianess) */
static inline void put_be16(void *ptr, UInteger16 x)
{
*(unsigned char *)(ptr++) = (x >> 8) & 0xff;
*(unsigned char *)(ptr++) = (x) & 0xff;
}
/* put 32 bit word in big endianess (from little endianess) */
static inline void put_be32(void *ptr, UInteger32 x)
{
*(unsigned char *)(ptr++) = (x >> 24) & 0xff;
*(unsigned char *)(ptr++) = (x >> 16) & 0xff;
*(unsigned char *)(ptr++) = (x >> 8) & 0xff;
*(unsigned char *)(ptr++) = (x) & 0xff;
}
/* gets 32 bit word from big endianness (to little endianness) */
static inline UInteger32 get_be32(void *ptr)
{
UInteger32 res = 0x0;
res = res | ((*(unsigned char *)(ptr++) << 24) & 0xFF000000);
res = res | ((*(unsigned char *)(ptr++) << 16) & 0x00FF0000);
res = res | ((*(unsigned char *)(ptr++) << 8 ) & 0x0000FF00);
res = res | ((*(unsigned char *)(ptr++) << 0 ) & 0x000000FF);
return res;
}
/* gets 16 bit word from big endianess (to little endianess) */
static inline UInteger16 get_be16(void *ptr)
{
UInteger16 res = 0x0;
res = res | ((*(unsigned char *)(ptr++) << 8 ) & 0xFF00);
res = res | ((*(unsigned char *)(ptr++) << 0 ) & 0x000FF);
return res;
}
/* Pack White rabbit message in the suffix of PTP announce message */ /* Pack White rabbit message in the suffix of PTP announce message */
void msg_pack_announce_wr_tlv(struct pp_instance *ppi) void msg_pack_announce_wr_tlv(struct pp_instance *ppi)
{ {
...@@ -91,7 +50,7 @@ void msg_unpack_announce_wr_tlv(void *buf, MsgAnnounce *ann, UInteger16 *wrFlags ...@@ -91,7 +50,7 @@ void msg_unpack_announce_wr_tlv(void *buf, MsgAnnounce *ann, UInteger16 *wrFlags
UInteger16 tlv_versionNumber; UInteger16 tlv_versionNumber;
UInteger16 tlv_wrMessageID; UInteger16 tlv_wrMessageID;
tlv_type = (UInteger16)get_be16(buf+64); tlv_type = ntohs(*(UInteger16 *)(buf + 64));
tlv_organizationID = ntohs(*(UInteger16 *)(buf+68)) << 8; tlv_organizationID = ntohs(*(UInteger16 *)(buf+68)) << 8;
tlv_organizationID = ntohs(*(UInteger16 *)(buf+70)) >> 8 tlv_organizationID = ntohs(*(UInteger16 *)(buf+70)) >> 8
| tlv_organizationID; | tlv_organizationID;
...@@ -106,7 +65,7 @@ void msg_unpack_announce_wr_tlv(void *buf, MsgAnnounce *ann, UInteger16 *wrFlags ...@@ -106,7 +65,7 @@ void msg_unpack_announce_wr_tlv(void *buf, MsgAnnounce *ann, UInteger16 *wrFlags
tlv_magicNumber == WR_TLV_MAGIC_NUMBER && tlv_magicNumber == WR_TLV_MAGIC_NUMBER &&
tlv_versionNumber == WR_TLV_WR_VERSION_NUMBER && tlv_versionNumber == WR_TLV_WR_VERSION_NUMBER &&
tlv_wrMessageID == ANN_SUFIX) { tlv_wrMessageID == ANN_SUFIX) {
*wrFlags= (UInteger16)get_be16(buf+76); *wrFlags= ntohs(*(UInteger16 *)(buf + 76));
} else } else
*wrFlags = 0; *wrFlags = 0;
} }
...@@ -131,7 +90,8 @@ int msg_pack_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id) ...@@ -131,7 +90,8 @@ int msg_pack_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id)
/* target portIdentity */ /* target portIdentity */
memcpy((buf+34), &DSPAR(ppi)->parentPortIdentity.clockIdentity, memcpy((buf+34), &DSPAR(ppi)->parentPortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH); PP_CLOCK_IDENTITY_LENGTH);
put_be16(buf + 42, DSPAR(ppi)->parentPortIdentity.portNumber); *(UInteger16 *)(buf + 42) =
htons(DSPAR(ppi)->parentPortIdentity.portNumber);
/* WR TLV */ /* WR TLV */
*(UInteger16 *)(buf+44) = htons(TLV_TYPE_ORG_EXTENSION); *(UInteger16 *)(buf+44) = htons(TLV_TYPE_ORG_EXTENSION);
...@@ -147,24 +107,34 @@ int msg_pack_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id) ...@@ -147,24 +107,34 @@ int msg_pack_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id)
switch (wr_msg_id) { switch (wr_msg_id) {
case CALIBRATE: case CALIBRATE:
if (wrp->calibrated) { if (wrp->calibrated) {
put_be16(buf+56, *(UInteger16 *)(buf + 56) =
(WR_DSPOR(ppi)->calRetry | 0x0000)); htons(WR_DSPOR(ppi)->calRetry | 0x0000);
} else { } else {
put_be16(buf+56, *(UInteger16 *)(buf + 56) =
(WR_DSPOR(ppi)->calRetry | 0x0100)); htons(WR_DSPOR(ppi)->calRetry | 0x0100);
} }
put_be32(buf+58, WR_DSPOR(ppi)->calPeriod);
/* calPeriod in a frame crosses a word boundary,
split it into two parts */
*(UInteger16 *)(buf + 58) =
htonl(WR_DSPOR(ppi)->calPeriod) & 0xFFFF;
*(UInteger16 *)(buf + 60) =
htonl(WR_DSPOR(ppi)->calPeriod) >> 16;
len = 14; len = 14;
break; break;
case CALIBRATED: case CALIBRATED:
/* delta TX */ /* delta TX */
put_be32(buf+56, wrp->deltaTx.scaledPicoseconds.msb); *(UInteger32 *)(buf + 56) =
put_be32(buf+60, wrp->deltaTx.scaledPicoseconds.lsb); htonl(wrp->deltaTx.scaledPicoseconds.msb);
*(UInteger32 *)(buf + 60) =
htonl(wrp->deltaTx.scaledPicoseconds.lsb);
/* delta RX */ /* delta RX */
put_be32(buf+64, wrp->deltaRx.scaledPicoseconds.msb); *(UInteger32 *)(buf + 64) =
put_be32(buf+68, wrp->deltaRx.scaledPicoseconds.lsb); htonl(wrp->deltaRx.scaledPicoseconds.msb);
*(UInteger32 *)(buf + 68) =
htonl(wrp->deltaRx.scaledPicoseconds.lsb);
len = 24; len = 24;
break; break;
...@@ -174,7 +144,8 @@ int msg_pack_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id) ...@@ -174,7 +144,8 @@ int msg_pack_wrsig(struct pp_instance *ppi, Enumeration16 wr_msg_id)
break; break;
} }
/* header len */ /* header len */
put_be16(buf + 2, WR_SIGNALING_MSG_BASE_LENGTH + len); *(UInteger16 *)(buf + 2) = htons(WR_SIGNALING_MSG_BASE_LENGTH + len);
/* TLV len */ /* TLV len */
*(Integer16 *)(buf+46) = htons(len); *(Integer16 *)(buf+46) = htons(len);
...@@ -196,9 +167,10 @@ int msg_unpack_wrsig(struct pp_instance *ppi, void *buf, ...@@ -196,9 +167,10 @@ int msg_unpack_wrsig(struct pp_instance *ppi, void *buf,
memcpy(&wrsig_msg->targetPortIdentity.clockIdentity, (buf + 34), memcpy(&wrsig_msg->targetPortIdentity.clockIdentity, (buf + 34),
PP_CLOCK_IDENTITY_LENGTH); PP_CLOCK_IDENTITY_LENGTH);
wrsig_msg->targetPortIdentity.portNumber = (UInteger16)get_be16(buf+42); wrsig_msg->targetPortIdentity.portNumber =
ntohs(*(UInteger16 *)(buf + 42));
tlv_type = (UInteger16)get_be16(buf + 44); tlv_type = ntohs(*(UInteger16 *)(buf + 44));
tlv_organizationID = ntohs(*(UInteger16 *)(buf + 48)) << 8; tlv_organizationID = ntohs(*(UInteger16 *)(buf + 48)) << 8;
tlv_organizationID = ntohs(*(UInteger16 *)(buf + 50)) >> 8 tlv_organizationID = ntohs(*(UInteger16 *)(buf + 50)) >> 8
| tlv_organizationID; | tlv_organizationID;
...@@ -244,29 +216,35 @@ int msg_unpack_wrsig(struct pp_instance *ppi, void *buf, ...@@ -244,29 +216,35 @@ int msg_unpack_wrsig(struct pp_instance *ppi, void *buf,
switch (wr_msg_id) { switch (wr_msg_id) {
case CALIBRATE: case CALIBRATE:
wrp->otherNodeCalSendPattern = wrp->otherNodeCalSendPattern =
0x00FF & (get_be16(buf+56) >> 8); 0x00FF & (ntohs(*(UInteger16 *)(buf + 56)) >> 8);
wrp->otherNodeCalRetry = wrp->otherNodeCalRetry =
0x00FF & get_be16(buf+56); 0x00FF & ntohs(*(UInteger16 *)(buf + 56));
wrp->otherNodeCalPeriod = get_be32(buf+58);
/* OtherNodeCalPeriod in a frame crosses a word boundary,
split it into two parts */
WR_DSPOR(ppi)->otherNodeCalPeriod =
ntohs(*(UInteger16 *)(buf + 60));
WR_DSPOR(ppi)->otherNodeCalPeriod <<= 16;
WR_DSPOR(ppi)->otherNodeCalPeriod |=
ntohs(*(UInteger16 *)(buf + 58));
pp_diag(ppi, frames, 1, "otherNodeCalPeriod " pp_diag(ppi, frames, 1, "otherNodeCalPeriod 0x%x\n",
"from frame = 0x%x | stored = 0x%x \n", get_be32(buf+58), WR_DSPOR(ppi)->otherNodeCalPeriod);
WR_DSPOR(ppi)->otherNodeCalPeriod);
break; break;
case CALIBRATED: case CALIBRATED:
/* delta TX */ /* delta TX */
wrp->otherNodeDeltaTx.scaledPicoseconds.msb = wrp->otherNodeDeltaTx.scaledPicoseconds.msb =
get_be32(buf+56); ntohl(*(UInteger32 *)(buf + 56));
wrp->otherNodeDeltaTx.scaledPicoseconds.lsb = wrp->otherNodeDeltaTx.scaledPicoseconds.lsb =
get_be32(buf+60); ntohl(*(UInteger32 *)(buf + 60));
/* delta RX */ /* delta RX */
wrp->otherNodeDeltaRx.scaledPicoseconds.msb = wrp->otherNodeDeltaRx.scaledPicoseconds.msb =
get_be32(buf+64); ntohl(*(UInteger32 *)(buf + 64));
wrp->otherNodeDeltaRx.scaledPicoseconds.lsb = wrp->otherNodeDeltaRx.scaledPicoseconds.lsb =
get_be32(buf+68); ntohl(*(UInteger32 *)(buf + 68));
break; break;
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment