orca-sim
Signal.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 #include <stdint.h>
27 
28 #include <iostream>
29 #include <vector>
30 #include <algorithm>
31 
32 // api includes
33 #include "UntimedModel.hpp"
34 #include "Signal.hpp"
35 
37 
45 template <typename T>
46 Signal<T>::Signal(std::string name) {
47  _t_ptr = &_t_storage;
48  _t_name = name;
49 }
50 
51 // @TODO(ad): rework class to inherit from UntimedModel
52 // @TODO(ad): turn multiple construction into a single on using optional params
53 
60 template <typename T>
61 Signal<T>::Signal(T* t_ptr, uint32_t addr, std::string name) {
62  _t_ptr = t_ptr;
63  _t_addr = addr;
64  _t_name = name;
65 }
66 
67 template <typename T>
68 Signal<T>::Signal(uint32_t addr, std::string name) {
69  _t_ptr = &_t_storage;
70  _t_addr = addr;
71  _t_name = name;
72 }
73 
78 template <typename T>
79 void Signal<T>::MapTo(bool keep_val) {
80  // copies current value before changing pointers
81  if (keep_val) {
82  T curr_val;
83  curr_val = this->Read();
84  _t_ptr = &_t_storage;
85  this->Write(curr_val);
86  } else {
87  _t_ptr = &_t_storage;
88  }
89 }
90 
97 template <typename T>
98 void Signal<T>::MapTo(MemoryType* memptr, MemoryAddr address, bool keep_val) {
99  // copies current value before changing pointers
100  if (keep_val)
101  *(reinterpret_cast<MemoryType*>(memptr)) = this->Read();
102 
103  _t_ptr = reinterpret_cast<T*>(memptr);
104  _t_addr = address;
105 }
106 
110 template <typename T>
112 
117 template <typename T>
119  return *_t_ptr;
120 }
121 
126 template <typename T>
127 void Signal<T>::Write(T val) {
128  *_t_ptr = val;
129 }
130 
135 template <typename T>
136 void Signal<T>::Inc(T val) {
137  *_t_ptr = (*_t_ptr) + val;
138 }
139 
144 template <typename T>
145 void Signal<T>::Dec(T val) {
146  *_t_ptr = (*_t_ptr) - val;
147 }
148 
153 template <typename T>
155  return _t_addr;
156 }
157 
162 template <typename T>
163 std::string Signal<T>::GetName() {
164  return _t_name;
165 }
166 
170 template <typename T>
172  _t_addr = addr;
173 }
The Signal class models a generic bus of width equals to the sizeof(T)
Definition: Signal.hpp:45
#define MemoryAddr
Definition: MemoryType.hpp:34
#define MemoryType
Definition: MemoryType.hpp:33