From b605da1aff81c2688bf43dfa50c4ea3e5b89b722 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Mon, 13 Nov 2017 20:00:52 +0100 Subject: Restructure: Move timer from common code to 'libtimer' --- .gitignore | 1 + configure.ac | 1 + src/Makefile.am | 2 +- src/amps/Makefile.am | 1 + src/amps/amps.c | 1 - src/amps/amps.h | 1 + src/amps/amps_tacs_main.c | 1 - src/amps/dsp.c | 1 - src/amps/frame.c | 1 - src/amps/sysinfo.c | 1 - src/amps/transaction.c | 1 - src/anetz/Makefile.am | 1 + src/anetz/anetz.c | 2 +- src/anetz/dsp.c | 2 +- src/anetz/main.c | 2 +- src/bnetz/Makefile.am | 1 + src/bnetz/bnetz.c | 1 - src/bnetz/bnetz.h | 1 + src/bnetz/dsp.c | 1 - src/bnetz/main.c | 1 - src/cnetz/Makefile.am | 1 + src/cnetz/cnetz.c | 1 - src/cnetz/cnetz.h | 1 + src/cnetz/database.c | 1 - src/cnetz/dsp.c | 1 - src/cnetz/fsk_demod.c | 1 - src/cnetz/main.c | 1 - src/cnetz/telegramm.c | 1 - src/cnetz/transaction.c | 1 - src/common/Makefile.am | 1 - src/common/call.c | 2 +- src/common/main_mobile.c | 2 +- src/common/sdr.c | 2 +- src/common/sender.c | 2 +- src/common/timer.c | 121 ---------------------------------------------- src/common/timer.h | 18 ------- src/jtacs/Makefile.am | 1 + src/libtimer/Makefile.am | 6 +++ src/libtimer/timer.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++ src/libtimer/timer.h | 18 +++++++ src/nmt/Makefile.am | 1 + src/nmt/dms.c | 1 - src/nmt/dsp.c | 1 - src/nmt/frame.c | 1 - src/nmt/main.c | 1 - src/nmt/nmt.c | 1 - src/nmt/nmt.h | 1 + src/nmt/sms.c | 1 - src/nmt/transaction.c | 1 - src/r2000/Makefile.am | 1 + src/r2000/dsp.c | 1 - src/r2000/main.c | 1 - src/r2000/r2000.c | 1 - src/r2000/r2000.h | 1 + src/tacs/Makefile.am | 1 + src/test/Makefile.am | 4 ++ src/test/test_dms.c | 1 - src/test/test_sms.c | 1 - src/tv/Makefile.am | 1 + 59 files changed, 173 insertions(+), 176 deletions(-) delete mode 100644 src/common/timer.c delete mode 100644 src/common/timer.h create mode 100644 src/libtimer/Makefile.am create mode 100644 src/libtimer/timer.c create mode 100644 src/libtimer/timer.h diff --git a/.gitignore b/.gitignore index f59d993..c2bf2a3 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ compile .libs .dirstamp m4 +src/libtimer/libtimer.a src/libsamplerate/libsamplerate.a src/libfilter/libfilter.a src/common/libcommon.a diff --git a/configure.ac b/configure.ac index 62e21b0..40ce417 100644 --- a/configure.ac +++ b/configure.ac @@ -75,6 +75,7 @@ AS_IF([test "x$with_soapy" == "xyes"],[AC_MSG_NOTICE( Compiling with SoapySDR su AS_IF([test "x$somethingmagick" == "xyes"],[AC_MSG_NOTICE( Compiling with ImageMagick )],[AC_MSG_NOTICE( ImageMagick not supported )]) AC_OUTPUT( + src/libtimer/Makefile src/libsamplerate/Makefile src/libfilter/Makefile src/common/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 79f134e..29743ae 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,3 +1,3 @@ AUTOMAKE_OPTIONS = foreign -SUBDIRS = libsamplerate libfilter common anetz bnetz cnetz nmt amps tacs jtacs r2000 tv test +SUBDIRS = libtimer libsamplerate libfilter common anetz bnetz cnetz nmt amps tacs jtacs r2000 tv test diff --git a/src/amps/Makefile.am b/src/amps/Makefile.am index 390a69e..f37c5ff 100644 --- a/src/amps/Makefile.am +++ b/src/amps/Makefile.am @@ -28,6 +28,7 @@ amps_LDADD = \ libamps.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(ALSA_LIBS) \ diff --git a/src/amps/amps.c b/src/amps/amps.c index 3115469..358163f 100644 --- a/src/amps/amps.c +++ b/src/amps/amps.c @@ -44,7 +44,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/call.h" #include "../common/cause.h" #include "amps.h" diff --git a/src/amps/amps.h b/src/amps/amps.h index d909208..390ec84 100644 --- a/src/amps/amps.h +++ b/src/amps/amps.h @@ -1,5 +1,6 @@ #include "../common/goertzel.h" #include "../common/sender.h" +#include "../libtimer/timer.h" #include "../common/compandor.h" #include "sysinfo.h" #include "transaction.h" diff --git a/src/amps/amps_tacs_main.c b/src/amps/amps_tacs_main.c index cd65a98..2104d25 100644 --- a/src/amps/amps_tacs_main.c +++ b/src/amps/amps_tacs_main.c @@ -25,7 +25,6 @@ #include "../common/sample.h" #include "../common/main_mobile.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/call.h" #include "../common/mncc_sock.h" #include "amps.h" diff --git a/src/amps/dsp.c b/src/amps/dsp.c index 27575f7..479daea 100644 --- a/src/amps/dsp.c +++ b/src/amps/dsp.c @@ -83,7 +83,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/call.h" #include "amps.h" #include "frame.h" diff --git a/src/amps/frame.c b/src/amps/frame.c index 983649b..efaf4cf 100644 --- a/src/amps/frame.c +++ b/src/amps/frame.c @@ -28,7 +28,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "amps.h" #include "dsp.h" #include "frame.h" diff --git a/src/amps/sysinfo.c b/src/amps/sysinfo.c index 8b99f30..767ea13 100644 --- a/src/amps/sysinfo.c +++ b/src/amps/sysinfo.c @@ -4,7 +4,6 @@ #include #include #include "../common/sample.h" -#include "../common/timer.h" #include "amps.h" #include "frame.h" #include "main.h" diff --git a/src/amps/transaction.c b/src/amps/transaction.c index 6b6add5..5491d88 100644 --- a/src/amps/transaction.c +++ b/src/amps/transaction.c @@ -22,7 +22,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/call.h" #include "../common/cause.h" #include "amps.h" diff --git a/src/anetz/Makefile.am b/src/anetz/Makefile.am index 26ad266..94b3f3c 100644 --- a/src/anetz/Makefile.am +++ b/src/anetz/Makefile.am @@ -14,6 +14,7 @@ anetz_LDADD = \ $(top_builddir)/src/common/libgermanton.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(ALSA_LIBS) \ diff --git a/src/anetz/anetz.c b/src/anetz/anetz.c index e5a3774..cf77ba6 100644 --- a/src/anetz/anetz.c +++ b/src/anetz/anetz.c @@ -26,7 +26,7 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" +#include "../libtimer/timer.h" #include "../common/call.h" #include "../common/cause.h" #include "anetz.h" diff --git a/src/anetz/dsp.c b/src/anetz/dsp.c index 0cd8184..bb08bdc 100644 --- a/src/anetz/dsp.c +++ b/src/anetz/dsp.c @@ -27,7 +27,7 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" +#include "../libtimer/timer.h" #include "../common/call.h" #include "anetz.h" #include "dsp.h" diff --git a/src/anetz/main.c b/src/anetz/main.c index 5a65457..ebd47fd 100644 --- a/src/anetz/main.c +++ b/src/anetz/main.c @@ -26,7 +26,7 @@ #include "../common/sample.h" #include "../common/main_mobile.h" #include "../common/debug.h" -#include "../common/timer.h" +#include "../libtimer/timer.h" #include "../common/call.h" #include "../common/mncc_sock.h" #include "../common/freiton.h" diff --git a/src/bnetz/Makefile.am b/src/bnetz/Makefile.am index f00b82b..6c1e478 100644 --- a/src/bnetz/Makefile.am +++ b/src/bnetz/Makefile.am @@ -16,6 +16,7 @@ bnetz_LDADD = \ $(top_builddir)/src/common/libgermanton.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(ALSA_LIBS) \ diff --git a/src/bnetz/bnetz.c b/src/bnetz/bnetz.c index f216d8c..284b484 100644 --- a/src/bnetz/bnetz.c +++ b/src/bnetz/bnetz.c @@ -26,7 +26,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/call.h" #include "../common/cause.h" #include "bnetz.h" diff --git a/src/bnetz/bnetz.h b/src/bnetz/bnetz.h index 95d6581..07ebae0 100644 --- a/src/bnetz/bnetz.h +++ b/src/bnetz/bnetz.h @@ -1,6 +1,7 @@ #include "../common/squelch.h" #include "../common/fsk.h" #include "../common/sender.h" +#include "../libtimer/timer.h" /* fsk modes of transmission */ enum dsp_mode { diff --git a/src/bnetz/dsp.c b/src/bnetz/dsp.c index f77680e..8ee1492 100644 --- a/src/bnetz/dsp.c +++ b/src/bnetz/dsp.c @@ -27,7 +27,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/call.h" #include "../common/goertzel.h" #include "bnetz.h" diff --git a/src/bnetz/main.c b/src/bnetz/main.c index 6595e5b..9d7e7d6 100644 --- a/src/bnetz/main.c +++ b/src/bnetz/main.c @@ -25,7 +25,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/call.h" #include "../common/mncc_sock.h" #include "../common/main_mobile.h" diff --git a/src/cnetz/Makefile.am b/src/cnetz/Makefile.am index 8065736..c0f6c90 100644 --- a/src/cnetz/Makefile.am +++ b/src/cnetz/Makefile.am @@ -20,6 +20,7 @@ cnetz_LDADD = \ $(top_builddir)/src/common/libgermanton.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(ALSA_LIBS) \ diff --git a/src/cnetz/cnetz.c b/src/cnetz/cnetz.c index 8842a00..c21c2d1 100644 --- a/src/cnetz/cnetz.c +++ b/src/cnetz/cnetz.c @@ -144,7 +144,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/call.h" #include "../common/cause.h" #include "cnetz.h" diff --git a/src/cnetz/cnetz.h b/src/cnetz/cnetz.h index 91c6997..0cb0931 100644 --- a/src/cnetz/cnetz.h +++ b/src/cnetz/cnetz.h @@ -1,4 +1,5 @@ #include "../common/compandor.h" +#include "../libtimer/timer.h" #include "../common/sender.h" #include "fsk_demod.h" #include "scrambler.h" diff --git a/src/cnetz/database.c b/src/cnetz/database.c index be89795..c8d6b64 100644 --- a/src/cnetz/database.c +++ b/src/cnetz/database.c @@ -23,7 +23,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "cnetz.h" #include "database.h" diff --git a/src/cnetz/dsp.c b/src/cnetz/dsp.c index bcd63e0..07a5117 100644 --- a/src/cnetz/dsp.c +++ b/src/cnetz/dsp.c @@ -27,7 +27,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/call.h" #include "cnetz.h" #include "sysinfo.h" diff --git a/src/cnetz/fsk_demod.c b/src/cnetz/fsk_demod.c index 6a921b7..8733930 100644 --- a/src/cnetz/fsk_demod.c +++ b/src/cnetz/fsk_demod.c @@ -129,7 +129,6 @@ #include #include #include "../common/sample.h" -#include "../common/timer.h" #include "../common/debug.h" #include "cnetz.h" #include "dsp.h" diff --git a/src/cnetz/main.c b/src/cnetz/main.c index 7a3f792..7f01f13 100644 --- a/src/cnetz/main.c +++ b/src/cnetz/main.c @@ -25,7 +25,6 @@ #include "../common/sample.h" #include "../common/main_mobile.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/call.h" #include "../common/mncc_sock.h" #include "../common/freiton.h" diff --git a/src/cnetz/telegramm.c b/src/cnetz/telegramm.c index 8b0b539..48c0e83 100644 --- a/src/cnetz/telegramm.c +++ b/src/cnetz/telegramm.c @@ -28,7 +28,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "cnetz.h" #include "dsp.h" #include "sysinfo.h" diff --git a/src/cnetz/transaction.c b/src/cnetz/transaction.c index 1945d0a..cc9aba4 100644 --- a/src/cnetz/transaction.c +++ b/src/cnetz/transaction.c @@ -22,7 +22,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/call.h" #include "../common/cause.h" #include "cnetz.h" diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 6f8ae93..50ee36a 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -5,7 +5,6 @@ noinst_LIBRARIES = libcommon.a libmobile.a libgermanton.a libimage.a libcommon_a_SOURCES = \ sample.c \ debug.c \ - timer.c \ sound_alsa.c \ wave.c \ goertzel.c \ diff --git a/src/common/call.c b/src/common/call.c index c1e6c86..e493607 100644 --- a/src/common/call.c +++ b/src/common/call.c @@ -29,7 +29,7 @@ #include "sender.h" #include "cause.h" #include "call.h" -#include "timer.h" +#include "../libtimer/timer.h" #include "mncc.h" #define DISC_TIMEOUT 30 diff --git a/src/common/main_mobile.c b/src/common/main_mobile.c index 0be77d2..6607f63 100644 --- a/src/common/main_mobile.c +++ b/src/common/main_mobile.c @@ -33,7 +33,7 @@ #include "main_mobile.h" #include "debug.h" #include "sender.h" -#include "timer.h" +#include "../libtimer/timer.h" #include "call.h" #include "mncc_console.h" #include "mncc_sock.h" diff --git a/src/common/sdr.c b/src/common/sdr.c index 72f7db5..01048ee 100644 --- a/src/common/sdr.c +++ b/src/common/sdr.c @@ -31,7 +31,7 @@ enum paging_signal; #include #include "sample.h" #include "fm_modulation.h" -#include "timer.h" +#include "../libtimer/timer.h" #include "sender.h" #include "sdr_config.h" #include "sdr.h" diff --git a/src/common/sender.c b/src/common/sender.c index a3b90e2..bd4baff 100644 --- a/src/common/sender.c +++ b/src/common/sender.c @@ -27,7 +27,7 @@ #include "sample.h" #include "debug.h" #include "sender.h" -#include "timer.h" +#include "../libtimer/timer.h" /* debug time consumption of audio processing */ //#define DEBUG_TIME_CONSUMPTION diff --git a/src/common/timer.c b/src/common/timer.c deleted file mode 100644 index 955d790..0000000 --- a/src/common/timer.c +++ /dev/null @@ -1,121 +0,0 @@ -/* Timer handling - * - * (C) 2016 by Andreas Eversberg - * All Rights Reserved - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include "timer.h" - -static struct timer *timer_head = NULL; -static struct timer **timer_tail_p = &timer_head; - -double get_time(void) -{ - struct timeval tv; - - gettimeofday(&tv, NULL); - - return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0; -} - -void timer_init(struct timer *timer, void (*fn)(struct timer *timer), void *priv) -{ - if (timer->linked) { - fprintf(stderr, "Timer is already initialized, aborting!\n"); - abort(); - } - - timer->timeout = 0; - timer->fn = fn; - timer->priv = priv; - timer->next = NULL; - *timer_tail_p = timer; - timer_tail_p = &timer->next; - timer->linked = 1; -} - -void timer_exit(struct timer *timer) -{ - timer_tail_p = &timer_head; - while (*timer_tail_p) { - if (timer == *timer_tail_p) - *timer_tail_p = (*timer_tail_p)->next; - else - timer_tail_p = &((*timer_tail_p)->next); - } - timer->linked = 0; -} - -void timer_start(struct timer *timer, double duration) -{ - struct timeval tv; - - if (!timer->linked) { - fprintf(stderr, "Timer is not initialized, aborting!\n"); - abort(); - } - - gettimeofday(&tv, NULL); - - timer->duration = duration; - timer->timeout = get_time() + duration; -} - -void timer_stop(struct timer *timer) -{ - if (!timer->linked) { - fprintf(stderr, "Timer is not initialized, aborting!\n"); - abort(); - } - - timer->timeout = 0; -} - -int timer_running(struct timer *timer) -{ - if (!timer->linked) { - fprintf(stderr, "Timer is not initialized, aborting!\n"); - abort(); - } - - return (timer->timeout != 0); -} - -void process_timer(void) -{ - struct timer *timer; - double now; - - now = get_time(); - -again: - timer = timer_head; - - while (timer) { - if (timer->linked && timer->timeout > 0 && now >= timer->timeout) { - timer->timeout = 0; - timer->fn(timer); - goto again; - } - timer = timer->next; - } -} - diff --git a/src/common/timer.h b/src/common/timer.h deleted file mode 100644 index 2073a8f..0000000 --- a/src/common/timer.h +++ /dev/null @@ -1,18 +0,0 @@ - -struct timer { - struct timer *next; - int linked; /* set is timer is initialized and linked */ - double duration; - double timeout; - void (*fn)(struct timer *timer); - void *priv; -}; - -double get_time(void); -void timer_init(struct timer *timer, void (*fn)(struct timer *timer), void *priv); -void timer_exit(struct timer *timer); -void timer_start(struct timer *timer, double duration); -void timer_stop(struct timer *timer); -int timer_running(struct timer *timer); -void process_timer(void); - diff --git a/src/jtacs/Makefile.am b/src/jtacs/Makefile.am index 763df25..651d2b9 100644 --- a/src/jtacs/Makefile.am +++ b/src/jtacs/Makefile.am @@ -14,6 +14,7 @@ jtacs_LDADD = \ ../amps/libamps.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(ALSA_LIBS) \ diff --git a/src/libtimer/Makefile.am b/src/libtimer/Makefile.am new file mode 100644 index 0000000..538670a --- /dev/null +++ b/src/libtimer/Makefile.am @@ -0,0 +1,6 @@ +AM_CPPFLAGS = -Wall -Wextra -g $(all_includes) + +noinst_LIBRARIES = libtimer.a + +libtimer_a_SOURCES = \ + timer.c diff --git a/src/libtimer/timer.c b/src/libtimer/timer.c new file mode 100644 index 0000000..955d790 --- /dev/null +++ b/src/libtimer/timer.c @@ -0,0 +1,121 @@ +/* Timer handling + * + * (C) 2016 by Andreas Eversberg + * All Rights Reserved + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include "timer.h" + +static struct timer *timer_head = NULL; +static struct timer **timer_tail_p = &timer_head; + +double get_time(void) +{ + struct timeval tv; + + gettimeofday(&tv, NULL); + + return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0; +} + +void timer_init(struct timer *timer, void (*fn)(struct timer *timer), void *priv) +{ + if (timer->linked) { + fprintf(stderr, "Timer is already initialized, aborting!\n"); + abort(); + } + + timer->timeout = 0; + timer->fn = fn; + timer->priv = priv; + timer->next = NULL; + *timer_tail_p = timer; + timer_tail_p = &timer->next; + timer->linked = 1; +} + +void timer_exit(struct timer *timer) +{ + timer_tail_p = &timer_head; + while (*timer_tail_p) { + if (timer == *timer_tail_p) + *timer_tail_p = (*timer_tail_p)->next; + else + timer_tail_p = &((*timer_tail_p)->next); + } + timer->linked = 0; +} + +void timer_start(struct timer *timer, double duration) +{ + struct timeval tv; + + if (!timer->linked) { + fprintf(stderr, "Timer is not initialized, aborting!\n"); + abort(); + } + + gettimeofday(&tv, NULL); + + timer->duration = duration; + timer->timeout = get_time() + duration; +} + +void timer_stop(struct timer *timer) +{ + if (!timer->linked) { + fprintf(stderr, "Timer is not initialized, aborting!\n"); + abort(); + } + + timer->timeout = 0; +} + +int timer_running(struct timer *timer) +{ + if (!timer->linked) { + fprintf(stderr, "Timer is not initialized, aborting!\n"); + abort(); + } + + return (timer->timeout != 0); +} + +void process_timer(void) +{ + struct timer *timer; + double now; + + now = get_time(); + +again: + timer = timer_head; + + while (timer) { + if (timer->linked && timer->timeout > 0 && now >= timer->timeout) { + timer->timeout = 0; + timer->fn(timer); + goto again; + } + timer = timer->next; + } +} + diff --git a/src/libtimer/timer.h b/src/libtimer/timer.h new file mode 100644 index 0000000..2073a8f --- /dev/null +++ b/src/libtimer/timer.h @@ -0,0 +1,18 @@ + +struct timer { + struct timer *next; + int linked; /* set is timer is initialized and linked */ + double duration; + double timeout; + void (*fn)(struct timer *timer); + void *priv; +}; + +double get_time(void); +void timer_init(struct timer *timer, void (*fn)(struct timer *timer), void *priv); +void timer_exit(struct timer *timer); +void timer_start(struct timer *timer, double duration); +void timer_stop(struct timer *timer); +int timer_running(struct timer *timer); +void process_timer(void); + diff --git a/src/nmt/Makefile.am b/src/nmt/Makefile.am index 4fde118..e3dd06b 100644 --- a/src/nmt/Makefile.am +++ b/src/nmt/Makefile.am @@ -24,6 +24,7 @@ nmt_LDADD = \ libdmssms.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(ALSA_LIBS) \ diff --git a/src/nmt/dms.c b/src/nmt/dms.c index 4efa73a..6fc0c5c 100644 --- a/src/nmt/dms.c +++ b/src/nmt/dms.c @@ -23,7 +23,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "nmt.h" #define MUTE_DURATION 0.300 /* 200ms, and about 95ms for the frame itself */ diff --git a/src/nmt/dsp.c b/src/nmt/dsp.c index 37c1688..84a33a6 100644 --- a/src/nmt/dsp.c +++ b/src/nmt/dsp.c @@ -27,7 +27,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "nmt.h" #include "transaction.h" #include "dsp.h" diff --git a/src/nmt/frame.c b/src/nmt/frame.c index ace9d1f..dd0df8f 100644 --- a/src/nmt/frame.c +++ b/src/nmt/frame.c @@ -24,7 +24,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/hagelbarger.h" #include "nmt.h" #include "frame.h" diff --git a/src/nmt/main.c b/src/nmt/main.c index 0eb626c..a28e10a 100644 --- a/src/nmt/main.c +++ b/src/nmt/main.c @@ -29,7 +29,6 @@ #include "../common/sample.h" #include "../common/main_mobile.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/mncc_sock.h" #include "nmt.h" #include "frame.h" diff --git a/src/nmt/nmt.c b/src/nmt/nmt.c index 997e849..4fdc195 100644 --- a/src/nmt/nmt.c +++ b/src/nmt/nmt.c @@ -27,7 +27,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/cause.h" #include "nmt.h" #include "transaction.h" diff --git a/src/nmt/nmt.h b/src/nmt/nmt.h index 335efde..c1c83da 100644 --- a/src/nmt/nmt.h +++ b/src/nmt/nmt.h @@ -1,4 +1,5 @@ #include "../common/sender.h" +#include "../libtimer/timer.h" #include "../common/compandor.h" #include "../common/dtmf.h" #include "../common/call.h" diff --git a/src/nmt/sms.c b/src/nmt/sms.c index abb6edf..3050f37 100644 --- a/src/nmt/sms.c +++ b/src/nmt/sms.c @@ -25,7 +25,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "nmt.h" #define SMS_RECEIVE_TO 5.0 diff --git a/src/nmt/transaction.c b/src/nmt/transaction.c index 71d671f..c02408e 100644 --- a/src/nmt/transaction.c +++ b/src/nmt/transaction.c @@ -23,7 +23,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "nmt.h" #include "transaction.h" diff --git a/src/r2000/Makefile.am b/src/r2000/Makefile.am index 704d734..a5e1585 100644 --- a/src/r2000/Makefile.am +++ b/src/r2000/Makefile.am @@ -14,6 +14,7 @@ radiocom2000_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(ALSA_LIBS) \ diff --git a/src/r2000/dsp.c b/src/r2000/dsp.c index f34889e..f6a2adc 100644 --- a/src/r2000/dsp.c +++ b/src/r2000/dsp.c @@ -27,7 +27,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "r2000.h" #include "dsp.h" diff --git a/src/r2000/main.c b/src/r2000/main.c index 422b4c1..bcac829 100644 --- a/src/r2000/main.c +++ b/src/r2000/main.c @@ -29,7 +29,6 @@ #include "../common/sample.h" #include "../common/main_mobile.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/mncc_sock.h" #include "r2000.h" #include "dsp.h" diff --git a/src/r2000/r2000.c b/src/r2000/r2000.c index 8c148f5..bf1bee4 100644 --- a/src/r2000/r2000.c +++ b/src/r2000/r2000.c @@ -27,7 +27,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../common/cause.h" #include "r2000.h" //#include "transaction.h" diff --git a/src/r2000/r2000.h b/src/r2000/r2000.h index bae6735..41a746a 100644 --- a/src/r2000/r2000.h +++ b/src/r2000/r2000.h @@ -1,4 +1,5 @@ #include "../common/compandor.h" +#include "../libtimer/timer.h" #include "../common/sender.h" #include "../common/call.h" #include "../common/fsk.h" diff --git a/src/tacs/Makefile.am b/src/tacs/Makefile.am index 7ba0e6a..1b392d3 100644 --- a/src/tacs/Makefile.am +++ b/src/tacs/Makefile.am @@ -15,6 +15,7 @@ tacs_LDADD = \ ../amps/libamps.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(ALSA_LIBS) \ diff --git a/src/test/Makefile.am b/src/test/Makefile.am index a30f003..37632cf 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -15,6 +15,7 @@ test_filter_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(ALSA_LIBS) \ @@ -39,6 +40,7 @@ test_emphasis_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(ALSA_LIBS) \ @@ -53,6 +55,7 @@ test_dms_LDADD = \ $(top_builddir)/src/nmt/libdmssms.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(ALSA_LIBS) \ @@ -67,6 +70,7 @@ test_sms_LDADD = \ $(top_builddir)/src/nmt/libdmssms.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(ALSA_LIBS) \ diff --git a/src/test/test_dms.c b/src/test/test_dms.c index bc44af0..74f7eb8 100644 --- a/src/test/test_dms.c +++ b/src/test/test_dms.c @@ -6,7 +6,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../nmt/nmt.h" extern int dms_allow_loopback; diff --git a/src/test/test_sms.c b/src/test/test_sms.c index 1706dd3..63726ca 100644 --- a/src/test/test_sms.c +++ b/src/test/test_sms.c @@ -6,7 +6,6 @@ #include #include "../common/sample.h" #include "../common/debug.h" -#include "../common/timer.h" #include "../nmt/nmt.h" static const uint8_t test_mo_sms_data1[] = { diff --git a/src/tv/Makefile.am b/src/tv/Makefile.am index b6d20de..1b984d8 100644 --- a/src/tv/Makefile.am +++ b/src/tv/Makefile.am @@ -16,6 +16,7 @@ osmotv_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/common/libimage.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(ALSA_LIBS) \ $(UHD_LIBS) \ -- cgit v1.2.3