Skip to content

Commit 1492dc1

Browse files
authored
Merge pull request #9685 from scartmell-arm/fix-sleep-tracer-lookup-failing
Fix sleep tracing not finding matching driver during unlock.
2 parents f2abdcb + 3f12c19 commit 1492dc1

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

platform/mbed_sleep_manager.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,28 @@ us_timestamp_t mbed_time_deepsleep(void)
7373

7474
#ifdef MBED_SLEEP_TRACING_ENABLED
7575

76+
// Length of the identifier extracted from the driver name to store for logging.
77+
#define IDENTIFIER_WIDTH 15
78+
7679
// Number of drivers that can be stored in the structure
7780
#define STATISTIC_COUNT 10
7881

7982
typedef struct sleep_statistic {
80-
const char *identifier;
83+
char identifier[IDENTIFIER_WIDTH];
8184
uint8_t count;
8285
} sleep_statistic_t;
8386

8487
static sleep_statistic_t sleep_stats[STATISTIC_COUNT];
8588

8689
static sleep_statistic_t *sleep_tracker_find(const char *const filename)
8790
{
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
8896
for (int i = 0; i < STATISTIC_COUNT; ++i) {
89-
if (sleep_stats[i].identifier == filename) {
97+
if (strcmp(sleep_stats[i].identifier, temp) == 0) {
9098
return &sleep_stats[i];
9199
}
92100
}
@@ -96,9 +104,15 @@ static sleep_statistic_t *sleep_tracker_find(const char *const filename)
96104

97105
static sleep_statistic_t *sleep_tracker_add(const char *const filename)
98106
{
107+
char temp[IDENTIFIER_WIDTH];
108+
strncpy(temp, filename, IDENTIFIER_WIDTH);
109+
temp[IDENTIFIER_WIDTH - 1] = '\0';
110+
99111
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();
102116

103117
return &sleep_stats[i];
104118
}
@@ -117,7 +131,7 @@ static void sleep_tracker_print_stats(void)
117131
continue;
118132
}
119133

120-
if (sleep_stats[i].identifier == NULL) {
134+
if (sleep_stats[i].identifier[0] == '\0') {
121135
return;
122136
}
123137

0 commit comments

Comments
 (0)