daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Oct 19th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <hls_stream.h>
  2. #include <ap_axi_sdata.h>
  3. #include <hls_math.h>
  4. #include <math.h>
  5.  
  6.  //--- struct for image flowing through AXI4-Stream
  7. template<int D>
  8. struct im_axis{
  9.     ap_uint<D>       data;
  10.     ap_uint<1>       user;
  11.     ap_uint<1>       last;
  12. };
  13. typedef im_axis<16> yuyv_image;
  14. typedef im_axis<8> yonly_image;
  15.  
  16. #define WIDTH 1920
  17. #define HEIGHT 1080
  18.  
  19. void yuyvy(hls::stream<yuyv_image>& axis_in, hls::stream<yonly_image> & axis_out, unsigned char& val){
  20.     #pragma HLS INTERFACE axis port=axis_in
  21.     #pragma HLS INTERFACE axis port=axis_out
  22.     #pragma HLS INTERFACE s_axilite port=val bundle=CONTROL_BUS// clock=s_axi_aclk
  23.     #pragma HLS INTERFACE ap_ctrl_none port=return
  24.     im_axis<16> axis_reader; // for read AXI4-Stream
  25.     im_axis<8> axis_writer; // for write AXI4-Stream
  26.     bool sof = false;              // Start of Frame
  27.     bool eol = false;              // End of Line
  28.  
  29.     // wait for the user signal to be asserted
  30.     while (!sof) {
  31.         #pragma HLS PIPELINE II=1
  32.         #pragma HLS LOOP_TRIPCOUNT avg=0 max=0
  33.  
  34.         axis_in >> axis_reader;
  35.         sof = axis_reader.user.to_int();
  36.     }
  37.  
  38.     // image proc loop
  39.     for(int yi = 0; yi < HEIGHT; yi++) {
  40.         eol = false;
  41.         for(int xi = 0; xi < WIDTH; xi++) {
  42.             #pragma HLS PIPELINE II=1
  43.             #pragma HLS LOOP_FLATTEN off
  44.  
  45.             // get pix until the last signal to be asserted
  46.             if(sof || eol) {
  47.                 // when frame is started (first pix have already latched)
  48.                 // or
  49.                 // when WIDTH param set more than actual frame size
  50.                 sof = false;
  51.                 eol = axis_reader.last.to_int();
  52.             }
  53.             else {
  54.                 axis_in >> axis_reader;
  55.                 eol = axis_reader.last.to_int();
  56.             }
  57.  
  58.             axis_writer.data = std::max((int)((axis_reader.data & 0xFF00) >> 8), (int)val);
  59.             // assert user signal at start of frame
  60.             if (xi == 0 && yi == 0) {
  61.                 axis_writer.user = 1;
  62.             }else {
  63.                 axis_writer.user = 0;
  64.             }
  65.  
  66.             // assert last signal at end of line
  67.             if (xi == (WIDTH - 1)) {
  68.                 axis_writer.last = 1;
  69.             }else {
  70.                 axis_writer.last = 0;
  71.             }
  72.  
  73.             axis_out << axis_writer;
  74.         }
  75.  
  76.         // when WIDTH param set less than actual frame size
  77.         // wait for the last signal to be asserted
  78.         while (!eol) {
  79.             #pragma HLS pipeline II=1
  80.             #pragma HLS loop_tripcount avg=0 max=0
  81.             axis_in >> axis_reader;
  82.             eol = axis_reader.last.to_int();
  83.         }
  84.     }
  85.  
  86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top