This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

clarification of logic in Emac_main.c in TMS320TCI6486 DSP

declarations

EMAC_Pkt packet_header_tx[PKT_MAX_TX];
EMAC_Pkt packet_header_rx[PKT_MAX_RX];
Uint8 packet_buffer_tx[PKT_MAX_TX][TX_BUFFER_SIZE];
Uint8 packet_buffer_rx[PKT_MAX_RX][RX_BUFFER_SIZE];

structure of  APP_PKTQ;

typedef struct app_pktq
{
volatile unsigned short Count; /**< Number of packets in queue */
volatile EMAC_Pkt *pHead; /**< Pointer to first packet */
volatile EMAC_Pkt *pTail; /**< Pointer to last packet */
} APP_PKTQ;

structure of  EMAC_Pkt

typedef struct _EMAC_Pkt {
Uint32 AppPrivate; /**< For use by the application */
struct _EMAC_Pkt *pPrev; /**< Previous record */
struct _EMAC_Pkt *pNext; /**< Next record */
Uint8 *pDataBuffer; /**< Pointer to Data Buffer (read only) */
Uint32 BufferLen; /**< Physical Length of buffer (read only) */
Uint32 Flags; /**< Packet Flags */
Uint32 ValidLen; /**< Length of valid data in buffer */
Uint32 DataOffset;/**< Byte offset to valid data */
Uint32 PktChannel;/**< Tx/Rx Channel/Priority 0-7 (SOP only) */
Uint32 PktLength;/**< Length of Packet (SOP only) (same as ValidLen on single frag Pkt) */
Uint32 PktFrags;/**< No of frags in packet (SOP only) frag is EMAC_Pkt record-normally 1*/
} EMAC_Pkt;

void Ethernet_queue_init(void)
{
Uint32 i;

/* Clear our FreeTX, FreeRX and RX Queues */

memset( &FreeTxQueue, 0, sizeof(APP_PKTQ) );
memset( &FreeRxQueue, 0, sizeof(APP_PKTQ) );
memset( &RxQueue, 0, sizeof(APP_PKTQ) );

/* Initialize RX Packet Headers and Put in Free RX Queue */
for( i=0; i<PKT_MAX_RX; i++ )
{
memset( &packet_header_rx[i], 0, sizeof(EMAC_Pkt) );
packet_header_rx[i].pDataBuffer = packet_buffer_rx[i];
packet_header_rx[i].BufferLen = RX_BUFFER_SIZE;
App_pqPush( &FreeRxQueue, &packet_header_rx[i] );
}

/* Initialize TX Packet Headers and Put in Free TX Queue */
for( i=0; i<PKT_MAX_TX; i++ )
{
memset( &packet_header_tx[i], 0, sizeof(EMAC_Pkt) );
packet_header_tx[i].pDataBuffer = packet_buffer_tx[i];
packet_header_tx[i].BufferLen = TX_BUFFER_SIZE;
App_pqPush( &FreeTxQueue, &packet_header_tx[i] );
}
}

void App_pqPush( APP_PKTQ *pq, EMAC_Pkt *pPktHdr )

{
pPktHdr->pNext = 0;
if( !pq->pHead )
{
/* Queue is empty.Initialize it with this one packet */
pq->pHead = pPktHdr;
pq->pTail = pPktHdr;
}
else
{
// Queue is not empty - Push onto END
pq->pTail->pNext = pPktHdr;
pq->pTail = pPktHdr;
}
pq->Count++;
}

can any one explain me what is happening inside the Ethernet_queue_init() function?