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] | Dt [tick] | addend | corr_ppb | mpd_ns | sync_period_ns\n\n");
14 }
15}
16
17// ------------------------
18
24typedef void (*LogEnFn)(bool en);
25
29typedef struct {
30 int id;
32 bool *en;
34
36 { PTP_LOG_DEF, ptp_log_def_en, &(S.logging.def) },
37 { PTP_LOG_CORR_FIELD, NULL, &(S.logging.corr) },
38 { PTP_LOG_TIMESTAMPS, NULL, &(S.logging.timestamps) },
39 { PTP_LOG_INFO, NULL, &(S.logging.info) },
40 { PTP_LOG_LOCKED_STATE, NULL, &(S.logging.locked) },
41 { PTP_LOG_BMCA, NULL, &(S.logging.bmca) },
42 { -1, NULL, NULL }
43};
44
45void ptp_log_enable(int logId, bool en) {
46 PtpLogPair *pIter = sLogTable;
47 while (pIter->id != -1) {
48 if (pIter->id == logId && *(pIter->en) != en) { // if callback is found and changing state indeed
49 if (pIter->logEnFn != NULL) { // callback function is not necessary
50 pIter->logEnFn(en);
51 }
52 *(pIter->en) = en;
53 break;
54 }
55 pIter++;
56 }
57}
58
60 PtpLogPair *pIter = sLogTable;
61 while (pIter->logEnFn != NULL) {
62 if (pIter->logEnFn != NULL) {
63 pIter->logEnFn(false);
64 }
65 *(pIter->en) = false;
66 pIter++;
67 }
68}
static void ptp_log_def_en(bool en)
Definition: logging.c:11
static PtpLogPair sLogTable[PTP_LOG_N+1]
Definition: logging.c:35
void ptp_log_disable_all()
Definition: logging.c:59
void(* LogEnFn)(bool en)
Definition: logging.c:24
void ptp_log_enable(int logId, bool en)
Definition: logging.c:45
This module handles various logging capabilities.
@ PTP_LOG_BMCA
Notifies the user about BMCA state changes.
Definition: logging.h:23
@ PTP_LOG_INFO
If enabled, the user will be notified of unexpected events occurred and exceptions.
Definition: logging.h:21
@ PTP_LOG_N
Definition: logging.h:24
@ PTP_LOG_CORR_FIELD
The PTP engine will print the correction fields of particular PTP messages.
Definition: logging.h:19
@ PTP_LOG_LOCKED_STATE
Signals the user if the PTP engine consideres the clock have gotten locked.
Definition: logging.h:22
@ PTP_LOG_TIMESTAMPS
The PTP engine will print the T1-T4/T6 timestamps (in E2E/P2P modes).
Definition: logging.h:20
@ PTP_LOG_DEF
Default PTP log, prints sync-cycle related data (e.g. time error, tuning, code word etc....
Definition: logging.h:18
Core of the PTP implementation. Defines functions for message processing, clock tuning,...
PTP log pair.
Definition: logging.c:29
bool * en
variable storing log state
Definition: logging.c:32
int id
ID of log type.
Definition: logging.c:30
LogEnFn logEnFn
Callback function on turning on/off logging.
Definition: logging.c:31