/*************************************************************************
WARNING
   Copyright 2006 Hamilton Sundstrand Corporation. This document is the
   property of Hamilton Sundstrand Corporation ("HSC"). You may not possess,
   use, copy or disclose this document or any information in it, for any
   purpose, including without limitation, to design, manufacture or repair
   parts, or obtain any government approval to do so, without HSC's express
   written permission. Neither receipt nor possession of this document
   alone, from any source, constitutes such permission. Possession, use,
   copying or disclosure by anyone without HSC's express written permission
   is not authorized and may result in criminal and/or civil liability.
  ***************************************************************************

                              ********************************
                              *                              *
                              *        BT_RAM_Test.C         *
                              *                              *
                              ********************************

unit title:  BT_RAM_Test.C
author(s):  Kamaraj Thangavelu
Modified: Chitra Amzarewale
****************************************************************************
description:

     This module contains the BT_RAM_Test API definition.

   FUNCTIONS
        extern BT_VOID BT_RAM_Test(BT_BOOL Execute,
                                   BT_U32  *RAM_TEST_StartLocation,
                                   BT_U32  RAM_TEST_Size,
                                   BT_U32  RAM_TEST_Attempt
                                   BT_U32  RAM_Pattern)

partitioning information BT, External API
****************************************************************************
VERSION        : %full_filespec: BT_RAM_Test.h,4:incl:1 %
****************************************************************************/

#include "BT_RAM_Test.h"
#include "BT_RAM_TestResult.h"
failed_sector_t write_status;

BT_VOID BT_RAM_Test (BT_BOOL Execute,
					 BT_U32  *RAM_TEST_StartLocation,
					 BT_U32  RAM_TEST_Size,
					 BT_U32  RAM_TEST_Attempt,
					 BT_U32  RAM_Pattern)
{
	BT_U32 index;
	BT_U32 *RAM_write_ptr;
	BT_U8 write_attempts =0;
	BT_U32* SourceAddress;
	BT_U32* DestinationAddress;
	BT_U32 RAM_Size;

	RAM_write_ptr = (BT_U32 *)RAM_TEST_StartLocation;

	if (Execute == BT_TRUE)
	{
		switch(RAM_Pattern)
		{
			case 0xFFFFFFFF:
			{
				for (index = (BT_U32)0; index<=RAM_TEST_Size; index = index + (BT_U32)4)
				{
					*RAM_write_ptr = RAM_Pattern;
					RAM_write_ptr++;
				}
				break;
			}

			case 0x00000000:
			{
				for (index = (BT_U32)0; index<=RAM_TEST_Size; index = index + (BT_U32)4)
				{
					*RAM_write_ptr = RAM_Pattern;
					RAM_write_ptr++;
				}
				break;
			}

			case 0x55555555:
			{
				for (index = (BT_U32)0; index<=RAM_TEST_Size; index = index + (BT_U32)4)
				{
					*RAM_write_ptr = RAM_Pattern;
					RAM_write_ptr++;
				}
				break;
			}

			case 0xAAAAAAAA:
			{
				for (index = (BT_U32)0; index<=RAM_TEST_Size; index = index + (BT_U32)4)
				{
					*RAM_write_ptr = RAM_Pattern;
					RAM_write_ptr++;
				}
				break;
			}
			default:
				break;


		}

		SourceAddress = (BT_U32 *)RAM_TEST_StartLocation;
		DestinationAddress = (BT_U32  *)0x08001540;
		RAM_Size = RAM_TEST_Size;

		BT_UT_Move_Block ( SourceAddress, DestinationAddress, RAM_Size);

		write_attempts = write_attempts + 1;
		RAM_ReadTestResult(RAM_TEST_StartLocation, RAM_TEST_Size, RAM_Pattern);

		if ((write_status.status == BT_FALSE) && (write_attempts>=RAM_TEST_Attempt))
		{
			BT_RAM_TestResult(&(write_status.status), write_status.add_sector, &RAM_Pattern);
		}
		else
		{

		}
	}
	else
	{

	}

	return;
}
/****************************************************************************
description:

     This module contains the BT_RAM_Test API definition.

   FUNCTIONS
	void RAM_ReadTestResult(BT_U32 *RAM_TEST_StartLocation,
						    BT_U32  RAM_TEST_Size,
						    BT_U32  RAM_Pattern)

partitioning information BT, External API
****************************************************************************
VERSION        : %full_filespec: BT_RAM_TestResult.h,4:incl:1 %
****************************************************************************/
void RAM_ReadTestResult(BT_U32 *RAM_TEST_StartLocation,
						   BT_U32 RAM_TEST_Size,
						   BT_U32 RAM_Pattern)
{
	BT_U32 index;
	BT_U32 *RAM_read_ptr;

	write_status.status  = BT_FALSE;
	write_status.add_sector = &index;

	RAM_read_ptr = (BT_U32 *)RAM_TEST_StartLocation;

	if (write_status.status == BT_FALSE)
	{
		switch(RAM_Pattern)
			{
			case 0xFFFFFFFF:
			{
				for (index = (BT_U32)0; index<=RAM_TEST_Size; index = index + (BT_U32)4)
				{
					if (*RAM_read_ptr == RAM_Pattern)
					{
						RAM_read_ptr++;
					}
					else
					{
						write_status.status = BT_TRUE;
						write_status.add_sector = RAM_read_ptr;
						break;
					}
				}
				break;
			}

			case 0x00000000:
			{
				for (index = (BT_U32)0; index<=RAM_TEST_Size; index = index + (BT_U32)4)
				{
					if (*RAM_read_ptr == RAM_Pattern)
					{
						RAM_read_ptr++;
					}
					else
					{
						write_status.status = BT_TRUE;
						write_status.add_sector = RAM_read_ptr;
						break;
					}
				}
				break;
			}

			case 0x55555555:
			{
				for (index = (BT_U32)0; index<=RAM_TEST_Size; index = index + (BT_U32)4)
				{
					if (*RAM_read_ptr == RAM_Pattern)
					{
						RAM_read_ptr++;
					}
					else
					{
						write_status.status = BT_TRUE;
						write_status.add_sector = RAM_read_ptr;
						break;
					}
				}
				break;
			}

			case 0xAAAAAAAA:
			{
				for (index = (BT_U32)0; index<=RAM_TEST_Size; index = index + (BT_U32)4)
				{
					if (*RAM_read_ptr == RAM_Pattern)
					{
						RAM_read_ptr++;
					}
					else
					{
						write_status.status = BT_TRUE;
						write_status.add_sector = RAM_read_ptr;
						break;
					}
				}

				break;
			}
			default:
				break;
		}

		return;
	}
	else
	{
		return;
	}

}
/****************************************************************************
description:

     This module contains the BT_RAM_TestResult API definition.

   FUNCTIONS
	void BT_RAM_TestResult( BT_BOOL *IsFailed,
							BT_U32 *RAM_Failed_Address,
							BT_U32 *Pattern)

partitioning information BT, External API
****************************************************************************
VERSION        : %full_filespec: BT_RAM_TestResult.h,4:incl:1 %
****************************************************************************/

void BT_RAM_TestResult (BT_BOOL *IsFailed, BT_U32 *RAM_Failed_Address, BT_U32 *Pattern)
{
	return;
}

