Skip to content

Simple async routines enabled for timer subsystem#832

Draft
anacierdem wants to merge 1 commit intoDragonMinded:previewfrom
anacierdem:aync
Draft

Simple async routines enabled for timer subsystem#832
anacierdem wants to merge 1 commit intoDragonMinded:previewfrom
anacierdem:aync

Conversation

@anacierdem
Copy link
Copy Markdown
Collaborator

@anacierdem anacierdem commented Feb 25, 2026

Example usage:

#include <stdio.h>

#include <libdragon.h>

typedef struct
{
    async_state;
    timer_link_t *timer;
    int counter;
} task_state;

// This is still supported
void cb(int ovfl) {
    printf("ovfl %d\n", ovfl);
}

async task(void *pt)
{
    task_state *st = (task_state*) pt;
    async_begin(st);

    while(1) {
        st->timer = new_timer(TIMER_TICKS(1000000), TF_ONE_SHOT, cb);
        await(async_timer_expired(st->timer));
        printf("Count: %d\n", st->counter);
        st->counter++;
        delete_timer(st->timer);
    }

    async_end;
}

int main(void)
{
    console_init();
    timer_init();

    debug_init_usblog();
    console_set_debug(true);

    async_init();

    task_state pt = {};
    async_new(&pt);
    async_schedule(task, &pt);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant