@@ -499,25 +499,38 @@ void rx_mode(uint32_t seq)
499499
500500void tx_mode (uint32_t seq )
501501{
502- bool started = false;
503-
504502 transceiver_startup (TRANSCEIVER_MODE_TX );
505503
506- // Set up OUT transfer of buffer 0.
507- usb_transfer_schedule_block (
508- & usb_endpoint_bulk_out ,
509- & usb_bulk_buffer [0x0000 ],
510- USB_TRANSFER_SIZE ,
511- transceiver_bulk_transfer_complete ,
512- NULL );
513- usb_started += USB_TRANSFER_SIZE ;
504+ // First, make transfers directly into the sample buffer to fill it.
505+ for (int i = 0 ; i < (USB_SAMP_BUFFER_SIZE / USB_TRANSFER_SIZE ); i ++ ) {
506+ // Set up transfer.
507+ usb_transfer_schedule_block (
508+ & usb_endpoint_bulk_out ,
509+ & usb_samp_buffer [usb_started ],
510+ USB_TRANSFER_SIZE ,
511+ transceiver_bulk_transfer_complete ,
512+ NULL );
513+ usb_started += USB_TRANSFER_SIZE ;
514+
515+ // Wait for the transfer to complete.
516+ while (usb_completed < usb_started ) {
517+ // Handle the host switching modes before filling the buffer.
518+ if (transceiver_request .seq != seq ) {
519+ transceiver_shutdown ();
520+ return ;
521+ }
522+ }
523+ }
514524
525+ // Sample buffer is now full. Update DMA counters accordingly.
526+ dma_started = USB_SAMP_BUFFER_SIZE ;
527+ m0_state .m4_count = USB_SAMP_BUFFER_SIZE ;
528+
529+ // Start transmitting samples.
530+ baseband_streaming_enable (& sgpio_config );
531+
532+ // Continue feeding samples to the sample buffer.
515533 while (transceiver_request .seq == seq ) {
516- if (!started && (m0_state .m4_count == USB_SAMP_BUFFER_SIZE )) {
517- // Buffer is now full, start streaming.
518- baseband_streaming_enable (& sgpio_config );
519- started = true;
520- }
521534 uint32_t data_used = m0_state .m0_count ;
522535 uint32_t dma_completed = m0_state .m4_count ;
523536 uint32_t data_available = usb_completed - dma_started ;
0 commit comments