fork

Dependencies:   mbed

Fork of LG by igor Apu

main.c

Committer:
igor_v
Date:
2016-01-30
Revision:
0:8ad47e2b6f00
Child:
3:ed8744c5f67a

File content as of revision 0:8ad47e2b6f00:


/****************************************Copyright (c)****************************************************
**--------------File Info---------------------------------------------------------------------------------
** File name:           main.c
** Last modified Date:  2011-10-24
** Last Version:        V1.00
** Descriptions:        The main() function
**
**--------------------------------------------------------------------------------------------------------
** Created by:          Electrooptica Incorp.
** Created date:        2011-08-22
** Version:             V1.00
** Descriptions:        
**--------------------------------------------------------------------------------------------------------       
*********************************************************************************************************/



#include "Global.h"



//#include <math.h>



/******************************************************************************
**   Main Function  main()
******************************************************************************/
extern uint32_t CMD_Mode;
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

				int i1 =0;
//extern unsigned int Buff_QEI[256];
volatile unsigned int IRQ_Counter=0;
volatile uint32_t timer1_counter = 0;
int temp111=0,temp=0;
int y = 0;
int CuruAngleOld=0;
unsigned int  LightUpCount,BackLightCount,secPuls,CountBI,CmmandIn,tt,th;


unsigned int paramV;




void Led_init()
{
	 LPC_PINCON->PINSEL0 = (0x00<<28);
	 LPC_GPIO1->FIODIR   = (0x1<<30);
	 LPC_PINCON->PINMODE0 = (0x3<<28);
	// LPC_GPIO1->FIOSET = (0x0<<30);
	// LPC_GPIO0->FIOSET = (1<<4);
}
int flag=0,  TIME=0,t=0, Sec=0,tmpSec=0,SEC=0, mSec=0;
int tempsec=0;
float DACF, K_DAC;
void Led_Blink()
{
	
	if (flag == 0)
	{
	LPC_GPIO1->FIOSET = (0x1<<30);
		flag=1;
	}
	else
	{
		flag =0;
		LPC_GPIO1->FIOCLR = (0x01<<30);
	}
}

long LED_TEMP=0;



int main (void)
{
 
{ 
	K_DAC=65535.0/(65535.0+(deltaDAC+deltaDAC/2));
  K_DAC=0.8;
	Main.Firmware_Version=0x15;
	Main.GLD_Serial = 0x20;
	Main.My_Addres=0;
	LightUpCount=1000;
	BackLightCount=5000;
	secPuls=0;
  Pulse_midl = 0;
  PulseHalf = 0;
  CuruAngle = 0;
	Spi.DAC_A=0x7fff;
	Spi.DAC_B=0x7fff;
  //�������������
  SystemInit();  // ������������� �������
  Led_init();

	///*
	//���������������� ������� �������
  LPC_PINCON->PINSEL0 &= ~(3<<8);		//e. P0.4 is GPIO pin (������ ( 00 ) � 9:8 ��� PISEL0    ����� P0.4 ��� GPIO)
  LPC_PINCON->PINMODE0 |= (3<<8);		//e. P0.4 is GPIO pin (������ ( 11 ) � 9:8 ��� PINMODE0  "��� ��������� �������������� ���������")
  LPC_GPIO0->FIODIR   |= (1<<4);		//e. P0.4 is output   (������ ( 1 ) �  5  ��� FIODIR    ����� P0.4 ��� �����)
  LightUpON		//e. P0.4 is output   (������ ( 1 ) �  5  ��� CLR       ������������� �� P0.4 ������ ������� �������)
  /*
	LPC_PINCON->PINSEL0 &= ~(3<<10);		//e. P0.4 is GPIO pin (������ ( 00 ) � 9:8 ��� PISEL0    ����� P0.4 ��� GPIO)
  LPC_PINCON->PINMODE0 |= (3<<10);		//e. P0.4 is GPIO pin (������ ( 11 ) � 9:8 ��� PINMODE0  "��� ��������� �������������� ���������")
  LPC_GPIO0->FIODIR   |= (1<<5);		//e. P0.4 is output   (������ ( 1 ) �  5  ��� FIODIR    ����� P0.4 ��� �����)
  LPC_GPIO0->FIOCLR   |= (1<<5);		//e. P0.4 is output   (������ ( 1 ) �  5  ��� CLR       ������������� �� P0.4 ������ ������� �������)*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
	LPC_PINCON->PINSEL3   = (0x00<<18);		//e. P1.25 is GPIO pin 
  LPC_PINCON->PINMODE3 |= (3<<18);		//e. P1.25  (��������e �������������� ���������")
  LPC_GPIO1->FIODIR    |= (1<<25);		//e. P0.5 is output   (������ ( 1 ) �  5  ��� FIODIR    ����� P0.5 ��� �����)
  LPC_GPIO1->FIOCLR    |= (1<<25);
	
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	LPC_PINCON->PINSEL3   = (0x00<<24);		//e. P1.28 is GPIO pin 
  LPC_PINCON->PINMODE3 |= (3<<24);		//e. P1.28 is GPIO pin (������ ( 11 ) � ��� PINMODE0  "��� ��������� �������������� ���������")
  LPC_GPIO1->FIODIR    |= (1<<28);		//e. P1.28 is output   (������ ( 1 ) �  5  ��� FIODIR    ����� P0.5 ��� �����)
  LPC_GPIO1->FIOCLR    |= (1<<28);
//  init_timer(TIME_INTERVAL ); // 10ms	
 // enable_timer1();
///������������� ���������
	LPC_PINCON->PINSEL2   = (0x00<<24);		//e. P2.12 is GPIO pin 
  LPC_PINCON->PINMODE3 |= (3<<24);		//e. P1.28 is GPIO pin (������ ( 11 ) � ��� PINMODE0  "��� ��������� �������������� ���������")
  LPC_GPIO2->FIODIR    |= (1<<12);		//e. P1.28 is output   (������ ( 1 ) �  5  ��� FIODIR    ����� P0.5 ��� �����)
  LPC_GPIO2->FIOCLR    |= (1<<12);
  
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
/*
  //���������������� ������� ������� ��������� ���� (������ �� 80 ���� ������ 81)
  LPC_PINCON->PINSEL0   = (0x00<<10);		//e. P0.5 is GPIO pin (������ ( 00 ) � 11:10 ��� PISEL0    ����� P0.5 ��� GPIO)
  LPC_PINCON->PINMODE0 |= (3<<10);		//e. P0.5 is GPIO pin (������ ( 11 ) � 11:10 ��� PINMODE0  "��� ��������� �������������� ���������")
  LPC_GPIO0->FIODIR    |= (1<<5);		//e. P0.5 is output   (������ ( 1 ) �  5  ��� FIODIR    ����� P0.5 ��� �����)
  LPC_GPIO0->FIOCLR    |= (1<<5);		//e. P0.5 is output   (������ ( 1 ) �  5  ��� CLR       ������������� �� P0.5 ������ ������� �������)
	*/
  DMA_Init();           // ������������� DMA
  FlashDMA_Init(); 			// �������� ���������� � ����
  
  SystemCoreClockUpdate();  // ������ ��������� ������� ��� UART.
  UARTInit();				        // �������������  UART0 �� �������� 38400.
  UART1_Init();             // �������������  UART1 �� �������� 38400.
	
	
  DAC_ADC_Exchange_Init();  // �������������  ������ ��� � ���.
	DACInit();                // ������������� ���.
  SOI_Init(); 			      	// ������������� ������������� ��������.
 
  IntLatch_Init();			// ������������� ���������� �������.
  ExtLatch_Init();			// ������������� ������� �������.

//----------------debug------------------------- 
  //LPC_GPIO2->FIODIR = 0x5C;		// P2.0...P2.7 defined as Outputs 
  //LPC_GPIO2->FIOCLR = 0x5C;		// turn off all the LEDs 
//----------------debug------------------------- 
 

    LoadFlashParam(FromFLASH); 	//�������� ����������.
    UART_DMA_Init();			    	//������������� DMA ��� UART.
    G_Photo_Init();				      //������������� ���������� I2C ��� �������������.
    Out_G_photo(60, 60);        //������ � ����� ������� �������� �� ������� ������ (60,60) � ��������� ����� ������ �������� � ������� ����.
//  WDTInit();


  	open_all_loops();                          //#define open_all_loops()			RgConA   = 0	(�������� ������� ���������� ���������� (0 - ��������, 1 - ���������)).
  	Output.Str.HF_reg = Device_blk.Str.HF_min; //HFO output voltage = ������������ ���������� �� ���.
   	init_PLC();                                //������������� ���(����������� ���������)
   	init_Dither_reg();                         //������������� ������������
  	RgConB = RATE_VIBRO_1; // �������������� ������� ���������� = �������� �������������� ����� ������� ������.��������(#define RATE_VIBRO_1	0x0001)
	  init_Vibro();
		init_timer(TIME_INTERVAL ); // 10ms	
    enable_timer1();
    Init_TIM2();
    enable_timer2();
    close_all_loops();
		
		LPC_GPIO0->FIOCLR = (1<<5);
 }	 

 
	Pulse_8Point = 0;
	Pulse_16Point = 0;
	Pulse_32Point = 0;

  Temp_AMP=0;
	Temp_ADC_2=0;
	Temp_ADC_3=0;
	Temp_ADC_4=0;
	Temp_ADC_5=0;
     

 
for (y = 0; y < 256; y++ ) 
 {
	 Buff_16Point [y] = 0xffff;
	 Buff_8Point [y] = 0xffff;
	 Buff_32Point [y] = 0xffff;
	    Buff_ADC_1	[y] = 0;// ���� ���.
	    Buff_ADC_2	[y] = 0;
			Buff_ADC_3	[y] = 0;
			Buff_ADC_4	[y] = 0;
			Buff_ADC_5	[y] = 0;
	
 }

 

SendToBuffStr ("\n\r ....... ");
OutBufConCount =0;
 WriteCon("\n\r ...WriteCon1.... ");
 do //�������� ����.
	  {
		

		if (OutBufConCount)  OutBufConCount--;	
		Concol ();
 //   Concol1 ();
     Read_CMD();
	
			//	VibroOut();

  
	   	if(Time_1kHz>100)
			{
				
        SEC++;
				if(Rate_Flag==1&&SEC>500)
				{
				SEC-=500;
				CMD_Rate();
				}
		  	
				Time_1kHz-=100;
				if(LightUpCount){LightUpCount--;LightUpON}
				
				else
				{
					LightUpOFF;
				}
				if(BackLightCount){BackLightCount--;BackLightON}
				else
				{
					BackLightOFF;
				}
			}
			ButtonLightUP();
		  //Device_blk.Str.
    TakeFromBuff();
			
	    //���������� �������.
  
	    // paramV=TakeParam(1);

	



			if (LPC_PWM1->IR & 0x0001) // ���� � �������� ���������� ���1 (������� PWM1IR) ���� ���� ���������� ���������� �������� � ����� (lim0 ?) ��:
	   { 	
	/*	ResetCS(ADC);					  	 //prepare ADC for sampling
		SetDAC(DAC);		
    LPC_GPIO2->FIOSET |= 0x0000004;		// turn on the LED
    LPC_GPIO2->FIOSET |= 0x0000004;		// turn on the LED
    LPC_GPIO2->FIOSET |= 0x0000004;		// turn on the LED			 
		SetCS(ADC);					    		//start ADC sampling
		ResetDAC(DAC);  	    			//start DAC prepearing for writing

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

              secPuls++;
        			tmpSec++;
			       	mSec++;  
						
		i1++;
		if(i1>10000)
		//if(CountV31>30)	
			{
			i1=0;
					/*	
					SendToBuffStr("\n\r");
				 	//	if (Buff_ADC_1	[y] > 65535)SendToBuffStr(" 0 "); else SendToBuffStr(" 1 ");
				  sprintf (BuffTemp,"<%05d> <%05d> <%05d> <%05d> <%05d>", Temp_AMP>>5,Temp_ADC_2>>5,Temp_ADC_3>>5,Temp_ADC_4>>5,Temp_ADC_5>>5); 
				 // sprintf (BuffTemp,"<%07d> <%07d> <%07d> <%07d> <%07d>", Spi.ADC1,Spi.ADC2,Spi.ADC3,Spi.ADC4,Spi.ADC5); 
						SendToBuffStr(BuffTemp);
				    */
				      /*
				      WriteConByte (Main.T_Vib&0xff00);
			        WriteConByte (Main.T_Vib&0x00ff);
			      	WriteConByte (Main.T_Vib);
				 */
				/*

				for (y = 0; y < 32; y++ )
							{
    					 
						  	 WriteCon(BuffTemp);
							}	WriteCon("\n\r");	
				
				*/		
/*
Main.T_Vib=((7680000*16/Main.Frq)*4096);
         th=   Main.T_Vib&0xff00;
         tt=   Main.T_Vib&0x00ff;
            sprintf(BuffTemp,"<%07d  >",( (Main.T_Vib&0xff00)));
						SendToBuffStr(BuffTemp);
						
						sprintf(BuffTemp,"<%07d  >",( ( Main.T_Vib&0x00ff)));
						SendToBuffStr(BuffTemp);
						/*
						CuruAngleOld=CuruAngle;*/
				    // Spi.ADC1=Spi.ADC1*0.000061;
				
				
			
				
				/*
				
				   	sprintf(BuffTemp,"\n\r<%05d><%05d><%05d><%05d><%05d>",Spi.ADC1,Spi.ADC2,Spi.ADC3,Spi.ADC4,Spi.ADC5);
		       	SendToBuffStr(BuffTemp);
				
				*/
				
					/*	sprintf(BuffTemp,"<%d>",(FrecTemp));
						SendToBuffStr(BuffTemp);
				for (y = 0; y < 32; y++ )
		   		{
						sprintf(BuffTemp,"   <%07d>", (Buff_16PointD [y]-65535));
						SendToBuffStr(BuffTemp);
					}		*/							
      }
		
		
	 
			 




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



						
		LPC_GPIO2->FIOSET |= 0x0000004;		// turn on the LED 

	
		Curr_Cnt_Vib = LPC_QEI->POS;		// �������� � ����������	Curr_Cnt_Vib ������� ��������� ��������.	(������� ���������� ���������)
		Latch_Event(); //����������� �������
		
	 	clc_Pulses(); // ������� ���������. RATE_REPER_OR_REFMEANDR ��� RATE_VIBRO_1
		
	
		//ADC_Input();  // �������� ������ ���������� ������ � ������� Thermo1, Thermo2, HF_out � �����  Input.ArrayIn[n].
	//DAC_ADC_Exchange();//  �������� ������ ���������� ������ � ����� � ����. 
		ServiceTime();//��������� ������.
	 	clc_ThermoSensors();//������ ������� ����������� �� �������	 
	 	clc_HFO(); //������ �������� ��� �������� � ������ ���(�� ���).
	 	clc_PLC();	  
	 //	clc_Dith_regulator(); 
	 	clc_OutFreq_regulator();
	 	Output.Str.WP_sin = clc_WP_sin();  	
	 	contrl_GLD(); 
   	G_Photo_Exchange();	
	//  Output.Str.T_Vibro = paramV*48;


	Line_1_Rcv();
 	decode_CMD(); 
  transm_DAT();  

		
//		data_Rdy &= ~RESET_PERIOD;


LPC_PWM1->IR = 0x0001;				 //e. clear interrupt flag 	



LPC_GPIO2->FIOCLR |= 0x0000004;		// turn off the LED 
//		WDTFeed();
		  
		
//SPI_Exchange();
   
	   }
		 
	  }	while ( 1 );	    // main infinie loop            
}

/******************************************************************************
**                            End Of File
******************************************************************************/