From a88997be30bc1c6e7b574b9033cd8ea8e1854b73 Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Fri, 4 Aug 2023 14:26:30 +0200 Subject: [PATCH] energest: inline functions when disabled Make the energest functions static inline functions in the header so the cost of disabled energest 0. This saves 12 bytes text on MSP430. --- os/sys/energest.c | 19 ------------------- os/sys/energest.h | 12 ++++++++++-- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/os/sys/energest.c b/os/sys/energest.c index beaf411bc95..46f4dd18a80 100644 --- a/os/sys/energest.c +++ b/os/sys/energest.c @@ -80,23 +80,4 @@ energest_get_total_time(void) energest_type_time(ENERGEST_TYPE_LPM) + energest_type_time(ENERGEST_TYPE_DEEP_LPM); } -/*---------------------------------------------------------------------------*/ -#else /* ENERGEST_CONF_ON */ - -void -energest_init(void) -{ -} - -void -energest_flush(void) -{ -} - -uint64_t -energest_get_total_time(void) -{ - return 0; -} - #endif /* ENERGEST_CONF_ON */ diff --git a/os/sys/energest.h b/os/sys/energest.h index 0875eaba7c7..9d126c82b6c 100644 --- a/os/sys/energest.h +++ b/os/sys/energest.h @@ -74,11 +74,15 @@ #endif /* ENERGEST_SECOND */ #ifndef ENERGEST_GET_TOTAL_TIME +#if ENERGEST_CONF_ON #ifdef ENERGEST_CONF_GET_TOTAL_TIME #define ENERGEST_GET_TOTAL_TIME ENERGEST_CONF_GET_TOTAL_TIME #else /* ENERGEST_CONF_GET_TOTAL_TIME */ #define ENERGEST_GET_TOTAL_TIME energest_get_total_time #endif /* ENERGEST_CONF_GET_TOTAL_TIME */ +#else /* ENERGEST_CONF_ON */ +#define ENERGEST_GET_TOTAL_TIME() +#endif /* ENERGEST_CONF_ON */ #endif /* ENERGEST_GET_TOTAL_TIME */ /* @@ -106,13 +110,13 @@ typedef enum energest_type { ENERGEST_TYPE_MAX } energest_type_t; +#if ENERGEST_CONF_ON + void energest_init(void); void energest_flush(void); uint64_t ENERGEST_GET_TOTAL_TIME(void); -#if ENERGEST_CONF_ON - extern uint64_t energest_total_time[ENERGEST_TYPE_MAX]; extern ENERGEST_TIME_T energest_current_time[ENERGEST_TYPE_MAX]; extern unsigned char energest_current_mode[ENERGEST_TYPE_MAX]; @@ -168,6 +172,10 @@ energest_switch(energest_type_t type_off, energest_type_t type_on) #else /* ENERGEST_CONF_ON */ +static inline void energest_init(void) { } + +static inline void energest_flush(void) { } + static inline uint64_t energest_type_time(energest_type_t type) { return 0; } static inline void energest_type_set(energest_type_t type, uint64_t time) { }