Skip to content

Commit

Permalink
Increment a sequence number when transceiver mode changes.
Browse files Browse the repository at this point in the history
This is to ensure that a rapid change of e.g. RX->OFF->RX causes the
loop function for that mode to restart.
  • Loading branch information
martinling committed Feb 2, 2022
1 parent d27b1fe commit e68ceca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion firmware/hackrf_usb/usb_api_sweep.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ usb_request_status_t usb_vendor_request_init_sweep(
}

void sweep_mode(void) {
uint32_t seq = transceiver_mode_seq();
unsigned int blocks_queued = 0;
unsigned int phase = 1;
bool odd = true;
Expand All @@ -97,7 +98,7 @@ void sweep_mode(void) {

baseband_streaming_enable(&sgpio_config);

while (TRANSCEIVER_MODE_RX_SWEEP == transceiver_mode()) {
while (transceiver_mode_seq() == seq) {
// Set up IN transfer of buffer 0.
if ( usb_bulk_buffer_offset >= 16384 && phase == 1) {
transfer = true;
Expand Down
13 changes: 11 additions & 2 deletions firmware/hackrf_usb/usb_api_transceiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ usb_request_status_t usb_vendor_request_set_freq_explicit(
}

static volatile transceiver_mode_t _transceiver_mode = TRANSCEIVER_MODE_OFF;
static volatile uint32_t _transceiver_mode_seq = 0;
static volatile hw_sync_mode_t _hw_sync_mode = HW_SYNC_MODE_OFF;

void set_hw_sync_mode(const hw_sync_mode_t new_hw_sync_mode) {
Expand All @@ -247,6 +248,10 @@ transceiver_mode_t transceiver_mode(void) {
return _transceiver_mode;
}

uint32_t transceiver_mode_seq(void) {
return _transceiver_mode_seq;
}

void set_transceiver_mode(const transceiver_mode_t new_transceiver_mode) {
baseband_streaming_disable(&sgpio_config);
operacake_sctimer_reset_state();
Expand Down Expand Up @@ -286,6 +291,8 @@ void set_transceiver_mode(const transceiver_mode_t new_transceiver_mode) {

usb_bulk_buffer_offset = 0;
}

_transceiver_mode_seq++;
}

usb_request_status_t usb_vendor_request_set_transceiver_mode(
Expand Down Expand Up @@ -324,11 +331,12 @@ usb_request_status_t usb_vendor_request_set_hw_sync_mode(
}

void rx_mode(void) {
uint32_t seq = _transceiver_mode_seq;
unsigned int phase = 1;

baseband_streaming_enable(&sgpio_config);

while (TRANSCEIVER_MODE_RX == _transceiver_mode) {
while (_transceiver_mode_seq == seq) {
// Set up IN transfer of buffer 0.
if (16384 <= usb_bulk_buffer_offset && 1 == phase) {
usb_transfer_schedule_block(
Expand All @@ -353,6 +361,7 @@ void rx_mode(void) {
}

void tx_mode(void) {
uint32_t seq = _transceiver_mode_seq;
unsigned int phase = 1;

memset(&usb_bulk_buffer[0x0000], 0, 0x8000);
Expand All @@ -366,7 +375,7 @@ void tx_mode(void) {
// Start transmitting zeros while the host fills buffer 1.
baseband_streaming_enable(&sgpio_config);

while (TRANSCEIVER_MODE_TX == _transceiver_mode) {
while (_transceiver_mode_seq == seq) {
// Set up OUT transfer of buffer 0.
if (16384 <= usb_bulk_buffer_offset && 1 == phase) {
usb_transfer_schedule_block(
Expand Down
1 change: 1 addition & 0 deletions firmware/hackrf_usb/usb_api_transceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ usb_request_status_t usb_vendor_request_set_hw_sync_mode(
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);

transceiver_mode_t transceiver_mode(void);
uint32_t transceiver_mode_seq(void);
void set_transceiver_mode(const transceiver_mode_t new_transceiver_mode);
void start_streaming_on_hw_sync();
void rx_mode(void);
Expand Down

0 comments on commit e68ceca

Please sign in to comment.