| | |
| | | #include "dw_mbx_tag.h" |
| | | #include "dps310.h" |
| | | #define DELAY_BETWEEN_TWO_FRAME_UUS 400 |
| | | #define POLL_RX_TO_RESP_TX_DLY_UUS 470 |
| | | #define POLL_RX_TO_RESP_TX_DLY_UUS 670 |
| | | #define UUS_TO_DWT_TIME 65536 |
| | | |
| | | static uint64_t get_rx_timestamp_u64(void) |
| | |
| | | dwt_writetxfctrl(38, 0);//设定发送长度 |
| | | result = dwt_starttx(DWT_START_TX_DELAYED); |
| | | |
| | | start_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | timeout=100; //单位0.1ms |
| | | end_time=start_time+(timeout<<2); |
| | | if(end_time>=32768) |
| | | { |
| | | end_time-=32768; |
| | | } |
| | | current_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // start_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // timeout=100; //单位0.1ms |
| | | // end_time=start_time+(timeout<<2); |
| | | // if(end_time>=32768) |
| | | // { |
| | | // end_time-=32768; |
| | | // } |
| | | // current_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & SYS_STATUS_TXFRS ))///不断查询芯片状态直到接收成功或者出现错误 |
| | | { |
| | | current_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | if(current_time>=end_time&¤t_time<end_time+15000) |
| | | break; |
| | | // current_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // if(current_time>=end_time&¤t_time<end_time+15000) |
| | | // break; |
| | | }; |
| | | tagofflinetime[taglist_pos] = 0; |
| | | // printf("测距成功,序号%d,距离%d\r\n",frame_seq_nb2,tagdist_list[taglist_pos]); |
| | |
| | | uint16_t checksum; |
| | | uint8_t kk; |
| | | |
| | | dwt_setrxtimeout(3000);//设定接收超时时间,0位没有超时时间 |
| | | dwt_rxenable(0);//打开接收 |
| | | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET); |
| | | temp231 = dwt_read32bitreg(CHAN_CTRL_ID) ; |
| | | start_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | timeout=100; //单位0.1ms |
| | | end_time=start_time+(timeout<<2); |
| | | if(end_time>=32768) |
| | | { |
| | | end_time-=32768; |
| | | } |
| | | current_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // dwt_setrxtimeout(3000);//设定接收超时时间,0位没有超时时间 |
| | | // dwt_rxenable(0);//打开接收 |
| | | // HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET); |
| | | // temp231 = dwt_read32bitreg(CHAN_CTRL_ID) ; |
| | | // start_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // timeout=100; //单位0.1ms |
| | | // end_time=start_time+(timeout<<2); |
| | | // if(end_time>=32768) |
| | | // { |
| | | // end_time-=32768; |
| | | // } |
| | | // current_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | |
| | | while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到接收成功或者出现错误 |
| | | { |
| | | current_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | if(current_time>=end_time&¤t_time<end_time+15000) |
| | | break; |
| | | }; |
| | | |
| | | // while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到接收成功或者出现错误 |
| | | // { |
| | | // current_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // if(current_time>=end_time&¤t_time<end_time+15000) |
| | | // break; |
| | | // }; |
| | | status_reg = dwt_read32bitreg(SYS_STATUS_ID); |
| | | 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), 0); |
| | | if (status_reg & SYS_STATUS_RXFCG && status_reg!=0xffffffff)//成功接收 |
| | | { |
| | | uint16_t tag_recv_interval; |
| | |
| | | // dwt_rxenable(0); |
| | | } |
| | | |
| | | dwt_forcetrxoff(); |
| | | dwt_entersleep(); |
| | | 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); |
| | | |
| | | } |
| | | wg_state_enum wg_state = WG_Lost; |
| | |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*2],report_ancdist,report_ancnum*2); |
| | | checksum = Checksum_u16(lora_sendbuffer,4*report_ancnum+ANCID_IDX); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*4],&checksum,2); |
| | | HAL_NVIC_DisableIRQ(EXTI4_15_IRQn); |
| | | Radio.Send(lora_sendbuffer,ANCID_IDX+report_ancnum*4+2); |
| | | LED_TB_ON; |
| | | bat_percent=Get_Battary(); |