#include "DSP281x_Examples.h"   // DSP281x Examples Include File
#include "DSP281x_SWPrioritizedIsrLevels.h"   // DSP281x Examples Include File
#include "DSP281x_Device.h"

#include <edrk_main.h>
#include "RS_Functions.h"
#include "xp_project.h"
#include "x_wdog.h"

void main()
{
	// Step 1. Initialize System Control:
	// PLL, WatchDog, enable Peripheral Clocks
	// This example function is found in the DSP281x_SysCtrl.c file.
    InitSysCtrl();

	XintfZone0_Timing();//Xilinx Zone
	XintfZone6_And7_Timing();//Flash Zone
	XintfZone2_Timing();//External RAM Zone

	// Step 2. Initalize GPIO:
	// This example function is found in the DSP281x_Gpio.c file and
	// illustrates how to set the GPIO to it's default state.
	// InitGpio();  // Skipped for this example
		
	// For this example use the following configuration:
	//Gpio_select();
	
	// Step 3. Clear all interrupts and initialize PIE vector table:
	// Disable CPU interrupts
	DINT;

//	status_interrupts = __disable_interrupts();
	
	// Initialize PIE control registers to their default state.
	// The default state is all PIE interrupts disabled and flags
	// are cleared.
	// This function is found in the DSP281x_PieCtrl.c file.
	
	InitPieCtrl();

//	__disable_interrupts();
	
	// Disable CPU interrupts and clear all CPU interrupt flags:
	IER = 0x0000;
	IFR = 0x0000;
	
	// Initialize the PIE vector table with pointers to the shell Interrupt 
	// Service Routines (ISR).
	// This will populate the entire table, even if the interrupt
	// is not used in this example.  This is useful for debug purposes.
	// The shell ISR routines are found in DSP281x_DefaultIsr.c.
	// This function is found in DSP281x_PieVect.c.
	
	InitPieVectTable();
	
	// Step 4. Initialize all the Device Peripherals:
	// This function is found in DSP281x_InitPeripherals.c
	// InitPeripherals(); // Not required for this example
		
	FlashInit();

	SetupLedsLine();
//while(1)
{
	i_led2_on_off(0);
	i_led1_on_off(1);
	DELAY_US(500000);
	i_led2_on_off(1);
	i_led1_on_off(0);
	DELAY_US(500000);
	i_led2_on_off(0);
	i_led1_on_off(0);
}


	RS232_TuneUp(RS232_SPEED_A, RS232_SPEED_B);

    KickDog();

    // ��������� �������, ��� ���!
    edrk_init_before_main();

    // ��������� ����������, ���� ��������� RS232
    project.enable_all_interrupt();


    DINT;
    i_led2_on_off(1);
    i_led1_on_off(1);
    DELAY_US(500000);
    i_led2_on_off(0);
    i_led1_on_off(0);
    DELAY_US(500000);
    i_led2_on_off(1);
    i_led1_on_off(1);
    DELAY_US(500000);
    i_led2_on_off(0);
    i_led1_on_off(0);
    DELAY_US(500000);
    project.enable_all_interrupt();

    // ��������� ������� ����� ����������� ������
    edrk_init_before_loop();

    // ��� �������� ���� main
	for(;;)
   	{
	    // ������ � ������, ������ ���������

	    edrk_go_main();
	    // ����� �� rs232
   		RS232_WorkingWith(1,0,0);
//   		static int fff=0;
//   		if (fff)
//   		{
//   		    Answer(&rs_a, CMD_RS232_POKE);
//   		    fff = 0;
//   		}

   	}


}