-
Notifications
You must be signed in to change notification settings - Fork 2
/
regT.h
63 lines (50 loc) · 1008 Bytes
/
regT.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef REGTMOD_H
#define REGTMOD_H
/**
*
* regT template interface.
*/
#include <systemc.h>
/**
* regT template.
* regT template implements a variable width register.
* The type of data is selected by the template class T.
* Synchronous on writes and resets.
*
* - input ports
* - \c T \c din - input
* - \c bool \c reset - reset
* - \c bool \c enable - enable
* - \c bool \c clk - clock
* - output ports
* - \c T \c dout - output
*/
template <class T> class regT : public sc_module
{
public:
sc_in< T > din;
sc_out< T > dout;
sc_in< bool > reset;
sc_in< bool > enable;
sc_in< bool > clk;
T val;
SC_CTOR(regT)
{
SC_METHOD(entry);
sensitive_pos << clk;
val=0;
}
void entry();
};
template <class T> void regT<T>::entry()
{
if(reset) {
val=0;
dout.write(val);
}
else if(clk.event() && clk==1 && enable==1) {
val=din.read();
dout.write(val);
}
}
#endif