# Condition review task

**URL:** <https://forums.freertos.org/t/condition-review-task/17144>\
**Category:** Kernel\
**Tags:** tutorial\
**Created:** [April 4, 2023, 4:40pm UTC](https://forums.freertos.org/t/condition-review-task/17144 "2023-04-04T16:40:46Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![Huydep\_1](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@Huydep\_1](https://forums.freertos.org/u/Huydep_1)\
**Post date:** [April 11, 2023, 8:17am UTC](https://forums.freertos.org/t/condition-review-task/17144/45 "2023-04-11T08:17:30Z")

</div>

Here is my raw project:  
_Link Removed_

---

<div class="post-metadata">

**Author:** ![kstribrn](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/kstribrn/32/6511_2.png) [@kstribrn](https://forums.freertos.org/u/kstribrn)\
**Post date:** [April 11, 2023, 4:06pm UTC](https://forums.freertos.org/t/condition-review-task/17144/46 "2023-04-11T16:06:21Z")

</div>

@Huydep_1 - Thanks for being so transparent and posting your code. I tried accessing the link but it prompted me to sign in. I’ve taken down this link to prevent users from logging into this site. I have no way of ensuring the login information is used correctly and I don’t want others to have compromised login credentials.

---

<div class="post-metadata">

**Author:** ![kstribrn](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/kstribrn/32/6511_2.png) [@kstribrn](https://forums.freertos.org/u/kstribrn)\
**Post date:** [April 11, 2023, 4:07pm UTC](https://forums.freertos.org/t/condition-review-task/17144/47 "2023-04-11T16:07:45Z")

</div>

> 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.

And thanks for this description! Sounds like you’re off to a great start 🙂

I’ll let you get to it. If you have further questions feel free to comment on this post or create a new post.

---

<div class="post-metadata">

**Author:** ![Huydep\_1](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@Huydep\_1](https://forums.freertos.org/u/Huydep_1)\
**Post date:** [April 11, 2023, 5:07pm UTC](https://forums.freertos.org/t/condition-review-task/17144/48 "2023-04-11T17:07:10Z")

</div>

Thank you for helping me!

---

<div class="post-metadata">

**Author:** ![Huydep\_1](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@Huydep\_1](https://forums.freertos.org/u/Huydep_1)\
**Post date:** [April 11, 2023, 5:25pm UTC](https://forums.freertos.org/t/condition-review-task/17144/49 "2023-04-11T17:25:36Z")

</div>

I followed your instructions and I referenced some similar examples on Github, I was able to connect to my Bluetooth. However, my event reading function still doesn’t work  
Here is all my code involved.

 ![12](https://d2v6vdsk2p900z.cloudfront.net/original/2X/c/c69e8cced25ff2c5ee223fba26973c2a61dc204a.jpeg)

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [April 12, 2023, 5:04am UTC](https://forums.freertos.org/t/condition-review-task/17144/50 "2023-04-12T05:04:02Z")

</div>

What are the priority of these tasks? How is `cyhal_system_delay` implemented? Try changing it to `vTaskDelay(pdMS_TO_TICKS(200));`.

---

<div class="post-metadata">

**Author:** ![Huydep\_1](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@Huydep\_1](https://forums.freertos.org/u/Huydep_1)\
**Post date:** [April 12, 2023, 5:07am UTC](https://forums.freertos.org/t/condition-review-task/17144/51 "2023-04-12T05:07:24Z")

</div>

I tried to change but why my program still doesn’t read the condition but it still executes the program while checking the condition is not true?

---

<div class="post-metadata">

**Author:** ![Huydep\_1](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@Huydep\_1](https://forums.freertos.org/u/Huydep_1)\
**Post date:** [April 12, 2023, 5:11am UTC](https://forums.freertos.org/t/condition-review-task/17144/52 "2023-04-12T05:11:24Z")

</div>

The led at pin P7\_1 stays on while the condition I set is 80 and what I read is 75?

---

<div class="post-metadata">

**Author:** ![Huydep\_1](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@Huydep\_1](https://forums.freertos.org/u/Huydep_1)\
**Post date:** [April 12, 2023, 6:55am UTC](https://forums.freertos.org/t/condition-review-task/17144/53 "2023-04-12T06:55:03Z")

</div>

I have checked the ADC’s condition but the DHT11’s condition I still can’t execute it!

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [April 12, 2023, 7:10am UTC](https://forums.freertos.org/t/condition-review-task/17144/54 "2023-04-12T07:10:37Z")

</div>

I don’t understand why the `uart_task` and the `ble_task` both access the sensors concurrently. That’s probably a problem and also seems to make no sense.  
What’s the purpose of the uart\_task ?  
Where are the ‘notification’ flags set/reset ?  
Did you define `configASSERT` and [enabled stack checking](https://www.freertos.org/Stacks-and-stack-overflow-checking.html?_ga=2.152686073.136317010.1674028012-1295978378.1669191309) ?  
What’s the size of the task stacks ?  
As @aggarg already recommended get rid of `cyhal_system_delay` and use `vTaskDelay`.

---

<div class="post-metadata">

**Author:** ![Huydep\_1](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@Huydep\_1](https://forums.freertos.org/u/Huydep_1)\
**Post date:** [April 12, 2023, 7:35am UTC](https://forums.freertos.org/t/condition-review-task/17144/55 "2023-04-12T07:35:32Z")

</div>

Because uart\_task is a function that sends read notifications, processes data from the kit to the mobile application.  
ble\_task is a task to handle Bluetooth connection and consider conditions to perform data sending function.  
Notification flags? What do you mean?  
I just configure and call it I haven’t found out through enabling stack inspection.  
The sizes of my stacks are:  
#define BLE\_TASK\_STACK\_SIZE ((configMINIMAL\_STACK\_SIZE \* 4 ))

#define BLE\_TASK\_PRIORITY ((configMAX\_PRIORITIES - 1 ))

#define UART\_TASK\_STACK\_SIZE ((configMINIMAL\_STACK\_SIZE \* 4 ))

#define UART\_TASK\_PRIORITY ((configMAX\_PRIORITIES - 2 ))

#define DK\_TASK\_STACK\_SIZE ((configMINIMAL\_STACK\_SIZE \* 4))

#define DK\_TASK\_PRIORITY ((configMAX\_PRIORITIES - 3 ))

I used vTaskDelay instead of cyhal\_system\_delay.  
Thank you.

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [April 12, 2023, 8:02am UTC](https://forums.freertos.org/t/condition-review-task/17144/56 "2023-04-12T08:02:22Z")

</div>

It seems odd to me that ble and uart\_task run the same sensor related code.

> [@Huydep\_1](#):
>
> Notification flags? What do you mean?

char\_ **notification** \_enabled, etc.

> [@Huydep\_1](#):
>
> I just configure and call it I haven’t found out through enabling stack inspection.

Sorry - I don’t understand this sentence.

But why not simply using the debugger and step through the code to see what’s going on ?

---

<div class="post-metadata">

**Author:** ![Huydep\_1](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@Huydep\_1](https://forums.freertos.org/u/Huydep_1)\
**Post date:** [April 12, 2023, 8:16am UTC](https://forums.freertos.org/t/condition-review-task/17144/57 "2023-04-12T08:16:45Z")

</div>

I also just created the task ble\_task as instructed above, in fact, there was only uart\_task at first

```auto
/* Notifications enabled */
uint8_t char_notification_enabled = 0;

uint8_t humidity_notification_enabled = 0;

uint8_t temperature_notification_enabled = 0;

void uart_task(void *arg)
{
for (;;)
{
if(char_notification_enabled == true)
{
/* Sample input voltage at channel 0 */
adc_single_channel_process();

xTaskNotifyGive(ble_task_handle);
xTaskNotifyGive(dk_task_handle);

adc_send_notification();
}

if(humidity_notification_enabled == true)
{
humidity_send_notification();
printf("\r\nHumidity = %.2f\r\n",DHT_read.humidity);
}

if(temperature_notification_enabled == true)
{
temperature_send_notification();
printf("\r\nTemperature = %.2f\r\n",DHT_read.temperature);
}

/* 200ms delay between scans */
vTaskDelay(pdMS_TO_TICKS(200));
}
}

```

I haven’t found out about the stack checking feature yet  
I tried using the debugger but it doesn’t detect the error!

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [April 12, 2023, 9:15am UTC](https://forums.freertos.org/t/condition-review-task/17144/58 "2023-04-12T09:15:14Z")

</div>

Are you aware that `uint8_t char_notification_enabled = 0;` means DISABLED because  
this and the other similar conditions `if(char_notification_enabled == true)` are never true ?  
Did you ever used a debugger ? It allows to set breakpoints and step through single lines of code to verify the code and correct program behavior.

---

<div class="post-metadata">

**Author:** ![Huydep\_1](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@Huydep\_1](https://forums.freertos.org/u/Huydep_1)\
**Post date:** [April 12, 2023, 10:31am UTC](https://forums.freertos.org/t/condition-review-task/17144/59 "2023-04-12T10:31:38Z")

</div>

I tried debugging it however, no problem at all!

---

<div class="post-metadata">

**Author:** ![Huydep\_1](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@Huydep\_1](https://forums.freertos.org/u/Huydep_1)\
**Post date:** [April 12, 2023, 10:33am UTC](https://forums.freertos.org/t/condition-review-task/17144/60 "2023-04-12T10:33:58Z")

</div>

You are probably right about this  
(Did you know that uint8\_t char\_notification\_enabled = 0; means STARTED)  
However, I understand it in a different way so for you that is when char\_notification\_enabled =0; means its value is equal to false;  
And when if(char\_notification\_enabled == 1) value of it by true;  
I may have misunderstood, please help me on this!  
Thank you!

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [April 12, 2023, 11:04am UTC](https://forums.freertos.org/t/condition-review-task/17144/61 "2023-04-12T11:04:02Z")

</div>

> [@Huydep\_1](#):
>
> (Did you know that uint8\_t char\_notification\_enabled = 0; means STARTED)

No - how should one know this secret meaning 😉  
I think it’s time to get _your_ hands dirty and solve your programming problems yourself.  
Take the chance to learn 👍 and maybe re-read the valuable hints the experts already provided to help you.  
Good luck !

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [April 12, 2023, 11:13am UTC](https://forums.freertos.org/t/condition-review-task/17144/62 "2023-04-12T11:13:46Z")

</div>

The OP shared the complete code here - [PSoC 6 BLE · Issue #1 · quochuy12345/huydep\_1 · GitHub](https://github.com/quochuy12345/huydep_1/issues/1)

There are following tasks -

1. DHT task - This task runs every 2 seconds and reads some sensors and updates some globals.
2. BLE task - This task send the sensors values updated by DHT task over BLE.
3. DK task - This task tuns on LED based on sensor values updated by DHT task.
4. Print task - This task prints sensor values updated by DHT task.
5. UART task - As @hs2 suggested, this task is duplicate of BLE task and is not needed.

I changed the priority of DHT task to the highest. BLE and DK tasks wait for notification from DHT task. I do not have the hardware and therefore, did not test these changes.

---

<div class="post-metadata">

**Author:** ![Huydep\_1](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@Huydep\_1](https://forums.freertos.org/u/Huydep_1)\
**Post date:** [April 13, 2023, 2:01am UTC](https://forums.freertos.org/t/condition-review-task/17144/64 "2023-04-13T02:01:59Z")

</div>

Thank you because information

---

<div class="post-metadata">

**Author:** ![Huydep\_1](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@Huydep\_1](https://forums.freertos.org/u/Huydep_1)\
**Post date:** [April 13, 2023, 2:03am UTC](https://forums.freertos.org/t/condition-review-task/17144/65 "2023-04-13T02:03:25Z")

</div>

I am so grateful for this!

[Previous page](https://forums.freertos.org/t/condition-review-task/17144.md?page=2)
