/*  ============================================================================
 *   Copyright (c) Texas Instruments Inc 2013
 *
 *   Use of this software is controlled by the terms and conditions found in the
 *   license agreement under which this software has been supplied.
* ============================================================================
Example to show the performance of Multicore Navigator on KeyStone DSP
* =============================================================================
*/

#include <stdio.h>
#include <csl_cacheAux.h>
#include <csl_cache.h>
#include <csl_qm_queue.h>
#include "K2_common.h"
#include "MNav_Test.h"

Uint32 uiaDescriptorBuffer[TEST_DESC_BUF_SIZE];
Uint32 pktLen, bufLen;

void PktDmaTest(void)
{
	int i, j;
	HostPacketDescriptor * hostDescriptor;
	MonolithicPacketDescriptor * monoDescriptor;
	Uint32 * uipSrcBufPtr, * uipDstBufPtr;
	Uint32 preTSC, cycles, uiEntryCount;

	/* Poll the packet descriptor in destination queue */	
	do
	{
		/* Received packet number should equal to channel number 
		since each channel transfer on packet*/
		uiEntryCount= KeyStone_GetQueueEntryCount(PKT_DMA_TEST_DST_Q);
	}while(!uiEntryCount);

	/*check recieved data and recycle descriptors and buffers */
	hostDescriptor= (HostPacketDescriptor *)KeyStone_queuePop(PKT_DMA_TEST_DST_Q);

	/* Invalid cache before read descriptor RAM */
	InvalidCache((void *)hostDescriptor, 64);

	/* Get the destination buffer */
	if(Cppi_DescType_HOST==hostDescriptor->type_id)
	{
		uipDstBufPtr= (Uint32 *)hostDescriptor->buffer_ptr;
		pktLen = hostDescriptor->packet_length;
        bufLen = hostDescriptor->buffer_len;
	}
	else
	{
		monoDescriptor= (MonolithicPacketDescriptor *)hostDescriptor;
		uipDstBufPtr= (Uint32 *)((Uint8 *)monoDescriptor + monoDescriptor->data_offset);
		pktLen = hostDescriptor->packet_length;
        bufLen = hostDescriptor->buffer_len;
	}
    printf("Receive descriptor address is 0x%08X \n", hostDescriptor);
    printf("Receive to 0x%08X \n", (Uint32)uipDstBufPtr);
    printf("Packet length is %8d \n", pktLen);
    printf("Bufer length is %8d \n", bufLen);
    printf("Descriptor type is %8d \n", hostDescriptor->type_id);

	/* Invalid old contents of destination buffer in cache before read */
	InvalidCache((void *)uipDstBufPtr, pktLen);

	/* Print the destination data */
	for(i=0; i<pktLen/4; i++)
	{
		printf("Receive word %d is %d \n", i, uipDstBufPtr[i]);
	}
		
	/* Descriptor Reclamation */
	gQueueManageVBUSM[RECLAMATION_QUEUE].REG_D_Descriptor= uiaDescriptorBuffer[j];

}


