// FILE:  Main.c
//
// TITLE: MetroDevice
#include "DSP281x_Device.h"     // DSP281x Headerfile Include File
#include "DSP281x_Examples.h"   // DSP281x Examples Include File
#include "Flash281x_API_Library.h"
#include "Event_lib.h"

//===========================================================================
#ifdef __cplusplus
#pragma CODE_SECTION("main_ptr_section");
#else
#pragma CODE_SECTION(main_ptr,"main_ptr_section");
#endif
void main_ptr(void)
{
//ÍÀÑÒÐÎÉÊÀ ÏÐÎÖÅÑÑÎÐÀ È ÅÃÎ ÊÎÌÏÎÍÅÍÒÎÂ
   	InitSysCtrl();
   	InitGpio();  
   	InitPieCtrl();
// Disable CPU interrupts andunsigned short
   	IER = 0x0000;
   	IFR = 0x0000;
   	InitPieVectTable();

   	SysCtrlRegs.SCSR = 0; // watchdog The WDRST output signal

   	DSP281x_MemCopy(&RamfuncsRunStart, &RamfuncsLoadStart, &RamfuncsLoadEnd - &RamfuncsLoadStart);
   	InitFlash();

   	EINT;          // Enable Global interrupt INTM
   	ERTM;          // Enable Global realtime interrupt DBGM
	//*****************************************************************

	DELAY_US(3000);

	EALLOW;
	SysCtrlRegs.WDCR 	= 0x002F;
	SysCtrlRegs.WDKEY 	= 0x0055;
	SysCtrlRegs.WDKEY 	= 0x00AA;
	EDIS;

	ModBusEventsV1_t ModBusEventsV1;

	ModBusEventsV1.OutputRegs_ptr->Fram.CriticalValues[1] = 10.0f; 	//TODO PopUp work!

	ModBusEventsV2_t ModBusEventsV2;

	ModBusEventsV2.Fram.OutputBits.isActive = true;					// TODO  PopUp Do not work! But compile well!
	ModBusEventsV2.DefaultsApply();

	EventsFram_t EventsFram;
	EventsSram_t EventsSram;

	EventsFram.OutputBits.isActive 	= true;  						//TODO PopUp work!
	EventsSram.InputBits.isWarning	= false;						//TODO PopUp work!

	for(;;)
	{
		KickDog();
	}
}

//===========================================================================
// No more.
//===========================================================================
#ifdef __cplusplus
#pragma CODE_SECTION("bootloader_main");
#else
#pragma CODE_SECTION(main,"bootloader_main");
#endif

void main(void)
{
	//Bootloader_main();
	main_ptr();
}
