Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Embedded Acceleration
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vipin Thomas
Embedded Acceleration
Commits
b9d82380
Commit
b9d82380
authored
3 years ago
by
Vipin Thomas
Browse files
Options
Downloads
Patches
Plain Diff
Update pixel_original.cpp
parent
d75b8718
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Testbench/pixel_original.cpp
+97
-86
97 additions, 86 deletions
Testbench/pixel_original.cpp
with
97 additions
and
86 deletions
Testbench/pixel_original.cpp
+
97
−
86
View file @
b9d82380
...
...
@@ -11,79 +11,76 @@
pkt_t
tmpA
;
void
pixel
(
ap_int
<
32
>
&
in_decimal
,
ap_int
<
32
>
selector
,
ap_int
<
32
>
position1
,
ap_int
<
32
>
position2
,
hls
::
stream
<
pkt_t
>
&
din
,
hls
::
stream
<
pkt_t
>
&
dout
void
pixel
(
apint
&
in_decimal
,
apint
selector
,
apint
stream_count
,
stream
&
din
,
stream
&
dout
)
{
#pragma HLS INTERFACE s_axilite port=in_decimal
#pragma HLS INTERFACE s_axilite port=selector
#pragma HLS INTERFACE s_axilite port=position1
#pragma HLS INTERFACE s_axilite port=position2
#pragma HLS INTERFACE s_axilite port=in_decimal
#pragma HLS INTERFACE s_axilite port=selector
#pragma HLS INTERFACE s_axilite port=stream_count
#pragma HLS INTERFACE axis port=din
#pragma HLS INTERFACE axis port=dout
din
>>
tmpA
;
din
>>
tmpA
;
//input data
switch
(
selector
)
switch
(
selector
)
{
// case 0 is for encoding
case
0
:
if
(
count_streams
==
0
){
final_char
=
0
;
decNum
=
in_decimal
;
decNum
=
in_decimal
;
//getting the ascii values of the word from the register
}
//123456321
if
((
count_streams
>=
(
position1
-
1
))
&&
(
count_streams
<
position2
)){
// addNum=0;
addNum
=
0
;
if
(
decimalCounter
%
8
==
0
){
/*checking if the counter is 8 which means the process reached the 8th bit*/
lastDecimalVal
=
getDecimal
(
decNum
);
decNum
/=
100
;
charIn
=
convert
(
lastDecimalVal
);
decNum
/=
100
;
//to delete the processed ascii value and get the next one
charIn
=
convert
(
lastDecimalVal
);
//to find the binary of the next ascii value
}
addNum
=
charIn
%
10
;
charIn
=
(
int
)
charIn
/
10
;
// if(decNum !=0 ){
// tmpA.data += getDecimal(decNum);
// decNum = decNum/1000;
// }
addNum
=
charIn
%
10
;
//LSB of charIn
charIn
=
(
int
)
charIn
/
10
;
//deleting lsb and get the next bit(lsb)
//updating the input data according to addNum and lsb of the input data.
//if addNum is equal to 1 and input data is even , 1 will be added to input data which turns to odd
//otherwise no action needed
if
(
tmpA
.
data
%
2
==
0
&&
addNum
==
1
){
tmpA
.
data
+=
1
;
}
else
if
(
tmpA
.
data
%
2
!=
0
&&
addNum
==
0
){
}
//if addNum is equal to 0, input data is odd, 1 will be subtracted fro the input data which will turn it to even
//otherwise no action needed
else
if
(
tmpA
.
data
%
2
!=
0
&&
addNum
==
0
){
tmpA
.
data
-=
1
;
}
decimalCounter
++
;
}
decimalCounter
++
;
break
;
//case 1 is for decoding
case
1
:
if
((
count_streams
>=
(
position1
-
1
))
&&
(
count_streams
<
position2
)){
dec
rypt
(
tmpA
.
data
);
dec
ode
(
tmpA
.
data
);
//getting decoded binary value bit by bit for every character
decimalCounter
++
;
if
(
decimalCounter
==
8
){
//after processing 8 bits, the ascii value will be returned by the convertBinInt
decimalOut
=
decimalOut
*
100
+
convertBinInt
(
final_char
);
decimalCounter
=
0
;
final_char
=
0
;
}
}
break
;
default
:
...
...
@@ -92,7 +89,8 @@
count_streams
++
;
if
(
count_streams
==
position2
-
1
){
if
(
count_streams
==
stream_count
){
//resetting variables
count_streams
=
0
;
charIn
=
0
;
addNum
=
0
;
...
...
@@ -105,54 +103,67 @@
}
if
(
count_streams
==
stream_count
){
//setting TLAST signal to 1
tmpA
.
last
=
1
;
}
dout
<<
tmpA
;
}
if
(
count_streams
==
position2
-
1
){
tmpA
.
last
=
1
;
}
tmpA
.
strb
=
0xf
;
dout
<<
tmpA
;
}
long
long
convert
(
int
n
)
{
long
long
bin
=
0
;
int
rem
,
i
=
1
,
step
=
1
;
while
(
n
!=
0
)
{
rem
=
n
%
2
;
n
/=
2
;
bin
+=
rem
*
i
;
i
*=
10
;
}
return
bin
;
}
void
decrypt
(
int
data
)
{
int
bit
;
if
(
data
%
2
==
0
){
bit
=
0
;
}
else
if
(
data
%
2
!=
0
){
bit
=
1
;
}
final_char
=
final_char
*
10
+
bit
;
}
int
convertBinInt
(
long
long
n
)
{
int
dec
=
0
,
i
=
7
,
b
=
0
,
rem
=
0
;
while
(
n
!=
0
)
{
b
=
pow
(
10
,
i
);
rem
=
n
/
b
;
n
=
n
%
b
;
dec
+=
rem
*
pow
(
2
,
7
-
i
);
--
i
;
}
return
dec
;
}
int
getDecimal
(
int
n
)
{
int
num
=
0
;
num
=
n
%
100
;
return
num
;
}
long
long
convert
(
int
n
)
{
/*
This function converts a decimal number to a Binary number and returns it
*/
long
long
bin
=
0
;
int
rem
,
i
=
1
,
step
=
1
;
while
(
n
!=
0
)
{
rem
=
n
%
2
;
n
/=
2
;
bin
+=
rem
*
i
;
i
*=
10
;
}
return
bin
;
}
void
decode
(
int
data
)
{
/*
get the binary value of the embedded ascii values by combining the LSBs.
*/
int
bit
;
if
(
data
%
2
==
0
){
bit
=
0
;
}
else
if
(
data
%
2
!=
0
){
bit
=
1
;
}
final_char
=
final_char
*
10
+
bit
;
}
int
convertBinInt
(
long
long
n
)
{
/*
This function returns decimal value from a binary number
*/
int
dec
=
0
,
i
=
7
,
b
=
0
,
rem
=
0
;
while
(
n
!=
0
)
{
b
=
pow
(
10
,
i
);
rem
=
n
/
b
;
n
=
n
%
b
;
dec
+=
rem
*
pow
(
2
,
7
-
i
);
--
i
;
}
return
dec
;
}
int
getDecimal
(
int
n
)
{
/*
returns the last two digits (which represents one character) of the corresponding ascii values passed to this function.
*/
int
num
=
0
;
num
=
n
%
100
;
return
num
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment