#include  "windef.h"
#include  "mbdr_dsp_common_main_init_manager.h"
#include  "mbdr_dsp_utils.h"
#include  "mbdr_dsp_sdc_hwimage_int.h"
#include  "mbdr_dsp_common_boot_loader_app.h"

#include <stdio.h>
#include <string.h>
#include <csl_tmr.h>
#include <csl_tmrAux.h>
#include <csl_intc.h>
#include <csl_intcAux.h>
#include <soc.h>
#include <platform.h>

#define DUMMY_ARRAY_SIZE 18

#define DEVICE_REG32_W(x,y)   *(volatile LONG *)(x)=(y)
#define DEVICE_REG32_R(x)    (*(volatile LONG *)(x))
#define DUMMY_NUMBER   0x55

#pragma DATA_MEM_BANK (dummy_array, 0);
#pragma DATA_SECTION  (dummy_array,".dummy_array_sect");
LONG dummy_array[DUMMY_ARRAY_SIZE];

extern uint8_t test_nand_device(void);

const mbdr_dsp_main_init_manager_params_t
                    mbdr_dsp_main_init_manager_params =
{
 /*************/
 /* init_list */
 /*************/
 {  /* init_value, *dw_p */
  { 0, (LONG *)     &mbdr_dsp_utils_dummy},
  { 0, (LONG *)     &mbdr_dsp_utils_dummy},
  { 0, (LONG *)     &mbdr_dsp_utils_dummy},
  { 0, (LONG *)     &mbdr_dsp_utils_dummy},
  { 0, (LONG *)     &mbdr_dsp_utils_dummy},
  { 0, (LONG *)     &mbdr_dsp_utils_dummy},
  { 0, (LONG *)     &mbdr_dsp_utils_dummy},
  { 0, (LONG *)     &mbdr_dsp_utils_dummy}
 },

 /* *mbdr_dsp_chip_peripherals_init */
 &mbdr_dsp_chip_peripherals_init,

  /* mbdr_dsp_cpu_common_interface_t address in DSP memory */
 &mbdr_dsp_cpu_common_interface_dsp[0],

 /* multi_core_platform_init_hook_proc_p                   */
 &mbdr_dsp_common_main_init_multi_core_platform_init_hook_dummy

};

// initialized by debugger
extern  LONG debug_main_start_count;
LONG    debug_main_start_count;
extern void mbdr_dsp_boot_loader_clean_boot_sequence_area(void);


//returns 0x800FFFFF if test OK. or first fail address if TEST fails
LONG DDR_TEST ()
{
	LONG                ui_DDR_Start_Add = 0x80000000;
	LONG                ui_DDR_End_Add = 0x800FFFFF;
	LONG				  ui_Address;
	LONG				  ui_ReadValue;

	/*write to DDR*/
	ui_Address = ui_DDR_Start_Add;
	while (ui_Address<ui_DDR_End_Add)
	{
	   DEVICE_REG32_W(ui_Address, DUMMY_NUMBER);
	   ui_Address = ui_Address + 1;

	}
	/*read from DDR*/
	ui_Address = ui_DDR_Start_Add;
	while (ui_Address<ui_DDR_End_Add)
	{
	  ui_ReadValue = DEVICE_REG32_R(ui_Address);
	  if (ui_ReadValue != DUMMY_NUMBER)
	  {
			 break;
	  }
	  ui_Address = ui_Address + 1;
	}
	return ui_Address;
}


/**********************************************************************
 ************************** Local Definitions *************************
 **********************************************************************/

/* Maximum delay to wait for to detect spurious interrupts. */
#define  MAX_DELAY                  0xFFFF

/**********************************************************************
 ************************** Global Variables **************************
 **********************************************************************/



/* INTC Objects */
CSL_IntcObj                  tmrIntcObj;
CSL_IntcContext              context;
CSL_IntcEventHandlerRecord   EventHandler[30];

/* Global Variable for the INTC Module; useful for debugging. */
CSL_IntcRegsOvly    gIntcRegisters    = (CSL_IntcRegsOvly)CSL_CGEM0_5_REG_BASE_ADDRESS_REGS;

/* Counter for Timer ISR */
volatile Int32 timerISRCounter = 0;

/**********************************************************************
 ************************ TIMER TEST FUNCTIONS ************************
 **********************************************************************/

/**
 *  @b Description
 *  @n
 *      This is the Timer ISR handler which is invoked when the timer expires
 *
 *  @param[in]  arg
 *      Event ID which caused the ISR to be invoked.
 *
 *  @retval
 *      Not Applicable.
 */
static void TimerInterruptHandler (void *arg)
{
    /* Increment the number of interrupts detected. */
    timerISRCounter++;

    /* Clear the event ID. */
    CSL_intcEventClear((CSL_IntcEventId)arg);
}

/**
 *  @b Description
 *  @n
 *      This is the Watch Dog ISR handler which is invoked when the Watch Dog
 *      timer expires.
 *
 *  @param[in]  arg
 *      Event ID which caused the ISR to be invoked.
 *
 *  @retval
 *      Not Applicable.
 */


/**
 *  @b Description
 *  @n
 *      The functions initializes the INTC module.
 *
 *  @retval
 *      Success -   0
 *  @retval
 *      Error   -   <0
 */
static Int32 intc_init (void)
{
    CSL_IntcGlobalEnableState   state;

    /* INTC module initialization */
    context.eventhandlerRecord = EventHandler;
    context.numEvtEntries      = 10;
    if (CSL_intcInit(&context) != CSL_SOK)
        return -1;

    /* Enable NMIs */
    if (CSL_intcGlobalNmiEnable() != CSL_SOK)
        return -1;

    /* Enable global interrupts */
    if (CSL_intcGlobalEnable(&state) != CSL_SOK)
        return -1;

    /* INTC has been initialized successfully. */
    return 0;
}

/**
 *  @b Description
 *  @n
 *      This funtion is used to test the LO Timer.
 *
 *  @param[in]  IntcInstance
 *      Timer Instance Number
 *
 *  @retval
 *      Success -   0
 *  @retval
 *      Error   -   <0
 */
static Int32 test_lo_single_shot_timer (Uint8 IntcInstance)
{
    CSL_TmrHandle               hTmr;
    CSL_TmrObj                  TmrObj;
    CSL_Status                  intStat, status;
    CSL_TmrHwSetup              hwSetup = CSL_TMR_HWSETUP_DEFAULTS;
    CSL_IntcEventHandlerRecord  EventRecord;
    CSL_IntcParam               vectId;
    Uint32                      LoadValue = 100;
    CSL_IntcHandle              tmrIntcHandle;
    CSL_TmrEnamode              TimeCountMode = CSL_TMR_ENAMODE_ENABLE;
    Uint32                      count;

    /* Clear local data structures */
    memset(&TmrObj, 0, sizeof(CSL_TmrObj));
    printf("Debug: Testing Low Timer (Unchained) in Single Shot Mode...\n");

    /**************************************************************
     ********************** INTC related code *********************
     **************************************************************/

    /* Open INTC */
    vectId = CSL_INTC_VECTID_12;
    tmrIntcHandle = CSL_intcOpen(&tmrIntcObj, CSL_GEM_TINTLN, &vectId, &intStat);
    if (tmrIntcHandle == NULL)
        return -1;

    /* Bind ISR to Interrupt */
    EventRecord.handler = (CSL_IntcEventHandler)&TimerInterruptHandler;
    EventRecord.arg     = (void *)CSL_GEM_TINTLN;
    CSL_intcPlugEventHandler(tmrIntcHandle, &EventRecord);

    /* Event Enable */
    CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTENABLE, NULL);

    /**************************************************************
     ********************** Timer related code ********************
     **************************************************************/

    /* Open the timer. */
    hTmr =  CSL_tmrOpen(&TmrObj, IntcInstance, NULL, &status);
    if (hTmr == NULL)
        return -1;

    /* Open the timer with the defaults. */
    CSL_tmrHwSetup(hTmr, &hwSetup);

    /* Stop the Timer */
    status = CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET_TIMLO, NULL);

    /* Set the timer mode to unchained dual mode */
    hwSetup.tmrTimerMode = CSL_TMR_TIMMODE_DUAL_UNCHAINED;
    CSL_tmrHwSetup(hTmr, &hwSetup);

    /* Reset the timer ISR Counter. */
    timerISRCounter = 0;

    /* Load the period register */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_LOAD_PRDLO, (void *)&LoadValue);

    /* Start the timer with one shot */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_START_TIMLO, (void *)&TimeCountMode);

    /* INTC related code */
    while (timerISRCounter != 1);

    /* Good. The timer ISR was invoked; now we wait for some time and make
     * sure that the ISR was not invoked again since this is a ONE SHOT
     * Timer. */
    for (LoadValue = 0; LoadValue < MAX_DELAY; LoadValue++);

    /* Timer ISR Counter should still be the same */
    if (timerISRCounter != 1)
        return -1;

    /* Also the LOW Count Register should remain at the value 0. */
    CSL_tmrGetTimLoCount(hTmr, &count);
    if (count != 0)
        return -1;

    /**************************************************************/

    /* Disable the interrupts. */
    CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTDISABLE, NULL);

    /* Stop the Timer */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET_TIMLO, NULL);

    /* Close the Timer and Interrupt Handles. */
    CSL_tmrClose(hTmr);
    CSL_intcClose(tmrIntcHandle);

    /* Test has been completed successfully. */
    return 0;
}

/**
 *  @b Description
 *  @n
 *      This function is used to test the HI Timer in Single Shot Mode
 *
 *  @param[in]  IntcInstance
 *      Timer Instance Number
 *
 *  @retval
 *      Success -   0
 *  @retval
 *      Error   -   <0
 */
static Int32 test_high_single_shot_timer (Uint8 IntcInstance)
{
    CSL_TmrHandle               hTmr;
    CSL_TmrObj                  TmrObj;
    CSL_Status                  status;
    CSL_TmrHwSetup              hwSetup = CSL_TMR_HWSETUP_DEFAULTS;
    CSL_IntcEventHandlerRecord  EventRecord;
    CSL_IntcParam               vectId;
    CSL_IntcHandle              tmrIntcHandle;
    Uint32                      LoadValue = 100;
    CSL_TmrEnamode              TimeCountMode = CSL_TMR_ENAMODE_ENABLE;
    Uint32                      count;

    /* Clear local data structures */
    memset(&TmrObj, 0, sizeof(CSL_TmrObj));
    printf("Debug: Testing High Timer (Unchained) in Single Shot Mode...\n");

    /**************************************************************
     ********************** INTC related code *********************
     **************************************************************/

    /* Open INTC */
    vectId = CSL_INTC_VECTID_13;
    tmrIntcHandle = CSL_intcOpen(&tmrIntcObj, CSL_GEM_TINTHN, &vectId, NULL);
    if (tmrIntcHandle == NULL)
        return -1;

    /* Bind ISR to Interrupt */
    EventRecord.handler = (CSL_IntcEventHandler)&TimerInterruptHandler;
    EventRecord.arg     = (void *)CSL_GEM_TINTLN;
    CSL_intcPlugEventHandler(tmrIntcHandle, &EventRecord);

    /* Event Enable */
    CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTENABLE, NULL);

    /**************************************************************
     ********************** Timer related code ********************
     **************************************************************/

    /* Open the timer. */
    hTmr =  CSL_tmrOpen(&TmrObj, IntcInstance, NULL, &status);
    if (hTmr == NULL)
        return -1;

    /* Open the timer with the defaults. */
    CSL_tmrHwSetup(hTmr, &hwSetup);

    /* Stop the Timer */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET_TIMHI, NULL);

    /* Set the timer mode to unchained dual mode */
    hwSetup.tmrTimerMode = CSL_TMR_TIMMODE_DUAL_UNCHAINED;
    CSL_tmrHwSetup(hTmr, &hwSetup);

    /* Reset the timer ISR Counter. */
    timerISRCounter = 0;

    /* Load the period register */
    status = CSL_tmrHwControl(hTmr, CSL_TMR_CMD_LOAD_PRDHI, (void *)&LoadValue);

    /* Start the timer in SINGLE SHOT Mode. */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_START_TIMHI, (void *)&TimeCountMode);

    /* Wait for the timer interrupts to fire...*/
    while (timerISRCounter != 1);

    /* Good. The timer ISR was invoked; now we wait for some time and make
     * sure that the ISR was not invoked again since this is a ONE SHOT
     * Timer. */
    for (LoadValue = 0; LoadValue < MAX_DELAY; LoadValue++);

    /* Timer ISR Counter should still be the same */
    if (timerISRCounter != 1)
        return -1;

    /* Also the HIGH Count Register should remain at the value 0. */
    CSL_tmrGetTimHiCount(hTmr, &count);
    if (count != 0)
        return -1;

    /**************************************************************/

    /* Disable the events. */
    CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTDISABLE, NULL);

    /* Stop the Timer */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET_TIMHI, NULL);

    /* Close the Tmr and Interrupt handles. */
    CSL_tmrClose(hTmr);
    CSL_intcClose(tmrIntcHandle);

    /* Test has completed successfully. */
    return 0;
}

/**
 *  @b Description
 *  @n
 *      This function is used to test the HI Timer in Continuous Mode
 *
 *  @param[in]  IntcInstance
 *      Timer Instance Number
 *
 *  @retval
 *      Success -   0
 *  @retval
 *      Error   -   <0
 */
static Int32 test_high_continuous_timer (Uint8 IntcInstance)
{
    CSL_TmrHandle               hTmr;
    CSL_TmrObj                  TmrObj;
    CSL_Status                  status;
    CSL_TmrHwSetup              hwSetup = CSL_TMR_HWSETUP_DEFAULTS;
    CSL_IntcEventHandlerRecord  EventRecord;
    CSL_IntcParam               vectId;
    CSL_IntcHandle              tmrIntcHandle;
    Uint32                      LoadValue = 1000;
    CSL_TmrEnamode              TimeCountMode = CSL_TMR_ENAMODE_CONT;
    Uint32                      count;

    /* Clear local data structures */
    memset(&TmrObj, 0, sizeof(CSL_TmrObj));
    printf("Debug: Testing High Timer (Unchained) in Continuous Mode....\n");

    /**************************************************************
     ********************** INTC related code *********************
     **************************************************************/

    /* Open INTC */
    vectId = CSL_INTC_VECTID_13;
    tmrIntcHandle = CSL_intcOpen(&tmrIntcObj, CSL_GEM_TINTHN, &vectId, NULL);
    if (tmrIntcHandle == NULL)
        return -1;

    /* Bind ISR to Interrupt */
    EventRecord.handler = (CSL_IntcEventHandler)&TimerInterruptHandler;
    EventRecord.arg     = (void *)CSL_GEM_TINTLN;
    CSL_intcPlugEventHandler(tmrIntcHandle, &EventRecord);

    /* Event Enable */
    CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTENABLE, NULL);

    /**************************************************************
     ********************** Timer related code ********************
     **************************************************************/

    /* Open the timer. */
    hTmr =  CSL_tmrOpen(&TmrObj, IntcInstance, NULL, &status);
    if (hTmr == NULL)
        return -1;

    /* Open the timer with the defaults. */
    CSL_tmrHwSetup(hTmr, &hwSetup);

    /* Stop the Timer */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET_TIMHI, NULL);

    /* Set the timer mode to unchained dual mode */
    hwSetup.tmrTimerMode = CSL_TMR_TIMMODE_DUAL_UNCHAINED;
    CSL_tmrHwSetup(hTmr, &hwSetup);

    /* Reset the timer ISR Counter. */
    timerISRCounter = 0;

    /* Load the period register */
    status = CSL_tmrHwControl(hTmr, CSL_TMR_CMD_LOAD_PRDHI, (void *)&LoadValue);

    /* Start the timer in CONTINUOUS Mode. */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_START_TIMHI, (void *)&TimeCountMode);

    /* Wait for the timer interrupts to fire...*/
    while (timerISRCounter <= 5);

    /* Since the HIGH Counter is operating in Continuous Mode; the value here should
     * be non-zero. Though there is a small probability that the value here could be 0. */
    CSL_tmrGetTimHiCount(hTmr, &count);
    if (count == 0)
    {
        /* Taking into account the small probability; lets confirm out again.
         * This time for sure the value should be non-zero. */
        CSL_tmrGetTimHiCount(hTmr, &count);
        if (count == 0)
            return -1;
    }

    /**************************************************************/

    /* Disable the events. */
    CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTDISABLE, NULL);

    /* Stop the Timer */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET_TIMHI, NULL);

    /* Close the Tmr and Interrupt handles. */
    CSL_tmrClose(hTmr);
    CSL_intcClose(tmrIntcHandle);

    /* Test has completed successfully. */
    return 0;
}

/**
 *  @b Description
 *  @n
 *      This function is used to test the timers while operating in CHAINED mode.
 *
 *  @param[in]  IntcInstance
 *      Timer Instance Number
 *
 *  @retval
 *      Success -   0
 *  @retval
 *      Error   -   <0
 */
static Int32 test_chained_timer (Uint8 IntcInstance)
{
    CSL_TmrHandle               hTmr;
    CSL_TmrObj                  TmrObj;
    CSL_Status                  status;
    CSL_IntcEventHandlerRecord  EventRecord;
    CSL_IntcHandle              tmrIntcHandle;
    CSL_IntcParam               vectId;
    Uint32                      LoadValue = 100;
    Uint32                      LoadValue1 = 0;
    Uint8                       preScalValue = 0;
    CSL_TmrHwSetup              hwSetup = CSL_TMR_HWSETUP_DEFAULTS;
    CSL_TmrEnamode              TimeCountMode = CSL_TMR_ENAMODE_ENABLE;

    /* Clear local data structures */
    memset(&TmrObj, 0, sizeof(CSL_TmrObj));
    printf("Debug: Testing Timer (Chained) in Single Shot Mode....\n");

    /**************************************************************
     ********************** INTC related code *********************
     **************************************************************/

    /* Open INTC */
    vectId = CSL_INTC_VECTID_12;
    tmrIntcHandle = CSL_intcOpen(&tmrIntcObj, CSL_GEM_TINTLN, &vectId, NULL);
    if (tmrIntcHandle == NULL)
        return -1;

    /* Bind ISR to Interrupt */
    EventRecord.handler = (CSL_IntcEventHandler)&TimerInterruptHandler;
    EventRecord.arg     = (void *)CSL_GEM_TINTLN;
    CSL_intcPlugEventHandler(tmrIntcHandle, &EventRecord);

    /* Event Enable */
    CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTENABLE, NULL);

    /**************************************************************
     ********************** Timer related code ********************
     **************************************************************/

    /* Open the timer. */
    hTmr =  CSL_tmrOpen(&TmrObj, IntcInstance, NULL, &status);
    if (hTmr == NULL)
        return -1;

    /* Open the timer with the defaults. */
    CSL_tmrHwSetup(hTmr, &hwSetup);

    /* Reset the Timer */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET64, NULL);

    /* Set the timer mode to dual chained mode */
    hwSetup.tmrTimerMode = CSL_TMR_TIMMODE_DUAL_CHAINED;
    CSL_tmrHwSetup(hTmr, &hwSetup);

    /* Reset the timer ISR Counter. */
    timerISRCounter = 0;

    /* Load the prescale value */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_LOAD_PSCHI, (void *)&preScalValue);

    /* Load the period register */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_LOAD_PRDLO, (void *)&LoadValue);

    /* Load the period register */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_LOAD_PRDHI, (void *)&LoadValue1);

    /* Start the timer with SINGLE SHOT Mode. */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_START64, (void *)&TimeCountMode);

    /* Wait for the timer interrupts to fire...*/
    while (timerISRCounter != 1);

    /* Good. The timer ISR was invoked; now we wait for some time and make
     * sure that the ISR was not invoked again since this is a ONE SHOT
     * Timer. */
    for (LoadValue = 0; LoadValue < MAX_DELAY; LoadValue++);

    /* Timer ISR Counter should still be the same */
    if (timerISRCounter != 1)
        return -1;

    /**************************************************************/

    /* Disable the events. */
    CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTDISABLE, NULL);

    /* Stop the Timer */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET64, NULL);

    /* Close the Tmr and interrupt handles */
    CSL_tmrClose(hTmr);
    CSL_intcClose(tmrIntcHandle);

    /* Test has completed successfully. */
    return 0;
}

/**
 *  @b Description
 *  @n
 *      This function is used to test the General Purpose Timer.
 *
 *  @param[in]  IntcInstance
 *      Timer Instance Number
 *
 *  @retval
 *      Success -   0
 *  @retval
 *      Error   -   <0
 */
static Int32 test_gp_timer (Uint8 IntcInstance)
{
    CSL_IntcHandle              tmrIntcHandle;
    CSL_TmrHandle               hTmr;
    CSL_TmrObj                  TmrObj;
    CSL_IntcEventHandlerRecord  EventRecord;
    CSL_IntcParam               vectId;
    CSL_Status                  status;
    CSL_TmrHwSetup              hwSetup = CSL_TMR_HWSETUP_DEFAULTS;
    CSL_TmrEnamode              TimeCountMode = CSL_TMR_ENAMODE_ENABLE;
    Uint32                      delayCount;

    /* Clear local data structures */
    memset(&TmrObj, 0, sizeof(CSL_TmrObj));
    printf("Debug: Testing 64bit Timer in Single Shot Mode...\n");

    /**************************************************************
     ********************** INTC related code *********************
     **************************************************************/

    /* Open INTC */
    vectId = CSL_INTC_VECTID_12;
    tmrIntcHandle = CSL_intcOpen(&tmrIntcObj, CSL_GEM_TINTLN, &vectId, NULL);

    /* Bind ISR to Interrupt */
    EventRecord.handler = (CSL_IntcEventHandler)&TimerInterruptHandler;
    EventRecord.arg     = (void *)CSL_GEM_TINTLN;
    CSL_intcPlugEventHandler(tmrIntcHandle, &EventRecord);

    /* Event Enable */
    CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTENABLE, NULL);

    /**************************************************************
     ********************** Timer related code ********************
     **************************************************************/

    /* Open the timer. */
    hTmr = CSL_tmrOpen(&TmrObj, IntcInstance, NULL, &status);
    if (hTmr == NULL)
        return -1;

    /* Set the timer mode to 64bit GP Timer Mode and set the PRD registers */
    hwSetup.tmrTimerMode     = CSL_TMR_TIMMODE_GPT;
    hwSetup.tmrTimerPeriodLo = 0x0f;
    hwSetup.tmrTimerPeriodHi = 0x00;
    CSL_tmrHwSetup(hTmr, &hwSetup);

    /* Reset the timer ISR Counter. */
    timerISRCounter = 0;

    /* Reset the Timer */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET64, NULL);

    /* Start the timer in SINGLE SHOT Mode. */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_START64, (void *)&TimeCountMode);

    /* INTC related code */
    while (timerISRCounter != 1);

    /* Good. The timer ISR was invoked; now we wait for some time and make
     * sure that the ISR was not invoked again since this is a ONE SHOT
     * Timer. */
    for (delayCount = 0; delayCount < MAX_DELAY; delayCount++);

    /* Timer ISR Counter should still be the same */
    if (timerISRCounter != 1)
        return -1;

    /**************************************************************/

    /* Disable the interrupts. */
    CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTDISABLE, NULL);

    /* Stop the Timer */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET64, NULL);

    /* Close the Tmr and interrupt handles */
    CSL_tmrClose(hTmr);
    CSL_intcClose(tmrIntcHandle);

    /* Test has been completed successfully. */
    return 0;
}



void main(void)
{
	LONG DDR_TEST_result;
	LONG NanaTestResult;
	/* main */
	DDR_TEST_result = DDR_TEST();
    NanaTestResult = test_nand_device();


		printf ("**************************************************\n");
	    printf ("****************** Timer Testing  ****************\n");
	    printf ("**************************************************\n");

	    /* Initialize the INTC Module. */
	    if (intc_init() < 0)
	    {
	        printf ("Error: Initialization of the INTC module failed\n");
	        return;
	    }

	    /* Initialize timer CSL module */
	    CSL_tmrInit(NULL);

	    /* Start the testing for the LOW Timer. */
	    if (test_lo_single_shot_timer(CSL_TMR_0) < 0)
	    {
	        printf("Error: Testing Low Timer (Unchained) in Single Shot Mode FAILED\n");
	        return;
	    }
	    printf("Debug: Testing Low Timer (Unchained) in Single Shot Mode Passed\n");
	    if (test_lo_single_shot_timer(CSL_TMR_1) < 0)
	    {
	        printf("Error: Testing Low Timer (Unchained) in Single Shot Mode FAILED\n");
	        return;
	    }
	    printf("Debug: Testing Low Timer (Unchained) in Single Shot Mode Passed\n");
	    if (test_lo_single_shot_timer(CSL_TMR_2) < 0)
	    {
	        printf("Error: Testing Low Timer (Unchained) in Single Shot Mode FAILED\n");
	        return;
	    }
	    printf("Debug: Testing Low Timer (Unchained) in Single Shot Mode Passed\n");
	    if (test_lo_single_shot_timer(CSL_TMR_3) < 0)
	    {
	        printf("Error: Testing Low Timer (Unchained) in Single Shot Mode FAILED\n");
	        return;
	    }
	    printf("Debug: Testing Low Timer (Unchained) in Single Shot Mode Passed\n");
	    if (test_lo_single_shot_timer(CSL_TMR_4) < 0)
	    {
	        printf("Error: Testing Low Timer (Unchained) in Single Shot Mode FAILED\n");
	        return;
	    }
	    printf("Debug: Testing Low Timer (Unchained) in Single Shot Mode Passed\n");
	    if (test_lo_single_shot_timer(CSL_TMR_5) < 0)
	    {
	        printf("Error: Testing Low Timer (Unchained) in Single Shot Mode FAILED\n");
	        return;
	    }
	    printf("Debug: Testing Low Timer (Unchained) in Single Shot Mode Passed\n");
	    if (test_lo_single_shot_timer(CSL_TMR_6) < 0)
	    {
	        printf("Error: Testing Low Timer (Unchained) in Single Shot Mode FAILED\n");
	        return;
	    }
	    printf("Debug: Testing Low Timer (Unchained) in Single Shot Mode Passed\n");
	    if (test_lo_single_shot_timer(CSL_TMR_7) < 0)
	    {
	        printf("Error: Testing Low Timer (Unchained) in Single Shot Mode FAILED\n");
	        return;
	    }

	    printf("Debug: Testing Low Timer (Unchained) in Single Shot Mode Passed\n");





   mbdr_dsp_boot_loader_header[0] = mbdr_dsp_boot_loader_header_init;


  /* calls helpful initialization manager */
  debug_main_start_count++;
  mbdr_dsp_common_main_init_manager(&mbdr_dsp_main_init_manager_params);

  mbdr_dsp_boot_loader_never_reach();
  mbdr_dsp_boot_loader_never_reach_2();
  mbdr_dsp_boot_loader_never_reach_3();

}/* main */
