我有一個等待信號量運行的任務。然后它必須進入一個無限回圈來控制電機位置。
我想在按下停止按鈕時打破第二個回圈。有沒有辦法xSemaphoreTake()從第二個回圈呼叫中斷但不阻塞控制元件的while回圈?
讓我嘗試給出一些代碼示例:
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?
}
}
}
uj5u.com熱心網友回復:
您可以嘗試立即獲取信號量,如果成功,則跳出回圈:
void startTaskFunction(void *params)
{
while (true) {
xSemaphoreTake(StartSema, portMAX_DELAY);
while (true) {
//do some logic to controll a motor and keep it steady
if (xSemaphoreTake(StopSema, 0) == pdTRUE) {
break;
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/427884.html
上一篇:Meson:根據目標改變C編譯器
下一篇:信號6的問題
