How to setup how long task will run?

Hello,

I need to count how many times I pressed the button in the task1 and using semaphore send this info to task2. But I do not know how to setup time how long task1 will run, for example how to make that task1 is running for a 10 second?

I’m not fully sure I understand your question, but maybe the following will help.

FreeRTOS will always run the highest priority task that is able to run (not waiting for an event). If you want the task to run for 10 seconds without being interrupted then make sure it is the highest priority task for those 10 seconds and make sure it doesn’t block on anything (like block to wait for a message).

If on the other hand you only want the task to run when the button has been pushed then you are better off having the task blocked on waiting for the button push event. You can do that by having the button generate an interrupt, then send the task a direct to task notification from the interrupt handler. Then the task will sit in a loop blocking to wait for a notification, unblocking when the notification is received, processing the button input, then back to the start to wait for the next button push. See https://www.freertos.org/RTOS_Task_Notification_As_Counting_Semaphore.html