/**
 * app_restart.c
 * 
 *
 * Copyright (c) 2012 Texas Instruments Incorporated ALL RIGHTS RESERVED
 *
*/

#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/family/arm/a8/Mmu.h>
#include <ti/ndk/inc/stkmain.h>
#include <ti/ndk/inc/netctrl/netctrl.h>
#include <ti/sysbios/knl/Task.h>

#include "osdrv_ndkdeviceconfig.h"
#include "app_restart.h"
#include "icss_nimu_eth.h"

/* ========================================================================== */
/*                          Function Definitions                              */
/* ========================================================================== */

/**
 *  \name restart_application
 *  \brief The function restarts the application
 *
 *  \param none
 *  \return none
 *
 */
void restart_application()
{

	NC_NetStop(0);

#ifdef USE_CPSW_DRIVER
	while(!ShutdownCompleteCheck())
#else
	while(GetNdkStatus(0))
#endif
	{
		Task_sleep(1);
	}
	BIOS_exit(100);
}


/**
 *  \name app_exit_handler
 *  \brief Exit handler for the application
 *
 *  \param var 
 *  \return none
 *
 */
void app_exit_handler(int var)
{

	void (*appEntry)();
	if(var == 100)
	{
		appEntry = (void (*)(void))0x80000000;
		Mmu_disable();
		(*appEntry)();
	}
}
