gPTP Documentation
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
linux_hal_generic.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 
3  Copyright (c) 2012, Intel Corporation
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are met:
8 
9  1. Redistributions of source code must retain the above copyright notice,
10  this list of conditions and the following disclaimer.
11 
12  2. Redistributions in binary form must reproduce the above copyright
13  notice, this list of conditions and the following disclaimer in the
14  documentation and/or other materials provided with the distribution.
15 
16  3. Neither the name of the Intel Corporation nor the names of its
17  contributors may be used to endorse or promote products derived from
18  this software without specific prior written permission.
19 
20  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  POSSIBILITY OF SUCH DAMAGE.
31 
32 ******************************************************************************/
33 
34 #ifndef LINUX_HAL_GENERIC_HPP
35 #define LINUX_HAL_GENERIC_HPP
36 
37 #include <linux_hal_common.hpp>
38 
46 
47 #ifdef WITH_IGBLIB
48 struct LinuxTimestamperIGBPrivate;
49 typedef struct LinuxTimestamperIGBPrivate * LinuxTimestamperIGBPrivate_t;
50 #endif
51 
56 private:
57  int sd;
58  int phc_fd;
59  Timestamp crstamp_system;
60  Timestamp crstamp_device;
61  LinuxTimestamperGenericPrivate_t _private;
62  bool cross_stamp_good;
63  std::list<Timestamp> rxTimestampList;
64  LinuxNetworkInterfaceList iface_list;
65 
66  TicketingLock *net_lock;
67 
68 #ifdef WITH_IGBLIB
69  LinuxTimestamperIGBPrivate_t igb_private;
70 #endif
71 
72 public:
77 
84 
91  bool Adjust( void *tmx );
92 
99  virtual bool HWTimestamper_init
100  ( InterfaceLabel *iface_label, OSNetworkInterface *iface );
101 
108  void pushRXTimestamp( Timestamp *tstamp ) {
109  tstamp->_version = version;
110  rxTimestampList.push_front(*tstamp);
111  }
112 
120  bool post_init( int ifindex, int sd, TicketingLock *lock );
121 
130  virtual bool HWTimestamper_gettime
131  ( Timestamp *system_time, Timestamp *device_time, uint32_t *local_clock,
132  uint32_t *nominal_clock_rate );
133 
143  virtual int HWTimestamper_txtimestamp
144  ( PortIdentity *identity, uint16_t sequenceId, Timestamp &timestamp,
145  unsigned &clock_value, bool last );
146 
157  virtual int HWTimestamper_rxtimestamp
158  ( PortIdentity *identity, uint16_t sequenceId, Timestamp &timestamp,
159  unsigned &clock_value, bool last ) {
160  /* This shouldn't happen. Ever. */
161  if( rxTimestampList.empty() ) return -72;
162  timestamp = rxTimestampList.back();
163  rxTimestampList.pop_back();
164 
165  return 0;
166  }
167 
173  virtual bool HWTimestamper_adjclockphase( int64_t phase_adjust );
174 
180  virtual bool HWTimestamper_adjclockrate( float freq_offset );
181 
182 #ifdef WITH_IGBLIB
183  bool HWTimestamper_PPS_start( );
184  bool HWTimestamper_PPS_stop();
185 #endif
186 
190  virtual ~LinuxTimestamperGeneric();
191 };
192 
193 
194 #endif/*LINUX_HAL_GENERIC_HPP*/
Definition: ieee1588.hpp:101
bool resetFrequencyAdjustment()
Resets frequency adjustment value to zero and calls linux system calls for frequency adjustment...
struct LinuxTimestamperGenericPrivate * LinuxTimestamperGenericPrivate_t
Definition: linux_hal_generic.hpp:45
std::list< LinuxNetworkInterface * > LinuxNetworkInterfaceList
Definition: linux_hal_common.hpp:223
Definition: avbts_port.hpp:76
virtual bool HWTimestamper_adjclockphase(int64_t phase_adjust)
Adjusts the clock phase.
Definition: linux_hal_generic.hpp:55
virtual bool HWTimestamper_adjclockrate(float freq_offset)
Adjusts the frequency.
uint8_t _version
8 bit version value
Definition: ieee1588.hpp:251
virtual bool HWTimestamper_PPS_start()
Starts the PPS (pulse per second) interface.
Definition: ieee1588.hpp:560
virtual bool HWTimestamper_PPS_stop()
Stops the PPS (pulse per second) interface.
Definition: ieee1588.hpp:566
virtual bool HWTimestamper_init(InterfaceLabel *iface_label, OSNetworkInterface *iface)
Initializes the Hardware timestamp interface.
Definition: linux_hal_generic_tsprivate.hpp:57
Definition: avbts_osnet.hpp:277
void pushRXTimestamp(Timestamp *tstamp)
Inserts a new timestamp to the beginning of the RX timestamp list.
Definition: linux_hal_generic.hpp:108
bool Adjust(void *tmx)
Calls linux system call for adjusting frequency or phase.
virtual ~LinuxTimestamperGeneric()
Definition: linux_hal_common.hpp:81
bool post_init(int ifindex, int sd, TicketingLock *lock)
Post initialization procedure.
Definition: linux_hal_common.hpp:126
uint8_t version
HWTimestamper version.
Definition: ieee1588.hpp:447
virtual int HWTimestamper_rxtimestamp(PortIdentity *identity, uint16_t sequenceId, Timestamp &timestamp, unsigned &clock_value, bool last)
Gets the RX timestamp from the hardware interface. This Currently the RX timestamp is retrieved at Li...
Definition: linux_hal_generic.hpp:158
virtual bool HWTimestamper_gettime(Timestamp *system_time, Timestamp *device_time, uint32_t *local_clock, uint32_t *nominal_clock_rate)
Gets the ptp clock time information.
virtual int HWTimestamper_txtimestamp(PortIdentity *identity, uint16_t sequenceId, Timestamp &timestamp, unsigned &clock_value, bool last)
Gets the TX timestamp from hardware interface.
Definition: ieee1588.hpp:222