/******************************************************************************

 C   M O D U L E   F I L E
 
 (c) Copyright Motorola Semiconductors Hong Kong Limited 2000-2003
 ALL RIGHTS RESERVED

*******************************************************************************

 Project Name	: i.MX System Test Program
 Project No.	: 
 Title			: 
 File Name		: main.c
 Last Modified	: 04/27/2003
 (MM/DD/YYYY)

 Description	: The main function
 
 Comments		:

 History (MM/DD/YYYY):
 04/27/2003 - Initial Proposal

******************************************************************************/
#include <stdio.h>
#include "common.h"
#include "tht_memory_map_defines.h"
#include "testcase.h"

/* Modify SysInit() for different system initialization settings */
extern int SysInit(void);

/* Modify the following data structure to contain the test cases to perform */
testcase_t gTestCaseArray[] = {
	{case1, 1},
	{case2, 2},
//	{case3, 3},
/*	{case4, 4},
	{case5, 5},
	{case6, 6},
	{case7, 7},
	{case8, 8},
	{case9, 9},
	{case10, 10},*/
};

/****************************************************************
 Private Functions
****************************************************************/

//---------------------------------------------------------------
// Function		: handleError
//		
// Description	: Handles error according to caseNum and the error
//
// Return Value	: None
//
//---------------------------------------------------------------
static void handleError
	(
	uint8_t* index, // IN/OUT: index into gTestCaseArray[]
	status_t status	// IN: the error status to handle
	)
{
	switch(status)
	{
	case ERR_TIMEOUT:
		printf("\n -- Time out!! --\n");
		
		// say, we want to retry....
		printf("Retrying Case %d....\n", gTestCaseArray[*index - 1].caseNum);
		*index -= 1;	// do this to retry
		break;
		
	default:
		printf("\n -- Error --\n");
	}
}

/*****************************************************************
 Public Functions
*****************************************************************/
int32_t main(void)
{

	static uint8_t index;
	status_t status;
	uint8_t numTestCase = sizeof(gTestCaseArray) / sizeof(testcase_t); // Check whether this works as intended!
	
	SysInit();
	
	for (index = 1; index <= numTestCase; index++)
	{
		printf("================================================\n");
		printf("Start of Case %d\n", gTestCaseArray[index - 1].caseNum);
		printf("================================================\n");
			
		status = gTestCaseArray[index - 1].func();
		if (status != OK)
		{
			// Error
			handleError(&index, status);
		}
		else
			printf("\n-- PASS --\n");
		printf("\n\n");
	}

}