From 4979f7565cbd5f093e280f9f277ae29bb450acb8 Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期六, 15 九月 2018 17:28:24 +0800
Subject: [PATCH] 增加低功耗标签

---
 源码/核心板/Src/application/dw_app.c |   68 ++++++++++++---------------------
 1 files changed, 25 insertions(+), 43 deletions(-)

diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c"
index db01397..d82f45e 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c"
@@ -26,6 +26,8 @@
 #include "dw_driver.h"
 #include "Spi.h"
 #include "led.h"
+#include "serial_at_cmd_app.h"
+#include "Usart.h"
 
 
 /*------------------------------------ Marcos ------------------------------------------*/
@@ -45,13 +47,13 @@
 #define POLL_TX_TO_RESP_RX_DLY_UUS 150
 /* This is the delay from Frame RX timestamp to TX reply timestamp used for calculating/setting the DW1000's delayed TX function. This includes the
  * frame length of approximately 2.66 ms with above configuration. */
-#define RESP_RX_TO_FINAL_TX_DLY_UUS 4100
+#define RESP_RX_TO_FINAL_TX_DLY_UUS 5100
 /* Receive response timeout. See NOTE 5 below. */
 #define RESP_RX_TIMEOUT_UUS 14700
 
 #define POLL_RX_TO_RESP_TX_DLY_UUS 3600
 /* This is the delay from the end of the frame transmission to the enable of the receiver, as programmed for the DW1000's wait for response feature. */
-#define RESP_TX_TO_FINAL_RX_DLY_UUS 500
+#define RESP_TX_TO_FINAL_RX_DLY_UUS 1500
 /* Receive final timeout. See NOTE 5 below. */
 #define FINAL_RX_TIMEOUT_UUS 4300
 
@@ -221,7 +223,9 @@
 
     /* Configure DW1000. See NOTE 6 below. */
     dwt_configure(&config);//配置DW1000
+	
 
+	
     /* Apply default antenna delay value. See NOTE 1 below. */
     dwt_setrxantennadelay(RX_ANT_DLY);		//设置接收天线延迟
     dwt_settxantennadelay(TX_ANT_DLY);		//设置发射天线延迟
@@ -231,11 +235,24 @@
     dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS);			//设置发送后开启接收,并设定延迟时间
     dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);						//设置接收超时时间
 }
+void Delayus(uint16_t time) 
+{
+  uint16_t i = 0;
+  while (time--) {
+    i = 10;
+    while (i--)
+      ;
 
+  }
+}
 void Tag_App(void)//发送模式(TAG标签)
 {
 	uint32_t frame_len;
 	uint32_t final_tx_time;
+	
+	GPIO_ResetBits(SPIx_GPIO, SPIx_CS);
+	Delayus(2000);
+	GPIO_SetBits(SPIx_GPIO, SPIx_CS);
 	
 	/* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */
 	tx_poll_msg[ALL_MSG_SN_IDX] = frame_seq_nb;
@@ -292,26 +309,6 @@
 			dwt_writetxdata(sizeof(tx_final_msg), tx_final_msg, 0);//将发送数据写入DW1000
 			dwt_writetxfctrl(sizeof(tx_final_msg), 0);//设定发送数据长度
 			dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送
-
-			//这里为串口输出
-//			if (GPIO_ReadInputDataBit(GPIOA, SW2) != RESET) //通过拨码开关判断数据输出格式
-//			{
-//				dID = TAG_ID;
-//				printf("TAG_ID: %2.0f		", dID);
-//				dID = ANCHOR_ID;
-//				printf("ANCHOR_ID: %2.0f		", dID);
-//				printf("Distance: %5.0f cm\n", (double)dist[TAG_ID]);
-//			}
-//			else
-//			{
-//				send[2] = ANCHOR_ID;
-//				send[3] = TAG_ID;
-
-//				memcpy(&send[4], &dist[TAG_ID], 2);
-//				check = Checksum_u16(&send[2], 6);
-//				memcpy(&send[8], &check, 2);
-//				USART_puts(send, 10);
-//			}
 			
 			/* Poll DW1000 until TX frame sent event set. See NOTE 8 below. */
 			while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))//不断查询芯片状态直到发送完成
@@ -337,7 +334,8 @@
 	}
 	LED0_BLINK;
 	/* Execute a delay between ranging exchanges. */
-	deca_sleep(RNG_DELAY_MS + random_delay_tim); //休眠固定时间
+	dwt_entersleep();
+	
 }
 
 void Anchor_App(void)
@@ -353,7 +351,10 @@
 
 	/* Poll for reception of a frame or error/timeout. See NOTE 7 below. */
 	while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到接收成功或者出现错误
-	{ };
+	{ 
+		UART_CheckReceive();
+		UART_CheckSend();
+	};
 
 	if (status_reg & SYS_STATUS_RXFCG)//成功接收
 	{
@@ -451,25 +452,6 @@
 //					dist[TAG_ID] = LP(dis, TAG_ID); //LP 为低通滤波器,让数据更稳定
 					
 					LED0_BLINK; //每成功一次通讯则闪烁一次
-					//这里供串口输出
-//					if (GPIO_ReadInputDataBit(GPIOA, SW2) != RESET) //通过拨码开关判断数据输出格式
-//					{
-//						dID = TAG_ID;
-//						printf("TAG_ID: %2.0f		", dID);
-//						dID = ANCHOR_ID;
-//						printf("ANCHOR_ID: %2.0f		", dID);
-//						printf("Distance: %5.0f cm\n", (double)dist[TAG_ID]);
-//					}
-//					else
-//					{
-//						send[2] = ANCHOR_ID;
-//						send[3] = TAG_ID;
-
-//						memcpy(&send[4], &dist[TAG_ID], 2);
-//						check = Checksum_u16(&send[2], 6);
-//						memcpy(&send[8], &check, 2);
-//						USART_puts(send, 10);
-//					}
 
 				}
 			}

--
Gitblit v1.9.3