forked from taitashaw/HLS_FPGA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdsp_pipeline.cpp
More file actions
74 lines (63 loc) Β· 2.05 KB
/
Copy pathdsp_pipeline.cpp
File metadata and controls
74 lines (63 loc) Β· 2.05 KB
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
/*** By John Bagshaw ***/
#include "HLS_dataflow_accel_dsp.hpp"
// Load function (input stream to intermediate stream)
void load_process(hls::stream<data_t>& in, hls::stream<data_t>& out) {
for (int i = 0; i < 1024; ++i) {
#pragma HLS PIPELINE II=1
if (!in.empty()) {
data_t val = in.read();
out.write(val);
}
}
}
// FIR filter process
void fir_filter_process(hls::stream<data_t>& in, hls::stream<data_t>& out) {
data_t coeffs[3] = {0.25, 0.5, 0.25};
data_t shift_reg[3] = {0, 0, 0};
for (int i = 0; i < 1024; ++i) {
#pragma HLS PIPELINE II=1
if (!in.empty()) {
shift_reg[2] = shift_reg[1];
shift_reg[1] = shift_reg[0];
shift_reg[0] = in.read();
data_t acc = 0;
for (int j = 0; j < 3; ++j) {
acc += coeffs[j] * shift_reg[j];
}
out.write(acc);
}
}
}
// Gain adjustment process
void gain_adjust_process(hls::stream<data_t>& in, hls::stream<data_t>& out, float gain) {
for (int i = 0; i < 1024; ++i) {
#pragma HLS PIPELINE II=1
if (!in.empty()) {
data_t val = in.read();
out.write(val * gain);
}
}
}
// Store function (intermediate stream to output stream)
void store_process(hls::stream<data_t>& in, hls::stream<data_t>& out) {
for (int i = 0; i < 1024; ++i) {
#pragma HLS PIPELINE II=1
if (!in.empty()) {
out.write(in.read());
}
}
}
// Top-level pipeline with dataflow optimization
void dsp_pipeline(hls::stream<data_t>& in_stream,
hls::stream<data_t>& out_stream,
float gain) {
#pragma HLS DATAFLOW
hls::stream<data_t> s1("s1"), s2("s2"), s3("s3");
#pragma HLS STREAM variable=s1 depth=8
#pragma HLS STREAM variable=s2 depth=8
#pragma HLS STREAM variable=s3 depth=8
load_process(in_stream, s1);
fir_filter_process(s1, s2);
gain_adjust_process(s2, s3, gain);
store_process(s3, out_stream);
}