| | |
| | | /* 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 850 |
| | | #define RESP_RX_TO_FINAL_TX_DLY_UUS_POLL 1850 |
| | | /* Receive response timeout. See NOTE 5 below. */ |
| | | #define RESP_RX_TIMEOUT_UUS 600 |
| | | |
| | |
| | | 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. */ |
| | | 0, /* Use non-standard SFD (Boolean) */ |
| | | 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. */ |
| | |
| | | * 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); //设置为快速模式 |
| | | |
| | |
| | | void Poll(void) |
| | | { |
| | | uint32_t frame_len; |
| | | uint32_t final_tx_time; |
| | | uint32_t final_tx_time,id; |
| | | u32 start_poll; |
| | | int32_t mindist=999999,minid=-1,temp_dist; |
| | | u8 i,getsync_flag=0; |
| | | id = dwt_readdevid() ; //0XFFFFFF BUG 初始化缺少Spi_ChangePrescaler(SPIx_PRESCALER_SLOW); //设置为快速模式 |
| | | while (DWT_DEVICE_ID != id) |
| | | { |
| | | id = dwt_readdevid() ; |
| | | } |
| | | dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); //设置发送后开启接收,并设定延迟时间 |
| | | dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS); |
| | | tag_succ_times = 0; |
| | |
| | | memcpy(&temp_dist, &rx_buffer[DIST_IDX], 4); |
| | | memcpy(&tx_final_msg[ANCHOR_ID_IDX], &rx_buffer[ANCHOR_ID_IDX], 4); |
| | | /* Compute final message transmission time. See NOTE 9 below. */ |
| | | final_tx_time = (resp_rx_ts + (RESP_RX_TO_FINAL_TX_DLY_UUS * UUS_TO_DWT_TIME)) >> 8;//计算final包发送时间,T5=T4+Treply2 |
| | | final_tx_time = (resp_rx_ts + (RESP_RX_TO_FINAL_TX_DLY_UUS_POLL * UUS_TO_DWT_TIME)) >> 8;//计算final包发送时间,T5=T4+Treply2 |
| | | dwt_setdelayedtrxtime(final_tx_time);//设置final包发送时间T5 |
| | | final_tx_ts = (((uint64_t)(final_tx_time & 0xFFFFFFFE)) << 8) + TX_ANT_DLY;//final包实际发送时间是计算时间加上发送天线delay |
| | | final_msg_set_ts(&tx_final_msg[FINAL_MSG_POLL_TX_TS_IDX], poll_tx_ts);//将T1,T4,T5写入发送数据 |
| | |
| | | change_base_count=0; |
| | | } |
| | | } |
| | | u8 anclost_times=0; |
| | | u8 anclost_times=0 , mainbase_lost_count=0; |
| | | u8 flag_finalsend,flag_getresponse; |
| | | uint16_t current_count,start_count,end_count; |
| | | void NearPoll(void) |
| | | { |
| | | static u8 mainbase_lost_count=0,flag_finalsend; |
| | | |
| | | uint32_t temp1,temp2,dw_systime; |
| | | uint32_t frame_len; |
| | | uint32_t final_tx_time; |
| | |
| | | nearbase_distlist[i]=0xffff; |
| | | |
| | | flag_finalsend=0; |
| | | flag_getresponse=0; |
| | | start_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | recbase_num=0; |
| | | timeout=ceil((float)nearbase_num/4)+2; |
| | |
| | | {end_count-=32768;} |
| | | mainbase_dist=100000; |
| | | mainbase_lost_count++; |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | while(current_count<end_count||current_count>end_count+15000) |
| | | { |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到成功接收或者发生错误 |
| | | { |
| | | if(flag_finalsend) |
| | |
| | | dw_systime=dwt_readsystimestamphi32(); |
| | | if(dw_systime>temp1&&dw_systime<temp2) |
| | | { |
| | | flag_finalsend=0; |
| | | |
| | | dwt_forcetrxoff(); |
| | | dwt_setdelayedtrxtime(final_tx_time); |
| | | result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送 |
| | | flag_finalsend=0; |
| | | break; |
| | | } |
| | | } |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | if(current_count>end_count&¤t_count<end_count+15000) |
| | | break; |
| | | }; |
| | |
| | | flag_finalsend=1; |
| | | memcpy(&mainbase_dist,&rx_buffer[DIST_IDX],4); |
| | | final_tx_time = (resp_rx_ts + ((RESP_RX_TO_FINAL_TX_DLY_UUS+DELAY_BETWEEN_TWO_FRAME_UUS*nearbase_num+500) * UUS_TO_DWT_TIME)) >> 8; |
| | | temp1=final_tx_time-((350*UUS_TO_DWT_TIME)>>8); |
| | | temp1=final_tx_time-((850*UUS_TO_DWT_TIME)>>8); |
| | | temp2=final_tx_time+((100*UUS_TO_DWT_TIME)>>8); |
| | | // dwt_setdelayedtrxtime(final_tx_time);//设置final包发送时间T5 |
| | | final_tx_ts = (((uint64_t)(final_tx_time & 0xFFFFFFFE)) << 8) + TX_ANT_DLY;//final包实际发送时间是计算时间加上发送天线delay |
| | |
| | | tx_near_msg[MESSAGE_TYPE_IDX]=NEAR_FINAL; |
| | | dwt_writetxdata(28+nearbase_num*4, tx_near_msg, 0);//将发送数据写入DW1000 |
| | | dwt_writetxfctrl(28+nearbase_num*4, 0);//设定发送数据长度 |
| | | usart_send[2] = 1;//正常模式 |
| | | usart_send[3] = 17;//数据段长度 |
| | | usart_send[4] = frame_seq_nb;//数据段长度 |
| | | memcpy(&usart_send[5],&dev_id,2); |
| | | memcpy(&usart_send[7],&rec_nearbaseid,2); |
| | | memcpy(&usart_send[9],&rx_buffer[DIST_IDX],4); |
| | | usart_send[13] = battary; |
| | | usart_send[14] = button; |
| | | checksum = Checksum_u16(&usart_send[2],17); |
| | | memcpy(&usart_send[19],&checksum,2); |
| | | UART_PushFrame(usart_send,21); |
| | | flag_getresponse=1; |
| | | // dwt_setdelayedtrxtime(final_tx_time); |
| | | //result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送 |
| | | }else{ |
| | | rec_nearbasepos=FindNearBasePos(rec_nearbaseid); |
| | |
| | | memcpy(&nearbase_distlist[rec_nearbasepos],&rx_buffer[DIST_IDX],4); |
| | | dwt_writetxdata(28+nearbase_num*4, tx_near_msg, 0);//将发送数据写入DW1000 |
| | | dwt_writetxfctrl(28+nearbase_num*4, 0);//设定发送数据长度 |
| | | LED0_BLINK; |
| | | usart_send[2] = 1;//正常模式 |
| | | usart_send[3] = 17;//数据段长度 |
| | | usart_send[4] = frame_seq_nb;//数据段长度 |
| | | memcpy(&usart_send[5],&dev_id,2); |
| | | memcpy(&usart_send[7],&rec_nearbaseid,2); |
| | | memcpy(&usart_send[9],&rx_buffer[DIST_IDX],4); |
| | | usart_send[13] = battary; |
| | | usart_send[14] = button; |
| | | checksum = Checksum_u16(&usart_send[2],17); |
| | | memcpy(&usart_send[19],&checksum,2); |
| | | UART_PushFrame(usart_send,21); |
| | | |
| | | |
| | | |
| | | //dwt_setdelayedtrxtime(final_tx_time);//设置final包发送时间T5 |
| | | // result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送 |
| | |
| | | } |
| | | } |
| | | } |
| | | dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | } |
| | | if(flag_getresponse==0) |
| | | { |
| | | LED_LR_BLINK; |
| | | } |
| | | if(mainbase_lost_count>5) |
| | | { |
| | | tag_state=DISCPOLL; |
| | | // tag_state=DISCPOLL; |
| | | } |
| | | NearAncSelect(); |
| | | if(recbase_num<MIN_ANCHOR_NUM ) |
| | |
| | | //LED0_ON; |
| | | dwt_forcetrxoff(); |
| | | g_Resttimer=0; |
| | | // tag_state=DISCPOLL; |
| | | switch(tag_state) |
| | | { |
| | | case DISCPOLL: |
| | |
| | | break; |
| | | case GETNEARMSG: |
| | | // if(trygetnearmsg_times--!=0) |
| | | {GetNearMsg(); |
| | | { |
| | | mainbase_lost_count=0; |
| | | GetNearMsg(); |
| | | } |
| | | // else{ |
| | | // tag_state=DISCPOLL; |