The Sparta Modeling Framework
Loading...
Searching...
No Matches
Core.cpp
1
2#include <string>
3
5#include "sparta/statistics/Counter.hpp"
6#include "sparta/functional/Register.hpp"
7
8#include "Core.hpp"
9
10namespace core_example
11{
12 // Register Tables for Core
13 const char* regfoo_aliases[] = { "the_foo_reg", "reg0", 0 };
14
15 sparta::Register::Definition core_reg_defs[] = {
16 { 0, "regfoo", 1, "reg", 0, "regfoo's description", 4, {
17 { "field1", "this is field 1. It is 2 bits", 0, 1 },
18 { "field2", "this is field 2. It is 4 bits", 0, 3 },
19 { "field3", "this is field 3. It is 3 bits", 1, 3 } },
20 {}, regfoo_aliases, sparta::Register::INVALID_ID, 0, NULL, 0, 0 },
22 };
23
24 Core::Core(sparta::TreeNode * node, // TreeNode which owns this. Publish child nodes to this
25 const CoreParameterSet * p) : // Core::ParameterSet, not generic SPARTA set
26 sparta::Unit(node),
27 regs_(sparta::RegisterSet::create(node, core_reg_defs)), // Create register set
28 counter_incr_event_(&unit_event_set_, "counter_incr_event",
29 CREATE_SPARTA_HANDLER(Core, incrementCounter_))
30 {
31 // Now parameters and ports are fixed and sparta device tree is
32 // now finalizing, so the parameters and ports can be used to
33 // initialize this unit once and permanently. The TreeNode
34 // arg node is the TreeNode which constructed this resource.
35 // In this constructor (only), we have the opportunity to add
36 // more TreeNodes as children of this node, such as
37 // RegisterSet, CounterSet, Register, Counter,
38 // Register::Field, etc. No new ResourceTreeNodes may be
39 // added, however. This unit's clock can be derived from
40 // node->getClock(). Child resources of this node who do not
41 // have their own nodes could examine the parameters argument
42 // here and attach counters to this node's CounterSet.
43
45 // Interpret Parameters (ignore any which are not read)
46 p->foo.ignore(); // Explicitly ignore (or framework will think we forgot to use it)
47 counter_incr_amount_ = p->ctr_incr_amount;
48 counter_incr_period_ = p->ctr_incr_period;
49
50 // Print out contents (vector<string>)
51 for(auto c : p->contents){
52 (void) c;
53 //std::cout << c << std::endl;
54 }
55
57 // Create Counters
58 fooctr_ = &unit_stat_set_.createCounter<sparta::Counter>("counter_foo", "Example Counter", sparta::Counter::COUNT_NORMAL);
59 assert(node->getClock());
60
61 warn_logger_ << " Completed construction of Core";
62 }
63
64 void Core::incrementCounter_() {
65 (*fooctr_) += counter_incr_amount_;
66 counter_incr_event_.schedule(counter_incr_period_);
67 }
68
69}
#define CREATE_SPARTA_HANDLER(clname, meth)
Basic Node framework in sparta device tree composite pattern.
Parameters for Core model.
Definition Core.hpp:24
Core(sparta::TreeNode *node, const CoreParameterSet *params)
Core constructor.
Definition Core.cpp:24
@ 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
void schedule()
Schedule this event with its pre-set delay using the pre-set Clock.
static constexpr ident_type INVALID_ID
Represents an invalid Register ID.
Definition Register.hpp:681
static const Definition DEFINITION_END
Entry indicating the end of a sparta::Register::Definition array.
Definition Register.hpp:687
CounterT & createCounter(_Args &&... __args)
Allocates a Counter which is owned by this StatisticSet and deleted at its destruction.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
const Clock * getClock() override
Walks up parents (starting with self) until a parent with an associated local clock is found,...
log::MessageSource warn_logger_
Default warn logger.
Definition Unit.hpp:164
sparta::StatisticSet unit_stat_set_
The Unit's statistic set.
Definition Unit.hpp:117
Macros for handling exponential backoff.
Describes an architected Register.
Definition Register.hpp:548