flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
logging.c
Go to the documentation of this file.
1#include "logging.h"
2#include "ptp_core.h"
3
4#include <flexptp_options.h>
5
7#define S (gPtpCoreState)
9
10// enable/disable general logging
11static void ptp_log_def_en(bool en) {
12 if (en) { // on turning on
13 MSG("\n\nT1 [s] | T1 [ns] | T4 [s] | T4 [ns] | Dt [s] | Dt [ns] |"
15 " Dt [tick] | addend |"
16#elif defined(PTP_HLT_INTERFACE)
17 " tuning_ppb |"
18#endif
19 " corr_ppb | mpd_ns | sync_period_ns\n\n");
20 }
21}
22
23// ------------------------
24
30typedef void (*LogEnFn)(bool en);
31
35typedef struct {
36 int id;
38 bool *en;
40
42 {PTP_LOG_DEF, ptp_log_def_en, &(S.logging.def)},
43 {PTP_LOG_CORR_FIELD, NULL, &(S.logging.corr)},
44 {PTP_LOG_TIMESTAMPS, NULL, &(S.logging.timestamps)},
45 {PTP_LOG_INFO, NULL, &(S.logging.info)},
46 {PTP_LOG_LOCKED_STATE, NULL, &(S.logging.locked)},
47 {PTP_LOG_BMCA, NULL, &(S.logging.bmca)},
48 {PTP_LOG_TRANSMISSION, NULL, &(S.logging.transmission)},
49 {PTP_LOG_LOGID, NULL, &(S.logging.logid)},
50 {-1, NULL, NULL}};
51
52void ptp_log_enable(int logId, bool en) {
53 PtpLogPair *pIter = sLogTable;
54 while (pIter->id != -1) {
55 if (pIter->id == logId && *(pIter->en) != en) { // if callback is found and changing state indeed
56 if (pIter->logEnFn != NULL) { // callback function is not necessary
57 pIter->logEnFn(en);
58 }
59 *(pIter->en) = en;
60 break;
61 }
62 pIter++;
63 }
64}
65
67 PtpLogPair *pIter = sLogTable;
68 while (pIter->logEnFn != NULL) {
69 if (pIter->logEnFn != NULL) {
70 pIter->logEnFn(false);
71 }
72 *(pIter->en) = false;
73 pIter++;
74 }
75}
#define PTP_ADDEND_INTERFACE
#define PTP_HLT_INTERFACE
static void ptp_log_def_en(bool en)
Definition: logging.c:11
static PtpLogPair sLogTable[PTP_LOG_N+1]
Definition: logging.c:41
void ptp_log_disable_all()
Definition: logging.c:66
void(* LogEnFn)(bool en)
Definition: logging.c:30
void ptp_log_enable(int logId, bool en)
Definition: logging.c:52
This module handles various logging capabilities.
@ PTP_LOG_TRANSMISSION
Message transmission logging.
Definition: logging.h:28
@ PTP_LOG_BMCA
Notifies the user about BMCA state changes.
Definition: logging.h:27
@ PTP_LOG_INFO
If enabled, the user will be notified of unexpected events occurred and exceptions.
Definition: logging.h:25
@ PTP_LOG_N
Definition: logging.h:30
@ PTP_LOG_CORR_FIELD
The PTP engine will print the correction fields of particular PTP messages.
Definition: logging.h:23
@ PTP_LOG_LOCKED_STATE
Signals the user if the PTP engine considers the clock have gotten locked.
Definition: logging.h:26
@ PTP_LOG_LOGID
Prints formatted identifier before each log line.
Definition: logging.h:29
@ PTP_LOG_TIMESTAMPS
The PTP engine will print the T1-T4/T6 timestamps (in E2E/P2P modes).
Definition: logging.h:24
@ PTP_LOG_DEF
Default PTP log, prints sync-cycle related data (e.g. time error, tuning, code word etc....
Definition: logging.h:22
Core of the PTP implementation. Defines functions for message processing, clock tuning,...
PTP log pair.
Definition: logging.c:35
bool * en
variable storing log state
Definition: logging.c:38
int id
ID of log type.
Definition: logging.c:36
LogEnFn logEnFn
Callback function on turning on/off logging.
Definition: logging.c:37