aes67_hw_timer.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * SPDX-FileCopyrightText: 2026 DatanoiseTV
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /*
  7. * Hardware PTP-synchronized audio frame timer.
  8. *
  9. * Uses the EMAC target time interrupt to fire a callback at precise
  10. * PTP-synchronized intervals, replacing software-based timing with
  11. * hardware-precision audio frame boundaries.
  12. */
  13. #pragma once
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include "esp_err.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /* Callback fired at each audio frame boundary from ISR context.
  21. * Must be IRAM_ATTR and as brief as possible - typically just
  22. * gives a semaphore or sets a flag. */
  23. typedef void (*aes67_hw_timer_cb_t)(void *user_data);
  24. /**
  25. * Initialize the hardware PTP frame timer.
  26. *
  27. * @param frame_period_ns Frame period in nanoseconds (e.g. 1000000 for 1ms)
  28. * @param cb Callback to fire at each frame boundary
  29. * @param user_data User data passed to callback
  30. * @return ESP_OK on success
  31. */
  32. esp_err_t aes67_hw_timer_init(uint32_t frame_period_ns,
  33. aes67_hw_timer_cb_t cb, void *user_data);
  34. /**
  35. * Start the hardware frame timer. Programs the first target time
  36. * aligned to the next PTP-time frame boundary.
  37. */
  38. esp_err_t aes67_hw_timer_start(void);
  39. /**
  40. * Stop the hardware frame timer.
  41. */
  42. esp_err_t aes67_hw_timer_stop(void);
  43. #ifdef __cplusplus
  44. }
  45. #endif