mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #17418 from aabadie/pr/drivers/periph_build_enh
drivers/periph_common: build periph module selectively
This commit is contained in:
commit
0056648581
@ -40,6 +40,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include "rtc_utils.h"
|
||||
#include "periph_conf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -143,71 +144,6 @@ void rtc_poweron(void);
|
||||
*/
|
||||
void rtc_poweroff(void);
|
||||
|
||||
/**
|
||||
* @brief Normalize the time struct
|
||||
*
|
||||
* @note The function modifies the fields of the tm structure as follows:
|
||||
* If structure members are outside their valid interval,
|
||||
* they will be normalized.
|
||||
* So that, for example, 40 October is changed into 9 November.
|
||||
*
|
||||
* If RTC_NORMALIZE_COMPAT is 1 `tm_wday` and `tm_yday` are set
|
||||
* to values determined from the contents of the other fields.
|
||||
*
|
||||
* @param time Pointer to the struct to normalize.
|
||||
*/
|
||||
void rtc_tm_normalize(struct tm *time);
|
||||
|
||||
/**
|
||||
* @brief Compare two time structs.
|
||||
*
|
||||
* @pre The time structs @p a and @p b are assumed to be normalized.
|
||||
* Use @ref rtc_tm_normalize to normalize a struct tm that has been
|
||||
* manually edited.
|
||||
*
|
||||
* @param[in] a The first time struct.
|
||||
* @param[in] b The second time struct.
|
||||
*
|
||||
* @return an integer < 0 if a is earlier than b
|
||||
* @return an integer > 0 if a is later than b
|
||||
* @return 0 if a and b are equal
|
||||
*/
|
||||
int rtc_tm_compare(const struct tm *a, const struct tm *b);
|
||||
|
||||
/**
|
||||
* @brief Convert time struct into timestamp.
|
||||
*
|
||||
* @pre The time structs @p a and @p b are assumed to be normalized.
|
||||
* Use @ref rtc_tm_normalize to normalize a struct tm that has been
|
||||
* manually edited.
|
||||
*
|
||||
* @param[in] t The time struct to convert
|
||||
*
|
||||
* @return elapsed seconds since `RIOT_EPOCH`
|
||||
*/
|
||||
uint32_t rtc_mktime(struct tm *t);
|
||||
|
||||
/**
|
||||
* @brief Converts an RTC timestamp into a time struct.
|
||||
*
|
||||
* @param[in] time elapsed seconds since `RIOT_EPOCH`
|
||||
* @param[out] t the corresponding timestamp
|
||||
*/
|
||||
void rtc_localtime(uint32_t time, struct tm *t);
|
||||
|
||||
/**
|
||||
* @brief Verify that a time struct @p t contains valid data.
|
||||
*
|
||||
* @note This function checks whether the fields of the
|
||||
* struct @p t are positive and within the bounds set
|
||||
* by @ref rtc_tm_normalize.
|
||||
*
|
||||
* @param[in] t The struct to be checked.
|
||||
*
|
||||
* @return true when valid, false if not
|
||||
*/
|
||||
bool rtc_tm_valid(const struct tm *t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -9,6 +9,7 @@ menuconfig MODULE_PERIPH_RTC
|
||||
bool "RTC peripheral driver"
|
||||
depends on HAS_PERIPH_RTC
|
||||
select MODULE_PERIPH_COMMON
|
||||
select MODULE_RTC_UTILS
|
||||
|
||||
if MODULE_PERIPH_RTC
|
||||
|
||||
|
@ -1 +1,7 @@
|
||||
PERIPH_COMMON_MODULES_SRCS_ALL = $(filter-out init.c,$(wildcard *.c))
|
||||
PERIPH_COMMON_MODULES_NAMES = $(subst .c,,$(PERIPH_COMMON_MODULES_SRCS_ALL))
|
||||
PERIPH_COMMON_MODULES = $(addprefix periph_, $(PERIPH_COMMON_MODULES_NAMES))
|
||||
PERIPH_COMMON_MODULES_USED = $(filter $(PERIPH_COMMON_MODULES),$(USEMODULE))
|
||||
SRC = init.c $(subst periph_,,$(addsuffix .c,$(PERIPH_COMMON_MODULES_USED)))
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
@ -23,9 +23,6 @@
|
||||
#include "periph_cpu.h"
|
||||
#include "assert.h"
|
||||
|
||||
/* guard this file, must be done before including periph/eeprom.h */
|
||||
#if defined(EEPROM_SIZE)
|
||||
|
||||
#include "periph/eeprom.h"
|
||||
|
||||
uint8_t eeprom_read_byte(uint32_t pos)
|
||||
@ -60,4 +57,3 @@ size_t eeprom_erase(void)
|
||||
{
|
||||
return eeprom_clear(0, EEPROM_SIZE);
|
||||
}
|
||||
#endif
|
||||
|
@ -22,13 +22,8 @@
|
||||
#include "cpu.h"
|
||||
#include "assert.h"
|
||||
|
||||
/* guard this file, must be done before including periph/flashpage.h
|
||||
* TODO: remove as soon as periph drivers can be build selectively */
|
||||
#if defined(FLASHPAGE_SIZE) || defined(PERIPH_FLASHPAGE_CUSTOM_PAGESIZES)
|
||||
#include "periph/flashpage.h"
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_PERIPH_FLASHPAGE_PAGEWISE
|
||||
void flashpage_read(unsigned page, void *data)
|
||||
{
|
||||
assert(page < FLASHPAGE_NUMOF);
|
||||
@ -64,6 +59,7 @@ int flashpage_write_and_verify(unsigned page, const void *data)
|
||||
return flashpage_verify(page, data);
|
||||
}
|
||||
|
||||
#ifdef FLASHPAGE_SIZE
|
||||
void flashpage_write_page(unsigned page, const void *data)
|
||||
{
|
||||
assert((unsigned) page < FLASHPAGE_NUMOF);
|
||||
@ -75,7 +71,7 @@ void flashpage_write_page(unsigned page, const void *data)
|
||||
flashpage_write(flashpage_addr(page), data, FLASHPAGE_SIZE);
|
||||
}
|
||||
}
|
||||
#endif /* MODULE_PERIPH_FLASHPAGE_PAGEWISE */
|
||||
#endif
|
||||
|
||||
#if defined(FLASHPAGE_RWWEE_NUMOF)
|
||||
void flashpage_rwwee_read(unsigned page, void *data)
|
||||
|
@ -9,8 +9,6 @@
|
||||
#include "periph/gpio.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef MODULE_PERIPH_GPIO
|
||||
|
||||
uint8_t gpio_util_shiftin(gpio_t data_pin, gpio_t clock_pin)
|
||||
{
|
||||
uint8_t byte = 0x00;
|
||||
@ -25,5 +23,3 @@ uint8_t gpio_util_shiftin(gpio_t data_pin, gpio_t clock_pin)
|
||||
|
||||
return byte;
|
||||
}
|
||||
|
||||
#endif /* MODULE_PERIPH_GPIO */
|
@ -24,8 +24,6 @@
|
||||
#include "periph/i2c.h"
|
||||
#include "byteorder.h"
|
||||
|
||||
#ifdef I2C_NUMOF
|
||||
|
||||
#ifdef PERIPH_I2C_NEED_READ_REG
|
||||
int i2c_read_reg(i2c_t dev, uint16_t addr, uint16_t reg,
|
||||
void *data, uint8_t flags)
|
||||
@ -103,5 +101,3 @@ int i2c_write_regs(i2c_t dev, uint16_t addr, uint16_t reg,
|
||||
return i2c_write_bytes(dev, addr, data, len, flags | I2C_NOSTART);
|
||||
}
|
||||
#endif /* PERIPH_I2C_NEED_WRITE_REGS */
|
||||
|
||||
#endif /* I2C_NUMOF */
|
||||
|
@ -18,7 +18,6 @@
|
||||
* @}
|
||||
*/
|
||||
#include "kernel_defines.h"
|
||||
#if IS_USED(MODULE_PERIPH_PTP_TIMER)
|
||||
#include "irq.h"
|
||||
#include "periph/ptp.h"
|
||||
|
||||
@ -45,6 +44,3 @@ void ptp_timer_set_u64(uint64_t target)
|
||||
irq_restore(irq_state);
|
||||
}
|
||||
#endif /* !defined(HAVE_PTP_TIMER_SET_U64) */
|
||||
#else
|
||||
typedef int dont_be_pedantic;
|
||||
#endif
|
@ -25,8 +25,6 @@
|
||||
#include "cpu.h"
|
||||
#include "periph/spi.h"
|
||||
|
||||
#ifdef SPI_NUMOF
|
||||
|
||||
#ifdef PERIPH_SPI_NEEDS_INIT_CS
|
||||
int spi_init_cs(spi_t bus, spi_cs_t cs)
|
||||
{
|
||||
@ -69,5 +67,3 @@ void spi_transfer_regs(spi_t bus, spi_cs_t cs,
|
||||
spi_transfer_bytes(bus, cs, false, out, in, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SPI_NUMOF */
|
||||
|
@ -51,6 +51,11 @@ ifneq (,$(filter periph_%, $(USEMODULE)))
|
||||
USEMODULE += periph_common
|
||||
endif
|
||||
|
||||
# include rtc_utils if periph_rtc is used
|
||||
ifneq (,$(filter periph_rtc, $(USEMODULE)))
|
||||
USEMODULE += rtc_utils
|
||||
endif
|
||||
|
||||
# select cortexm_svc pseudomodule if the corresponding feature is used
|
||||
USEMODULE += $(filter cortexm_svc, $(FEATURES_USED))
|
||||
|
||||
|
@ -71,6 +71,7 @@ rsource "pm_layered/Kconfig"
|
||||
rsource "progress_bar/Kconfig"
|
||||
rsource "ps/Kconfig"
|
||||
rsource "random/Kconfig"
|
||||
rsource "rtc_utils/Kconfig"
|
||||
rsource "saul_reg/Kconfig"
|
||||
rsource "schedstatistics/Kconfig"
|
||||
rsource "sema/Kconfig"
|
||||
|
100
sys/include/rtc_utils.h
Normal file
100
sys/include/rtc_utils.h
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2019 ML!PA Consulting GmbH
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup sys_rtc_utils RTC helpers
|
||||
* @ingroup sys
|
||||
* @brief Common RTC helper functions
|
||||
* @{
|
||||
* @file
|
||||
*
|
||||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
||||
*/
|
||||
|
||||
#ifndef RTC_UTILS_H
|
||||
#define RTC_UTILS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Normalize the time struct
|
||||
*
|
||||
* @note The function modifies the fields of the tm structure as follows:
|
||||
* If structure members are outside their valid interval,
|
||||
* they will be normalized.
|
||||
* So that, for example, 40 October is changed into 9 November.
|
||||
*
|
||||
* If RTC_NORMALIZE_COMPAT is 1 `tm_wday` and `tm_yday` are set
|
||||
* to values determined from the contents of the other fields.
|
||||
*
|
||||
* @param time Pointer to the struct to normalize.
|
||||
*/
|
||||
void rtc_tm_normalize(struct tm *time);
|
||||
|
||||
/**
|
||||
* @brief Compare two time structs.
|
||||
*
|
||||
* @pre The time structs @p a and @p b are assumed to be normalized.
|
||||
* Use @ref rtc_tm_normalize to normalize a struct tm that has been
|
||||
* manually edited.
|
||||
*
|
||||
* @param[in] a The first time struct.
|
||||
* @param[in] b The second time struct.
|
||||
*
|
||||
* @return an integer < 0 if a is earlier than b
|
||||
* @return an integer > 0 if a is later than b
|
||||
* @return 0 if a and b are equal
|
||||
*/
|
||||
int rtc_tm_compare(const struct tm *a, const struct tm *b);
|
||||
|
||||
/**
|
||||
* @brief Convert time struct into timestamp.
|
||||
*
|
||||
* @pre The time structs @p a and @p b are assumed to be normalized.
|
||||
* Use @ref rtc_tm_normalize to normalize a struct tm that has been
|
||||
* manually edited.
|
||||
*
|
||||
* @param[in] t The time struct to convert
|
||||
*
|
||||
* @return elapsed seconds since `RIOT_EPOCH`
|
||||
*/
|
||||
uint32_t rtc_mktime(struct tm *t);
|
||||
|
||||
/**
|
||||
* @brief Converts an RTC timestamp into a time struct.
|
||||
*
|
||||
* @param[in] time elapsed seconds since `RIOT_EPOCH`
|
||||
* @param[out] t the corresponding timestamp
|
||||
*/
|
||||
void rtc_localtime(uint32_t time, struct tm *t);
|
||||
|
||||
/**
|
||||
* @brief Verify that a time struct @p t contains valid data.
|
||||
*
|
||||
* @note This function checks whether the fields of the
|
||||
* struct @p t are positive and within the bounds set
|
||||
* by @ref rtc_tm_normalize.
|
||||
*
|
||||
* @param[in] t The struct to be checked.
|
||||
*
|
||||
* @return true when valid, false if not
|
||||
*/
|
||||
bool rtc_tm_valid(const struct tm *t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RTC_UTILS_H */
|
||||
/** @} */
|
10
sys/rtc_utils/Kconfig
Normal file
10
sys/rtc_utils/Kconfig
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2021 Inria
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
config MODULE_RTC_UTILS
|
||||
bool "RTC helper functions"
|
||||
depends on TEST_KCONFIG
|
1
sys/rtc_utils/Makefile
Normal file
1
sys/rtc_utils/Makefile
Normal file
@ -0,0 +1 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -7,11 +7,11 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup drivers_periph_rtc
|
||||
* @ingroup sys_rtc_utils
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief common RTC function fallback implementations
|
||||
* @brief common RTC helper functions
|
||||
*
|
||||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
||||
*
|
@ -1,6 +1,6 @@
|
||||
CFLAGS += -DRTC_NORMALIZE_COMPAT=1
|
||||
|
||||
USEMODULE += periph_rtc_common
|
||||
USEMODULE += rtc_utils
|
||||
|
||||
# AVR/ATmega uses `int8_t` for `struct tm` which leads to integer overflows
|
||||
# in these tests
|
||||
|
Loading…
Reference in New Issue
Block a user