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
9999static 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
131132void 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
176177void 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
0 commit comments