69 lines
1.6 KiB
C
69 lines
1.6 KiB
C
#ifndef SDR_SDR_H
|
|
#define SDR_SDR_H
|
|
|
|
#include <complex.h>
|
|
#include <semaphore.h>
|
|
#include <stdbool.h>
|
|
|
|
#include <libhackrf/hackrf.h>
|
|
|
|
#include <liquid/liquid.h>
|
|
|
|
#include "results.h"
|
|
|
|
typedef enum {
|
|
SDR_STATUS_IDLE,
|
|
SDR_STATUS_TX,
|
|
SDR_STATUS_RX
|
|
} sdr_status_t;
|
|
|
|
typedef struct {
|
|
hackrf_device *hackrf;
|
|
|
|
firinterp_crcf interp;
|
|
nco_crcf tx_nco;
|
|
cbuffercf tx_buf;
|
|
|
|
firdecim_crcf decim;
|
|
nco_crcf rx_nco;
|
|
cbuffercf rx_buf;
|
|
|
|
sem_t buf_sem;
|
|
|
|
sdr_status_t status;
|
|
double tx_duration;
|
|
double tx_start_time; // time when tx_callback() was first called
|
|
} sdr_ctx_t;
|
|
|
|
result_t sdr_init(sdr_ctx_t *ctx);
|
|
result_t sdr_destroy(sdr_ctx_t *ctx);
|
|
|
|
result_t sdr_start_rx(sdr_ctx_t *ctx);
|
|
result_t sdr_start_tx(sdr_ctx_t *ctx, size_t burst_size);
|
|
|
|
result_t sdr_stop_rx(sdr_ctx_t *ctx);
|
|
result_t sdr_stop_tx(sdr_ctx_t *ctx);
|
|
|
|
result_t sdr_transmit(sdr_ctx_t *ctx, const float complex *samples, size_t nsamples, long timeout_us);
|
|
result_t sdr_receive(sdr_ctx_t *ctx, float complex *samples, size_t *nsamples, long timeout_us);
|
|
|
|
result_t sdr_flush_tx_buffer(sdr_ctx_t *ctx);
|
|
size_t sdr_get_tx_buffer_free_space(sdr_ctx_t *ctx);
|
|
size_t sdr_get_tx_buffer_used_space(sdr_ctx_t *ctx);
|
|
|
|
/*!
|
|
* \brief Convert and resample a received signal to baseband.
|
|
*/
|
|
result_t sdr_rf_to_baseband(sdr_ctx_t *ctx,
|
|
const float complex *rf_samples, size_t nrf,
|
|
float complex *bb_samples, size_t *nbb);
|
|
|
|
/*!
|
|
* \brief Convert and resample a baseband signal for transmission.
|
|
*/
|
|
result_t sdr_baseband_to_rf(sdr_ctx_t *ctx,
|
|
const float complex *bb_samples, size_t nbb,
|
|
float complex *rf_samples, size_t *nrf);
|
|
|
|
#endif // SDR_SDR_H
|