sdr: properly flush the transmit buffers
This commit is contained in:
parent
497498acd2
commit
628659511c
|
@ -264,16 +264,13 @@ int main(void)
|
||||||
if(!on_air) {
|
if(!on_air) {
|
||||||
RESULT_CHECK(sdr_stop_rx(&sdr));
|
RESULT_CHECK(sdr_stop_rx(&sdr));
|
||||||
RESULT_CHECK(sdr_start_tx(&sdr, burst_len * SDR_OVERSAMPLING));
|
RESULT_CHECK(sdr_start_tx(&sdr, burst_len * SDR_OVERSAMPLING));
|
||||||
|
|
||||||
// hopefully no longer needed with latest libhackrf
|
|
||||||
//RESULT_CHECK(sdr_flush_tx_buffer(&sdr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RESULT_CHECK(transmit_in_chunks(&sdr, whole_burst, burst_len));
|
RESULT_CHECK(transmit_in_chunks(&sdr, whole_burst, burst_len));
|
||||||
|
|
||||||
on_air = true;
|
on_air = true;
|
||||||
} else if(on_air) { // ret == 0
|
} else if(on_air) { // ret == 0
|
||||||
//RESULT_CHECK(sdr_flush_tx_buffer(&sdr));
|
RESULT_CHECK(sdr_flush_tx_buffer(&sdr));
|
||||||
|
|
||||||
RESULT_CHECK(sdr_stop_tx(&sdr));
|
RESULT_CHECK(sdr_stop_tx(&sdr));
|
||||||
RESULT_CHECK(sdr_start_rx(&sdr));
|
RESULT_CHECK(sdr_start_rx(&sdr));
|
||||||
|
|
|
@ -67,6 +67,7 @@ static inline int8_t clamp_float2int8(float s)
|
||||||
static int tx_callback(hackrf_transfer *transfer)
|
static int tx_callback(hackrf_transfer *transfer)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
int retcode = 0;
|
||||||
|
|
||||||
sdr_ctx_t *sdr_ctx = (sdr_ctx_t*)transfer->tx_ctx;
|
sdr_ctx_t *sdr_ctx = (sdr_ctx_t*)transfer->tx_ctx;
|
||||||
|
|
||||||
|
@ -86,9 +87,15 @@ static int tx_callback(hackrf_transfer *transfer)
|
||||||
result = cbuffercf_read(sdr_ctx->tx_buf, samples_requested, &samples, &samples_read);
|
result = cbuffercf_read(sdr_ctx->tx_buf, samples_requested, &samples, &samples_read);
|
||||||
if(result != LIQUID_OK) {
|
if(result != LIQUID_OK) {
|
||||||
fprintf(stderr, "cbuffercf_read failed: %d. Samples are lost.\n", result);
|
fprintf(stderr, "cbuffercf_read failed: %d. Samples are lost.\n", result);
|
||||||
|
sem_post(&sdr_ctx->buf_sem);
|
||||||
return HACKRF_ERROR_OTHER;
|
return HACKRF_ERROR_OTHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(samples_read == 0) {
|
||||||
|
// buffer has run empty, so this is the end of the transmission
|
||||||
|
sdr_ctx->tx_done = true;
|
||||||
|
}
|
||||||
|
|
||||||
for(size_t i = 0; i < samples_read; i++) {
|
for(size_t i = 0; i < samples_read; i++) {
|
||||||
transfer->buffer[2*i + 0] = clamp_float2int8(creal(samples[i]));
|
transfer->buffer[2*i + 0] = clamp_float2int8(creal(samples[i]));
|
||||||
transfer->buffer[2*i + 1] = clamp_float2int8(cimag(samples[i]));
|
transfer->buffer[2*i + 1] = clamp_float2int8(cimag(samples[i]));
|
||||||
|
@ -111,7 +118,7 @@ static int tx_callback(hackrf_transfer *transfer)
|
||||||
return HACKRF_ERROR_OTHER;
|
return HACKRF_ERROR_OTHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return retcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static result_t stop_streaming(sdr_ctx_t *ctx)
|
static result_t stop_streaming(sdr_ctx_t *ctx)
|
||||||
|
@ -282,12 +289,13 @@ result_t sdr_transmit(sdr_ctx_t *ctx, const float complex *samples, size_t nsamp
|
||||||
return ERR_LIQUID;
|
return ERR_LIQUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx->tx_done = false;
|
||||||
|
|
||||||
if(sem_post(&ctx->buf_sem) < 0) {
|
if(sem_post(&ctx->buf_sem) < 0) {
|
||||||
perror("sem_post");
|
perror("sem_post");
|
||||||
return ERR_SDR;
|
return ERR_SDR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,8 +342,10 @@ result_t sdr_receive(sdr_ctx_t *ctx, float complex *samples, size_t *nsamples, l
|
||||||
|
|
||||||
result_t sdr_flush_tx_buffer(sdr_ctx_t *ctx)
|
result_t sdr_flush_tx_buffer(sdr_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
// currently not implemented
|
while(!ctx->tx_done) {
|
||||||
(void)ctx;
|
struct timespec ts_1ms = {0, 1000000};
|
||||||
|
nanosleep(&ts_1ms, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <complex.h>
|
#include <complex.h>
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <libhackrf/hackrf.h>
|
#include <libhackrf/hackrf.h>
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@ typedef struct {
|
||||||
sem_t buf_sem;
|
sem_t buf_sem;
|
||||||
|
|
||||||
sdr_status_t status;
|
sdr_status_t status;
|
||||||
|
bool tx_done;
|
||||||
} sdr_ctx_t;
|
} sdr_ctx_t;
|
||||||
|
|
||||||
result_t sdr_init(sdr_ctx_t *ctx);
|
result_t sdr_init(sdr_ctx_t *ctx);
|
||||||
|
|
Loading…
Reference in a new issue