Condition review task

With the changes I suggested, the dk_task will only run when it gets a notification from uart_task which is at most once in 200 ms. You need to find out what is blocking your Bluetooth task. How did you determine that the bluetooth task is blocked? Can you break in the debugger and see what it is doing when it appears blocked?

I can’t see where the program is blocked, that’s my biggest problem right now, I determined the blocked Bluetooth task is because I can’t see and connect to Bluetooth.
Thank you!

I can’t see where the program is blocked, that’s my biggest problem right now

I’d highly recommend breaking out a debugger as @aggarg has recommended. This should allow you to see the FreeRTOS task states (at best) or at least the current executing task (at worst).

In short the behavior you’re looking for is something like the following, right?

  • UART task fires and calls adc_single_channel_process to update the ADC sample
  • Bluetooth task then pushes the updated value over the BLE connection.

The way to accomplish this is to have the UART task, which is controlling the ADC sampling signal to the BLE task when the ADC sample is updated. This can be done in the UART task as Gaurav has shown above. Your BLE task will then need to be blocking on the ADC sample update. When it receives the sample update signal through xTaskNotifyTake - it would then be swapped in by the FreeRTOS scheduler and allowed to run. You can send this data over the BLE connection and return to blocking (xTaskNotifyTake) which will allow FreeRTOS to swap in the UART task.

Then to summarize how you need to set things up:

  • Your BLE task needs to have a higher priority than your UART task
  • Your BLE task when unblocked will do it’s work and then block/wait once again using xTaskNotifyTake.
  • Your UART task will notify the BLE task when the ADC sample is updated using xTaskNotifyGive

Below is a bit of pseudo-code which explains my thinking…

The UART Task

void uart_task( void * arg )
{
    for( ;; )
    {
      xSampleADCAndStoreValue(); //Samples the ADC and stores the value to shared variable/memory location which can be used by the BLE task.
      xTaskNotifyGive(bleTaskHandle); //Notify the BLE task that the update is completed
    }
}

The BLE Task

void ble_task( void * arg )
{
   bleOneTimeSetupCodeHere(); //Whatever one time code you need to establish the BLE connection
    for( ;; )
    {
      xTaskNotifyTake(); //Notify the BLE task that the update is completed
      sendADCValueOverBLE();
     //any other work you want here
    }
}

Task creation

TaskHandle_t uart_task_handle;
TaskHandle_t ble_task_handle;
uart_task_result = xTaskCreate( uart_task,
                               "UART",
                               UART_TASK_STACK_SIZE,
                               NULL,
                               1, //Or BLE_TASK_PRIORITY - 1
                               &( uart_task_handle ) );

ble_task_result = xTaskCreate( ble_task,
                               "BLE",
                               BLE_TASK_STACK_SIZE,
                               NULL,
                               2, //Or BLE_TASK_PRIORITY - 1
                               &( ble_task_handle ) );

Thank you for calling this idea!
The task that I am looking for is exactly:
UART action triggers and calls ADC model update, model DHT11
The Bluetooth action will then push the updated value over the BLE connection.
However, BLE is big task it is not seen as a task, it is a program and the tasks to serve it.

I built according to your suggestion, is it reasonable or not?
Thanks!

You just should try it yourself and verify if it meets your requirements.
(I don’t understand why there so many delays. I think the delay at the end of the sensor loop is sufficient if you want a common poll interval for all sensors.)

1 Like

Thank you for the information.
Can you tell me that functions like:
sendADCValueOverBLE();
xSampleADCAndStoreValue();
bleOneTimeSetupCodeHere();
What are they? and where they are in the API reference: FreeRTOS API categories. I can’t find them, I get quite a few errors about them.

These functions are indeed not part of FreeRTOS. Instead they are part of the application code.

Can you tell me what and where they are?
Thank you!

…no, it’s your code, right :wink: I’ve no idea about your application.
Good luck !

I don’t mean the components that Kstribrn above showed me!

What I’m talking about here!

As @kstribrn mentioned these functions are pseudo-code YOU have to implement.

I don’t know how to describe what I need for you to understand!
But roughly I need something like an API reference to understand it better!

Google is your friend :slight_smile: Easy to find:

Again good luck :+1:t2:

2 Likes

@Huydep_1 sorry for the confusion. The functions below are completely made up. I named them so you would get a sense of what application would do. I also put comments next to them to give some hint of what you’d probably want to do.

  • sendADCValueOverBLE(); - would be whatever code or function call you need to send the data value over the Bluetooth connection.
  • xSampleADCAndStoreValue();- would be whatever code would read your ADC value and store it to the accessible variable. This variable would be used later to access the value to send over Bluetooth
  • bleOneTimeSetupCodeHere(); - would be whatever BLE setup calls you need to make. These calls would establish the BLE connection so that you can later send the data.

Basically the purpose of the pseudo code was to show you how you could lay out your code so that your application could behave as desired. I wouldn’t take what I wrote as working, implemented code for your use case.

There are 2 sets of APIs at play here.

There are your application APIs. These include your BLE library (no idea what you’re using), any other libraries (once again no idea what you’re using), and functions you’ve written (really no idea what you’re using). We cannot supply an API reference for any of these.

As for the FreeRTOS APIs, please refer to the link @hs2 has posted. This webpage lists all FreeRTOS APIs and gives information on things like task creation+control, delays (blocking and otherwise), and notifications. For information on how to use these, please see the link @aggarg has posted earlier which explains many FreeRTOS fundamentals.

Best of luck with your development - and remember, take it a small step at a time. It’s almost always better to start with a simple blinky demo, which there are many and building out from there :slight_smile:

Thank you for this!
Last time I really didn’t understand what those codes were, but now I understand what they are!

I would like to answer your questions:
My BLE library uses HAL API for all applications like BLUETOOTH communication and sensor reading, my function is to use PSoC 063 BLE to read DHT11 sensor and soil moisture sensor values and send The data is read over the mobile via Bluetooth LE connection. I use Modus Toolbox’s HAL API to do all of the above.

Thank you!