The Sparta Modeling Framework
Loading...
Searching...
No Matches
Producer.hpp
1// <Producer.hpp> -*- C++ -*-
2
3#pragma once
4
5#include <cinttypes>
6#include <string>
7
14
15// Possible to create this class outside of the Producer class, but
16// simply not that clean. It's better to put it in the Producer class
17// (for namespacing), but definitely not required.
19{
20public:
23 {
24 // See test_arch_with_override.sh for explanation about this
25 // parameter. It is being used for a test as part of make regress.
26 arch_override_test_param = "reset_in_constructor";
27 auto non_zero_validator = [](uint32_t & val, const sparta::TreeNode*)->bool {
28 if(val > 0) {
29 return true;
30 }
31 return false;
32 };
33 max_ints_to_send.addDependentValidationCallback(non_zero_validator,
34 "Num to send must be greater than 0");
35 }
36
37 PARAMETER(uint32_t, max_ints_to_send, 100, "Send a bunch of ints")
38 VOLATILE_PARAMETER(uint32_t, test_param, 0, "A dummy parameter")
39 PARAMETER(std::string, arch_override_test_param, "arch_override_default_value", "Set this to true in ParameterSet construction")
40};
41
42//
43// The Producer class
44//
45class Producer : public sparta::Unit
46{
47public:
48
50 const ProducerParameterSet * p);
51
52 // Name of this resource. Required by sparta::ResourceFactory
53 static const char * name;
54
55private:
56
57 // Producer's ports
58 sparta::DataOutPort<uint32_t> producer_out_port_{&unit_port_set_, "producer_out_port"};
59 sparta::SignalInPort producer_go_port_ {&unit_port_set_, "producer_go_port"};
60
61 // Producer's producer handler
62 void produceData_();
63
64 // Internal count
65 const uint32_t max_ints_to_send_;
66 uint32_t current_ints_count_ = 0;
67
68 // Stats
69 sparta::Counter num_produced_{&unit_stat_set_, "num_produced",
70 "Number of items produced", sparta::Counter::COUNT_NORMAL};
71
72 // Loggers
73 sparta::log::MessageSource producer_info_;
74};
75
File that defines Data[In,Out]Port<DataT>
A set of sparta::Parameters per sparta::ResourceTreeNode.
#define VOLATILE_PARAMETER(type, name, def, doc)
Special-case PARAMETER declaration.
#define PARAMETER(type, name, def, doc)
Parameter declaration.
File that defines the PortSet class.
File that defines the SignalInPort.
File that defines the UniqueEvent class.
File that defines the Unit class, a common grouping of sets and loggers.
@ 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
DataOutPort is used for transferring any data to another module.
Definition DataPort.hpp:77
Generic container of Parameters.
SignalInPort receives data from sender using a SignalOutPort.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
The is the base class for user defined blocks in simulation.
Definition Unit.hpp:38
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.