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

How to configure FREERTOS Tasks for the following description

Hi Everyone

My requirements are as follows

1. I am running 4 tasks using free rtos in which one measures the ADC , 2nd sends the adc data over BLE and 3rd check if the button is pressed or not and 4th sends the ADC data to LORA.

2. All my 4 tasks are running perfectly so far.

But i would like to have this feature in my code.

Whenever i press the button , the controller should come out of sleep mode and run the other 2 tasks of measuring adc and sending data over BLE.

As long as button is in low state(NOT PRESSED) ,the controller should remain in sleep mode and should not do anything.

My questions are

1. How to put the nrf52840 to Sleep mode ?

2. How to achieve the above described theory using FREERTOS Tasks.

3. Can i use mutexes and sempahores for the above theory?

4. What are the available Sleep modes on nrf52840.?

5. What are the functions to call to put nrf52840 to sleep modes?

Parents Reply
  • I know that but before that, I need to show the working with freertos tasks. I have attached the code snippet.

    void Battery_Level_Take_Reading(void)
    {
      
      vTaskSuspend(ble_task_handle);
      uint32_t iteration = 0;
      while (1)
    
      {
      
         {
            uint32_t i;
            for(iteration = 0;iteration <500; iteration++)
            {
              nrf_saadc_value_t result;
              uint32_t calc;
    
              if (nrfx_saadc_sample_convert(0, &result) != NRFX_SUCCESS)
              {
                NRF_LOG_INFO("ADC failure\r\n");
              }
              else
              {
            //    calc = result;
            //    calc *= NANOVOLTS_PER_BIT;
            //    calc /= MV_PER_NV; // Calc now contains the voltage in mV
    
                printf("ADC: %d\r\n", result);
          //      NRF_LOG_INFO("ADC: %d\r\n", result);
               }
               vTaskDelay(TASK_DELAY);
            }
            vTaskResume(ble_task_handle);
         }
    
      }
        
    }
    
    
    
    
    
     void advertising_start(void)
    {
        
    
        vTaskSuspend(adc1_task_handle);
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
    
        
        while(1)
      {
        
        printf(" ble task 1 \n");
       
    //    if(xSemaphoreTake(task_signal, portMAX_DELAY))
    
        {
          uint32_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
          APP_ERROR_CHECK(err_code);
    
          vTaskDelay(15000);
    
          vTaskResume(adc1_task_handle);
        }
       }
    }
    

Children
  • void Battery_Level_Take_Reading(void)
    {
      
      
      uint32_t iteration = 0;
      while (1)
    
      {
         
      
         {
    	     vTaskSuspend(ble_task_handle);
            uint32_t i;
            for(iteration = 0;iteration <500; iteration++)
            {
              nrf_saadc_value_t result;
              uint32_t calc;
    
              if (nrfx_saadc_sample_convert(0, &result) != NRFX_SUCCESS)
              {
                NRF_LOG_INFO("ADC failure\r\n");
              }
              else
              {
            //    calc = result;
            //    calc *= NANOVOLTS_PER_BIT;
            //    calc /= MV_PER_NV; // Calc now contains the voltage in mV
    
                printf("ADC: %d\r\n", result);
          //      NRF_LOG_INFO("ADC: %d\r\n", result);
               }
               vTaskDelay(TASK_DELAY);
            }
            vTaskResume(ble_task_handle);
         }
    
      }
        
    }
    
    
    
    
    
     void advertising_start(void)
    {
        
    
        
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
    
        
        while(1)
      {
        
        printf(" ble task 1 \n");
       
    //    if(xSemaphoreTake(task_signal, portMAX_DELAY))
    
        {
    	  vTaskSuspend(adc1_task_handle);
          uint32_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
          APP_ERROR_CHECK(err_code);
    
          vTaskDelay(15000);
    
          vTaskResume(adc1_task_handle);
        }
       }
    }
    

    Try with this one

  • No. Now its continuously performing the battery that is adc task.

  • void Battery_Level_Take_Reading(void)
    {


    uint32_t iteration = 0;
    while (1)

    {
    vTaskSuspend(ble_task_handle);

    {

    uint32_t i;
    for(iteration = 0;iteration <500; iteration++)
    {
    nrf_saadc_value_t result;
    uint32_t calc;

    if (nrfx_saadc_sample_convert(0, &result) != NRFX_SUCCESS)
    {
    NRF_LOG_INFO("ADC failure\r\n");
    }
    else
    {
    // calc = result;
    // calc *= NANOVOLTS_PER_BIT;
    // calc /= MV_PER_NV; // Calc now contains the voltage in mV

    printf("ADC: %d\r\n", result);
    // NRF_LOG_INFO("ADC: %d\r\n", result);
    }
    vTaskDelay(TASK_DELAY);
    }

    }
    vTaskResume(ble_task_handle);
    }

    }

    void advertising_start(void)
    {


    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();


    while(1)
    {

    printf(" ble task 1 \n");
    vTaskSuspend(adc1_task_handle);
    // if(xSemaphoreTake(task_signal, portMAX_DELAY))

    {

    uint32_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);

    vTaskDelay(15000);


    }
    vTaskResume(adc1_task_handle);
    }
    }

    Try with this one , but i guess this is also possible using semaphores 
    Sorry , its been a while since i worked with freertos so couldn't offer much help Disappointed

  • No. Disappointedit's still the same. Its k whatever help you have done so far is also worth it. Thank you soo much.

  • I think you can create a global semaphore (only at boot) and use that to run the tasks 

    It will work this way

Related