non blocking semaphore in task

kyrpav
Posts: 37
Joined: Wed Jan 29, 2020 8:27 am

non blocking semaphore in task

Postby kyrpav » Thu Feb 17, 2022 11:49 pm

Hi i have a Task where it waits for a Samaphore to run.
Then it has to go in an infinate loop to control a motor position.
I would like to break this second loop when the stop button is pressed is there any way to call SemaphoreTake function to break from the second loop but not block the while loop of the control ?

Let me try to give some code example

Code: Select all

void startTaskFunction(void *params){ //this is the function
    while (true)
    {
        xSemaphoreTake(StartSema,portMAX_DELAY);//which in order to start waits this Semaphore to be Given
        while(true){

            //do some logic to controll a motor and keep it steady

            /////to stop this while on some stop button if i use the next i think it will stop and waits on the first run of the loop so there is 
            //no control
            xSemaphoreTake(StopSema,portMAX_DELAY);
            break;
            // if i wrap it in an if condition i think it is the same isn't it?

        }
    }
}

kyrpav
Posts: 37
Joined: Wed Jan 29, 2020 8:27 am

Re: non blocking semaphore in task

Postby kyrpav » Fri Feb 18, 2022 12:08 am

Unfortunately i was not thinking clearly i can set the delay not to portMax_Delay but to some milliseconds. but i still need to wrap it in if condition in order to know if this happend so the question is that does the semaphoreTake return something i tried to open to see the declaration but i did not understand it.

imdaad
Posts: 10
Joined: Mon Oct 26, 2020 12:58 pm

Re: non blocking semaphore in task

Postby imdaad » Mon Feb 21, 2022 7:50 am

yes, it does return a BaseType_t. if it is pdPass you successfully obtained the token, otherwise, you will get pdFALSE which indicated either the token was not available or timeout.
Wbt using an event group if you need to look into multiple conditions?

Who is online

Users browsing this forum: dzungpv, Google [Bot] and 96 guests