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
  • Hi,

    about the sleep mode i think that the FREERTOS when no tasks are running is in idle task mode and that the idle taks is already in the deepest sleep mode (maybe nordic guys can confirm that).

    I think that you could solve this issue using binary semaphores. You can check this video https://www.youtube.com/watch?v=grXuVMttVuU on how to use them. It could look like that:

    xSemaphoreHandle button_signal = 0;
    xSemaphoreHandle adc_signal = 0;
    
    void button_interrupt_handler(){
        xSemaphoreGiveFromISR(button_signal);
    }
    
    void adc_task(void *p){
        while (1){
            if(xSemaphoreTake(button_signal, portMAX_DELAY)) {
    	        //do the staff
        	    xSemaphoreGive(adc_signal);
    	    }
        }
    }
    
    void ble_task(void *p){
        while (1){
            if(xSemaphoreTake(adc_signal, portMAX_DELAY)) {
    	        //do the staff
    	    }
        }
    }

Reply
  • Hi,

    about the sleep mode i think that the FREERTOS when no tasks are running is in idle task mode and that the idle taks is already in the deepest sleep mode (maybe nordic guys can confirm that).

    I think that you could solve this issue using binary semaphores. You can check this video https://www.youtube.com/watch?v=grXuVMttVuU on how to use them. It could look like that:

    xSemaphoreHandle button_signal = 0;
    xSemaphoreHandle adc_signal = 0;
    
    void button_interrupt_handler(){
        xSemaphoreGiveFromISR(button_signal);
    }
    
    void adc_task(void *p){
        while (1){
            if(xSemaphoreTake(button_signal, portMAX_DELAY)) {
    	        //do the staff
        	    xSemaphoreGive(adc_signal);
    	    }
        }
    }
    
    void ble_task(void *p){
        while (1){
            if(xSemaphoreTake(adc_signal, portMAX_DELAY)) {
    	        //do the staff
    	    }
        }
    }

Children
Related