mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-20 12:03:52 +01:00
arm/newlib: Add pseudomodule to enable floating point printf support
This commit is contained in:
parent
b46b9d9086
commit
e1fcee67c0
@ -23,6 +23,7 @@ PSEUDOMODULES += schedstatistics
|
|||||||
PSEUDOMODULES += netif
|
PSEUDOMODULES += netif
|
||||||
PSEUDOMODULES += saul_default
|
PSEUDOMODULES += saul_default
|
||||||
PSEUDOMODULES += saul_gpio
|
PSEUDOMODULES += saul_gpio
|
||||||
|
PSEUDOMODULES += printf_float
|
||||||
|
|
||||||
# include variants of the AT86RF2xx drivers as pseudo modules
|
# include variants of the AT86RF2xx drivers as pseudo modules
|
||||||
PSEUDOMODULES += at86rf23%
|
PSEUDOMODULES += at86rf23%
|
||||||
|
|||||||
@ -95,6 +95,7 @@ include $(RIOTCPU)/cortexm_common/Makefile.include
|
|||||||
|
|
||||||
# use the nano-specs of Newlib when available
|
# use the nano-specs of Newlib when available
|
||||||
USEMODULE += newlib_nano
|
USEMODULE += newlib_nano
|
||||||
|
export USE_NANO_SPECS = 1
|
||||||
|
|
||||||
# Avoid overriding the default rule:
|
# Avoid overriding the default rule:
|
||||||
all:
|
all:
|
||||||
|
|||||||
@ -63,4 +63,10 @@ ifneq (,$(filter arduino,$(USEMODULE)))
|
|||||||
include $(RIOTBASE)/sys/arduino/Makefile.include
|
include $(RIOTBASE)/sys/arduino/Makefile.include
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq (,$(filter printf_float,$(USEMODULE)))
|
||||||
|
ifeq (1,$(USE_NANO_SPECS))
|
||||||
|
export LINKFLAGS += -u _printf_float
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
INCLUDES += -I$(RIOTBASE)/sys/libc/include
|
INCLUDES += -I$(RIOTBASE)/sys/libc/include
|
||||||
|
|||||||
6
tests/printf_float/Makefile
Normal file
6
tests/printf_float/Makefile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
APPLICATION = test_printf_float
|
||||||
|
include ../Makefile.tests_common
|
||||||
|
|
||||||
|
USEMODULE += printf_float
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.include
|
||||||
51
tests/printf_float/main.c
Normal file
51
tests/printf_float/main.c
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||||
|
*
|
||||||
|
* 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 tests
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief print floating point values test application
|
||||||
|
*
|
||||||
|
* This test is supposed to check that floating point values can be
|
||||||
|
* displayed with printf function.
|
||||||
|
*
|
||||||
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
static const char * expected_result = "2016.0";
|
||||||
|
static const double floating_point_value = 2016.0317;
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
const uint8_t str_len = strlen(expected_result);
|
||||||
|
char result[str_len];
|
||||||
|
snprintf(result, str_len + 1,
|
||||||
|
"%.f", floating_point_value);
|
||||||
|
|
||||||
|
printf("Value displayed: %s\n", result);
|
||||||
|
|
||||||
|
if (strcmp(result, expected_result) == 0) {
|
||||||
|
printf("[OK]\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("[FAILED] Values are not equal:\n"
|
||||||
|
"actual: %s\n"
|
||||||
|
"expected: %s\n", result, expected_result);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user