コード例 #1
0
ファイル: control.c プロジェクト: junife/LevelMeter_ICCAVR804
void Con_Module_Init_Proc(void)
{
  ADDR_CODE_T    temp_addr_code;
  MT_FULL_T      temp_mt_full;
  MT_EMPTY_T     temp_mt_empty;
  PER_HIGH_T     temp_per_high;
  PER_LOW_T      temp_per_low;
  RESP_TIME_T    temp_resp_time;
  HV_800V_T      temp_hv_value;
  //EEPROM_Write_Bytes(SEQ_NUM_ADDR, &me_seq_num.year, sizeof(SEQ_NUM_T));
  //EEPROM_Write_Bytes(ADDR_CODE_ADDR, &me_addr_code.highByte, sizeof(ADDR_CODE_T));
  //EEPROM_Write_Bytes(HIGH_THRESH_ADDR, &me_high_thresh.highByte, sizeof(HIGH_THRESH_T));
  //EEPROM_Write_Bytes(LOW_THRESH_ADDR, &me_low_thresh.highByte, sizeof(LOW_THRESH_T));
  //EEPROM_Write_Bytes(OP_TIME_LOW_ADDR, &me_op_time.val[0], sizeof(OP_TIME_T));
	  
  EEPROM_Read_Bytes(ADDR_CODE_ADDR, &temp_addr_code.highByte, sizeof(ADDR_CODE_T));
  EEPROM_Read_Bytes(MT_FULL_ADDR, &temp_mt_full.highByte, sizeof(MT_FULL_T));
  EEPROM_Read_Bytes(MT_EMPTY_ADDR, &temp_mt_empty.highByte, sizeof(MT_EMPTY_T));
  EEPROM_Read_Bytes(PER_HIGH_ADDR, &temp_per_high.highByte, sizeof(PER_HIGH_T));
  EEPROM_Read_Bytes(PER_LOW_ADDR, &temp_per_low.highByte, sizeof(PER_LOW_T));
  EEPROM_Read_Bytes(RESP_TIME_ADDR, &temp_resp_time.highByte, sizeof(RESP_TIME_T));
  EEPROM_Read_Bytes(HV_800V_ADDR, &temp_hv_value.highByte, sizeof(HV_800V_T));
  
  g_addr_code = temp_addr_code.highByte*100 + temp_addr_code.lowByte;
  g_mt_full = temp_mt_full.highByte*100 + temp_mt_full.lowByte;
  g_mt_empty = temp_mt_empty.highByte*100 + temp_mt_empty.lowByte;
  g_per_high = temp_per_high.highByte*100 + temp_per_high.lowByte;
  g_per_low = temp_per_low.highByte*100 + temp_per_low.lowByte;
  g_resp_time = temp_resp_time.highByte*100 + temp_resp_time.lowByte;
  g_hv_value = temp_hv_value.highByte*100 + temp_hv_value.lowByte;
  
  KZ1_OUT_LOW();   
  KZ2_OUT_HIGH(); 
  
  RL1_OPEN();  
  RL2_OPEN();  
  
  if(tickCnt<2)
  {
    if(timer_1000ms_flag)
	{
	  timer_1000ms_flag = FALSE;
	  if(tickCnt%2 == 0)
	  {
	  	Seg_164_Number(g_addr_code, SEG_COLOR_GREEN, MARK_NULL);
		//LedLight(LED_D1, OFF);
	  }
	  else
	  {
		//LedLight(LED_D1, ON);
	  }
	  tickCnt++;
	}
  }
  else if(tickCnt<5)
  {
    if(timer_1000ms_flag)
	{
	  timer_1000ms_flag = FALSE;
	  tickCnt++;
	  Seg_164_Alpha(H, U, g, E, SEG_COLOR_RED);
	  //Seg_164_Number(8888, SEG_COLOR_RED, MARK_NULL);
	}
	LedLight(LED_D1, ON);
	LedLight(LED_D2, ON);
  }
  else
  {
    LedLight(LED_D1, OFF);
    LedLight(LED_D2, OFF);
    module_prevState = MODULE_STATE_INIT;
    module_state = MODULE_STATE_WORK_NORM;
	tickCnt = 0;
  }
}
コード例 #2
0
ファイル: main.c プロジェクト: PolyakovV/Unit213
int32_t main()
{

/***************************************************************************
*       ClkInit()
****************************************************************************/
	ClkInit();

/***************************************************************************
*       GPIOInit();
****************************************************************************/
//	DrvGPIO_InitFunction(E_FUNC_GPIO);
	outpw(&SYS->P0_MFP, 0);
	outpw(&SYS->P1_MFP, 0);
	outpw(&SYS->P2_MFP, 0);
	outpw(&SYS->P3_MFP, 0);
	outpw(&SYS->P4_MFP, 0);

	_GPIO_SET_PIN_MODE(MODEM_ON_PORT, MODEM_ON_PIN, GPIO_PMD_OUTPUT);
	ModuleOn(TRUE);

	_GPIO_SET_PIN_MODE(MODEM_POWER_PORT, MODEM_POWER_PIN, GPIO_PMD_OUTPUT);
	ModulePowerOn(FALSE);

	_GPIO_SET_PIN_MODE(LOCK_POWER_PORT, LOCK_POWER_PIN, GPIO_PMD_OUTPUT);
	LockPower(FALSE);

	_GPIO_SET_PIN_MODE(KEY_HELP_PORT, KEY_HELP_PIN, GPIO_PMD_QUASI);
	_GPIO_SET_PIN_MODE(KEY_BAT_PORT, KEY_BAT_PIN, GPIO_PMD_QUASI);

	_GPIO_SET_PIN_MODE(SLEEP_PORT, SLEEP_PIN, GPIO_PMD_OUTPUT);
	ModemSleep(FALSE);

	_GPIO_SET_PIN_MODE(LED_PORT, LED_PIN, GPIO_PMD_OUTPUT);
	
	LedDark();
	
	_GPIO_SET_PIN_MODE(INT_PORT, INT_PIN, GPIO_PMD_INPUT);

/***************************************************************************
*       TimerInit();
****************************************************************************/
	SysTick_Config(SYS_TICK);
//	SYS_LockReg();

/***************************************************************************
*       UartInit();
****************************************************************************/
	UartInit();
//	debug(VERSION);
//	DrvSYS_GetPLLClockFreq();

/***************************************************************************
*       WatchdogInit();
****************************************************************************/	
	WatchdogInit();

//	udpTest();
	NvInit();



 	WhatToDo();
	AdcInit();
	
	
	
	WaitLockPower();

  LockPower(!custermParam.param.lockState);


	InitMsgDebug();	
	
	if( Communication(10) == FALSE )
		SoftReset();

	if( isCheckingBattery )
	{
		delay_50ms(40);
		MeasurePower(4);
	}
	else
	{
		MeasurePower(2);
	}
					
	Flag_ModuleOn = TRUE;
	//Flag_ModuleOn = TRUE;
	ModemVolumeInit();

	///--------------------24.11.2015----------------------------------------------
	////////////////////////////////////////////////////////////////////////////////////////
while(PressHelp()&&(tmp_my<200)&&(PressBatter())){
	tmp_my++;
		
	delay_50ms(1);
if (tmp_my>=150) {
	  LedLight(144);
	    if (custermParam.param.lockState) {
														LockPower(TRUE);
														custermParam.param.lockState = FALSE;
												    WriteToNv( &custermParam ); //- save to eeprom
  													PlayVoice("\"unitUnlock.wav\",2\r");
														delay_ms(2000);
			                      LockPower(FALSE);
			
			} else {
	                          //  debug("ins");
															while(PressBatter()){};
														 tmp_my=0;
												while (tmp_my<25){               
																											tmp_my++;
																											delay_ms(150);
																											if (PressBatter()){counterPress++;
																																				while(!PressBatter()){};
																																					}
																										  if (counterPress>2){ 
																																					PlayVoice("\"unitLock.wav\",2\r");
																																					delay_ms(2000);
																																					custermParam.param.lockState = TRUE;
																																					WriteToNv( &custermParam ); //- save to eeprom
																																		      tmp_my=0;
																																					delay_ms(2000);
																																					LockPower(DISABLE);

																																				}
																											}
													LedBlink();
										} 
					///////				
			tmp_my=0;
			}

}

while(custermParam.param.lockState){}
 
///////////////////////////////////////////////////////////////////////////////////////////////													
#ifdef DELAY_TEST
	DelayTest();
#endif
	PowerOn();
	
	

	
	if(state==STATE_POWERING_DOWN || Flag_Power_Down)
	{
		Flag_Power_Down = FALSE;
		EnterPowerDown();
		while( TimerWait )
			FeedWatchdog();
		PowerDown();
		//不会返回
	}
	
	InitVariables();
	  
	if(state == STATE_NULL)
	{
		state = STATE_1ST_CALL;
		TimerWait = 100;	// 5 s
	}
	
	TimerTestMode = 6000;
	//debug("ent main loop");
	while(1)
	{  
			
		///--------------------
				if (!TimerTestMode && state==STATE_TEST)
										{ 
										PlayMusic(MUSIC_PD);
										EnterPowerDown();
										}
		
		///--------------------
		
		if( Flag_Incomming )
		{
	#if 1
			TimerWait = 200;
			Flag_Incomming = FALSE;
			TimerStandby = custermParam.param.delay;
			//if(state != STATE_ACTIVE)
			{
				ModemSleep(FALSE);
				state = STATE_INCOMMING;
			}
	#else
			Flag_Incomming = FALSE;
			if(state != STATE_INCOMMING)
			{
				state = STATE_INCOMMING;
				ModemSleep(FALSE);
				EnterAnswer();
			}
	#endif
		}
		
		if(TimerWait == 0)
		{
			switch(state)
			{
									
			case STATE_POWERING_DOWN:
				PowerDown();
				break;

			case STATE_1ST_CALL:
				RegisterWait();
				break;

			case STATE_REGISTER_OK:	
				GetCpsiInfo();
				if( Flag_ObtainCpsi==TRUE)
				{
					state = STATE_GSM_STEADY;
					if( Flag_SimExist )
					{
						//delay_50ms(200);
						SockOpen();
						TimerWait = 400;
					}
					else
					{
						TimerWait = 60;
					}
				}
				else
				{
					TimerWait = 70;
				}
				break;

			case STATE_GSM_STEADY:	
				if( gPhoneNumOk==PHONE_NUM_READY || Flag_SimExist==FALSE)
					EnterCall();
				else
					TimerWait = 40;
				break;
				
			case STATE_CALL_PROMPT:
				Call();
				break;

			case STATE_ALERT:
				EnterCallFail();
				break;
			
			case STATE_NEXT_CALL:
				Redial();
				break;				

			case STATE_BATT_DISPLAY:
				EnterPowerDown();
				break;

			case STATE_INCOMMING:
				TimerStandby = custermParam.param.delay;
				EnterStandby();
				break;
			}
		}

		if( TimerSock==0 && Flag_SimExist
			&& ( (state>=STATE_GSM_STEADY && state<STATE_STANDBY) || progress>=TEST_GPS ) )
		{
			switch(sockState)
			{
			//case SOCKSTATE_NULL:
			case SOCKSTATE_CONFIG:				
			case SOCKSTATE_OPENNING:
				SockOpen();	// 打开失败,从新打开
				break;

			case SOCKSTATE_OPENED:
				SendAtWaitRsq(50, 1, FALSE, "AT+CIPOPEN=0,\"UDP\",,,%s\r\n", custermParam.param.local_port);
				TimerSock = 80;
				break;
	#if 0
			case SOCKSTATE_CONNECTING:
				SockConnect();	// 连接失败,从新连接
				break;
	#endif
			case SOCKSTATE_CONNECT_OK:		
				if( witchApn == 1)
					ClientInit();
				break;

			default:
				break;
			}
		}

		KeyHandle();

		SecondHandle();
		//SignalCheck();
		BatterCheck();
		PowerDownHandle();
		MsgHandle();
											
		if( Flag_SimExist )
		{
			UdpHandle();
			SmsHandle();
			PowerDownHandle();
		}
		
		FeedWatchdog();
	}
}