Skip to content

Commit 48b37dd

Browse files
committed
Merge branch 'contrib/github_pr_16016' into 'master'
Enable Timestamping for Non-PTP Ethernet frames (GitHub PR) Closes IDFGH-15359 See merge request espressif/esp-idf!39581
2 parents 23d71fe + eae1f3c commit 48b37dd

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

components/esp_eth/include/esp_eth_mac_esp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ typedef enum {
197197
ETH_MAC_ESP_CMD_ADJ_PTP_FREQ, /*!< Adjust current PTP time frequency increment by scale factor */
198198
ETH_MAC_ESP_CMD_ADJ_PTP_TIME, /*!< Adjust base PTP time frequency increment by PPS */
199199
ETH_MAC_ESP_CMD_S_TARGET_TIME, /*!< Set Target Time at which interrupt is invoked when PTP time exceeds this value*/
200-
ETH_MAC_ESP_CMD_S_TARGET_CB /*!< Set pointer to a callback function invoked when PTP time exceeds Target Time */
200+
ETH_MAC_ESP_CMD_S_TARGET_CB, /*!< Set pointer to a callback function invoked when PTP time exceeds Target Time */
201+
ETH_MAC_ESP_CMD_ENABLE_TS4ALL /*!< Enable timestamp for all received frames */
201202
} eth_mac_esp_io_cmd_t;
202203

203204
#ifdef SOC_EMAC_IEEE1588V2_SUPPORTED

components/esp_eth/src/mac/esp_eth_mac_esp.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@ esp_err_t emac_esp_custom_ioctl(esp_eth_mac_t *mac, int cmd, void *data)
364364
"failed to set PTP target time");
365365
break;
366366
}
367+
case ETH_MAC_ESP_CMD_ENABLE_TS4ALL: {
368+
ESP_RETURN_ON_FALSE(data, ESP_ERR_INVALID_ARG, TAG, "PTP enable TS for all invalid argument, cant' be NULL");
369+
bool enable = *(bool *)data;
370+
ESP_RETURN_ON_ERROR(emac_hal_ptp_enable_ts4all(&emac->hal, enable), TAG, "failed to enable timestamping for all frames");
371+
break;
372+
}
367373
#else
368374
case ETH_MAC_ESP_CMD_PTP_ENABLE:
369375
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)
372378
case ETH_MAC_ESP_CMD_ADJ_PTP_FREQ:
373379
case ETH_MAC_ESP_CMD_S_TARGET_CB:
374380
case ETH_MAC_ESP_CMD_S_TARGET_TIME:
375-
return ESP_ERR_NOT_SUPPORTED;
381+
case ETH_MAC_ESP_CMD_ENABLE_TS4ALL:
382+
return ESP_ERR_NOT_SUPPORTED;
376383
#endif
377384
case ETH_MAC_ESP_CMD_SET_TDES0_CFG_BITS:
378385
ESP_RETURN_ON_FALSE(data != NULL, ESP_ERR_INVALID_ARG, TAG, "cannot set DMA tx desc flag to null");

components/hal/emac_hal.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,12 @@ esp_err_t emac_hal_ptp_set_target_time(emac_hal_context_t *hal, uint32_t seconds
517517
emac_ll_ts_target_int_trig_enable(hal->ptp_regs);
518518
return ESP_OK;
519519
}
520+
521+
esp_err_t emac_hal_ptp_enable_ts4all(emac_hal_context_t *hal, bool enable)
522+
{
523+
emac_ll_ts_all_enable(hal->ptp_regs, enable);
524+
return ESP_OK;
525+
}
520526
#endif // SOC_EMAC_IEEE1588V2_SUPPORTED
521527

522528

components/hal/include/hal/emac_hal.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,16 @@ esp_err_t emac_hal_ptp_get_sys_time(emac_hal_context_t *hal, uint32_t *seconds,
415415
*/
416416
esp_err_t emac_hal_ptp_set_target_time(emac_hal_context_t *hal, uint32_t seconds, uint32_t nano_seconds);
417417

418+
/**
419+
* @brief Enable rx/tx timestamps for all Ethernet frames
420+
*
421+
* @param hal EMAC HAL context infostructure
422+
* @param enable timestamping for non-PTP Ethernet frames
423+
* @return
424+
* - ESP_OK on success
425+
*/
426+
esp_err_t emac_hal_ptp_enable_ts4all(emac_hal_context_t *hal, bool enable);
427+
418428
/**
419429
* @brief Get timestamp from receive descriptor
420430
*

0 commit comments

Comments
 (0)