UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Observer kuangjiqingma
Observer
1,098 Views
Registered: ‎04-06-2016

How to write function's return in IP readable register

Jump to solution

I want to get a position from a function.The input is image ,and also the output is image.The return of the function is a point,I want to use the point in software,so I want to read it by IP's readable registers.But I don't konw how to solve it.Thank you a lot. 

 

#include<stdio.h>
#include"top.h"
#include"math.h"

P move(GRAY1_IMAGE& src,GRAY1_IMAGE& dst,int rows,int cols)
{

    gray_data pix;
    P position;
for(int row=0;row<rows;row++)
for(int col=0;col<cols;col++)
{
    src >> pix;
    dst << pix;
    if(pix.val[0]>=0)
    { 
        xposition=30;
        yposition=30;
    }
    else
   {
      xposition=30;
      yposition=30;
   }
}
    position.x=xposition;
    position.y=yposition;
    return position;

}

P sobel( AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM,int rows, int cols )
{
#pragma HLS INTERFACE axis port=INPUT_STREAM
#pragma HLS INTERFACE axis port=OUTPUT_STREAM

#pragma HLS RESOURCE core=AXI_SLAVE variable=rows metadata="-bus_bundle CONTROL_BUS"
#pragma HLS RESOURCE core=AXI_SLAVE variable=cols metadata="-bus_bundle CONTROL_BUS"
#pragma HLS RESOURCE core=AXI_SLAVE variable=return metadata="-bus_bundle CONTROL_BUS"

#pragma HLS INTERFACE ap_stable port=rows
#pragma HLS INTERFACE ap_stable port=cols

#pragma HLS INTERFACE ap_stable port=xposition
#pragma HLS INTERFACE ap_stable port=yposition

RGB_IMAGE img_2(rows, cols);
GRAY_IMAGE img_3(rows, cols);
GRAY_IMAGE img_4(rows, cols);
GRAY_IMAGE img_5(rows, cols);

GRAY1_IMAGE img_9(MIN_WIDTH, MIN_HEIGHT);
GRAY1_IMAGE img_10(MIN_WIDTH, MIN_HEIGHT);
GRAY1_IMAGE img_11(MIN_WIDTH, MIN_HEIGHT);

P position;

#pragma HLS STREAM variable=img_3.data_stream depth=262200
#pragma HLS DATAFLOW
    hls::AXIvideo2Mat(INPUT_STREAM, img_2);
    hls::CvtColor<HLS_RGB2GRAY>(img_2,img_3);
    hls::Duplicate(img_3,img_4,img_5);
    hls::Resize(img_4,img_9);
    position=move(img_9,img_10,64,64);
    hls::Mat2AXIvideo(img_5, OUTPUT_STREAM);
    return position;
}

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Participant valato
Participant
1,555 Views
Registered: ‎09-29-2017

Re: How to write function's return in IP readable register

Jump to solution

Try something like this:

 

void sobel( AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM,int rows, int cols, int * pointx, int * pointy )
{
#pragma HLS INTERFACE axis port=INPUT_STREAM
#pragma HLS INTERFACE axis port=OUTPUT_STREAM

#pragma HLS RESOURCE core=AXI_SLAVE variable=rows metadata="-bus_bundle CONTROL_BUS"
#pragma HLS RESOURCE core=AXI_SLAVE variable=cols metadata="-bus_bundle CONTROL_BUS"

#pragma HLS RESOURCE core=AXI_SLAVE variable=pointx metadata="-bus_bundle CONTROL_BUS"

#pragma HLS RESOURCE core=AXI_SLAVE variable=pointy metadata="-bus_bundle CONTROL_BUS"
#pragma HLS RESOURCE core=AXI_SLAVE variable=return metadata="-bus_bundle CONTROL_BUS"

#pragma HLS INTERFACE ap_stable port=rows
#pragma HLS INTERFACE ap_stable port=cols

#pragma HLS INTERFACE ap_stable port=xposition
#pragma HLS INTERFACE ap_stable port=yposition

RGB_IMAGE img_2(rows, cols);
GRAY_IMAGE img_3(rows, cols);
GRAY_IMAGE img_4(rows, cols);
GRAY_IMAGE img_5(rows, cols);

GRAY1_IMAGE img_9(MIN_WIDTH, MIN_HEIGHT);
GRAY1_IMAGE img_10(MIN_WIDTH, MIN_HEIGHT);
GRAY1_IMAGE img_11(MIN_WIDTH, MIN_HEIGHT);

P position;

#pragma HLS STREAM variable=img_3.data_stream depth=262200
#pragma HLS DATAFLOW
    hls::AXIvideo2Mat(INPUT_STREAM, img_2);
    hls::CvtColor<HLS_RGB2GRAY>(img_2,img_3);
    hls::Duplicate(img_3,img_4,img_5);
    hls::Resize(img_4,img_9);
    position=move(img_9,img_10,64,64);
    hls::Mat2AXIvideo(img_5, OUTPUT_STREAM);
    *pointx = position.x;

    *pointy = position.y;
}

----- Please mark the post as an answer "Accept as solution" in case it helped to solve your problem. Give kudos in case the post guided you to the solution.
3 Replies
Highlighted
Participant valato
Participant
1,556 Views
Registered: ‎09-29-2017

Re: How to write function's return in IP readable register

Jump to solution

Try something like this:

 

void sobel( AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM,int rows, int cols, int * pointx, int * pointy )
{
#pragma HLS INTERFACE axis port=INPUT_STREAM
#pragma HLS INTERFACE axis port=OUTPUT_STREAM

#pragma HLS RESOURCE core=AXI_SLAVE variable=rows metadata="-bus_bundle CONTROL_BUS"
#pragma HLS RESOURCE core=AXI_SLAVE variable=cols metadata="-bus_bundle CONTROL_BUS"

#pragma HLS RESOURCE core=AXI_SLAVE variable=pointx metadata="-bus_bundle CONTROL_BUS"

#pragma HLS RESOURCE core=AXI_SLAVE variable=pointy metadata="-bus_bundle CONTROL_BUS"
#pragma HLS RESOURCE core=AXI_SLAVE variable=return metadata="-bus_bundle CONTROL_BUS"

#pragma HLS INTERFACE ap_stable port=rows
#pragma HLS INTERFACE ap_stable port=cols

#pragma HLS INTERFACE ap_stable port=xposition
#pragma HLS INTERFACE ap_stable port=yposition

RGB_IMAGE img_2(rows, cols);
GRAY_IMAGE img_3(rows, cols);
GRAY_IMAGE img_4(rows, cols);
GRAY_IMAGE img_5(rows, cols);

GRAY1_IMAGE img_9(MIN_WIDTH, MIN_HEIGHT);
GRAY1_IMAGE img_10(MIN_WIDTH, MIN_HEIGHT);
GRAY1_IMAGE img_11(MIN_WIDTH, MIN_HEIGHT);

P position;

#pragma HLS STREAM variable=img_3.data_stream depth=262200
#pragma HLS DATAFLOW
    hls::AXIvideo2Mat(INPUT_STREAM, img_2);
    hls::CvtColor<HLS_RGB2GRAY>(img_2,img_3);
    hls::Duplicate(img_3,img_4,img_5);
    hls::Resize(img_4,img_9);
    position=move(img_9,img_10,64,64);
    hls::Mat2AXIvideo(img_5, OUTPUT_STREAM);
    *pointx = position.x;

    *pointy = position.y;
}

----- Please mark the post as an answer "Accept as solution" in case it helped to solve your problem. Give kudos in case the post guided you to the solution.
Explorer
Explorer
1,063 Views
Registered: ‎08-31-2017

Re: How to write function's return in IP readable register

Jump to solution

Hi, Valato,

 

 One thing to confirm with you. According to my understanding from your suggestion, it means the sobel module provides an output interface which is ap_stable to be accessed by external. Does it imply the two signals will be allocated as register wrapped by AXI_SLAVE interface ?

 

 However, I checked the UG902 and it mentions "Note: The ap_stable type can only be applied to input ports. When applied to inout ports, only the input of the port is considered stable.". Thus, I am confused here and raise the question to learn from your thought.  Thanks a lot.

 

 

 int * pointx, int * pointy

 

#pragma HLS RESOURCE core=AXI_SLAVE variable=pointx metadata="-bus_bundle CONTROL_BUS"

#pragma HLS RESOURCE core=AXI_SLAVE variable=pointy metadata="-bus_bundle CONTROL_BUS"

#pragma HLS INTERFACE ap_stable port=xposition
#pragma HLS INTERFACE ap_stable port=yposition

 

Thanks

0 Kudos
Participant valato
Participant
1,046 Views
Registered: ‎09-29-2017

Re: How to write function's return in IP readable register

Jump to solution
ap_stable means you have to set this register before starting IP and it cannot change. Your output is in different registers pointx and pointy accessible through axi_slave interface. And these cannot be marked as ap_stable.
----- Please mark the post as an answer "Accept as solution" in case it helped to solve your problem. Give kudos in case the post guided you to the solution.
0 Kudos