Skip to content

Commit 3d8ac18

Browse files
committed
Update UI opportunistically in sweep mode
1 parent 1489f0e commit 3d8ac18

6 files changed

Lines changed: 84 additions & 25 deletions

File tree

firmware/common/radio.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ static bool radio_update_frequency(radio_t* const radio, uint64_t* bank)
270270
bool set_lo = (requested_lo != RADIO_UNSET);
271271
bool set_img_reject = (requested_img_reject != RADIO_UNSET);
272272

273+
uint64_t opmode = bank[RADIO_OPMODE];
274+
if (opmode == RADIO_UNSET) {
275+
opmode = radio->config[RADIO_BANK_APPLIED][RADIO_OPMODE];
276+
}
277+
273278
if (set_if && set_lo && set_img_reject) {
274279
bool new_if =
275280
(requested_if !=
@@ -284,7 +289,8 @@ static bool radio_update_frequency(radio_t* const radio, uint64_t* bank)
284289
set_freq_explicit(
285290
requested_if / FP_ONE_HZ,
286291
requested_lo / FP_ONE_HZ,
287-
requested_img_reject);
292+
requested_img_reject,
293+
opmode);
288294
radio->config[RADIO_BANK_APPLIED][RADIO_FREQUENCY_IF] =
289295
requested_if;
290296
radio->config[RADIO_BANK_APPLIED][RADIO_FREQUENCY_LO] =
@@ -323,10 +329,6 @@ static bool radio_update_frequency(radio_t* const radio, uint64_t* bank)
323329
if (applied_afe_rate == RADIO_UNSET) {
324330
return false;
325331
}
326-
uint64_t opmode = bank[RADIO_OPMODE];
327-
if (opmode == RADIO_UNSET) {
328-
opmode = radio->config[RADIO_BANK_APPLIED][RADIO_OPMODE];
329-
}
330332
const tune_config_t* tune_config = select_tune_config(opmode);
331333
const tune_config_t* applied_tune_config =
332334
select_tune_config(radio->config[RADIO_BANK_APPLIED][RADIO_OPMODE]);
@@ -349,12 +351,16 @@ static bool radio_update_frequency(radio_t* const radio, uint64_t* bank)
349351
fp_40_24_t offset = applied_afe_rate / 4;
350352
bool new_offset = (applied_offset != offset);
351353
if (new_rotation || new_offset || new_config || new_rf) {
352-
tuning_set_frequency(tune_config, requested_rf_hz, offset / FP_ONE_HZ);
354+
tuning_set_frequency(
355+
tune_config,
356+
requested_rf_hz,
357+
offset / FP_ONE_HZ,
358+
opmode);
353359
applied_offset = offset;
354360
}
355361
#else
356362
if (new_rf) {
357-
set_freq(requested_rf_hz);
363+
set_freq(requested_rf_hz, opmode);
358364
}
359365
#endif
360366
radio->config[RADIO_BANK_APPLIED][RADIO_FREQUENCY_RF] = requested_rf;

firmware/common/rf_path.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "mixer.h"
3535
#include "platform_detect.h"
3636
#include "sgpio.h"
37+
#include "transceiver_mode.h"
3738
#if defined(HACKRF_ONE) || defined(RAD1O) || defined(PRALINE)
3839
#include "platform_scu.h"
3940
#endif
@@ -537,7 +538,10 @@ void rf_path_set_direction(rf_path_t* const rf_path, const rf_path_direction_t d
537538
hackrf_ui()->set_direction(direction);
538539
}
539540

540-
void rf_path_set_filter(rf_path_t* const rf_path, const rf_path_filter_t filter)
541+
void rf_path_set_filter(
542+
rf_path_t* const rf_path,
543+
const rf_path_filter_t filter,
544+
const transceiver_mode_t opmode)
541545
{
542546
switch (filter) {
543547
default:
@@ -560,7 +564,9 @@ void rf_path_set_filter(rf_path_t* const rf_path, const rf_path_filter_t filter)
560564

561565
switchctrl_set(rf_path, rf_path->switchctrl);
562566

563-
hackrf_ui()->set_filter(filter);
567+
if (opmode != TRANSCEIVER_MODE_RX_SWEEP) {
568+
hackrf_ui()->set_filter(filter);
569+
}
564570
}
565571

566572
void rf_path_set_lna(rf_path_t* const rf_path, const uint_fast8_t enable)

firmware/common/rf_path.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include <stdint.h>
2727

28+
#include "transceiver_mode.h"
2829
#if defined(HACKRF_ONE) || defined(RAD1O) || defined(PRALINE)
2930
#include "gpio.h"
3031
#endif
@@ -91,7 +92,10 @@ void rf_path_init(rf_path_t* const rf_path);
9192

9293
void rf_path_set_direction(rf_path_t* const rf_path, const rf_path_direction_t direction);
9394

94-
void rf_path_set_filter(rf_path_t* const rf_path, const rf_path_filter_t filter);
95+
void rf_path_set_filter(
96+
rf_path_t* const rf_path,
97+
const rf_path_filter_t filter,
98+
const transceiver_mode_t opmode);
9599

96100
void rf_path_set_lna(rf_path_t* const rf_path, const uint_fast8_t enable);
97101
void rf_path_set_antenna(rf_path_t* const rf_path, const uint_fast8_t enable);

firmware/common/tuning.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "max283x.h"
2929
#include "mixer.h"
3030
#include "sgpio.h"
31+
#include "transceiver_mode.h"
3132
#if defined(PRALINE) || defined(HACKRF_ONE)
3233
#include "operacake.h"
3334
#endif
@@ -79,7 +80,7 @@ static uint32_t max2837_freq_nominal_hz = 2560000000;
7980
* hz between 0 to 999999 Hz (not checked)
8081
* return false on error or true if success.
8182
*/
82-
bool set_freq(const uint64_t freq)
83+
bool set_freq(const uint64_t freq, const transceiver_mode_t opmode)
8384
{
8485
bool success;
8586
uint64_t mixer_freq_hz;
@@ -92,7 +93,7 @@ bool set_freq(const uint64_t freq)
9293
max283x_mode_t prior_max283x_mode = max283x_mode(&max283x);
9394
max283x_set_mode(&max283x, MAX283x_MODE_STANDBY);
9495
if (freq_mhz < MAX_LP_FREQ_MHZ) {
95-
rf_path_set_filter(&rf_path, RF_PATH_FILTER_LOW_PASS);
96+
rf_path_set_filter(&rf_path, RF_PATH_FILTER_LOW_PASS, opmode);
9697
#ifdef RAD1O
9798
max2837_freq_nominal_hz = 2300 * FREQ_ONE_MHZ;
9899
#else
@@ -105,7 +106,7 @@ bool set_freq(const uint64_t freq)
105106
max283x_set_frequency(&max283x, real_mixer_freq_hz - freq);
106107
sgpio_cpld_set_mixer_invert(&sgpio_config, 1);
107108
} else if ((freq_mhz >= MIN_BYPASS_FREQ_MHZ) && (freq_mhz < MAX_BYPASS_FREQ_MHZ)) {
108-
rf_path_set_filter(&rf_path, RF_PATH_FILTER_BYPASS);
109+
rf_path_set_filter(&rf_path, RF_PATH_FILTER_BYPASS, opmode);
109110
/* mixer_freq_mhz <= not used in Bypass mode */
110111
max283x_set_frequency(&max283x, freq);
111112
sgpio_cpld_set_mixer_invert(&sgpio_config, 0);
@@ -124,7 +125,7 @@ bool set_freq(const uint64_t freq)
124125
max2837_freq_nominal_hz = (2500 * FREQ_ONE_MHZ) +
125126
((freq - (MID2_HP_FREQ_MHZ * FREQ_ONE_MHZ)) / 9);
126127
}
127-
rf_path_set_filter(&rf_path, RF_PATH_FILTER_HIGH_PASS);
128+
rf_path_set_filter(&rf_path, RF_PATH_FILTER_HIGH_PASS, opmode);
128129
mixer_freq_hz = freq - max2837_freq_nominal_hz;
129130
/* Set Freq and read real freq */
130131
real_mixer_freq_hz = mixer_set_frequency(&mixer, mixer_freq_hz);
@@ -136,7 +137,9 @@ bool set_freq(const uint64_t freq)
136137
}
137138
max283x_set_mode(&max283x, prior_max283x_mode);
138139
if (success) {
139-
hackrf_ui()->set_frequency(freq);
140+
if (opmode != TRANSCEIVER_MODE_RX_SWEEP) {
141+
hackrf_ui()->set_frequency(freq);
142+
}
140143
#ifdef HACKRF_ONE
141144
operacake_set_range(freq_mhz);
142145
#endif
@@ -149,7 +152,8 @@ bool set_freq(const uint64_t freq)
149152
bool tuning_set_frequency(
150153
const tune_config_t* cfg,
151154
const uint64_t freq,
152-
const uint32_t offset)
155+
const uint32_t offset,
156+
const transceiver_mode_t opmode)
153157
{
154158
uint64_t mixer_freq_hz;
155159
uint64_t real_mixer_freq_hz;
@@ -175,11 +179,11 @@ bool tuning_set_frequency(
175179
max283x_set_mode(&max283x, MAX283x_MODE_STANDBY);
176180

177181
if (cfg->if_mhz == 0) {
178-
rf_path_set_filter(&rf_path, RF_PATH_FILTER_BYPASS);
182+
rf_path_set_filter(&rf_path, RF_PATH_FILTER_BYPASS, opmode);
179183
max283x_set_frequency(&max283x, rf);
180184
sgpio_cpld_set_mixer_invert(&sgpio_config, 0);
181185
} else if (cfg->if_mhz > freq_mhz) {
182-
rf_path_set_filter(&rf_path, RF_PATH_FILTER_LOW_PASS);
186+
rf_path_set_filter(&rf_path, RF_PATH_FILTER_LOW_PASS, opmode);
183187
if (cfg->high_lo) {
184188
mixer_freq_hz = FREQ_ONE_MHZ * cfg->if_mhz + rf;
185189
real_mixer_freq_hz = mixer_set_frequency(&mixer, mixer_freq_hz);
@@ -192,15 +196,17 @@ bool tuning_set_frequency(
192196
sgpio_cpld_set_mixer_invert(&sgpio_config, 0);
193197
}
194198
} else {
195-
rf_path_set_filter(&rf_path, RF_PATH_FILTER_HIGH_PASS);
199+
rf_path_set_filter(&rf_path, RF_PATH_FILTER_HIGH_PASS, opmode);
196200
mixer_freq_hz = rf - FREQ_ONE_MHZ * cfg->if_mhz;
197201
real_mixer_freq_hz = mixer_set_frequency(&mixer, mixer_freq_hz);
198202
max283x_set_frequency(&max283x, rf - real_mixer_freq_hz);
199203
sgpio_cpld_set_mixer_invert(&sgpio_config, 0);
200204
}
201205

202206
max283x_set_mode(&max283x, prior_max283x_mode);
203-
hackrf_ui()->set_frequency(freq);
207+
if (opmode != TRANSCEIVER_MODE_RX_SWEEP) {
208+
hackrf_ui()->set_frequency(freq);
209+
}
204210
operacake_set_range(freq_mhz);
205211
return true;
206212
}
@@ -209,7 +215,8 @@ bool tuning_set_frequency(
209215
bool set_freq_explicit(
210216
const uint64_t if_freq_hz,
211217
const uint64_t lo_freq_hz,
212-
const rf_path_filter_t path)
218+
const rf_path_filter_t path,
219+
const transceiver_mode_t opmode)
213220
{
214221
if ((if_freq_hz < ((uint64_t) ABS_MIN_BYPASS_FREQ_MHZ * FREQ_ONE_MHZ)) ||
215222
(if_freq_hz > ((uint64_t) ABS_MAX_BYPASS_FREQ_MHZ * FREQ_ONE_MHZ))) {
@@ -225,7 +232,7 @@ bool set_freq_explicit(
225232
return false;
226233
}
227234

228-
rf_path_set_filter(&rf_path, path);
235+
rf_path_set_filter(&rf_path, path, opmode);
229236
max283x_set_frequency(&max283x, if_freq_hz);
230237

231238
if (lo_freq_hz > if_freq_hz) {

firmware/common/tuning.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,24 @@
2727
#include <stdint.h>
2828

2929
#include "rf_path.h"
30+
#include "transceiver_mode.h"
3031
#if defined(PRALINE)
3132
#include "tune_config.h"
3233
#endif
3334

3435
#define FREQ_ONE_MHZ (1000ULL * 1000)
3536

36-
bool set_freq(const uint64_t freq);
37+
bool set_freq(const uint64_t freq, const transceiver_mode_t opmode);
3738
bool set_freq_explicit(
3839
const uint64_t if_freq_hz,
3940
const uint64_t lo_freq_hz,
40-
const rf_path_filter_t path);
41+
const rf_path_filter_t path,
42+
const transceiver_mode_t opmode);
4143

4244
#ifdef PRALINE
4345
bool tuning_set_frequency(
4446
const tune_config_t* cfg,
4547
const uint64_t freq,
46-
const uint32_t offset);
48+
const uint32_t offset,
49+
const transceiver_mode_t opmode);
4750
#endif

firmware/hackrf_usb/usb_api_sweep.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727

2828
#include <fixed_point.h>
2929
#include <hackrf_core.h>
30+
#include <hackrf_ui.h>
3031
#include <m0_state.h>
3132
#include <radio.h>
33+
#include <rf_path.h>
3234
#include <streaming.h>
3335
#include <transceiver_mode.h>
3436
#include <usb_queue.h>
@@ -58,6 +60,31 @@ static uint32_t dwell_blocks = 0;
5860
static uint32_t step_width = 0;
5961
static uint32_t offset = 0;
6062
static enum sweep_style style = LINEAR;
63+
static bool freq_ui_dirty = false;
64+
static bool img_reject_ui_dirty = false;
65+
static rf_path_filter_t img_reject;
66+
67+
/*
68+
* Opportunistic UI updates are made when time is available. Updates are
69+
* prioritized to prevent a single update from taking too long. Lower priority
70+
* changes to the image reject filter path display are done only if there is
71+
* time remaining after the higher priority update to the frequency display.
72+
*/
73+
void update_ui(void)
74+
{
75+
if (freq_ui_dirty) {
76+
hackrf_ui()->set_frequency(sweep_freq + offset);
77+
freq_ui_dirty = false;
78+
} else if (img_reject_ui_dirty) {
79+
const uint64_t new_img_reject =
80+
radio_reg_read(&radio, RADIO_BANK_APPLIED, RADIO_IMAGE_REJECT);
81+
if (new_img_reject != img_reject) {
82+
img_reject = new_img_reject;
83+
hackrf_ui()->set_filter(img_reject);
84+
}
85+
img_reject_ui_dirty = false;
86+
}
87+
}
6188

6289
/* Do this before starting sweep mode with request_transceiver_mode(). */
6390
usb_request_status_t usb_vendor_request_init_sweep(
@@ -153,6 +180,9 @@ void sweep_mode(uint32_t seq)
153180
uint8_t* buffer;
154181

155182
transceiver_startup(TRANSCEIVER_MODE_RX_SWEEP);
183+
hackrf_ui()->set_frequency(sweep_freq + offset);
184+
img_reject = radio_reg_read(&radio, RADIO_BANK_APPLIED, RADIO_IMAGE_REJECT);
185+
hackrf_ui()->set_filter(img_reject);
156186

157187
// Set M0 to RX first buffer, then wait.
158188
m0_state.threshold = 0x4000;
@@ -235,6 +265,8 @@ void sweep_mode(uint32_t seq)
235265
(sweep_freq + offset) * FP_ONE_HZ);
236266
nvic_enable_irq(NVIC_USB0_IRQ);
237267
radio_update(&radio);
268+
freq_ui_dirty = true;
269+
img_reject_ui_dirty = true;
238270
blocks_queued = 0;
239271
}
240272

@@ -243,6 +275,7 @@ void sweep_mode(uint32_t seq)
243275
if (transceiver_request.seq != seq) {
244276
goto end;
245277
}
278+
update_ui();
246279
}
247280

248281
// Set M0 to switch back to WAIT after filling next buffer.

0 commit comments

Comments
 (0)