-
Notifications
You must be signed in to change notification settings - Fork 2
/
mux4.h
58 lines (49 loc) · 1.05 KB
/
mux4.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
#ifndef MUX4MOD_H
#define MUX4MOD_H
/**
*
* 2:1 Mux module template.
*/
#include <systemc.h>
/**
* Mux module.
* Mux module models a generic 2:1 multiplexor of template type T.
* Implementation based on a template class.
*
* - input ports
* - \c T \c din0 - input
* - \c T \c din1 - input
* - \c bool \c sel - select
* - output ports
* - \c T \c dout - output
*/
template <class T> class mux4: public sc_module
{
public:
sc_in< sc_uint<32> > PC4;
sc_in< sc_uint<32> > jr;
sc_in< sc_uint<32> > bta;
sc_in< sc_uint<32> > jta;
sc_in< sc_uint<2> > sel;
sc_out< T > dout;
SC_CTOR(mux4)
{
SC_METHOD(entry);
sensitive << PC4 << jr << bta << jta << sel;
}
void entry();
};
template <class T> void mux4<T>::entry()
{
switch(sel.read()) {
case 0: dout.write(PC4.read());
break;
case 1: dout.write(jr.read());
break;
case 2: dout.write(bta.read());
break;
case 3: dout.write(jta.read());
break;
}
}
#endif