Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit e7fe2f1

Browse files
committed
Solved ERROR
1 parent a68d324 commit e7fe2f1

File tree

11 files changed

+144
-91
lines changed

11 files changed

+144
-91
lines changed

FPL2018.rar

-14.5 MB
Binary file not shown.

Milestone-2/src/core.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,52 @@
11
#include "my_ip_hls.hpp"
2-
#include <iostream>
3-
#include <stdint.h>
42

5-
void core(stream<axiWord> &ps2ipIntFifo,stream<axiWord> &ip2psIntFifo,uint32 rules[],uint32 rulesCnts[]) {
3+
void core( stream<axiWord> &ps2ipIntFifo,stream<axiWord> &ip2psIntFifo,
4+
uint32 rule0Reg, uint32 rule1Reg, uint32 rule2Reg,
5+
uint32 &cnt0Reg, uint32 &cnt1Reg, uint32 &cnt2Reg) {
6+
67
#pragma HLS PIPELINE II=1 enable_flush
78
#pragma HLS INTERFACE ap_ctrl_none port=return
89

9-
static enum inStates {
10-
IN_STATE_IDLE = 0
11-
} curState;
10+
static enum inStates {
11+
IN_STATE_IDLE = 0
12+
} curState;
1213

1314
static axiWord newInWord = {0,0,0};
1415

1516
switch(curState) {
17+
1618
case (IN_STATE_IDLE): {
1719
if (!ps2ipIntFifo.empty()) {
1820
ps2ipIntFifo.read(newInWord);
1921

2022
// Check if this packet triggers one of the rules
21-
int flag = 0 ;
22-
for(int i=0; i<3; i++){
23-
if (newInWord.data == rules[i]){
24-
rulesCnts[i] = rulesCnts[i] + 1;
25-
flag = 1;
26-
}
23+
if (rule0Reg == newInWord.data){
24+
cnt0Reg++;
25+
}
26+
else if(rule1Reg == newInWord.data){
27+
cnt1Reg++;
28+
}
29+
else if (rule2Reg == newInWord.data){
30+
cnt2Reg++;
2731
}
28-
2932
// Write back packet only in case none
3033
// of the rules has been triggered
31-
if(flag == 0){
32-
ip2psIntFifo.write(newInWord);
34+
else{
35+
ip2psIntFifo.write(newInWord);
3336
}
3437
}
38+
3539
curState = IN_STATE_IDLE;
3640

3741
break;
3842
}
3943
};
44+
4045
return;
46+
4147
}
48+
49+
50+
51+
52+

Milestone-2/src/counters_out.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "my_ip_hls.hpp"
2+
3+
void counters_out( uint32 cnt0Reg, uint32 cnt1Reg, uint32 cnt2Reg,
4+
uint32 &rule0cnt, uint32 &rule1cnt, uint32 &rule2cnt){
5+
6+
// Read rules' Counters
7+
rule0cnt = cnt0Reg;
8+
rule1cnt = cnt1Reg;
9+
rule2cnt = cnt2Reg;
10+
}

Milestone-2/src/ip2ps_fifo.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#include "my_ip_hls.hpp"
22

3+
34
void ip2ps_fifo(stream<axiWord> &ip2psIntFifo,stream<axiWord> &ip2ps) {
45
#pragma HLS PIPELINE II=1 enable_flush
56

6-
static enum inStates {
7-
IN_STATE_IDLE = 0
8-
} curState;
7+
static enum inStates { IN_STATE_IDLE = 0
8+
} curState;
9+
910

1011
switch(curState) {
12+
1113
case (IN_STATE_IDLE): {
1214
if (!ip2psIntFifo.empty()) {
1315
axiWord newInWord = {0,0,0};
@@ -23,3 +25,8 @@ void ip2ps_fifo(stream<axiWord> &ip2psIntFifo,stream<axiWord> &ip2ps) {
2325
return;
2426

2527
}
28+
29+
30+
31+
32+

Milestone-2/src/my_ip_hls.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#include "my_ip_hls.hpp"
2-
#include <iostream>
3-
#include <stdint.h>
4-
#include <hls_stream.h>
5-
#include <ap_int.h>
6-
#include <stdio.h>
72

8-
void my_ip_hls(stream<axiWord> &slaveIn,stream<axiWord> &masterOut,uint32 rule0, uint32 rule1, uint32 rule2, uint32 &rule0cnt, uint32 &rule1cnt, uint32 &rule2cnt) {
3+
4+
void my_ip_hls( stream<axiWord> &slaveIn,stream<axiWord> &masterOut,
5+
uint32 rule0, uint32 rule1, uint32 rule2){//,
6+
//uint32 &rule0cnt, uint32 &rule1cnt, uint32 &rule2cnt) {
97

108
// AXI 4 Stream interface
119
#pragma HLS DATAFLOW interval=1
@@ -21,25 +19,39 @@ void my_ip_hls(stream<axiWord> &slaveIn,stream<axiWord> &masterOut,uint32 rule0,
2119
#pragma HLS INTERFACE s_axilite port=rule1 bundle=psAxiLite
2220
#pragma HLS INTERFACE s_axilite port=rule2 bundle=psAxiLite
2321
// Rules' Counters
24-
#pragma HLS INTERFACE s_axilite port=rule0cnt bundle=psAxiLite
25-
#pragma HLS INTERFACE s_axilite port=rule1cnt bundle=psAxiLite
26-
#pragma HLS INTERFACE s_axilite port=rule2cnt bundle=psAxiLite
22+
//#pragma HLS INTERFACE s_axilite port=rule0cnt bundle=psAxiLite
23+
//#pragma HLS INTERFACE s_axilite port=rule1cnt bundle=psAxiLite
24+
//#pragma HLS INTERFACE s_axilite port=rule2cnt bundle=psAxiLite
2725

28-
//internal fifos for input and output data streams
26+
//internal fifos
2927
static stream<axiWord> ps2ipFifo("ps2ipFifo");
3028
#pragma HLS STREAM variable=ps2ipFifo depth=64 dim=1
3129
static stream<axiWord> ip2psFifo("ip2psFifo");
3230
#pragma HLS STREAM variable=ip2psFifo depth=64 dim=1
3331

34-
35-
static uint32 rulesCnts [3] = { 0, 0, 0 }; // Rules' Counters registers
36-
static uint32 rules [3] = { -1 , -1 , -1 }; // Rules registers
37-
38-
give_rules(rule0, rule1, rule2, rules, rulesCnts); // Save Rules and their counters in registers
39-
ps2ip_fifo(slaveIn,ps2ipFifo); // FIFO that keeps input data
40-
core(ps2ipFifo,ip2psFifo,rules,rulesCnts); // Core of the IP with core logic
41-
read_rules_counters(rulesCnts, rule0cnt, rule1cnt, rule2cnt); // Give back rules' counters
42-
ip2ps_fifo(ip2psFifo,masterOut); // FIFO that keeps output data
32+
// Rules registers
33+
static uint32 rule0Reg=0;
34+
static uint32 rule1Reg=0;
35+
static uint32 rule2Reg=0;
36+
// Rules' Counters registers
37+
static uint32 cnt0Reg=0;
38+
static uint32 cnt1Reg=0;
39+
static uint32 cnt2Reg=0;
40+
41+
// Save Rules and their counters in registers
42+
rules_in(rule0, rule1, rule2, rule0Reg, rule1Reg, rule2Reg);
43+
44+
//fifo that keeps input data
45+
ps2ip_fifo(slaveIn,ps2ipFifo);
46+
//core of the IP
47+
core(ps2ipFifo, ip2psFifo, rule0Reg, rule1Reg, rule2Reg, cnt0Reg, cnt1Reg, cnt2Reg);
48+
//fifo that keeps output data
49+
ip2ps_fifo(ip2psFifo,masterOut);
50+
51+
// Give back rules' counters
52+
// TODO
53+
//counters_out(cnt0Reg, cnt1Reg, cnt2Reg, rule0cnt, rule1cnt, rule2cnt);
54+
//printf("\nResults:\n Counter 0 : %d\n Counter 1 : %d\n Counter 2 : %d\n---------------------------------\n\n",(int)cnt0Reg,(int)cnt1Reg,(int)cnt2Reg);
4355

4456
return;
4557

Milestone-2/src/my_ip_hls.hpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <ap_int.h>
33
#include <iostream>
44
#include <stdint.h>
5-
#include <stdio.h>
65

76
using namespace hls;
87

@@ -17,12 +16,16 @@ typedef ap_uint<1> uint1;
1716
typedef ap_uint<2> uint2;
1817

1918
void ps2ip_fifo(stream<axiWord> &ps2ip,stream<axiWord> &ps2ipIntFifo);
20-
2119
void ip2ps_fifo(stream<axiWord> &ip2psIntFifo,stream<axiWord> &ip2ps);
2220

23-
void core(stream<axiWord> &ps2ipIntFifo,stream<axiWord> &ip2psIntFifo,uint32 rules[],uint32 rulesCnts[]);
21+
void core( stream<axiWord> &ps2ipIntFifo,stream<axiWord> &ip2psIntFifo,
22+
uint32 rule0Reg, uint32 rule1Reg, uint32 rule2Reg,
23+
uint32 &cnt0Reg, uint32 &cnt1Reg, uint32 &cnt2Reg);
2424

25-
void my_ip_hls(stream<axiWord> &slaveIn,stream<axiWord> &masterOut, uint32 rule0, uint32 rule1, uint32 rule2, uint32 &rule0cnt, uint32 &rule1cnt, uint32 &rule2cnt);
25+
//TODO: AXI 4 Lite counters out
26+
void my_ip_hls( stream<axiWord> &slaveIn,stream<axiWord> &masterOut,
27+
uint32 rule0, uint32 rule1, uint32 rule2);
28+
//uint32 &rule0cnt, uint32 &rule1cnt, uint32 &rule2cnt);
2629

2730
/**
2831
* \brief This function saves rules' values from axi 4 lite interface in internal registers.
@@ -32,19 +35,25 @@ void my_ip_hls(stream<axiWord> &slaveIn,stream<axiWord> &masterOut, uint32 rule0
3235
* \param rule1 Second rule value
3336
* \param rule2 Third rule value
3437
*
35-
* \param rules The array style registers that rules are saved
36-
* \param rulesCnts The array style registers that rules counters are located
38+
* \param rule0Reg Registers that first rule is located
39+
* \param rule1Reg Registers that second rule is located
40+
* \param rule2Reg Registers that third rule is located
3741
*/
38-
void give_rules(uint32 rule0, uint32 rule1, uint32 rule2, uint32 rules[], uint32 rulesCnts[]);
42+
void rules_in( uint32 rule0, uint32 rule1, uint32 rule2,
43+
uint32 &rule0Reg, uint32 &rule1Reg, uint32 &rule2Reg);
3944

4045
/**
4146
* \brief The actual wiring between rules' counters internal registers and
4247
* axi 4 lite interface.
4348
*
44-
* \param rulesCnts The array style registers that rules' counters are located
49+
* \param cnt0Reg Registers that first counter value is located
50+
* \param cnt1Reg Registers that second counter value is located
51+
* \param cnt2Reg Registers that third counter value is located
52+
*
53+
* \param rule0cnt first counter to Axi 4 Lite
54+
* \param rule1cnt second counter to Axi 4 Lite
55+
* \param rule2cnt third counter to Axi 4 Lite
4556
*
46-
* \param rule0cnt First rule counter value
47-
* \param rule1cnt Second rule counter value
48-
* \param rule2cnt Third rule counter value
4957
*/
50-
void read_rules_counters(uint32 rulesCnts[] ,uint32 &rule0cnt, uint32 &rule1cnt, uint32 &rule2cnt);
58+
void counters_out( uint32 cnt0Reg, uint32 cnt1Reg, uint32 cnt2Reg,
59+
uint32 &rule0cnt, uint32 &rule1cnt, uint32 &rule2cnt);

Milestone-2/src/my_ip_hls_tb.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ uint32 MDATA [STREAM_TEST_ITERATIONS] = {10,15,20,25,30,35,40,45,50,55,
2121
// This part of the code is just for testing and DEBUGING purposes
2222
// If you need to test what is going to happen in case that you would like
2323
// to change/give one or more of the rules at a specific point of execution
24-
// un-comment DEBUG and use below variables and function
24+
// uncomment DEBUG and use below variables and function as needed
2525

2626
//#define DEBUG 0
2727

@@ -31,10 +31,19 @@ uint32 rules[3][numOfChanges] = {
3131
{10,40}, //Rule 0
3232
{65,35}, //Rule 1
3333
{35,0}}; //Rule 2
34-
// The domain of iterations that we are going to use for each rule value
34+
35+
// The domain of iterations that we are going to use for each rule
36+
// E.g.
37+
// If you have the following arrays
38+
// rules {a, b, c}
39+
// rulesChangeOnIteration {d, f, g, h}
40+
// Then:
41+
// use rule a in [d, f)
42+
// use rule b in [f, g)
43+
// use rule c in [g, h)
3544
uint32 rulesChangeOnIteration[3][numOfChanges+1] = {
36-
{0,15,1000}, //Rule 0
37-
{0,15,1000}, //Rule 1
45+
{0,15,1000}, //Rule 0
46+
{0,15,1000}, //Rule 1
3847
{0,1000,1000},}; //Rule 2
3948

4049
// The value that each rule has at a specific time of operation
@@ -57,10 +66,15 @@ int main() {
5766
stream<axiWord> slaveIn("slaveIn");
5867
stream<axiWord> masterOut("masterOut");
5968

60-
static uint32 rulesCnts [3] = { 0, 0, 0 }; // Rule Counters
69+
uint32 rule0cnt = 0, rule1cnt = 0, rule2cnt = 0; // Rule Counters
70+
71+
// DEBUG Message
72+
#ifdef ARRAY_SOLUTION
73+
printf("\n---------------------------------\nArray solution\nBegin Simulation...\n");
74+
#else
75+
printf("\n---------------------------------\nSimple Solution\nBegin Simulation...\n");
76+
#endif
6177

62-
printf("\n---------------------------------\n");
63-
printf("Begin Simulation...\n");
6478
for (i=0;i<STREAM_TEST_ITERATIONS;i++) {
6579
axiWord dataIn = {0,0,0};
6680
dataIn.data = MDATA[i];
@@ -73,10 +87,11 @@ int main() {
7387

7488
slaveIn.write(dataIn);
7589

90+
// Select which simulation is going to be executed (basic VS complex)
7691
#ifdef DEBUG
77-
my_ip_hls(slaveIn, masterOut, ruleXState(0,i), ruleXState(1,i), ruleXState(2,i), rulesCnts[0], rulesCnts[1], rulesCnts[2]);
92+
my_ip_hls(slaveIn, masterOut, ruleXState(0,i), ruleXState(1,i), ruleXState(2,i), rule0cnt, rule1cnt, rule2cnt);
7893
#else
79-
my_ip_hls(slaveIn, masterOut, static0Rule, static1Rule, static2Rule, rulesCnts[0], rulesCnts[1], rulesCnts[2]);
94+
my_ip_hls(slaveIn, masterOut, static0Rule, static1Rule, static2Rule);//, rule0cnt, rule1cnt, rule2cnt);
8095
#endif
8196

8297
if (!masterOut.empty()) {
@@ -88,17 +103,14 @@ int main() {
88103
printf("%d: no data available!\n",(int)i);
89104
}
90105

106+
// DEBUG Message
91107
#ifdef DEBUG
92108
printf("R0: %d | R1: %d | R2: %d\n", (int)ruleXState(0,i), (int)ruleXState(1,i), (int)ruleXState(2,i));
93-
printf("C0: %d | C1: %d | C2: %d\n--\n", int(rulesCnts[0]), int(rulesCnts[1]), int(rulesCnts[2]));
109+
printf("C0: %d | C1: %d | C2: %d\n--\n", (int)rule0cnt, (int)rule1cnt, (int)rule2cnt);
94110
#endif
95111

96112
}
97-
printf("\nResults:\n");
98-
printf(" Counter 0 : %d\n", int(rulesCnts[0]));
99-
printf(" Counter 1 : %d\n", int(rulesCnts[1]));
100-
printf(" Counter 2 : %d\n", int(rulesCnts[2]));
101-
printf("---------------------------------\n\n");
113+
//printf("\nResults:\n Counter 0 : %d\n Counter 1 : %d\n Counter 2 : %d\n---------------------------------\n\n")
102114

103115
return 0;
104116
}

Milestone-2/src/ps2ip_fifo.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#include "my_ip_hls.hpp"
22

3+
34
void ps2ip_fifo(stream<axiWord> &ps2ip,stream<axiWord> &ps2ipIntFifo) {
45
#pragma HLS PIPELINE II=1 enable_flush
56

6-
static enum inStates {
7-
IN_STATE_IDLE = 0
8-
} curState;
7+
static enum inStates { IN_STATE_IDLE = 0
8+
} curState;
9+
910

1011
switch(curState) {
12+
1113
case (IN_STATE_IDLE): {
1214
if (!ps2ip.empty()) {
1315
axiWord newInWord = {0,0,0};
@@ -23,3 +25,8 @@ void ps2ip_fifo(stream<axiWord> &ps2ip,stream<axiWord> &ps2ipIntFifo) {
2325
return;
2426

2527
}
28+
29+
30+
31+
32+

Milestone-2/src/rule_module_read.cpp

Lines changed: 0 additions & 9 deletions
This file was deleted.

Milestone-2/src/rule_module_write.cpp

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)