icE1usb fw: Have e1_rx_need_data() optionally return FIFO position

The position indicates where we are in terms of frame and multiframe.

The related code was ported over from e1-tracer.

Related: OS#4674
Change-Id: I9e59d86a2e8f4e85ca84c592438ad79966b49448
diff --git a/firmware/ice40-riscv/icE1usb/e1.c b/firmware/ice40-riscv/icE1usb/e1.c
index 5d4d3ee..0f1d89d 100644
--- a/firmware/ice40-riscv/icE1usb/e1.c
+++ b/firmware/ice40-riscv/icE1usb/e1.c
@@ -328,7 +328,7 @@
 #include "dma.h"
 
 unsigned int
-e1_rx_need_data(unsigned int usb_addr, unsigned int max_frames)
+e1_rx_need_data(unsigned int usb_addr, unsigned int max_frames, unsigned int *pos)
 {
 	unsigned int ofs;
 	int tot_frames = 0;
@@ -340,6 +340,12 @@
 		if (!n_frames)
 			break;
 
+		/* Give pos */
+		if (pos) {
+			*pos = ofs & g_e1.rx.fifo.mask;
+			pos = NULL;
+		}
+
 		/* Copy from FIFO to USB */
 		dma_exec(e1f_ofs_to_dma(ofs), usb_addr, n_frames * (32 / 4), false, NULL, NULL);
 
diff --git a/firmware/ice40-riscv/icE1usb/usb_e1.c b/firmware/ice40-riscv/icE1usb/usb_e1.c
index f724665..6bcb1b4 100644
--- a/firmware/ice40-riscv/icE1usb/usb_e1.c
+++ b/firmware/ice40-riscv/icE1usb/usb_e1.c
@@ -23,7 +23,7 @@
 
 
 /* Hack */
-unsigned int e1_rx_need_data(unsigned int usb_addr, unsigned int max_len);
+unsigned int e1_rx_need_data(unsigned int usb_addr, unsigned int max_len, unsigned int *pos);
 unsigned int e1_tx_feed_data(unsigned int usb_addr, unsigned int len);
 unsigned int e1_tx_level(void);
 unsigned int e1_rx_level(void);
@@ -93,7 +93,7 @@
 		else if (!n)
 			break;
 
-		n = e1_rx_need_data((ptr >> 2) + 1, n);
+		n = e1_rx_need_data((ptr >> 2) + 1, n, NULL);
 
 		/* Write header */
 		hdr = 0x616b00b5;