How can I use my own scheduler with app_timer?

Hello everyone,

This might be a somewhat silly question. I'm trying to use SDK v17.1, and have an issue with the app_timer library.

I remember that before SDK v13 one would init app_timer with the APP_TIMER_INIT() macro, and there one should input the event scheduler, but now the macro has been removed, and the app_timer lib doesn't have a way to define a custom scheduler, as far as i know.

I have my own event scheduler in my code, it's a simple task queue, and back in SDK v11 I would use task_queue_post() to schedule the corresponding task.

uint32_t event_handler(app_timer_timeout_handler_t timeout_handler,
void * p_context)
{
return task_queue_post(timeout_handler, p_context);
}


// Initialize app_timer.
APP_TIMER_INIT(TIMER_PRESCALER, OP_QUEUES_SIZE, event_handler);

I was just wondering if someone could tell me how can i keep using my own task scheduler, since as far as i'm concerned one can use app_timer with app_scheduler, but I'd like to use my very own scheduler instead.

Thanks for your help

Parents
  • Hello,

    The app timer library was rewritten as app_timer2.  Unfortunately it no longer supports user provided scheduler functions. However, it can optionally be used with app_scheduler by enabling the APP_TIMER_CONFIG_USE_SCHEDULER setting in sdk_config.h. Is it an alternative to just add your tasks to your scheduler from the app timer interrupts instead?

    Best regards,

    Vidar

  • Hello,

    If i use it with app_scheduler, can i register my scheduler as a handler? or do i have to schedule my own scheduler as a task each time?

    Thanks,

    Julián

  • Hello Julián,

    Using app_scheduler() in addition to your own scheduler sounds  a bit excessive. Can you enqueue your scheduler tasks from the app timer timeout handlers instead (interrupt context)?

    Best regards,

    Vidar

  • Hello Vidar,

    Yes, I agree, it's a bit excessive. I'm now using app_scheduler, and my own, previous, scheduler now functions as a wrapper for app_scheduler so I don't have to change all my code. 

    However, I have a problem when using timers with the scheduler. Even though the timer interruptions function properly and I can get them to work normally, I keep getting events put into the schedule by the RTC (see image).



    At some point in my code, I need to check if there are tasks scheduled pending to be executed in order to decide if the code shall go on or keep cycling. Since RTC keeps putting events into the schedule, I can never get to see an empty task queue.

    I need to understand why this happens, and if there's any way to prevent it while still using app_timer with app_scheduler. I've read both libs documentation but there's no specification on this.

    Maybe it's my error on the configuration.

    By the way, is there some way to clear the schedule?

    Thanks,

    Julián

Reply
  • Hello Vidar,

    Yes, I agree, it's a bit excessive. I'm now using app_scheduler, and my own, previous, scheduler now functions as a wrapper for app_scheduler so I don't have to change all my code. 

    However, I have a problem when using timers with the scheduler. Even though the timer interruptions function properly and I can get them to work normally, I keep getting events put into the schedule by the RTC (see image).



    At some point in my code, I need to check if there are tasks scheduled pending to be executed in order to decide if the code shall go on or keep cycling. Since RTC keeps putting events into the schedule, I can never get to see an empty task queue.

    I need to understand why this happens, and if there's any way to prevent it while still using app_timer with app_scheduler. I've read both libs documentation but there's no specification on this.

    Maybe it's my error on the configuration.

    By the way, is there some way to clear the schedule?

    Thanks,

    Julián

Children
No Data
Related