28
28
#include "platform/mbed_wait_api.h"
29
29
30
30
#include <stdio.h>
31
+ #ifdef MBED_SLEEP_TRACING_ENABLED
32
+ #include <string.h>
33
+ #endif
31
34
32
35
#if DEVICE_SLEEP
33
36
@@ -138,19 +141,27 @@ static sleep_statistic_t *sleep_tracker_add(const char *const filename)
138
141
139
142
static void sleep_tracker_print_stats (void )
140
143
{
141
- mbed_error_printf ("Sleep locks held:\r\n" );
142
- for (int i = 0 ; i < STATISTIC_COUNT ; ++ i ) {
143
- if (sleep_stats [i ].count == 0 ) {
144
- continue ;
145
- }
146
-
147
- if (sleep_stats [i ].identifier [0 ] == '\0' ) {
148
- return ;
144
+ if (sleep_manager_can_deep_sleep ()) {
145
+ mbed_error_printf ("deepsleep unlocked" );
146
+ #ifdef MBED_DEBUG
147
+ mbed_error_printf (" but disabled with MBED_DEBUG" );
148
+ #endif
149
+ } else {
150
+ mbed_error_printf ("deepsleep locked by:" );
151
+ for (int i = 0 ; i < STATISTIC_COUNT ; ++ i ) {
152
+ if (sleep_stats [i ].count == 0 ) {
153
+ continue ;
154
+ }
155
+
156
+ if (sleep_stats [i ].identifier [0 ] == '\0' ) {
157
+ return ;
158
+ }
159
+
160
+ mbed_error_printf (" [%s x %u]" , sleep_stats [i ].identifier ,
161
+ sleep_stats [i ].count );
149
162
}
150
-
151
- mbed_error_printf ("[id: %s, count: %u]\r\n" , sleep_stats [i ].identifier ,
152
- sleep_stats [i ].count );
153
163
}
164
+ mbed_error_printf ("\r\n" );
154
165
}
155
166
156
167
void sleep_tracker_lock (const char * const filename , int line )
@@ -164,7 +175,9 @@ void sleep_tracker_lock(const char *const filename, int line)
164
175
165
176
core_util_atomic_incr_u8 (& stat -> count , 1 );
166
177
178
+ #if MBED_CONF_PLATFORM_DEEPSLEEP_STATS_VERBOSE
167
179
mbed_error_printf ("LOCK: %s, ln: %i, lock count: %u\r\n" , filename , line , deep_sleep_lock );
180
+ #endif
168
181
}
169
182
170
183
void sleep_tracker_unlock (const char * const filename , int line )
@@ -179,7 +192,9 @@ void sleep_tracker_unlock(const char *const filename, int line)
179
192
180
193
core_util_atomic_decr_u8 (& stat -> count , 1 );
181
194
195
+ #if MBED_CONF_PLATFORM_DEEPSLEEP_STATS_VERBOSE
182
196
mbed_error_printf ("UNLOCK: %s, ln: %i, lock count: %u\r\n" , filename , line , deep_sleep_lock );
197
+ #endif
183
198
}
184
199
185
200
#endif // MBED_SLEEP_TRACING_ENABLED
0 commit comments