Merge pull request #1125 from martinling/simplify-rx-loop
Simplify RX and TX loops
This commit is contained in:
@ -44,6 +44,8 @@
|
||||
#include "usb_endpoint.h"
|
||||
#include "usb_api_sweep.h"
|
||||
|
||||
#define USB_TRANSFER_SIZE 0x4000
|
||||
|
||||
typedef struct {
|
||||
uint32_t freq_mhz;
|
||||
uint32_t freq_hz;
|
||||
@ -368,35 +370,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) >= USB_TRANSFER_SIZE) {
|
||||
usb_transfer_schedule_block(
|
||||
&usb_endpoint_bulk_in,
|
||||
&usb_bulk_buffer[0x0000],
|
||||
0x4000,
|
||||
&usb_bulk_buffer[usb_count & USB_BULK_BUFFER_MASK],
|
||||
USB_TRANSFER_SIZE,
|
||||
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 += USB_TRANSFER_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -404,7 +393,7 @@ void rx_mode(uint32_t seq) {
|
||||
}
|
||||
|
||||
void tx_mode(uint32_t seq) {
|
||||
unsigned int phase = 0;
|
||||
unsigned int usb_count = 0;
|
||||
|
||||
transceiver_startup(TRANSCEIVER_MODE_TX);
|
||||
|
||||
@ -412,10 +401,11 @@ void tx_mode(uint32_t seq) {
|
||||
usb_transfer_schedule_block(
|
||||
&usb_endpoint_bulk_out,
|
||||
&usb_bulk_buffer[0x0000],
|
||||
0x4000,
|
||||
USB_TRANSFER_SIZE,
|
||||
transceiver_bulk_transfer_complete,
|
||||
NULL
|
||||
);
|
||||
usb_count += USB_TRANSFER_SIZE;
|
||||
|
||||
// Enable streaming. The M0 is in TX_START mode, and will automatically
|
||||
// send zeroes until the host fills buffer 0. Once that buffer is filled,
|
||||
@ -424,28 +414,15 @@ void tx_mode(uint32_t seq) {
|
||||
baseband_streaming_enable(&sgpio_config);
|
||||
|
||||
while (transceiver_request.seq == seq) {
|
||||
uint32_t m0_offset = m0_state.m0_count & USB_BULK_BUFFER_MASK;
|
||||
// Set up OUT transfer of buffer 0.
|
||||
if (16384 <= m0_offset && 1 == phase) {
|
||||
if ((usb_count - m0_state.m0_count) <= USB_TRANSFER_SIZE) {
|
||||
usb_transfer_schedule_block(
|
||||
&usb_endpoint_bulk_out,
|
||||
&usb_bulk_buffer[0x0000],
|
||||
0x4000,
|
||||
&usb_bulk_buffer[usb_count & USB_BULK_BUFFER_MASK],
|
||||
USB_TRANSFER_SIZE,
|
||||
transceiver_bulk_transfer_complete,
|
||||
NULL
|
||||
);
|
||||
phase = 0;
|
||||
}
|
||||
// Set up OUT transfer of buffer 1.
|
||||
if (16384 > m0_offset && 0 == phase) {
|
||||
usb_transfer_schedule_block(
|
||||
&usb_endpoint_bulk_out,
|
||||
&usb_bulk_buffer[0x4000],
|
||||
0x4000,
|
||||
transceiver_bulk_transfer_complete,
|
||||
NULL
|
||||
);
|
||||
phase = 1;
|
||||
usb_count += USB_TRANSFER_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user