Skip to content

Commit d6f57bc

Browse files
committed
Fix review comments and merge issues
1 parent 206cc29 commit d6f57bc

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

hal/mbed_sleep_manager.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "mbed_critical.h"
2020
#include "sleep_api.h"
2121
#include "mbed_error.h"
22+
#include "mbed_debug.h"
2223
#include <limits.h>
2324
#include <stdio.h>
2425

@@ -30,7 +31,7 @@ static uint16_t deep_sleep_lock = 0U;
3031
#ifdef MBED_SLEEP_TRACING_ENABLED
3132

3233
// Length of the identifier extracted from the driver name to store for logging.
33-
#define IDENTIFIER_WIDTH 7
34+
#define IDENTIFIER_WIDTH 15
3435
// Number of drivers that can be stored in the structure
3536
#define STATISTIC_COUNT 10
3637

@@ -90,14 +91,14 @@ static sleep_statistic_t* sleep_tracker_add(const char* const filename)
9091
}
9192
}
9293

93-
// Panic if there are no free indexes left to track with
94-
error("No free indexes left to use in mbed stats tracker");
94+
debug("No free indexes left to use in mbed sleep tracker.\r\n");
9595

9696
return NULL;
9797
}
9898

9999
static void sleep_tracker_print_stats(void)
100100
{
101+
debug("Sleep locks held:\r\n");
101102
for (int i = 0; i < STATISTIC_COUNT; ++i) {
102103
if (sleep_stats[i].count == 0) {
103104
continue;
@@ -107,7 +108,7 @@ static void sleep_tracker_print_stats(void)
107108
return;
108109
}
109110

110-
printf("[id: %s, count: %u]\r\n", sleep_stats[i].identifier,
111+
debug("[id: %s, count: %u]\r\n", sleep_stats[i].identifier,
111112
sleep_stats[i].count);
112113
}
113114
}
@@ -120,12 +121,12 @@ void sleep_tracker_lock(const char* const filename, int line)
120121

121122
// Entry for this driver does not exist, create one.
122123
if (stat == NULL) {
123-
stat = sleep_tracker_add(filename);
124+
stat = sleep_tracker_add(stripped_path);
124125
}
125126

126127
core_util_atomic_incr_u8(&stat->count, 1);
127128

128-
printf("LOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, line, deep_sleep_lock);
129+
debug("LOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, line, deep_sleep_lock);
129130
}
130131

131132
void sleep_tracker_unlock(const char* const filename, int line)
@@ -135,13 +136,13 @@ void sleep_tracker_unlock(const char* const filename, int line)
135136

136137
// Entry for this driver does not exist, something went wrong.
137138
if (stat == NULL) {
138-
error("Unlocking sleep for driver that was not previously locked.");
139+
debug("Unlocking sleep for driver that was not previously locked: %s, ln: %i\r\n", stripped_path, line);
140+
return;
139141
}
140142

141143
core_util_atomic_decr_u8(&stat->count, 1);
142144

143-
printf("UNLOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, line, deep_sleep_lock);
144-
sleep_tracker_print_stats();
145+
debug("UNLOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, line, deep_sleep_lock);
145146
}
146147

147148
#endif // MBED_SLEEP_TRACING_ENABLED
@@ -175,6 +176,9 @@ bool sleep_manager_can_deep_sleep(void)
175176

176177
void sleep_manager_sleep_auto(void)
177178
{
179+
#ifdef MBED_SLEEP_TRACING_ENABLED
180+
sleep_tracker_print_stats();
181+
#endif
178182
core_util_critical_section_enter();
179183
// debug profile should keep debuggers attached, no deep sleep allowed
180184
#ifdef MBED_DEBUG

platform/mbed_power_mgmt.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ extern "C" {
6363
* }
6464
* @endcode
6565
*/
66-
#ifdef SLEEP_PROFILING_ENABLED
66+
#ifdef MBED_SLEEP_TRACING_ENABLED
67+
68+
void sleep_tracker_lock(const char *const filename, int line);
69+
void sleep_tracker_unlock(const char *const filename, int line);
6770

6871
#define sleep_manager_lock_deep_sleep() \
6972
do \
@@ -79,18 +82,15 @@ extern "C" {
7982
sleep_tracker_unlock(__FILE__, __LINE__); \
8083
} while (0);
8184

82-
void sleep_tracker_lock(const char *const filename, int line);
83-
void sleep_tracker_unlock(const char *const filename, int line);
84-
8585
#else
8686

8787
#define sleep_manager_lock_deep_sleep() \
8888
sleep_manager_lock_deep_sleep_internal()
8989

9090
#define sleep_manager_unlock_deep_sleep() \
91-
sleep_manager_lock_deep_sleep_internal()
91+
sleep_manager_unlock_deep_sleep_internal()
9292

93-
#endif // SLEEP_PROFILING_ENABLED
93+
#endif // MBED_SLEEP_TRACING_ENABLED
9494

9595
/** Lock the deep sleep mode
9696
*

0 commit comments

Comments
 (0)