优先级别继承
![图片[1]-70022 ESP32_freeRTOS mutex互斥量-爱设计](https://lovedisign.com/wp-content/uploads/2025/08/20250828143336127-image-1024x385.png)
![图片[2]-70022 ESP32_freeRTOS mutex互斥量-爱设计](https://lovedisign.com/wp-content/uploads/2025/08/20250828195146186-image.png)
![图片[3]-70022 ESP32_freeRTOS mutex互斥量-爱设计](https://lovedisign.com/wp-content/uploads/2025/08/20250828195533887-image.png)
![图片[4]-70022 ESP32_freeRTOS mutex互斥量-爱设计](https://lovedisign.com/wp-content/uploads/2025/08/20250828202823524-image.png)
![图片[5]-70022 ESP32_freeRTOS mutex互斥量-爱设计](https://lovedisign.com/wp-content/uploads/2025/08/20250828202804497-image.png)
void Task1(void *pvParameters)
{
BaseType_t iRet;
while (1)
{
printf("Task1:run\n");
iRet = xSemaphoreTake(mutexHandle, portMAX_DELAY);
if (iRet == pdPASS)
{
printf("Task1:take\n");
for (int i = 0; i < 10; i++)
{
printf("Task1:i=%d\n", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
xSemaphoreGive(mutexHandle);
printf("Task1:give\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
else
{
printf("Task1:take fail\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
}
void Task2(void *pvParameters)
{
printf("Task2:run\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
while (1)
{
;
}
}
void Task3(void *pvParameters)
{
BaseType_t iRet;
printf("Task3:run\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
while (1)
{
iRet = xSemaphoreTake(mutexHandle, portMAX_DELAY);
if (iRet == pdPASS)
{
printf("Task3:take\n");
for (int i = 0; i < 10; i++)
{
printf("Task3:i=%d\n", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
xSemaphoreGive(mutexHandle);
printf("Task3:give\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
else
{
printf("Task3:take fail\n");
}
}
}
void app_main(void)
{
mutexHandle = xSemaphoreCreateMutex();
vTaskSuspendAll();
xTaskCreate(Task1, "Task1", 2048 * 5, NULL, 1, NULL);
xTaskCreate(Task2, "Task2", 2048 * 5, NULL, 2, NULL);
xTaskCreate(Task3, "Task3", 2048 * 5, NULL, 3, NULL);
xTaskResumeAll();
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END









暂无评论内容