亲爱的大家,我想开发PTP IEEE 1588。
但发现了一些问题:
1)起初,我使用ne
tif并获得IP(就像 \examples\ethernet\basic ),然后使用eth广播一个缓冲区(我参考 \components\esp_eth\test_apps\main\esp_eth_test.c),程序运行正常,我在 wireshark 中从 esp32 获取数据包。
2) 然后,我修改“esp_eth_mac_new_esp32()”。
我只是让“emac_esp32_t *emac = NULL”在函数外定义,让它成为一个 gloable var,我可以访问“hal.tx_desc->TimeStampLow”和“hal.tx_desc->TimeStampHigh”我做了一个循环等待“
emac ->hal.tx_desc->TDES0.FirstSegment”和“TDES0.LastSegment”变为1,这个也实现了。
3)
我发现“emac->hal.tx_desc->TDES0.TxTimestampStatus”永远不会变成 1。并且时间戳的值始终为 0。我已经检查“TDES0.TransmitTimestampEnable”是否为 1。
所以,我该怎么办。下面是主要程序。
void app_main(void)
{
// 初始化 TCP/IP 网络接口(应在应用程序中只调用一次)
ESP_ERROR_CHECK(esp_netif_init());
// 创建在后台运行的默认事件循环
ESP_ERROR_CHECK(esp_event_loop_create_default());
// 为以太网创建 esp-netif 的新默认实例
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
esp_netif_t *eth_netif = esp_netif_new(&cfg);
// 将 MAC 和 PHY 配置初始化为默认值
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR;
phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO;
mac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO;
mac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO;
esp_eth_mac_t *mac = esp_eth_mac_new_esp32_2(&mac_config); // 使用修改后的函数
esp_eth_phy_t *phy = esp_eth_phy_new_lan87xx(&phy_config);
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
esp_eth_handle_t eth_handle = NULL;
ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
//----------------初始化netif-------------------------------- -
// 将以太网驱动程序附加到 TCP/IP 堆栈
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)));
//TDES0.TransmitTimestampEnable
ESP_LOGI(TAG, "\n\n TransmitTimestampEnable:%d",emac->hal.tx_desc->TDES0.TransmitTimestampEnable);
//------------广播--------------------
SemaphoreHandle_t mutex = xSemaphoreCreateBinary();
esp_event_loop_create_default();
esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, mutex);
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));
emac->hal.tx_desc->TDES0.TxTimestampStatus = 1;
ESP_LOGI(TAG, "\n\n TxTimestampStatus:%d",emac->hal.tx_desc->TDES0.TxTimestampStatus);
ESP_ERROR_CHECK(esp_eth_start(eth_handle));
ESP_LOGI(TAG, "\n\n TxTimestampStatus:%d",emac->hal.tx_desc->TDES0.TxTimestampStatus);
xSemaphoreTake(互斥锁,pdMS_TO_TICKS(3000));
// 即使 PHY (IP101) 指示自动协商完成并连接,它有时可能会在 atonego 重置后丢失几个数据包,因此请稍等
vTaskDelay(pdMS_TO_TICKS(100));
ESP_LOGI(TAG, "\n\n TxTimestampStatus:%d",emac->hal.tx_desc->TDES0.TxTimestampStatus);
emac_frame_t *pkt = malloc(1024);
pkt->proto = 0x2222;
memset(pkt->dest, 0xff, 6); // 广播地址
printf("packet len:%d\n", 40 - ETH_HEADER_LEN);
对于 (int i = 0; i < (40 - ETH_HEADER_LEN); ++i){
pkt->data
= i & 0xff;
}
esp_eth_transmit(eth_handle, pkt, 40);
vTaskDelay(pdMS_TO_TICKS(100));
免费(包);
/*
ESP_ERROR_CHECK(esp_eth_stop(eth_handle));
ESP_ERROR_CHECK(esp_event_loop_delete_default());
ESP_ERROR_CHECK(esp_eth_driver_uninstall(eth_handle));
phy->del(phy);
mac->del(mac);
vSemaphoreDelete(互斥体);
*/
printf("等待时间戳\n");
while(emac->hal.tx_desc->TDES0.FirstSegment == 0) {
printf("仍在等待时间戳\n");
vTaskDelay(pdMS_TO_TICKS(10));
}
//------------尝试捕获时间戳----------------
ESP_LOGI(TAG, "\n\n TxTimestampStatus: %d",emac->hal.tx_desc->TDES0.TxTimestampStatus);
//TDES0.TransmitTimestampEnable
ESP_LOGI(TAG, "\n\n TransmitTimestampEnable:%d",emac->hal.tx_desc->TDES0.TransmitTimestampEnable);
ESP_LOGI(TAG, "如果 tx 时间戳可用 TDES0.FirstSegment %d TDES0.LastSegment %d",emac->hal.tx_desc->TDES0.FirstSegment,
emac->hal.tx_desc->TDES0。
ESP_LOGI(TAG, "tx timestmap: TimeStampLow:%d, TimeStampHigh:%d\n", emac->hal.tx_desc->TimeStampLow,
emac->hal.tx_desc->TimeStampHigh );
/*
ESP_LOGI(TAG, "如果 rx 时间戳可用,RDES0.LastDescriptor: %d ",emac->hal.rx_desc->RDES0.LastDescriptor );
ESP_LOGI(TAG, "rx timestmap: TimeStampLow %d TimeStampHigh %d\n",emac->hal.rx_desc->TimeStampLow,
emac->hal.rx_desc->TimeStampHigh );
*/
ESP_LOGI(TAG, "Buffer1Addr:%d, Buffer2NextDescAddr %d\n",emac->hal.tx_desc->Buffer1Addr,
emac->hal.tx_desc->Buffer2NextDescAddr);
ESP_LOGI(TAG,"捕获系统时间 %lld", esp_timer_get_time() );
ESP_LOGI(TAG, "\n\n TxTimestampStatus:%d",emac->hal.tx_desc->TDES0.TxTimestampStatus);
while(emac->hal.tx_desc->TDES0.TxTimestampStatus == 0) {
//printf("仍在等待 TTTS 变为 1\n");
emac->hal.tx_desc->TDES0.TxTimestampStatus = 1;
ESP_LOGI(TAG, "1 TxTimestampStatus:%d",emac->hal.tx_desc->TDES0.TxTimestampStatus);
esp_eth_transmit(eth_handle, pkt, 40);
ESP_LOGI(TAG, "2 TxTimestampStatus:%d",emac->hal.tx_desc->TDES0.TxTimestampStatus);
//vTaskDelay(pdMS_TO_TICKS(10));
ESP_LOGI(TAG, "如果 tx 时间戳可用 TDES0.FirstSegment %d TDES0.LastSegment %d",emac->hal.tx_desc->TDES0。
emac->hal.tx_desc->TDES0.LastSegment );
ESP_LOGI(TAG, "tx timestmap: TimeStampLow:%d, TimeStampHigh:%d\n", emac->hal.tx_desc->TimeStampLow,
emac->hal.tx_desc->TimeStampHigh );
}
printf("完成!\n");
//------------广播结束--------------------
}