|
/*! ----------------------------------------------------------------------------
|
* @file main.c
|
* @brief Double-sided two-way ranging (DS TWR) initiator example code
|
*
|
*
|
*
|
* @attention
|
*
|
* Copyright 2015 (c) Decawave Ltd, Dublin, Ireland.
|
*
|
* All rights reserved.
|
*
|
* @author Decawave
|
*/
|
|
#include <string.h>
|
#include <math.h>
|
#include "dw_app.h"
|
#include "deca_device_api.h"
|
#include "deca_regs.h"
|
#include "dw_driver.h"
|
#include "Spi.h"
|
#include "led.h"
|
#include "serial_at_cmd_app.h"
|
#include "Usart.h"
|
#include "global_param.h"
|
#include "filters.h"
|
#include <stdio.h>
|
#include "beep.h"
|
#include "modbus.h"
|
#include "CRC.h"
|
|
//#define USART_INTEGRATE_OUTPUT
|
/*------------------------------------ Marcos ------------------------------------------*/
|
/* Inter-ranging delay period, in milliseconds. */
|
#define RNG_DELAY_MS 100
|
|
/* Default antenna delay values for 64 MHz PRF. See NOTE 1 below. */
|
#define TX_ANT_DLY 0
|
#define RX_ANT_DLY 32899
|
|
/* UWB microsecond (uus) to device time unit (dtu, around 15.65 ps) conversion factor.
|
* 1 uus = 512 / 499.2 µs and 1 µs = 499.2 * 128 dtu. */
|
#define UUS_TO_DWT_TIME 65536
|
|
///* Delay between frames, in UWB microseconds. See NOTE 4 below. */
|
///* 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 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 410
|
|
///* Receive response timeout. See NOTE 5 below. */
|
//#define RESP_RX_TIMEOUT_UUS 600
|
|
//#define DELAY_BETWEEN_TWO_FRAME_UUS 400
|
|
////#define POLL_RX_TO_RESP_TX_DLY_UUS 470
|
///* 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 200
|
///* Receive final timeout. See NOTE 5 below. */
|
//#define FINAL_RX_TIMEOUT_UUS 4300
|
|
|
#define SPEED_OF_LIGHT 299702547
|
|
/* Indexes to access some of the fields in the frames defined above. */
|
#define FINAL_MSG_POLL_TX_TS_IDX 10
|
#define FINAL_MSG_RESP_RX_TS_IDX 14
|
#define FINAL_MSG_FINAL_TX_TS_IDX 18
|
#define FINAL_MSG_TS_LEN 4
|
|
//#define _UWB_4G
|
|
static dwt_config_t config = {
|
#ifdef _UWB_4G
|
2, /* Channel number. */
|
#else
|
5,
|
#endif
|
DWT_PRF_64M, /* Pulse repetition frequency. */
|
DWT_PLEN_128, /* Preamble length. */
|
DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */
|
9, /* TX preamble code. Used in TX only. */
|
9, /* RX preamble code. Used in RX only. */
|
1, /* Use non-standard SFD (Boolean) */
|
DWT_BR_6M8, /* Data rate. */
|
DWT_PHRMODE_STD, /* PHY header mode. */
|
(129 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */
|
};
|
|
uint32_t uwbid=0;
|
void Dw1000_Init(void)
|
{
|
/* Reset and initialise DW1000.
|
* For initialisation, DW1000 clocks must be temporarily set to crystal speed. After initialisation SPI rate can be increased for optimum
|
* performance. */
|
Reset_DW1000();//ÖØÆôDW1000 /* Target specific drive of RSTn line into DW1000 low for a period. */
|
Spi_ChangePrescaler(SPIx_PRESCALER_SLOW); //ÉèÖÃΪ¿ìËÙģʽ
|
dwt_initialise(DWT_LOADUCODE);//³õʼ»¯DW1000
|
Spi_ChangePrescaler(SPIx_PRESCALER_FAST); //ÉèÖÃΪ¿ìËÙģʽ
|
|
/* Configure DW1000. See NOTE 6 below. */
|
dwt_configure(&config);//ÅäÖÃDW1000
|
|
// dwt_setinterrupt( DWT_INT_RFCG | (DWT_INT_ARFE | DWT_INT_RFSL | DWT_INT_SFDT | DWT_INT_RPHE | DWT_INT_RFCE | DWT_INT_RFTO | DWT_INT_RXPTO), 1);
|
|
|
/* Apply default antenna delay value. See NOTE 1 below. */
|
dwt_setrxantennadelay(RX_ANT_DLY); //ÉèÖýÓÊÕÌìÏßÑÓ³Ù
|
dwt_settxantennadelay(TX_ANT_DLY); //ÉèÖ÷¢ÉäÌìÏßÑÓ³Ù
|
|
// dwt_setrxtimeout(1000);//É趨½ÓÊÕ³¬Ê±Ê±¼ä£¬0λûÓг¬Ê±Ê±¼ä
|
// dwt_rxenable(0);//´ò¿ª½ÓÊÕ
|
// uwbid=dwt_readdevid();
|
/* Set expected response's delay and timeout. See NOTE 4 and 5 below.
|
* As this example only handles one incoming frame with always the same delay and timeout, those values can be set here once for all. */
|
//ÉèÖýÓÊÕ³¬Ê±Ê±¼ä
|
}
|
|
uint16_t Checksum_u16(uint8_t* pdata, uint32_t len)
|
{
|
uint16_t sum = 0;
|
uint32_t i;
|
for(i=0; i<len; i++)
|
sum += pdata[i];
|
sum = ~sum;
|
return sum;
|
}
|
|
u16 tag_time_recv[TAG_NUM_IN_SYS];
|
u8 usart_send[300]={0x55,0xAA};
|
u8 battary,button;
|
extern uint8_t g_pairstart;
|
void tag_sleep_configuraion(void)
|
{
|
dwt_configuresleep(0x940, 0x7);
|
dwt_entersleep();
|
}
|
u32 id;
|
void UWB_Wkup(void)
|
{
|
|
SPIx_CS_GPIO->BRR = SPIx_CS;
|
delay_us(600);
|
SPIx_CS_GPIO->BSRR = SPIx_CS;
|
id = dwt_readdevid() ;
|
while (0xDECA0130!=id)
|
{
|
u8 iderror_count = 0;
|
id = dwt_readdevid() ;
|
if(iderror_count++>100)
|
{
|
printf("UWBоƬID´íÎó");
|
break;
|
}
|
}
|
}
|