1

I am writing an HLS unit with an AXI4 Stream input. Several words in the stream comprise a struct that I would like to access. For example:

struct eth_header {
    ap_uint<48> dest;
    ap_uint<48> source;
    ap_uint<16> proto;
}

I can easily buffer the stream's words and concatenate them to a big ap_uint<112>. However, I would very much like to convert the ap_uint<112> into a nice struct like the eth_header above that I can access with the field syntax. I can't find a nice way to do that. I cannot cast or use a union because the ap_uint class is not a POD.

Is it possible to convert the types somehow (without writing explicit code for each field)?

EDIT: it wasn't clear that the struct needs to be converted from several words from the stream.

haggai_e
  • 4,689
  • 1
  • 24
  • 37

2 Answers2

1

I ended up writing explicit code to do the conversion. For example:

struct eth_header {
    ap_uint<48> dest;
    ap_uint<48> source;
    ap_uint<16> proto;

    static const int width = 112;

    eth_header(const ap_uint<width>& d) :
        dest  (d( 47,  0)),
        source(d( 95, 48)),
        proto (d(111, 96))
    {}

    operator ap_uint<width>()
    {
        return (hls_helpers::swap16(proto), source, dest);
    }
};

This is very ugly, but its the only thing that worked for me.

haggai_e
  • 4,689
  • 1
  • 24
  • 37
0

As it was explained here, for different reasons, the best way is to define by yourself a little struct with the data that you need and the data-type that you prefer. For instance, using float:

struct my_data{
  float data;
  bool last;
};

and, if you are using a AXI4 streaming interface:

#define N 32


void my_function(my_data input[N], my_data output[N])
{
#pragma HLS INTERFACE axis port=output
#pragma HLS INTERFACE axis port=input
#pragma HLS INTERFACE s_axilite port=return


float tmp_data;
float tmp_last;

int k=0;

for(k=0;k<N;k++)
    {
        tmp_data[k] = input[k].data;
        tmp_last[k] = input[k].last;
    }

//...do something here

    for(k=0;k<25;k++)
    {
        output[k].data = tmp_data[k];
        output[k].last = tmp_last[k];
    }
 }
Community
  • 1
  • 1
Leos313
  • 5,152
  • 6
  • 40
  • 69