Skip to content
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

Fixup .ini file parse and add support for linux kernel HW timestamping #462

Merged
merged 2 commits into from
Aug 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions daemons/gptp/linux/build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ ALTERNATE_LINUX_INCPATH=$(HOME)/header/include/
CFLAGS_G = -Wall -std=c++0x -g -I. -I../../common -I../src \
-I$(ALTERNATE_LINUX_INCPATH)

# Check to see if PTP cross-timestamping is supported in hardware/driver
# and, if so, add flag to compile in support

PRECISE_TIME_TEST = "\#include <linux/ptp_clock.h>\\n\
\#ifdef PTP_SYS_OFFSET_PRECISE\\nint main(){return 0;}\\n\#endif"

HAS_PRECISE_TIME = $(shell echo $(PRECISE_TIME_TEST) | gcc -xc - \
-I$(ALTERNATE_LINUX_INCPATH) -o /dev/null > /dev/null 2>&1 ; echo $$?)

ifeq ($(HAS_PRECISE_TIME),0)
CFLAGS_G += -DPTP_HW_CROSSTSTAMP
endif

CPPFLAGS_G = $(CFLAGS_G) -Wnon-virtual-dtor

LDFLAGS_G = -lpthread -lrt
Expand Down
9 changes: 5 additions & 4 deletions daemons/gptp/linux/src/daemon_cl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,6 @@ int main(int argc, char **argv)
portInit.lock_factory = lock_factory;

pPort = new IEEE1588Port(&portInit);
if (!pPort->init_port(phy_delay)) {
printf("failed to initialize port \n");
return -1;
}

if(use_config_file)
{
Expand Down Expand Up @@ -408,6 +404,11 @@ int main(int argc, char **argv)

}

if (!pPort->init_port(phy_delay)) {
printf("failed to initialize port \n");
return -1;
}

if( restoredataptr != NULL ) {
if( !restorefailed ) {
restorefailed = !pPort->restoreSerializedState( restoredataptr, &restoredatacount );
Expand Down
51 changes: 40 additions & 11 deletions daemons/gptp/linux/src/linux_hal_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ bool LinuxTimestamperGeneric::HWTimestamper_init
cross_stamp_good = false;
int phc_index;
char ptp_device[] = PTP_DEVICE;

#ifdef PTP_HW_CROSSTSTAMP
struct ptp_clock_caps ptp_capability;
#endif
_private = new LinuxTimestamperGenericPrivate;

pthread_mutex_init( &_private->cross_stamp_lock, NULL );
Expand All @@ -244,6 +246,16 @@ bool LinuxTimestamperGeneric::HWTimestamper_init
return false;
}

#ifdef PTP_HW_CROSSTSTAMP
// Query PTP stack for availability of HW cross-timestamp
if( ioctl( phc_fd, PTP_CLOCK_GETCAPS, &ptp_capability ) == -1 )
{
GPTP_LOG_ERROR( "Failed to query PTP clock capabilities" );
return false;
}
precise_timestamp_enabled = ptp_capability.cross_timestamping;
#endif

if( !resetFrequencyAdjustment() ) {
GPTP_LOG_ERROR( "Failed to reset (zero) frequency adjustment" );
return false;
Expand Down Expand Up @@ -411,20 +423,39 @@ static inline Timestamp pctTimestamp( struct ptp_clock_time *t ) {
return result;
}

// Use HW cross-timestamp if available
bool LinuxTimestamperGeneric::HWTimestamper_gettime
( Timestamp *system_time, Timestamp *device_time, uint32_t *local_clock,
uint32_t *nominal_clock_rate ) {
unsigned i;
struct ptp_sys_offset offset;
struct ptp_clock_time *pct;
struct ptp_clock_time *system_time_l, *device_time_l;
if( phc_fd == -1 )
return false;

int64_t interval = LLONG_MAX;
#ifdef PTP_HW_CROSSTSTAMP
if( precise_timestamp_enabled )
{
struct ptp_sys_offset_precise offset;
memset( &offset, 0, sizeof(offset));
if( ioctl( phc_fd, PTP_SYS_OFFSET_PRECISE, &offset ) == 0 )
{
*device_time = pctTimestamp( &offset.device );
*system_time = pctTimestamp( &offset.sys_realtime );

return true;
}
}
#endif

{
unsigned i;
struct ptp_clock_time *pct;
struct ptp_clock_time *system_time_l, *device_time_l;
int64_t interval = LLONG_MAX;
struct ptp_sys_offset offset;

if( phc_fd != -1 ) {
memset( &offset, 0, sizeof(offset));
offset.n_samples = PTP_MAX_SAMPLES;
ioctl( phc_fd, PTP_SYS_OFFSET, &offset );
if( ioctl( phc_fd, PTP_SYS_OFFSET, &offset ) == -1 )
return false;

pct = &offset.ts[0];
for( i = 0; i < offset.n_samples; ++i ) {
Expand All @@ -439,9 +470,7 @@ bool LinuxTimestamperGeneric::HWTimestamper_gettime

*device_time = pctTimestamp( device_time_l );
*system_time = pctTimestamp( system_time_l );

return true;
}

return false;
return true;
}
3 changes: 3 additions & 0 deletions daemons/gptp/linux/src/linux_hal_generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class LinuxTimestamperGeneric : public LinuxTimestamper {
bool cross_stamp_good;
std::list<Timestamp> rxTimestampList;
LinuxNetworkInterfaceList iface_list;
#ifdef PTP_HW_CROSSTSTAMP
bool precise_timestamp_enabled;
#endif

TicketingLock *net_lock;

Expand Down