examples/blinky: add a new example app
This commit is contained in:
parent
863badf5c3
commit
f8b1dd41c5
27
examples/blinky/Makefile
Normal file
27
examples/blinky/Makefile
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# name of your application
|
||||||
|
APPLICATION = blinky
|
||||||
|
|
||||||
|
# If no BOARD is found in the environment, use this default:
|
||||||
|
BOARD ?= native
|
||||||
|
|
||||||
|
# This has to be the absolute path to the RIOT base directory:
|
||||||
|
RIOTBASE ?= $(CURDIR)/../..
|
||||||
|
|
||||||
|
# Comment this out to disable code in RIOT that does safety checking
|
||||||
|
# which is not needed in a production environment but helps in the
|
||||||
|
# development process:
|
||||||
|
DEVELHELP ?= 1
|
||||||
|
|
||||||
|
# Change this to 0 show compiler invocation lines by default:
|
||||||
|
QUIET ?= 1
|
||||||
|
|
||||||
|
# Use a peripheral timer for the delay, if available
|
||||||
|
FEATURES_OPTIONAL += periph_timer
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
|
||||||
|
ifeq (native,$(BOARD))
|
||||||
|
# For the native board, CLOCK_CORECLOCK is undefined. But we need
|
||||||
|
# a valid number to get the example compiled
|
||||||
|
CFLAGS += -DCLOCK_CORECLOCK=1000000000
|
||||||
|
endif
|
||||||
3
examples/blinky/Makefile.board.dep
Normal file
3
examples/blinky/Makefile.board.dep
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
ifneq (,$(filter periph_timer,$(FEATURES_USED)))
|
||||||
|
USEMODULE += ztimer_usec
|
||||||
|
endif
|
||||||
9
examples/blinky/README.md
Normal file
9
examples/blinky/README.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Blinky!
|
||||||
|
=======
|
||||||
|
|
||||||
|
This is a basic example that blinks an LED, if available. (If no LED is present or configured, it
|
||||||
|
will print "Blink!" via stdio instead.)
|
||||||
|
|
||||||
|
This is mostly useful for boards without stdio to check if a new port of RIOT works. For that
|
||||||
|
reason, this example has only an optional dependency on timer drivers. Hence, this application only
|
||||||
|
needs a working GPIO driver and is likely the first milestone when porting RIOT to new MCUs.
|
||||||
60
examples/blinky/main.c
Normal file
60
examples/blinky/main.c
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 Otto-von-Guericke-Universität Magdeburg
|
||||||
|
*
|
||||||
|
* 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 examples
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief Blinky application
|
||||||
|
*
|
||||||
|
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "board.h"
|
||||||
|
#include "periph_conf.h"
|
||||||
|
#include "timex.h"
|
||||||
|
#include "ztimer.h"
|
||||||
|
|
||||||
|
static void delay(void)
|
||||||
|
{
|
||||||
|
if (IS_USED(MODULE_ZTIMER)) {
|
||||||
|
ztimer_sleep(ZTIMER_USEC, 1 * US_PER_SEC);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/*
|
||||||
|
* As fallback for freshly ported boards with no timer drivers written
|
||||||
|
* yet, we just use the CPU to delay execution and assume that roughly
|
||||||
|
* 20 CPU cycles are spend per loop iteration.
|
||||||
|
*
|
||||||
|
* Note that the volatile qualifier disables compiler optimizations for
|
||||||
|
* all accesses to the counter variable. Without volatile, modern
|
||||||
|
* compilers would detect that the loop is only wasting CPU cycles and
|
||||||
|
* optimize it out - but here the wasting of CPU cycles is desired.
|
||||||
|
*/
|
||||||
|
for (volatile uint32_t i = 0; i < CLOCK_CORECLOCK / 20; i++) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
while (1) {
|
||||||
|
delay();
|
||||||
|
#ifdef LED0_TOGGLE
|
||||||
|
LED0_TOGGLE;
|
||||||
|
#else
|
||||||
|
puts("Blink! (No LED present or configured...)");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user