diff --git a/TESTS/mbed_platform/stats_cpu/main.cpp b/TESTS/mbed_platform/stats_cpu/main.cpp index 705f5d0374..abbe0202cd 100644 --- a/TESTS/mbed_platform/stats_cpu/main.cpp +++ b/TESTS/mbed_platform/stats_cpu/main.cpp @@ -39,7 +39,7 @@ static void busy_thread() { volatile uint64_t i = ~0; - while(i--) { + while (i--) { led1 = !led1; wait_us(wait_time); } @@ -52,7 +52,7 @@ void get_cpu_usage() mbed_stats_cpu_get(&stats); uint64_t diff = (stats.idle_time - prev_idle_time); - uint8_t usage = 100 - ((diff * 100) / (SAMPLE_TIME*1000)); + uint8_t usage = 100 - ((diff * 100) / (SAMPLE_TIME * 1000)); prev_idle_time = stats.idle_time; TEST_ASSERT_NOT_EQUAL(0, usage); diff --git a/hal/mbed_sleep_manager.c b/hal/mbed_sleep_manager.c index 7a080ee418..8e33acfcb9 100644 --- a/hal/mbed_sleep_manager.c +++ b/hal/mbed_sleep_manager.c @@ -31,18 +31,18 @@ // deep sleep locking counter. A target is allowed to deep sleep if counter == 0 static uint16_t deep_sleep_lock = 0U; -static uint64_t sleep_time = 0; -static uint64_t deep_sleep_time = 0; +static us_timestamp_t sleep_time = 0; +static us_timestamp_t deep_sleep_time = 0; #if defined(MBED_CPU_STATS_ENABLED) && defined(DEVICE_LOWPOWERTIMER) static ticker_data_t *sleep_ticker = NULL; #endif -static inline uint64_t read_us(void) +static inline us_timestamp_t read_us(void) { #if defined(MBED_CPU_STATS_ENABLED) && defined(DEVICE_LOWPOWERTIMER) if (NULL == sleep_ticker) { - sleep_ticker = (ticker_data_t*) get_lp_ticker_data(); + sleep_ticker = (ticker_data_t *)get_lp_ticker_data(); } return ticker_read_us(sleep_ticker); #else @@ -50,29 +50,22 @@ static inline uint64_t read_us(void) #endif } -uint64_t mbed_time_idle(void) +us_timestamp_t mbed_time_idle(void) { - return (sleep_time+deep_sleep_time); + return (sleep_time + deep_sleep_time); } -uint64_t mbed_uptime(void) +us_timestamp_t mbed_uptime(void) { -#if defined(MBED_CPU_STATS_ENABLED) && defined(DEVICE_LOWPOWERTIMER) - if (NULL == sleep_ticker) { - sleep_ticker = (ticker_data_t*) get_lp_ticker_data(); - } - return ticker_read_us(sleep_ticker); -#else - return 0; -#endif + return read_us(); } -uint64_t mbed_time_sleep(void) +us_timestamp_t mbed_time_sleep(void) { return sleep_time; } -uint64_t mbed_time_deepsleep(void) +us_timestamp_t mbed_time_deepsleep(void) { return deep_sleep_time; } @@ -83,7 +76,7 @@ uint64_t mbed_time_deepsleep(void) #define STATISTIC_COUNT 10 typedef struct sleep_statistic { - const char* identifier; + const char *identifier; uint8_t count; } sleep_statistic_t; @@ -132,7 +125,7 @@ static void sleep_tracker_print_stats(void) } } -void sleep_tracker_lock(const char* const filename, int line) +void sleep_tracker_lock(const char *const filename, int line) { sleep_statistic_t *stat = sleep_tracker_find(filename); @@ -196,7 +189,7 @@ void sleep_manager_sleep_auto(void) sleep_tracker_print_stats(); #endif core_util_critical_section_enter(); - uint64_t start = read_us(); + us_timestamp_t start = read_us(); bool deep = false; // debug profile should keep debuggers attached, no deep sleep allowed @@ -211,8 +204,8 @@ void sleep_manager_sleep_auto(void) } #endif - uint64_t end = read_us(); - if(true == deep) { + us_timestamp_t end = read_us(); + if (true == deep) { deep_sleep_time += end - start; } else { sleep_time += end - start; diff --git a/platform/mbed_power_mgmt.h b/platform/mbed_power_mgmt.h index dadf4955b7..9fa7552ab0 100644 --- a/platform/mbed_power_mgmt.h +++ b/platform/mbed_power_mgmt.h @@ -25,6 +25,7 @@ #include "sleep_api.h" #include "mbed_toolchain.h" +#include "hal/ticker_api.h" #include #ifdef __cplusplus @@ -206,31 +207,33 @@ static inline void system_reset(void) NVIC_SystemReset(); } -/** Provides the time spent in sleep mode, since system is up and running +/** Provides the time spent in sleep mode since boot. * * @return Time spent in sleep + * @note Works only if platform supports LP ticker. */ -uint64_t mbed_time_sleep(void); +us_timestamp_t mbed_time_sleep(void); -/** Provides the time spent in deep sleep mode, since system is up and running +/** Provides the time spent in deep sleep mode since boot. * * @return Time spent in deep sleep + * @note Works only if platform supports LP ticker. */ -uint64_t mbed_time_deepsleep(void); +us_timestamp_t mbed_time_deepsleep(void); -/** Provides the time spent in idle thread since the system is up +/** Provides the time spent in idle mode since boot. * * @return Idle thread time. + * @note Works only if platform supports LP ticker. */ -uint64_t mbed_time_idle(void); +us_timestamp_t mbed_time_idle(void); - -/** Provides the time since the system is up and running +/** Provides the time since the system is up i.e. boot. * * @return System uptime. + * @note Works only if platform supports LP ticker. */ -uint64_t mbed_uptime(void); - +us_timestamp_t mbed_uptime(void); #ifdef __cplusplus } diff --git a/platform/mbed_stats.h b/platform/mbed_stats.h index 60634cce4d..3e8f79caca 100644 --- a/platform/mbed_stats.h +++ b/platform/mbed_stats.h @@ -24,6 +24,7 @@ #define MBED_STATS_H #include #include +#include "hal/ticker_api.h" #ifdef __cplusplus extern "C" { @@ -87,10 +88,10 @@ size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count); * struct mbed_stats_cpu_t definition */ typedef struct { - uint64_t uptime; /**< Time since system is up and running */ - uint64_t idle_time; /**< Time spent in idle thread since system is up and running */ - uint64_t sleep_time; /**< Time spent in sleep since system is up and running */ - uint64_t deep_sleep_time; /**< Time spent in deep sleep since system is up and running */ + us_timestamp_t uptime; /**< Time since system is up and running */ + us_timestamp_t idle_time; /**< Time spent in idle thread since system is up and running */ + us_timestamp_t sleep_time; /**< Time spent in sleep since system is up and running */ + us_timestamp_t deep_sleep_time; /**< Time spent in deep sleep since system is up and running */ } mbed_stats_cpu_t; /**