@@ -73,20 +73,28 @@ us_timestamp_t mbed_time_deepsleep(void)
73
73
74
74
#ifdef MBED_SLEEP_TRACING_ENABLED
75
75
76
+ // Length of the identifier extracted from the driver name to store for logging.
77
+ #define IDENTIFIER_WIDTH 15
78
+
76
79
// Number of drivers that can be stored in the structure
77
80
#define STATISTIC_COUNT 10
78
81
79
82
typedef struct sleep_statistic {
80
- const char * identifier ;
83
+ char identifier [ IDENTIFIER_WIDTH ] ;
81
84
uint8_t count ;
82
85
} sleep_statistic_t ;
83
86
84
87
static sleep_statistic_t sleep_stats [STATISTIC_COUNT ];
85
88
86
89
static sleep_statistic_t * sleep_tracker_find (const char * const filename )
87
90
{
91
+ char temp [IDENTIFIER_WIDTH ];
92
+ strncpy (temp , filename , IDENTIFIER_WIDTH );
93
+ temp [IDENTIFIER_WIDTH - 1 ] = '\0' ;
94
+
95
+ // Search for the a driver matching the current name and return it's index
88
96
for (int i = 0 ; i < STATISTIC_COUNT ; ++ i ) {
89
- if (sleep_stats [i ].identifier == filename ) {
97
+ if (strcmp ( sleep_stats [i ].identifier , temp ) == 0 ) {
90
98
return & sleep_stats [i ];
91
99
}
92
100
}
@@ -96,9 +104,15 @@ static sleep_statistic_t *sleep_tracker_find(const char *const filename)
96
104
97
105
static sleep_statistic_t * sleep_tracker_add (const char * const filename )
98
106
{
107
+ char temp [IDENTIFIER_WIDTH ];
108
+ strncpy (temp , filename , IDENTIFIER_WIDTH );
109
+ temp [IDENTIFIER_WIDTH - 1 ] = '\0' ;
110
+
99
111
for (int i = 0 ; i < STATISTIC_COUNT ; ++ i ) {
100
- if (sleep_stats [i ].identifier == NULL ) {
101
- sleep_stats [i ].identifier = filename ;
112
+ if (sleep_stats [i ].identifier [0 ] == '\0' ) {
113
+ core_util_critical_section_enter ();
114
+ strncpy (sleep_stats [i ].identifier , temp , sizeof (temp ));
115
+ core_util_critical_section_exit ();
102
116
103
117
return & sleep_stats [i ];
104
118
}
@@ -117,7 +131,7 @@ static void sleep_tracker_print_stats(void)
117
131
continue ;
118
132
}
119
133
120
- if (sleep_stats [i ].identifier == NULL ) {
134
+ if (sleep_stats [i ].identifier [ 0 ] == '\0' ) {
121
135
return ;
122
136
}
123
137
0 commit comments