#ifdef CPE_40
#ifdef BUP_DIAGS
#include <stdio.h>
#ifdef USE_VXWORKS /* IXDP425 */
#include <vxWorks.h>
#include <stdio.h>
#include <bme.h>
#endif
#include "bup_jaguar_mem.h"

int lbistDdr ()
{
	int i=0;
	int j=0;
	int ife_present=0;
	int test_data0 = 0;
	int test_data1 = 0;
	int cmp_data = 0;
	int read_data = 0;
	unsigned int data;
	unsigned int Flag = 0;
	unsigned int IfeId, stat;


	i = 0;
	j = 0;
	// Reset the ASIC
	stat = wtIfeReg (DTEST_ADDR,  0x1);
	if (stat)
		return -1;
	stat = wtIfeReg (AFE_CH0_ADDR,0x0);
	if (stat)
		return -1;
	testPIOWrite(1,INTP_EN,0x00000101);

	//test_data0 = 0x0000aaaa + i; 
	// DDR_LBIST_DATA0 and DDR_LBIST_DATA1 are used as data test source. Data 1 will be dropped
	// by afe
	test_data0 = 0x0000aaaa;  
//	test_data1 = 0x00003366; 
	testPIOWrite(1,DDR_LBIST_DATA0,test_data0);
//	testPIOWrite(1,DDR_LBIST_DATA1,test_data1);

	// afe drops 2 bits and sends it back
	cmp_data =  (test_data0 & 0x00003fff)>>2;
	testPIOWrite(1,DDR_LBIST_CMP, ((cmp_data<<8) | 0x00000001));

	// enab;e lbist mode
	testPIOWrite(1,DDR_TEST_CTRL,0x00000001);

	// Comparision Loop do serial access and then compare the DDR Loopback Data
	taskDelay(100);
	read_data = testPIORead1 (1,DDR_LBIST_STAT);
	if ((read_data & 0x00000001) == 1)
	{
		printf ("\t***** >>>> DDR I/F test FAILED: (LBIST)  <<<< *****\n");
		return -1;
	}
	testPIOWrite(1,DDR_LBIST_CMP, 0x0);
	testPIOWrite(1,DDR_TEST_CTRL,0x00000000);
	if (Flag != 1)
	{
		printf ("\t\t\tDDR I/F test Passed\n");
		return 0;
	}
}

#if 0
inline void	testPIOWrite (int bup_bme,int address,int data)
{

	* ((int *) (address))   = data;

}

inline int	 testPIORead1 (int bup_bme,int address)
{
	return * ((int *) (address))   ;
}
#endif

#endif
#endif
//------------------------------------------------------------
