orca-sim
Signal.hpp
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 #ifndef ORCASIM_MODELING_INCLUDE_SIGNAL_HPP_
27 #define ORCASIM_MODELING_INCLUDE_SIGNAL_HPP_
28 
29 // lib dependent includes
30 #include <stdint.h>
31 #include <iostream>
32 #include <vector>
33 #include <string>
34 
35 // api includes
36 #include "UntimedModel.hpp"
37 #include "MemoryType.hpp"
38 
39 namespace orcasim::modeling {
40 
44 template <typename T>
45 class Signal{
46  private:
48  volatile T* _t_ptr;
49 
51  volatile T _t_storage;
52 
54  std::string _t_name;
55 
57  volatile uint32_t _t_addr;
58 
59  public:
66  Signal(T* t_ptr, uint32_t addr, std::string name);
67 
73  Signal(uint32_t addr, std::string name);
74 
79  explicit Signal(std::string name);
80 
86  ~Signal();
87 
92  T Read();
93 
97  void MapTo(bool keep_val = true);
98 
106  void MapTo(MemoryType* memptr, MemoryAddr address, bool keep_val = true);
107 
112  void Write(T val);
113 
118  void Inc(T val);
119 
124  void Dec(T val);
125 
130  uint32_t GetAddress();
131 
135  void SetAddress(MemoryAddr);
136 
141  std::string GetName();
142 };
143 
144 // Some of the most used instances. More can be added later.
145 // for larger data size, consider using a Memory instead.
146 template class Signal<bool>; // wire
147 template class Signal<uint8_t>; // mem word
148 template class Signal<uint16_t>; // dmni/noc word
149 template class Signal<uint32_t>; // proc word
150 template class Signal<float>; // float cooprocessor output
151 template class Signal<uint64_t>; // double word
152 template class Signal<int8_t>; // mem word
153 template class Signal<int16_t>; // dmni/noc word
154 template class Signal<int32_t>; // proc word
155 template class Signal<int64_t>; // double word
156 
157 } // namespace orcasim::modeling
158 #endif // ORCASIM_MODELING_INCLUDE_SIGNAL_HPP_
The Signal class models a generic bus of width equals to the sizeof(T)
Definition: Signal.hpp:45
void SetAddress(MemoryAddr)
Set an address for this signal.
Definition: Signal.cpp:171
void MapTo(bool keep_val=true)
Maps current Signal to the internal storage.
Definition: Signal.cpp:79
std::string _t_name
an optional name to identify this bus during runtime
Definition: Signal.hpp:54
T Read()
Get the last value writen to the bus.
Definition: Signal.cpp:118
#define MemoryAddr
Definition: MemoryType.hpp:34
void Write(T val)
Writes some value to the bus.
Definition: Signal.cpp:127
~Signal()
Destructor.
Definition: Signal.cpp:111
volatile T _t_storage
internal storage (necessary when mmio is not used)
Definition: Signal.hpp:51
volatile T * _t_ptr
pointer to the place where the bus data will be stored
Definition: Signal.hpp:48
void Inc(T val)
Increments the value of the bus by the given value.
Definition: Signal.cpp:136
void Dec(T val)
Descrements the value of the bus by the given value.
Definition: Signal.cpp:145
Signal(T *t_ptr, uint32_t addr, std::string name)
Constructor.
Definition: Signal.cpp:61
std::string GetName()
Return the name of the Signal.
Definition: Signal.cpp:163
volatile uint32_t _t_addr
a memory address in case this is mapped using mmio
Definition: Signal.hpp:57
#define MemoryType
Definition: MemoryType.hpp:33
uint32_t GetAddress()
Return the addres to which this Signal is mapped.
Definition: Signal.cpp:154