| 154 | } |
| 155 | |
| 156 | bool AsyncLogger::enableBackgroundFlush(fl::u32 interval_ms, fl::size messages_per_tick) { |
| 157 | detail::BackgroundFlushState& state = Singleton<detail::BackgroundFlushState>::instance(); |
| 158 | |
| 159 | // If already enabled, disable first |
| 160 | if (state.mEnabled) { |
| 161 | disableBackgroundFlush(); |
| 162 | } |
| 163 | |
| 164 | // Configure flush parameters |
| 165 | state.mMessagesPerTick = messages_per_tick; |
| 166 | |
| 167 | // Setup ISR timer configuration |
| 168 | fl::isr::config config; |
| 169 | config.handler = detail::async_log_flush_timer_isr; |
| 170 | config.user_data = &state; |
| 171 | config.frequency_hz = 1000 / interval_ms; // Convert ms to Hz |
| 172 | config.priority = fl::isr::ISR_PRIORITY_LOW; // Low priority to avoid interfering with LED timing |
| 173 | config.flags = fl::isr::ISR_FLAG_IRAM_SAFE; |
| 174 | |
| 175 | // Attach timer ISR (returns 0 on success, negative on error) |
| 176 | if (fl::isr::attach_timer_handler(config, &state.mTimerHandle) != 0) { |
| 177 | return false; // Platform doesn't support timers or attachment failed |
| 178 | } |
| 179 | |
| 180 | state.mEnabled = true; |
| 181 | return true; |
| 182 | } |
| 183 | |
| 184 | void AsyncLogger::disableBackgroundFlush() { |
| 185 | detail::BackgroundFlushState& state = Singleton<detail::BackgroundFlushState>::instance(); |
no test coverage detected