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