AnsweredAssumed Answered

KSDK1.3 ENET_DRV_Adjust1588timer bug

Question asked by Jose Raffucci on Dec 4, 2015
Latest reply on Dec 10, 2015 by Iva Dorazinova

I've been working on getting PTP working on the K64FRDM board with KSDK1.3 and I found a a transposition error in the current ENET_DRV/ENET_HAL.  The HAL function kept barfing on the first (increaseCorrection) assertion when I tried to adjust the clock frequency. The correction factor appeared to be correct.

 

fsl_enet_hal.h:

 

static inline void ENET_HAL_Adjust1588Timer(ENET_Type * base, uint32_t increaseCorrection, uint32_t periodCorrection)  {
    assert(increaseCorrection <= ENET_ATINC_INC_MASK);  <== value C0A, Mask 7F
    assert(periodCorrection <= ENET_ATCOR_COR_MASK);
    /* Set correction for PTP timer increment*/
          ENET_BWR_ATINC_INC_CORR(base, increaseCorrection);
     /* Set correction for PTP timer period*/
     ENET_BWR_ATCOR_COR(base, periodCorrection);
}

 

Hours of debugging later (in PTP code of course) eventually led me to the call in ENET_DRV_Adjust1588timer().

 

fsl_enet_driver.c:

 

        /* Calculate the clock correction increase value*/
         if (drift < 0)         {
             corrIncrease = clockIncrease - corrIncrease;
         }
         else
         {
             corrIncrease = clockIncrease + corrIncrease;

         }

 

         /* Adjust the ptp timer*/
         ENET_HAL_Adjust1588Timer(base, corrPeriod, corrIncrease);
     }
     else
     {

         /* Adjust the ptp timer*/
         ENET_HAL_Adjust1588Timer(base, 0, clockIncrease);
     }

 

     return kStatus_ENET_Success;
}

 

 

It doesn't look like anybody's tested this with a real PTP server.  Boo for not paying attention when porting.  Kudos for using assertions and saving me a few more days of debugging.

Outcomes