orca-sim
SignalSet.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * This file is part of project ORCA. More information on the project
3  * can be found at the following repositories at GitHub's website.
4  *
5  * http://https://github.com/andersondomingues/orca-sim
6  * http://https://github.com/andersondomingues/orca-software
7  * http://https://github.com/andersondomingues/orca-mpsoc
8  * http://https://github.com/andersondomingues/orca-tools
9  *
10  * Copyright (C) 2018-2020 Anderson Domingues, <ti.andersondomingues@gmail.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 ******************************************************************************/
26 
27 #include <stdint.h>
28 
29 // lib dependent includes
30 #include <iostream>
31 #include <vector>
32 #include <algorithm>
33 
34 
35 // api includes
36 #include "UntimedModel.hpp"
37 #include "Signal.hpp"
38 #include "SignalSet.hpp"
39 #include "Memory.hpp"
40 
43 
44 // ctor.
45 template <typename T>
46 SignalSet<T>::SignalSet(std::string name, uint32_t nsig): UntimedModel(name) {
47  // set internal variables
48  _num_signals = nsig;
50 
51  // create a new vector of signals. Signals are no mapped yep, use MapTo.
52  for (uint32_t i = 0; i < _num_signals; i++)
53  _signals[i] = new Signal<T>(this->GetName() + "." + std::to_string(i));
54 }
55 
56 // dtor.
57 template <typename T>
59  delete[] _signals;
60 }
61 
62 // mapping function
63 template <typename T>
65  MemoryAddr address = addr;
66  MemoryType* memtype = memptr;
67 
68  // set the proper address to each signal and map
69  for (uint32_t i = 0; i < _num_signals; i++) {
70  _signals[i]->SetAddress(address);
71  _signals[i]->MapTo(memtype, address, false);
72 
73  address += sizeof(T);
74 
75  // caution, pointer arithmetic here
76  for (uint32_t j = 0; j < sizeof(T) / sizeof(MemoryType); j++)
77  memtype++;
78  }
79 }
80 
81 // getters
82 template <typename T>
84  if (index > _num_signals - 1 || index < 0) {
85  std::cout << "warn: requested signals is out of the bounds of the set"
86  << std::endl;
87  return nullptr;
88  }
89 
90  return _signals[index];
91 }
The Signal class models a generic bus of width equals to the sizeof(T)
Definition: Signal.hpp:45
#define MemoryAddr
Definition: MemoryType.hpp:34
uint32_t _num_signals
number of signals in the set.
Definition: SignalSet.hpp:50
std::string GetName()
Getter method for the <_name> field.
Definition: Model.cpp:34
Untimed models represent hardware models whose clock period is irrelevant for the simulation...
void MapTo(MemoryType *mptr, MemoryAddr addr)
Maps the signal set to a given memory address.
Definition: SignalSet.cpp:64
Signal< T > ** _signals
a pointer to the first signal.
Definition: SignalSet.hpp:59
Signal< T > * GetSignal(uint32_t index)
Get the a signal from the set.
Definition: SignalSet.cpp:83
The SignalSet class models a generic set of busses of type T.
Definition: SignalSet.hpp:47
#define MemoryType
Definition: MemoryType.hpp:33