void AVB1722_AVBTP_HeaderGen(unsigned char Buf[], int valid_ts, unsigned avbtp_ts, int pkt_data_length, int sequence_number, const unsigned stream_id0) { AVB_DataHeader_t *pAVBHdr = (AVB_DataHeader_t *) &(Buf[AVB_ETHERNET_HDR_SIZE]); SET_AVBTP_PACKET_DATA_LENGTH(pAVBHdr, pkt_data_length); // only stamp the AVBTP timestamp when required. if (valid_ts) { SET_AVBTP_TV(pAVBHdr, 1); // AVB timestamp valid. SET_AVBTP_TIMESTAMP(pAVBHdr, avbtp_ts); // Valid ns field. } else { SET_AVBTP_TV(pAVBHdr, 0); // AVB timestamp not valid. SET_AVBTP_TIMESTAMP(pAVBHdr, 0); // NULL the timestmap field as well. } // update stream ID by adding stream number to preloaded stream ID // (ignoring the fact that talkerStreamIdExt is stored MSB-first - it's just an ID) SET_AVBTP_STREAM_ID0(pAVBHdr, stream_id0); // update the ... SET_AVBTP_SEQUENCE_NUMBER(pAVBHdr, sequence_number); }
/** This configure AVB Talker buffer for a given stream configuration. * It updates the static portion of Ehternet/AVB transport layer headers. */ void AVB1722_Talker_bufInit(unsigned char Buf0[], avb1722_Talker_StreamConfig_t *pStreamConfig, int vlanid) { int i; unsigned char *Buf = &Buf0[2]; AVB_Frame_t *pEtherHdr = (AVB_Frame_t *) &(Buf[0]); AVB_DataHeader_t *p1722Hdr = (AVB_DataHeader_t *) &(Buf[AVB_ETHERNET_HDR_SIZE]); AVB_AVB1722_CIP_Header_t *p61883Hdr = (AVB_AVB1722_CIP_Header_t *) &(Buf[AVB_ETHERNET_HDR_SIZE + AVB_TP_HDR_SIZE]); // clear all the bytes in header. memset( (void *) Buf, 0, (AVB_ETHERNET_HDR_SIZE + AVB_TP_HDR_SIZE + AVB_CIP_HDR_SIZE)); //-------------------------------------------------------------------------- // 1. Initialaise the ethernet layer. // copy both Src/Dest MAC address for (i = 0; i < MAC_ADRS_BYTE_COUNT; i++) { pEtherHdr->DA[i] = pStreamConfig->destMACAdrs[i]; pEtherHdr->SA[i] = pStreamConfig->srcMACAdrs[i]; } SET_AVBTP_TPID(pEtherHdr, AVB_TPID); SET_AVBTP_PCP(pEtherHdr, AVB_DEFAULT_PCP); SET_AVBTP_CFI(pEtherHdr, AVB_DEFAULT_CFI); SET_AVBTP_VID(pEtherHdr, vlanid); SET_AVBTP_ETYPE(pEtherHdr, AVB_1722_ETHERTYPE); //-------------------------------------------------------------------------- // 2. Initialaise the AVB TP layer. // NOTE: Since the data structure is cleared before we only set the requird bits. SET_AVBTP_SV(p1722Hdr, 1); // set stream ID to valid. SET_AVBTP_STREAM_ID0(p1722Hdr, pStreamConfig->streamId[0]); SET_AVBTP_STREAM_ID1(p1722Hdr, pStreamConfig->streamId[1]); //-------------------------------------------------------------------------- // 3. Initialaise the 61883 CIP protocol specific part SET_AVB1722_CIP_TAG(p1722Hdr, AVB1722_DEFAULT_TAG); SET_AVB1722_CIP_CHANNEL(p1722Hdr, AVB1722_DEFAULT_CHANNEL); SET_AVB1722_CIP_TCODE(p1722Hdr, AVB1722_DEFAULT_TCODE); SET_AVB1722_CIP_SY(p1722Hdr, AVB1722_DEFAULT_SY); SET_AVB1722_CIP_EOH1(p61883Hdr, AVB1722_DEFAULT_EOH1); SET_AVB1722_CIP_SID(p61883Hdr, AVB1722_DEFAULT_SID); SET_AVB1722_CIP_DBS(p61883Hdr, 6); SET_AVB1722_CIP_FN(p61883Hdr, 3); SET_AVB1722_CIP_QPC(p61883Hdr, 0); SET_AVB1722_CIP_SPH(p61883Hdr, 1); SET_AVB1722_CIP_DBC(p61883Hdr, AVB1722_DEFAULT_DBC); SET_AVB1722_CIP_EOH2(p61883Hdr, AVB1722_DEFAULT_EOH2); SET_AVB1722_CIP_FMT(p61883Hdr, 0x20); SET_AVB1722_CIP_FDF(p61883Hdr, 0x80); SET_AVB1722_CIP_SYT(p61883Hdr, AVB1722_DEFAULT_SYT); }