Skip to content

Commit 68c4ba0

Browse files
author
andrew-elder
authored
Merge pull request #532 from AVnu/open-avb-next
Maintenance pull request from open-avb-next to master
2 parents 4d90c8a + d5d7d26 commit 68c4ba0

File tree

95 files changed

+5846
-4577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+5846
-4577
lines changed

daemons/gptp/README_GENIVI_DLT.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## Introduction
2+
This readme covers the **optional** feature to use GENIVI DLT (Diagnostic Log and Trace)
3+
for logging withiin gPTP. General information about GENIVI DLT can be found at:
4+
5+
Primary DLT site:
6+
https://at.projects.genivi.org/wiki/display/PROJ/Diagnostic+Log+and+Trace
7+
8+
DLT on GitHub:
9+
https://github.com/GENIVI/dlt-daemon
10+
11+
12+
## Build Related
13+
14+
DLT support in gPTP is a build time option.
15+
16+
### DLT must be built separately first before it can be used within gPTP.
17+
- Get the latest DLT from github
18+
- https://github.com/GENIVI/dlt-daemon.git
19+
- Follow instructions in INSTALL file.
20+
- For example (Building with Shared libraries off)
21+
- mkdir build
22+
- cd build
23+
- cmake -DBUILD_SHARED_LIBS=OFF ..
24+
- make
25+
- sudo make install
26+
- Install places static lib in: /usr/local/lib/x86_64-linux-gnu/static/libdlt.a
27+
- Install places header files in: /usr/local/include/dlt/dlt.h
28+
29+
### Building gPTP with DLT loggging enabled.
30+
- May need to update the gptp Makefile to specify location of DLT headers and lib
31+
- GENIVI_DLT=1 make gptp
32+
33+
34+
## Running
35+
### DLT
36+
- See the DLT documentaion about how to run the dlt-daemon.
37+
- For example
38+
- dlt-daemon -d
39+
- Runs the daemon
40+
- dlt-receive -a localhost
41+
- Simple test client included in DLT to recieve DLT messages.
42+
- dlt-user-example "Test message"
43+
- Test the DLT client and daemon.
44+
45+
### gPTP
46+
- Run as normal.
47+
48+

daemons/gptp/common/gptp_log.cpp

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,35 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3333
// MS VC++ 2013 has C++11 but not C11 support, use this to get millisecond resolution
3434
#include <chrono>
3535

36-
void gptpLog(const char *tag, const char *path, int line, const char *fmt, ...)
36+
#ifdef GENIVI_DLT
37+
DLT_DECLARE_CONTEXT(dlt_con_gptp);
38+
#endif
39+
40+
void gptplogRegister(void)
41+
{
42+
#ifdef GENIVI_DLT
43+
DLT_REGISTER_APP("GPTP","OpenAVB gPTP");
44+
DLT_REGISTER_CONTEXT(dlt_con_gptp, "GNRL", "General Context");
45+
#endif
46+
}
47+
48+
void gptplogUnregister(void)
49+
{
50+
#ifdef GENIVI_DLT
51+
DLT_UNREGISTER_CONTEXT(dlt_con_gptp);
52+
DLT_UNREGISTER_APP();
53+
#endif
54+
}
55+
56+
void gptpLog(GPTP_LOG_LEVEL level, const char *tag, const char *path, int line, const char *fmt, ...)
3757
{
3858
char msg[1024];
3959

4060
va_list args;
4161
va_start(args, fmt);
4262
vsprintf(msg, fmt, args);
4363

64+
#ifndef GENIVI_DLT
4465
std::chrono::system_clock::time_point cNow = std::chrono::system_clock::now();
4566
time_t tNow = std::chrono::system_clock::to_time_t(cNow);
4667
struct tm tmNow;
@@ -56,5 +77,37 @@ void gptpLog(const char *tag, const char *path, int line, const char *fmt, ...)
5677
fprintf(stderr, "%s: GPTP [%2.2d:%2.2d:%2.2d:%3.3ld] %s\n",
5778
tag, tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec, millis, msg);
5879
}
80+
#else
81+
DltLogLevelType dlt_level;
82+
83+
switch (level) {
84+
case GPTP_LOG_LVL_CRITICAL:
85+
dlt_level = DLT_LOG_FATAL;
86+
break;
87+
case GPTP_LOG_LVL_ERROR:
88+
dlt_level = DLT_LOG_ERROR;
89+
break;
90+
case GPTP_LOG_LVL_EXCEPTION:
91+
case GPTP_LOG_LVL_WARNING:
92+
dlt_level = DLT_LOG_WARN;
93+
break;
94+
case GPTP_LOG_LVL_INFO:
95+
case GPTP_LOG_LVL_STATUS:
96+
dlt_level = DLT_LOG_INFO;
97+
break;
98+
case GPTP_LOG_LVL_DEBUG:
99+
dlt_level = DLT_LOG_DEBUG;
100+
break;
101+
case GPTP_LOG_LVL_VERBOSE:
102+
dlt_level = DLT_LOG_VERBOSE;
103+
break;
104+
default:
105+
dlt_level = DLT_LOG_INFO;
106+
break;
107+
}
108+
109+
DLT_LOG(dlt_con_gptp, dlt_level, DLT_STRING(msg));
110+
#endif
111+
59112
}
60113

daemons/gptp/common/gptp_log.hpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,62 +32,84 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
#include <stdarg.h>
3333
#include <time.h>
3434

35+
#ifdef GENIVI_DLT
36+
#include "dlt.h"
37+
#endif
38+
3539
#define GPTP_LOG_CRITICAL_ON 1
3640
#define GPTP_LOG_ERROR_ON 1
37-
#define GPTP_LOG_EXCEPTION_ON 1
38-
#define GPTP_LOG_WARNING_ON 1
39-
#define GPTP_LOG_INFO_ON 1
41+
#define GPTP_LOG_EXCEPTION_ON 1
42+
#define GPTP_LOG_WARNING_ON 1
43+
#define GPTP_LOG_INFO_ON 1
4044
#define GPTP_LOG_STATUS_ON 1
4145
//#define GPTP_LOG_DEBUG_ON 1
4246
//#define GPTP_LOG_VERBOSE_ON 1
4347

48+
typedef enum {
49+
GPTP_LOG_LVL_CRITICAL,
50+
GPTP_LOG_LVL_ERROR,
51+
GPTP_LOG_LVL_EXCEPTION,
52+
GPTP_LOG_LVL_WARNING,
53+
GPTP_LOG_LVL_INFO,
54+
GPTP_LOG_LVL_STATUS,
55+
GPTP_LOG_LVL_DEBUG,
56+
GPTP_LOG_LVL_VERBOSE,
57+
} GPTP_LOG_LEVEL;
58+
59+
60+
void gptplogRegister(void);
61+
void gptplogUnregister(void);
62+
void gptpLog(GPTP_LOG_LEVEL level, const char *tag, const char *path, int line, const char *fmt, ...);
63+
64+
65+
#define GPTP_LOG_REGISTER() gptplogRegister()
4466

45-
void gptpLog(const char *tag, const char *path, int line, const char *fmt, ...);
67+
#define GPTP_LOG_UNREGISTER() gptplogUnregister()
4668

4769
#ifdef GPTP_LOG_CRITICAL_ON
48-
#define GPTP_LOG_CRITICAL(fmt,...) gptpLog("CRITICAL ", NULL, 0, fmt, ## __VA_ARGS__)
70+
#define GPTP_LOG_CRITICAL(fmt,...) gptpLog(GPTP_LOG_LVL_CRITICAL, "CRITICAL ", NULL, 0, fmt, ## __VA_ARGS__)
4971
#else
5072
#define GPTP_LOG_CRITICAL(fmt,...)
5173
#endif
5274

5375
#ifdef GPTP_LOG_ERROR_ON
54-
#define GPTP_LOG_ERROR(fmt,...) gptpLog("ERROR ", NULL, 0, fmt, ## __VA_ARGS__)
76+
#define GPTP_LOG_ERROR(fmt,...) gptpLog(GPTP_LOG_LVL_ERROR, "ERROR ", NULL, 0, fmt, ## __VA_ARGS__)
5577
#else
5678
#define GPTP_LOG_ERROR(fmt,...)
5779
#endif
5880

5981
#ifdef GPTP_LOG_EXCEPTION_ON
60-
#define GPTP_LOG_EXCEPTION(fmt,...) gptpLog("EXCEPTION", NULL, 0, fmt, ## __VA_ARGS__)
82+
#define GPTP_LOG_EXCEPTION(fmt,...) gptpLog(GPTP_LOG_LVL_EXCEPTION, "EXCEPTION", NULL, 0, fmt, ## __VA_ARGS__)
6183
#else
6284
#define GPTP_LOG_EXCEPTION(fmt,...)
6385
#endif
6486

6587
#ifdef GPTP_LOG_WARNING_ON
66-
#define GPTP_LOG_WARNING(fmt,...) gptpLog("WARNING ", NULL, 0, fmt, ## __VA_ARGS__)
88+
#define GPTP_LOG_WARNING(fmt,...) gptpLog(GPTP_LOG_LVL_WARNING, "WARNING ", NULL, 0, fmt, ## __VA_ARGS__)
6789
#else
6890
#define GPTP_LOG_WARNING(fmt,...)
6991
#endif
7092

7193
#ifdef GPTP_LOG_INFO_ON
72-
#define GPTP_LOG_INFO(fmt,...) gptpLog("INFO ", NULL, 0, fmt, ## __VA_ARGS__)
94+
#define GPTP_LOG_INFO(fmt,...) gptpLog(GPTP_LOG_LVL_INFO, "INFO ", NULL, 0, fmt, ## __VA_ARGS__)
7395
#else
7496
#define GPTP_LOG_INFO(fmt,...)
7597
#endif
7698

7799
#ifdef GPTP_LOG_STATUS_ON
78-
#define GPTP_LOG_STATUS(fmt,...) gptpLog("STATUS ", NULL, 0, fmt, ## __VA_ARGS__)
100+
#define GPTP_LOG_STATUS(fmt,...) gptpLog(GPTP_LOG_LVL_STATUS, "STATUS ", NULL, 0, fmt, ## __VA_ARGS__)
79101
#else
80102
#define GPTP_LOG_STATUS(fmt,...)
81103
#endif
82104

83105
#ifdef GPTP_LOG_DEBUG_ON
84-
#define GPTP_LOG_DEBUG(fmt,...) gptpLog("DEBUG ", __FILE__, __LINE__, fmt, ## __VA_ARGS__)
106+
#define GPTP_LOG_DEBUG(fmt,...) gptpLog(GPTP_LOG_LVL_DEBUG, "DEBUG ", __FILE__, __LINE__, fmt, ## __VA_ARGS__)
85107
#else
86108
#define GPTP_LOG_DEBUG(fmt,...)
87109
#endif
88110

89111
#ifdef GPTP_LOG_VERBOSE_ON
90-
#define GPTP_LOG_VERBOSE(fmt,...) gptpLog("VERBOSE ", __FILE__, __LINE__, fmt, ## __VA_ARGS__)
112+
#define GPTP_LOG_VERBOSE(fmt,...) gptpLog(GPTP_LOG_LVL_VERBOSE, "VERBOSE ", __FILE__, __LINE__, fmt, ## __VA_ARGS__)
91113
#else
92114
#define GPTP_LOG_VERBOSE(fmt,...)
93115
#endif

daemons/gptp/common/ieee1588.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,11 @@ class Timestamp {
379379
#define INVALID_TIMESTAMP (Timestamp( 0xC0000000, 0, 0 )) /*!< Defines an invalid timestamp using a Timestamp instance and a fixed value*/
380380
#define PDELAY_PENDING_TIMESTAMP (Timestamp( 0xC0000001, 0, 0 )) /*!< PDelay is pending timestamp */
381381

382-
#define TIMESTAMP_TO_NS(ts) (((static_cast<long long int>((ts).seconds_ms) \
383-
<< sizeof((ts).seconds_ls)*8) + \
384-
(ts).seconds_ls)*1000000000LL + (ts).nanoseconds) /*!< Converts timestamp value into nanoseconds value*/
382+
static inline uint64_t TIMESTAMP_TO_NS(Timestamp &ts)
383+
{
384+
return (((static_cast<long long int>(ts.seconds_ms) << sizeof(ts.seconds_ls)*8) +
385+
ts.seconds_ls)*1000000000LL + ts.nanoseconds) ; /*!< Converts timestamp value into nanoseconds value*/
386+
}
385387

386388
/**
387389
* @brief Swaps out byte-a-byte a 64 bit value

daemons/gptp/common/ieee1588port.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,8 @@ void IEEE1588Port::processEvent(Event e)
712712
break;
713713

714714
case LINKUP:
715+
haltPdelay(false);
716+
startPDelay();
715717
if (automotive_profile) {
716718
GPTP_LOG_EXCEPTION("LINKUP");
717719
}
@@ -771,10 +773,12 @@ void IEEE1588Port::processEvent(Event e)
771773
break;
772774

773775
case LINKDOWN:
776+
stopPDelay();
774777
if (automotive_profile) {
775778
GPTP_LOG_EXCEPTION("LINK DOWN");
776779
}
777780
else {
781+
setAsCapable(false);
778782
GPTP_LOG_STATUS("LINK DOWN");
779783
}
780784
if (testMode) {

daemons/gptp/common/ptptypes.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@
3636

3737
/**@file*/
3838

39+
#if defined(__clang__) && defined(__x86_64__)
40+
// Clang/llvm has incompatible long double (fp128) for x86_64.
41+
typedef double FrequencyRatio; /*!< Frequency Ratio */
42+
#else
3943
typedef long double FrequencyRatio; /*!< Frequency Ratio */
44+
#endif
4045

4146
#define ETHER_ADDR_OCTETS 6 /*!< Number of octets in a link layer address*/
4247
#define IP_ADDR_OCTETS 4 /*!< Number of octets in a ip address*/

daemons/gptp/linux/build/Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ ifeq ($(HAS_PRECISE_TIME),0)
4747
endif
4848

4949
CPPFLAGS_G = $(CFLAGS_G) -std=c++0x -Wnon-virtual-dtor
50-
51-
LDFLAGS_G = -lpthread -lrt
50+
LDFLAGS_G =
5251

5352
COMMON_DIR = ../../common
5453
SRC_DIR = ../src
@@ -112,6 +111,15 @@ else
112111
HEADER_FILES += $(SRC_DIR)/linux_hal_generic.hpp
113112
endif
114113

114+
ifeq ($(GENIVI_DLT),1)
115+
GENIVI_DLT_INCLUDE_PATH=/usr/local/include/dlt/
116+
GENIVI_DLT_LIB_PATH=/usr/local/lib/x86_64-linux-gnu/static/
117+
CFLAGS_G += -I$(GENIVI_DLT_INCLUDE_PATH) -DGENIVI_DLT
118+
LDFLAGS_G += -ldlt -L$(GENIVI_DLT_LIB_PATH)
119+
endif
120+
121+
LDFLAGS_G += -lpthread -lrt
122+
115123
CFLAGS = $(CFLAGS_G)
116124
CPPFLAGS = $(CPPFLAGS_G)
117125
LDFLAGS = $(LDFLAGS_G)

daemons/gptp/linux/shm_test/shm_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ int main(int argc, char *argv[])
9797
fprintf(stdout, "ml freq offset %Lf\n", ptpData->ml_freqoffset);
9898
fprintf(stdout, "ls phoffset %ld\n", ptpData->ls_phoffset);
9999
fprintf(stdout, "ls freq offset %Lf\n", ptpData->ls_freqoffset);
100-
fprintf(stdout, "local time %lu\n", ptpData->local_time);
100+
fprintf(stdout, "local time %llu\n", ptpData->local_time);
101101
fprintf(stdout, "sync count %u\n", ptpData->sync_count);
102102
fprintf(stdout, "pdelay count %u\n", ptpData->pdelay_count);
103103
fprintf(stdout, "asCapable %s\n", ptpData->asCapable ? "True" : "False");
104104
fprintf(stdout, "Port State %d\n", (int)ptpData->port_state);
105+
fprintf(stdout, "process_id %d\n", (int)ptpData->process_id);
105106

106107
return 0;
107108
}

0 commit comments

Comments
 (0)