Skip to content

Commit

Permalink
firmware/eth_stream: add double buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Binkowski committed Jan 31, 2020
1 parent 16d2848 commit 25c89d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
13 changes: 10 additions & 3 deletions firmware/eth_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ static int eth_stream_in_pos;
static int eth_stream_out_pos;
static int eth_stream_out_state;

int eth_stream_in_fb_index;

static unsigned int eth_stream_out_next_fb;
static unsigned int eth_stream_out_size;

Expand Down Expand Up @@ -42,6 +44,8 @@ void eth_stream_init(void)
(tcp_socket_event_callback_t) eth_stream_out_event_cb);
tcp_socket_listen(&eth_stream_socket_out, ETH_STREAM_PORT_OUT);

eth_stream_in_fb_index = 0;

printf("Ethernet streamer listening on ports %d(in) %d(out)\n", ETH_STREAM_PORT_IN, ETH_STREAM_PORT_OUT);
#endif
}
Expand All @@ -54,6 +58,8 @@ int eth_stream_in_event_cb(struct tcp_socket *s, void *ptr, tcp_socket_event_t e
eth_stream_in_pos = 0;
break;
case TCP_SOCKET_CLOSED:
eth_stream_in_fb_index = (eth_stream_in_fb_index + 1) % 4;
break;
case TCP_SOCKET_TIMEDOUT:
case TCP_SOCKET_ABORTED:
default:
Expand All @@ -64,14 +70,15 @@ int eth_stream_in_event_cb(struct tcp_socket *s, void *ptr, tcp_socket_event_t e

int eth_stream_in_data_cb(struct tcp_socket *s, void *ptr, const char *rxbuf, int rxlen)
{
uint8_t *fb_base = (uint8_t*)fb_ptrdiff_to_main_ram(FRAMEBUFFER_BASE_ETH_IN);
char idx = (eth_stream_in_fb_index + 1) % 4;
uint8_t *fb_base = (uint8_t*)fb_ptrdiff_to_main_ram(eth_stream_in_framebuffer_base(idx));
memcpy(fb_base + eth_stream_in_pos, rxbuf, rxlen);
eth_stream_in_pos += rxlen;
return 0;
}

unsigned int eth_stream_in_framebuffer_base(void) {
return FRAMEBUFFER_BASE_ETH_IN;
unsigned int eth_stream_in_framebuffer_base(char n) {
return FRAMEBUFFER_BASE_ETH_IN + n * FRAMEBUFFER_SIZE;
}

int eth_stream_out_event_cb(struct tcp_socket *s, void *ptr, tcp_socket_event_t event)
Expand Down
4 changes: 3 additions & 1 deletion firmware/eth_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ enum {
ETH_STREAM_OUT_STATE_CLOSE,
};

extern int eth_stream_in_fb_index;

void eth_stream_init(void);

int eth_stream_in_event_cb(struct tcp_socket *s, void *ptr, tcp_socket_event_t event);
Expand All @@ -30,7 +32,7 @@ int eth_stream_in_data_cb(struct tcp_socket *s, void *ptr, const char *rxbuf, in
int eth_stream_out_event_cb(struct tcp_socket *s, void *ptr, tcp_socket_event_t event);
int eth_stream_out_data_cb(struct tcp_socket *s, void *ptr, const char *rxbuf, int rxlen);

unsigned int eth_stream_in_framebuffer_base(void);
unsigned int eth_stream_in_framebuffer_base(char n);

void eth_stream_out_service(void);
void eth_stream_out_base_write(unsigned int value);
Expand Down
2 changes: 1 addition & 1 deletion firmware/processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ void processor_update(void)
hdmi_out0_core_initiator_base_write(pattern_framebuffer_base());

if(processor_hdmi_out0_source == VIDEO_IN_ETH)
hdmi_out0_core_initiator_base_write(eth_stream_in_framebuffer_base());
hdmi_out0_core_initiator_base_write(eth_stream_in_framebuffer_base(eth_stream_in_fb_index));
#endif

#ifdef CSR_HDMI_OUT1_BASE
Expand Down

0 comments on commit 25c89d4

Please sign in to comment.