The Sparta Modeling Framework
Loading...
Searching...
No Matches
Producer.cpp
1// <Producer.cpp> -*- C++ -*-
2
3#include "Producer.hpp"
4#include "MessageCategories.hpp"
5
6const char * Producer::name = "producer";
7
8Producer::Producer (sparta::TreeNode * node,
9 const ProducerParameterSet * p) :
10 sparta::Unit(node, name),
11 max_ints_to_send_(p->max_ints_to_send),
12 producer_info_(node, message_categories::INFO, "Producer Info Messages")
13{
14 // Register a go-handler when the consumer sends a go request
15 producer_go_port_.registerConsumerHandler(CREATE_SPARTA_HANDLER(Producer, produceData_));
16 ProducerParameterSet* pnc = const_cast<ProducerParameterSet*>(p);
17 pnc->test_param = pnc->test_param + 1;
18
19 // The warn_logger_ (a sparta::log::MessageSource) comes for free with sparta::Unit
20 warn_logger_ << " Modify test_b Producer(): " << pnc->test_param.getValue();
21
22 p->arch_override_test_param.ignore();
23
24}
25
26void Producer::produceData_()
27{
28 if(current_ints_count_ < max_ints_to_send_)
29 {
30 if(SPARTA_EXPECT_FALSE(producer_info_)) {
31 producer_info_ << "Producer: " << getName() << "@" << getContainer()->getLocation()
32 << " Sending " << current_ints_count_ << std::endl;
33 }
34
35 // Sent the integer to the listening consumers
36 producer_out_port_.send(current_ints_count_);
37 ++current_ints_count_;
38 ++num_produced_;
39 }
40 else if(SPARTA_EXPECT_FALSE(producer_info_)) {
41 producer_info_ << "Producer: " << getName() << "@" << getContainer()->getLocation()
42 << " Is done sending data " << current_ints_count_;
43 }
44}
#define SPARTA_EXPECT_FALSE(x)
A macro for hinting to the compiler a particular condition should be considered most likely false.
#define CREATE_SPARTA_HANDLER(clname, meth)
void send(const DataT &dat, sparta::Clock::Cycle rel_time=0)
Send data to bound receivers.
Definition DataPort.hpp:145
TreeNode * getContainer()
Gets the TreeNode (container) for this resource (if any)
std::string getName() const
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
std::string getLocation() const override final
Macros for handling exponential backoff.