46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
// Copyright (2019-2023) Paul Scherrer Institute
|
|
|
|
#include "hls_jfjoch.h"
|
|
|
|
void stream_merge(AXI_STREAM &input_0,
|
|
AXI_STREAM &input_1,
|
|
AXI_STREAM &output) {
|
|
#pragma HLS INTERFACE ap_ctrl_none port=return
|
|
#pragma HLS INTERFACE axis register both port=input_0
|
|
#pragma HLS INTERFACE axis register both port=input_1
|
|
#pragma HLS INTERFACE axis register both port=output
|
|
|
|
#pragma HLS PIPELINE II=1 style=flp
|
|
enum state {ARBITRATE, FORWARD};
|
|
static state state = ARBITRATE;
|
|
static ap_uint<1> select_input = 0;
|
|
|
|
packet_512_t packet_in;
|
|
#pragma HLS RESET variable=state
|
|
switch (state) {
|
|
case ARBITRATE:
|
|
if (input_0.read_nb(packet_in)) {
|
|
select_input = 0;
|
|
if (!packet_in.last)
|
|
state = FORWARD;
|
|
output.write(packet_in);
|
|
} else if (input_1.read_nb(packet_in)) {
|
|
select_input = 1;
|
|
if (!packet_in.last)
|
|
state = FORWARD;
|
|
output.write(packet_in);
|
|
}
|
|
break;
|
|
case FORWARD:
|
|
if (select_input == 0) {
|
|
input_0.read(packet_in);
|
|
} else
|
|
input_1.read(packet_in);
|
|
output.write(packet_in);
|
|
|
|
if (packet_in.last)
|
|
state = ARBITRATE;
|
|
break;
|
|
}
|
|
}
|