ptp.c
void ptp_perform_correction()
{
    // timestamps and time intervals
    struct TimestampI d, syncMa, syncSl, delReqSl, delReqMa;

    // copy timestamps to assign then with meaningful names
    syncMa = sSyncData.t1;
    syncSl = sSyncData.t2;
    delReqSl = sSyncData.t3;
    delReqMa = sSyncData.t4;

    // compute difference between master and slave clock
    subTime(&d, &syncSl, &syncMa); // t2 - t1 ...
    subTime(&d, &d, &delReqMa); // - t4 ...
    addTime(&d, &d, &delReqSl); // + t3
    divTime(&d, &d, 2); // division by 2

    // substract offset
    subTime(&d, &d, &sOptions.offset);

    // normalize time difference (eliminate malformed time value issues)
    normTime(&d);

    // translate time difference into clock tick unit
    int32_t d_ticks = tsToTick(&d, PTP_CLOCK_TICK_FREQ_HZ);

    // if time difference is at least one second, then jump the clock
    if (d.sec != 0)
    {
        PTP_UPDATE_CLOCK(d.sec, d.nanosec); // jump the clock by difference

        MSG("Time difference is over 1s, performing coarse correction!\n");
        return;
    }

    // run controller
    float corr_ppb = PTP_SERVO_RUN(nsI(&d));

    // compute addend value
    addend += corr_ppb * PTP_ADDEND_CORR_PER_PPB_F;

    // write addend into hardware
    PTP_SET_ADDEND(addend);

    // log on cli (if enabled)
    CLILOG(log_en, "%d %d %d %d %d %d %d 0x%X\n", (int32_t )syncMa.sec, syncMa.nanosec, (int32_t )delReqMa.sec, delReqMa.nanosec, (int32_t ) d.sec, d.nanosec, d_ticks, addend);

}
// perform clock correction based on gathered timestamps (NON-REENTRANT!)
perform clock correction based on gathered timestamps (NON-REENTRANT!)
perform clock correction based on gathered timestamps ( NON - REENTRANT! )
void ptp_perform_correction()
{
    struct TimestampI d, syncMa, syncSl, delReqSl, delReqMa;
    syncMa = sSyncData.t1;
    syncSl = sSyncData.t2;
    delReqSl = sSyncData.t3;
    delReqMa = sSyncData.t4;
    subTime(&d, &syncSl, &syncMa); 
    subTime(&d, &d, &delReqMa); 
    addTime(&d, &d, &delReqSl); 
    divTime(&d, &d, 2); 
    subTime(&d, &d, &sOptions.offset);
    normTime(&d);
    int32_t d_ticks = tsToTick(&d, PTP_CLOCK_TICK_FREQ_HZ);
    if (d.sec != 0)
    {
        PTP_UPDATE_CLOCK(d.sec, d.nanosec); 
        MSG("Time difference is over 1s, performing coarse correction!\n");
        return;
    }
    float corr_ppb = PTP_SERVO_RUN(nsI(&d));
    addend += corr_ppb * PTP_ADDEND_CORR_PER_PPB_F;
    PTP_SET_ADDEND(addend);
    CLILOG(log_en, "%d %d %d %d %d %d %d 0x%X\n", (int32_t )syncMa.sec, syncMa.nanosec, (int32_t )delReqMa.sec, delReqMa.nanosec, (int32_t ) d.sec, d.nanosec, d_ticks, addend);
}
void ptp_perform_correction ( ) { struct TimestampI d , syncMa , syncSl , delReqSl , delReqMa ; syncMa = sSyncData . t1 ; syncSl = sSyncData . t2 ; delReqSl = sSyncData . t3 ; delReqMa = sSyncData . t4 ; subTime ( & d , & syncSl , & syncMa ) ; subTime ( & d , & d , & delReqMa ) ; addTime ( & d , & d , & delReqSl ) ; divTime ( & d , & d , 2 ) ; subTime ( & d , & d , & sOptions . offset ) ; normTime ( & d ) ; int32_t d_ticks = tsToTick ( & d , PTP_CLOCK_TICK_FREQ_HZ ) ; if ( d . sec != 0 ) { PTP_UPDATE_CLOCK ( d . sec , d . nanosec ) ; MSG ( " \n " ) ; return ; } float corr_ppb = PTP_SERVO_RUN ( nsI ( & d ) ) ; addend += corr_ppb * PTP_ADDEND_CORR_PER_PPB_F ; PTP_SET_ADDEND ( addend ) ; CLILOG ( log_en , " \n " , ( int32_t ) syncMa . sec , syncMa . nanosec , ( int32_t ) delReqMa . sec , delReqMa . nanosec , ( int32_t ) d . sec , d . nanosec , d_ticks , addend ) ; }
perform clock correction based on gathered timestamps (NON-REENTRANT!)
perform clock correction based on gathered timestamps ( NON - REENTRANT! )
// timestamps and time intervals // copy timestamps to assign then with meaningful names // compute difference between master and slave clock // t2 - t1 ... // - t4 ... // + t3 // division by 2 // substract offset // normalize time difference (eliminate malformed time value issues) // translate time difference into clock tick unit // if time difference is at least one second, then jump the clock // jump the clock by difference // run controller // compute addend value // write addend into hardware // log on cli (if enabled)