This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

What happens if handlers are called at the same time? (nrf51422)

Hi,

I am new to firmware engineering. I have a simple and basic question.

If there's Timer A and B, and both interval is 100ms, what happens to the timeout handler functions? If both timers start at the same time then also the predefined timeout handler functions will be called at every same, right? If it's right, how does nrf51422(s130) handle this situation? Does it runs only one handler? Or both?

define A_TIMER_INTERVAL APP_TIMER_TICKS(100,APP_TIMER_PRESCALER)

define B_TIMER_INTERVAL APP_TIMER_TICKS(100,APP_TIMER_PRESCALER)

APP_TIMER_DEF(A_timer_id);

APP_TIMER_DEF(B_timer_id);

static void A_timeout_handler(void * p_context) {/* some codes */}

static void B_timeout_handler(void * p_context) {/* some codes */}

app_timer_create(&A_timer_id,APP_TIMER_MODE_REPEATED,A_timeout_handler);

app_timer_create(&B_timer_id,APP_TIMER_MODE_REPEATED,B_timeout_handler);

app_timer_start(A_timer_id,A_TIMER_INTERVAL,NULL);

app_timer_start(B_timer_id,B_TIMER_INTERVAL,NULL);

Parents
  • In such scenario:

    A_timeout_handler will be called every 100ms - timer interval is counted between function calls.

    B_timer will be called also every 100ms but with 50ms offset to A_timeout_handler due to blocking time in A_timeout_handler.

    So at the end LED will be blinking every 100ms.

  • I really appreciate your kind answer! I have one last question and hope it won't bother you... If these handlers are defined like this,

    "static void A_timeout_handler(void * p_context) { complicated_task_A();}

    static void B_timeout_handler(void * p_context) { complicated_task_B(); }"

    and assuming these "tasks" are so complicated that it will take a some time to be done, these tasks will never be run at the same time? Does task_B always be start after the task_A is done? Is it not possible to play music and blink lights at the same time when mcu is single core?

    Thank you for reading this article written in nasty grammar. I am really looking forward for your answer.

Reply
  • I really appreciate your kind answer! I have one last question and hope it won't bother you... If these handlers are defined like this,

    "static void A_timeout_handler(void * p_context) { complicated_task_A();}

    static void B_timeout_handler(void * p_context) { complicated_task_B(); }"

    and assuming these "tasks" are so complicated that it will take a some time to be done, these tasks will never be run at the same time? Does task_B always be start after the task_A is done? Is it not possible to play music and blink lights at the same time when mcu is single core?

    Thank you for reading this article written in nasty grammar. I am really looking forward for your answer.

Children
No Data
Related