17#define MIN(a, b) (((a) < (b)) ? (a) : (b))
23#define MAX(a, b) (((a) > (b)) ? (a) : (b))
32static int CB_reset(
const CliToken_Type *ppArgs, uint8_t argc) {
34 MSG(
"> PTP reset!\n");
38static int CB_offset(
const CliToken_Type *ppArgs, uint8_t argc) {
47static int CB_log(
const CliToken_Type *ppArgs, uint8_t argc) {
51 if (!strcmp(ppArgs[1],
"on")) {
53 }
else if (!strcmp(ppArgs[1],
"off")) {
59 if (!strcmp(ppArgs[0],
"def")) {
61 }
else if (!strcmp(ppArgs[0],
"corr")) {
63 }
else if (!strcmp(ppArgs[0],
"ts")) {
65 }
else if (!strcmp(ppArgs[0],
"info")) {
67 }
else if (!strcmp(ppArgs[0],
"locked")) {
69 }
else if (!strcmp(ppArgs[0],
"bmca")) {
82static int CB_time(
const CliToken_Type *ppArgs, uint8_t argc) {
87 if (argc > 0 && !strcmp(ppArgs[0],
"ns")) {
91 MSG(
"%s\n", datetime);
97static int CB_master(
const CliToken_Type *ppArgs, uint8_t argc) {
99 if (!strcmp(ppArgs[0],
"prefer")) {
105 }
else if (!strcmp(ppArgs[0],
"unprefer")) {
110 MSG(
"Master clock ID: ");
116static int CB_ptpinfo(
const CliToken_Type *ppArgs, uint8_t argc) {
117 MSG(
"Own clock ID: ");
119 MSG(
"\nMaster clock ID: ");
125static int CB_ptpdomain(
const CliToken_Type *ppArgs, uint8_t argc) {
133static int CB_addend(
const CliToken_Type *ppArgs, uint8_t argc) {
141static int CB_transportType(
const CliToken_Type *ppArgs, uint8_t argc) {
143 if (!strcmp(ppArgs[0],
"ipv4")) {
145 }
else if (!strcmp(ppArgs[0],
"802.3")) {
154static int CB_delayMechanism(
const CliToken_Type *ppArgs, uint8_t argc) {
156 if (!strcmp(ppArgs[0],
"e2e")) {
158 }
else if (!strcmp(ppArgs[0],
"p2p")) {
167static int CB_transpec(
const CliToken_Type *ppArgs, uint8_t argc) {
169 if (!strcmp(ppArgs[0],
"def") || !strcmp(ppArgs[0],
"unknown")) {
171 }
else if (!strcmp(ppArgs[0],
"gPTP")) {
180static int CB_profile(
const CliToken_Type *ppArgs, uint8_t argc) {
181 bool printProfileSummary =
true;
182 if (argc > 0 && !strcmp(ppArgs[0],
"preset")) {
186 MSG(
"Loading preset '%s'...\n\n", ppArgs[1]);
189 MSG(
"Profile preset '%s' is unknown, settings untouched!\n", ppArgs[1]);
192 MSG(
"PTP profile presets: ");
195 for (i = 0; i < N; i++) {
202 printProfileSummary =
false;
206 if (printProfileSummary) {
212static int CB_tlv(
const CliToken_Type *ppArgs, uint8_t argc) {
213 bool printLoadedTlvPresetChain =
true;
215 if (!strcmp(ppArgs[0],
"preset")) {
219 MSG(
"Loading TLV-chain '%s'...\n\n", ppArgs[1]);
222 MSG(
"TLV-chain preset '%s' is unknown, settings are not tampered with!\n", ppArgs[1]);
224 printLoadedTlvPresetChain =
false;
227 MSG(
"TLV-chain presets: ");
230 for (i = 0; i < N; i++) {
238 printLoadedTlvPresetChain =
false;
240 }
else if (!strcmp(ppArgs[0],
"unload")) {
241 MSG(
"Unloading any TLV-chain...\n\n");
243 printLoadedTlvPresetChain =
false;
247 if (printLoadedTlvPresetChain) {
248 MSG(
"Loaded TLV-chain: ");
250 if (!strcmp(tlvSet,
"")) {
253 MSG(
"'%s'\n\n", tlvSet);
260static int CB_profile_flags(
const CliToken_Type *ppArgs, uint8_t argc) {
262 uint8_t pf = atoi(ppArgs[0]);
271static int CB_logPeriod(
const CliToken_Type *ppArgs, uint8_t argc) {
273 if (!strcmp(ppArgs[0],
"delreq")) {
274 if (!strcmp(ppArgs[1],
"match")) {
277 int8_t lp = atoi(ppArgs[1]);
281 }
else if (!strcmp(ppArgs[0],
"sync")) {
282 int8_t lp = atoi(ppArgs[1]);
285 }
else if (!strcmp(ppArgs[0],
"ann")) {
286 int8_t lp = atoi(ppArgs[1]);
292 MSG(
"(P)Delay_Req log. period: ");
306static int CB_coarseThreshold(
const CliToken_Type *ppArgs, uint8_t argc) {
315static int CB_priority(
const CliToken_Type *ppArgs, uint8_t argc) {
342 CMD_COARSE_THRESHOLD,
348static int sCmds[CMD_N + 1];
355 sCmds[CMD_RESET] =
CLI_REG_CMD(
"ptp reset \t\t\tReset PTP subsystem", 2, 0, CB_reset);
356 sCmds[CMD_OFFSET] =
CLI_REG_CMD(
"ptp servo offset [offset_ns] \t\t\tSet or query clock offset", 3, 0, CB_offset);
357 sCmds[CMD_LOG] =
CLI_REG_CMD(
"ptp log {def|corr|ts|info|locked|bmca} {on|off} \t\t\tTurn on or off logging", 2, 2, CB_log);
358 sCmds[CMD_TIME] =
CLI_REG_CMD(
"time [ns] \t\t\tPrint time", 1, 0, CB_time);
359 sCmds[CMD_MASTER] =
CLI_REG_CMD(
"ptp master [[un]prefer] [clockid] \t\t\tMaster clock settings", 2, 0, CB_master);
360 sCmds[CMD_PTPINFO] =
CLI_REG_CMD(
"ptp info \t\t\tPrint PTP info", 2, 0, CB_ptpinfo);
361 sCmds[CMD_PTPDOMAIN] =
CLI_REG_CMD(
"ptp domain [domain]\t\t\tPrint or set PTP domain", 2, 0, CB_ptpdomain);
362 sCmds[CMD_ADDEND] =
CLI_REG_CMD(
"ptp addend [addend]\t\t\tPrint or set addend", 2, 0, CB_addend);
363 sCmds[CMD_TRANSPORTTYPE] =
CLI_REG_CMD(
"ptp transport [{ipv4|802.3}]\t\t\tSet or get PTP transport layer", 2, 0, CB_transportType);
364 sCmds[CMD_DELAYMECH] =
CLI_REG_CMD(
"ptp delmech [{e2e|p2p}]\t\t\tSet or get PTP delay mechanism", 2, 0, CB_delayMechanism);
365 sCmds[CMD_TRANSPEC] =
CLI_REG_CMD(
"ptp transpec [{def|gPTP}]\t\t\tSet or get PTP transportSpecific field (majorSdoId)", 2, 0, CB_transpec);
366 sCmds[CMD_PROFILE] =
CLI_REG_CMD(
"ptp profile [preset [<name>]]\t\t\tPrint or set PTP profile, or list available presets", 2, 0, CB_profile);
367 sCmds[CMD_TLV] =
CLI_REG_CMD(
"ptp tlv [preset [name]|unload]\t\t\tPrint or set TLV-chain, or list available TLV presets", 2, 0, CB_tlv);
368 sCmds[CMD_PROFILE_FLAGS] =
CLI_REG_CMD(
"ptp pflags [<flags>]\t\t\tPrint or set profile flags", 2, 0, CB_profile_flags);
369 sCmds[CMD_LOGPERIOD] =
CLI_REG_CMD(
"ptp period <delreq|sync|ann> [<lp>|matched]\t\t\tPrint or set log. periods", 2, 0, CB_logPeriod);
370 sCmds[CMD_COARSE_THRESHOLD] =
CLI_REG_CMD(
"ptp coarse [threshold]\t\t\tPrint or set coarse correction threshold", 2, 0, CB_coarseThreshold);
371 sCmds[CMD_PRIORITY] =
CLI_REG_CMD(
"ptp priority [<p1> <p2>]\t\t\tPrint or set clock priority fields", 2, 0, CB_priority);
378 cli_remove_command_array(sCmds);
void ptp_register_cli_commands()
void ptp_remove_cli_commands()
This module handles and registers CLI commands. Commands:
void ptp_print_clock_identity(uint64_t clockID)
uint64_t hextoclkid(const char *str)
This module defines clock identity related operations.
#define CLI_REG_CMD(cmd_hintline, n_cmd, n_min_arg, cb)
void ptp_log_enable(int logId, bool en)
This module handles various logging capabilities.
@ PTP_LOG_BMCA
Notifies the user about BMCA state changes.
@ PTP_LOG_INFO
If enabled, the user will be notified of unexpected events occurred and exceptions.
@ PTP_LOG_CORR_FIELD
The PTP engine will print the correction fields of particular PTP messages.
@ PTP_LOG_LOCKED_STATE
Signals the user if the PTP engine consideres the clock have gotten locked.
@ PTP_LOG_TIMESTAMPS
The PTP engine will print the T1-T4/T6 timestamps (in E2E/P2P modes).
@ PTP_LOG_DEF
Default PTP log, prints sync-cycle related data (e.g. time error, tuning, code word etc....
char * PTP_TRANSPORT_TYPE_HINT[]
Hint on transport types.
char * PTP_TRANSPEC_HINT[]
Hint on transport specific field.
char * PTP_DELMECH_HINT[]
Hint on delay mechanism.
This module implements defines a single method that prints a verbose summary of the operating PTP pro...
Core of the PTP implementation. Defines functions for message processing, clock tuning,...
const PtpProfileTlvElement * ptp_tlv_chain_preset_get(const char *pName)
const char * ptp_tlv_chain_preset_get_name(size_t i)
const PtpProfile * ptp_profile_preset_get(const char *pName)
size_t ptp_tlv_chain_preset_cnt()
const char * ptp_profile_preset_get_name(size_t i)
size_t ptp_profile_preset_cnt()
This module manages predefined profile presets. It allows their fetching by name or ID.
This module defines the fundamental PTP message and state machine type, flags, bitfields and the PTP ...
@ PTP_TP_IPv4
IPv4 Transport Type.
@ PTP_TP_802_3
Ethernet Transport Type.
@ PTP_LOGPER_MAX
Maximal logarithmic messaging period.
@ PTP_LOGPER_MIN
Minimal logarithmic messaging period.
@ PTP_LOGPER_SYNCMATCHED
Messaging occurs whenever a Sync arrives.
@ PTP_DM_E2E
End-to-End Delay Mechanism.
@ PTP_DM_P2P
Peer-to-Peer Delay Mechanism.
@ PTP_TSPEC_GPTP_8021AS
802.1AS Transport Specific Flag
@ PTP_TSPEC_UNKNOWN_DEF
Unkown Transport Specific Flag (default)
void ptp_time(TimestampU *pT)
void ptp_set_delay_mechanism(PtpDelayMechanism dm)
uint64_t ptp_get_coarse_threshold()
void ptp_set_announce_log_period(int8_t alp)
PtpDelayMechanism ptp_get_delay_mechanism()
void ptp_set_delay_req_log_period(int8_t drlp)
int8_t ptp_get_announce_log_period()
void ptp_set_transport_type(PtpTransportType tp)
void ptp_set_clock_offset(int32_t offset)
PtpTransportType ptp_get_transport_type()
uint8_t ptp_get_priority2()
uint8_t ptp_get_profile_flags()
uint64_t ptp_get_current_master_clock_identity()
int8_t ptp_get_sync_log_period()
uint8_t ptp_get_priority1()
int8_t ptp_get_delay_req_log_period()
int32_t ptp_get_clock_offset()
void ptp_set_domain(uint8_t domain)
void ptp_set_priority2(uint8_t p2)
void ptp_set_addend(uint32_t addend)
PtpTransportSpecific ptp_get_transport_specific()
void ptp_set_sync_log_period(int8_t slp)
void ptp_set_transport_specific(PtpTransportSpecific tspec)
void ptp_unprefer_master_clock()
void ptp_prefer_master_clock(uint64_t clockId)
uint64_t ptp_get_own_clock_identity()
void ptp_set_tlv_chain_by_name(const char *tlvSet)
void ptp_set_priority1(uint8_t p1)
void ptp_set_profile_flags(uint8_t flags)
const char * ptp_get_loaded_tlv_chain()
uint32_t ptp_get_addend()
void ptp_load_profile(const PtpProfile *pProfile)
void ptp_set_coarse_threshold(uint64_t ns)
This module features functions to tweak around the PTP engine's almost every property.
PTP profile additional data list element.
uint32_t nanosec
nanoseconds
void tsPrint(char *str, const TimestampI *ts)