在博文:https://www.cnblogs.com/tuzhuke/p/11638221.html 中描述了delayed tx实现方法,这里贴出全部delayed tx 代码以及对应验证代码
1 delayed tx 代码
static uint32 final_tx_time; static uint64 final_tx_ts; void BPhero_Distance_Sync_Node(void) { int address = 0; msg_f_send.destAddr[0] = 0xFF; msg_f_send.destAddr[1] = 0xFF; final_tx_time = dwt_readsystimestamphi32() +0x100000; dwt_setdelayedtrxtime(final_tx_time); final_tx_ts = (((uint64)(final_tx_time & 0xFFFFFFFE)) << 8) + TX_ANT_DLY; final_msg_set_ts(&msg_f_send.messageData[FIRST_TX], final_tx_ts);// 2 3 4 5 6 msg_f_send.seqNum = sync_seqnum; msg_f_send.messageData[0]='S'; msg_f_send.messageData[1]=0; dwt_writetxdata(psduLength, (uint8 *)&msg_f_send, 0) ; // write the frame data dwt_writetxfctrl(psduLength, 0); dwt_starttx(DWT_START_TX_DELAYED); while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS)) { }; /* Clear TX frame sent event. */ dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS); // dwt_forcetrxoff(); if(++sync_seqnum == 256) sync_seqnum = 0; }
2 delayed tx验证方法
h32_timestamp= final_tx_ts>>8; l8_timestamp = final_tx_ts&0xFF; sprintf(lcd_display_str, "%X%X",h32_timestamp,l8_timestamp); OLED_ShowString(0,4,(uint8_t *)lcd_display_str); last_tx_ts = get_tx_timestamp_u64(); h32_timestamp= last_tx_ts>>8; l8_timestamp = last_tx_ts&0xFF; sprintf(lcd_display_str, "%X%X",h32_timestamp,l8_timestamp); OLED_ShowString(0,6,(uint8_t *)lcd_display_str);
验证方法是把delayed tx timestamp打印出来,同时打印发送tx_timestamp,比较二者是否一致。
上述代码将两个时间放在液晶上显示,观察到两个数据完全一样,说明delayed tx code 没有问题
3注意问题:
final_tx_ts 所有40bit都是有效的,而last_tx_ts低9bit 一直为0,两者比较的时候需要忽略低9bit
4其它问题:
64bit 显示有如下问题,中间需要加变量,具体原因没有去深入查资料,有明白的同学可以留言指导
last_rx_ts= 0x123456789A;
sprintf(lcd_display_str, "%X%X",last_rx_ts>>32,last_rx_ts);
液晶上显示120
last_rx_ts= 0x123456789A;
sprintf(lcd_display_str, "%X%X",last_rx_ts,last_rx_ts>>32);
液晶上显示3456789A12
更多内容参考蓝点无限论坛bphero.com.cn