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

Task getting preempted when it shouldn't be.

I'm using the basic sdk example of ble_app_hrs_freertos example and created two tasks in it, namely Task1 and Task2. Now I have enabled preemption by setting "configUSE_PREEMPTION 1" and here the time slicing is set to 0 "configUSE_TIME_SLICING 0".

Both the Task1 and Task2 have same priority which is 1. So according to FreeRtos documentation only Task1 should run because for two tasks with same priority and time slicing disabled the task1 should run without getting preempted.  I'm using a printf statement to check which task is running and BOTH task1 and task2 are running.

When I change the priority of both the task to 2, then it works fine. Only task1 is running and its not being preempted. Why does changing the priority fix this problem.

Here's the code that I added to basic sdk example

// Tasks initialization

 if (pdPASS != xTaskCreate(task1, "t1", 256, NULL, 1, &m_task1))
    {
        APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    }


 if (pdPASS != xTaskCreate(task2, "t2", 256, NULL, 1, &m_task2))
    {
        APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    }
    
    
// Task Implementation

static void task1(void * arg){

  while(1){
  printf("Task 1\n");
  nrf_delay_ms(100);
  }
}
static void task2(void * arg){

  while(1){
  printf("Task 2\n");
  nrf_delay_ms(100);
  }
}

Im also attaching the output 

Parents Reply Children
Related