-
Notifications
You must be signed in to change notification settings - Fork 0
/
decimation.h
89 lines (78 loc) · 3.12 KB
/
decimation.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef _DECIMATION_H_
#define _DECIMATION_H_
#include <iostream>
using namespace std;
#include <systemc>
using namespace sc_dt;
using namespace sc_core;
const int WIDTH = 3;
#include "ready_valid_port.h"
class decimation : public sc_module
{
public:
sc_in_clk i_clk;
sc_in<bool> i_rst;
// i_a input ports: message, ready, valid signals
rdyvld_port_in<sc_uint<WIDTH>> i_a_port;
// i_b input ports: message, ready, valid signals
rdyvld_port_in<sc_uint<WIDTH>> i_b_port;
// i_c input ports: message, ready, valid signals
rdyvld_port_in<sc_uint<WIDTH>> i_c_port;
// o_sum output ports: message, ready, valid signals
rdyvld_port_out<sc_uint<WIDTH + 1>> o_sum_port;
void do_decimation()
{
const float x_input_signal = {0.500, 0.525, 0.549, 0.574, 0.598, 0.622, 0.646, 0.670,
0.693, 0.715, 0.737, 0.759, 0.780, 0.800, 0.819, 0.838,
0.856, 0.873, 0.889, 0.904, 0.918, 0.931, 0.943, 0.954,
0.964, 0.972, 0.980, 0.986, 0.991, 0.995, 0.998, 1.000,
1.000, 0.999, 0.997, 0.994, 0.989, 0.983, 0.976, 0.968,
0.959, 0.949, 0.937, 0.925, 0.911, 0.896, 0.881, 0.864,
0.847, 0.829, 0.810, 0.790, 0.769, 0.748, 0.726, 0.704,
0.681, 0.658, 0.634, 0.610, 0.586, 0.562, 0.537, 0.512,
0.488, 0.463, 0.438, 0.414, 0.390, 0.366, 0.342, 0.319,
0.296, 0.274, 0.252, 0.231, 0.210, 0.190, 0.171, 0.153,
0.136, 0.119, 0.104, 0.089, 0.075, 0.063, 0.051, 0.041,
0.032, 0.024, 0.017, 0.011, 0.006, 0.003, 0.001, 0.000,
0.000, 0.002, 0.005, 0.009, 0.014, 0.020, 0.028, 0.036,
0.046, 0.057, 0.069, 0.082, 0.096, 0.111, 0.127, 0.144,
0.162, 0.181, 0.200, 0.220, 0.241, 0.263, 0.285, 0.307,
0.330, 0.354, 0.378, 0.402, 0.426, 0.451, 0.475, 0.500};
// initilize handshaking signals
i_a_port.rdy.write(false);
i_b_port.rdy.write(false);
i_c_port.rdy.write(false);
o_sum_port.vld.write(false);
while (true)
{
for (i = 0; i < 126; i += 2)
{
_i_a = x_input_signal[i];
_i_b = x_input_signal[i + 1];
_i_c = x_input_signal[i + 2];
wait();
_o_sum = _i_a * (1 / 6) + _i_b * (1 / 3) + _i_c * (1 / 2);
o_sum_port.write(_o_sum);
wait();
}
}
SC_HAS_PROCESS(decimation);
decimation(sc_module_name name, int i) : id(i)
{
SC_THREAD(do_decimation);
sensitive << i_clk.pos();
dont_initialize();
// reset_signal_is(i_rst, false);
}
sc_uint<WIDTH> i_a() { return _i_a; }
sc_uint<WIDTH> i_b() { return _i_b; }
sc_uint<WIDTH> i_c() { return _i_c; }
sc_uint<WIDTH + 1> o_sum() { return _o_sum; }
private:
const int id;
sc_uint<WIDTH> _i_a;
sc_uint<WIDTH> _i_b;
sc_uint<WIDTH> _i_c;
sc_uint<WIDTH + 1> _o_sum;
};
#endif