Skip to content

Commit 5d05592

Browse files
ZhaoQiang-b45475dleach02
authored andcommitted
mcux: netc: ptp_clock: Correct function NETC_TimerAdjustFreq
The TMR_CTRL[period] is integral period of the timer clock in ns, while TMR_ADD represents the fractional clock period. So TMR_CTRL[period] should be updated too. Signed-off-by: Qiang Zhao <qiang.zhao@nxp.com>
1 parent 4fa5cab commit 5d05592

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

mcux/mcux-sdk-ng/drivers/netc/fsl_netc_timer.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2023 NXP
2+
* Copyright 2022-2023, 2025 NXP
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
@@ -67,7 +67,6 @@ void NETC_TimerInitHandle(netc_timer_handle_t *handle)
6767
status_t NETC_TimerInit(netc_timer_handle_t *handle, const netc_timer_config_t *config)
6868
{
6969
status_t result = kStatus_Success;
70-
uint32_t period = NETC_NANOSECOND_ONE_SECOND / config->refClkHz;
7170

7271
/* Initialize the handle. */
7372
NETC_TimerInitHandle(handle);
@@ -90,10 +89,9 @@ status_t NETC_TimerInit(netc_timer_handle_t *handle, const netc_timer_config_t *
9089
return result;
9190
}
9291

93-
handle->hw.base->TMR_CTRL =
94-
ENETC_PF_TMR_TMR_CTRL_TCLK_PERIOD(period) | ENETC_PF_TMR_TMR_CTRL_COPH(config->clkOutputPhase) |
92+
handle->hw.base->TMR_CTRL = ENETC_PF_TMR_TMR_CTRL_COPH(config->clkOutputPhase) |
9593
ENETC_PF_TMR_TMR_CTRL_CIPH(config->clkInputPhase) | ENETC_PF_TMR_TMR_CTRL_TE(config->enableTimer) |
96-
ENETC_PF_TMR_TMR_CTRL_COMP_MODE(config->atomicMode) | ENETC_PF_TMR_TMR_CTRL_CK_SEL(config->clockSelect);
94+
ENETC_PF_TMR_TMR_CTRL_COMP_MODE(1U) | ENETC_PF_TMR_TMR_CTRL_CK_SEL(config->clockSelect);
9795

9896
NETC_TimerAdjustFreq(handle, config->defaultPpb);
9997

@@ -402,6 +400,7 @@ void NETC_TimerAdjustFreq(netc_timer_handle_t *handle, int32_t ppb)
402400
{
403401
int64_t offset = 1000000000LL + ppb;
404402
uint64_t addend;
403+
uint32_t control;
405404

406405
/* period (in ns) is given by: 10^9 / freq */
407406
/* ppb is applied to period: period' = period * (1 + ppb / 10^9) */
@@ -410,6 +409,9 @@ void NETC_TimerAdjustFreq(netc_timer_handle_t *handle, int32_t ppb)
410409
/* addend' = 10^9 / freq * (1 + ppp / 10^9) * 2^32 = (2^32 * (10^9 + ppb)) / freq */
411410
addend = (((uint64_t)1ULL << 32) * (uint64_t)offset) / handle->timerFreq;
412411

412+
control = handle->hw.base->TMR_CTRL & ~ENETC_PF_TMR_TMR_CTRL_TCLK_PERIOD_MASK;
413+
handle->hw.base->TMR_CTRL = control | ENETC_PF_TMR_TMR_CTRL_TCLK_PERIOD((uint32_t)(addend >> 32));
414+
413415
handle->hw.base->TMR_ADD = (uint32_t)addend;
414416
}
415417

mcux/mcux-sdk-ng/drivers/netc/fsl_netc_timer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ typedef struct _netc_timer_config
116116
bool clkInputPhase; /*!< True: Inverted frequency tuned timer input clock, False: Non-inverted frequency tuned timer
117117
input clock. */
118118
bool enableTimer; /*!< True: Enable 1588 timer, False: Disable 1588 timer, use default counter. */
119-
bool atomicMode; /*!< True: Allow atomic updates to TMR_PERIOD and TMR_ADD, False: Disable it. */
120119
netc_timer_ref_clk_t clockSelect; /*!< Timer reference clock. */
121120
uint32_t refClkHz; /*!< Timer reference clock frequency in Hz. */
122121
int32_t defaultPpb; /*!< Default ppb. */

0 commit comments

Comments
 (0)