The FIR function is defined in the HLS namespace and can be called as follows:
// Create an instance of the FIR
static hls::FIR<STATIC_PARAM> fir1;
// Execute the FIR instance fir1
fir1.run(INPUT_DATA_ARRAY, OUTPUT_DATA_ARRAY);
The STATIC_PARAM
is the static parameterization
struct that defines most static parameters for the FIR.
Both the input and output data are supplied to the function as arrays (INPUT_DATA_ARRAY
and OUTPUT_DATA_ARRAY
). In the final implementation, these ports on the
FIR IP will be implemented as AXI4-Stream ports.
Xilinx recommends always using the FIR
function in a region using the dataflow optimization (set_directive_dataflow
), because this ensures the arrays are
implemented as streaming arrays. An alternative is to specify both arrays as
streaming using the set_directive_stream
command.
The multichannel functionality of the FIR is supported through interleaving the data in a single input and single output array.
- The size of the input array should be large enough to accommodate all samples:
num_channels * input_length
. - The output array size should be specified to contain all output samples:
num_channels * output_length
.
The following code example demonstrates, for two channels, how the data is
interleaved. In this example, the top-level function has two channels of input data
(din_i
, din_q
)
and two channels of output data (dout_i
, dout_q
). Two functions, at the front-end (fe) and
back-end (be) are used to correctly order the data in the FIR input array and
extract it from the FIR output array.
void dummy_fe(din_t din_i[LENGTH], din_t din_q[LENGTH], din_t out[FIR_LENGTH]) {
for (unsigned i = 0; i < LENGTH; ++i) {
out[2*i] = din_i[i];
out[2*i + 1] = din_q[i];
}
}
void dummy_be(dout_t in[FIR_LENGTH], dout_t dout_i[LENGTH], dout_t dout_q[LENGTH]) {
for(unsigned i = 0; i < LENGTH; ++i) {
dout_i[i] = in[2*i];
dout_q[i] = in[2*i+1];
}
}
void fir_top(din_t din_i[LENGTH], din_t din_q[LENGTH],
dout_t dout_i[LENGTH], dout_t dout_q[LENGTH]) {
din_t fir_in[FIR_LENGTH];
dout_t fir_out[FIR_LENGTH];
static hls::FIR<myconfig> fir1;
dummy_fe(din_i, din_q, fir_in);
fir1.run(fir_in, fir_out);
dummy_be(fir_out, dout_i, dout_q);
}