mirror of https://github.com/ARMmbed/mbed-os.git
Addressed review comments
1. LP ticker limiation note 2. Use read_us in mbed_uptime function 3. Doxygen recommendations 4. Use us_timestamp_t instead uint64_t 5. Astyle changespull/6857/head
parent
3420ff7f9c
commit
029237b683
|
|
@ -39,7 +39,7 @@ static void busy_thread()
|
||||||
{
|
{
|
||||||
volatile uint64_t i = ~0;
|
volatile uint64_t i = ~0;
|
||||||
|
|
||||||
while(i--) {
|
while (i--) {
|
||||||
led1 = !led1;
|
led1 = !led1;
|
||||||
wait_us(wait_time);
|
wait_us(wait_time);
|
||||||
}
|
}
|
||||||
|
|
@ -52,7 +52,7 @@ void get_cpu_usage()
|
||||||
mbed_stats_cpu_get(&stats);
|
mbed_stats_cpu_get(&stats);
|
||||||
|
|
||||||
uint64_t diff = (stats.idle_time - prev_idle_time);
|
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;
|
prev_idle_time = stats.idle_time;
|
||||||
|
|
||||||
TEST_ASSERT_NOT_EQUAL(0, usage);
|
TEST_ASSERT_NOT_EQUAL(0, usage);
|
||||||
|
|
|
||||||
|
|
@ -31,18 +31,18 @@
|
||||||
|
|
||||||
// deep sleep locking counter. A target is allowed to deep sleep if counter == 0
|
// deep sleep locking counter. A target is allowed to deep sleep if counter == 0
|
||||||
static uint16_t deep_sleep_lock = 0U;
|
static uint16_t deep_sleep_lock = 0U;
|
||||||
static uint64_t sleep_time = 0;
|
static us_timestamp_t sleep_time = 0;
|
||||||
static uint64_t deep_sleep_time = 0;
|
static us_timestamp_t deep_sleep_time = 0;
|
||||||
|
|
||||||
#if defined(MBED_CPU_STATS_ENABLED) && defined(DEVICE_LOWPOWERTIMER)
|
#if defined(MBED_CPU_STATS_ENABLED) && defined(DEVICE_LOWPOWERTIMER)
|
||||||
static ticker_data_t *sleep_ticker = NULL;
|
static ticker_data_t *sleep_ticker = NULL;
|
||||||
#endif
|
#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 defined(MBED_CPU_STATS_ENABLED) && defined(DEVICE_LOWPOWERTIMER)
|
||||||
if (NULL == sleep_ticker) {
|
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);
|
return ticker_read_us(sleep_ticker);
|
||||||
#else
|
#else
|
||||||
|
|
@ -50,29 +50,22 @@ static inline uint64_t read_us(void)
|
||||||
#endif
|
#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)
|
return read_us();
|
||||||
if (NULL == sleep_ticker) {
|
|
||||||
sleep_ticker = (ticker_data_t*) get_lp_ticker_data();
|
|
||||||
}
|
|
||||||
return ticker_read_us(sleep_ticker);
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t mbed_time_sleep(void)
|
us_timestamp_t mbed_time_sleep(void)
|
||||||
{
|
{
|
||||||
return sleep_time;
|
return sleep_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t mbed_time_deepsleep(void)
|
us_timestamp_t mbed_time_deepsleep(void)
|
||||||
{
|
{
|
||||||
return deep_sleep_time;
|
return deep_sleep_time;
|
||||||
}
|
}
|
||||||
|
|
@ -83,7 +76,7 @@ uint64_t mbed_time_deepsleep(void)
|
||||||
#define STATISTIC_COUNT 10
|
#define STATISTIC_COUNT 10
|
||||||
|
|
||||||
typedef struct sleep_statistic {
|
typedef struct sleep_statistic {
|
||||||
const char* identifier;
|
const char *identifier;
|
||||||
uint8_t count;
|
uint8_t count;
|
||||||
} sleep_statistic_t;
|
} 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);
|
sleep_statistic_t *stat = sleep_tracker_find(filename);
|
||||||
|
|
||||||
|
|
@ -196,7 +189,7 @@ void sleep_manager_sleep_auto(void)
|
||||||
sleep_tracker_print_stats();
|
sleep_tracker_print_stats();
|
||||||
#endif
|
#endif
|
||||||
core_util_critical_section_enter();
|
core_util_critical_section_enter();
|
||||||
uint64_t start = read_us();
|
us_timestamp_t start = read_us();
|
||||||
bool deep = false;
|
bool deep = false;
|
||||||
|
|
||||||
// debug profile should keep debuggers attached, no deep sleep allowed
|
// debug profile should keep debuggers attached, no deep sleep allowed
|
||||||
|
|
@ -211,8 +204,8 @@ void sleep_manager_sleep_auto(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint64_t end = read_us();
|
us_timestamp_t end = read_us();
|
||||||
if(true == deep) {
|
if (true == deep) {
|
||||||
deep_sleep_time += end - start;
|
deep_sleep_time += end - start;
|
||||||
} else {
|
} else {
|
||||||
sleep_time += end - start;
|
sleep_time += end - start;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "sleep_api.h"
|
#include "sleep_api.h"
|
||||||
#include "mbed_toolchain.h"
|
#include "mbed_toolchain.h"
|
||||||
|
#include "hal/ticker_api.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
@ -206,31 +207,33 @@ static inline void system_reset(void)
|
||||||
NVIC_SystemReset();
|
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
|
* @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
|
* @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.
|
* @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 i.e. boot.
|
||||||
/** Provides the time since the system is up and running
|
|
||||||
*
|
*
|
||||||
* @return System uptime.
|
* @return System uptime.
|
||||||
|
* @note Works only if platform supports LP ticker.
|
||||||
*/
|
*/
|
||||||
uint64_t mbed_uptime(void);
|
us_timestamp_t mbed_uptime(void);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#define MBED_STATS_H
|
#define MBED_STATS_H
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include "hal/ticker_api.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
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
|
* struct mbed_stats_cpu_t definition
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t uptime; /**< Time since system is up and running */
|
us_timestamp_t uptime; /**< Time since system is up and running */
|
||||||
uint64_t idle_time; /**< Time spent in idle thread since system is up and running */
|
us_timestamp_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 */
|
us_timestamp_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 deep_sleep_time; /**< Time spent in deep sleep since system is up and running */
|
||||||
} mbed_stats_cpu_t;
|
} mbed_stats_cpu_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue