Condition review task

Hello everyone!
I am doing a project with PSoC 63 BLE and Modus Toolbox, I have DHT11 sensor data as temperature, humidity and soil moisture sensor data as soil moisture, I have initialized a task to review the conditions used to control the automatic motor from my PSoC 63 BLE kit as shown below. However, this task blocks my Bluetooth LE playback and it cannot perform the condition review! I am a beginner in FreeRTOS, hope anyone can help me.
Thank you guys!

456

Which will just run forever and never block to let other tasks run. It should be waiting for a signal from whatever is updating the adc_percent variable that it has changed.

What should I do to fix this?

As I said, the task should block until someone tells it that the value of the adc has been updated, and whatever updates that variable needs to send that signal when it gets a new value.

Ok, as you said it will run when the value is updated, but it interferes with the bluetooth playback of the program, resulting in the program’s ability to send notifications to enable read data functionality can now.

No, as written, it runs continuously and does’t give up the CPU to let other tasks of lower priority run.

The loop needs a call to block on something, like a Semaphore or and EventGroup.

Why do you think it only runs when the value is updated?

@richard-damon is right. Your task right now is continually running. You either need to block so that another task can run OR enable preemption. Considering your example case here sounds fairly simple - blocking is the way to go.

Your BLE task could update the motor position and then call xTaskNotifyWait for to wait for another task (the one updating the ADC value) to notify that the value has been modified since last read.

Your ADC update task would then just need to update the ADC value and call xTaskNotify. When no update occurs, the task notification doesn’t occur.

Thank you for your reply!
I think it will block my Bluetooth transmitter so it can perform my device control execution condition.

Thank you!
But I still haven’t figured out how the system will work as you say and the bigger problem is that I don’t know how to use them!

Do you have a specific example?

If you referring to how to use task notifications this page has an example usage of a task being notified from an ISR, which might be similar to your use case.

I’m trying to rely on the API to build the important problem is that I can’t quite understand what they do!
Thank you!

I do not understand you!

This is good resource about learning FreeRTOS fundamentals - https://www.freertos.org/fr-content-src/uploads/2018/07/161204_Mastering_the_FreeRTOS_Real_Time_Kernel-A_Hands-On_Tutorial_Guide.pdf

Where is adc_percent defined and where is it updated?

The code on the left is my ADC reading code
And the code on the right is the UART task that handles updating my data.

So, after updating the variable, it can signal the tasks that need to know that the value has changed.

And here is one way to do what @richard-damon suggested -

/* Obtain the task handle at the time of task creation. */
TaskHandle_t dk_task_handle;
rtos_api_result = xTaskCreate( dk_task,
                               "DK Task",
                               DK_TASK_STACK_SIZE,
                               NULL,
                               DK_TASK_PRIORITY,
                               &( dk_task_handle ) );

void uart_task( void * arg )
{
    for( ;; )
    {
        if( char_notification_enabled == true )
        {
            adc_single_channel_process();

            /* Signal the dk task. */
            xTaskNotifyGive( dk_task_handle );

            adc_send_notification();
        }

        if( humidity_notification_enabled == true )
        {
            humidity_send_notification();
        }

        if( temperature_notification_enabled == true )
        {
            temperature_send_notification();
        }

        /* 200ms delay between scans. */
        cyhal_system_delay_ms( 200 );
    }
}

void dk_task( void * pvParam )
{
    for( ;; )
    {
        /* Wait for a notification from the uart_task. */
        ulTaskNotifyTake( pdTRUE, portMAX_DELAY );

        if( adc_percent > dset)
        {
            cyhal_gpio_write( P7_1, true );
        }
        else
        {
            cyhal_gpio_write( P7_1, false );
        }
    }
}

I tried doing it as you suggested. However, it still has a situation where it blocks my Bluetooth task.
Thanks!

And that goes away when you do not create dk_task?

And dk_task is the task that takes the condition from uart_task to execute my engine control! if dk_task is removed, how can i check the condition to execute the motor control program without blocking the bluetooth task?
Thank you!