一、测试激励编写

#include "top.h"

#include "hls_opencv.h"

#include "iostream"

using namespace std;

using namespace cv;

int main (int argc, char** argv)
{

int len = 100;
ap_axiu<32,1,1,1> tmp;
ap_uint<32> tmp1;


hls::stream<ap_axiu<32,1,1,1> > dst_axi;
hls::stream<ap_uint<32> > src_axi;

for(int i=0;i<10;i++){//row
    //tmp.last = 0;
    for(int j=0;j<10;j++){//col
        //tmp.data(11,0)     = j;
        //tmp.data(23,12) = j;
        //tmp.data(35,24) = j;
        //tmp.data(47,36) = j;

        tmp1(7,0)     = j;
        tmp1(15,8) = j;
        tmp1(23,16) = j;
        tmp1(31,24) = j;

//        if(i==0 && j==0){
//            tmp.user = 1;
//        }
//        else{
//            tmp.user = 0;
//        }
//
//        if(j==9){
//            tmp.last = 1;
//        }
//        else{
//            tmp.last = 0;
//        }
        src_axi << tmp1;//write
    }
}

hls_video_scaler_top(dst_axi,src_axi,10,10);

//for(int i=0;i<100;i++){
//    //if(!dst_axi.empty())
//       dst_axi >> tmp1;
//    std::cout<<std::hex <<tmp1<<std::endl;
//}

//waitKey(0);

return 0;

}

二、顶层核心代码设计

#include "top.h"

void hls_video_scaler_top
(
    hls::stream<ap_axiu<32,1,1,1> >& dst_strm,//8*4
    hls::stream<ap_uint<32> >& src_strm,//8*4
    ap_uint<16> width,
    ap_uint<16> high
)
{
#pragma HLS INTERFACE ap_ctrl_none port=return
#pragma HLS INTERFACE ap_stable port=high
#pragma HLS INTERFACE ap_stable port=width
#pragma HLS INTERFACE axis register both port=dst_strm
#pragma HLS INTERFACE axis register both port=src_strm

    ap_uint<32> data_tmp;
    ap_axiu<32,1,1,1> strm_tmp;

    bool sof = 1;

    for(ap_uint<16> i=0;i<high;i++){
        for(ap_uint<16> j=0;j<width;j++){
#pragma HLS LOOP_FLATTEN off
#pragma HLS pipeline II=1
            if(sof==1){
                strm_tmp.user = 1;//first pixel
                sof = 0;
            }
            else{
                strm_tmp.user = 0;
            }

            if((width-1)==j){
                strm_tmp.last = 1;
            }
            else{
                strm_tmp.last = 0;
            }
            src_strm >> data_tmp;//read
            strm_tmp.data = data_tmp;
            strm_tmp.keep = -1;
            dst_strm << strm_tmp;//write
        }
    }


}
 

三、综合和联合仿真

四、像素位宽转换后修改代码如下

#include "top.h"

void hls_video_scaler_top
(
    hls::stream<ap_axiu<32,1,1,1> >& dst_strm,//8*4
    hls::stream<ap_uint<32> >& src_strm,//8*4
    ap_uint<16> width,
    ap_uint<16> high
)
{
#pragma HLS INTERFACE ap_ctrl_none port=return
#pragma HLS INTERFACE ap_stable port=high
#pragma HLS INTERFACE ap_stable port=width
#pragma HLS INTERFACE axis register both port=dst_strm
#pragma HLS INTERFACE axis register both port=src_strm

    ap_uint<32> data_tmp;
    ap_axiu<32,1,1,1> strm_tmp;

    bool sof = 1;

    for(ap_uint<16> i=0;i<high;i++){
        for(ap_uint<16> j=0;j<width;j++){
#pragma HLS LOOP_FLATTEN off
#pragma HLS pipeline II=1
            if(sof==1){
                strm_tmp.user = 1;//first pixel
                sof = 0;
            }
            else{
                strm_tmp.user = 0;
            }

            if((width-1)==j){
                strm_tmp.last = 1;
            }
            else{
                strm_tmp.last = 0;
            }
            src_strm >> data_tmp;//read

            //当进行pixel像素转换的时候可以新增下面的代码设计
            for(ap_uint<3> k = 0;k<4;k++){
#pragma HLS UNROLL
                strm_tmp.data(8*(k+1)-1,8*k) = data_tmp(8*(k+1)-1,8*k);//pixel
            }

            strm_tmp.keep = -1;
            dst_strm << strm_tmp;//write
        }
    }


}

更多推荐