From a58107e9dcf49b7bf0b31cf201d29069550fd6cd Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期二, 05 十一月 2019 08:26:13 +0800
Subject: [PATCH] 机场发货

---
 源码/核心板/Src/main.c |   52 +++++++++++++++++++++++++++++++---------------------
 1 files changed, 31 insertions(+), 21 deletions(-)

diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c"
index e07463e..5336223 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c"
@@ -16,14 +16,16 @@
 {
 	RCC_Configuration();
 	//SystemInit();
+	NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x5000);
 	Nvic_Init();
-	Systick_Init();
+//	Systick_Init();
+	TIM3_Int_Init();
 	Led_Init();
 	Beep_Init();
 	DW_GPIO_Init();
 	Uart1_Init();
 	Spi_Init();
-	ADC_Configuration();
+	//ADC_Configuration();
 	
 	GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
 }
@@ -41,6 +43,7 @@
 	checksum = Checksum_u16(&hbsend[2],12);
 	memcpy(&hbsend[14],&checksum,2);
 }
+u16 tyncpoll_time;
 void Program_Init(void)
 {uint16_t i;
 	Usart1ParseDataCallback = UsartParseDataHandler;
@@ -48,17 +51,25 @@
 	//deca_sleep(1000);
 	HeartBeatInit();
 	dev_id = g_com_map[DEV_ID];
+//	g_com_map[DEV_ROLE]=1;
+//		g_com_map[DEV_ID]=1;
+//	g_com_map[COM_INTERVAL]=10;
+	OUT485_ENABLE;
+	g_com_map[VERSION] = 0x0104;		
 	if(g_com_map[DEV_ROLE])
 	{
+		tyncpoll_time=g_com_map[DEV_ID]*g_com_map[MAX_REPORT_ANC_NUM]*4/3;
 	printf("标签ID: %d .\r\n",dev_id);
 	printf("通讯间隔: %d ms.\r\n",g_com_map[COM_INTERVAL]);
 	printf("单次通讯基站数量: %d个.\r\n",g_com_map[MAX_REPORT_ANC_NUM]);
 	}else{
+	
 	anchor_type = dev_id%g_com_map[MAX_REPORT_ANC_NUM];
 	printf("基站ID: %x .\r\n",dev_id);
 	printf("基站类型: %c .\r\n",anchor_type+0x41);
 	printf("单次通讯基站数量: %d个.\r\n",g_com_map[MAX_REPORT_ANC_NUM]);
 	}
+	OUT485_DISABLE;
 //	printf("DEVICE PAIRID: %d .\r\n",g_com_map[PAIR_ID]);
 //	printf("DEVICE ALARM DISTANCE: 1.%d 2.%d 3.%d .\r\n",g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],g_com_map[ALARM_DISTANCE3]);
 
@@ -82,9 +93,11 @@
 { 
 UART_PushFrame(hbsend,16);
 }
-u16 heartbeat_timer,poll_timer;
+extern u8 g_start_sync_flag;
+u16 heartbeat_timer,poll_timer,sync_timer;
 void IdleTask(void)
 {
+	g_start_sync_flag=0;
 			UART_CheckReceive();
 		UART_CheckSend();
 	if(heartbeat_timer>1000)
@@ -93,23 +106,20 @@
 		if(g_com_map[HEARTBEAT]&&g_com_map[DEV_ROLE]==0)
 		HeatBeat();
 	}
-	if(poll_timer>=g_com_map[COM_INTERVAL]-tag_delaytime)
+
+	if(g_com_map[CNT_UPDATE]==1)
 	{
-		poll_timer=0;
-		if(g_com_map[ANC_POLL]||g_com_map[DEV_ROLE])
-		{
-			if(g_com_map[DEV_ROLE]==0)
-			{int8_t correction_time;
-				correction_time=tag_timer-(GROUP_TAG_NUM+1)*3;
-				tag_delaytime=correction_time;
-							if(tag_delaytime>g_com_map[COM_INTERVAL]/2)
-							{
-							tag_delaytime=tag_delaytime-g_com_map[COM_INTERVAL];
-							}
-			}
-		g_start_send_flag=1;
-		}
-		
+	uint32_t result = 0;
+		u16 tmp = 0xAAAA;
+	__disable_irq();
+	result = FLASH_Prepare(0x8004A38, 2);
+	if(result)
+		result = FLASH_Write(0x8004A38, (const uint8_t*)&tmp, 2); 
+	__enable_irq();
+		printf("进入升级模式\r\n");
+		//	STMFLASH_Write_NoCheck(0x8004A38,0xAAAA);
+		//	Delay_ms(100);
+			SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
 	}
 
 	}
@@ -125,13 +135,13 @@
 	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
 	usart_send[0]=0x55;
 	usart_send[1]=0xAA;
+	
 	while(1)
 	{
 		IdleTask();		
 	if(g_start_send_flag)
 	{
-		g_start_send_flag = 0;
-		
+		g_start_send_flag = 0;		
 		Tag_App();
 	}
 	

--
Gitblit v1.9.3