orca-sim
Public Member Functions | Private Attributes | List of all members
orcasim::modeling::Signal< T > Class Template Reference

The Signal class models a generic bus of width equals to the sizeof(T) More...

#include <Signal.hpp>

Public Member Functions

 Signal (T *t_ptr, uint32_t addr, std::string name)
 Constructor. More...
 
 Signal (uint32_t addr, std::string name)
 Constructor. More...
 
 Signal (std::string name)
 Constructor. More...
 
 ~Signal ()
 Destructor. More...
 
Read ()
 Get the last value writen to the bus. More...
 
void MapTo (bool keep_val=true)
 Maps current Signal to the internal storage. More...
 
void MapTo (MemoryType *memptr, MemoryAddr address, bool keep_val=true)
 Maps current Signal to an external storage, updates internal reference and sets a new address. More...
 
void Write (T val)
 Writes some value to the bus. More...
 
void Inc (T val)
 Increments the value of the bus by the given value. More...
 
void Dec (T val)
 Descrements the value of the bus by the given value. More...
 
uint32_t GetAddress ()
 Return the addres to which this Signal is mapped. More...
 
void SetAddress (MemoryAddr)
 Set an address for this signal. More...
 
std::string GetName ()
 Return the name of the Signal. More...
 

Private Attributes

volatile T * _t_ptr
 pointer to the place where the bus data will be stored More...
 
volatile T _t_storage
 internal storage (necessary when mmio is not used) More...
 
std::string _t_name
 an optional name to identify this bus during runtime More...
 
volatile uint32_t _t_addr
 a memory address in case this is mapped using mmio More...
 

Detailed Description

template<typename T>
class orcasim::modeling::Signal< T >

The Signal class models a generic bus of width equals to the sizeof(T)

Definition at line 45 of file Signal.hpp.

Constructor & Destructor Documentation

§ Signal() [1/3]

template<typename T>
Signal::Signal ( T *  t_ptr,
uint32_t  addr,
std::string  name 
)

Constructor.

Instiate a new bus with external storage (can be changed later via "MapTo()")

Creates a new Signal using external storage

Parameters
t_ptrpointer to the location of the value of the bus.
name(optional) An arbitrary name for the instance.
addre(optinal) Address to which the bus is mapped in memory.
t_ptr
addr
name

Definition at line 61 of file Signal.cpp.

61  {
62  _t_ptr = t_ptr;
63  _t_addr = addr;
64  _t_name = name;
65 }
std::string _t_name
an optional name to identify this bus during runtime
Definition: Signal.hpp:54
volatile T * _t_ptr
pointer to the place where the bus data will be stored
Definition: Signal.hpp:48
volatile uint32_t _t_addr
a memory address in case this is mapped using mmio
Definition: Signal.hpp:57

§ Signal() [2/3]

template<typename T>
Signal::Signal ( uint32_t  addr,
std::string  name 
)

Constructor.

Create new Signal using internal storage

Parameters
name(optional) An arbitrary name for the instance.
addr(optinal) Address to which the bus is mapped in memory.

Definition at line 68 of file Signal.cpp.

68  {
69  _t_ptr = &_t_storage;
70  _t_addr = addr;
71  _t_name = name;
72 }
std::string _t_name
an optional name to identify this bus during runtime
Definition: Signal.hpp:54
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
volatile uint32_t _t_addr
a memory address in case this is mapped using mmio
Definition: Signal.hpp:57

§ Signal() [3/3]

template<typename T>
Signal::Signal ( std::string  name)
explicit

Constructor.

Instiate a new bus with external storage (can be changed later via "MapTo(&)")

Create new Signal using internal storage

Parameters
name(optional) An arbitrary name for the instance.
nameA unique name to the bus (optional)
default_valueA value to be read in case none has been set yet
addrA memory base to be used within memory mapping

Definition at line 46 of file Signal.cpp.

46  {
47  _t_ptr = &_t_storage;
48  _t_name = name;
49 }
std::string _t_name
an optional name to identify this bus during runtime
Definition: Signal.hpp:54
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

§ ~Signal()

template<typename T >
Signal::~Signal ( )

Destructor.

Dtor.

Note
DO NOT free _t_ptr by any means as this pointer must be freed by the class which allocated the space.

Definition at line 111 of file Signal.cpp.

111 { }

Member Function Documentation

§ Dec()

template<typename T>
void Signal::Dec ( val)

Descrements the value of the bus by the given value.

Set the value of the bus.

Parameters
valValue to besubtracted from the current value of the bus
valthe value

Definition at line 145 of file Signal.cpp.

145  {
146  *_t_ptr = (*_t_ptr) - val;
147 }
volatile T * _t_ptr
pointer to the place where the bus data will be stored
Definition: Signal.hpp:48

§ GetAddress()

template<typename T >
uint32_t Signal::GetAddress ( )

Return the addres to which this Signal is mapped.

Get the memory mapping address.

Returns
The address of mmio (zero if not mapped)
the address

Definition at line 154 of file Signal.cpp.

154  {
155  return _t_addr;
156 }
volatile uint32_t _t_addr
a memory address in case this is mapped using mmio
Definition: Signal.hpp:57

§ GetName()

template<typename T >
std::string Signal::GetName ( )

Return the name of the Signal.

Get the name of the Signal.

Returns
The name of the Signal or empty if no name has been set.
the name (empty string if empty)

Definition at line 163 of file Signal.cpp.

163  {
164  return _t_name;
165 }
std::string _t_name
an optional name to identify this bus during runtime
Definition: Signal.hpp:54

§ Inc()

template<typename T>
void Signal::Inc ( val)

Increments the value of the bus by the given value.

Set the value of the bus.

Parameters
valValue to be added to the current value of the bus
valthe value

Definition at line 136 of file Signal.cpp.

136  {
137  *_t_ptr = (*_t_ptr) + val;
138 }
volatile T * _t_ptr
pointer to the place where the bus data will be stored
Definition: Signal.hpp:48

§ MapTo() [1/2]

template<typename T >
void Signal::MapTo ( bool  keep_val = true)

Maps current Signal to the internal storage.

Parameters
keep_valCopies current value to internal storage

Definition at line 79 of file Signal.cpp.

79  {
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 }
T Read()
Get the last value writen to the bus.
Definition: Signal.cpp:118
void Write(T val)
Writes some value to the bus.
Definition: Signal.cpp:127
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

§ MapTo() [2/2]

template<typename T >
void Signal::MapTo ( MemoryType memptr,
MemoryAddr  address,
bool  keep_val = true 
)

Maps current Signal to an external storage, updates internal reference and sets a new address.

Maps current Signal to an external storage and updates internal reference.

Parameters
memptrExternal storage memory place
addressMemory address if using memory maps
keep_valSet to true to keep current signal val
memptrLocation to shadown the access in
addressto be used if mapping to memory
keep_valset to true to keep current signal value

Definition at line 98 of file Signal.cpp.

98  {
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 }
T Read()
Get the last value writen to the bus.
Definition: Signal.cpp:118
volatile T * _t_ptr
pointer to the place where the bus data will be stored
Definition: Signal.hpp:48
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

§ Read()

template<typename T >
T Signal::Read ( )

Get the last value writen to the bus.

Read the value stored into the bus.

Returns
A value of type T.
the value

Definition at line 118 of file Signal.cpp.

118  {
119  return *_t_ptr;
120 }
volatile T * _t_ptr
pointer to the place where the bus data will be stored
Definition: Signal.hpp:48

§ SetAddress()

template<typename T >
void Signal::SetAddress ( MemoryAddr  addr)

Set an address for this signal.

Set an address for the signal.

Definition at line 171 of file Signal.cpp.

171  {
172  _t_addr = addr;
173 }
volatile uint32_t _t_addr
a memory address in case this is mapped using mmio
Definition: Signal.hpp:57

§ Write()

template<typename T>
void Signal::Write ( val)

Writes some value to the bus.

Set the value of the bus.

Parameters
valValue to be writen to the bus
valthe value

Definition at line 127 of file Signal.cpp.

127  {
128  *_t_ptr = val;
129 }
volatile T * _t_ptr
pointer to the place where the bus data will be stored
Definition: Signal.hpp:48

Member Data Documentation

§ _t_addr

template<typename T>
volatile uint32_t orcasim::modeling::Signal< T >::_t_addr
private

a memory address in case this is mapped using mmio

Definition at line 57 of file Signal.hpp.

§ _t_name

template<typename T>
std::string orcasim::modeling::Signal< T >::_t_name
private

an optional name to identify this bus during runtime

Definition at line 54 of file Signal.hpp.

§ _t_ptr

template<typename T>
volatile T* orcasim::modeling::Signal< T >::_t_ptr
private

pointer to the place where the bus data will be stored

Definition at line 48 of file Signal.hpp.

§ _t_storage

template<typename T>
volatile T orcasim::modeling::Signal< T >::_t_storage
private

internal storage (necessary when mmio is not used)

Definition at line 51 of file Signal.hpp.


The documentation for this class was generated from the following files: