Simplify rx_mode loop and prevent it stalling.

On rad1o, the UI update could block this loop from running for long
enough that it could stall in a state where neither of the conditions
was met.

Fix this by removing the 'phase' variable, in favour of a counter
tracking the number of bytes that have been scheduled for USB transfer.
Whenever there are enough bytes to schedule the next transfer, do so.

Meanwhile, the M0 count is prevented from wrapping around and clobbering
data not yet sent, because the M0 code monitors the m4_count variable
which is updated as each transfer completes.
This commit is contained in:
Martin Ling
2022-07-25 10:25:56 +01:00
parent 1ed2d3bb14
commit 0175c2e84e

View File

@ -368,35 +368,22 @@ void transceiver_bulk_transfer_complete(void *user_data, unsigned int bytes_tran
} }
void rx_mode(uint32_t seq) { void rx_mode(uint32_t seq) {
unsigned int phase = 1; uint32_t usb_count = 0;
transceiver_startup(TRANSCEIVER_MODE_RX); transceiver_startup(TRANSCEIVER_MODE_RX);
baseband_streaming_enable(&sgpio_config); baseband_streaming_enable(&sgpio_config);
while (transceiver_request.seq == seq) { while (transceiver_request.seq == seq) {
uint32_t m0_offset = m0_state.m0_count & USB_BULK_BUFFER_MASK; if ((m0_state.m0_count - usb_count) >= 0x4000) {
// Set up IN transfer of buffer 0.
if (16384 <= m0_offset && 1 == phase) {
usb_transfer_schedule_block( usb_transfer_schedule_block(
&usb_endpoint_bulk_in, &usb_endpoint_bulk_in,
&usb_bulk_buffer[0x0000], &usb_bulk_buffer[usb_count & USB_BULK_BUFFER_MASK],
0x4000, 0x4000,
transceiver_bulk_transfer_complete, transceiver_bulk_transfer_complete,
NULL NULL
); );
phase = 0; usb_count += 0x4000;
}
// Set up IN transfer of buffer 1.
if (16384 > m0_offset && 0 == phase) {
usb_transfer_schedule_block(
&usb_endpoint_bulk_in,
&usb_bulk_buffer[0x4000],
0x4000,
transceiver_bulk_transfer_complete,
NULL
);
phase = 1;
} }
} }