Skip to content

Commit f412add

Browse files
committed
fix(cam_hal): throttle WARN spam so cam_verify_jpeg_soi reduces it's stack footprint
* First occurrence of each warning: ESP_DRAM_LOGW() → zero stack after the first print. * Subsequent occurrences: count with a uint16_t and emit a **literal** ESP_LOGW() only every 100th event (~ 60 B stack usage). * Counters auto-reset at 10 000 to avoid wraparound.
1 parent 711b572 commit f412add

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

driver/cam_hal.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,32 @@
4242
static const char *TAG = "cam_hal";
4343
static cam_obj_t *cam_obj = NULL;
4444

45+
/* helper to throttle repeated warnings */
46+
#define CAM_WARN_THROTTLE(first) \
47+
do { \
48+
if ((warn_soi_miss_cnt) == 0) { \
49+
ESP_DRAM_LOGW(TAG, first); \
50+
} \
51+
if (++(warn_soi_miss_cnt) % 100 == 0) { \
52+
ESP_LOGW(TAG, "NO-SOI - 100 additional misses"); \
53+
} \
54+
if ((warn_soi_miss_cnt) >= 10000) { \
55+
ESP_LOGW(TAG, "NO-SOI - counter reset at 10000"); \
56+
(warn_soi_miss_cnt) = 0; \
57+
} \
58+
} while (0)
59+
4560
/* JPEG markers in little-endian order (ESP32). */
4661
static const uint8_t JPEG_SOI_MARKER[] = {0xFF, 0xD8, 0xFF}; /* SOI = FF D8 FF */
4762
static const uint16_t JPEG_EOI_MARKER = 0xD9FF; /* EOI = FF D9 */
4863

4964
static int cam_verify_jpeg_soi(const uint8_t *inbuf, uint32_t length)
5065
{
5166
const size_t soi_len = sizeof(JPEG_SOI_MARKER);
67+
static uint16_t warn_soi_miss_cnt;
5268

5369
if (length < soi_len) {
54-
ESP_LOGW(TAG, "NO-SOI");
70+
CAM_WARN_THROTTLE("NO-SOI - JPEG start marker missing (below 3 bytes in length)");
5571
return -1;
5672
}
5773

@@ -61,7 +77,8 @@ static int cam_verify_jpeg_soi(const uint8_t *inbuf, uint32_t length)
6177
return i;
6278
}
6379
}
64-
ESP_LOGW(TAG, "NO-SOI");
80+
81+
CAM_WARN_THROTTLE("NO-SOI - JPEG start marker missing");
6582
return -1;
6683
}
6784

0 commit comments

Comments
 (0)