Skip to content

Commit 029237b

Browse files
author
Deepika
committed
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 changes
1 parent 3420ff7 commit 029237b

File tree

4 files changed

+35
-38
lines changed

4 files changed

+35
-38
lines changed

TESTS/mbed_platform/stats_cpu/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static void busy_thread()
3939
{
4040
volatile uint64_t i = ~0;
4141

42-
while(i--) {
42+
while (i--) {
4343
led1 = !led1;
4444
wait_us(wait_time);
4545
}
@@ -52,7 +52,7 @@ void get_cpu_usage()
5252
mbed_stats_cpu_get(&stats);
5353

5454
uint64_t diff = (stats.idle_time - prev_idle_time);
55-
uint8_t usage = 100 - ((diff * 100) / (SAMPLE_TIME*1000));
55+
uint8_t usage = 100 - ((diff * 100) / (SAMPLE_TIME * 1000));
5656
prev_idle_time = stats.idle_time;
5757

5858
TEST_ASSERT_NOT_EQUAL(0, usage);

hal/mbed_sleep_manager.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,48 +31,41 @@
3131

3232
// deep sleep locking counter. A target is allowed to deep sleep if counter == 0
3333
static uint16_t deep_sleep_lock = 0U;
34-
static uint64_t sleep_time = 0;
35-
static uint64_t deep_sleep_time = 0;
34+
static us_timestamp_t sleep_time = 0;
35+
static us_timestamp_t deep_sleep_time = 0;
3636

3737
#if defined(MBED_CPU_STATS_ENABLED) && defined(DEVICE_LOWPOWERTIMER)
3838
static ticker_data_t *sleep_ticker = NULL;
3939
#endif
4040

41-
static inline uint64_t read_us(void)
41+
static inline us_timestamp_t read_us(void)
4242
{
4343
#if defined(MBED_CPU_STATS_ENABLED) && defined(DEVICE_LOWPOWERTIMER)
4444
if (NULL == sleep_ticker) {
45-
sleep_ticker = (ticker_data_t*) get_lp_ticker_data();
45+
sleep_ticker = (ticker_data_t *)get_lp_ticker_data();
4646
}
4747
return ticker_read_us(sleep_ticker);
4848
#else
4949
return 0;
5050
#endif
5151
}
5252

53-
uint64_t mbed_time_idle(void)
53+
us_timestamp_t mbed_time_idle(void)
5454
{
55-
return (sleep_time+deep_sleep_time);
55+
return (sleep_time + deep_sleep_time);
5656
}
5757

58-
uint64_t mbed_uptime(void)
58+
us_timestamp_t mbed_uptime(void)
5959
{
60-
#if defined(MBED_CPU_STATS_ENABLED) && defined(DEVICE_LOWPOWERTIMER)
61-
if (NULL == sleep_ticker) {
62-
sleep_ticker = (ticker_data_t*) get_lp_ticker_data();
63-
}
64-
return ticker_read_us(sleep_ticker);
65-
#else
66-
return 0;
67-
#endif
60+
return read_us();
6861
}
6962

70-
uint64_t mbed_time_sleep(void)
63+
us_timestamp_t mbed_time_sleep(void)
7164
{
7265
return sleep_time;
7366
}
7467

75-
uint64_t mbed_time_deepsleep(void)
68+
us_timestamp_t mbed_time_deepsleep(void)
7669
{
7770
return deep_sleep_time;
7871
}
@@ -83,7 +76,7 @@ uint64_t mbed_time_deepsleep(void)
8376
#define STATISTIC_COUNT 10
8477

8578
typedef struct sleep_statistic {
86-
const char* identifier;
79+
const char *identifier;
8780
uint8_t count;
8881
} sleep_statistic_t;
8982

@@ -132,7 +125,7 @@ static void sleep_tracker_print_stats(void)
132125
}
133126
}
134127

135-
void sleep_tracker_lock(const char* const filename, int line)
128+
void sleep_tracker_lock(const char *const filename, int line)
136129
{
137130
sleep_statistic_t *stat = sleep_tracker_find(filename);
138131

@@ -196,7 +189,7 @@ void sleep_manager_sleep_auto(void)
196189
sleep_tracker_print_stats();
197190
#endif
198191
core_util_critical_section_enter();
199-
uint64_t start = read_us();
192+
us_timestamp_t start = read_us();
200193
bool deep = false;
201194

202195
// debug profile should keep debuggers attached, no deep sleep allowed
@@ -211,8 +204,8 @@ void sleep_manager_sleep_auto(void)
211204
}
212205
#endif
213206

214-
uint64_t end = read_us();
215-
if(true == deep) {
207+
us_timestamp_t end = read_us();
208+
if (true == deep) {
216209
deep_sleep_time += end - start;
217210
} else {
218211
sleep_time += end - start;

platform/mbed_power_mgmt.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "sleep_api.h"
2727
#include "mbed_toolchain.h"
28+
#include "hal/ticker_api.h"
2829
#include <stdbool.h>
2930

3031
#ifdef __cplusplus
@@ -206,31 +207,33 @@ static inline void system_reset(void)
206207
NVIC_SystemReset();
207208
}
208209

209-
/** Provides the time spent in sleep mode, since system is up and running
210+
/** Provides the time spent in sleep mode since boot.
210211
*
211212
* @return Time spent in sleep
213+
* @note Works only if platform supports LP ticker.
212214
*/
213-
uint64_t mbed_time_sleep(void);
215+
us_timestamp_t mbed_time_sleep(void);
214216

215-
/** Provides the time spent in deep sleep mode, since system is up and running
217+
/** Provides the time spent in deep sleep mode since boot.
216218
*
217219
* @return Time spent in deep sleep
220+
* @note Works only if platform supports LP ticker.
218221
*/
219-
uint64_t mbed_time_deepsleep(void);
222+
us_timestamp_t mbed_time_deepsleep(void);
220223

221-
/** Provides the time spent in idle thread since the system is up
224+
/** Provides the time spent in idle mode since boot.
222225
*
223226
* @return Idle thread time.
227+
* @note Works only if platform supports LP ticker.
224228
*/
225-
uint64_t mbed_time_idle(void);
229+
us_timestamp_t mbed_time_idle(void);
226230

227-
228-
/** Provides the time since the system is up and running
231+
/** Provides the time since the system is up i.e. boot.
229232
*
230233
* @return System uptime.
234+
* @note Works only if platform supports LP ticker.
231235
*/
232-
uint64_t mbed_uptime(void);
233-
236+
us_timestamp_t mbed_uptime(void);
234237

235238
#ifdef __cplusplus
236239
}

platform/mbed_stats.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define MBED_STATS_H
2525
#include <stdint.h>
2626
#include <stddef.h>
27+
#include "hal/ticker_api.h"
2728

2829
#ifdef __cplusplus
2930
extern "C" {
@@ -87,10 +88,10 @@ size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count);
8788
* struct mbed_stats_cpu_t definition
8889
*/
8990
typedef struct {
90-
uint64_t uptime; /**< Time since system is up and running */
91-
uint64_t idle_time; /**< Time spent in idle thread since system is up and running */
92-
uint64_t sleep_time; /**< Time spent in sleep since system is up and running */
93-
uint64_t deep_sleep_time; /**< Time spent in deep sleep since system is up and running */
91+
us_timestamp_t uptime; /**< Time since system is up and running */
92+
us_timestamp_t idle_time; /**< Time spent in idle thread since system is up and running */
93+
us_timestamp_t sleep_time; /**< Time spent in sleep since system is up and running */
94+
us_timestamp_t deep_sleep_time; /**< Time spent in deep sleep since system is up and running */
9495
} mbed_stats_cpu_t;
9596

9697
/**

0 commit comments

Comments
 (0)