/** @file sys_main.c 
*   @brief Application main file
*   @date 9.Sep.2014
*   @version 04.01.00
*
*   This file contains an empty main function,
*   which can be used for the application.
*/

/* (c) Texas Instruments 2009-2014, All rights reserved. */

/* USER CODE BEGIN (0) */
/* USER CODE END */

/* Include Files */

#include "sys_common.h"

/* USER CODE BEGIN (1) */
#include "sys_mpu.h"
#include "reg_ecap.h"
#include "system.h"

#include "ti_fee.h"


#include "rti.h"


#include "sci.h"
#include "reg_sci.h"
#include "bl_config.h"
#include "bl_uart.h"
#include "bl_check.h"
#include "sci_common.h"
#include "bl_led_demo.h"
/* USER CODE END */

/** @fn void main(void)
*   @brief Application main function
*   @note This function is empty by default.
*
*   This function is called after startup.
*   The user can use this function to implement the application.
*/

/* USER CODE BEGIN (2) */
//#if defined (SPI_ENABLE_UPDATE) || defined(UART_ENABLE_UPDATE) || defined(CAN_ENABLE_UPDATE)
uint32_t g_ulTransferSize;
uint32_t g_ulTransferAddress;
uint32_t g_pulDataBuffer[BUFFER_SIZE];
uint32_t g_pulUpdateSuccess[] = {0x5A5A5A5A, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
uint32_t g_ulUpdateStatusAddr = 0x07FF0;
uint32_t g_ulVectorTable = 0x8000000;
uint32_t g_ulUpdateBufferSize = 32;  //32 bytes or 8 32-bit words

#define E_PASS     		0
#define E_FAIL     		0x1U
#define E_TIMEOUT  		0x2U

uint8_t *g_pucDataBuffer;



sint16 iTimerForEEPROM = -1;
uint16 Status;
/* USER CODE END */

void main(void)
{
/* USER CODE BEGIN (3) */
	uint32 fnRetValue;
	_mpuInit_();


	sciInit();
	sciSetBaudrate(sciREG, 57600);
	fnRetValue = 1;//CheckForceUpdate();
    if ( !fnRetValue )
    {
#ifdef DEBUG_MSG_L3
    	UART_putString(UART, "\r Jump to application...  ");
#endif
        g_ulTransferAddress = (uint32_t)APP_START_ADDRESS;
        ((void (*)(void))g_ulTransferAddress)();
    }


	UpdaterUART();

	g_ulTransferAddress = (uint32_t)APP_START_ADDRESS;
	((void (*)(void))g_ulTransferAddress)();
/* USER CODE END */
}

/* USER CODE BEGIN (4) */

/* USER CODE END */
