Compare commits

...
Sign in to create a new pull request.

4 commits

Author SHA1 Message Date
Ryan Thompson
86ef50e210 nios: added support for more fastlock profiles
Only supported by the xA9 FPGA given the addition M10K blocks required.
2024-12-06 08:20:21 -06:00
Ryan Thompson
42cda64a98 nios: added quick tune debug print for late timestamps
In the case the fastlock AD9361 SPI writes are too slow, we make sure
the requested timestamp is in the future before assigning the next
fastlock profile.
2024-12-06 08:20:21 -06:00
Ryan Thompson
2a109c9af2 nios: fixed num profile mask to support uint16_t
This relieves the silent 256 profile limit.
2024-12-06 08:20:21 -06:00
Ryan Thompson
979c175891 test: added scheduled ahead test
This test schedules N retunes ahead. This will test the max number
of profiles that the nios core can hold.
2024-12-06 08:20:21 -06:00
9 changed files with 231 additions and 18 deletions

View file

@ -97,7 +97,7 @@ static bladerf_frequency const RESET_FREQUENCY = 70000000;
/* Number of fast lock profiles that can be stored in the Nios
* Make sure this number matches that of the Nios' devices.h */
#define NUM_BBP_FASTLOCK_PROFILES 256
#define NUM_BBP_FASTLOCK_PROFILES 2048
/* Number of fast lock profiles that can be stored in the RFFE
* Make sure this number matches that of the Nios' devices.h */

View file

@ -496,7 +496,7 @@ set_connection_parameter_value nios2.data_master/peripheral_spi.spi_control_port
add_connection nios2.data_master ram.s1
set_connection_parameter_value nios2.data_master/ram.s1 arbitrationPriority {1}
set_connection_parameter_value nios2.data_master/ram.s1 baseAddress {0x00020000}
set_connection_parameter_value nios2.data_master/ram.s1 baseAddress {0x00040000}
set_connection_parameter_value nios2.data_master/ram.s1 defaultConnection {0}
add_connection nios2.data_master rffe_spi.spi_control_port
@ -556,7 +556,7 @@ set_connection_parameter_value nios2.instruction_master/nios2.debug_mem_slave de
add_connection nios2.instruction_master ram.s1
set_connection_parameter_value nios2.instruction_master/ram.s1 arbitrationPriority {1}
set_connection_parameter_value nios2.instruction_master/ram.s1 baseAddress {0x00020000}
set_connection_parameter_value nios2.instruction_master/ram.s1 baseAddress {0x00040000}
set_connection_parameter_value nios2.instruction_master/ram.s1 defaultConnection {0}
add_connection nios2.irq command_uart.interrupt

View file

@ -38,7 +38,7 @@ function get_device_family() {
# RAM during Qsys generation
function get_qsys_ram() {
if [ "${1}" == "A4" ] || [ "${1}" == "A5" ] || [ "${1}" == "A9" ]; then
rams=131072
rams=262144
else
rams=32768
fi

View file

@ -102,7 +102,7 @@
/* Number of RFFE fast lock profiles to store in the Nios.
* Make sure this matches what is defined in bladerf2.c.
*/
#define NUM_BBP_FASTLOCK_PROFILES 256
#define NUM_BBP_FASTLOCK_PROFILES 2048
/* Number of fast lock profiles that can be stored in the RFFE */
#define NUM_RFFE_FASTLOCK_PROFILES 8

View file

@ -98,7 +98,7 @@ static inline bool perform_write(uint8_t id, uint8_t addr, uint32_t data)
#ifdef BOARD_BLADERF_MICRO
case NIOS_PKT_8x32_TARGET_FASTLOCK:
adi_fastlock_save( (addr == 1), (data >> 16), (data & 0xff));
adi_fastlock_save( (addr == 1), (data >> 16), (data & 0xffff));
break;
#endif // BOARD_BLADERF_MICRO

View file

@ -28,6 +28,7 @@
#include "nios_pkt_retune2.h" /* Packet format definition */
#include "devices.h"
#include "debug.h"
#include "sys/alt_stdio.h"
#ifdef BLADERF_NIOS_LIBAD936X
void rfic_invalidate_frequency(bladerf_module module);
@ -41,9 +42,9 @@ void rfic_invalidate_frequency(bladerf_module module);
#endif
/* The enqueue/dequeue routines require that this be a power of two */
#define RETUNE2_QUEUE_MAX 16
#define QUEUE_FULL 0xff
#define QUEUE_EMPTY 0xfe
#define RETUNE2_QUEUE_MAX 2048
#define QUEUE_FULL UINT16_MAX
#define QUEUE_EMPTY (UINT16_MAX - 1)
/* State of items in the retune queue */
enum entry_state {
@ -63,20 +64,20 @@ struct queue_entry {
};
static struct queue {
uint8_t count; /* Total number of items in the queue */
uint8_t ins_idx; /* Insertion index */
uint8_t rem_idx; /* Removal index */
uint16_t count; /* Total number of items in the queue */
uint16_t ins_idx; /* Insertion index */
uint16_t rem_idx; /* Removal index */
struct queue_entry entries[RETUNE2_QUEUE_MAX];
} rx_queue, tx_queue;
/* Returns queue size after enqueue operation, or QUEUE_FULL if we could
* not enqueue the requested item */
static inline uint8_t enqueue_retune(struct queue *q,
static inline uint16_t enqueue_retune(struct queue *q,
fastlock_profile *p,
uint64_t timestamp)
{
uint8_t ret;
uint16_t ret;
if (q->count >= RETUNE2_QUEUE_MAX) {
return QUEUE_FULL;
@ -96,9 +97,9 @@ static inline uint8_t enqueue_retune(struct queue *q,
/* Retune number of items left in the queue after the dequeue operation,
* or QUEUE_EMPTY if there was nothing to dequeue */
static inline uint8_t dequeue_retune(struct queue *q, struct queue_entry *e)
static inline uint16_t dequeue_retune(struct queue *q, struct queue_entry *e)
{
uint8_t ret;
uint16_t ret;
if (q->count == 0) {
return QUEUE_EMPTY;
@ -131,7 +132,7 @@ static inline struct queue_entry* peek_next_retune(struct queue *q)
/* Get the queue element at the given offset relative to the removal index */
static inline struct queue_entry* peek_next_retune_offset(struct queue *q,
uint8_t offset)
uint16_t offset)
{
if (q == NULL) {
return NULL;
@ -294,6 +295,14 @@ static inline void perform_work(struct queue *q, bladerf_module module)
/* Load the fast lock profile into the RFFE */
profile_load(module, e->profile);
#ifdef BLADERF_NIOS_DEBUG
if (time_tamer_read(module) > e->timestamp) {
DBG("Timestamp %x is in the past. SPI write likely too slow.\n", e->timestamp);
DBG("Try increasing timestamp spacing between retunes.\n");
INCREMENT_ERROR_COUNT();
}
#endif
/* Schedule the retune */
e->state = ENTRY_STATE_SCHEDULED;
tamer_schedule(module, e->timestamp);
@ -410,7 +419,7 @@ void pkt_retune2(struct pkt_buf *b)
status = -1;
}
} else {
uint8_t queue_size;
uint16_t queue_size;
switch (module) {
case BLADERF_MODULE_RX:

View file

@ -18,6 +18,7 @@ add_subdirectory(test_repeater)
add_subdirectory(test_quick_retune)
add_subdirectory(test_repeated_stream)
add_subdirectory(test_rx_discont)
add_subdirectory(test_scheduled_ahead)
add_subdirectory(test_scheduled_retune)
add_subdirectory(test_sync)
add_subdirectory(test_timestamps)

View file

@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.5)
project(libbladeRF_test_scheduled_ahead C)
set(INCLUDES
${libbladeRF_SOURCE_DIR}/include
${BLADERF_HOST_COMMON_INCLUDE_DIRS}
)
if(MSVC)
set(INCLUDES ${INCLUDES} ${MSVC_C99_INCLUDES})
endif()
set(LIBS libbladerf_shared)
set(SRC
src/main.c
${BLADERF_HOST_COMMON_SOURCE_DIR}/conversions.c
)
if(MSVC)
set(SRC ${SRC}
${BLADERF_HOST_COMMON_SOURCE_DIR}/windows/getopt_long.c
)
endif()
include_directories(${INCLUDES})
add_executable(libbladeRF_test_scheduled_ahead ${SRC})
target_link_libraries(libbladeRF_test_scheduled_ahead ${LIBS} m)

View file

@ -0,0 +1,175 @@
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include <libbladeRF.h>
#include <math.h>
#define CHECK_STATUS(fn) do { \
status = fn; \
if (status != 0) { \
fprintf(stderr, "%s:%d: %s failed: %s\n", __FILE__, __LINE__, #fn, \
bladerf_strerror(status)); \
goto error; \
} \
} while (0)
#define CHECK_NULL(...) do { \
const void* _args[] = { __VA_ARGS__, NULL }; \
for (size_t _i = 0; _args[_i] != NULL; ++_i) { \
if (_args[_i] == NULL) { \
fprintf(stderr, "%s:%d: Argument %zu is NULL\n", __FILE__, __LINE__, _i + 1); \
return BLADERF_ERR_INVAL; \
} \
} \
} while (0)
static const struct option long_options[] = {
{ "device", required_argument, NULL, 'd' },
{ "profiles", required_argument, NULL, 'p' },
{ "samplerate", required_argument, NULL, 's' },
{ "verbosity", required_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 },
};
int main(int argc, char *argv[])
{
int opt = 0;
int opt_ind = 0;
int status = 0;
char *devstr = NULL;
struct bladerf *dev;
const size_t num_samples = 508;
int16_t *samples = NULL;
const size_t num_buffers = 2;
const size_t buffer_size = 2048;
int verbosity = BLADERF_LOG_LEVEL_INFO;
size_t freq_min = 915e6;
size_t freq_max = 5.05e9;
size_t num_profiles = 8;
size_t freq_step;
bladerf_frequency *freqs = NULL;
struct bladerf_quick_tune *quick_tune = NULL;
struct bladerf_metadata metadata;
bladerf_timestamp *ts = NULL;
unsigned int samplerate = 10e6;
double *powers = NULL;
while (opt != -1) {
opt = getopt_long(argc, argv, "d:p:s:v:h", long_options, &opt_ind);
switch (opt) {
case 'd':
devstr = optarg;
break;
case 'p':
num_profiles = atoi(optarg);
break;
case 's':
samplerate = atof(optarg) * 1e6;
break;
case 'v':
verbosity = atoi(optarg);
break;
case 'h':
printf("Usage: %s [options]\n", argv[0]);
printf(" -d, --device <str> Specify device to open\n");
printf(" -p, --profiles <n> Number of frequency profiles (default: 8)\n");
printf(" -s, --samplerate <n> Sample rate in MHz (default: 10)\n");
printf(" -v, --verbosity <n> Set libbladeRF verbosity level (default: 3)\n");
printf(" 0=verbose, 1=debug, 2=info, 3=warning, 4=error, 5=critical, 6=silent\n");
printf(" -h, --help Show this text\n");
return 0;
default:
break;
}
}
bladerf_log_set_verbosity(verbosity);
freq_step = (freq_max - freq_min) / (num_profiles - 1);
samples = (int16_t *)malloc(num_samples * 2 * sizeof(int16_t));
freqs = (bladerf_frequency *)malloc(num_profiles * sizeof(bladerf_frequency));
quick_tune = (struct bladerf_quick_tune *)malloc(num_profiles * sizeof(struct bladerf_quick_tune));
ts = (bladerf_timestamp *)malloc((num_profiles + 1) * sizeof(bladerf_timestamp));
powers = (double *)malloc(num_profiles * sizeof(double));
CHECK_NULL(samples, freqs, quick_tune, ts, powers);
CHECK_STATUS(bladerf_open(&dev, devstr));
CHECK_STATUS(bladerf_sync_config(dev, BLADERF_RX_X1,
BLADERF_FORMAT_SC16_Q11_META,
num_buffers, buffer_size, 1, 1e3));
CHECK_STATUS(bladerf_set_gain_mode(dev, BLADERF_CHANNEL_RX(0), BLADERF_GAIN_MANUAL));
CHECK_STATUS(bladerf_set_gain(dev, BLADERF_CHANNEL_RX(0), 0));
CHECK_STATUS(bladerf_set_sample_rate(dev, BLADERF_CHANNEL_RX(0), samplerate, NULL));
CHECK_STATUS(bladerf_set_bandwidth(dev, BLADERF_CHANNEL_RX(0), samplerate, NULL));
CHECK_STATUS(bladerf_enable_module(dev, BLADERF_CHANNEL_RX(0), true));
printf("Configuring %zu frequency profiles:\n", num_profiles);
for (size_t i = 0; i < num_profiles; i++) {
freqs[i] = freq_min + i*freq_step;
printf("Profile %zu: %.3f MHz\n", i, freqs[i] / 1e6);
CHECK_STATUS(bladerf_set_frequency(dev, BLADERF_CHANNEL_RX(0), freqs[i]));
CHECK_STATUS(bladerf_get_quick_tune(dev, BLADERF_CHANNEL_RX(0), &quick_tune[i]));
}
CHECK_STATUS(bladerf_get_timestamp(dev, BLADERF_RX, &ts[0]));
ts[0] += samplerate;
for (size_t i = 0; i < num_profiles; i++) {
CHECK_STATUS(bladerf_schedule_retune(dev, BLADERF_CHANNEL_RX(0),
ts[i], freqs[i], &(quick_tune[i])));
ts[i+1] = ts[i] + 10e3;
}
for (size_t i = 0; i < num_profiles; i++) {
metadata.flags = 0;
metadata.timestamp = ts[i+1];
CHECK_STATUS(bladerf_sync_rx(dev, samples, num_samples, &metadata, 1000));
if (metadata.status & BLADERF_META_STATUS_OVERRUN) {
fprintf(stderr, "Overflow detected\n");
status = EXIT_FAILURE;
goto error;
}
double power_sum = 0;
for (size_t j = 0; j < metadata.actual_count; j++) {
double i_val = samples[2*j] / 2047.0;
double q_val = samples[2*j+1] / 2047.0;
power_sum += i_val * i_val + q_val * q_val;
}
powers[i] = power_sum / metadata.actual_count;
}
// Close now to dismiss overrun warnings
bladerf_enable_module(dev, BLADERF_CHANNEL_RX(0), false);
bladerf_close(dev);
dev = NULL;
printf("\nMeasured powers:\n");
for (size_t i = 0; i < num_profiles; i++) {
printf("%.3f MHz: %.2f dBFS\n", freqs[i] / 1e6, 10 * log10(powers[i]));
}
error:
if (dev != NULL) {
bladerf_enable_module(dev, BLADERF_CHANNEL_RX(0), false);
bladerf_close(dev);
}
free(samples);
free(freqs);
free(quick_tune);
free(ts);
free(powers);
return status;
}