From c44c022ac426672eb02a0656632afca635a1ce96 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 14 Aug 2015 16:02:32 +0200 Subject: [PATCH] examples: timers: add timer_periodic_wakeup example --- examples/timer_periodic_wakeup/Makefile | 9 ++++++ examples/timer_periodic_wakeup/main.c | 37 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 examples/timer_periodic_wakeup/Makefile create mode 100644 examples/timer_periodic_wakeup/main.c diff --git a/examples/timer_periodic_wakeup/Makefile b/examples/timer_periodic_wakeup/Makefile new file mode 100644 index 000000000..e8744e127 --- /dev/null +++ b/examples/timer_periodic_wakeup/Makefile @@ -0,0 +1,9 @@ +APPLICATION = timer_periodic_wakeup +RIOTBASE ?= $(CURDIR)/../.. +BOARD ?= native +USEMODULE += xtimer +QUIET ?= 1 + +FEATURES_REQUIRED += periph_timer + +include $(RIOTBASE)/Makefile.include diff --git a/examples/timer_periodic_wakeup/main.c b/examples/timer_periodic_wakeup/main.c new file mode 100644 index 000000000..ce080f4e9 --- /dev/null +++ b/examples/timer_periodic_wakeup/main.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2015 Kaspar Schleiser + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup xtimer_examples + * @{ + * + * @file + * @brief example application for setting a periodic wakeup + * + * @author Kaspar Schleiser + * + * @} + */ + +#include +#include "xtimer.h" + +/* set interval to 1 second */ +#define INTERVAL (1000000U) + +int main(void) +{ + uint32_t last_wakeup = xtimer_now(); + + while(1) { + xtimer_usleep_until(&last_wakeup, INTERVAL); + printf("slept until %"PRIu32"\n", xtimer_now()); + } + + return 0; +}