The Sparta Modeling Framework
Loading...
Searching...
No Matches
DataContainer.hpp
Go to the documentation of this file.
1// <Port> -*- C++ -*-
2
3
10#pragma once
11
14
15namespace sparta
16{
24 template<class DataT>
26 {
27 public:
35 clock_(clk)
36 {
37 sparta_assert(clock_ != nullptr);
38 }
39
48 bool dataReceived() const {
49 return data_.isValid();
50 }
51
59 bool dataReceivedThisCycle() const {
60 return (data_.isValid() &&
61 (data_valid_time_stamp_ == clock_->getScheduler()->getCurrentTick()));
62 }
63
72 DataT pullData() {
74 const DataT & dat = data_.getValue();
75 data_.clearValid();
76 return dat;
77 }
78
84 const DataT & peekData() const {
86 return data_.getValue();
87 }
88
90 void clearData() {
91 data_.clearValid();
92 }
93
99 Clock::Cycle getReceivedTimeStamp() const {
101 return clock_->getCycle(data_valid_time_stamp_);
102 }
103
104 protected:
105
107 void setData_(const DataT & dat) {
108 data_ = dat;
109 data_valid_time_stamp_ = clock_->getScheduler()->getCurrentTick();
110 }
111
112 private:
113
116
118 Scheduler::Tick data_valid_time_stamp_ = 0;
119
121 const sparta::Clock * clock_ = nullptr;
122
123 };
124}
125
File that defines the Clock class.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
File that defines a ValidValue.
A representation of simulated time.
Definition Clock.hpp:51
Scheduler * getScheduler() const
Definition Clock.hpp:302
Cycle getCycle(const Scheduler::Tick &tick) const
Given the tick, convert to a Clock::Cycle.
Definition Clock.hpp:166
Used by DataInPort and SyncInPort, this class holds received data from these ports and remembers the ...
DataContainer(const sparta::Clock *clk)
Construct the DataContainer with the clock used for timestamping.
DataT pullData()
Return the last data received by the port, then clear it.
bool dataReceived() const
Has this port received data (not timed)
bool dataReceivedThisCycle() const
Has this port received data this cycle.
void setData_(const DataT &dat)
Set the data received.
const DataT & peekData() const
Peek at the data in the port, but don't invalidate it.
void clearData()
Clear the validity of the data at the port.
Clock::Cycle getReceivedTimeStamp() const
Returns the clock cycle data was received.
Tick getCurrentTick() const noexcept
The current tick the Scheduler is working on or just finished.
uint64_t Tick
Typedef for our unit of time.
Provides a wrapper around a value to ensure that the value is assigned.
void clearValid()
Clear the validity of this object.
const value_type & getValue() const
Get the value - const version.
bool isValid() const
Is this value valid.
Macros for handling exponential backoff.