/*! ---------------------------------------------------------------------------- * @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 #include #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 #include "beep.h" //#include "modbus.h" //#include "BMP390.h" /*------------------------------------ Marcos ------------------------------------------*/ dwt_config_t config = { 5, /* Channel number. */ 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. */ }; 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 /* Apply default antenna delay value. See NOTE 1 below. */ dwt_setrxantennadelay(32899); //ÉèÖýÓÊÕÌìÏßÑÓ³Ù dwt_settxantennadelay(0); //ÉèÖ÷¢ÉäÌìÏßÑÓ³Ù /* 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>8; usart_send[8] = bat_percent; usart_send[9] = 0; memcpy(&usart_send[10],&intheight,2); usart_send[12] = tag_frequency; usart_send[13] = 0; usart_send[14] = 0; usart_send[15] = 0; usart_send[16] = nearbase_num+1; memcpy(&usart_send[17],&mainbase_id,2); // memcpy(&usart_send[19],&nearbaseid_list,2*nearbase_num); // memcpy(&usart_send[19+nearbase_num*2],&nearbase_distlist,4*nearbase_num+4); // memcpy(&usart_send[19+nearbase_num*6+4],&rec_anc_signalpower,2*nearbase_num+2); checksum = Checksum_u16(&usart_send[2],23+8*nearbase_num); memcpy(&usart_send[25+8*nearbase_num],&checksum,2); // USART_puts(usart_send,27+8*nearbase_num); //HexToAsciiSendUDP(usart_send,27+8*nearbase_num); } extern void SwitchTagState(void); extern u8 userkey_state; extern void delay_us(uint32_t nTimer) ; void Tag_App(void)//·¢ËÍģʽ(TAG±êÇ©) { //LED0_ON; SPIx_CS_GPIO->BRR = SPIx_CS; delay_us(700); SPIx_CS_GPIO->BSRR = SPIx_CS; id = dwt_readdevid() ; while (DWT_DEVICE_ID != id) { // Dw1000_Init(); id = dwt_readdevid() ; IdleTask(); if(error_times++>20) { // printf("DW ID ERROR.\r\n"); // SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //Èí¸´Î»»Øµ½bootloader } } #ifdef QIYA_JIZHAN QiyaJizhan_Send(); #else // Dw1000_Init(); dwt_forcetrxoff(); error_times = 0; SwitchTagState(); dwt_forcetrxoff(); // 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); // dwt_setrxtimeout(0);//É趨½ÓÊÕ³¬Ê±Ê±¼ä£¬0λûÓг¬Ê±Ê±¼ä // dwt_rxenable(0); #endif dwt_entersleep(); }