Skip to content

File syn_port_hpclock.h

FileList > port > syn_port_hpclock.h

Go to the source code of this file

High-precision clock port interface — implement for your platform. More...

  • #include <stdint.h>

Public Attributes

Type Name
volatile uint32_t syn_hpclock_msb
Global overflow counter — incremented by the platform ISR.

Public Functions

Type Name
uint32_t syn_port_hpclock_freq_hz (void)
Return the timer clock frequency in Hz.
volatile uint32_t * syn_port_hpclock_lsb_ptr (void)
Return a pointer to the hardware timer count register.

Macros

Type Name
define SYN_HPCLOCK_OVERFLOW_TICK () ([**syn\_hpclock\_msb**](syn__hpclock_8c.md#variable-syn_hpclock_msb)++)
Macro for the platform overflow ISR — one line, nothing else.

Detailed Description

Provides the hardware timer counter register and overflow counter that the syn_hpclock driver uses to construct 64-bit system-clock- precision timestamps.

Platform implementation checklist

  • Configure a free-running hardware timer at the system clock rate (or as fast as practical). For example, STM32 TIM2 in free-run mode, or AVR Timer1 with no prescaler.
  • Define syn_port_hpclock_lsb_ptr() to return a pointer to the timer's count register.
  • Enable the timer overflow interrupt and call SYN_HPCLOCK_OVERFLOW_TICK() from the ISR.
  • Define syn_port_hpclock_freq_hz() to return the timer's clock frequency.
  • The overflow ISR MUST have the highest interrupt priority in the system. The resolve algorithm assumes the overflow ISR can preempt any context that calls SYN_HPCLOCK_CAPTURE(). If a higher-priority ISR captures a timestamp while the overflow ISR is pended, the resolved tick will be silently wrong by one full counter period. There is no runtime detection of this error.

** **

// In your platform port file:
volatile uint32_t *syn_port_hpclock_lsb_ptr(void) {
    return &TIM2->CNT;
}

uint32_t syn_port_hpclock_freq_hz(void) {
    return 84000000UL;
}

// Priority 0 = highest on Cortex-M NVIC
void TIM2_IRQHandler(void) {
    SYN_HPCLOCK_OVERFLOW_TICK();
    LL_TIM_ClearFlag_UPDATE(TIM2);
}

Public Attributes Documentation

variable syn_hpclock_msb

Global overflow counter — incremented by the platform ISR.

volatile uint32_t syn_hpclock_msb;

Declared here so both the port ISR and the driver can access it. Defined in syn_hpclock.c.


Public Functions Documentation

function syn_port_hpclock_freq_hz

Return the timer clock frequency in Hz.

uint32_t syn_port_hpclock_freq_hz (
    void
) 

Used for tick-to-nanosecond conversion. Must be a compile-time constant or a value that does not change after initialization.

Returns:

Timer frequency in Hz (e.g. 16000000 for 16 MHz).


function syn_port_hpclock_lsb_ptr

Return a pointer to the hardware timer count register.

volatile uint32_t * syn_port_hpclock_lsb_ptr (
    void
) 

The returned pointer must be volatile and point to a memory-mapped register that increments at the rate returned by syn_port_hpclock_freq_hz().

Returns:

Pointer to the timer counter register.


Macro Definition Documentation

define SYN_HPCLOCK_OVERFLOW_TICK

Macro for the platform overflow ISR — one line, nothing else.

#define SYN_HPCLOCK_OVERFLOW_TICK (

) `( syn_hpclock_msb ++)`

Call this from your timer update/overflow interrupt handler. Do not add any other logic before this macro in the ISR.



The documentation for this class was generated from the following file src/syntropic/port/syn_port_hpclock.h