From 07d3f5865015755fbb240a2d3ebe752ef3e13ac2 Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Fri, 27 Dec 2024 22:18:44 +0100 Subject: [PATCH] lib: fix idle line bug After the recent change pipelining over three DMA transfers, we obviously need two different idle line buffers, otherwise the the metadata in the idle line currently in flight will be overwritten in case we have two idle lines in a row. When utilizing the full data rate, this cannot be observed, as there won't be two idle lines in a row. --- libpicohsdaoh/picohsdaoh.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libpicohsdaoh/picohsdaoh.c b/libpicohsdaoh/picohsdaoh.c index dbd2851..3865253 100644 --- a/libpicohsdaoh/picohsdaoh.c +++ b/libpicohsdaoh/picohsdaoh.c @@ -68,7 +68,8 @@ #define HSTX_CMD_NOP (0xfu << 12) uint16_t *ring_buf = NULL; -uint16_t idle_line_buf[MODE_H_ACTIVE_PIXELS]; +uint16_t idle_line_buf1[MODE_H_ACTIVE_PIXELS]; +uint16_t idle_line_buf2[MODE_H_ACTIVE_PIXELS]; uint32_t info_p[64]; uint32_t info_len; @@ -232,10 +233,11 @@ void __scratch_x("") hstx_dma_irq_handler() /* Output of actual data in active video lines */ uint16_t *next_line; int next_tail = (fifo_tail + 1) % RBUF_SLICES; + uint16_t cur_active_line = v_scanline - (MODE_V_TOTAL_LINES - MODE_V_ACTIVE_LINES); if (fifo_head == next_tail) { /* No data to send, use idle line */ - next_line = idle_line_buf; + next_line = (cur_active_line % 2) ? idle_line_buf1 : idle_line_buf2; next_line[RBUF_SLICE_LEN - 1] = 0; } else { next_line = &ring_buf[fifo_tail * RBUF_SLICE_LEN]; @@ -243,8 +245,6 @@ void __scratch_x("") hstx_dma_irq_handler() next_line[RBUF_SLICE_LEN - 1] = RBUF_DATA_LEN; } - uint16_t cur_active_line = v_scanline - (MODE_V_TOTAL_LINES - MODE_V_ACTIVE_LINES); - /* fill in metadata word (last word of line) */ if (cur_active_line < (sizeof(metadata_t) * 2)) { uint8_t *met_p = (uint8_t *)&metadata;