RX frames have two timestamps: monotonic - for protocol timings management; utc - for application-level timestamping

This commit is contained in:
Pavel Kirienko
2014-02-11 14:32:45 +04:00
parent b8f6bf3ffa
commit 696451baca
10 changed files with 85 additions and 62 deletions
+9 -2
View File
@@ -93,10 +93,17 @@ public:
/**
* Non-blocking reception.
* out_utc_timestamp_usec must be provided by the driver, ideally by the hardware CAN controller; 0 if unknown.
* Timestamps should be provided by the CAN driver, ideally by the hardware CAN controller.
* Monotonic timestamp is required and can be not precise since it is needed only for
* protocol timing validation (transfer timeouts and inter-transfer intervals).
* UTC timestamp is optional, if available it will be used for precise time synchronization;
* must be set to zero if not available.
* Refer to @ref ISystemClock to learn more about timestamps.
* @param [out] out_ts_monotonic_usec Monotonic timestamp, usec, mandatory.
* @param [out] out_ts_utc_usec UTC timestamp, usec, optional, zero if unknown.
* @return 1 = one frame received, 0 = RX buffer empty, negative for error.
*/
virtual int receive(CanFrame& out_frame, uint64_t& out_utc_timestamp_usec) = 0;
virtual int receive(CanFrame& out_frame, uint64_t& out_ts_monotonic_usec, uint64_t& out_ts_utc_usec) = 0;
/**
* Configure the hardware CAN filters. @ref CanFilterConfig.
@@ -19,11 +19,13 @@ namespace uavcan
struct CanRxFrame : public CanFrame
{
uint64_t timestamp;
uint64_t ts_monotonic;
uint64_t ts_utc;
uint8_t iface_index;
CanRxFrame()
: timestamp(0)
: ts_monotonic(0)
, ts_utc(0)
, iface_index(0)
{ }
};
@@ -137,11 +137,13 @@ struct Frame
struct RxFrame : public Frame
{
uint_fast64_t timestamp;
uint_fast64_t ts_monotonic;
uint_fast64_t ts_utc;
uint_fast8_t iface_index;
RxFrame()
: timestamp(0)
: ts_monotonic(0)
, ts_utc(0)
, iface_index(0)
{ }
@@ -149,7 +151,8 @@ struct RxFrame : public Frame
{
if (!Frame::parse(can_frame))
return false;
timestamp = can_frame.timestamp;
ts_monotonic = can_frame.ts_monotonic;
ts_utc = can_frame.ts_utc;
iface_index = can_frame.iface_index;
return true;
}
@@ -23,9 +23,10 @@ private:
enum TidRelation { TID_SAME, TID_REPEAT, TID_FUTURE };
enum { IFACE_INDEX_NOTSET = 0xFF };
uint64_t prev_transfer_timestamp_;
uint64_t this_transfer_timestamp_;
uint64_t transfer_interval_;
uint64_t prev_transfer_ts_monotonic_;
uint64_t this_transfer_ts_monotonic_;
uint64_t first_frame_ts_utc_;
uint64_t transfer_interval_; // TODO: make 32 bit
ITransferBufferManager* bufmgr_;
TransferBufferManagerKey bufmgr_key_;
TransferID tid_;
@@ -48,8 +49,9 @@ private:
public:
TransferReceiver()
: prev_transfer_timestamp_(0)
, this_transfer_timestamp_(0)
: prev_transfer_ts_monotonic_(0)
, this_transfer_ts_monotonic_(0)
, first_frame_ts_utc_(0)
, transfer_interval_(DEFAULT_TRANSFER_INTERVAL)
, bufmgr_(NULL)
, iface_index_(IFACE_INDEX_NOTSET)
@@ -57,8 +59,9 @@ public:
{ }
TransferReceiver(ITransferBufferManager* bufmgr, const TransferBufferManagerKey& bufmgr_key)
: prev_transfer_timestamp_(0)
, this_transfer_timestamp_(0)
: prev_transfer_ts_monotonic_(0)
, this_transfer_ts_monotonic_(0)
, first_frame_ts_utc_(0)
, transfer_interval_(DEFAULT_TRANSFER_INTERVAL)
, bufmgr_(bufmgr)
, bufmgr_key_(bufmgr_key)
@@ -74,8 +77,9 @@ public:
TransferReceiver& operator=(const TransferReceiver& rhs)
{
cleanup();
prev_transfer_timestamp_ = rhs.prev_transfer_timestamp_;
this_transfer_timestamp_ = rhs.this_transfer_timestamp_;
prev_transfer_ts_monotonic_ = rhs.prev_transfer_ts_monotonic_;
this_transfer_ts_monotonic_ = rhs.this_transfer_ts_monotonic_;
first_frame_ts_utc_ = rhs.first_frame_ts_utc_;
transfer_interval_ = rhs.transfer_interval_;
bufmgr_ = rhs.bufmgr_;
tid_ = rhs.tid_;
@@ -89,7 +93,8 @@ public:
ResultCode addFrame(const RxFrame& frame);
uint64_t getLastTransferTimestamp() const { return prev_transfer_timestamp_; }
uint64_t getLastTransferTimestampMonotonic() const { return prev_transfer_ts_monotonic_; }
uint64_t getLastTransferTimestampUtc() const { return first_frame_ts_utc_; }
uint64_t getInterval() const { return transfer_interval_; }
};