Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3556

SDK • Re: RP2040 inter thread synchronisation

$
0
0
I just got confused because there's a DMA timer with that name, but that's not the case.

The main timer interrupts are actually related to ALARMs.
I think that SDK is using one alarm (from alarm pool) only on request by sleep functions.
I haven't seen them interfering with any timing, the core is put at sleep if possible, or is polling the timer (busy_wait) if not.
Unless something else is stealing and abusing it ...
4.2.11.4. sleep
Sleep functions for delaying execution in a lower power state.
4.2.11.4.1. Detailed Description
These functions allow the calling core to sleep. This is a lower powered sleep; waking and re-checking time on every
processor event (WFE)
These functions should not be called from an IRQ handler.
Lower powered sleep requires use of the default alarm pool which may be disabled by the
PICO_TIME_DEFAULT_ALARM_POOL_DISABLED #define or currently full in which case these functions become busy
waits instead.
Whilst sleep_ functions are preferable to busy_wait functions from a power perspective, the busy_wait equivalent
function may return slightly sooner after the target is reached.
add_alarm_at is doing it (one shot):

Code:

void sleep_until(absolute_time_t t) {#if PICO_ON_DEVICE && !defined(NDEBUG)    if (__get_current_exception()) {        panic("Attempted to sleep inside of an exception handler; use busy_wait if you must");    }#endif#if !PICO_TIME_DEFAULT_ALARM_POOL_DISABLED    uint64_t t_us = to_us_since_boot(t);    uint64_t t_before_us = t_us - PICO_TIME_SLEEP_OVERHEAD_ADJUST_US;    // needs to work in the first PICO_TIME_SLEEP_OVERHEAD_ADJUST_US of boot    if (t_before_us > t_us) t_before_us = 0;    absolute_time_t t_before;    update_us_since_boot(&t_before, t_before_us);    if (absolute_time_diff_us(get_absolute_time(), t_before) > 0) {        if (add_alarm_at(t_before, sleep_until_callback, NULL, false) >= 0) {            // able to add alarm for just before the time            while (!time_reached(t_before)) {                uint32_t save = spin_lock_blocking(sleep_notifier.spin_lock);                lock_internal_spin_unlock_with_wait(&sleep_notifier, save);            }        }    }#else    // hook in case we're in RTOS; note we assume using the alarm pool is better always if available.    sync_internal_yield_until_before(t);#endif    // now wait until the exact time    busy_wait_until(t);}

Statistics: Posted by gmx — Fri Sep 20, 2024 11:14 pm



Viewing all articles
Browse latest Browse all 3556

Trending Articles