esp_wifi/
tasks.rs

1use crate::{
2    compat::timer_compat::TIMERS,
3    preempt::{task_create, yield_task},
4    time::systimer_count,
5};
6
7/// Initializes the `timer` task for the Wi-Fi driver.
8pub(crate) fn init_tasks() {
9    // schedule the timer task
10    task_create(timer_task, core::ptr::null_mut(), 8192);
11}
12
13/// Entry point for the timer task responsible for handling scheduled timer
14/// events.
15pub(crate) extern "C" fn timer_task(_param: *mut esp_wifi_sys::c_types::c_void) {
16    loop {
17        let current_timestamp = systimer_count();
18        let to_run = TIMERS.with(|timers| {
19            let to_run = unsafe { timers.find_next_due(current_timestamp) }?;
20
21            to_run.active = to_run.periodic;
22
23            if to_run.periodic {
24                to_run.started = current_timestamp;
25            }
26
27            Some(to_run.callback)
28        });
29
30        // run the due timer callback NOT in an interrupt free context
31        if let Some(to_run) = to_run {
32            trace!("trigger timer....");
33            to_run.call();
34            trace!("timer callback called");
35        } else {
36            yield_task();
37        }
38    }
39}