The Sparta Modeling Framework
Loading...
Searching...
No Matches
Consumer.hpp
1// <Consumer.hpp> -*- C++ -*-
2
3#pragma once
4
5#include <cinttypes>
6
13
14class Consumer : public sparta::Unit
15{
16public:
17
19 static const char * name;
20
22 {
23 public:
26 {
27 }
28 PARAMETER(uint32_t, num_producers, 1, "Number of producers")
29 };
30
32
33private:
34 // Consumer's InPort to get data
35 sparta::DataInPort<uint32_t> consumer_in_port_{&unit_port_set_, "consumer_in_port", 1};
36
37 // Consumer's push-back (or go) port
38 std::vector<std::unique_ptr<sparta::SignalOutPort>> producer_go_port_;
39 uint32_t current_producer_ = 0;
40 const uint32_t num_producers_;
41
42 // Consumer's receiving callback
43 void receiveData_(const uint32_t & dat);
45
46 // 0 cycle delay on scheduling
47 sparta::UniqueEvent<> ev_data_arrived_{&unit_event_set_, "ev_data_arrived",
48 CREATE_SPARTA_HANDLER(Consumer, dataArrived_), 0};
49
50 // Operate on incoming data
51 void dataArrived_();
52
53 // Startup handler
54 void signalNextProducer_();
55
56 // Stats
57 sparta::Counter num_consumed_{&unit_stat_set_, "num_consumed",
58 "Number of items consumed", sparta::Counter::COUNT_NORMAL};
59
61 sparta::log::MessageSource consumer_log_;
62
63};
64
File that defines Data[In,Out]Port<DataT>
A set of sparta::Parameters per sparta::ResourceTreeNode.
#define PARAMETER(type, name, def, doc)
Parameter declaration.
File that defines the SignalInPort.
#define CREATE_SPARTA_HANDLER(clname, meth)
File that defines the UniqueEvent class.
File that defines the Unit class, a common grouping of sets and loggers.
File that defines a ValidValue.
static const char * name
Name of this resource. Required by sparta::ResourceFactory.
Definition Consumer.hpp:19
@ COUNT_NORMAL
Counter counts the number of times something happens like one would expect. This is a weakly monotoni...
Represents a counter of type counter_type (uint64_t). 2 and greater than 0 with a ceiling specified....
Definition Counter.hpp:27
DataInPort receives data from sender using a DataOutPort.
Definition DataPort.hpp:289
Generic container of Parameters.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
A type of Event that uniquely schedules itself on the schedule within a single time quantum....
The is the base class for user defined blocks in simulation.
Definition Unit.hpp:38
sparta::EventSet unit_event_set_
The Unit's event set.
Definition Unit.hpp:114
sparta::StatisticSet unit_stat_set_
The Unit's statistic set.
Definition Unit.hpp:117
sparta::PortSet unit_port_set_
The Unit's Ports.
Definition Unit.hpp:111
Message source object associated with a sparta TreeNode through which messages can be sent.
Provides a wrapper around a value to ensure that the value is assigned.