zhyinch
2018-09-15 4979f7565cbd5f093e280f9f277ae29bb450acb8
Ô´Âë/ºËÐİå/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;
@@ -317,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)
@@ -333,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)//成功接收
   {