19
19
#include "mbed_critical.h"
20
20
#include "sleep_api.h"
21
21
#include "mbed_error.h"
22
+ #include "mbed_debug.h"
22
23
#include <limits.h>
23
24
#include <stdio.h>
24
25
@@ -30,7 +31,7 @@ static uint16_t deep_sleep_lock = 0U;
30
31
#ifdef MBED_SLEEP_TRACING_ENABLED
31
32
32
33
// Length of the identifier extracted from the driver name to store for logging.
33
- #define IDENTIFIER_WIDTH 7
34
+ #define IDENTIFIER_WIDTH 15
34
35
// Number of drivers that can be stored in the structure
35
36
#define STATISTIC_COUNT 10
36
37
@@ -90,14 +91,14 @@ static sleep_statistic_t* sleep_tracker_add(const char* const filename)
90
91
}
91
92
}
92
93
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" );
95
95
96
96
return NULL ;
97
97
}
98
98
99
99
static void sleep_tracker_print_stats (void )
100
100
{
101
+ debug ("Sleep locks held:\r\n" );
101
102
for (int i = 0 ; i < STATISTIC_COUNT ; ++ i ) {
102
103
if (sleep_stats [i ].count == 0 ) {
103
104
continue ;
@@ -107,7 +108,7 @@ static void sleep_tracker_print_stats(void)
107
108
return ;
108
109
}
109
110
110
- printf ("[id: %s, count: %u]\r\n" , sleep_stats [i ].identifier ,
111
+ debug ("[id: %s, count: %u]\r\n" , sleep_stats [i ].identifier ,
111
112
sleep_stats [i ].count );
112
113
}
113
114
}
@@ -120,12 +121,12 @@ void sleep_tracker_lock(const char* const filename, int line)
120
121
121
122
// Entry for this driver does not exist, create one.
122
123
if (stat == NULL ) {
123
- stat = sleep_tracker_add (filename );
124
+ stat = sleep_tracker_add (stripped_path );
124
125
}
125
126
126
127
core_util_atomic_incr_u8 (& stat -> count , 1 );
127
128
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 );
129
130
}
130
131
131
132
void sleep_tracker_unlock (const char * const filename , int line )
@@ -135,13 +136,13 @@ void sleep_tracker_unlock(const char* const filename, int line)
135
136
136
137
// Entry for this driver does not exist, something went wrong.
137
138
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 ;
139
141
}
140
142
141
143
core_util_atomic_decr_u8 (& stat -> count , 1 );
142
144
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 );
145
146
}
146
147
147
148
#endif // MBED_SLEEP_TRACING_ENABLED
@@ -175,6 +176,9 @@ bool sleep_manager_can_deep_sleep(void)
175
176
176
177
void sleep_manager_sleep_auto (void )
177
178
{
179
+ #ifdef MBED_SLEEP_TRACING_ENABLED
180
+ sleep_tracker_print_stats ();
181
+ #endif
178
182
core_util_critical_section_enter ();
179
183
// debug profile should keep debuggers attached, no deep sleep allowed
180
184
#ifdef MBED_DEBUG
0 commit comments