diff --git a/components/esp_eth/include/esp_eth_mac_esp.h b/components/esp_eth/include/esp_eth_mac_esp.h index d75e3fc387..0037abfb6d 100644 --- a/components/esp_eth/include/esp_eth_mac_esp.h +++ b/components/esp_eth/include/esp_eth_mac_esp.h @@ -197,7 +197,8 @@ typedef enum { ETH_MAC_ESP_CMD_ADJ_PTP_FREQ, /*!< Adjust current PTP time frequency increment by scale factor */ ETH_MAC_ESP_CMD_ADJ_PTP_TIME, /*!< Adjust base PTP time frequency increment by PPS */ ETH_MAC_ESP_CMD_S_TARGET_TIME, /*!< Set Target Time at which interrupt is invoked when PTP time exceeds this value*/ - ETH_MAC_ESP_CMD_S_TARGET_CB /*!< Set pointer to a callback function invoked when PTP time exceeds Target Time */ + ETH_MAC_ESP_CMD_S_TARGET_CB, /*!< Set pointer to a callback function invoked when PTP time exceeds Target Time */ + ETH_MAC_ESP_CMD_ENABLE_TS4ALL /*!< Enable timestamp for all received frames */ } eth_mac_esp_io_cmd_t; #ifdef SOC_EMAC_IEEE1588V2_SUPPORTED diff --git a/components/esp_eth/src/mac/esp_eth_mac_esp.c b/components/esp_eth/src/mac/esp_eth_mac_esp.c index c9f9084b8e..71e1db99c1 100644 --- a/components/esp_eth/src/mac/esp_eth_mac_esp.c +++ b/components/esp_eth/src/mac/esp_eth_mac_esp.c @@ -364,6 +364,12 @@ esp_err_t emac_esp_custom_ioctl(esp_eth_mac_t *mac, int cmd, void *data) "failed to set PTP target time"); break; } + case ETH_MAC_ESP_CMD_ENABLE_TS4ALL: { + ESP_RETURN_ON_FALSE(data, ESP_ERR_INVALID_ARG, TAG, "PTP enable TS for all invalid argument, cant' be NULL"); + bool enable = *(bool *)data; + ESP_RETURN_ON_ERROR(emac_hal_ptp_enable_ts4all(&emac->hal, enable), TAG, "failed to enable timestamping for all frames"); + break; + } #else case ETH_MAC_ESP_CMD_PTP_ENABLE: case ETH_MAC_ESP_CMD_S_PTP_TIME: @@ -372,7 +378,8 @@ esp_err_t emac_esp_custom_ioctl(esp_eth_mac_t *mac, int cmd, void *data) case ETH_MAC_ESP_CMD_ADJ_PTP_FREQ: case ETH_MAC_ESP_CMD_S_TARGET_CB: case ETH_MAC_ESP_CMD_S_TARGET_TIME: - return ESP_ERR_NOT_SUPPORTED; + case ETH_MAC_ESP_CMD_ENABLE_TS4ALL: + return ESP_ERR_NOT_SUPPORTED; #endif case ETH_MAC_ESP_CMD_SET_TDES0_CFG_BITS: ESP_RETURN_ON_FALSE(data != NULL, ESP_ERR_INVALID_ARG, TAG, "cannot set DMA tx desc flag to null"); diff --git a/components/hal/emac_hal.c b/components/hal/emac_hal.c index 5fa476dce8..c90fb8ec5f 100644 --- a/components/hal/emac_hal.c +++ b/components/hal/emac_hal.c @@ -517,6 +517,12 @@ esp_err_t emac_hal_ptp_set_target_time(emac_hal_context_t *hal, uint32_t seconds emac_ll_ts_target_int_trig_enable(hal->ptp_regs); return ESP_OK; } + +esp_err_t emac_hal_ptp_enable_ts4all(emac_hal_context_t *hal, bool enable) +{ + emac_ll_ts_all_enable(hal->ptp_regs, enable); + return ESP_OK; +} #endif // SOC_EMAC_IEEE1588V2_SUPPORTED diff --git a/components/hal/include/hal/emac_hal.h b/components/hal/include/hal/emac_hal.h index f911c62759..7787f82374 100644 --- a/components/hal/include/hal/emac_hal.h +++ b/components/hal/include/hal/emac_hal.h @@ -415,6 +415,16 @@ esp_err_t emac_hal_ptp_get_sys_time(emac_hal_context_t *hal, uint32_t *seconds, */ esp_err_t emac_hal_ptp_set_target_time(emac_hal_context_t *hal, uint32_t seconds, uint32_t nano_seconds); +/** + * @brief Enable rx/tx timestamps for all Ethernet frames + * + * @param hal EMAC HAL context infostructure + * @param enable timestamping for non-PTP Ethernet frames + * @return + * - ESP_OK on success + */ +esp_err_t emac_hal_ptp_enable_ts4all(emac_hal_context_t *hal, bool enable); + /** * @brief Get timestamp from receive descriptor *