Skip to content

drivers: ptp_clock: add ptp_clock shell commands #89243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yangbolu1991
Copy link
Contributor

Added ptp_clock shell commands to check, use, and verify ptp clock. Supported get, set, adjust, rate adjust, and selftest functions.

return ret;
}

tm.second = strtoull(argv[2], NULL, 10);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make sense to use the shell_strtoull() and similar checkers that the shell provides, and then the conversion errors can be easily checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks a lot. I would have noticed them.

}

shell_print(sh, "adjust ratio %f, sleep 10s...", ratio);
k_sleep(K_MSEC(10000));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps allow user to set the delay instead of always blocking the shell for 10 secs.
So something like ptp_clock selftest <device> [<sleep delay, default 10 sec>]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. I think I should let user configure all args for selftest.
Because ptp hardware varies and something like rate limitation is different.

}

shell_print(sh, "adjust 3 seconds: %"PRIu64".%09u", tm.second, tm.nanosecond);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we able to give a better summary of the selftest, or was the plan that user can see the numbers and act accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, let me give a new version to review.
Will give a better description in help and print messages to explain what the selftest does.
Actually it's very easy to understand the tests.
Thanks.

Copy link
Contributor Author

@yangbolu1991 yangbolu1991 Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In v2, the help info is as below.

uart:~$ ptp_clock
ptp_clock - PTP clock commands
Subcommands:
  get       : Get time: get <device>
  set       : Set time: set <device> <seconds>
  adj       : Adjust time: adj <device> <seconds>
  freq      : Adjust frequency: freq <device> <ppb>
  selftest  : selftest <device> <time> <freq> <delay> <adj>
              The selftest will do following steps:
              1. set 'time' with seconds and read back to
              verify clock setting/getting.
              2. set 'freq' with ppb value, sleep 'delay' seconds,
              and read back time to verify rate adjustment.
              3. set 'adj' seconds and read back time to
              verify time adjustment.
              Example:
                 ptp_clock selftest ptp_clock 1000 100000000 10 10

The print messages will be as below.

uart:~$ ptp_clock selftest ptp_clock 1000 -10000000 10 10
test1: set time 1000.000000000
  result: read back time 1000.002214824
test2: adjust frequency -10000000 ppb (ratio 0.990000), delay 10 seconds...
  result: read back time 1009.929990349
test3: adjust time 10 seconds
  result: read back time 1009.935486840

Please ignore the adjust time issue. It indeed had issue on my platform:)
Thanks a lot.

@yangbolu1991
Copy link
Contributor Author

yangbolu1991 commented Apr 30, 2025

Updated to v2. Changes include,

  • Improved code per @jukkar suggestion.
  • Made user configure selftest args.

Thanks.

}

/* set 'time' seconds and read back to verify clock setting/getting */
tm.second = seconds;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seconds should be uint64_t. Please change shell_strtol() to shell_strtoull()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed in v3.

@yangbolu1991
Copy link
Contributor Author

Updated to v3. Changes include,

  • Fixed set time seconds with uint64_t.

Thanks.

@yangbolu1991 yangbolu1991 requested review from awojasinski and jukkar May 7, 2025 02:41
awojasinski
awojasinski previously approved these changes May 7, 2025
@yangbolu1991
Copy link
Contributor Author

yangbolu1991 commented May 14, 2025

Updated to v4. Changes include,

  • Just found the typo in v3 changes. I should have used shell_strtoull() not shell_strtoll(). Fixed.

Thanks.

@yangbolu1991
Copy link
Contributor Author

Rebased. Thanks.

@yangbolu1991
Copy link
Contributor Author

It seems some CI issue on code base.
Rebased, thanks.

Copy link
Member

@jukkar jukkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Added ptp_clock shell commands to check, use, and verify
ptp clock. Supported get, set, adjust, rate adjust, and
selftest functions.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants