From d56968352c626dda51552bb469ac23a8964d6d29 Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Sun, 25 Aug 2019 17:29:34 +0200 Subject: fl2k_fm: make inline functions static Otherwise the linker will complain when building with -DCMAKE_BUILD_TYPE=Debug --- src/fl2k_fm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/fl2k_fm.c') diff --git a/src/fl2k_fm.c b/src/fl2k_fm.c index 4aae95b..5d14fba 100644 --- a/src/fl2k_fm.c +++ b/src/fl2k_fm.c @@ -153,17 +153,17 @@ typedef struct { unsigned long int phase_slope; } dds_t; -inline void dds_setphase(dds_t *dds, double phase) +static inline void dds_setphase(dds_t *dds, double phase) { dds->phase = phase * ANG_INCR; } -inline double dds_getphase(dds_t *dds) +static inline double dds_getphase(dds_t *dds) { return dds->phase / ANG_INCR; } -inline void dds_set_freq(dds_t *dds, double freq, double fslope) +static inline void dds_set_freq(dds_t *dds, double freq, double fslope) { dds->fslope = fslope; dds->phase_step = (freq / dds->sample_freq) * 2 * M_PI * ANG_INCR; @@ -196,7 +196,7 @@ dds_t dds_init(double sample_freq, double freq, double phase) return dds; } -inline int8_t dds_real(dds_t *dds) +static inline int8_t dds_real(dds_t *dds) { int tmp; @@ -209,7 +209,7 @@ inline int8_t dds_real(dds_t *dds) return sine_table[tmp]; } -inline void dds_real_buf(dds_t *dds, int8_t *buf, int count) +static inline void dds_real_buf(dds_t *dds, int8_t *buf, int count) { int i; for (i = 0; i < count; i++) @@ -267,7 +267,7 @@ static void *fm_worker(void *arg) pthread_exit(NULL); } -inline int writelen(int maxlen) +static inline int writelen(int maxlen) { int rp = readpos; int len; @@ -283,7 +283,7 @@ inline int writelen(int maxlen) return r; } -inline double modulate_sample(int lastwritepos, double lastfreq, double sample) +static inline double modulate_sample(int lastwritepos, double lastfreq, double sample) { double freq, slope; -- cgit v1.2.3 From 077613efc501195f4ad0018e9d94f848654f6c3e Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Mon, 26 Aug 2019 19:26:30 +0200 Subject: improve exit handling on device removal --- src/fl2k_file.c | 6 ++++++ src/fl2k_fm.c | 1 + src/fl2k_tcp.c | 12 ++++++++++++ src/fl2k_test.c | 10 ++++++---- src/libosmo-fl2k.c | 17 ++++++++++------- 5 files changed, 35 insertions(+), 11 deletions(-) (limited to 'src/fl2k_fm.c') diff --git a/src/fl2k_file.c b/src/fl2k_file.c index 80ddcad..5ae199b 100644 --- a/src/fl2k_file.c +++ b/src/fl2k_file.c @@ -85,6 +85,12 @@ void fl2k_callback(fl2k_data_info_t *data_info) int r, left = FL2K_BUF_LEN; static uint32_t repeat_cnt = 0; + if (data_info->device_error) { + fprintf(stderr, "Device error, exiting.\n"); + do_exit = 1; + return; + } + data_info->sampletype_signed = 1; data_info->r_buf = txbuf; diff --git a/src/fl2k_fm.c b/src/fl2k_fm.c index 5d14fba..f947fda 100644 --- a/src/fl2k_fm.c +++ b/src/fl2k_fm.c @@ -419,6 +419,7 @@ void fm_modulator_stereo(int use_rds) void fl2k_callback(fl2k_data_info_t *data_info) { if (data_info->device_error) { + fprintf(stderr, "Device error, exiting.\n"); do_exit = 1; pthread_cond_signal(&fm_cond); } diff --git a/src/fl2k_tcp.c b/src/fl2k_tcp.c index bd01758..1fa9e5d 100644 --- a/src/fl2k_tcp.c +++ b/src/fl2k_tcp.c @@ -107,6 +107,12 @@ void fl2k_callback(fl2k_data_info_t *data_info) int r; struct timeval tv = { 1, 0 }; + if (data_info->device_error) { + fprintf(stderr, "Device error, exiting.\n"); + do_exit = 1; + return; + } + if (!connected) return; @@ -122,6 +128,12 @@ void fl2k_callback(fl2k_data_info_t *data_info) if (r) { received = recv(sock, txbuf + (FL2K_BUF_LEN - left), left, 0); + if (!received) { + fprintf(stderr, "Connection was closed!\n"); + fl2k_stop_tx(dev); + do_exit = 1; + } + left -= received; } } diff --git a/src/fl2k_test.c b/src/fl2k_test.c index 6d82922..b166dda 100644 --- a/src/fl2k_test.c +++ b/src/fl2k_test.c @@ -213,6 +213,12 @@ static void ppm_test(uint32_t len) void fl2k_callback(fl2k_data_info_t *data_info) { + if (data_info->device_error) { + fprintf(stderr, "Device error, exiting.\n"); + do_exit = 1; + return; + } + /* drop first couple of callbacks until everything is settled */ if (cb_cnt > 20) { ppm_test(FL2K_BUF_LEN); @@ -222,7 +228,6 @@ void fl2k_callback(fl2k_data_info_t *data_info) data_info->r_buf = buffer; cb_cnt++; } - } int main(int argc, char **argv) @@ -295,9 +300,6 @@ int main(int argc, char **argv) while (!do_exit) sleep_ms(500); - if (do_exit) - fprintf(stderr, "\nUser cancel, exiting...\n"); - exit: fl2k_close(dev); free(buffer); diff --git a/src/libosmo-fl2k.c b/src/libosmo-fl2k.c index 0b03254..afc4d4f 100644 --- a/src/libosmo-fl2k.c +++ b/src/libosmo-fl2k.c @@ -529,6 +529,7 @@ static void LIBUSB_CALL _libusb_callback(struct libusb_transfer *xfer) fl2k_xfer_info_t *next_xfer_info; fl2k_dev_t *dev = (fl2k_dev_t *)xfer_info->dev; struct libusb_transfer *next_xfer = NULL; + int r = 0; if (LIBUSB_TRANSFER_COMPLETED == xfer->status) { /* resubmit transfer */ @@ -541,8 +542,7 @@ static void LIBUSB_CALL _libusb_callback(struct libusb_transfer *xfer) /* Submit next filled transfer */ next_xfer_info->state = BUF_SUBMITTED; - libusb_submit_transfer(next_xfer); - + r = libusb_submit_transfer(next_xfer); xfer_info->state = BUF_EMPTY; pthread_cond_signal(&dev->buf_cond); } else { @@ -551,17 +551,21 @@ static void LIBUSB_CALL _libusb_callback(struct libusb_transfer *xfer) * stops to output data and hangs * (happens only in the hacked 'gapless' * mode without HSYNC and VSYNC) */ - libusb_submit_transfer(xfer); + r = libusb_submit_transfer(xfer); pthread_cond_signal(&dev->buf_cond); dev->underflow_cnt++; } } - } else if (LIBUSB_TRANSFER_CANCELLED != xfer->status) { + } + + if (((LIBUSB_TRANSFER_CANCELLED != xfer->status) && + (LIBUSB_TRANSFER_COMPLETED != xfer->status)) || + (r == LIBUSB_ERROR_NO_DEVICE)) { dev->dev_lost = 1; fl2k_stop_tx(dev); pthread_cond_signal(&dev->buf_cond); - fprintf(stderr, "cb transfer status: %d, " - "canceling...\n", xfer->status); + fprintf(stderr, "cb transfer status: %d, submit " + "transfer %d, canceling...\n", xfer->status, r); } } @@ -919,7 +923,6 @@ static void *fl2k_sample_worker(void *arg) if (dev->dev_lost && dev->cb) { data_info.device_error = 1; dev->cb(&data_info); - fl2k_stop_tx(dev); } pthread_exit(NULL); -- cgit v1.2.3 From 22ca7ecab52ac0f657568e99a662c21849fc593d Mon Sep 17 00:00:00 2001 From: Felix Erckenbrecht Date: Fri, 1 Nov 2019 14:41:44 +0100 Subject: Rename delta_freq to deviation --- src/fl2k_fm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/fl2k_fm.c') diff --git a/src/fl2k_fm.c b/src/fl2k_fm.c index f947fda..b22efcd 100644 --- a/src/fl2k_fm.c +++ b/src/fl2k_fm.c @@ -73,7 +73,7 @@ uint32_t samp_rate = 100000000; #define PILOT_FREQ 19000 /* In Hz */ #define STEREO_CARRIER 38000 /* In Hz */ -int delta_freq = 75000; +int deviation = 75000; int carrier_freq = 97000000; int carrier_per_signal; int input_freq = 44100; @@ -289,7 +289,7 @@ static inline double modulate_sample(int lastwritepos, double lastfreq, double s /* Calculate modulator frequency at this point to lessen * the calculations needed in the signal generator */ - freq = sample * delta_freq; + freq = sample * deviation; freq += carrier_freq; /* What we do here is calculate a linear "slope" from @@ -468,7 +468,7 @@ int main(int argc, char **argv) carrier_freq = (uint32_t)atof(optarg); break; case 'f': - delta_freq = (uint32_t)atof(optarg); + deviation = (uint32_t)atof(optarg); break; case 'i': input_freq = (uint32_t)atof(optarg); -- cgit v1.2.3